Class: OpenStack::Volume::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/openstack/volume/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Connection

Returns a new instance of Connection.



9
10
11
12
13
# File 'lib/openstack/volume/connection.rb', line 9

def initialize(connection)
  @connection = connection
  OpenStack::Authentication.init(@connection)
  @volumes_native, @volume_path = check_if_native
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



6
7
8
# File 'lib/openstack/volume/connection.rb', line 6

def connection
  @connection
end

#volumes_nativeObject (readonly)

Returns the value of attribute volumes_native.



7
8
9
# File 'lib/openstack/volume/connection.rb', line 7

def volumes_native
  @volumes_native
end

Instance Method Details

#authok?Boolean

Returns true if the authentication was successful and returns false otherwise.

cs.authok?
=> true

Returns:

  • (Boolean)


19
20
21
# File 'lib/openstack/volume/connection.rb', line 19

def authok?
  @connection.authok
end

#create_volume(options) ⇒ Object

require params: :size optional params: :metadata=>{:key=>val, …, :availability_zone, :volume_type } returns OpenStack::Volume::Volume object



26
27
28
29
30
31
32
# File 'lib/openstack/volume/connection.rb', line 26

def create_volume(options)
  raise OpenStack::Exception::MissingArgument, ":display_name and :size must be specified to create a volume" unless (options[:display_name] && options[:size])
  data = JSON.generate(:volume => options)
  response = @connection.csreq("POST",@connection.service_host,"#{@connection.service_path}/#{@volume_path}",@connection.service_port,@connection.service_scheme,{'content-type' => 'application/json'},data)
  volume_info = JSON.parse(response.body)["volume"]
  volume = OpenStack::Volume::Volume.new(volume_info)
end

#delete_volume(vol_id) ⇒ Object



51
52
53
54
# File 'lib/openstack/volume/connection.rb', line 51

def delete_volume(vol_id)
  response = @connection.req("DELETE", "/#{@volume_path}/#{vol_id}")
  true
end

#get_volume(vol_id) ⇒ Object Also known as: volume



44
45
46
47
48
# File 'lib/openstack/volume/connection.rb', line 44

def get_volume(vol_id)
  response = @connection.req("GET", "/#{@volume_path}/#{vol_id}")
  volume_hash = JSON.parse(response.body)["volume"]
  OpenStack::Volume::Volume.new(volume_hash)
end

#list_volumesObject Also known as: volumes

no options documented in API at Nov 2012 (e.g. like limit/marker as used in Nova for servers)



36
37
38
39
40
# File 'lib/openstack/volume/connection.rb', line 36

def list_volumes
  response = @connection.req("GET", "/#{@volume_path}")
  volumes_hash = JSON.parse(response.body)["volumes"]
  volumes_hash.inject([]){|res, current| res << OpenStack::Volume::Volume.new(current); res}
end