Class: VagrantPlugins::Openstack::NeutronClient

Inherits:
Object
  • Object
show all
Includes:
Singleton, Utils
Defined in:
lib/vagrant-openstack-provider/client/neutron.rb

Instance Method Summary collapse

Methods included from Utils

#authenticated, #handle_response

Constructor Details

#initializeNeutronClient

Returns a new instance of NeutronClient.



13
14
15
16
# File 'lib/vagrant-openstack-provider/client/neutron.rb', line 13

def initialize
  @logger = Log4r::Logger.new('vagrant_openstack::neutron')
  @session = VagrantPlugins::Openstack.session
end

Instance Method Details

#get_private_networks(env) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/vagrant-openstack-provider/client/neutron.rb', line 18

def get_private_networks(env)
  authenticated(env) do
    networks_json = RestClient.get("#{@session.endpoints[:network]}/networks",
                                   'X-Auth-Token' => @session.token,
                                   :accept => :json) { |res| handle_response(res) }
    networks = []
    JSON.parse(networks_json)['networks'].each do |n|
      networks << { id: n['id'], name: n['name'] } if n['tenant_id'].eql? @session.project_id
    end
    networks
  end
end