github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/dc/v3/gateways/requests.go (about) 1 package gateways 2 3 import ( 4 "github.com/chnsz/golangsdk" 5 "github.com/chnsz/golangsdk/openstack/common/tags" 6 ) 7 8 // CreateOpts is the structure used to create a virtual gateway. 9 type CreateOpts struct { 10 // The ID of the VPC connected to the virtual gateway. 11 VpcId string `json:"vpc_id" required:"true"` 12 // The list of IPv4 subnets from the virtual gateway to access cloud services, which is usually the CIDR block of 13 // the VPC. 14 LocalEpGroup []string `json:"local_ep_group" required:"true"` 15 // The list of IPv6 subnets from the virtual gateway to access cloud services, which is usually the CIDR block of 16 // the VPC. 17 LocalEpGroupIpv6 []string `json:"local_ep_group_ipv6,omitempty"` 18 // Specifies the name of the virtual gateway. 19 // The valid length is limited from 0 to 64, only chinese and english letters, digits, hyphens (-), underscores (_) 20 // and dots (.) are allowed. 21 // The name must start with a chinese or english letter, and the Chinese characters must be in **UTF-8** or 22 // **Unicode** format. 23 Name string `json:"name,omitempty"` 24 // Specifies the description of the virtual gateway. 25 // The description contain a maximum of 64 characters and the angle brackets (< and >) are not allowed. 26 // Chinese characters must be in **UTF-8** or **Unicode** format. 27 Description string `json:"description,omitempty"` 28 // The local BGP ASN of the virtual gateway. 29 BgpAsn int `json:"bgp_asn,omitempty"` 30 // The enterprise project ID to which the virtual gateway belongs. 31 EnterpriseProjectId string `json:"enterprise_project_id,omitempty"` 32 // The key/value pairs to associate with the virtual gateway. 33 Tags []tags.ResourceTag `json:"tags,omitempty"` 34 } 35 36 var requestOpts = golangsdk.RequestOpts{ 37 MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"}, 38 } 39 40 // Create is a method used to create a virtual gateway using given parameters. 41 func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*VirtualGateway, error) { 42 b, err := golangsdk.BuildRequestBody(opts, "virtual_gateway") 43 if err != nil { 44 return nil, err 45 } 46 47 var r createResp 48 _, err = client.Post(rootURL(client), b, &r, &golangsdk.RequestOpts{ 49 MoreHeaders: requestOpts.MoreHeaders, 50 }) 51 return &r.VirtualGateway, err 52 } 53 54 // UpdateOpts is the structure used to update the configuration of the virtual gateway. 55 type UpdateOpts struct { 56 // The list of IPv4 subnets from the virtual gateway to access cloud services, which is usually the CIDR block of 57 // the VPC. 58 LocalEpGroup []string `json:"local_ep_group" required:"true"` 59 // The list of IPv6 subnets from the virtual gateway to access cloud services, which is usually the CIDR block of 60 // the VPC. 61 LocalEpGroupIpv6 []string `json:"local_ep_group_ipv6,omitempty"` 62 // Specifies the name of the virtual gateway. 63 // The valid length is limited from 0 to 64, only chinese and english letters, digits, hyphens (-), underscores (_) 64 // and dots (.) are allowed. 65 // The name must start with a chinese or english letter, and the Chinese characters must be in **UTF-8** or 66 // **Unicode** format. 67 Name string `json:"name,omitempty"` 68 // Specifies the description of the virtual gateway. 69 // The description contain a maximum of 64 characters and the angle brackets (< and >) are not allowed. 70 // Chinese characters must be in **UTF-8** or **Unicode** format. 71 Description *string `json:"description,omitempty"` 72 } 73 74 // Update is a method used to update the specified virtual gateway using given parameters. 75 func Update(client *golangsdk.ServiceClient, gatewayId string, opts UpdateOpts) (*VirtualGateway, error) { 76 b, err := golangsdk.BuildRequestBody(opts, "virtual_gateway") 77 if err != nil { 78 return nil, err 79 } 80 81 var r createResp 82 _, err = client.Put(resourceURL(client, gatewayId), b, &r, &golangsdk.RequestOpts{ 83 MoreHeaders: requestOpts.MoreHeaders, 84 }) 85 return &r.VirtualGateway, err 86 } 87 88 // Get is a method used to obtain the details of the virtual gateway using its ID. 89 func Get(client *golangsdk.ServiceClient, gatewayId string) (*VirtualGateway, error) { 90 var r getResp 91 _, err := client.Get(resourceURL(client, gatewayId), &r, &golangsdk.RequestOpts{ 92 MoreHeaders: requestOpts.MoreHeaders, 93 }) 94 return &r.VirtualGateway, err 95 } 96 97 // Delete is a method used to remove an existing virtual gateway using its ID. 98 func Delete(client *golangsdk.ServiceClient, gatewayId string) error { 99 _, err := client.Delete(resourceURL(client, gatewayId), &golangsdk.RequestOpts{ 100 MoreHeaders: requestOpts.MoreHeaders, 101 }) 102 return err 103 }