Debian Codegraph @

network/network.go

raw symbols SCIP
1 package network
2
3 import (
4 "fmt"
5
6 "github.com/CenturyLinkCloud/clc-sdk/api"
7 "github.com/CenturyLinkCloud/clc-sdk/status"
8 )
9
10 func New(client api.HTTP) *Service {
11 return &Service{
12 client: client,
13 config: client.Config(),
14 }
15 }
16
17 type Service struct {
18 client api.HTTP
19 config *api.Config
20 }
21
22 /*
23 * Networks are "claimed" and "released" from the datacenter.
24 * Claim returns a status.QueuedOperation object which should be polled until status=succeeded.
25 * At which point, an api.Link object with rel=network can be inspected for the ID of the claimed network.
26 */
27
28 func (s *Service) List(dc string) (*[]Network, error) {
29 resp := &[]Network{}
30 url := fmt.Sprintf("%s/networks/%s/%s", s.config.BaseURL, s.config.Alias, dc)
31 err := s.client.Get(url, resp)
32 return resp, err
33 }
34
35 func (s *Service) Get(dc, id string) (*Network, error) {
36 url := fmt.Sprintf("%s/networks/%s/%s/%s", s.config.BaseURL, s.config.Alias, dc, id)
37 resp := &Network{}
38 err := s.client.Get(url, resp)
39 return resp, err
40 }
41
42 func (s *Service) GetAddresses(dc, id string) (*[]IP, error) {
43 resp := &[]IP{}
44 url := fmt.Sprintf("%s/networks/%s/%s/%s/ipAddresses", s.config.BaseURL, s.config.Alias, dc, id)
45 err := s.client.Get(url, resp)
46 return resp, err
47 }
48
49 func (s *Service) Claim(dc string) (*status.QueuedOperation, error) {
50 resp := &status.QueuedOperation{}
51 url := fmt.Sprintf("%s/networks/%s/%s/claim", s.config.BaseURL, s.config.Alias, dc)
52 err := s.client.Post(url, "", resp)
53 return resp, err
54 }
55
56 func (s *Service) Release(dc, id string) error {
57 url := fmt.Sprintf("%s/networks/%s/%s/%s/release", s.config.BaseURL, s.config.Alias, dc, id)
58 err := s.client.Post(url, "", nil)
59 return err
60 }
61
62 func (s *Service) Update(dc, id, name, description string) error {
63 url := fmt.Sprintf("%s/networks/%s/%s/%s", s.config.BaseURL, s.config.Alias, dc, id)
64 body := fmt.Sprintf(`{"name": "%s", "description": "%s"}`, name, description)
65 err := s.client.Post(url, body, nil)
66 return err
67 }
68
69 type Network struct {
70 ID string `json:"id"`
71 CIDR string `json:"cidr"`
72 Description string `json:"description"`
73 Gateway string `json:"gateway"`
74 Name string `json:"name"`
75 Netmask string `json:"netmask"`
76 Type string `json:"type"`
77 VLAN int `json:"vlan"`
78 IPAddresses []IP `json:"ipAddresses"`
79 Links api.Links `json:"links"`
80 }
81
82 type IP struct {
83 Address string `json:"address"`
84 Claimed bool `json:"claimed"`
85 Server string `json:"server"`
86 Type string `json:"type"` // private | virtual | publicMapped
87 }