github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/bms/v2/servers/results.go (about) 1 package servers 2 3 import ( 4 "time" 5 6 "github.com/huaweicloud/golangsdk" 7 "github.com/huaweicloud/golangsdk/pagination" 8 ) 9 10 type commonResult struct { 11 golangsdk.Result 12 } 13 14 type ServerPage struct { 15 pagination.LinkedPageBase 16 } 17 18 // IsEmpty returns true if a page contains no Server results. 19 func (r ServerPage) IsEmpty() (bool, error) { 20 s, err := ExtractServers(r) 21 return len(s) == 0, err 22 } 23 24 // NextPageURL uses the response's embedded link reference to navigate to the 25 // next page of results. 26 func (r ServerPage) NextPageURL() (string, error) { 27 var s struct { 28 Links []golangsdk.Link `json:"servers_links"` 29 } 30 err := r.ExtractInto(&s) 31 if err != nil { 32 return "", err 33 } 34 return golangsdk.ExtractNextURL(s.Links) 35 } 36 37 // GetResult represents the result of a get operation. Call its Extract 38 // method to interpret it as a server. 39 type GetResult struct { 40 commonResult 41 } 42 43 // Extract is a function that accepts a result and extracts a server. 44 func (r commonResult) Extract() (*Server, error) { 45 var s struct { 46 Server *Server `json:"server"` 47 } 48 err := r.ExtractInto(&s) 49 return s.Server, err 50 } 51 52 // ExtractServers accepts a Page struct, specifically a ServerPage struct, 53 // and extracts the elements into a slice of Server structs. In other words, 54 // a generic collection is mapped into a relevant slice. 55 func ExtractServers(r pagination.Page) ([]Server, error) { 56 var s struct { 57 Servers []Server `json:"servers"` 58 } 59 err := (r.(ServerPage)).ExtractInto(&s) 60 return s.Servers, err 61 } 62 63 // Server exposes fields corresponding to a given server on the user's account. 64 type Server struct { 65 // ID uniquely identifies this server amongst all other servers, including those not accessible to the current tenant. 66 ID string `json:"id"` 67 // TenantID identifies the tenant owning this server resource. 68 TenantID string `json:"tenant_id"` 69 // UserID uniquely identifies the user account owning the tenant. 70 UserID string `json:"user_id"` 71 // Name contains the human-readable name for the server. 72 Name string `json:"name"` 73 // Status contains the current operational status of the server, such as IN_PROGRESS or ACTIVE. 74 Status string `json:"status"` 75 // Updated and Created contain ISO-8601 timestamps of when the state of the server last changed, and when it was created. 76 Updated time.Time `json:"updated"` 77 Created time.Time `json:"created"` 78 //Specifies the nova-compute status. 79 HostStatus string `json:"host_status"` 80 //Specifies the host ID of the BMS. 81 HostID string `json:"hostid"` 82 // Progress ranges from 0..100. 83 // A request made against the server completes only once Progress reaches 100. 84 Progress int `json:"progress"` 85 // AccessIPv4 and AccessIPv6 contain the IP addresses of the server, suitable for remote access for administration. 86 AccessIPv4 string `json:"accessIPv4"` 87 AccessIPv6 string `json:"accessIPv6"` 88 // Image refers to a JSON object, which itself indicates the OS image used to deploy the server. 89 Image Images `json:"image"` 90 // Flavor refers to a JSON object, which itself indicates the hardware configuration of the deployed server. 91 Flavor Flavor `json:"flavor"` 92 // Addresses includes a list of all IP addresses assigned to the server, keyed by pool. 93 Addresses map[string]interface{} `json:"addresses"` 94 // Metadata includes a list of all user-specified key-value pairs attached to the server. 95 Metadata map[string]string `json:"metadata"` 96 // Links includes HTTP references to the itself, useful for passing along to other APIs that might want a server reference. 97 Links []Links `json:"links"` 98 // KeyName indicates which public key was injected into the server on launch. 99 KeyName string `json:"key_name"` 100 // AdminPass will generally be empty. However, it will contain the administrative password chosen when provisioning a new server without a set AdminPass setting in the first place. 101 // Note that this is the ONLY time this field will be valid. 102 AdminPass string `json:"adminPass"` 103 // SecurityGroups includes the security groups that this instance has applied to it 104 SecurityGroups []SecurityGroups `json:"security_groups"` 105 //Specifies the BMS tag. 106 //Added in micro version 2.26. 107 Tags []string `json:"tags"` 108 //Specifies whether a BMS is locked 109 Locked bool `json:"locked"` 110 ConfigDrive string `json:"config_drive"` 111 //Specifies the AZ ID. This is an extended attribute. 112 AvailabilityZone string `json:"OS-EXT-AZ:availability_zone"` 113 //Specifies the disk configuration mode. This is an extended attribute. 114 DiskConfig string `json:"OS-DCF:diskConfig"` 115 //Specifies the name of a host on the hypervisor. 116 // It is an extended attribute provided by the Nova driver 117 HostName string `json:"OS-EXT-SRV-ATTR:hostname"` 118 //Specifies the server description. 119 Description string `json:"description"` 120 //Specifies the job status of the BMS. This is an extended attribute. 121 TaskState string `json:"OS-EXT-STS:task_state"` 122 //Specifies the power status of the BMS. This is an extended attribute 123 PowerState int `json:"OS-EXT-STS:power_state"` 124 //Specifies the UUID of the kernel image when the AMI image is used 125 KernelId string `json:"OS-EXT-SRV-ATTR:kernel_id"` 126 //Specifies the host name of the BMS. This is an extended attribute 127 Host string `json:"OS-EXT-SRV-ATTR:host"` 128 //Specifies the UUID of the Ramdisk image when the AMI image is used. 129 RamdiskId string `json:"OS-EXT-SRV-ATTR:ramdisk_id"` 130 //Specifies the BMS startup sequence in the batch BMS creation scenario. 131 Launch_index int `json:"OS-EXT-SRV-ATTR:launch_index"` 132 //Specifies the user data specified during BMS creation. 133 UserData string `json:"OS-EXT-SRV-ATTR:user_data"` 134 //Specifies the reserved BMS IDs in the batch BMS creation scenario. 135 ReservationID string `json:"OS-EXT-SRV-ATTR:reservation_id"` 136 //Specifies the device name of the BMS system disk 137 RootDevicName string `json:"OS-EXT-SRV-ATTR:root_device_name"` 138 //Specifies the name of a host on the hypervisor. 139 HypervisorHostName string `json:"OS-EXT-SRV-ATTR:hypervisor_hostname"` 140 //Specifies the BMS status. This is an extended attribute. 141 VMState string `json:"OS-EXT-STS:vm_state"` 142 //Specifies the BMS ID. This is an extended attribute. 143 InstanceName string `json:"OS-EXT-SRV-ATTR:instance_name"` 144 } 145 146 type SecurityGroups struct { 147 Name string `json:"name"` 148 } 149 150 type Flavor struct { 151 ID string `json:"id"` 152 Links []Links `json:"links"` 153 } 154 155 type Links struct { 156 Rel string `json:"rel"` 157 Href string `json:"href"` 158 } 159 160 type Images struct { 161 ID string `json:"id"` 162 Links []Links `json:"links"` 163 }