github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/ecs/v1/cloudservers/results.go (about) 1 package cloudservers 2 3 import ( 4 "time" 5 6 "github.com/huaweicloud/golangsdk" 7 "github.com/huaweicloud/golangsdk/pagination" 8 ) 9 10 type cloudServerResult struct { 11 golangsdk.Result 12 } 13 14 type Flavor struct { 15 Disk string `json:"disk"` 16 Vcpus string `json:"vcpus"` 17 RAM string `json:"ram"` 18 ID string `json:"id"` 19 Name string `json:"name"` 20 } 21 22 // Image defines a image struct in details of a server. 23 type Image struct { 24 ID string `json:"id"` 25 } 26 27 type SysTags struct { 28 Key string `json:"key"` 29 Value string `json:"value"` 30 } 31 32 type OsSchedulerHints struct { 33 Group []string `json:"group"` 34 FaultDomain string `json:"fault_domain,omitempty"` 35 } 36 37 // Metadata is only used for method that requests details on a single server, by ID. 38 // Because metadata struct must be a map. 39 type Metadata struct { 40 ChargingMode string `json:"charging_mode"` 41 OrderID string `json:"metering.order_id"` 42 ProductID string `json:"metering.product_id"` 43 VpcID string `json:"vpc_id"` 44 EcmResStatus string `json:"EcmResStatus"` 45 ImageID string `json:"metering.image_id"` 46 Imagetype string `json:"metering.imagetype"` 47 Resourcespeccode string `json:"metering.resourcespeccode"` 48 ImageName string `json:"image_name"` 49 OsBit string `json:"os_bit"` 50 LockCheckEndpoint string `json:"lock_check_endpoint"` 51 LockSource string `json:"lock_source"` 52 LockSourceID string `json:"lock_source_id"` 53 LockScene string `json:"lock_scene"` 54 VirtualEnvType string `json:"virtual_env_type"` 55 AgencyName string `json:"agency_name"` 56 } 57 58 type Address struct { 59 Version string `json:"version"` 60 Addr string `json:"addr"` 61 MacAddr string `json:"OS-EXT-IPS-MAC:mac_addr"` 62 PortID string `json:"OS-EXT-IPS:port_id"` 63 Type string `json:"OS-EXT-IPS:type"` 64 } 65 66 type VolumeAttached struct { 67 ID string `json:"id"` 68 DeleteOnTermination string `json:"delete_on_termination"` 69 BootIndex string `json:"bootIndex"` 70 Device string `json:"device"` 71 } 72 73 type SecurityGroups struct { 74 Name string `json:"name"` 75 ID string `json:"id"` 76 } 77 78 // CloudServer is only used for method that requests details on a single server, by ID. 79 // Because metadata struct must be a map. 80 type CloudServer struct { 81 Status string `json:"status"` 82 Updated time.Time `json:"updated"` 83 HostID string `json:"hostId"` 84 Addresses map[string][]Address `json:"addresses"` 85 ID string `json:"id"` 86 Name string `json:"name"` 87 AccessIPv4 string `json:"accessIPv4"` 88 AccessIPv6 string `json:"accessIPv6"` 89 Created time.Time `json:"created"` 90 Tags []string `json:"tags"` 91 Description string `json:"description"` 92 Locked *bool `json:"locked"` 93 ConfigDrive string `json:"config_drive"` 94 TenantID string `json:"tenant_id"` 95 UserID string `json:"user_id"` 96 HostStatus string `json:"host_status"` 97 EnterpriseProjectID string `json:"enterprise_project_id"` 98 SysTags []SysTags `json:"sys_tags"` 99 Flavor Flavor `json:"flavor"` 100 Metadata Metadata `json:"metadata"` 101 SecurityGroups []SecurityGroups `json:"security_groups"` 102 KeyName string `json:"key_name"` 103 Image Image `json:"image"` 104 Progress *int `json:"progress"` 105 PowerState *int `json:"OS-EXT-STS:power_state"` 106 VMState string `json:"OS-EXT-STS:vm_state"` 107 TaskState string `json:"OS-EXT-STS:task_state"` 108 DiskConfig string `json:"OS-DCF:diskConfig"` 109 AvailabilityZone string `json:"OS-EXT-AZ:availability_zone"` 110 LaunchedAt string `json:"OS-SRV-USG:launched_at"` 111 TerminatedAt string `json:"OS-SRV-USG:terminated_at"` 112 RootDeviceName string `json:"OS-EXT-SRV-ATTR:root_device_name"` 113 RamdiskID string `json:"OS-EXT-SRV-ATTR:ramdisk_id"` 114 KernelID string `json:"OS-EXT-SRV-ATTR:kernel_id"` 115 LaunchIndex *int `json:"OS-EXT-SRV-ATTR:launch_index"` 116 ReservationID string `json:"OS-EXT-SRV-ATTR:reservation_id"` 117 Hostname string `json:"OS-EXT-SRV-ATTR:hostname"` 118 UserData string `json:"OS-EXT-SRV-ATTR:user_data"` 119 Host string `json:"OS-EXT-SRV-ATTR:host"` 120 InstanceName string `json:"OS-EXT-SRV-ATTR:instance_name"` 121 HypervisorHostname string `json:"OS-EXT-SRV-ATTR:hypervisor_hostname"` 122 VolumeAttached []VolumeAttached `json:"os-extended-volumes:volumes_attached"` 123 OsSchedulerHints OsSchedulerHints `json:"os:scheduler_hints"` 124 } 125 126 // NewCloudServer defines the response from details on a single server, by ID. 127 type NewCloudServer struct { 128 CloudServer 129 Metadata map[string]string `json:"metadata"` 130 } 131 132 // GetResult is the response from a Get operation. Call its Extract 133 // method to interpret it as a Server. 134 type GetResult struct { 135 cloudServerResult 136 } 137 138 func (r GetResult) Extract() (*CloudServer, error) { 139 var s struct { 140 Server *CloudServer `json:"server"` 141 } 142 err := r.ExtractInto(&s) 143 return s.Server, err 144 } 145 146 // ServerPage abstracts the raw results of making a List() request against 147 // the API. 148 type ServerPage struct { 149 pagination.LinkedPageBase 150 } 151 152 // IsEmpty returns true if a page contains no Server results. 153 func (r ServerPage) IsEmpty() (bool, error) { 154 s, err := ExtractServers(r) 155 return len(s) == 0, err 156 } 157 158 // NextPageURL uses the response's embedded link reference to navigate to the 159 // next page of results. 160 func (r ServerPage) NextPageURL() (string, error) { 161 var s struct { 162 Links []golangsdk.Link `json:"servers_links"` 163 } 164 err := r.ExtractInto(&s) 165 if err != nil { 166 return "", err 167 } 168 return golangsdk.ExtractNextURL(s.Links) 169 } 170 171 // ExtractServers interprets the results of a single page from a List() call, 172 // producing a slice of CloudServer entities. 173 func ExtractServers(r pagination.Page) ([]CloudServer, error) { 174 var s struct { 175 Servers []CloudServer `json:"servers"` 176 } 177 178 err := (r.(ServerPage)).ExtractInto(&s) 179 return s.Servers, err 180 }