github.com/gophercloud/gophercloud@v1.11.0/openstack/compute/v2/extensions/quotasets/results.go (about)

     1  package quotasets
     2  
     3  import (
     4  	"github.com/gophercloud/gophercloud"
     5  	"github.com/gophercloud/gophercloud/pagination"
     6  )
     7  
     8  // QuotaSet is a set of operational limits that allow for control of compute
     9  // usage.
    10  type QuotaSet struct {
    11  	// ID is tenant associated with this QuotaSet.
    12  	ID string `json:"id"`
    13  
    14  	// FixedIPs is number of fixed ips allotted this QuotaSet.
    15  	FixedIPs int `json:"fixed_ips"`
    16  
    17  	// FloatingIPs is number of floating ips allotted this QuotaSet.
    18  	FloatingIPs int `json:"floating_ips"`
    19  
    20  	// InjectedFileContentBytes is the allowed bytes for each injected file.
    21  	InjectedFileContentBytes int `json:"injected_file_content_bytes"`
    22  
    23  	// InjectedFilePathBytes is allowed bytes for each injected file path.
    24  	InjectedFilePathBytes int `json:"injected_file_path_bytes"`
    25  
    26  	// InjectedFiles is the number of injected files allowed for each project.
    27  	InjectedFiles int `json:"injected_files"`
    28  
    29  	// KeyPairs is number of ssh keypairs.
    30  	KeyPairs int `json:"key_pairs"`
    31  
    32  	// MetadataItems is number of metadata items allowed for each instance.
    33  	MetadataItems int `json:"metadata_items"`
    34  
    35  	// RAM is megabytes allowed for each instance.
    36  	RAM int `json:"ram"`
    37  
    38  	// SecurityGroupRules is number of security group rules allowed for each
    39  	// security group.
    40  	SecurityGroupRules int `json:"security_group_rules"`
    41  
    42  	// SecurityGroups is the number of security groups allowed for each project.
    43  	SecurityGroups int `json:"security_groups"`
    44  
    45  	// Cores is number of instance cores allowed for each project.
    46  	Cores int `json:"cores"`
    47  
    48  	// Instances is number of instances allowed for each project.
    49  	Instances int `json:"instances"`
    50  
    51  	// ServerGroups is the number of ServerGroups allowed for the project.
    52  	ServerGroups int `json:"server_groups"`
    53  
    54  	// ServerGroupMembers is the number of members for each ServerGroup.
    55  	ServerGroupMembers int `json:"server_group_members"`
    56  }
    57  
    58  // QuotaDetailSet represents details of both operational limits of compute
    59  // resources and the current usage of those resources.
    60  type QuotaDetailSet struct {
    61  	// ID is the tenant ID associated with this QuotaDetailSet.
    62  	ID string `json:"id"`
    63  
    64  	// FixedIPs is number of fixed ips allotted this QuotaDetailSet.
    65  	FixedIPs QuotaDetail `json:"fixed_ips"`
    66  
    67  	// FloatingIPs is number of floating ips allotted this QuotaDetailSet.
    68  	FloatingIPs QuotaDetail `json:"floating_ips"`
    69  
    70  	// InjectedFileContentBytes is the allowed bytes for each injected file.
    71  	InjectedFileContentBytes QuotaDetail `json:"injected_file_content_bytes"`
    72  
    73  	// InjectedFilePathBytes is allowed bytes for each injected file path.
    74  	InjectedFilePathBytes QuotaDetail `json:"injected_file_path_bytes"`
    75  
    76  	// InjectedFiles is the number of injected files allowed for each project.
    77  	InjectedFiles QuotaDetail `json:"injected_files"`
    78  
    79  	// KeyPairs is number of ssh keypairs.
    80  	KeyPairs QuotaDetail `json:"key_pairs"`
    81  
    82  	// MetadataItems is number of metadata items allowed for each instance.
    83  	MetadataItems QuotaDetail `json:"metadata_items"`
    84  
    85  	// RAM is megabytes allowed for each instance.
    86  	RAM QuotaDetail `json:"ram"`
    87  
    88  	// SecurityGroupRules is number of security group rules allowed for each
    89  	// security group.
    90  	SecurityGroupRules QuotaDetail `json:"security_group_rules"`
    91  
    92  	// SecurityGroups is the number of security groups allowed for each project.
    93  	SecurityGroups QuotaDetail `json:"security_groups"`
    94  
    95  	// Cores is number of instance cores allowed for each project.
    96  	Cores QuotaDetail `json:"cores"`
    97  
    98  	// Instances is number of instances allowed for each project.
    99  	Instances QuotaDetail `json:"instances"`
   100  
   101  	// ServerGroups is the number of ServerGroups allowed for the project.
   102  	ServerGroups QuotaDetail `json:"server_groups"`
   103  
   104  	// ServerGroupMembers is the number of members for each ServerGroup.
   105  	ServerGroupMembers QuotaDetail `json:"server_group_members"`
   106  }
   107  
   108  // QuotaDetail is a set of details about a single operational limit that allows
   109  // for control of compute usage.
   110  type QuotaDetail struct {
   111  	// InUse is the current number of provisioned/allocated resources of the
   112  	// given type.
   113  	InUse int `json:"in_use"`
   114  
   115  	// Reserved is a transitional state when a claim against quota has been made
   116  	// but the resource is not yet fully online.
   117  	Reserved int `json:"reserved"`
   118  
   119  	// Limit is the maximum number of a given resource that can be
   120  	// allocated/provisioned.  This is what "quota" usually refers to.
   121  	Limit int `json:"limit"`
   122  }
   123  
   124  // QuotaSetPage stores a single page of all QuotaSet results from a List call.
   125  type QuotaSetPage struct {
   126  	pagination.SinglePageBase
   127  }
   128  
   129  // IsEmpty determines whether or not a QuotaSetsetPage is empty.
   130  func (page QuotaSetPage) IsEmpty() (bool, error) {
   131  	if page.StatusCode == 204 {
   132  		return true, nil
   133  	}
   134  
   135  	ks, err := ExtractQuotaSets(page)
   136  	return len(ks) == 0, err
   137  }
   138  
   139  // ExtractQuotaSets interprets a page of results as a slice of QuotaSets.
   140  func ExtractQuotaSets(r pagination.Page) ([]QuotaSet, error) {
   141  	var s struct {
   142  		QuotaSets []QuotaSet `json:"quotas"`
   143  	}
   144  	err := (r.(QuotaSetPage)).ExtractInto(&s)
   145  	return s.QuotaSets, err
   146  }
   147  
   148  type quotaResult struct {
   149  	gophercloud.Result
   150  }
   151  
   152  // Extract is a method that attempts to interpret any QuotaSet resource response
   153  // as a QuotaSet struct.
   154  func (r quotaResult) Extract() (*QuotaSet, error) {
   155  	var s struct {
   156  		QuotaSet *QuotaSet `json:"quota_set"`
   157  	}
   158  	err := r.ExtractInto(&s)
   159  	return s.QuotaSet, err
   160  }
   161  
   162  // GetResult is the response from a Get operation. Call its Extract method to
   163  // interpret it as a QuotaSet.
   164  type GetResult struct {
   165  	quotaResult
   166  }
   167  
   168  // UpdateResult is the response from a Update operation. Call its Extract method
   169  // to interpret it as a QuotaSet.
   170  type UpdateResult struct {
   171  	quotaResult
   172  }
   173  
   174  // DeleteResult is the response from a Delete operation. Call its Extract method
   175  // to interpret it as a QuotaSet.
   176  type DeleteResult struct {
   177  	quotaResult
   178  }
   179  
   180  type quotaDetailResult struct {
   181  	gophercloud.Result
   182  }
   183  
   184  // GetDetailResult is the response from a Get operation. Call its Extract
   185  // method to interpret it as a QuotaSet.
   186  type GetDetailResult struct {
   187  	quotaDetailResult
   188  }
   189  
   190  // Extract is a method that attempts to interpret any QuotaDetailSet
   191  // resource response as a set of QuotaDetailSet structs.
   192  func (r quotaDetailResult) Extract() (QuotaDetailSet, error) {
   193  	var s struct {
   194  		QuotaData QuotaDetailSet `json:"quota_set"`
   195  	}
   196  	err := r.ExtractInto(&s)
   197  	return s.QuotaData, err
   198  }