github.com/recobe182/terraform@v0.8.5-0.20170117231232-49ab22a935b7/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/fwaas/firewalls" 6 "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/policies" 7 "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/rules" 8 "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips" 9 "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers" 10 "github.com/gophercloud/gophercloud/openstack/networking/v2/networks" 11 "github.com/gophercloud/gophercloud/openstack/networking/v2/ports" 12 "github.com/gophercloud/gophercloud/openstack/networking/v2/subnets" 13 ) 14 15 // FirewallCreateOpts represents the attributes used when creating a new firewall. 16 type FirewallCreateOpts struct { 17 firewalls.CreateOpts 18 ValueSpecs map[string]string `json:"value_specs,omitempty"` 19 } 20 21 // ToFirewallCreateMap casts a CreateOpts struct to a map. 22 // It overrides firewalls.ToFirewallCreateMap to add the ValueSpecs field. 23 func (opts FirewallCreateOpts) ToFirewallCreateMap() (map[string]interface{}, error) { 24 return BuildRequest(opts, "firewall") 25 } 26 27 // FloatingIPCreateOpts represents the attributes used when creating a new floating ip. 28 type FloatingIPCreateOpts struct { 29 floatingips.CreateOpts 30 ValueSpecs map[string]string `json:"value_specs,omitempty"` 31 } 32 33 // ToFloatingIPCreateMap casts a CreateOpts struct to a map. 34 // It overrides floatingips.ToFloatingIPCreateMap to add the ValueSpecs field. 35 func (opts FloatingIPCreateOpts) ToFloatingIPCreateMap() (map[string]interface{}, error) { 36 return BuildRequest(opts, "floatingip") 37 } 38 39 // KeyPairCreateOpts represents the attributes used when creating a new keypair. 40 type KeyPairCreateOpts struct { 41 keypairs.CreateOpts 42 ValueSpecs map[string]string `json:"value_specs,omitempty"` 43 } 44 45 // ToKeyPairCreateMap casts a CreateOpts struct to a map. 46 // It overrides keypairs.ToKeyPairCreateMap to add the ValueSpecs field. 47 func (opts KeyPairCreateOpts) ToKeyPairCreateMap() (map[string]interface{}, error) { 48 return BuildRequest(opts, "keypair") 49 } 50 51 // NetworkCreateOpts represents the attributes used when creating a new network. 52 type NetworkCreateOpts struct { 53 networks.CreateOpts 54 ValueSpecs map[string]string `json:"value_specs,omitempty"` 55 } 56 57 // ToNetworkCreateMap casts a CreateOpts struct to a map. 58 // It overrides networks.ToNetworkCreateMap to add the ValueSpecs field. 59 func (opts NetworkCreateOpts) ToNetworkCreateMap() (map[string]interface{}, error) { 60 return BuildRequest(opts, "network") 61 } 62 63 // PolicyCreateOpts represents the attributes used when creating a new firewall policy. 64 type PolicyCreateOpts struct { 65 policies.CreateOpts 66 ValueSpecs map[string]string `json:"value_specs,omitempty"` 67 } 68 69 // ToPolicyCreateMap casts a CreateOpts struct to a map. 70 // It overrides policies.ToFirewallPolicyCreateMap to add the ValueSpecs field. 71 func (opts PolicyCreateOpts) ToFirewallPolicyCreateMap() (map[string]interface{}, error) { 72 return BuildRequest(opts, "firewall_policy") 73 } 74 75 // PortCreateOpts represents the attributes used when creating a new port. 76 type PortCreateOpts struct { 77 ports.CreateOpts 78 ValueSpecs map[string]string `json:"value_specs,omitempty"` 79 } 80 81 // ToPortCreateMap casts a CreateOpts struct to a map. 82 // It overrides ports.ToPortCreateMap to add the ValueSpecs field. 83 func (opts PortCreateOpts) ToPortCreateMap() (map[string]interface{}, error) { 84 return BuildRequest(opts, "port") 85 } 86 87 // RouterCreateOpts represents the attributes used when creating a new router. 88 type RouterCreateOpts struct { 89 routers.CreateOpts 90 ValueSpecs map[string]string `json:"value_specs,omitempty"` 91 } 92 93 // ToRouterCreateMap casts a CreateOpts struct to a map. 94 // It overrides routers.ToRouterCreateMap to add the ValueSpecs field. 95 func (opts RouterCreateOpts) ToRouterCreateMap() (map[string]interface{}, error) { 96 return BuildRequest(opts, "router") 97 } 98 99 // RuleCreateOpts represents the attributes used when creating a new firewall rule. 100 type RuleCreateOpts struct { 101 rules.CreateOpts 102 ValueSpecs map[string]string `json:"value_specs,omitempty"` 103 } 104 105 // ToRuleCreateMap casts a CreateOpts struct to a map. 106 // It overrides rules.ToRuleCreateMap to add the ValueSpecs field. 107 func (opts RuleCreateOpts) ToRuleCreateMap() (map[string]interface{}, error) { 108 b, err := BuildRequest(opts, "firewall_rule") 109 if err != nil { 110 return nil, err 111 } 112 113 if m := b["firewall_rule"].(map[string]interface{}); m["protocol"] == "any" { 114 m["protocol"] = nil 115 } 116 117 return b, nil 118 } 119 120 // SubnetCreateOpts represents the attributes used when creating a new subnet. 121 type SubnetCreateOpts struct { 122 subnets.CreateOpts 123 ValueSpecs map[string]string `json:"value_specs,omitempty"` 124 } 125 126 // ToSubnetCreateMap casts a CreateOpts struct to a map. 127 // It overrides subnets.ToSubnetCreateMap to add the ValueSpecs field. 128 func (opts SubnetCreateOpts) ToSubnetCreateMap() (map[string]interface{}, error) { 129 b, err := BuildRequest(opts, "subnet") 130 if err != nil { 131 return nil, err 132 } 133 134 if m := b["subnet"].(map[string]interface{}); m["gateway_ip"] == "" { 135 m["gateway_ip"] = nil 136 } 137 138 return b, nil 139 }