github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/vpcep/v1/endpoints/requests.go (about) 1 package endpoints 2 3 import ( 4 "net/http" 5 6 golangsdk "github.com/opentelekomcloud/gophertelekomcloud" 7 "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/tags" 8 "github.com/opentelekomcloud/gophertelekomcloud/pagination" 9 ) 10 11 type CreateOpts struct { 12 // The value must be the ID of the subnet created in the VPC specified by vpc_id and in the format of the UUID. 13 // This parameter is mandatory only if you create a VPC endpoint for connecting to an interface VPC endpoint service. 14 NetworkID string `json:"subnet_id,omitempty"` 15 16 // Specifies the ID of the VPC endpoint service. 17 ServiceID string `json:"endpoint_service_id" required:"true"` 18 19 // Specifies the ID of the VPC where the VPC endpoint is to be created. 20 RouterID string `json:"vpc_id" required:"true"` 21 22 // Specifies whether to create a private domain name. 23 EnableDNS bool `json:"enable_dns"` 24 25 // Lists the resource tags. 26 Tags []tags.ResourceTag `json:"tags,omitempty"` 27 28 // Lists the IDs of route tables. 29 // This parameter is mandatory only if you create a VPC endpoint for connecting to a `gateway` VPC endpoint service. 30 RouteTables []string `json:"routetables,omitempty"` 31 32 // Specifies the IP address for accessing the associated VPC endpoint service. 33 // This parameter is mandatory only if you create a VPC endpoint for connecting to an `interface` VPC endpoint service. 34 PortIP string `json:"port_ip,omitempty"` 35 36 // Specifies the whitelist for controlling access to the VPC endpoint. 37 // 38 // IPv4 addresses or CIDR blocks can be specified to control access when you create a VPC endpoint. 39 // 40 // This parameter is mandatory only when you create a VPC endpoint for connecting to an interface VPC endpoint service. 41 Whitelist []string `json:"whitelist,omitempty"` 42 43 // Specifies whether to enable access control. 44 EnableWhitelist *bool `json:"enable_whitelist,omitempty"` 45 } 46 47 type CreateOptsBuilder interface { 48 ToEndpointCreateMap() (map[string]interface{}, error) 49 } 50 51 func (opts CreateOpts) ToEndpointCreateMap() (map[string]interface{}, error) { 52 return golangsdk.BuildRequestBody(opts, "") 53 } 54 55 func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 56 b, err := opts.ToEndpointCreateMap() 57 if err != nil { 58 r.Err = err 59 return 60 } 61 _, r.Err = client.Post(baseURL(client), b, &r.Body, &golangsdk.RequestOpts{ 62 OkCodes: []int{http.StatusOK, http.StatusCreated}, 63 }) 64 return 65 } 66 67 func Get(client *golangsdk.ServiceClient, id string) (r GetResult) { 68 _, r.Err = client.Get(resourceURL(client, id), &r.Body, nil) 69 return 70 } 71 72 func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) { 73 _, r.Err = client.Delete(resourceURL(client, id), &golangsdk.RequestOpts{ 74 OkCodes: []int{http.StatusNoContent}, 75 }) 76 return 77 } 78 79 type ListOptsBuilder interface { 80 ToEndpointListQuery() (string, error) 81 } 82 83 type ListOpts struct { 84 ServiceName string `q:"endpoint_service_name"` 85 RouterID string `q:"vpc_id"` 86 ID string `q:"id"` 87 SortKey string `q:"sort_key"` 88 SortDir string `q:"sort_dir"` 89 } 90 91 func (opts ListOpts) ToEndpointListQuery() (string, error) { 92 q, err := golangsdk.BuildQueryString(opts) 93 if err != nil { 94 return "", err 95 } 96 return q.String(), nil 97 } 98 99 func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { 100 url := baseURL(client) 101 if opts != nil { 102 q, err := opts.ToEndpointListQuery() 103 if err != nil { 104 return pagination.Pager{Err: err} 105 } 106 url += q 107 } 108 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 109 return EndpointPage{OffsetPageBase: pagination.OffsetPageBase{PageResult: r}} 110 }) 111 } 112 113 func WaitForEndpointStatus(client *golangsdk.ServiceClient, id string, status Status, timeout int) error { 114 return golangsdk.WaitFor(timeout, func() (bool, error) { 115 ep, err := Get(client, id).Extract() 116 if err != nil { 117 if _, ok := err.(golangsdk.ErrDefault404); ok && status == "" { 118 return true, nil 119 } 120 return false, err 121 } 122 if ep.Status == status { 123 return true, nil 124 } 125 return false, nil 126 }) 127 }