Sha256: 0e727764e6c57b44c012e9929c524b9afd54b250028248b89cfab4c276c3ca54

Contents?: true

Size: 1.42 KB

Versions: 11

Compression:

Stored size: 1.42 KB

Contents

require 'log4r'
require 'json'

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

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

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

      def get_all_volumes(env)
        volumes_json = get(env, "#{@session.endpoints[:volume]}/volumes/detail")
        JSON.parse(volumes_json)['volumes'].map do |volume|
          name = volume['display_name']
          name = volume['name'] if name.nil? # To be compatible with cinder api v1 and v2
          case volume['attachments'].size
          when 0
            @logger.debug "No attachment found for volume #{volume['id']}"
          else
            attachment = volume['attachments'][0]
            server_id = attachment['server_id']
            device = attachment['device']
            @logger.warn "Found #{attachment.size} attachments for volume #{volume['id']} : " if attachment.size > 1
            @logger.debug "Attachment found for volume #{volume['id']} : #{attachment.to_json}"
          end
          Volume.new(volume['id'], name, volume['size'], volume['status'], volume['bootable'], server_id, device)
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
vagrant-openstack-provider-0.13.0 lib/vagrant-openstack-provider/client/cinder.rb
vagrant-openstack-provider-0.12.0 lib/vagrant-openstack-provider/client/cinder.rb
vagrant-openstack-provider-illuin-0.11.1 lib/vagrant-openstack-provider/client/cinder.rb
vagrant-openstack-provider-0.11.0 lib/vagrant-openstack-provider/client/cinder.rb
vagrant-openstack-provider-0.10.0 lib/vagrant-openstack-provider/client/cinder.rb
vagrant-openstack-provider-0.9.0 lib/vagrant-openstack-provider/client/cinder.rb
vagrant-openstack-provider-0.8.0 lib/vagrant-openstack-provider/client/cinder.rb
vagrant-openstack-provider-0.7.2 lib/vagrant-openstack-provider/client/cinder.rb
vagrant-openstack-provider-0.7.1 lib/vagrant-openstack-provider/client/cinder.rb
vagrant-openstack-provider-0.7.0 lib/vagrant-openstack-provider/client/cinder.rb
vagrant-openstack-provider-0.6.1 lib/vagrant-openstack-provider/client/cinder.rb