2016-09-27 15:09:28 +02:00
|
|
|
package openstack
|
|
|
|
|
|
|
|
import (
|
2016-10-10 12:25:06 +02:00
|
|
|
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs"
|
2016-11-05 11:06:49 +01:00
|
|
|
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/firewalls"
|
2016-11-03 14:18:45 +01:00
|
|
|
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/policies"
|
2016-11-03 13:59:07 +01:00
|
|
|
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/fwaas/rules"
|
2016-10-05 18:23:30 +02:00
|
|
|
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips"
|
2016-10-06 16:45:22 +02:00
|
|
|
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers"
|
2016-10-06 17:03:37 +02:00
|
|
|
"github.com/gophercloud/gophercloud/openstack/networking/v2/networks"
|
2016-10-03 18:29:42 +02:00
|
|
|
"github.com/gophercloud/gophercloud/openstack/networking/v2/ports"
|
2016-09-27 15:09:28 +02:00
|
|
|
"github.com/gophercloud/gophercloud/openstack/networking/v2/subnets"
|
|
|
|
)
|
|
|
|
|
2016-11-05 11:06:49 +01:00
|
|
|
// FirewallCreateOpts represents the attributes used when creating a new firewall.
|
|
|
|
type FirewallCreateOpts struct {
|
|
|
|
firewalls.CreateOpts
|
|
|
|
ValueSpecs map[string]string `json:"value_specs,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToFirewallCreateMap casts a CreateOpts struct to a map.
|
|
|
|
// It overrides firewalls.ToFirewallCreateMap to add the ValueSpecs field.
|
|
|
|
func (opts FirewallCreateOpts) ToFirewallCreateMap() (map[string]interface{}, error) {
|
|
|
|
return BuildRequest(opts, "firewall")
|
|
|
|
}
|
|
|
|
|
|
|
|
// FloatingIPCreateOpts represents the attributes used when creating a new floating ip.
|
2016-10-05 18:23:30 +02:00
|
|
|
type FloatingIPCreateOpts struct {
|
|
|
|
floatingips.CreateOpts
|
|
|
|
ValueSpecs map[string]string `json:"value_specs,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToFloatingIPCreateMap casts a CreateOpts struct to a map.
|
|
|
|
// It overrides floatingips.ToFloatingIPCreateMap to add the ValueSpecs field.
|
|
|
|
func (opts FloatingIPCreateOpts) ToFloatingIPCreateMap() (map[string]interface{}, error) {
|
|
|
|
return BuildRequest(opts, "floatingip")
|
|
|
|
}
|
|
|
|
|
2016-10-10 12:25:06 +02:00
|
|
|
// KeyPairCreateOpts represents the attributes used when creating a new keypair.
|
|
|
|
type KeyPairCreateOpts struct {
|
|
|
|
keypairs.CreateOpts
|
|
|
|
ValueSpecs map[string]string `json:"value_specs,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToKeyPairCreateMap casts a CreateOpts struct to a map.
|
|
|
|
// It overrides keypairs.ToKeyPairCreateMap to add the ValueSpecs field.
|
|
|
|
func (opts KeyPairCreateOpts) ToKeyPairCreateMap() (map[string]interface{}, error) {
|
|
|
|
return BuildRequest(opts, "keypair")
|
|
|
|
}
|
|
|
|
|
2016-10-06 17:03:37 +02:00
|
|
|
// NetworkCreateOpts represents the attributes used when creating a new network.
|
|
|
|
type NetworkCreateOpts struct {
|
|
|
|
networks.CreateOpts
|
|
|
|
ValueSpecs map[string]string `json:"value_specs,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToNetworkCreateMap casts a CreateOpts struct to a map.
|
|
|
|
// It overrides networks.ToNetworkCreateMap to add the ValueSpecs field.
|
|
|
|
func (opts NetworkCreateOpts) ToNetworkCreateMap() (map[string]interface{}, error) {
|
|
|
|
return BuildRequest(opts, "network")
|
|
|
|
}
|
|
|
|
|
2016-11-03 14:18:45 +01:00
|
|
|
// PolicyCreateOpts represents the attributes used when creating a new firewall policy.
|
|
|
|
type PolicyCreateOpts struct {
|
|
|
|
policies.CreateOpts
|
|
|
|
ValueSpecs map[string]string `json:"value_specs,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToPolicyCreateMap casts a CreateOpts struct to a map.
|
|
|
|
// It overrides policies.ToFirewallPolicyCreateMap to add the ValueSpecs field.
|
|
|
|
func (opts PolicyCreateOpts) ToFirewallPolicyCreateMap() (map[string]interface{}, error) {
|
|
|
|
return BuildRequest(opts, "firewall_policy")
|
|
|
|
}
|
|
|
|
|
2016-10-03 18:29:42 +02:00
|
|
|
// PortCreateOpts represents the attributes used when creating a new port.
|
|
|
|
type PortCreateOpts struct {
|
|
|
|
ports.CreateOpts
|
|
|
|
ValueSpecs map[string]string `json:"value_specs,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToPortCreateMap casts a CreateOpts struct to a map.
|
|
|
|
// It overrides ports.ToPortCreateMap to add the ValueSpecs field.
|
|
|
|
func (opts PortCreateOpts) ToPortCreateMap() (map[string]interface{}, error) {
|
|
|
|
return BuildRequest(opts, "port")
|
|
|
|
}
|
|
|
|
|
2016-10-06 16:45:22 +02:00
|
|
|
// RouterCreateOpts represents the attributes used when creating a new router.
|
|
|
|
type RouterCreateOpts struct {
|
|
|
|
routers.CreateOpts
|
|
|
|
ValueSpecs map[string]string `json:"value_specs,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToRouterCreateMap casts a CreateOpts struct to a map.
|
|
|
|
// It overrides routers.ToRouterCreateMap to add the ValueSpecs field.
|
|
|
|
func (opts RouterCreateOpts) ToRouterCreateMap() (map[string]interface{}, error) {
|
|
|
|
return BuildRequest(opts, "router")
|
|
|
|
}
|
2016-10-06 17:04:21 +02:00
|
|
|
|
2016-11-03 13:59:07 +01:00
|
|
|
// RuleCreateOpts represents the attributes used when creating a new firewall rule.
|
|
|
|
type RuleCreateOpts struct {
|
|
|
|
rules.CreateOpts
|
|
|
|
ValueSpecs map[string]string `json:"value_specs,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToRuleCreateMap casts a CreateOpts struct to a map.
|
|
|
|
// It overrides rules.ToRuleCreateMap to add the ValueSpecs field.
|
|
|
|
func (opts RuleCreateOpts) ToRuleCreateMap() (map[string]interface{}, error) {
|
|
|
|
b, err := BuildRequest(opts, "firewall_rule")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if m := b["firewall_rule"].(map[string]interface{}); m["protocol"] == "any" {
|
|
|
|
m["protocol"] = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return b, nil
|
|
|
|
}
|
|
|
|
|
2016-10-06 17:04:21 +02:00
|
|
|
// SubnetCreateOpts represents the attributes used when creating a new subnet.
|
|
|
|
type SubnetCreateOpts struct {
|
|
|
|
subnets.CreateOpts
|
|
|
|
ValueSpecs map[string]string `json:"value_specs,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToSubnetCreateMap casts a CreateOpts struct to a map.
|
|
|
|
// It overrides subnets.ToSubnetCreateMap to add the ValueSpecs field.
|
|
|
|
func (opts SubnetCreateOpts) ToSubnetCreateMap() (map[string]interface{}, error) {
|
2016-10-07 16:54:37 +02:00
|
|
|
b, err := BuildRequest(opts, "subnet")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if m := b["subnet"].(map[string]interface{}); m["gateway_ip"] == "" {
|
|
|
|
m["gateway_ip"] = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return b, nil
|
2016-10-06 17:04:21 +02:00
|
|
|
}
|