github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/compute/v2/extensions/attachinterfaces/requests.go (about) 1 package attachinterfaces 2 3 import ( 4 "github.com/huaweicloud/golangsdk" 5 "github.com/huaweicloud/golangsdk/pagination" 6 ) 7 8 // List makes a request against the nova API to list the server's interfaces. 9 func List(client *golangsdk.ServiceClient, serverID string) pagination.Pager { 10 return pagination.NewPager(client, listInterfaceURL(client, serverID), func(r pagination.PageResult) pagination.Page { 11 return InterfacePage{pagination.SinglePageBase(r)} 12 }) 13 } 14 15 // Get requests details on a single interface attachment by the server and port IDs. 16 func Get(client *golangsdk.ServiceClient, serverID, portID string) (r GetResult) { 17 _, r.Err = client.Get(getInterfaceURL(client, serverID, portID), &r.Body, &golangsdk.RequestOpts{ 18 OkCodes: []int{200}, 19 }) 20 return 21 } 22 23 // CreateOptsBuilder allows extensions to add additional parameters to the 24 // Create request. 25 type CreateOptsBuilder interface { 26 ToAttachInterfacesCreateMap() (map[string]interface{}, error) 27 } 28 29 // CreateOpts specifies parameters of a new interface attachment. 30 type CreateOpts struct { 31 // PortID is the ID of the port for which you want to create an interface. 32 // The NetworkID and PortID parameters are mutually exclusive. 33 // If you do not specify the PortID parameter, the OpenStack Networking API 34 // v2.0 allocates a port and creates an interface for it on the network. 35 PortID string `json:"port_id,omitempty"` 36 37 // NetworkID is the ID of the network for which you want to create an interface. 38 // The NetworkID and PortID parameters are mutually exclusive. 39 // If you do not specify the NetworkID parameter, the OpenStack Networking 40 // API v2.0 uses the network information cache that is associated with the instance. 41 NetworkID string `json:"net_id,omitempty"` 42 43 // Slice of FixedIPs. If you request a specific FixedIP address without a 44 // NetworkID, the request returns a Bad Request (400) response code. 45 // Note: this uses the FixedIP struct, but only the IPAddress field can be used. 46 FixedIPs []FixedIP `json:"fixed_ips,omitempty"` 47 } 48 49 // ToAttachInterfacesCreateMap constructs a request body from CreateOpts. 50 func (opts CreateOpts) ToAttachInterfacesCreateMap() (map[string]interface{}, error) { 51 return golangsdk.BuildRequestBody(opts, "interfaceAttachment") 52 } 53 54 // Create requests the creation of a new interface attachment on the server. 55 func Create(client *golangsdk.ServiceClient, serverID string, opts CreateOptsBuilder) (r CreateResult) { 56 b, err := opts.ToAttachInterfacesCreateMap() 57 if err != nil { 58 r.Err = err 59 return 60 } 61 _, r.Err = client.Post(createInterfaceURL(client, serverID), b, &r.Body, &golangsdk.RequestOpts{ 62 OkCodes: []int{200}, 63 }) 64 return 65 } 66 67 // Delete makes a request against the nova API to detach a single interface from the server. 68 // It needs server and port IDs to make a such request. 69 func Delete(client *golangsdk.ServiceClient, serverID, portID string) (r DeleteResult) { 70 _, r.Err = client.Delete(deleteInterfaceURL(client, serverID, portID), nil) 71 return 72 }