github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/cbr/v3/vaults/results.go (about) 1 package vaults 2 3 import ( 4 "fmt" 5 6 "github.com/chnsz/golangsdk" 7 "github.com/chnsz/golangsdk/openstack/common/tags" 8 "github.com/chnsz/golangsdk/pagination" 9 ) 10 11 type commonResult struct { 12 golangsdk.Result 13 } 14 15 type CreateResult struct { 16 commonResult 17 } 18 19 type GetResult struct { 20 commonResult 21 } 22 23 type UpdateResult struct { 24 commonResult 25 } 26 27 type DeleteResult struct { 28 golangsdk.ErrResult 29 } 30 31 type Vault struct { 32 ID string `json:"id"` 33 Name string `json:"name"` 34 Billing Billing `json:"billing"` 35 Description string `json:"description"` 36 ProjectID string `json:"project_id"` 37 ProviderID string `json:"provider_id"` 38 Resources []ResourceResp `json:"resources"` 39 Tags []tags.ResourceTag `json:"tags"` 40 EnterpriseProjectID string `json:"enterprise_project_id"` 41 AutoBind bool `json:"auto_bind"` 42 BindRules VaultBindRules `json:"bind_rules"` 43 UserID string `json:"user_id"` 44 CreatedAt string `json:"created_at"` 45 AutoExpand bool `json:"auto_expand"` 46 SmnNotify bool `json:"smn_notify"` 47 Threshold int `json:"threshold"` 48 BackupNamePrefix string `json:"backup_name_prefix"` 49 } 50 51 type Billing struct { 52 Allocated int `json:"allocated"` 53 ChargingMode string `json:"charging_mode"` 54 CloudType string `json:"cloud_type"` 55 ConsistentLevel string `json:"consistent_level"` 56 ObjectType string `json:"object_type"` 57 OrderID string `json:"order_id"` 58 ProductID string `json:"product_id"` 59 ProtectType string `json:"protect_type"` 60 Size int `json:"size"` 61 SpecCode string `json:"spec_code"` 62 Status string `json:"status"` 63 StorageUnit string `json:"storage_unit"` 64 Used int `json:"used"` 65 FrozenScene string `json:"frozen_scene"` 66 IsMultiAz bool `json:"is_multi_az"` 67 } 68 69 type ResourceResp struct { 70 ExtraInfo ResourceExtraInfo `json:"extra_info"` 71 ID string `json:"id"` 72 Name string `json:"name"` 73 ProtectStatus string `json:"protect_status"` 74 Size int `json:"size"` 75 Type string `json:"type"` 76 BackupSize int `json:"backup_size"` 77 BackupCount int `json:"backup_count"` 78 } 79 80 func (r commonResult) Extract() (*Vault, error) { 81 var s struct { 82 Vault *Vault `json:"vault"` 83 } 84 err := r.ExtractInto(&s) 85 return s.Vault, err 86 } 87 88 type OrderResp struct { 89 ErrText string `json:"errText"` 90 ErrCode string `json:"error_code"` 91 RetCode int `json:"retCode"` 92 Orders []Order `json:"orders"` 93 } 94 95 type Order struct { 96 CloudServiceId string `json:"cloudServiceId"` 97 ID string `json:"orderId"` 98 ReserveInstanceIds []string `json:"reserveInstanceIds"` 99 ResourceId string `json:"resourceId"` 100 SubscribeResult string `json:"subscribeResult"` 101 } 102 103 func (r CreateResult) ExtractOrder() (*OrderResp, error) { 104 var s OrderResp 105 err := r.ExtractInto(&s) 106 return &s, err 107 } 108 109 type AssociateResourcesResult struct { 110 golangsdk.Result 111 } 112 113 func (r AssociateResourcesResult) Extract() ([]string, error) { 114 var s struct { 115 AddResourceIDs []string `json:"add_resource_ids"` 116 } 117 if r.Err != nil { 118 return nil, r.Err 119 } 120 err := r.ExtractInto(&s) 121 if err != nil { 122 return nil, fmt.Errorf("failed to extract Associated Resource IDs") 123 } 124 return s.AddResourceIDs, nil 125 } 126 127 type DissociateResourcesResult struct { 128 golangsdk.Result 129 } 130 131 func (r DissociateResourcesResult) Extract() ([]string, error) { 132 var s struct { 133 RemoveResourceIDs []string `json:"remove_resource_ids"` 134 } 135 if r.Err != nil { 136 return nil, r.Err 137 } 138 err := r.ExtractInto(&s) 139 if err != nil { 140 return nil, fmt.Errorf("failed to extract Dissociated Resource IDs") 141 } 142 return s.RemoveResourceIDs, nil 143 } 144 145 type BindPolicyResult struct { 146 golangsdk.Result 147 } 148 149 type PolicyBinding struct { 150 // The destination vault ID, returned only for replication policy association. 151 DestinationVaultId string `json:"destination_vault_id"` 152 // The policy ID. 153 VaultID string `json:"vault_id"` 154 // The policy ID list. 155 PolicyID string `json:"policy_id"` 156 } 157 158 func (r BindPolicyResult) Extract() (*PolicyBinding, error) { 159 var s struct { 160 PolicyBinding *PolicyBinding `json:"associate_policy"` 161 } 162 err := r.ExtractInto(&s) 163 return s.PolicyBinding, err 164 } 165 166 type UnbindPolicyResult struct { 167 golangsdk.Result 168 } 169 170 func (r UnbindPolicyResult) Extract() (*PolicyBinding, error) { 171 var s struct { 172 PolicyBinding *PolicyBinding `json:"dissociate_policy"` 173 } 174 err := r.ExtractInto(&s) 175 return s.PolicyBinding, err 176 } 177 178 type VaultPage struct { 179 pagination.SinglePageBase 180 } 181 182 func ExtractVaults(r pagination.Page) (*[]Vault, error) { 183 var s struct { 184 Vaults []Vault `json:"vaults"` 185 } 186 err := (r.(VaultPage)).ExtractInto(&s) 187 return &s.Vaults, err 188 }