Class: Ropenstack::Networking

Overview

  • Name: Networking

* Description: An implementation of the Networking V2.0 API Client in Ruby * Authors: Sam ‘Tehsmash’ Betts, John Davidge * Date: 01/15/2013

Defined Under Namespace

Modules: Version2

Instance Method Summary collapse

Methods included from Version2::Extensions::L3

#add_router_gateway, #add_router_interface, #create_floating_ip, #create_router, #delete_floating_ip, #delete_router, #delete_router_gateway, #delete_router_interface, #floating_ips, #routers, #update_floating_ip

Methods inherited from OpenstackService

#initialize

Methods inherited from Rest

#build_headers, #build_http, #delete_request, #do_request, #error_manager, #get_request, #post_request, #put_request

Constructor Details

This class inherits a constructor from Ropenstack::OpenstackService

Instance Method Details

#create_network(name, tenant, admin_state_up = true) ⇒ Object

Create a new network on Openstack given a name and tenant id.



38
39
40
41
42
43
44
45
46
47
# File 'lib/ropenstack/networking.rb', line 38

def create_network(name, tenant, admin_state_up = true)
  data = {
    'network' => {
      'name' => name,
      'tenant_id' => tenant,
      'admin_state_up' => admin_state_up
    }   
  }
  return post_request(address("networks"), data, @token)
end

#create_port(network, subnet = nil, device = nil, device_owner = nil) ⇒ Object

Create a new port given network and device ids, optional parameter subnet id allows for scoping the port to a single subnet.



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/ropenstack/networking.rb', line 107

def create_port(network, subnet = nil, device = nil, device_owner = nil)
  data = {
    'port' => {
      'network_id' => network,
    }   
  }
  unless device_owner.nil?
    data['port']['device_owner'] = device_owner
  end
  unless device.nil?
    data['port']['device_id'] = device
  end
  unless subnet.nil?
    data['port']['fixed_ips'] = [{'subnet_id' => subnet}]
  end
  
  puts data

  return post_request(address("ports"), data, @token)
end

#create_subnet(network, cidr) ⇒ Object

Create a new ipv4 subnet in a network, given a network id, and a IP range in CIDR format.



69
70
71
72
73
74
75
76
77
78
# File 'lib/ropenstack/networking.rb', line 69

def create_subnet(network, cidr)
  data = {
    'subnet' => {
      'network_id' => network,
      'ip_version' => 4,
      'cidr' => cidr
    }   
  }
  return post_request(address("subnets"), data, @token)
end

#delete_network(network) ⇒ Object

Delete a network given a network id.



52
53
54
# File 'lib/ropenstack/networking.rb', line 52

def delete_network(network)
  return delete_request(address("networks/" + network), @token)
end

#delete_port(port) ⇒ Object

Delete a port given a port id.



150
151
152
# File 'lib/ropenstack/networking.rb', line 150

def delete_port(port)
  return delete_request(address("ports/" + port), @token)
end

#delete_subnet(subnet) ⇒ Object

Delete a subnet given a subnet id



83
84
85
# File 'lib/ropenstack/networking.rb', line 83

def delete_subnet(subnet)
  return delete_request(address("subnets/" + subnet), @token)
end

#device_ports(device_id) ⇒ Object

Get a list of ports specific to a device_id



99
100
101
# File 'lib/ropenstack/networking.rb', line 99

def device_ports(device_id)
  return get_request(address("ports?device_id=#{device_id}"), @token)
end

#move_port_to_subnets(port_id, subnet_ids) ⇒ Object

Weird function for adding a port to multiple subnets if nessessary.



139
140
141
142
143
144
145
# File 'lib/ropenstack/networking.rb', line 139

def move_port_to_subnets(port_id, subnet_ids)
  id_list = Array.new()
  subnet_ids.each do |id|
    id_list << { "subnet_id" => id }
  end
  return update_port(port_id, id_list)
end

#networks(id = nil) ⇒ Object

Get a list of a tenants networks

:call-seq:

networks(id) => A single network with the id matching the parameter
networks => All networks visible to the tenant making the request


27
28
29
30
31
32
33
# File 'lib/ropenstack/networking.rb', line 27

def networks(id = nil)
  endpoint = "networks"
  unless id.nil?
    endpoint = endpoint + "/" + id
  end
  return get_request(address(endpoint), @token)
end

#portsObject

Get a list of ports



92
93
94
# File 'lib/ropenstack/networking.rb', line 92

def ports
  return get_request(address("ports"), @token)
end

#subnetsObject

Get a list of subnets



61
62
63
# File 'lib/ropenstack/networking.rb', line 61

def subnets
  return get_request(address("subnets"), @token)
end

#update_port(port, fixed_ips) ⇒ Object

Update a specific ports fixed_ips, including subnet and ip data.



131
132
133
134
# File 'lib/ropenstack/networking.rb', line 131

def update_port(port, fixed_ips) 
  data = { 'port' => { 'fixed_ips' => fixed_ips } }
  return put_request(address("ports/"+port), data, @token)
end