github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/extensions/portsbinding/requests.go (about)

     1  package portsbinding
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk/openstack/networking/v2/ports"
     5  )
     6  
     7  // CreateOptsExt adds port binding options to the base ports.CreateOpts.
     8  type CreateOptsExt struct {
     9  	// CreateOptsBuilder is the interface options structs have to satisfy in order
    10  	// to be used in the main Create operation in this package.
    11  	ports.CreateOptsBuilder
    12  
    13  	// The ID of the host where the port is allocated
    14  	HostID string `json:"binding:host_id,omitempty"`
    15  
    16  	// The virtual network interface card (vNIC) type that is bound to the
    17  	// neutron port.
    18  	VNICType string `json:"binding:vnic_type,omitempty"`
    19  
    20  	// A dictionary that enables the application running on the specified
    21  	// host to pass and receive virtual network interface (VIF) port-specific
    22  	// information to the plug-in.
    23  	Profile map[string]string `json:"binding:profile,omitempty"`
    24  }
    25  
    26  // ToPortCreateMap casts a CreateOpts struct to a map.
    27  func (opts CreateOptsExt) ToPortCreateMap() (map[string]interface{}, error) {
    28  	base, err := opts.CreateOptsBuilder.ToPortCreateMap()
    29  	if err != nil {
    30  		return nil, err
    31  	}
    32  
    33  	port := base["port"].(map[string]interface{})
    34  
    35  	if opts.HostID != "" {
    36  		port["binding:host_id"] = opts.HostID
    37  	}
    38  
    39  	if opts.VNICType != "" {
    40  		port["binding:vnic_type"] = opts.VNICType
    41  	}
    42  
    43  	if opts.Profile != nil {
    44  		port["binding:profile"] = opts.Profile
    45  	}
    46  
    47  	return base, nil
    48  }
    49  
    50  // UpdateOptsExt adds port binding options to the base ports.UpdateOpts
    51  type UpdateOptsExt struct {
    52  	// UpdateOptsBuilder is the interface options structs have to satisfy in order
    53  	// to be used in the main Update operation in this package.
    54  	ports.UpdateOptsBuilder
    55  
    56  	// The ID of the host where the port is allocated.
    57  	HostID string `json:"binding:host_id,omitempty"`
    58  
    59  	// The virtual network interface card (vNIC) type that is bound to the
    60  	// neutron port.
    61  	VNICType string `json:"binding:vnic_type,omitempty"`
    62  
    63  	// A dictionary that enables the application running on the specified
    64  	// host to pass and receive virtual network interface (VIF) port-specific
    65  	// information to the plug-in.
    66  	Profile map[string]string `json:"binding:profile,omitempty"`
    67  }
    68  
    69  // ToPortUpdateMap casts an UpdateOpts struct to a map.
    70  func (opts UpdateOptsExt) ToPortUpdateMap() (map[string]interface{}, error) {
    71  	base, err := opts.UpdateOptsBuilder.ToPortUpdateMap()
    72  	if err != nil {
    73  		return nil, err
    74  	}
    75  
    76  	port := base["port"].(map[string]interface{})
    77  
    78  	if opts.HostID != "" {
    79  		port["binding:host_id"] = opts.HostID
    80  	}
    81  
    82  	if opts.VNICType != "" {
    83  		port["binding:vnic_type"] = opts.VNICType
    84  	}
    85  
    86  	if opts.Profile != nil {
    87  		port["binding:profile"] = opts.Profile
    88  	}
    89  
    90  	return base, nil
    91  }