Class: Fog::Compute::Voxel::Real
- Inherits:
-
Object
- Object
- Fog::Compute::Voxel::Real
- Includes:
- Collections
- Defined in:
- lib/fog/voxel/compute.rb,
lib/fog/voxel/requests/compute/images_list.rb,
lib/fog/voxel/requests/compute/devices_list.rb,
lib/fog/voxel/requests/compute/devices_power.rb,
lib/fog/voxel/requests/compute/voxcloud_create.rb,
lib/fog/voxel/requests/compute/voxcloud_delete.rb,
lib/fog/voxel/requests/compute/voxcloud_status.rb
Instance Method Summary collapse
- #create_signature(secret, options) ⇒ Object
- #devices_list(device_id = nil) ⇒ Object
- #devices_power(device_id, power_action) ⇒ Object
- #images_list(image_id = nil) ⇒ Object
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
- #request(method_name, options = {}) ⇒ Object
- #voxcloud_create(options) ⇒ Object
- #voxcloud_delete(device_id) ⇒ Object
- #voxcloud_status(device_id = nil) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/fog/voxel/compute.rb', line 75 def initialize( = {}) require 'time' require 'digest/md5' @voxel_api_key = [:voxel_api_key] @voxel_api_secret = [:voxel_api_secret] @connection_options = [:connection_options] || {} @host = [:host] || "api.voxel.net" @port = [:port] || 443 @scheme = [:scheme] || 'https' @persistent = [:persistent] || false @connection_options[:ssl_verify_peer] = false @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end |
Instance Method Details
#create_signature(secret, options) ⇒ Object
118 119 120 121 |
# File 'lib/fog/voxel/compute.rb', line 118 def create_signature(secret, ) to_sign = .keys.map { |k| k.to_s }.sort.map { |k| "#{k}#{[k.to_sym]}" }.join("") Digest::MD5.hexdigest( secret + to_sign ) end |
#devices_list(device_id = nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/fog/voxel/requests/compute/devices_list.rb', line 8 def devices_list(device_id = nil) = { :parser => Fog::Parsers::Compute::Voxel::DevicesList.new, :verbosity => 'normal' } unless device_id.nil? [:device_id] = device_id end request("voxel.devices.list", ) end |
#devices_power(device_id, power_action) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/fog/voxel/requests/compute/devices_power.rb', line 8 def devices_power(device_id, power_action) = { :device_id => device_id, :parser => Fog::Parsers::Compute::Voxel::Basic.new, :power_action => power_action, :verbosity => 'normal' } request("voxel.devices.power", ) end |
#images_list(image_id = nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/fog/voxel/requests/compute/images_list.rb', line 8 def images_list(image_id = nil) = { :parser => Fog::Parsers::Compute::Voxel::ImagesList.new, :verbosity => 'compact' } unless image_id.nil? [:verbosity] = 'extended' [:image_id] = image_id end data = request("voxel.images.list", ) if data.body['stat'] == "ok" data else raise Fog::Compute::Voxel::NotFound end end |
#request(method_name, options = {}) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/fog/voxel/compute.rb', line 93 def request(method_name, = {}) begin parser = .delete(:parser) .merge!({ :method => method_name, :timestamp => Time.now.xmlschema, :key => @voxel_api_key }) [:api_sig] = create_signature(@voxel_api_secret, ) data = @connection.request( :method => "POST", :query => , :parser => parser, :path => "/version/1.0/" ) unless data.body['stat'] == 'ok' raise Fog::Compute::Voxel::Error, "#{data.body['err']['msg']}" end data rescue Excon::Errors::HTTPStatusError => error raise case error when Excon::Errors::NotFound Fog::Compute::Voxel::NotFound.slurp(error) else error end end end |
#voxcloud_create(options) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/fog/voxel/requests/compute/voxcloud_create.rb', line 8 def voxcloud_create() [:parser] = Fog::Parsers::Compute::Voxel::VoxcloudCreate.new if .has_key?(:password) [:admin_password] = [:password] .delete(:password) end request("voxel.voxcloud.create", ) end |
#voxcloud_delete(device_id) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/fog/voxel/requests/compute/voxcloud_delete.rb', line 8 def voxcloud_delete(device_id) = { :device_id => device_id, :parser => Fog::Parsers::Compute::Voxel::VoxcloudDelete.new } request("voxel.voxcloud.delete", ) end |
#voxcloud_status(device_id = nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/fog/voxel/requests/compute/voxcloud_status.rb', line 8 def voxcloud_status(device_id = nil) = { :parser => Fog::Parsers::Compute::Voxel::VoxcloudStatus.new, :verbosity => 'compact' } unless device_id.nil? [:device_id] = device_id end request("voxel.voxcloud.status", ) end |