Sha256: ca2c609b4e90bb82ddb495097606b8828d193550cfb99385ed26d37db3f229a9

Contents?: true

Size: 1.74 KB

Versions: 20

Compression:

Stored size: 1.74 KB

Contents

module Fog
  module OpenStack
    class Network
      class Real
        def create_subnet(network_id, cidr, ip_version, options = {})
          data = {
            'subnet' => {
              'network_id' => network_id,
              'cidr'       => cidr,
              'ip_version' => ip_version
            }
          }

          vanilla_options = [:name, :gateway_ip, :allocation_pools,
                             :dns_nameservers, :host_routes, :enable_dhcp,
                             :tenant_id]
          vanilla_options.select { |o| options.key?(o) }.each do |key|
            data['subnet'][key] = options[key]
          end

          request(
            :body    => Fog::JSON.encode(data),
            :expects => [201],
            :method  => 'POST',
            :path    => 'subnets'
          )
        end
      end

      class Mock
        def create_subnet(network_id, cidr, ip_version, options = {})
          response = Excon::Response.new
          response.status = 201
          data = {
            'id'               => Fog::Mock.random_numbers(6).to_s,
            'name'             => options[:name],
            'network_id'       => network_id,
            'cidr'             => cidr,
            'ip_version'       => ip_version,
            'gateway_ip'       => options[:gateway_ip],
            'allocation_pools' => options[:allocation_pools],
            'dns_nameservers'  => options[:dns_nameservers],
            'host_routes'      => options[:host_routes],
            'enable_dhcp'      => options[:enable_dhcp],
            'tenant_id'        => options[:tenant_id]
          }
          self.data[:subnets][data['id']] = data
          response.body = {'subnet' => data}
          response
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 3 rubygems

Version Path
fog-openstack-1.1.3 lib/fog/openstack/network/requests/create_subnet.rb
fog-openstack-1.1.2 lib/fog/openstack/network/requests/create_subnet.rb
fog-openstack-fork-99 lib/fog/openstack/network/requests/create_subnet.rb
fog-openstack-1.1.0 lib/fog/openstack/network/requests/create_subnet.rb
fog-openstack-1.1.0.pre lib/fog/openstack/network/requests/create_subnet.rb
fog-openstack-apibank-1.0.102 lib/fog/openstack/network/requests/create_subnet.rb
fog-openstack-1.0.11 lib/fog/openstack/network/requests/create_subnet.rb
fog-openstack-apibank-1.0.101 lib/fog/openstack/network/requests/create_subnet.rb
fog-openstack-1.0.10 lib/fog/openstack/network/requests/create_subnet.rb
fog-openstack-1.0.9 lib/fog/openstack/network/requests/create_subnet.rb
fog-openstack-1.0.8 lib/fog/openstack/network/requests/create_subnet.rb
fog-openstack-1.0.7 lib/fog/openstack/network/requests/create_subnet.rb
fog-openstack-1.0.6 lib/fog/openstack/network/requests/create_subnet.rb
fog-openstack-1.0.5 lib/fog/openstack/network/requests/create_subnet.rb
fog-openstack-1.0.4 lib/fog/openstack/network/requests/create_subnet.rb
fog-openstack-1.0.3 lib/fog/openstack/network/requests/create_subnet.rb
fog-openstack-1.0.2 lib/fog/openstack/network/requests/create_subnet.rb
fog-openstack-1.0.1 lib/fog/openstack/network/requests/create_subnet.rb
fog-openstack-1.0.0 lib/fog/openstack/network/requests/create_subnet.rb
fog-openstack-0.3.1 lib/fog/openstack/network/requests/create_subnet.rb