class OpenStack::Network::Connection
Attributes
connection[RW]
Public Class Methods
new(connection)
click to toggle source
# File lib/openstack/network/connection.rb, line 8 def initialize(connection) @connection = connection OpenStack::Authentication.init(@connection) end
Public Instance Methods
add_router_interface(id, subnet_id)
click to toggle source
# File lib/openstack/network/connection.rb, line 126 def add_router_interface(id, subnet_id) req_body = JSON.generate({'subnet_id' => subnet_id}) @connection.req('PUT', "/routers/#{id}/add_router_interface", {:data => req_body}) end
add_router_interface_by_name(name, interface)
click to toggle source
# File lib/openstack/network/connection.rb, line 122 def add_router_interface_by_name(name, interface) @connection.req('PUT', "/routers/#{get_router_id(name)}/#{interface}") end
authok?()
click to toggle source
Returns true if the authentication was successful and returns false otherwise.
cs.authok? => true
# File lib/openstack/network/connection.rb, line 17 def authok? @connection.authok end
create_network(name, parameter={})
click to toggle source
# File lib/openstack/network/connection.rb, line 34 def create_network(name, parameter={}) body_hash = {"network" => {"name"=>name}} body_hash['network'].merge! parameter req_body = JSON.generate(body_hash) response = @connection.req("POST", "/networks", {:data=>req_body}) OpenStack::Network::Network.new(JSON.parse(response.body)["network"]) end
create_port(network_id, opts={})
click to toggle source
# File lib/openstack/network/connection.rb, line 86 def create_port(network_id, opts={}) body_hash = {"port"=>{"network_id"=> network_id}} body_hash["port"].merge!(opts) #fixme - validation? req_body = JSON.generate(body_hash) response = @connection.req("POST", "/ports", {:data=>req_body}) OpenStack::Network::Port.new(JSON.parse(response.body)["port"]) end
create_router(name, admin_state_up, opts={})
click to toggle source
# File lib/openstack/network/connection.rb, line 106 def create_router(name, admin_state_up, opts={}) body_hash = {'router'=> {'name' => name, 'admin_state_up' => admin_state_up}} body_hash['router'].merge! opts req_body = JSON.generate body_hash response = @connection.req('POST', '/routers', {:data => req_body }) OpenStack::Network::Router.new(JSON.parse(response.body)['router']) end
create_subnet(network_id, cidr, ip_version="4", opts={})
click to toggle source
# File lib/openstack/network/connection.rb, line 60 def create_subnet(network_id, cidr, ip_version="4", opts={}) body_hash = {"subnet"=>{"network_id"=> network_id, "cidr"=>cidr, "ip_version"=>ip_version}} body_hash["subnet"].merge!(opts) #fixme - validation? req_body = JSON.generate(body_hash) response = @connection.req("POST", "/subnets", {:data=>req_body}) OpenStack::Network::Subnet.new(JSON.parse(response.body)["subnet"]) end
delete_network(id)
click to toggle source
# File lib/openstack/network/connection.rb, line 42 def delete_network(id) @connection.req("DELETE", "/networks/#{id}") true end
delete_port(id)
click to toggle source
# File lib/openstack/network/connection.rb, line 94 def delete_port(id) @connection.req("DELETE", "/ports/#{id}") true end
delete_router(id)
click to toggle source
# File lib/openstack/network/connection.rb, line 118 def delete_router(id) @connection.req('DELETE', "/routers/#{id}") end
delete_router_by_name(name)
click to toggle source
# File lib/openstack/network/connection.rb, line 114 def delete_router_by_name(name) @connection.req('DELETE', "/routers/#{get_router_id(name)}") end
delete_subnet(id)
click to toggle source
# File lib/openstack/network/connection.rb, line 68 def delete_subnet(id) @connection.req("DELETE", "/subnets/#{id}") true end
get_network(network_id)
click to toggle source
# File lib/openstack/network/connection.rb, line 28 def get_network(network_id) response = @connection.req("GET", "/networks/#{network_id}") OpenStack::Network::Network.new(JSON.parse(response.body)["network"]) end
Also aliased as: network
get_port(port_id)
click to toggle source
# File lib/openstack/network/connection.rb, line 80 def get_port(port_id) response = @connection.req("GET", "/ports/#{port_id}") OpenStack::Network::Port.new(JSON.parse(response.body)["port"]) end
Also aliased as: port
get_router_id(name)
click to toggle source
# File lib/openstack/network/connection.rb, line 148 def get_router_id(name) routers.detect do |value| return value.id if value.name == name end end
get_subnet(subnet_id)
click to toggle source
# File lib/openstack/network/connection.rb, line 54 def get_subnet(subnet_id) response = @connection.req("GET", "/subnets/#{subnet_id}") OpenStack::Network::Subnet.new(JSON.parse(response.body)["subnet"]) end
Also aliased as: subnet
list_networks()
click to toggle source
# File lib/openstack/network/connection.rb, line 21 def list_networks response = @connection.req("GET", "/networks") nets_hash = JSON.parse(response.body)["networks"] nets_hash.inject([]){|res, current| res << OpenStack::Network::Network.new(current); res} end
Also aliased as: networks
list_ports()
click to toggle source
# File lib/openstack/network/connection.rb, line 73 def list_ports response = @connection.req("GET", "/ports") ports_hash = JSON.parse(response.body)["ports"] ports_hash.inject([]){|res, current| res << OpenStack::Network::Port.new(current); res} end
Also aliased as: ports
list_routers()
click to toggle source
# File lib/openstack/network/connection.rb, line 99 def list_routers response = @connection.req('GET', '/routers') nets_hash = JSON.parse(response.body)['routers'] nets_hash.inject([]){|res, current| res << OpenStack::Network::Router.new(current); res} end
Also aliased as: routers
list_subnets()
click to toggle source
# File lib/openstack/network/connection.rb, line 47 def list_subnets response = @connection.req("GET", "/subnets") nets_hash = JSON.parse(response.body)["subnets"] nets_hash.inject([]){|res, current| res << OpenStack::Network::Subnet.new(current); res} end
Also aliased as: subnets
remove_router_interface(id, subnet_id)
click to toggle source
# File lib/openstack/network/connection.rb, line 131 def remove_router_interface(id, subnet_id) req_body = JSON.generate({'subnet_id' => subnet_id}) @connection.req('PUT', "/routers/#{id}/remove_router_interface", {:data => req_body}) end
update_router(id,opts={})
click to toggle source
# File lib/openstack/network/connection.rb, line 142 def update_router(id,opts={}) req_body = JSON.generate({'router' => opts}) response = @connection.req('PUT',"/routers/#{id}",{:data => req_body}) OpenStack::Network::Router.new(JSON.parse(response.body)['router']) end
update_router_by_name(name,opts={})
click to toggle source
# File lib/openstack/network/connection.rb, line 136 def update_router_by_name(name,opts={}) req_body = JSON.generate opts response = @connection.req('PUT',"/routers/#{get_router_id(name)}",{:data => req_body}) OpenStack::Network::Router.new(JSON.parse(response.body)['router']) end