This repository has been archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
requests.go
239 lines (209 loc) · 8.85 KB
/
requests.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
package blockchains
import (
"github.com/huaweicloud/golangsdk"
)
//CreateOpts is a struct which will be used to create a bcs instance
type CreateOpts struct {
Name string `json:"name" required:"true"`
ClusterType string `json:"cluster_type" required:"true"`
CreateNewCluster *bool `json:"create_new_cluster" required:"true"`
EnterpriseProjectId string `json:"enterprise_project_id" required:"true"`
FabricVersion string `json:"fabric_version" required:"true"`
Password string `json:"resource_password" required:"true"`
VersionType int `json:"version_type" required:"true"`
BlockChainType string `json:"blockchain_type,omitempty"`
Consensus string `json:"consensus,omitempty"`
SignAlgorithm string `json:"sign_algorithm,omitempty"`
VolumeType string `json:"volume_type,omitempty"`
EvsDiskType string `json:"evs_disk_type,omitempty"`
OrgDiskSize int `json:"org_disk_size,omitempty"`
DatabaseType string `json:"database_type,omitempty"`
OrdererNodeNumber int `json:"orderer_node_number,omitempty"`
EIPEnable bool `json:"use_eip,omitempty"`
BandwidthSize int `json:"bandwidth_size,omitempty"`
CCEClusterInfo *CCEClusterInfo `json:"cce_cluster_info,omitempty"`
CCECreateInfo *CCECreateInfo `json:"cce_create_info,omitempty"`
IEFDeployMode int `json:"ief_deploy_mode,omitempty"`
IEFNodesInfo []IEFNode `json:"ief_nodes_info,omitempty"`
PeerOrgs []PeerOrg `json:"peer_orgs,omitempty"`
Channels []ChannelInfo `json:"channels,omitempty"`
CouchDBInfo *CouchDBInfo `json:"couchdb_info,omitempty"`
SFSTurbo *SFSTurbo `json:"turbo_info,omitempty"`
Block *BlockInfo `json:"block_info,omitempty"`
Kafka *KafkaInfo `json:"kafka_create_info,omitempty"`
TC3Need bool `json:"tc3_need,omitempty"`
RestfulAPISupport bool `json:"restful_api_support,omitempty"`
IsInvitee bool `json:"is_invitee,omitempty"`
InvitorInfo *InvitorInfo `json:"invitor_infos,omitempty"`
}
//CCEClusterInfo is the CCE cluster struct that will be used to associate when creating a bcs instance
type CCEClusterInfo struct {
ID string `json:"cluster_id" required:"true"`
Name string `json:"cluster_name" required:"true"`
}
//CCECreateInfo is the struct that will be used to specify the creation of a new CCE cluster
//when creating a bcs instance
type CCECreateInfo struct {
NodeNum int `json:"node_num" required:"true"`
Flavor string `json:"node_flavor" required:"true"`
ClusterFlavor string `json:"cce_flavor" required:"true"`
Password string `json:"init_node_pwd" required:"true"`
AvailabilityZone string `json:"az" required:"true"`
PlatformType string `json:"cluster_platform_type" required:"true"`
}
//IEFNode is the IEF node struct that will be used to associate when creating a bcs instance
type IEFNode struct {
ID string `json:"id" required:"true"`
Status string `json:"status" required:"true"`
IPAddress string `json:"public_ip_address" required:"true"`
}
//PeerOrg is the peer organization struct that will be used to creating a bcs instance
type PeerOrg struct {
Name string `json:"name" required:"true"`
NodeCount int `json:"node_count" required:"true"`
}
//ChannelInfo is the channel struct that will be used to creating a bcs instance
type ChannelInfo struct {
Name string `json:"name" required:"true"`
OrgNames []string `json:"org_names" required:"true"`
Description string `json:"desctiption,omitempty"`
}
//CouchDBInfo is the couch database struct that will be used to creating a bcs instance
type CouchDBInfo struct {
UserName string `json:"user_name" required:"true"`
Password string `json:"password" required:"true"`
}
//SFSTurbo is the turbo struct that will be used to creating a bcs instance
type SFSTurbo struct {
ShareType string `json:"share_type" required:"true"`
Type string `json:"type" required:"true"`
AvailabilityZone string `json:"availability_zone" required:"true"`
Flavor string `json:"resource_spec_code" required:"true"`
}
//BlockInfo is the turbo struct that will be used to creating a bcs instance
type BlockInfo struct {
BatchTimeout int `json:"batch_timeout,omitempty"`
MaxMessageCount int `json:"max_message_count,omitempty"`
PreferredMaxbytes int `json:"preferred_maxbytes,omitempty"`
}
//KafkaInfo is the block generation struct that be used to config when creating a bcs instance
type KafkaInfo struct {
Flavor string `json:"spec" required:"true"`
Storage int `json:"storage" required:"true"`
AvailabilityZone string `json:"az" required:"true"`
}
//InvitorInfo is the invitor struct that be used to config when creating a bcs instance
type InvitorInfo struct {
TenantID string `json:"tenant_id" required:"true"`
ProjectID string `json:"project_id" required:"true"`
BlockchainID string `json:"blockchain_id" required:"true"`
}
type CreateOptsBuilder interface {
ToInstancesCreateMap() (map[string]interface{}, error)
}
func (opts CreateOpts) ToInstancesCreateMap() (map[string]interface{}, error) {
b, err := golangsdk.BuildRequestBody(opts, "")
if err != nil {
return nil, err
}
return b, nil
}
//Create is a method by which can be able to access the create function that create a bcs instance
func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
b, err := opts.ToInstancesCreateMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Post(rootURL(client), b, &r.Body, &golangsdk.RequestOpts{
OkCodes: []int{200, 202},
})
return
}
//DeleteOpts is a struct which will be used to delete an existing bcs instance
type DeleteOpts struct {
IsDeleteStorage bool `q:"is_delete_storage"`
IsDeleteOBS bool `q:"is_delete_obs"`
IsDeleteResource bool `q:"is_delete_resource"`
}
type DeleteOptsBuilder interface {
ToInstanceDeleteQuery() (string, error)
}
func (opts DeleteOpts) ToInstanceDeleteQuery() (string, error) {
q, err := golangsdk.BuildQueryString(opts)
if err != nil {
return "", err
}
return q.String(), err
}
//Delete is a method to delete an existing bcs instance
func Delete(client *golangsdk.ServiceClient, opts DeleteOptsBuilder, id string) (r DeleteResult) {
url := resourceURL(client, id)
if opts != nil {
query, err := opts.ToInstanceDeleteQuery()
if err != nil {
r.Err = err
return
}
url += query
}
_, r.Err = client.Delete(url, &golangsdk.RequestOpts{
OkCodes: []int{200, 202, 204},
JSONResponse: nil,
MoreHeaders: map[string]string{"Content-Type": "application/json"},
})
return
}
//Get is a method to obtain the detailed information of an existing bcs instance
func Get(client *golangsdk.ServiceClient, id string) (r ShowResult) {
_, r.Err = client.Get(resourceURL(client, id), &r.Body, nil)
return
}
//GetStatus is a method to obtain all block status of an existing bcs instance
func GetStatus(client *golangsdk.ServiceClient, id string) (r StatusResult) {
_, r.Err = client.Get(extraURL(client, id, "status"), &r.Body, nil)
return
}
//List is a method to obtain the detailed information list of all existing bcs instance
func List(client *golangsdk.ServiceClient) (r ListResult) {
_, r.Err = client.Get(rootURL(client), &r.Body, nil)
return
}
//GetNodes is a method to obtain the node information list of an existing bcs instance
func GetNodes(client *golangsdk.ServiceClient, id string) (r NodesResult) {
_, r.Err = client.Get(extraURL(client, id, "nodes"), &r.Body, nil)
return
}
//UpdateOpts is a struct which will be used to update an existing bcs instance
type UpdateOpts struct {
NodePeer []NodePeer `json:"node_orgs" required:"true"`
PublicIPs []IEFNode `json:"publicips,omitempty"`
}
//NodePeer is the peer organization struct that will be used to add a peer organization to an existing bcs instance
type NodePeer struct {
Name string `json:"name" required:"true"`
Count int `json:"node_count" required:"true"`
PVCName string `json:"pvc_name,omitempty"`
}
type UpdateOptsBuilder interface {
ToInstancesUpdateMap() (map[string]interface{}, error)
}
func (opts UpdateOpts) ToInstancesUpdateMap() (map[string]interface{}, error) {
b, err := golangsdk.BuildRequestBody(opts, "")
if err != nil {
return nil, err
}
return b, nil
}
//Update is a method to update an existing bcs instance
func Update(client *golangsdk.ServiceClient, opts UpdateOptsBuilder, id string) (r UpdateResult) {
b, err := opts.ToInstancesUpdateMap()
if err != nil {
r.Err = err
return
}
_, r.Err = client.Post(resourceURL(client, id), b, nil, &golangsdk.RequestOpts{
OkCodes: []int{200, 202},
})
return
}