class Ropenstack::Networking

Public Instance Methods

create_network(name, tenant, admin_state_up = true) click to toggle source

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_port(network, subnet = nil, device = nil, device_owner = nil) click to toggle source

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_subnet(network, cidr) click to toggle source

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_network(network) click to toggle source

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_port(port) click to toggle source

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_subnet(subnet) click to toggle source

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
device_ports(device_id) click to toggle source

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
move_port_to_subnets(port_id, subnet_ids) click to toggle source

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
networks(id) → A single network with the id matching the parameter click to toggle source
networks → All networks visible to the tenant making the request

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
ports() click to toggle source

Get a list of ports

# File lib/ropenstack/networking.rb, line 92
def ports
  return get_request(address("ports"), @token)
end
subnets() click to toggle source

Get a list of subnets

# File lib/ropenstack/networking.rb, line 61
def subnets
  return get_request(address("subnets"), @token)
end
update_port(port, fixed_ips) click to toggle source

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

address(endpoint) click to toggle source
Calls superclass method Ropenstack::OpenstackService#address
# File lib/ropenstack/networking.rb, line 156
def address(endpoint)
  super("/v2.0/#{endpoint}")
end