-
Notifications
You must be signed in to change notification settings - Fork 0
/
subnet-ipam.go
69 lines (54 loc) · 1.46 KB
/
subnet-ipam.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
package subnet
import (
"context"
"fmt"
"github.com/AlecAivazis/survey/v2"
"mmesh.dev/m-api-go/grpc/resources/topology"
"mmesh.dev/m-cli/pkg/grpc"
"mmesh.dev/m-cli/pkg/input"
"mmesh.dev/m-cli/pkg/output"
"mmesh.dev/m-cli/pkg/status"
"mmesh.dev/m-lib/pkg/utils/msg"
)
type ipamEndpoint struct {
endpointID string
ipv4 string
}
func (api *API) DeleteIPAMEntry() {
s := GetSubnet(false)
nxc, grpcConn := grpc.GetTopologyAPIClient()
defer grpcConn.Close()
var endpointOptID string
ipamEndpointsOpts := make([]string, 0)
ipamEndpoints := make(map[string]*ipamEndpoint)
for e, ipv4 := range s.IPAM.Endpoints {
endpointOptID = fmt.Sprintf("%s: %s", ipv4, e)
ipamEndpointsOpts = append(ipamEndpointsOpts, endpointOptID)
ipamEndpoints[endpointOptID] = &ipamEndpoint{
endpointID: e,
ipv4: ipv4,
}
}
if len(ipamEndpointsOpts) == 0 {
msg.Info("No objects found")
return
}
endpointOptID = input.GetSelect("IPAM Endpoint:", "", ipamEndpointsOpts, survey.Required)
ss := output.Spinner()
req := &topology.RemoveSubnetIPAMEntryRequest{
AccountID: s.AccountID,
TenantID: s.TenantID,
NetID: s.NetID,
SubnetID: s.SubnetID,
EndpointID: ipamEndpoints[endpointOptID].endpointID,
IPv4: ipamEndpoints[endpointOptID].ipv4,
}
s, err := nxc.RemoveSubnetIPAMEntry(context.TODO(), req)
if err != nil {
ss.Stop()
status.Error(err, "Unable to remove subnet IPAM entry")
}
ss.Stop()
// output.Show(s)
Output().Show(s)
}