Top Level Namespace

Defined Under Namespace

Modules: Fog

Instance Method Summary collapse

Instance Method Details

#create_tenant_network(tenant_name, external_net, router_name = 'router1', subnet_range = '10.0.0.0/21', subnet_gateway = '10.0.0.1', private_network_name = 'private') ⇒ Object

Quantum demo

Create some routers, networks and subnets for a couple of tenants.

Needs Fog >= 1.11.0 Needs OpenStack credentials in ~/.fog



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/fog/openstack/examples/network/network_subnets_routers.rb', line 13

def create_tenant_network( tenant_name,
                           external_net,
                           router_name = 'router1',
                           subnet_range = '10.0.0.0/21',
                           subnet_gateway = '10.0.0.1',
                           private_network_name = 'private' )

  network = Fog::Network[:openstack]
  id = Fog::Identity[:openstack]

  tenant = id.tenants.find { |t| t.name == tenant_name }

  # Create a router for the tenant
  router = network.routers.create :name => router_name,
                                  :tenant_id => tenant.id,
                                  :external_gateway_info => {
                                    'network_id' => external_net.id
                                  }

  # Create a private network for the tenant
  net = network.networks.create :name => private_network_name,
                                :tenant_id => tenant.id

  # Create a subnet for the previous network and associate it
  # with the tenant
  subnet = network.subnets.create :name => 'net_10',
                                  :network_id  => net.id,
                                  :ip_version  => 4,
                                  :gateway_ip  => subnet_gateway,
                                  :cidr        => subnet_range,
                                  :tenant_id => tenant.id,
                                  :enable_dhcp => true

  network.add_router_interface router.id, subnet.id
end