class OpenStack::Volume::Connection

Attributes

connection[RW]
volumes_native[R]

Public Class Methods

new(connection) click to toggle source
# File lib/openstack/volume/connection.rb, line 9
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

Public Instance Methods

authok?() click to toggle source

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

cs.authok?
=> true
# File lib/openstack/volume/connection.rb, line 20
def authok?
  @connection.authok
end
create_snapshot(options) click to toggle source

require params: {:display_name, :volume_id} optional params: {:display_description, :metadata=>{:key=>val, ...}, :availability_zone, :volume_type } returns OpenStack::Volume::Snapshot object

# File lib/openstack/volume/connection.rb, line 75
def create_snapshot(options)
  raise OpenStack::Exception::MissingArgument, ":volume_id and :display_name must be specified to create a snapshot" unless (options[:display_name] && options[:volume_id])
  #:force documented in API but not explained... clarify (fails without)
  options.merge!({:force=>"true"})
  data = JSON.generate(:snapshot => options)
  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(%r^20.$/)
  snapshot_info = JSON.parse(response.body)["snapshot"]
  OpenStack::Volume::Snapshot.new(snapshot_info)
end
create_volume(options) click to toggle source

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

# File lib/openstack/volume/connection.rb, line 27
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)
  OpenStack::Exception.raise_exception(response) unless response.code.match(%r^20.$/)
  volume_info = JSON.parse(response.body)["volume"]
  volume = OpenStack::Volume::Volume.new(volume_info)
end
delete_snapshot(snap_id) click to toggle source
# File lib/openstack/volume/connection.rb, line 86
def delete_snapshot(snap_id)
  @connection.req("DELETE", "/#{@snapshot_path}/#{snap_id}")
  true
end
delete_volume(vol_id) click to toggle source
# File lib/openstack/volume/connection.rb, line 53
def delete_volume(vol_id)
  response = @connection.req("DELETE", "/#{@volume_path}/#{vol_id}")
  true
end
get_snapshot(snap_id) click to toggle source
# File lib/openstack/volume/connection.rb, line 65
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
Also aliased as: snapshot
get_volume(vol_id) click to toggle source
# File lib/openstack/volume/connection.rb, line 46
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
Also aliased as: volume
list_snapshots() click to toggle source
# File lib/openstack/volume/connection.rb, line 58
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
Also aliased as: snapshots
list_volumes() click to toggle source

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

# File lib/openstack/volume/connection.rb, line 38
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
Also aliased as: volumes
snapshot(snap_id) click to toggle source
Alias for: get_snapshot
snapshots() click to toggle source
Alias for: list_snapshots
volume(vol_id) click to toggle source
Alias for: get_volume
volumes() click to toggle source
Alias for: list_volumes