Sha256: c32a2540ebed92dea5f595523d022a5de608af970ad07d3cd2e7ca7d5b2efb36

Contents?: true

Size: 1.48 KB

Versions: 3

Compression:

Stored size: 1.48 KB

Contents

require 'log4r'
require 'restclient'
require 'json'

require 'vagrant-openstack-provider/client/http_utils'
require 'vagrant-openstack-provider/client/domain'

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

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

      def get_api_version_list(_env)
        json = RestClient.get(@session.endpoints[:network], 'X-Auth-Token' => @session.token, :accept => :json) do |response|
          log_response(response)
          case response.code
          when 200, 300
            response
          when 401
            fail Errors::AuthenticationFailed
          else
            fail Errors::VagrantOpenstackError, message: response.to_s
          end
        end
        JSON.parse(json)['versions']
      end

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

      def get_all_networks(env)
        get_networks(env, true)
      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

3 entries across 3 versions & 1 rubygems

Version Path
vagrant-openstack-provider-0.5.2 lib/vagrant-openstack-provider/client/neutron.rb
vagrant-openstack-provider-0.5.1 lib/vagrant-openstack-provider/client/neutron.rb
vagrant-openstack-provider-0.5.0 lib/vagrant-openstack-provider/client/neutron.rb