-
Notifications
You must be signed in to change notification settings - Fork 149
/
custom_placement_group.go
107 lines (84 loc) · 2.76 KB
/
custom_placement_group.go
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package instance
import (
"context"
"reflect"
"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
)
//
// Builders
//
func placementGroupGetBuilder(c *core.Command) *core.Command {
c.Run = func(ctx context.Context, argsI interface{}) (i interface{}, e error) {
req := argsI.(*instance.GetPlacementGroupRequest)
client := core.ExtractClient(ctx)
api := instance.NewAPI(client)
placementGroupResponse, err := api.GetPlacementGroup(req)
if err != nil {
return nil, err
}
placementGroupServersResponse, err := api.GetPlacementGroupServers(&instance.GetPlacementGroupServersRequest{
Zone: req.Zone,
PlacementGroupID: req.PlacementGroupID,
})
if err != nil {
return nil, err
}
return &struct {
*instance.PlacementGroup
Servers []*instance.PlacementGroupServer `json:"servers"`
}{
placementGroupResponse.PlacementGroup,
placementGroupServersResponse.Servers,
}, nil
}
c.View = &core.View{
Sections: []*core.ViewSection{
{FieldName: "PlacementGroup", Title: "Placement Group"},
{FieldName: "Servers", Title: "Servers"},
},
}
return c
}
func placementGroupCreateBuilder(c *core.Command) *core.Command {
type customCreatePlacementGroupRequest struct {
*instance.CreatePlacementGroupRequest
OrganizationID *string
ProjectID *string
}
renameOrganizationIDArgSpec(c.ArgSpecs)
renameProjectIDArgSpec(c.ArgSpecs)
c.ArgsType = reflect.TypeOf(customCreatePlacementGroupRequest{})
c.AddInterceptors(func(ctx context.Context, argsI interface{}, runner core.CommandRunner) (i interface{}, err error) {
args := argsI.(*customCreatePlacementGroupRequest)
if args.CreatePlacementGroupRequest == nil {
args.CreatePlacementGroupRequest = &instance.CreatePlacementGroupRequest{}
}
request := args.CreatePlacementGroupRequest
request.Organization = args.OrganizationID
request.Project = args.ProjectID
return runner(ctx, request)
})
return c
}
func placementGroupListBuilder(c *core.Command) *core.Command {
type customListPlacementGroupsRequest struct {
*instance.ListPlacementGroupsRequest
OrganizationID *string
ProjectID *string
}
renameOrganizationIDArgSpec(c.ArgSpecs)
renameProjectIDArgSpec(c.ArgSpecs)
c.ArgsType = reflect.TypeOf(customListPlacementGroupsRequest{})
c.AddInterceptors(func(ctx context.Context, argsI interface{}, runner core.CommandRunner) (i interface{}, err error) {
args := argsI.(*customListPlacementGroupsRequest)
if args.ListPlacementGroupsRequest == nil {
args.ListPlacementGroupsRequest = &instance.ListPlacementGroupsRequest{}
}
request := args.ListPlacementGroupsRequest
request.Organization = args.OrganizationID
request.Project = args.ProjectID
return runner(ctx, request)
})
return c
}