Permalink
Browse files

[voxel|compute] cleanup

  • Loading branch information...
1 parent 03dbc70 commit 10f084e7fe58a591f824f7859cea17037ed3a7f6 @geemus geemus committed Feb 23, 2011
View
@@ -15,7 +15,7 @@ GEM
remote: http://rubygems.org/
specs:
builder (3.0.0)
- excon (0.5.6)
+ excon (0.5.5)
formatador (0.0.16)
json (1.5.1)
mime-types (1.16)
@@ -10,18 +10,18 @@ class Images < Fog::Collection
model Fog::Voxel::Compute::Image
def all
- data = connection.images_list
+ data = connection.images_list.body['images']
load(data)
end
def get(image_id)
- data = connection.images_list(image_id)
+ data = connection.images_list(image_id).body['images']
- if data.empty?
- nil
- else
- new(data.first)
- end
+ if data.empty?
+ nil
+ else
+ new(data.first)
+ end
end
end
@@ -4,20 +4,16 @@ module Fog
module Voxel
class Compute
- class BlockInstantiationError < StandardError; end
-
class Server < Fog::Model
identity :id
attribute :name
attribute :processing_cores
attribute :image_id
- attribute :status
attribute :facility
attribute :disk_size
- attribute :addresses
- attribute :password
+ attribute :ip_assignments, :aliases => 'ipassignments'
def initialize(attributes={})
super
@@ -31,26 +27,44 @@ def destroy
def image
requires :image_id
- connection.images_list(image_id)
+ connection.images.get(image_id)
end
def ready?
status == 'SUCCEEDED'
end
+ def private_ip_address
+ ip_assignments.select {|ip_assignment| ip_assignment['type'] == 'internal'}.first
+ end
+
+ def public_ip_address
+ ip_assignments.select {|ip_assignment| ip_assignment['type'] == 'external'}.first
+ end
+
+ def reboot
+ requires :id
+ connection.devices_power(id, :reboot)
+ true
+ end
+
def status
- connection.voxcloud_status(id).first[:status]
+ @status ||= connection.voxcloud_status(id).body['devices'].first['status']
end
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
requires :name, :image_id, :processing_cores, :facility, :disk_size
- options = { :hostname => name, :image_id => image_id, :processing_cores => processing_cores, :facility => facility, :disk_size => disk_size }
-
- data = connection.voxcloud_create(options)
+ data = connection.voxcloud_create({
+ :disk_size => disk_size,
+ :facility => facility,
+ :hostname => name,
+ :image_id => image_id,
+ :processing_cores => processing_cores
+ }).body
- merge_attributes(data.first)
+ merge_attributes(data['device'])
true
end
@@ -9,24 +9,18 @@ class Servers < Fog::Collection
model Fog::Voxel::Compute::Server
def all
- data = connection.devices_list
+ data = connection.devices_list.body['devices'].select {|device| device['type']['id'] == '3'}
load(data)
end
- def bootstrap(new_attributes = {})
- server = create(new_attributes)
- server.wait_for { ready? }
- server
- end
-
def get(device_id)
- if device_id && server = connection.devices_list(device_id)
+ if device_id && server = connection.devices_list(device_id).body['devices']
- if server.empty?
- nil
- else
- new(server.first)
- end
+ if server.empty?
+ nil
+ else
+ new(server.first)
+ end
end
end
@@ -0,0 +1,31 @@
+module Fog
+ module Parsers
+ module Voxel
+ module Compute
+
+ class Basic < Fog::Parsers::Base
+
+ def reset
+ @response = {}
+ end
+
+ def start_element(name, attrs = [])
+ super
+
+ case name
+ when 'err'
+ @response['err'] = {
+ 'code' => attr_value('code', attrs),
+ 'msg' => attr_value('msg', attrs)
+ }
+ when 'rsp'
+ @response['stat'] = attr_value('stat', attrs)
+ end
+ end
+
+ end
+
+ end
+ end
+ end
+end
@@ -7,58 +7,99 @@ class DevicesList < Fog::Parsers::Base
def reset
@device = {}
- @response = { :stat => nil, :devices => [] }
- @in_accessmethod = false
+ @response = { 'devices' => [] }
@in_storage = false
end
def start_element(name, attrs = [])
super
case name
+ when 'accessmethod'
+ @access_method = { 'type' => attr_value('type', attrs) }
+ when 'accessmethods'
+ @device['access_methods'] = []
when 'device'
@device = {
- :id => attr_value('id', attrs).to_i,
- :name => attr_value('label', attrs)
+ 'id' => attr_value('id', attrs),
+ 'label' => attr_value('label', attrs),
+ 'status' => attr_value('status', attrs)
}
- when 'type'
- @device[:type] = attr_value('id', attrs)
- when 'rsp'
- @response[:stat] = attr_value('stat', attrs)
- when 'ipassignment'
- @device[:addresses] ||= {}
- @current_type = attr_value('type', attrs).to_sym
- @device[:addresses][@current_type] = []
- when "facility"
- @device[:facility] = attr_value('code', attrs)
- when "storage"
- @in_storage = true
- when "accessmethod"
- if attr_value('type', attrs) == "admin"
- @in_accessmethod = true
+ when 'err'
+ @response['err'] = {
+ 'code' => attr_value('code', attrs),
+ 'msg' => attr_value('msg', attrs)
+ }
+ when 'cage', 'facility', 'rack', 'row', 'zone'
+ @device['location'][name] = { 'id' => attr_value('id', attrs) }
+ if code = attr_value('code', attrs)
+ @device['location'][name]['code'] = code
end
+ when 'drive'
+ @drive = { 'position' => attr_value('position', attrs) }
+ when 'ipassignment'
+ type = attr_value('type', attrs)
+ @device['ipassignments'] = []
+ @device['ipassignments'] << {
+ 'id' => attr_value('id', attrs),
+ 'type' => attr_value('type', attrs),
+ 'description' => attr_value('description', attrs),
+ }
+ when 'ipassignments'
+ @device['ipassignments'] = {}
+ when 'location'
+ @device['location'] = {}
+ when 'memory'
+ @device['memory'] = { 'size' => attr_value('size', attrs).to_i }
+ when 'model', 'type'
+ @device[name] = { 'id' => attr_value('id', attrs) }
+ when 'operating_system'
+ @device['operating_system'] = {}
+ when 'power_consumption'
+ @device[name] = attr_value('unit', attrs)
+ when 'processor'
+ @device['processor'] = {}
+ when 'rsp'
+ @response['stat'] = attr_value('stat', attrs)
+ when 'storage'
+ @device['drives'] = []
end
end
def end_element(name)
case name
+ when 'access_method'
+ @device['access_methods'] << @access_method
+ when 'architecture'
+ @device['operating_system'][name] = @value.to_i
+ when 'cage', 'facility', 'rack', 'row', 'zone'
+ @device['location'][name]['value'] = @value
+ when 'cores'
+ @device['processor'][name] = @value.to_i
+ when 'description'
+ @device[name] = @value
when 'device'
- @response[:devices] << @device
+ @response['devices'] << @device
@device = {}
+ when 'drive'
+ @device['drives'] << @drive
+ @drive = {}
when 'cores'
- @device[:processing_cores] = @value.to_i
+ @device['processing_cores'] = @value.to_i
when 'ipassignment'
- @device[:addresses][@current_type] << @value
- when "size"
- if @in_storage
- @device[:disk_size] = @value.to_i
- @in_storage = false
- end
- when "password"
- if @in_accessmethod
- @device[:password] = @value
- @in_accessmethod = false
- end
+ @device['ipassignments'].last['value'] = @value
+ when 'model', 'type'
+ @device[name]['value'] = @value
+ when 'name'
+ @device['operating_system'][name] = @value
+ when 'position'
+ @device['location'][name] = @value
+ when 'power_consumption'
+ @device[name] = [@value, @device[name]].join(' ')
+ when 'size'
+ @drive[name] = @value.to_i
+ when 'host', 'password', 'protocol', 'username'
+ @access_method[name] = @value
end
end
@@ -7,28 +7,47 @@ class ImagesList < Fog::Parsers::Base
def reset
@image = {}
- @response = { :stat => nil, :images => [] }
+ @response = { 'images' => [] }
end
def start_element(name, attrs = [])
super
case name
+ when 'err'
+ @response['err'] = {
+ 'code' => attr_value('code', attrs),
+ 'msg' => attr_value('msg', attrs)
+ }
+ when 'size'
+ @image['filesystem']['units'] = attr_value('units', attrs)
when 'image'
@image = {
- :id => attr_value('id', attrs).to_i,
- :name => attr_value('summary', attrs)
+ 'id' => attr_value('id', attrs).to_i,
+ 'summary' => attr_value('summary', attrs)
}
+ when 'filesystem', 'operating_system'
+ @image[name] = {}
when 'rsp'
- @response[:stat] = attr_value('stat', attrs)
+ @response['stat'] = attr_value('stat', attrs)
end
end
def end_element(name)
case name
+ when 'architecture'
+ @image['operating_system'][name] = @value.to_i
+ when 'admin_username', 'family', 'product_family', 'product_version', 'version'
+ @image['operating_system'][name] = @value
+ when 'description'
+ @image[name] = @value
when 'image'
- @response[:images] << @image
+ @response['images'] << @image
@image = {}
+ when 'size'
+ @image['filesystem'][name] = @value.to_i
+ when 'type'
+ @image['filesystem'][name] = @value
end
end
@@ -37,4 +56,4 @@ def end_element(name)
end
end
end
-end
+end
@@ -6,22 +6,29 @@ module Compute
class VoxcloudCreate < Fog::Parsers::Base
def reset
- @response = { :stat => nil, :device => {} }
+ @response = { 'device' => {} }
end
def start_element(name, attrs = [])
super
case name
+ when 'err'
+ @response['err'] = {
+ 'code' => attr_value('code', attrs),
+ 'msg' => attr_value('msg', attrs)
+ }
when 'rsp'
- @response[:stat] = attr_value('stat', attrs)
+ @response['stat'] = attr_value('stat', attrs)
end
end
def end_element(name)
case name
when 'id'
- @response[:device][:id] = @value
+ @response['device'][name] = @value
+ when 'last_update'
+ @response['device'][name] = Time.at(@value.to_i)
end
end
Oops, something went wrong.

0 comments on commit 10f084e

Please sign in to comment.