github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/networking/v1/eips/results.go (about) 1 package eips 2 3 import ( 4 "github.com/chnsz/golangsdk" 5 "github.com/chnsz/golangsdk/pagination" 6 ) 7 8 // ApplyResult is a struct which represents the result of apply public ip 9 type ApplyResult struct { 10 golangsdk.Result 11 } 12 13 func (r ApplyResult) Extract() (PublicIp, error) { 14 var ipResp struct { 15 IP PublicIp `json:"publicip"` 16 OrderID string `json:"order_id"` 17 PublicipID string `json:"publicip_id"` 18 } 19 err := r.Result.ExtractInto(&ipResp) 20 if ipResp.PublicipID != "" { 21 ipResp.IP.ID = ipResp.PublicipID 22 } 23 if ipResp.OrderID != "" { 24 ipResp.IP.OrderID = ipResp.OrderID 25 } 26 27 return ipResp.IP, err 28 } 29 30 // PublicIp is a struct that represents a public ip 31 type PublicIp struct { 32 ID string `json:"id"` 33 Status string `json:"status"` 34 Type string `json:"type"` 35 PublicAddress string `json:"public_ip_address"` 36 PublicIpv6Address string `json:"public_ipv6_address"` 37 PrivateAddress string `json:"private_ip_address"` 38 PortID string `json:"port_id"` 39 TenantID string `json:"tenant_id"` 40 OrderID string `json:"order_id"` 41 CreateTime string `json:"create_time"` 42 BandwidthID string `json:"bandwidth_id"` 43 BandwidthName string `json:"bandwidth_name"` 44 BandwidthSize int `json:"bandwidth_size"` 45 BandwidthShareType string `json:"bandwidth_share_type"` 46 EnterpriseProjectID string `json:"enterprise_project_id"` 47 IpVersion int `json:"ip_version"` 48 Alias string `json:"alias"` 49 AllowShareBandwidthTypes []string `json:"allow_share_bandwidth_types"` 50 51 Profile Profile `json:"profile"` 52 Tags []string `json:"tags"` 53 } 54 55 type Profile struct { 56 UserID string `json:"user_id"` 57 ProductID string `json:"product_id"` 58 RegionID string `json:"region_id"` 59 OrderID string `json:"order_id"` 60 } 61 62 // GetResult is a return struct of get method 63 type GetResult struct { 64 golangsdk.Result 65 } 66 67 func (r GetResult) Extract() (PublicIp, error) { 68 var getResp struct { 69 IP PublicIp `json:"publicip"` 70 } 71 err := r.Result.ExtractInto(&getResp) 72 return getResp.IP, err 73 } 74 75 // DeleteResult is a struct of delete result 76 type DeleteResult struct { 77 golangsdk.ErrResult 78 } 79 80 // UpdateResult is a struct which contains the result of update method 81 type UpdateResult struct { 82 golangsdk.Result 83 } 84 85 func (r UpdateResult) Extract() (PublicIp, error) { 86 var ip PublicIp 87 err := r.Result.ExtractIntoStructPtr(&ip, "publicip") 88 return ip, err 89 } 90 91 type PublicIPPage struct { 92 pagination.LinkedPageBase 93 } 94 95 func (r PublicIPPage) NextPageURL() (string, error) { 96 publicIps, err := ExtractPublicIPs(r) 97 if err != nil { 98 return "", err 99 } 100 return r.WrapNextPageURL(publicIps[len(publicIps)-1].ID) 101 } 102 103 func ExtractPublicIPs(r pagination.Page) ([]PublicIp, error) { 104 var s struct { 105 PublicIPs []PublicIp `json:"publicips"` 106 } 107 err := r.(PublicIPPage).ExtractInto(&s) 108 return s.PublicIPs, err 109 } 110 111 // IsEmpty checks whether a NetworkPage struct is empty. 112 func (r PublicIPPage) IsEmpty() (bool, error) { 113 s, err := ExtractPublicIPs(r) 114 return len(s) == 0, err 115 } 116 117 type ChangeResult struct { 118 golangsdk.Result 119 } 120 121 func (r ChangeResult) Extract() (string, error) { 122 var s struct { 123 PublicIPIDs []string `json:"publicip_ids"` 124 OrderID string `json:"order_id"` 125 RequestID string `json:"request_id"` 126 } 127 err := r.ExtractInto(&s) 128 return s.OrderID, err 129 }