github.com/leeclow-ops/gophercloud@v1.2.1/openstack/identity/v3/limits/results.go (about)

     1  package limits
     2  
     3  import (
     4  	"github.com/leeclow-ops/gophercloud"
     5  	"github.com/leeclow-ops/gophercloud/pagination"
     6  )
     7  
     8  // A model describing the configured enforcement model used by the deployment.
     9  type EnforcementModel struct {
    10  	// The name of the enforcement model.
    11  	Name string `json:"name"`
    12  
    13  	// A short description of the enforcement model used.
    14  	Description string `json:"description"`
    15  }
    16  
    17  // EnforcementModelResult is the response from a GetEnforcementModel operation. Call its Extract method
    18  // to interpret it as a EnforcementModel.
    19  type EnforcementModelResult struct {
    20  	gophercloud.Result
    21  }
    22  
    23  // Extract interprets EnforcementModelResult as a EnforcementModel.
    24  func (r EnforcementModelResult) Extract() (*EnforcementModel, error) {
    25  	var out struct {
    26  		Model *EnforcementModel `json:"model"`
    27  	}
    28  	err := r.ExtractInto(&out)
    29  	return out.Model, err
    30  }
    31  
    32  // A limit is the limit that override the registered limit for each project.
    33  type Limit struct {
    34  	// ID is the unique ID of the limit.
    35  	ID string `json:"id"`
    36  
    37  	// RegionID is the ID of the region where the limit is applied.
    38  	RegionID string `json:"region_id"`
    39  
    40  	// ProjectID is the ID of the project where the limit is applied.
    41  	ProjectID string `json:"project_id"`
    42  
    43  	// DomainID is the ID of the domain where the limit is applied.
    44  	DomainID string `json:"domain_id"`
    45  
    46  	// ServiceID is the ID of the service where the limit is applied.
    47  	ServiceID string `json:"service_id"`
    48  
    49  	// Description of the limit.
    50  	Description string `json:"description"`
    51  
    52  	// ResourceName is the name of the resource that the limit is applied to.
    53  	ResourceName string `json:"resource_name"`
    54  
    55  	// ResourceLimit is the override limit.
    56  	ResourceLimit int `json:"resource_limit"`
    57  
    58  	// Links contains referencing links to the limit.
    59  	Links map[string]interface{} `json:"links"`
    60  }
    61  
    62  // A LimitsOutput is an array of limits returned by List and BatchCreate operations
    63  type LimitsOutput struct {
    64  	Limits []Limit `json:"limits"`
    65  }
    66  
    67  // LimitPage is a single page of Limit results.
    68  type LimitPage struct {
    69  	pagination.LinkedPageBase
    70  }
    71  
    72  // CreateResult is the response from a Create operation. Call its Extract method
    73  // to interpret it as a Limits.
    74  type CreateResult struct {
    75  	gophercloud.Result
    76  }
    77  
    78  // IsEmpty determines whether or not a page of Limits contains any results.
    79  func (r LimitPage) IsEmpty() (bool, error) {
    80  	if r.StatusCode == 204 {
    81  		return true, nil
    82  	}
    83  
    84  	limits, err := ExtractLimits(r)
    85  	return len(limits) == 0, err
    86  }
    87  
    88  // NextPageURL extracts the "next" link from the links section of the result.
    89  func (r LimitPage) NextPageURL() (string, error) {
    90  	var s struct {
    91  		Links struct {
    92  			Next     string `json:"next"`
    93  			Previous string `json:"previous"`
    94  		} `json:"links"`
    95  	}
    96  	err := r.ExtractInto(&s)
    97  	if err != nil {
    98  		return "", err
    99  	}
   100  	return s.Links.Next, err
   101  }
   102  
   103  // ExtractLimits returns a slice of Limits contained in a single page of
   104  // results.
   105  func ExtractLimits(r pagination.Page) ([]Limit, error) {
   106  	var out LimitsOutput
   107  	err := (r.(LimitPage)).ExtractInto(&out)
   108  	return out.Limits, err
   109  }
   110  
   111  // Extract interprets CreateResult as slice of Limits.
   112  func (r CreateResult) Extract() ([]Limit, error) {
   113  	var out LimitsOutput
   114  	err := r.ExtractInto(&out)
   115  	return out.Limits, err
   116  }