-
Notifications
You must be signed in to change notification settings - Fork 71
/
deploySet.go
169 lines (149 loc) · 5.1 KB
/
deploySet.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
* Copyright 2021 Baidu, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
// client.go - define the client for BEC service
// Package bec defines the BEC services of BCE. The supported APIs are all defined in sub-package
package bec
import (
"fmt"
"strconv"
"github.com/baidubce/bce-sdk-go/bce"
"github.com/baidubce/bce-sdk-go/http"
"github.com/baidubce/bce-sdk-go/services/bec/api"
)
// CreateDeploySet - create deploy set with the specific parameters
//
// PARAMS:
// - args: the arguments to create a deploy set
// RETURNS:
// - *CreateDeploySetResponseArgs: the result of create deploy set
// - error: nil if ok otherwise the specific error
func (c *Client) CreateDeploySet(args *api.CreateDeploySetArgs) (*api.CreateDeploySetResponseArgs, error) {
if args == nil {
return nil, fmt.Errorf("please set argments")
}
result := &api.CreateDeploySetResponseArgs{}
req := &api.PostHttpReq{Url: api.GetDeploySetURI() + "/create", Result: result, Body: args}
err := api.Post(c, req)
return result, err
}
// UpdateVmInstanceDeploySet - update vm instance deploy set with the specific parameters
//
// PARAMS:
// - args: the arguments to update a vm instance deploy set
// RETURNS:
// - error: nil if ok otherwise the specific error
func (c *Client) UpdateVmInstanceDeploySet(args *api.UpdateVmDeploySetArgs) error {
if args == nil {
return fmt.Errorf("please set argments")
}
req := &api.PostHttpReq{Url: api.GetDeploySetURI() + "/updateRelation", Body: args}
err := api.Post(c, req)
return err
}
// DeleteVmInstanceFromDeploySet - remove vm instances from deploy set with the specific parameters
//
// PARAMS:
// - args: the arguments to remove vm instances from deploy set
// RETURNS:
// - error: nil if ok otherwise the specific error
func (c *Client) DeleteVmInstanceFromDeploySet(args *api.DeleteVmDeploySetArgs) error {
if args == nil {
return fmt.Errorf("please set argments")
}
req := &api.PostHttpReq{Url: api.GetDeploySetURI() + "/delRelation", Body: args}
err := api.Post(c, req)
return err
}
// UpdateDeploySet - update deploy set with the specific parameters
//
// PARAMS:
// - args: the arguments to update deploy set
// RETURNS:
// - *ListVmServiceResult: the result of get vm services
// - error: nil if ok otherwise the specific error
func (c *Client) UpdateDeploySet(deploySetId string, args *api.CreateDeploySetArgs) error {
if args == nil || deploySetId == "" {
return fmt.Errorf("please set argments")
}
params := make(map[string]string)
params["modifyAttribute"] = ""
req := &api.PostHttpReq{Url: api.GetDeploySetURI() + "/" + deploySetId, Body: args, Params: params}
err := api.Put(c, req)
return err
}
// GetDeploySetList - get deploy set list with the specific parameters
// RETURNS:
// - *LogicPageDeploySetResult: the result of deploy set list
// - error: nil if ok otherwise the specific error
func (c *Client) GetDeploySetList(args *api.ListRequest) (*api.LogicPageDeploySetResult, error) {
if args == nil {
return nil, fmt.Errorf("please set argments")
}
params := make(map[string]string)
if args.PageSize != 0 {
params["pageSize"] = strconv.Itoa(args.PageSize)
}
if args.PageNo != 0 {
params["pageNo"] = strconv.Itoa(args.PageNo)
}
if args.KeywordType != "" {
params["keywordType"] = args.KeywordType
}
if args.Keyword != "" {
params["keyword"] = args.Keyword
}
result := &api.LogicPageDeploySetResult{}
err := bce.NewRequestBuilder(c).
WithMethod(http.GET).
WithURL(api.GetDeploySetURI() + "/list").
WithQueryParams(params).
WithResult(result).
Do()
return result, err
}
// GetDeploySetDetail - get vm service detail with the specific parameters
//
// PARAMS:
// - deploySetId: deploy set id
// RETURNS:
// - *DeploySetDetails: the result of deploy set detail
// - error: nil if ok otherwise the specific error
func (c *Client) GetDeploySetDetail(deploySetId string) (*api.DeploySetDetails, error) {
if deploySetId == "" {
return nil, fmt.Errorf("please set argments")
}
result := &api.DeploySetDetails{}
err := bce.NewRequestBuilder(c).
WithMethod(http.GET).
WithURL(api.GetDeploySetURI() + "/" + deploySetId).
WithResult(result).
Do()
return result, err
}
// DeleteDeploySet - delete deploy set with the specific parameters
//
// PARAMS:
// - deploySetId: deploy set id
// RETURNS:
// - error: nil if ok otherwise the specific error
func (c *Client) DeleteDeploySet(deploySetId string) error {
if deploySetId == "" {
return fmt.Errorf("please set argments")
}
err := bce.NewRequestBuilder(c).
WithMethod(http.DELETE).
WithURL(api.GetDeploySetURI() + "/" + deploySetId).
Do()
return err
}