Sha256: 9eefca143e82dca98e9c4be987549a4c0867b1d57c6c6ab46df55c9778d1f650

Contents?: true

Size: 1.31 KB

Versions: 6

Compression:

Stored size: 1.31 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)
        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 n['tenant_id'].eql? @session.project_id
        end
        networks
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
vagrant-openstack-provider-0.4.1 lib/vagrant-openstack-provider/client/neutron.rb
vagrant-openstack-provider-0.4.0 lib/vagrant-openstack-provider/client/neutron.rb
vagrant-openstack-provider-0.3.4.pre lib/vagrant-openstack-provider/client/neutron.rb
vagrant-openstack-provider-0.3.3 lib/vagrant-openstack-provider/client/neutron.rb
vagrant-openstack-provider-0.3.2 lib/vagrant-openstack-provider/client/neutron.rb
vagrant-openstack-provider-0.3.0 lib/vagrant-openstack-provider/client/neutron.rb