Debian Codegraph @

dc/dc.go

raw symbols SCIP
1 package dc
2
3 import (
4 "fmt"
5
6 "github.com/CenturyLinkCloud/clc-sdk/api"
7 )
8
9 func New(client api.HTTP) *Service {
10 return &Service{
11 client: client,
12 config: client.Config(),
13 }
14 }
15
16 type Service struct {
17 client api.HTTP
18 config *api.Config
19 }
20
21 func (s *Service) Get(id string) (*Response, error) {
22 url := fmt.Sprintf("%s/datacenters/%s/%s?groupLinks=true", s.config.BaseURL, s.config.Alias, id)
23 dc := &Response{}
24 err := s.client.Get(url, dc)
25 return dc, err
26 }
27
28 func (s *Service) GetAll() ([]*Response, error) {
29 url := fmt.Sprintf("%s/datacenters/%s", s.config.BaseURL, s.config.Alias)
30 dcs := make([]*Response, 0)
31 err := s.client.Get(url, &dcs)
32 return dcs, err
33 }
34
35 func (s *Service) GetCapabilities(id string) (*CapabilitiesResponse, error) {
36 url := fmt.Sprintf("%s/datacenters/%s/%s/deploymentCapabilities", s.config.BaseURL, s.config.Alias, id)
37 c := &CapabilitiesResponse{}
38 err := s.client.Get(url, c)
39 return c, err
40 }
41
42 func (s *Service) GetBareMetalCapabilities(dataCenterId string) (*BareMetalCapabilitiesResponse, error) {
43 url := fmt.Sprintf("%s/datacenters/%s/%s/bareMetalCapabilities", s.config.BaseURL, s.config.Alias, dataCenterId)
44 bm := &BareMetalCapabilitiesResponse{}
45 err := s.client.Get(url, bm)
46 return bm, err
47 }
48
49 type Response struct {
50 ID string `json:"id"`
51 Name string `json:"name"`
52 Links api.Links `json:"links"`
53 }
54
55 type CapabilitiesResponse struct {
56 SupportsPremiumStorage bool `json:"supportsPremiumStorage"`
57 SupportsBareMetalServers bool `json:"supportsBareMetalServers"`
58 SupportsSharedLoadBalancer bool `json:"supportsSharedLoadBalancer"`
59 Templates []struct {
60 Name string `json:"name"`
61 Description string `json:"description"`
62 StorageSizeGB int `json:"storageSizeGB"`
63 Capabilities []string `json:"capabilities"`
64 ReservedDrivePaths []string `json:"reservedDrivePaths"`
65 } `json:"templates"`
66 DeployableNetworks []struct {
67 Name string `json:"name"`
68 NetworkId string `json:"networkId"`
69 Type string `json:"type"`
70 AccountID string `json:"accountID"`
71 } `json:"deployableNetworks"`
72 }
73
74 type BareMetalCapabilitiesResponse struct {
75 SKUs []struct {
76 ID string `json:"id"`
77 HourlyRate float32 `json:"hourlyRate"`
78 Availability string `json:"availability"`
79 Memory []struct {
80 CapacityInGB int `json:"capacityGB"`
81 } `json:"memory"`
82 Processor struct {
83 Sockets int `json:"sockets"`
84 CoresPerSocket int `json:"coresPerSocket"`
85 Description string `json:"description"`
86 } `json:"processor"`
87 Storage []struct {
88 Type string `json:"type"`
89 CapacityInGB int `json:"capacityGB"`
90 SpeedInRPM int `json:"speedRpm"`
91 } `json:"storage"`
92 } `json:"skus"`
93 OperatingSystems []struct {
94 Type string `json:"type"`
95 Description string `json:"description"`
96 HourlyRatePerSocket float32 `json:"hourlyRatePerSocket"`
97 } `json:"operatingSystems"`
98 }