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