Class: OpenStack::Volume::Connection
- Inherits:
-
Object
- Object
- OpenStack::Volume::Connection
- Defined in:
- lib/openstack/volume/connection.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#volumes_native ⇒ Object
readonly
Returns the value of attribute volumes_native.
Instance Method Summary collapse
-
#authok? ⇒ Boolean
Returns true if the authentication was successful and returns false otherwise.
-
#create_volume(options) ⇒ Object
require params: :size optional params: :metadata=>{:key=>val, …, :availability_zone, :volume_type } returns OpenStack::Volume::Volume object.
- #delete_volume(vol_id) ⇒ Object
- #get_volume(vol_id) ⇒ Object (also: #volume)
-
#initialize(connection) ⇒ Connection
constructor
A new instance of Connection.
-
#list_volumes ⇒ Object
(also: #volumes)
no options documented in API at Nov 2012 (e.g. like limit/marker as used in Nova for servers).
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
#connection ⇒ Object
Returns the value of attribute connection.
6 7 8 |
# File 'lib/openstack/volume/connection.rb', line 6 def connection @connection end |
#volumes_native ⇒ Object (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
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() raise OpenStack::Exception::MissingArgument, ":display_name and :size must be specified to create a volume" unless ([:display_name] && [:size]) data = JSON.generate(:volume => ) 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_volumes ⇒ Object 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 |