github.com/gophercloud/gophercloud@v1.11.0/openstack/networking/v2/extensions/qos/rules/results.go (about)

     1  package rules
     2  
     3  import (
     4  	"github.com/gophercloud/gophercloud"
     5  	"github.com/gophercloud/gophercloud/pagination"
     6  )
     7  
     8  type commonResult struct {
     9  	gophercloud.Result
    10  }
    11  
    12  // Extract is a function that accepts a result and extracts a BandwidthLimitRule.
    13  func (r commonResult) ExtractBandwidthLimitRule() (*BandwidthLimitRule, error) {
    14  	var s struct {
    15  		BandwidthLimitRule *BandwidthLimitRule `json:"bandwidth_limit_rule"`
    16  	}
    17  	err := r.ExtractInto(&s)
    18  	return s.BandwidthLimitRule, err
    19  }
    20  
    21  // GetBandwidthLimitRuleResult represents the result of a Get operation. Call its Extract
    22  // method to interpret it as a BandwidthLimitRule.
    23  type GetBandwidthLimitRuleResult struct {
    24  	commonResult
    25  }
    26  
    27  // CreateBandwidthLimitRuleResult represents the result of a Create operation. Call its Extract
    28  // method to interpret it as a BandwidthLimitRule.
    29  type CreateBandwidthLimitRuleResult struct {
    30  	commonResult
    31  }
    32  
    33  // UpdateBandwidthLimitRuleResult represents the result of a Update operation. Call its Extract
    34  // method to interpret it as a BandwidthLimitRule.
    35  type UpdateBandwidthLimitRuleResult struct {
    36  	commonResult
    37  }
    38  
    39  // DeleteBandwidthLimitRuleResult represents the result of a Delete operation. Call its Extract
    40  // method to interpret it as a BandwidthLimitRule.
    41  type DeleteBandwidthLimitRuleResult struct {
    42  	gophercloud.ErrResult
    43  }
    44  
    45  // BandwidthLimitRule represents a QoS policy rule to set bandwidth limits.
    46  type BandwidthLimitRule struct {
    47  	// ID is a unique ID of the policy.
    48  	ID string `json:"id"`
    49  
    50  	// TenantID is the ID of the Identity project.
    51  	TenantID string `json:"tenant_id"`
    52  
    53  	// MaxKBps is a maximum kilobits per second.
    54  	MaxKBps int `json:"max_kbps"`
    55  
    56  	// MaxBurstKBps is a maximum burst size in kilobits.
    57  	MaxBurstKBps int `json:"max_burst_kbps"`
    58  
    59  	// Direction represents the direction of traffic.
    60  	Direction string `json:"direction"`
    61  
    62  	// Tags optionally set via extensions/attributestags.
    63  	Tags []string `json:"tags"`
    64  }
    65  
    66  // BandwidthLimitRulePage stores a single page of BandwidthLimitRules from a List() API call.
    67  type BandwidthLimitRulePage struct {
    68  	pagination.LinkedPageBase
    69  }
    70  
    71  // IsEmpty checks whether a BandwidthLimitRulePage is empty.
    72  func (r BandwidthLimitRulePage) IsEmpty() (bool, error) {
    73  	if r.StatusCode == 204 {
    74  		return true, nil
    75  	}
    76  
    77  	is, err := ExtractBandwidthLimitRules(r)
    78  	return len(is) == 0, err
    79  }
    80  
    81  // ExtractBandwidthLimitRules accepts a BandwidthLimitRulePage, and extracts the elements into a slice of
    82  // BandwidthLimitRules.
    83  func ExtractBandwidthLimitRules(r pagination.Page) ([]BandwidthLimitRule, error) {
    84  	var s []BandwidthLimitRule
    85  	err := ExtractBandwidthLimitRulesInto(r, &s)
    86  	return s, err
    87  }
    88  
    89  // ExtractBandwidthLimitRulesInto extracts the elements into a slice of RBAC Policy structs.
    90  func ExtractBandwidthLimitRulesInto(r pagination.Page, v interface{}) error {
    91  	return r.(BandwidthLimitRulePage).Result.ExtractIntoSlicePtr(v, "bandwidth_limit_rules")
    92  }
    93  
    94  // Extract is a function that accepts a result and extracts a DSCPMarkingRule.
    95  func (r commonResult) ExtractDSCPMarkingRule() (*DSCPMarkingRule, error) {
    96  	var s struct {
    97  		DSCPMarkingRule *DSCPMarkingRule `json:"dscp_marking_rule"`
    98  	}
    99  	err := r.ExtractInto(&s)
   100  	return s.DSCPMarkingRule, err
   101  }
   102  
   103  // GetDSCPMarkingRuleResult represents the result of a Get operation. Call its Extract
   104  // method to interpret it as a DSCPMarkingRule.
   105  type GetDSCPMarkingRuleResult struct {
   106  	commonResult
   107  }
   108  
   109  // CreateDSCPMarkingRuleResult represents the result of a Create operation. Call its Extract
   110  // method to interpret it as a DSCPMarkingRule.
   111  type CreateDSCPMarkingRuleResult struct {
   112  	commonResult
   113  }
   114  
   115  // UpdateDSCPMarkingRuleResult represents the result of a Update operation. Call its Extract
   116  // method to interpret it as a DSCPMarkingRule.
   117  type UpdateDSCPMarkingRuleResult struct {
   118  	commonResult
   119  }
   120  
   121  // DeleteDSCPMarkingRuleResult represents the result of a Delete operation. Call its Extract
   122  // method to interpret it as a DSCPMarkingRule.
   123  type DeleteDSCPMarkingRuleResult struct {
   124  	gophercloud.ErrResult
   125  }
   126  
   127  // DSCPMarkingRule represents a QoS policy rule to set DSCP marking.
   128  type DSCPMarkingRule struct {
   129  	// ID is a unique ID of the policy.
   130  	ID string `json:"id"`
   131  
   132  	// TenantID is the ID of the Identity project.
   133  	TenantID string `json:"tenant_id"`
   134  
   135  	// DSCPMark contains DSCP mark value.
   136  	DSCPMark int `json:"dscp_mark"`
   137  
   138  	// Tags optionally set via extensions/attributestags.
   139  	Tags []string `json:"tags"`
   140  }
   141  
   142  // DSCPMarkingRulePage stores a single page of DSCPMarkingRules from a List() API call.
   143  type DSCPMarkingRulePage struct {
   144  	pagination.LinkedPageBase
   145  }
   146  
   147  // IsEmpty checks whether a DSCPMarkingRulePage is empty.
   148  func (r DSCPMarkingRulePage) IsEmpty() (bool, error) {
   149  	if r.StatusCode == 204 {
   150  		return true, nil
   151  	}
   152  
   153  	is, err := ExtractDSCPMarkingRules(r)
   154  	return len(is) == 0, err
   155  }
   156  
   157  // ExtractDSCPMarkingRules accepts a DSCPMarkingRulePage, and extracts the elements into a slice of
   158  // DSCPMarkingRules.
   159  func ExtractDSCPMarkingRules(r pagination.Page) ([]DSCPMarkingRule, error) {
   160  	var s []DSCPMarkingRule
   161  	err := ExtractDSCPMarkingRulesInto(r, &s)
   162  	return s, err
   163  }
   164  
   165  // ExtractDSCPMarkingRulesInto extracts the elements into a slice of RBAC Policy structs.
   166  func ExtractDSCPMarkingRulesInto(r pagination.Page, v interface{}) error {
   167  	return r.(DSCPMarkingRulePage).Result.ExtractIntoSlicePtr(v, "dscp_marking_rules")
   168  }
   169  
   170  // Extract is a function that accepts a result and extracts a BandwidthLimitRule.
   171  func (r commonResult) ExtractMinimumBandwidthRule() (*MinimumBandwidthRule, error) {
   172  	var s struct {
   173  		MinimumBandwidthRule *MinimumBandwidthRule `json:"minimum_bandwidth_rule"`
   174  	}
   175  	err := r.ExtractInto(&s)
   176  	return s.MinimumBandwidthRule, err
   177  }
   178  
   179  // GetMinimumBandwidthRuleResult represents the result of a Get operation. Call its Extract
   180  // method to interpret it as a MinimumBandwidthRule.
   181  type GetMinimumBandwidthRuleResult struct {
   182  	commonResult
   183  }
   184  
   185  // CreateMinimumBandwidthRuleResult represents the result of a Create operation. Call its Extract
   186  // method to interpret it as a MinimumBandwidthtRule.
   187  type CreateMinimumBandwidthRuleResult struct {
   188  	commonResult
   189  }
   190  
   191  // UpdateMinimumBandwidthRuleResult represents the result of a Update operation. Call its Extract
   192  // method to interpret it as a MinimumBandwidthRule.
   193  type UpdateMinimumBandwidthRuleResult struct {
   194  	commonResult
   195  }
   196  
   197  // DeleteMinimumBandwidthRuleResult represents the result of a Delete operation. Call its Extract
   198  // method to interpret it as a MinimumBandwidthRule.
   199  type DeleteMinimumBandwidthRuleResult struct {
   200  	gophercloud.ErrResult
   201  }
   202  
   203  // MinimumBandwidthRule represents a QoS policy rule to set minimum bandwidth.
   204  type MinimumBandwidthRule struct {
   205  	// ID is a unique ID of the rule.
   206  	ID string `json:"id"`
   207  
   208  	// TenantID is the ID of the Identity project.
   209  	TenantID string `json:"tenant_id"`
   210  
   211  	// MaxKBps is a maximum kilobits per second.
   212  	MinKBps int `json:"min_kbps"`
   213  
   214  	// Direction represents the direction of traffic.
   215  	Direction string `json:"direction"`
   216  
   217  	// Tags optionally set via extensions/attributestags.
   218  	Tags []string `json:"tags"`
   219  }
   220  
   221  // MinimumBandwidthRulePage stores a single page of MinimumBandwidthRules from a List() API call.
   222  type MinimumBandwidthRulePage struct {
   223  	pagination.LinkedPageBase
   224  }
   225  
   226  // IsEmpty checks whether a MinimumBandwidthRulePage is empty.
   227  func (r MinimumBandwidthRulePage) IsEmpty() (bool, error) {
   228  	if r.StatusCode == 204 {
   229  		return true, nil
   230  	}
   231  
   232  	is, err := ExtractMinimumBandwidthRules(r)
   233  	return len(is) == 0, err
   234  }
   235  
   236  // ExtractMinimumBandwidthRules accepts a MinimumBandwidthRulePage, and extracts the elements into a slice of
   237  // MinimumBandwidthRules.
   238  func ExtractMinimumBandwidthRules(r pagination.Page) ([]MinimumBandwidthRule, error) {
   239  	var s []MinimumBandwidthRule
   240  	err := ExtractMinimumBandwidthRulesInto(r, &s)
   241  	return s, err
   242  }
   243  
   244  // ExtractMinimumBandwidthRulesInto extracts the elements into a slice of RBAC Policy structs.
   245  func ExtractMinimumBandwidthRulesInto(r pagination.Page, v interface{}) error {
   246  	return r.(MinimumBandwidthRulePage).Result.ExtractIntoSlicePtr(v, "minimum_bandwidth_rules")
   247  }