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

     1  package portsecurity
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk/openstack/networking/v2/networks"
     5  	"github.com/huaweicloud/golangsdk/openstack/networking/v2/ports"
     6  )
     7  
     8  // PortCreateOptsExt adds port security options to the base ports.CreateOpts.
     9  type PortCreateOptsExt struct {
    10  	ports.CreateOptsBuilder
    11  
    12  	// PortSecurityEnabled toggles port security on a port.
    13  	PortSecurityEnabled *bool `json:"port_security_enabled,omitempty"`
    14  }
    15  
    16  // ToPortCreateMap casts a CreateOpts struct to a map.
    17  func (opts PortCreateOptsExt) ToPortCreateMap() (map[string]interface{}, error) {
    18  	base, err := opts.CreateOptsBuilder.ToPortCreateMap()
    19  	if err != nil {
    20  		return nil, err
    21  	}
    22  
    23  	port := base["port"].(map[string]interface{})
    24  
    25  	if opts.PortSecurityEnabled != nil {
    26  		port["port_security_enabled"] = &opts.PortSecurityEnabled
    27  	}
    28  
    29  	return base, nil
    30  }
    31  
    32  // PortUpdateOptsExt adds port security options to the base ports.UpdateOpts.
    33  type PortUpdateOptsExt struct {
    34  	ports.UpdateOptsBuilder
    35  
    36  	// PortSecurityEnabled toggles port security on a port.
    37  	PortSecurityEnabled *bool `json:"port_security_enabled,omitempty"`
    38  }
    39  
    40  // ToPortUpdateMap casts a UpdateOpts struct to a map.
    41  func (opts PortUpdateOptsExt) ToPortUpdateMap() (map[string]interface{}, error) {
    42  	base, err := opts.UpdateOptsBuilder.ToPortUpdateMap()
    43  	if err != nil {
    44  		return nil, err
    45  	}
    46  
    47  	port := base["port"].(map[string]interface{})
    48  
    49  	if opts.PortSecurityEnabled != nil {
    50  		port["port_security_enabled"] = &opts.PortSecurityEnabled
    51  	}
    52  
    53  	return base, nil
    54  }
    55  
    56  // NetworkCreateOptsExt adds port security options to the base
    57  // networks.CreateOpts.
    58  type NetworkCreateOptsExt struct {
    59  	networks.CreateOptsBuilder
    60  
    61  	// PortSecurityEnabled toggles port security on a port.
    62  	PortSecurityEnabled *bool `json:"port_security_enabled,omitempty"`
    63  }
    64  
    65  // ToNetworkCreateMap casts a CreateOpts struct to a map.
    66  func (opts NetworkCreateOptsExt) ToNetworkCreateMap() (map[string]interface{}, error) {
    67  	base, err := opts.CreateOptsBuilder.ToNetworkCreateMap()
    68  	if err != nil {
    69  		return nil, err
    70  	}
    71  
    72  	network := base["network"].(map[string]interface{})
    73  
    74  	if opts.PortSecurityEnabled != nil {
    75  		network["port_security_enabled"] = &opts.PortSecurityEnabled
    76  	}
    77  
    78  	return base, nil
    79  }
    80  
    81  // NetworkUpdateOptsExt adds port security options to the base
    82  // networks.UpdateOpts.
    83  type NetworkUpdateOptsExt struct {
    84  	networks.UpdateOptsBuilder
    85  
    86  	// PortSecurityEnabled toggles port security on a port.
    87  	PortSecurityEnabled *bool `json:"port_security_enabled,omitempty"`
    88  }
    89  
    90  // ToNetworkUpdateMap casts a UpdateOpts struct to a map.
    91  func (opts NetworkUpdateOptsExt) ToNetworkUpdateMap() (map[string]interface{}, error) {
    92  	base, err := opts.UpdateOptsBuilder.ToNetworkUpdateMap()
    93  	if err != nil {
    94  		return nil, err
    95  	}
    96  
    97  	network := base["network"].(map[string]interface{})
    98  
    99  	if opts.PortSecurityEnabled != nil {
   100  		network["port_security_enabled"] = &opts.PortSecurityEnabled
   101  	}
   102  
   103  	return base, nil
   104  }