Debian Codegraph @

aa/aa.go

raw symbols SCIP
1 package aa
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) (*Policy, error) {
22 url := fmt.Sprintf("%s/antiAffinityPolicies/%s/%s", s.config.BaseURL, s.config.Alias, id)
23 policy := &Policy{}
24 err := s.client.Get(url, policy)
25 return policy, err
26 }
27
28 func (s *Service) GetAll() (*Policies, error) {
29 url := fmt.Sprintf("%s/antiAffinityPolicies/%s", s.config.BaseURL, s.config.Alias)
30 policies := &Policies{}
31 err := s.client.Get(url, policies)
32 return policies, err
33 }
34
35 func (s *Service) Create(name, location string) (*Policy, error) {
36 policy := &Policy{Name: name, Location: location}
37 resp := &Policy{}
38 url := fmt.Sprintf("%s/antiAffinityPolicies/%s", s.config.BaseURL, s.config.Alias)
39 err := s.client.Post(url, policy, resp)
40 return resp, err
41 }
42
43 func (s *Service) Update(id string, name string) (*Policy, error) {
44 policy := &Policy{Name: name}
45 resp := &Policy{}
46 url := fmt.Sprintf("%s/antiAffinityPolicies/%s/%s", s.config.BaseURL, s.config.Alias, id)
47 err := s.client.Put(url, policy, resp)
48 return resp, err
49 }
50
51 func (s *Service) Delete(id string) error {
52 url := fmt.Sprintf("%s/antiAffinityPolicies/%s/%s", s.config.BaseURL, s.config.Alias, id)
53 err := s.client.Delete(url, nil)
54 return err
55 }
56
57 type Policy struct {
58 ID string `json:"id,omitempty"`
59 Name string `json:"name,omitempty"`
60 Location string `json:"location,omitempty"`
61 Links api.Links `json:"links,omitempty"`
62 }
63
64 type Policies struct {
65 Items []Policy `json:"items,omitempty"`
66 Links api.Links `json:"links,omitempty"`
67 }