github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/cbr/v3/vaults/requests.go (about) 1 package vaults 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/openstack/common/tags" 6 "github.com/huaweicloud/golangsdk/pagination" 7 ) 8 9 type CreateOpts struct { 10 Billing *BillingCreate `json:"billing" required:"true"` 11 Name string `json:"name" required:"true"` 12 Resources []ResourceCreate `json:"resources" required:"true"` 13 AutoBind bool `json:"auto_bind,omitempty"` 14 AutoExpand bool `json:"auto_expand,omitempty"` 15 BackupPolicyID string `json:"backup_policy_id,omitempty"` 16 BindRules *VaultBindRules `json:"bind_rules,omitempty"` 17 Description string `json:"description,omitempty"` 18 EnterpriseProjectID string `json:"enterprise_project_id,omitempty"` 19 Tags []tags.ResourceTag `json:"tags,omitempty"` 20 } 21 22 type BillingCreate struct { 23 ConsistentLevel string `json:"consistent_level" required:"true"` 24 ObjectType string `json:"object_type" required:"true"` 25 ProtectType string `json:"protect_type" required:"true"` 26 Size int `json:"size" required:"true"` 27 ChargingMode string `json:"charging_mode,omitempty"` 28 CloudType string `json:"cloud_type,omitempty"` 29 ConsoleURL string `json:"console_url,omitempty"` 30 ExtraInfo *BillingCreateExtraInfo `json:"extra_info,omitempty"` 31 PeriodNum int `json:"period_num,omitempty"` 32 PeriodType string `json:"period_type,omitempty"` 33 IsAutoRenew bool `json:"is_auto_renew,omitempty"` 34 IsAutoPay bool `json:"is_auto_pay,omitempty"` 35 } 36 37 type BillingCreateExtraInfo struct { 38 CombinedOrderECSNum int `json:"combined_order_ecs_num,omitempty"` 39 CombinedOrderID string `json:"combined_order_id,omitempty"` 40 } 41 42 type ResourceCreate struct { 43 ID string `json:"id" required:"true"` 44 Type string `json:"type" required:"true"` 45 Name string `json:"name,omitempty"` 46 ExtraInfo *ResourceExtraInfo `json:"extra_info,omitempty"` 47 } 48 49 type ResourceExtraInfo struct { 50 ExcludeVolumes []string `json:"exclude_volumes,omitempty"` 51 IncludeVolumes []ResourceExtraInfoIncludeVolumes `json:"include_volumes,omitempty"` 52 } 53 54 type ResourceExtraInfoIncludeVolumes struct { 55 ID string `json:"id" required:"true"` 56 OSVersion string `json:"os_version,omitempty"` 57 } 58 59 type VaultBindRules struct { 60 Tags []tags.ResourceTag `json:"tags,omitempty"` 61 } 62 63 type CreateOptsBuilder interface { 64 ToVaultCreateMap() (map[string]interface{}, error) 65 } 66 67 func (opts CreateOpts) ToVaultCreateMap() (map[string]interface{}, error) { 68 return golangsdk.BuildRequestBody(opts, "vault") 69 } 70 71 func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 72 reqBody, err := opts.ToVaultCreateMap() 73 if err != nil { 74 r.Err = err 75 return 76 } 77 _, err = client.Post(rootURL(client), reqBody, &r.Body, &golangsdk.RequestOpts{ 78 OkCodes: []int{200}, 79 }) 80 r.Err = err 81 return 82 } 83 84 func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { 85 _, r.Err = client.Delete(resourceURL(client, id), nil) 86 return 87 } 88 89 func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { 90 _, r.Err = client.Get(resourceURL(client, id), &r.Body, nil) 91 return 92 } 93 94 type UpdateOpts struct { 95 Billing *BillingUpdate `json:"billing,omitempty"` 96 Name string `json:"name,omitempty"` 97 AutoBind *bool `json:"auto_bind,omitempty"` 98 BindRules *VaultBindRules `json:"bind_rules,omitempty"` 99 AutoExpand *bool `json:"auto_expand,omitempty"` 100 } 101 102 type BillingUpdate struct { 103 Size int `json:"size,omitempty"` 104 } 105 106 type UpdateOptsBuilder interface { 107 ToVaultUpdateMap() (map[string]interface{}, error) 108 } 109 110 func (opts UpdateOpts) ToVaultUpdateMap() (map[string]interface{}, error) { 111 return golangsdk.BuildRequestBody(opts, "vault") 112 } 113 114 func Update(client *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { 115 reqBody, err := opts.ToVaultUpdateMap() 116 if err != nil { 117 r.Err = err 118 return 119 } 120 _, r.Err = client.Put(resourceURL(client, id), reqBody, &r.Body, &golangsdk.RequestOpts{ 121 OkCodes: []int{200}, 122 }) 123 return 124 } 125 126 type ListOpts struct { 127 CloudType string `q:"cloud_type"` 128 EnterpriseProjectID string `q:"enterprise_project_id"` 129 ID string `q:"id"` 130 Limit string `q:"limit"` 131 Name string `q:"name"` 132 ObjectType string `q:"object_type"` 133 Offset string `q:"offset"` 134 PolicyID string `q:"policy_id"` 135 ProtectType string `q:"protect_type"` 136 ResourceIDs string `q:"resource_ids"` 137 Status string `q:"status"` 138 } 139 140 func (opts ListOpts) ToPolicyListQuery() (string, error) { 141 q, err := golangsdk.BuildQueryString(opts) 142 if err != nil { 143 return "", err 144 } 145 return q.String(), err 146 } 147 148 type ListOptsBuilder interface { 149 ToPolicyListQuery() (string, error) 150 } 151 152 //List is a method to obtain the specified CBR vaults according to the vault ID, vault name and so on. 153 //This method can also obtain all the CBR vaults through the default parameter settings. 154 func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { 155 url := rootURL(client) 156 if opts != nil { 157 query, err := opts.ToPolicyListQuery() 158 if err != nil { 159 return pagination.Pager{Err: err} 160 } 161 url += query 162 } 163 164 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 165 return VaultPage{pagination.SinglePageBase(r)} 166 }) 167 } 168 169 type BindPolicyOpts struct { 170 PolicyID string `json:"policy_id" required:"true"` 171 } 172 173 func (opts BindPolicyOpts) ToBindPolicyMap() (map[string]interface{}, error) { 174 return golangsdk.BuildRequestBody(opts, "") 175 } 176 177 type BindPolicyOptsBuilder interface { 178 ToBindPolicyMap() (map[string]interface{}, error) 179 } 180 181 func BindPolicy(client *golangsdk.ServiceClient, vaultID string, opts BindPolicyOptsBuilder) (r BindPolicyResult) { 182 reqBody, err := opts.ToBindPolicyMap() 183 if err != nil { 184 r.Err = err 185 return 186 } 187 _, r.Err = client.Post(bindPolicyURL(client, vaultID), reqBody, &r.Body, &golangsdk.RequestOpts{ 188 OkCodes: []int{200}, 189 }) 190 return 191 } 192 193 func UnbindPolicy(client *golangsdk.ServiceClient, vaultID string, opts BindPolicyOptsBuilder) (r UnbindPolicyResult) { 194 reqBody, err := opts.ToBindPolicyMap() 195 if err != nil { 196 r.Err = err 197 return 198 } 199 _, r.Err = client.Post(unbindPolicyURL(client, vaultID), reqBody, &r.Body, &golangsdk.RequestOpts{ 200 OkCodes: []int{200}, 201 }) 202 return 203 } 204 205 type AssociateResourcesOpts struct { 206 Resources []ResourceCreate `json:"resources" required:"true"` 207 } 208 209 func (opts AssociateResourcesOpts) ToAssociateResourcesMap() (map[string]interface{}, error) { 210 return golangsdk.BuildRequestBody(opts, "") 211 } 212 213 type AssociateResourcesOptsBuilder interface { 214 ToAssociateResourcesMap() (map[string]interface{}, error) 215 } 216 217 func AssociateResources(client *golangsdk.ServiceClient, vaultID string, opts AssociateResourcesOptsBuilder) (r AssociateResourcesResult) { 218 reqBody, err := opts.ToAssociateResourcesMap() 219 if err != nil { 220 r.Err = err 221 return 222 } 223 _, r.Err = client.Post(addResourcesURL(client, vaultID), reqBody, &r.Body, &golangsdk.RequestOpts{ 224 OkCodes: []int{200}, 225 }) 226 return 227 } 228 229 type DissociateResourcesOpts struct { 230 ResourceIDs []string `json:"resource_ids" required:"true"` 231 } 232 233 func (opts DissociateResourcesOpts) ToDissociateResourcesMap() (map[string]interface{}, error) { 234 return golangsdk.BuildRequestBody(opts, "") 235 } 236 237 type DissociateResourcesOptsBuilder interface { 238 ToDissociateResourcesMap() (map[string]interface{}, error) 239 } 240 241 func DissociateResources(client *golangsdk.ServiceClient, vaultID string, opts DissociateResourcesOptsBuilder) (r DissociateResourcesResult) { 242 reqBody, err := opts.ToDissociateResourcesMap() 243 if err != nil { 244 r.Err = err 245 return 246 } 247 _, r.Err = client.Post(removeResourcesURL(client, vaultID), reqBody, &r.Body, &golangsdk.RequestOpts{ 248 OkCodes: []int{200}, 249 }) 250 return 251 }