github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/blockstorage/extensions/quotasets/requests.go (about) 1 package quotasets 2 3 import ( 4 "fmt" 5 6 "github.com/huaweicloud/golangsdk" 7 ) 8 9 // Get returns public data about a previously created QuotaSet. 10 func Get(client *golangsdk.ServiceClient, projectID string) (r GetResult) { 11 _, r.Err = client.Get(getURL(client, projectID), &r.Body, nil) 12 return 13 } 14 15 // GetDefaults returns public data about the project's default block storage quotas. 16 func GetDefaults(client *golangsdk.ServiceClient, projectID string) (r GetResult) { 17 _, r.Err = client.Get(getDefaultsURL(client, projectID), &r.Body, nil) 18 return 19 } 20 21 // GetUsage returns detailed public data about a previously created QuotaSet. 22 func GetUsage(client *golangsdk.ServiceClient, projectID string) (r GetUsageResult) { 23 u := fmt.Sprintf("%s?usage=true", getURL(client, projectID)) 24 _, r.Err = client.Get(u, &r.Body, nil) 25 return 26 } 27 28 // Updates the quotas for the given projectID and returns the new QuotaSet. 29 func Update(client *golangsdk.ServiceClient, projectID string, opts UpdateOptsBuilder) (r UpdateResult) { 30 b, err := opts.ToBlockStorageQuotaUpdateMap() 31 if err != nil { 32 r.Err = err 33 return 34 } 35 36 _, r.Err = client.Put(updateURL(client, projectID), b, &r.Body, &golangsdk.RequestOpts{ 37 OkCodes: []int{200}, 38 }) 39 return r 40 } 41 42 // UpdateOptsBuilder enables extensins to add parameters to the update request. 43 type UpdateOptsBuilder interface { 44 // Extra specific name to prevent collisions with interfaces for other quotas 45 // (e.g. neutron) 46 ToBlockStorageQuotaUpdateMap() (map[string]interface{}, error) 47 } 48 49 // ToBlockStorageQuotaUpdateMap builds the update options into a serializable 50 // format. 51 func (opts UpdateOpts) ToBlockStorageQuotaUpdateMap() (map[string]interface{}, error) { 52 return golangsdk.BuildRequestBody(opts, "quota_set") 53 } 54 55 // Options for Updating the quotas of a Tenant. 56 // All int-values are pointers so they can be nil if they are not needed. 57 // You can use gopercloud.IntToPointer() for convenience 58 type UpdateOpts struct { 59 // Volumes is the number of volumes that are allowed for each project. 60 Volumes *int `json:"volumes,omitempty"` 61 62 // Snapshots is the number of snapshots that are allowed for each project. 63 Snapshots *int `json:"snapshots,omitempty"` 64 65 // Gigabytes is the size (GB) of volumes and snapshots that are allowed for 66 // each project. 67 Gigabytes *int `json:"gigabytes,omitempty"` 68 69 // PerVolumeGigabytes is the size (GB) of volumes and snapshots that are 70 // allowed for each project and the specifed volume type. 71 PerVolumeGigabytes *int `json:"per_volume_gigabytes,omitempty"` 72 73 // Backups is the number of backups that are allowed for each project. 74 Backups *int `json:"backups,omitempty"` 75 76 // BackupGigabytes is the size (GB) of backups that are allowed for each 77 // project. 78 BackupGigabytes *int `json:"backup_gigabytes,omitempty"` 79 80 // Groups is the number of groups that are allowed for each project. 81 Groups *int `json:"groups,omitempty"` 82 83 // Force will update the quotaset even if the quota has already been used 84 // and the reserved quota exceeds the new quota. 85 Force bool `json:"force,omitempty"` 86 } 87 88 // Resets the quotas for the given tenant to their default values. 89 func Delete(client *golangsdk.ServiceClient, projectID string) (r DeleteResult) { 90 _, r.Err = client.Delete(updateURL(client, projectID), &golangsdk.RequestOpts{ 91 OkCodes: []int{200}, 92 }) 93 return 94 }