Class: OpenStack::Volume::Connection
- Defined in:
- lib/openstack/volume/connection.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#volume_path ⇒ Object
readonly
Returns the value of attribute volume_path.
-
#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_snapshot(options) ⇒ Object
require params: :volume_id optional params: :metadata=>{:key=>val, …, :availability_zone, :volume_type } returns OpenStack::Volume::Snapshot object.
-
#create_volume(options) ⇒ Object
require params: :size optional params: :metadata=>{:key=>val, …, :availability_zone, :volume_type } returns OpenStack::Volume::Volume object.
- #delete_snapshot(snap_id) ⇒ Object
- #delete_volume(vol_id, force = false) ⇒ Object
-
#get_pools(details = true) ⇒ Object
Lists all back-end storage pools that are known to the scheduler service.
-
#get_quotas(tenant_id) ⇒ Object
get_quotas(1) => { “volumes_slow”=>-1, “snapshots_slow”=>-1, “gigabytes_slow”=>-1, “volumes_fast”=>-1, “snapshots_fast”=>-1, “gigabytes_fast”=>-1, “volumes”=>10, “snapshots”=>10, “gigabytes”=>1001, “id”=>“1”}.
- #get_snapshot(snap_id) ⇒ Object (also: #snapshot)
- #get_volume(vol_id) ⇒ Object (also: #volume)
-
#initialize(connection) ⇒ Connection
constructor
A new instance of Connection.
- #list_snapshots ⇒ Object (also: #snapshots)
-
#list_volume_types ⇒ Object
(also: #types)
[ :extra_specs=>{:volume_backend_name=>“volumes-standard”, :name=>“slow”, :id=>“b3a104b6-fe70-4450-8681-e911a153f41f”}, :extra_specs=>{:volume_backend_name=>“volumes-speed”, :name=>“fast”, :id=>“0e278952-9baa-4aa8-88a7-fe8387f1d86c”} ].
-
#list_volumes(options = {}) ⇒ Object
(also: #volumes)
no options documented in API at Nov 2012 (e.g. like limit/marker as used in Nova for servers).
-
#update_quotas(tenant_id, quota_set) ⇒ Object
quota_set = { gigabytes: 500, gigabytes_slow: 200, gigabytes_fast: 300 } cinder.update_quotas(1, quota_set).
Constructor Details
#initialize(connection) ⇒ Connection
Returns a new instance of Connection.
10 11 12 13 14 15 |
# File 'lib/openstack/volume/connection.rb', line 10 def initialize(connection) @connection = connection OpenStack::Authentication.init(@connection) @volumes_native, @volume_path = check_if_native("volumes") @snapshots_native, @snapshot_path = check_if_native("snapshots") 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 |
#volume_path ⇒ Object (readonly)
Returns the value of attribute volume_path.
8 9 10 |
# File 'lib/openstack/volume/connection.rb', line 8 def volume_path @volume_path 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
21 22 23 |
# File 'lib/openstack/volume/connection.rb', line 21 def authok? @connection.authok end |
#create_snapshot(options) ⇒ Object
require params: :volume_id optional params: :metadata=>{:key=>val, …, :availability_zone, :volume_type } returns OpenStack::Volume::Snapshot object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/openstack/volume/connection.rb', line 82 def create_snapshot() raise OpenStack::Exception::MissingArgument, ":volume_id and :display_name must be specified to create a snapshot" unless ([:display_name] && [:volume_id]) #:force documented in API but not explained... clarify (fails without) .merge!({:force=>"true"}) data = JSON.generate(:snapshot => ) response = @connection.csreq("POST",@connection.service_host,"#{@connection.service_path}/#{@snapshot_path}",@connection.service_port,@connection.service_scheme,{'content-type' => 'application/json'},data) OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) snapshot_info = JSON.parse(response.body)["snapshot"] OpenStack::Volume::Snapshot.new(snapshot_info) end |
#create_volume(options) ⇒ Object
require params: :size optional params: :metadata=>{:key=>val, …, :availability_zone, :volume_type } returns OpenStack::Volume::Volume object
28 29 30 31 32 33 34 35 |
# File 'lib/openstack/volume/connection.rb', line 28 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) OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) volume_info = JSON.parse(response.body)["volume"] OpenStack::Volume::Volume.new(self, volume_info) end |
#delete_snapshot(snap_id) ⇒ Object
93 94 95 96 |
# File 'lib/openstack/volume/connection.rb', line 93 def delete_snapshot(snap_id) @connection.req("DELETE", "/#{@snapshot_path}/#{snap_id}") true end |
#delete_volume(vol_id, force = false) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/openstack/volume/connection.rb', line 55 def delete_volume(vol_id, force = false) if force data = JSON.generate({'os-force_delete' => {}}) @connection.req("POST", "/#{@volume_path}/#{vol_id}/action", {data: data}) else @connection.req("DELETE", "/#{@volume_path}/#{vol_id}") end true end |
#get_pools(details = true) ⇒ Object
Lists all back-end storage pools that are known to the scheduler service
124 125 126 127 128 129 |
# File 'lib/openstack/volume/connection.rb', line 124 def get_pools(details = true) path = details ? "/scheduler-stats/get_pools?detail=true" : "/scheduler-stats/get_pools" response = @connection.req('GET', path) OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) JSON.parse(response.body)['pools'] end |
#get_quotas(tenant_id) ⇒ Object
get_quotas(1)
> { “volumes_slow”=>-1, “snapshots_slow”=>-1, “gigabytes_slow”=>-1,
"volumes_fast"=>-1, "snapshots_fast"=>-1, "gigabytes_fast"=>-1,
"volumes"=>10, "snapshots"=>10, "gigabytes"=>1001, "id"=>"1"}
110 111 112 113 |
# File 'lib/openstack/volume/connection.rb', line 110 def get_quotas(tenant_id) response = @connection.req('GET', "/os-quota-sets/#{tenant_id}") JSON.parse(response.body)['quota_set'] end |
#get_snapshot(snap_id) ⇒ Object Also known as: snapshot
72 73 74 75 76 |
# File 'lib/openstack/volume/connection.rb', line 72 def get_snapshot(snap_id) response = @connection.req("GET", "/#{@snapshot_path}/#{snap_id}") snapshot_hash = JSON.parse(response.body)["snapshot"] OpenStack::Volume::Snapshot.new(snapshot_hash) end |
#get_volume(vol_id) ⇒ Object Also known as: volume
48 49 50 51 52 |
# File 'lib/openstack/volume/connection.rb', line 48 def get_volume(vol_id) response = @connection.req("GET", "/#{@volume_path}/#{vol_id}") volume_hash = JSON.parse(response.body)["volume"] OpenStack::Volume::Volume.new(self, volume_hash) end |
#list_snapshots ⇒ Object Also known as: snapshots
65 66 67 68 69 |
# File 'lib/openstack/volume/connection.rb', line 65 def list_snapshots response = @connection.req("GET", "/#{@snapshot_path}") snapshot_hash = JSON.parse(response.body)["snapshots"] snapshot_hash.inject([]){|res, current| res << OpenStack::Volume::Snapshot.new(current); res} end |
#list_volume_types ⇒ Object Also known as: types
[ :extra_specs=>{:volume_backend_name=>“volumes-standard”, :name=>“slow”, :id=>“b3a104b6-fe70-4450-8681-e911a153f41f”},
{:extra_specs=>{:volume_backend_name=>"volumes-speed"}, :name=>"fast", :id=>"0e278952-9baa-4aa8-88a7-fe8387f1d86c"} ]
100 101 102 103 |
# File 'lib/openstack/volume/connection.rb', line 100 def list_volume_types response = @connection.req('GET', '/types') OpenStack.symbolize_keys(JSON.parse(response.body)['volume_types']) end |
#list_volumes(options = {}) ⇒ Object Also known as: volumes
no options documented in API at Nov 2012 (e.g. like limit/marker as used in Nova for servers)
39 40 41 42 43 44 |
# File 'lib/openstack/volume/connection.rb', line 39 def list_volumes( = {}) path = .empty? ? "/#{@volume_path}/detail" : "/#{@volume_path}/detail?#{.to_query}" response = @connection.req("GET", path) volumes_hash = JSON.parse(response.body)["volumes"] volumes_hash.inject([]){|res, current| res << OpenStack::Volume::Volume.new(self, current); res} end |
#update_quotas(tenant_id, quota_set) ⇒ Object
quota_set = { gigabytes: 500, gigabytes_slow: 200, gigabytes_fast: 300 } cinder.update_quotas(1, quota_set)
117 118 119 120 121 |
# File 'lib/openstack/volume/connection.rb', line 117 def update_quotas(tenant_id, quota_set) req_body = JSON.generate({'quota_set' => quota_set}) response = @connection.req('PUT', "/os-quota-sets/#{tenant_id}", data: req_body) JSON.parse(response.body)['quota_set'] end |