github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/ecs/v1/flavors/results.go (about)

     1  package flavors
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk/pagination"
     5  )
     6  
     7  type Flavor struct {
     8  	// Specifies the ID of ECS specifications.
     9  	ID string `json:"id"`
    10  
    11  	// Specifies the name of the ECS specifications.
    12  	Name string `json:"name"`
    13  
    14  	// Specifies the number of CPU cores in the ECS specifications.
    15  	Vcpus string `json:"vcpus"`
    16  
    17  	// Specifies the memory size (MB) in the ECS specifications.
    18  	Ram int64 `json:"ram"`
    19  
    20  	// Specifies the system disk size in the ECS specifications.
    21  	// The value 0 indicates that the disk size is not limited.
    22  	Disk string `json:"disk"`
    23  
    24  	// Specifies shortcut links for ECS flavors.
    25  	Links []Link `json:"links"`
    26  
    27  	// Specifies extended ECS specifications.
    28  	OsExtraSpecs OsExtraSpecs `json:"os_extra_specs"`
    29  
    30  	// Reserved
    31  	Swap string `json:"swap"`
    32  
    33  	// Reserved
    34  	FlvEphemeral int64 `json:"OS-FLV-EXT-DATA:ephemeral"`
    35  
    36  	// Reserved
    37  	FlvDisabled bool `json:"OS-FLV-DISABLED:disabled"`
    38  
    39  	// Reserved
    40  	RxtxFactor int64 `json:"rxtx_factor"`
    41  
    42  	// Reserved
    43  	RxtxQuota string `json:"rxtx_quota"`
    44  
    45  	// Reserved
    46  	RxtxCap string `json:"rxtx_cap"`
    47  
    48  	// Reserved
    49  	AccessIsPublic bool `json:"os-flavor-access:is_public"`
    50  }
    51  
    52  type Link struct {
    53  	// Specifies the shortcut link marker name.
    54  	Rel string `json:"rel"`
    55  
    56  	// Provides the corresponding shortcut link.
    57  	Href string `json:"href"`
    58  
    59  	// Specifies the shortcut link type.
    60  	Type string `json:"type"`
    61  }
    62  
    63  type OsExtraSpecs struct {
    64  	// Specifies the ECS specifications types
    65  	PerformanceType string `json:"ecs:performancetype"`
    66  
    67  	// Specifies the resource type.
    68  	ResourceType string `json:"resource_type"`
    69  
    70  	// Specifies the generation of an ECS type
    71  	Generation string `json:"ecs:generation"`
    72  
    73  	// Specifies a virtualization type
    74  	VirtualizationEnvTypes string `json:"ecs:virtualization_env_types"`
    75  
    76  	// Indicates whether the GPU is passthrough.
    77  	PciPassthroughEnableGpu string `json:"pci_passthrough:enable_gpu"`
    78  
    79  	// Indicates the technology used on the G1 and G2 ECSs,
    80  	// including GPU virtualization and GPU passthrough.
    81  	PciPassthroughGpuSpecs string `json:"pci_passthrough:gpu_specs"`
    82  
    83  	// Indicates the model and quantity of passthrough-enabled GPUs on P1 ECSs.
    84  	PciPassthroughAlias string `json:"pci_passthrough:alias"`
    85  
    86  	// Indicates the status of the flavor in region level.
    87  	OperationStatus string `json:"cond:operation:status"`
    88  
    89  	// Indicates the status of the flavor in az level.
    90  	OperationAz string `json:"cond:operation:az"`
    91  }
    92  
    93  // FlavorsPage is the page returned by a pager when traversing over a
    94  // collection of flavor.
    95  type FlavorsPage struct {
    96  	pagination.LinkedPageBase
    97  }
    98  
    99  // IsEmpty checks whether a FlavorsPage struct is empty.
   100  func (r FlavorsPage) IsEmpty() (bool, error) {
   101  	is, err := ExtractFlavors(r)
   102  	return len(is) == 0, err
   103  }
   104  
   105  // ExtractFlavors accepts a Page struct, specifically a FlavorsPage struct,
   106  // and extracts the elements into a slice of flavor structs. In other words,
   107  // a generic collection is mapped into a relevant slice.
   108  func ExtractFlavors(r pagination.Page) ([]Flavor, error) {
   109  	var s struct {
   110  		Flavors []Flavor `json:"flavors"`
   111  	}
   112  	err := (r.(FlavorsPage)).ExtractInto(&s)
   113  	return s.Flavors, err
   114  }