Sha256: e8ce99309156b40b6d1c0e1b5d4fef9076272ea47f09a4a05de84901ac9143b5

Contents?: true

Size: 1.25 KB

Versions: 11

Compression:

Stored size: 1.25 KB

Contents

require 'log4r'
require 'json'

require 'vagrant-conoha/client/http_utils'
require 'vagrant-conoha/client/domain'

module VagrantPlugins
  module ConoHa
    class NeutronClient
      include Singleton
      include VagrantPlugins::ConoHa::HttpUtils
      include VagrantPlugins::ConoHa::Domain

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

      def get_private_networks(env)
        get_networks(env, false)
      end

      def get_all_networks(env)
        get_networks(env, true)
      end

      def get_subnets(env)
        subnets_json = get(env, "#{@session.endpoints[:network]}/subnets")
        subnets = []
        JSON.parse(subnets_json)['subnets'].each do |n|
          subnets << Subnet.new(n['id'], n['name'], n['cidr'], n['enable_dhcp'], n['network_id'])
        end
        subnets
      end

      private

      def get_networks(env, all)
        networks_json = get(env, "#{@session.endpoints[:network]}/networks")
        networks = []
        JSON.parse(networks_json)['networks'].each do |n|
          networks << Item.new(n['id'], n['name']) if all || n['tenant_id'].eql?(@session.project_id)
        end
        networks
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
vagrant-conoha-0.1.10 lib/vagrant-conoha/client/neutron.rb
vagrant-conoha-0.1.9 lib/vagrant-conoha/client/neutron.rb
vagrant-conoha-0.1.8 lib/vagrant-conoha/client/neutron.rb
vagrant-conoha-0.1.7 lib/vagrant-conoha/client/neutron.rb
vagrant-conoha-0.1.6 lib/vagrant-conoha/client/neutron.rb
vagrant-conoha-0.1.5 lib/vagrant-conoha/client/neutron.rb
vagrant-conoha-0.1.4 lib/vagrant-conoha/client/neutron.rb
vagrant-conoha-0.1.3 lib/vagrant-conoha/client/neutron.rb
vagrant-conoha-0.1.2 lib/vagrant-conoha/client/neutron.rb
vagrant-conoha-0.1.1 lib/vagrant-conoha/client/neutron.rb
vagrant-conoha-0.1.0 lib/vagrant-conoha/client/neutron.rb