github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/vpcep/v1/services/results.go (about) 1 package services 2 3 import ( 4 golangsdk "github.com/opentelekomcloud/gophertelekomcloud" 5 "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/tags" 6 "github.com/opentelekomcloud/gophertelekomcloud/pagination" 7 ) 8 9 type commonResult struct { 10 golangsdk.Result 11 } 12 13 type CreateResult struct { 14 commonResult 15 } 16 17 type GetResult struct { 18 commonResult 19 } 20 21 type ErrorParameters struct { 22 ErrorCode string 23 ErrorMessage string 24 } 25 26 type Status string 27 type ServerType string 28 type ServiceType string 29 30 const ( 31 StatusCreating Status = "creating" 32 StatusAvailable Status = "available" 33 StatusFailed Status = "failed" 34 StatusDeleting Status = "deleting" 35 StatusDeleted Status = "" // this is a special status for missing LB 36 37 ServerTypeVM ServerType = "VM" 38 ServerTypeVIP ServerType = "VIP" 39 ServerTypeLB ServerType = "LB" 40 41 ServiceTypeInterface ServiceType = "interface" 42 ServiceTypeGateway ServiceType = "gateway" 43 ) 44 45 type Service struct { 46 ID string `json:"id"` 47 PortID string `json:"port_id"` 48 VIPPortID string `json:"vip_port_id"` 49 ServiceName string `json:"service_name"` 50 ServiceType string `json:"service_type"` 51 ServerType ServerType `json:"server_type"` 52 RouterID string `json:"vpc_id"` 53 PoolID string `json:"pool_id"` 54 ApprovalEnabled bool `json:"approval_enabled"` 55 Status Status `json:"status"` 56 CreatedAt string `json:"created_at"` 57 UpdatedAt string `json:"updated_at"` 58 ProjectID string `json:"project_id"` 59 CIDRType string `json:"cidr_type"` // CIDRType returned only in Create 60 Ports []PortMapping `json:"ports"` 61 TCPProxy string `json:"tcp_proxy"` 62 Tags []tags.ResourceTag `json:"tags"` 63 64 // ConnectionCount is set in `Get` and `List` only 65 ConnectionCount int `json:"connection_count"` 66 // Error is set in `Get` and `List` only 67 Error []ErrorParameters `json:"error"` 68 } 69 70 func (r commonResult) Extract() (*Service, error) { 71 srv := &Service{} 72 err := r.ExtractInto(srv) 73 if err != nil { 74 return nil, err 75 } 76 return srv, nil 77 } 78 79 type ServicePage struct { 80 pagination.OffsetPageBase 81 } 82 83 func ExtractServices(p pagination.Page) ([]Service, error) { 84 var srv []Service 85 err := (p.(ServicePage)).ExtractIntoSlicePtr(&srv, "endpoint_services") 86 return srv, err 87 } 88 89 type PublicService struct { 90 ID string `json:"id"` 91 Owner string `json:"owner"` 92 ServiceName string `json:"service_name"` 93 ServiceType ServiceType `json:"service_type"` 94 CreatedAt string `json:"created_at"` 95 IsCharge bool `json:"is_charge"` 96 } 97 98 func ExtractPublicServices(p pagination.Page) ([]PublicService, error) { 99 var srv []PublicService 100 err := (p.(ServicePage)).ExtractIntoSlicePtr(&srv, "endpoint_services") 101 return srv, err 102 } 103 104 func (p ServicePage) IsEmpty() (bool, error) { 105 srv, err := ExtractServices(p) 106 if err != nil { 107 return false, err 108 } 109 return len(srv) == 0, err 110 } 111 112 type UpdateResult struct { 113 commonResult 114 } 115 116 type DeleteResult struct { 117 golangsdk.ErrResult 118 }