class Ropenstack::Networking
-
Name:
Networking
-
Description: An implementation of the
Networking
V2.0 API Client in Ruby -
Authors: Sam ‘Tehsmash’ Betts, John Davidge
-
Date: 01/15/2013
Public Instance Methods
Create a new network on Openstack given a name and tenant id.
# 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 a new port given network and device ids, optional parameter subnet id allows for scoping the port to a single subnet.
# 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 a new ipv4 subnet in a network, given a network id, and a IP range in CIDR format.
# 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 a network given a network id.
# File lib/ropenstack/networking.rb, line 52 def delete_network(network) return delete_request(address("networks/" + network), @token) end
Delete a port given a port id.
# File lib/ropenstack/networking.rb, line 150 def delete_port(port) return delete_request(address("ports/" + port), @token) end
Delete a subnet given a subnet id
# File lib/ropenstack/networking.rb, line 83 def delete_subnet(subnet) return delete_request(address("subnets/" + subnet), @token) end
Get a list of ports specific to a device_id
# File lib/ropenstack/networking.rb, line 99 def device_ports(device_id) return get_request(address("ports?device_id=#{device_id}"), @token) end
Weird function for adding a port to multiple subnets if nessessary.
# 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
Get a list of a tenants networks
# 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
Get a list of ports
# File lib/ropenstack/networking.rb, line 92 def ports return get_request(address("ports"), @token) end
Get a list of subnets
# File lib/ropenstack/networking.rb, line 61 def subnets return get_request(address("subnets"), @token) end
Update a specific ports fixed_ips, including subnet and ip data.
# 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
Private Instance Methods
Ropenstack::OpenstackService#address
# File lib/ropenstack/networking.rb, line 156 def address(endpoint) super("/v2.0/#{endpoint}") end