github.com/minamijoyo/terraform@v0.7.8-0.20161029001309-18b3736ba44b/builtin/providers/openstack/types.go (about)

     1  package openstack
     2  
     3  import (
     4  	"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs"
     5  	"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips"
     6  	"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers"
     7  	"github.com/gophercloud/gophercloud/openstack/networking/v2/networks"
     8  	"github.com/gophercloud/gophercloud/openstack/networking/v2/ports"
     9  	"github.com/gophercloud/gophercloud/openstack/networking/v2/subnets"
    10  )
    11  
    12  // FloatingIPCreateOpts represents the attributes used when creating a new port.
    13  type FloatingIPCreateOpts struct {
    14  	floatingips.CreateOpts
    15  	ValueSpecs map[string]string `json:"value_specs,omitempty"`
    16  }
    17  
    18  // ToFloatingIPCreateMap casts a CreateOpts struct to a map.
    19  // It overrides floatingips.ToFloatingIPCreateMap to add the ValueSpecs field.
    20  func (opts FloatingIPCreateOpts) ToFloatingIPCreateMap() (map[string]interface{}, error) {
    21  	return BuildRequest(opts, "floatingip")
    22  }
    23  
    24  // KeyPairCreateOpts represents the attributes used when creating a new keypair.
    25  type KeyPairCreateOpts struct {
    26  	keypairs.CreateOpts
    27  	ValueSpecs map[string]string `json:"value_specs,omitempty"`
    28  }
    29  
    30  // ToKeyPairCreateMap casts a CreateOpts struct to a map.
    31  // It overrides keypairs.ToKeyPairCreateMap to add the ValueSpecs field.
    32  func (opts KeyPairCreateOpts) ToKeyPairCreateMap() (map[string]interface{}, error) {
    33  	return BuildRequest(opts, "keypair")
    34  }
    35  
    36  // NetworkCreateOpts represents the attributes used when creating a new network.
    37  type NetworkCreateOpts struct {
    38  	networks.CreateOpts
    39  	ValueSpecs map[string]string `json:"value_specs,omitempty"`
    40  }
    41  
    42  // ToNetworkCreateMap casts a CreateOpts struct to a map.
    43  // It overrides networks.ToNetworkCreateMap to add the ValueSpecs field.
    44  func (opts NetworkCreateOpts) ToNetworkCreateMap() (map[string]interface{}, error) {
    45  	return BuildRequest(opts, "network")
    46  }
    47  
    48  // PortCreateOpts represents the attributes used when creating a new port.
    49  type PortCreateOpts struct {
    50  	ports.CreateOpts
    51  	ValueSpecs map[string]string `json:"value_specs,omitempty"`
    52  }
    53  
    54  // ToPortCreateMap casts a CreateOpts struct to a map.
    55  // It overrides ports.ToPortCreateMap to add the ValueSpecs field.
    56  func (opts PortCreateOpts) ToPortCreateMap() (map[string]interface{}, error) {
    57  	return BuildRequest(opts, "port")
    58  }
    59  
    60  // RouterCreateOpts represents the attributes used when creating a new router.
    61  type RouterCreateOpts struct {
    62  	routers.CreateOpts
    63  	ValueSpecs map[string]string `json:"value_specs,omitempty"`
    64  }
    65  
    66  // ToRouterCreateMap casts a CreateOpts struct to a map.
    67  // It overrides routers.ToRouterCreateMap to add the ValueSpecs field.
    68  func (opts RouterCreateOpts) ToRouterCreateMap() (map[string]interface{}, error) {
    69  	return BuildRequest(opts, "router")
    70  }
    71  
    72  // SubnetCreateOpts represents the attributes used when creating a new subnet.
    73  type SubnetCreateOpts struct {
    74  	subnets.CreateOpts
    75  	ValueSpecs map[string]string `json:"value_specs,omitempty"`
    76  }
    77  
    78  // ToSubnetCreateMap casts a CreateOpts struct to a map.
    79  // It overrides subnets.ToSubnetCreateMap to add the ValueSpecs field.
    80  func (opts SubnetCreateOpts) ToSubnetCreateMap() (map[string]interface{}, error) {
    81  	b, err := BuildRequest(opts, "subnet")
    82  	if err != nil {
    83  		return nil, err
    84  	}
    85  
    86  	if m := b["subnet"].(map[string]interface{}); m["gateway_ip"] == "" {
    87  		m["gateway_ip"] = nil
    88  	}
    89  
    90  	return b, nil
    91  }