File: aa.go

package info (click to toggle)
golang-github-centurylinkcloud-clc-sdk 0.0.2%2Bgit20161004.f62483c-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 236 kB
  • sloc: sh: 18; makefile: 13
file content (67 lines) | stat: -rw-r--r-- 1,731 bytes parent folder | download | duplicates (2)
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
package aa

import (
	"fmt"

	"github.com/CenturyLinkCloud/clc-sdk/api"
)

func New(client api.HTTP) *Service {
	return &Service{
		client: client,
		config: client.Config(),
	}
}

type Service struct {
	client api.HTTP
	config *api.Config
}

func (s *Service) Get(id string) (*Policy, error) {
	url := fmt.Sprintf("%s/antiAffinityPolicies/%s/%s", s.config.BaseURL, s.config.Alias, id)
	policy := &Policy{}
	err := s.client.Get(url, policy)
	return policy, err
}

func (s *Service) GetAll() (*Policies, error) {
	url := fmt.Sprintf("%s/antiAffinityPolicies/%s", s.config.BaseURL, s.config.Alias)
	policies := &Policies{}
	err := s.client.Get(url, policies)
	return policies, err
}

func (s *Service) Create(name, location string) (*Policy, error) {
	policy := &Policy{Name: name, Location: location}
	resp := &Policy{}
	url := fmt.Sprintf("%s/antiAffinityPolicies/%s", s.config.BaseURL, s.config.Alias)
	err := s.client.Post(url, policy, resp)
	return resp, err
}

func (s *Service) Update(id string, name string) (*Policy, error) {
	policy := &Policy{Name: name}
	resp := &Policy{}
	url := fmt.Sprintf("%s/antiAffinityPolicies/%s/%s", s.config.BaseURL, s.config.Alias, id)
	err := s.client.Put(url, policy, resp)
	return resp, err
}

func (s *Service) Delete(id string) error {
	url := fmt.Sprintf("%s/antiAffinityPolicies/%s/%s", s.config.BaseURL, s.config.Alias, id)
	err := s.client.Delete(url, nil)
	return err
}

type Policy struct {
	ID       string    `json:"id,omitempty"`
	Name     string    `json:"name,omitempty"`
	Location string    `json:"location,omitempty"`
	Links    api.Links `json:"links,omitempty"`
}

type Policies struct {
	Items []Policy  `json:"items,omitempty"`
	Links api.Links `json:"links,omitempty"`
}