create_volume(name, description, size, options={})
click to toggle source
def create_volume(name, description, size, options={})
data = {
'volume' => {
'display_name' => name,
'display_description' => description,
'size' => size
}
}
vanilla_options = [:snapshot_id, :imageRef, :volume_type,
:source_volid]
vanilla_options.select{|o| options[o]}.each do |key|
data['volume'][key] = options[key]
end
request(
:body => MultiJson.encode(data),
:expects => [200, 202],
:method => 'POST',
:path => "volumes"
)
end
create_volume_snapshot(volume_id, name, description, force=false)
click to toggle source
def create_volume_snapshot(volume_id, name, description, force=false)
data = {
'snapshot' => {
'volume_id' => volume_id,
'display_name' => name,
'display_description' => description,
'force' => force
}
}
request(
:body => MultiJson.encode(data),
:expects => [200, 202],
:method => 'POST',
:path => "snapshots"
)
end
credentials()
click to toggle source
def credentials
{ :provider => 'openstack',
:openstack_auth_url => @openstack_auth_uri.to_s,
:openstack_auth_token => @auth_token,
:openstack_management_url => @openstack_management_url,
:current_user => @current_user,
:current_tenant => @current_tenant }
end
delete_snapshot(snapshot_id)
click to toggle source
def delete_snapshot(snapshot_id)
request(
:expects => 202,
:method => 'DELETE',
:path => "snapshots/#{snapshot_id}"
)
end
delete_volume(volume_id)
click to toggle source
def delete_volume(volume_id)
request(
:expects => 202,
:method => 'DELETE',
:path => "volumes/#{volume_id}"
)
end
get_quota(tenant_id)
click to toggle source
def get_quota(tenant_id)
request(
:expects => 200,
:method => 'GET',
:path => "/os-quota-sets/#{tenant_id}"
)
end
get_quota_defaults(tenant_id)
click to toggle source
def get_quota_defaults(tenant_id)
request(
:expects => 200,
:method => 'GET',
:path => "/os-quota-sets/#{tenant_id}/defaults"
)
end
get_snapshot_details(snapshot_id)
click to toggle source
def get_snapshot_details(snapshot_id)
request(
:expects => 200,
:method => 'GET',
:path => "snapshots/#{snapshot_id}"
)
end
get_volume_details(volume_id)
click to toggle source
def get_volume_details(volume_id)
request(
:expects => 200,
:method => 'GET',
:path => "volumes/#{volume_id}"
)
end
list_snapshots(detailed=true)
click to toggle source
def list_snapshots(detailed=true)
path = detailed ? 'snapshots/detail' : 'snapshots'
request(
:expects => 200,
:method => 'GET',
:path => path
)
end
list_volumes(detailed=true)
click to toggle source
def list_volumes(detailed=true)
path = detailed ? 'volumes/detail' : 'volumes'
request(
:expects => 200,
:method => 'GET',
:path => path
)
end
reload()
click to toggle source
def reload
@connection.reset
end
request(params)
click to toggle source
def request(params)
begin
response = @connection.request(params.merge({
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'X-Auth-Token' => @auth_token
}.merge!(params[:headers] || {}),
:host => @host,
:path => "#{@path}/#{params[:path]}"
}))
rescue Excon::Errors::Unauthorized => error
if error.response.body != 'Bad username or password'
@openstack_must_reauthenticate = true
authenticate
retry
else
raise error
end
rescue Excon::Errors::HTTPStatusError => error
raise case error
when Excon::Errors::NotFound
Fog::Compute::OpenStack::NotFound.slurp(error)
else
error
end
end
unless response.body.empty?
response.body = MultiJson.decode(response.body)
end
response
end
set_tenant(tenant)
click to toggle source
def set_tenant(tenant)
@openstack_must_reauthenticate = true
@openstack_tenant = tenant.to_s
authenticate
end
update_quota(tenant_id, options = {})
click to toggle source
def update_quota(tenant_id, options = {})
options['tenant_id'] = tenant_id
request(
:body => Fog::JSON.encode({ 'quota_set' => options }),
:expects => 200,
:method => 'PUT',
:path => "/os-quota-sets/#{tenant_id}"
)
end