-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeps.go
More file actions
65 lines (54 loc) · 2.06 KB
/
deps.go
File metadata and controls
65 lines (54 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package debugcmd
import (
"context"
"fmt"
"strconv"
"strings"
"github.com/threefoldtech/zosbase/pkg"
"github.com/threefoldtech/zosbase/pkg/gridtypes"
"github.com/threefoldtech/zosbase/pkg/gridtypes/zos"
)
// Storage is the subset of the provision interface used by debug commands.
type Storage interface {
GetDeployment(ctx context.Context, twin uint32, contractID uint64) (gridtypes.Deployment, error)
GetDeployments(ctx context.Context, twin uint32) ([]gridtypes.Deployment, error)
GetTwins(ctx context.Context) ([]uint32, error)
Changes(ctx context.Context, twin uint32, contractID uint64) ([]gridtypes.Workload, error)
GetWorkload(ctx context.Context, twin uint32, contractID uint64, name gridtypes.Name) (gridtypes.Workload, bool, error)
}
// VM is the subset of the vmd zbus interface used by debug commands.
type VM interface {
Exists(ctx context.Context, id string) bool
Inspect(ctx context.Context, id string) (pkg.VMInfo, error)
Logs(ctx context.Context, id string) (string, error)
LogsFull(ctx context.Context, id string) (string, error)
}
// Network is the subset of the network zbus interface used by debug commands.
type Network interface {
Namespace(ctx context.Context, id zos.NetID) string
}
type Deps struct {
VM VM
Network Network
Storage Storage
}
// ParseDeploymentID parses a deployment identifier in the format "twin-id:contract-id"
// and returns the twin ID and contract ID.
func ParseDeploymentID(deploymentStr string) (uint32, uint64, error) {
if deploymentStr == "" {
return 0, 0, fmt.Errorf("deployment identifier is required")
}
parts := strings.Split(deploymentStr, ":")
if len(parts) != 2 {
return 0, 0, fmt.Errorf("invalid deployment format: expected 'twin-id:contract-id', got '%s'", deploymentStr)
}
twinID, err := strconv.ParseUint(parts[0], 10, 32)
if err != nil {
return 0, 0, fmt.Errorf("invalid twin ID: %s: %w", parts[0], err)
}
contractID, err := strconv.ParseUint(parts[1], 10, 64)
if err != nil {
return 0, 0, fmt.Errorf("invalid contract ID: %s: %w", parts[1], err)
}
return uint32(twinID), contractID, nil
}