github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/dc/v3/interfaces/requests.go (about) 1 package interfaces 2 3 import ( 4 "github.com/chnsz/golangsdk" 5 ) 6 7 // CreateOpts is the structure used to create a virtual interface. 8 type CreateOpts struct { 9 // The type of the virtual interface. 10 Type string `json:"type" required:"true"` 11 // The VLAN for constom side. 12 Vlan int `json:"vlan" required:"true"` 13 // The ingress bandwidth size of the virtual interface. 14 Bandwidth int `json:"bandwidth" required:"true"` 15 // The ID of the virtual gateway to which the virtual interface is connected. 16 VgwId string `json:"vgw_id" required:"true"` 17 // The route mode of the virtual interface. 18 RouteMode string `json:"route_mode" required:"true"` 19 // The CIDR list of remote subnets. 20 RemoteEpGroup []string `json:"remote_ep_group" required:"true"` 21 // The CIDR list of subnets in service side. 22 ServiceEpGroup []string `json:"service_ep_group,omitempty"` 23 // Specifies the name of the virtual interface. 24 // The valid length is limited from 1 to 64, only chinese and english letters, digits, hyphens (-), underscores (_) 25 // and dots (.) are allowed. 26 // The name must start with a chinese or english letter, and the Chinese characters must be in **UTF-8** or 27 // **Unicode** format. 28 Name string `json:"name,omitempty"` 29 // Specifies the description of the virtual interface. 30 // The description contain a maximum of 128 characters and the angle brackets (< and >) are not allowed. 31 // Chinese characters must be in **UTF-8** or **Unicode** format. 32 Description string `json:"description,omitempty"` 33 // The ID of the direct connection associated with the virtual interface. 34 DirectConnectId string `json:"direct_connect_id,omitempty"` 35 // The service type of the virtual interface. 36 ServiceType string `json:"service_type,omitempty"` 37 // The IPv4 address of the virtual interface in cloud side. 38 LocalGatewayV4Ip string `json:"local_gateway_v4_ip,omitempty"` 39 // The IPv4 address of the virtual interface in client side. 40 RemoteGatewayV4Ip string `json:"remote_gateway_v4_ip,omitempty"` 41 // The address family type. 42 AddressFamily string `json:"address_family,omitempty"` 43 // The IPv6 address of the virtual interface in cloud side. 44 LocalGatewayV6Ip string `json:"local_gateway_v6_ip,omitempty"` 45 // The IPv6 address of the virtual interface in client side. 46 RemoteGatewayV6Ip string `json:"remote_gateway_v6_ip,omitempty"` 47 // The local BGP ASN in client side. 48 BgpAsn int `json:"bgp_asn,omitempty"` 49 // The (MD5) password for the local BGP. 50 BgpMd5 string `json:"bgp_md5,omitempty"` 51 // Whether to enable the Bidirectional Forwarding Detection (BFD) function. 52 EnableBfd bool `json:"enable_bfd,omitempty"` 53 // Whether to enable the Network Quality Analysis (NQA) function. 54 EnableNqa bool `json:"enable_nqa,omitempty"` 55 // The ID of the link aggregation group (LAG) associated with the virtual interface. 56 LagId string `json:"lag_id,omitempty"` 57 // The ID of the target tenant ID, which is used for cross tenant virtual interface creation. 58 ResourceTenantId string `json:"resource_tenant_id,omitempty"` 59 // The enterprise project ID to which the virtual interface belongs. 60 EnterpriseProjectId string `json:"enterprise_project_id,omitempty"` 61 } 62 63 var requestOpts = golangsdk.RequestOpts{ 64 MoreHeaders: map[string]string{"Content-Type": "application/json", "X-Language": "en-us"}, 65 } 66 67 // Create is a method used to create a virtual interface using given parameters. 68 func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*VirtualInterface, error) { 69 b, err := golangsdk.BuildRequestBody(opts, "virtual_interface") 70 if err != nil { 71 return nil, err 72 } 73 74 var r createResp 75 _, err = client.Post(rootURL(client), b, &r, &golangsdk.RequestOpts{ 76 MoreHeaders: requestOpts.MoreHeaders, 77 }) 78 return &r.VirtualInterface, err 79 } 80 81 // Get is a method used to obtain the details of the virtual interface using its ID. 82 func Get(client *golangsdk.ServiceClient, interfaceId string) (*VirtualInterface, error) { 83 var r getResp 84 _, err := client.Get(resourceURL(client, interfaceId), &r, &golangsdk.RequestOpts{ 85 MoreHeaders: requestOpts.MoreHeaders, 86 }) 87 return &r.VirtualInterface, err 88 } 89 90 // UpdateOpts is the structure used to update an existing virtual interface. 91 type UpdateOpts struct { 92 // Specifies the name of the virtual interface. 93 // The valid length is limited from 0 to 64, only chinese and english letters, digits, hyphens (-), underscores (_) 94 // and dots (.) are allowed. 95 // The name must start with a chinese or english letter, and the Chinese characters must be in **UTF-8** or 96 // **Unicode** format. 97 Name string `json:"name,omitempty"` 98 // Specifies the description of the virtual interface. 99 // The description contain a maximum of 128 characters and the angle brackets (< and >) are not allowed. 100 // Chinese characters must be in **UTF-8** or **Unicode** format. 101 Description *string `json:"description,omitempty"` 102 // The ingress bandwidth size of the virtual interface. 103 Bandwidth int `json:"bandwidth,omitempty"` 104 // The CIDR list of remote subnets. 105 RemoteEpGroup []string `json:"remote_ep_group,omitempty"` 106 // The CIDR list of subnets in service side. 107 ServiceEpGroup []string `json:"service_ep_group,omitempty"` 108 // Whether to enable the Bidirectional Forwarding Detection (BFD) function. 109 EnableBfd *bool `json:"enable_bfd,omitempty"` 110 // Whether to enable the Network Quality Analysis (NQA) function. 111 EnableNqa *bool `json:"enable_nqa,omitempty"` 112 // The status of the virtual interface to be changed. 113 Status string `json:"status,omitempty"` 114 } 115 116 // Update is a method used to update the specified virtual interface using given parameters. 117 func Update(client *golangsdk.ServiceClient, interfaceId string, opts UpdateOpts) (*VirtualInterface, error) { 118 b, err := golangsdk.BuildRequestBody(opts, "virtual_interface") 119 if err != nil { 120 return nil, err 121 } 122 123 var r updateResp 124 _, err = client.Put(resourceURL(client, interfaceId), b, &r, &golangsdk.RequestOpts{ 125 MoreHeaders: requestOpts.MoreHeaders, 126 }) 127 return &r.VirtualInterface, err 128 } 129 130 // Delete is a method used to remove an existing virtual interface using its ID. 131 func Delete(client *golangsdk.ServiceClient, interfaceId string) error { 132 _, err := client.Delete(resourceURL(client, interfaceId), &golangsdk.RequestOpts{ 133 MoreHeaders: requestOpts.MoreHeaders, 134 }) 135 return err 136 }