Skip to content
Browse files

Merge pull request #811 from decklin/ibm-enhancements

Ibm enhancements
  • Loading branch information...
2 parents a48a37b + c604203 commit 62488b4335dbcd61d528ce4ea9e36097d91d86cd @decklin committed Mar 23, 2012
View
9 lib/fog/ibm/models/compute/image.rb
@@ -55,6 +55,15 @@ def ready?
state == 'Available'
end
+ def clone(name, description)
+ connection.clone_image(id, name, description).body['ImageID']
+ end
+
+ def destroy
+ requires :id
+ connection.delete_image(id).body['success']
+ end
+
end
end
end
View
38 lib/fog/ibm/models/compute/server.rb
@@ -6,24 +6,24 @@ class IBM
class Server < Fog::Compute::Server
- STATES = [
- "New", # => 0
- "Provisioning", # => 1
- "Failed", # => 2
- "Removed", # => 3
- "Rejected", # => 4
- "Active", # => 5
- "Unknown", # => 6
- "Deprovisioning", # => 7
- "Restarting", # => 8
- "Starting", # => 9
- "Stopping", # => 10
- "Stopped", # => 11
- "Deprovisioning pending", # => 12
- "Restart pending",# => 13
- "Attaching", # => 14
- "Detaching" # => 15
- ]
+ STATES = {
+ 0 => 'New',
+ 1 => 'Provisioning',
+ 2 => 'Failed',
+ 3 => 'Removed',
+ 4 => 'Rejected',
+ 5 => 'Active',
+ 6 => 'Unknown',
+ 7 => 'Deprovisioning',
+ 8 => 'Restarting',
+ 9 => 'Starting',
+ 10 => 'Stopping',
+ 11 => 'Stopped',
+ 12 => 'Deprovisioning pending',
+ 13 => 'Restart pending',
+ 14 => 'Attaching',
+ 15 => 'Detaching'
+ }
identity :id
@@ -73,7 +73,7 @@ def save
end
def state
- STATES[attributes[:state].to_i]
+ STATES[attributes[:state]]
end
def ready?
View
47 lib/fog/ibm/models/storage/volume.rb
@@ -5,23 +5,23 @@ module Storage
class IBM
class Volume < Fog::Model
- STATUS = [
- "New", # => 0
- "Creating", # => 1
- "Deleting", # => 2
- "Deleted", # => 3
- "Detached", # => 4
- "Attached", # => 5
- "Failed", # => 6
- "Deletion pending", # => 7
- "Being cloned", # => 8
- "Cloning", # => 9
- "Attaching", # => 10
- "Detaching", # => 11
- "Copying", # => 12
- "Importing", # => 13
- "Transfer retrying" # => 14
- ]
+ STATES = {
+ 0 => 'New',
+ 1 => 'Creating',
+ 2 => 'Deleting',
+ 3 => 'Deleted',
+ 4 => 'Detached',
+ 5 => 'Attached',
+ 6 => 'Failed',
+ 7 => 'Deletion pending',
+ 8 => 'Being cloned',
+ 9 => 'Cloning',
+ 10 => 'Attaching',
+ 11 => 'Detaching',
+ 12 => 'Copying',
+ 13 => 'Importing',
+ 14 => 'Transfer retrying',
+ }
identity :id
@@ -36,9 +36,12 @@ class Volume < Fog::Model
attribute :location_id, :aliases => "location"
attribute :product_codes, :aliases => "productCodes"
attribute :format
+ attribute :storage_area, :aliases => 'storageArea'
+ attribute :platform_version, :aliases => 'platformVersion'
+ attribute :clone_status, :aliases => 'cloneStatus'
def attached?
- status == "Attached"
+ state == "Attached"
end
def attach(instance_id)
@@ -73,8 +76,8 @@ def location
# Are we ready to be attached to an instance?
def ready?
- # TODO: Not sure if this is the only status we should be matching.
- status == "Detached"
+ # TODO: Not sure if this is the only state we should be matching.
+ state == "Detached"
end
def save
@@ -85,8 +88,8 @@ def save
true
end
- def status
- STATUS[attributes[:state].to_i]
+ def state
+ STATES[attributes[:state]]
end
end
View
2 lib/fog/ibm/requests/compute/clone_image.rb
@@ -33,7 +33,7 @@ def clone_image(image_id, name, description)
response = Excon::Response.new
if image_exists? image_id
id = Fog::IBM::Mock.instance_id
- self.data[:images][id] = self.data[:images][image_id].dup
+ self.data[:images][id] = self.data[:images][image_id].merge('id' => id, 'name' => name, 'description' => description)
response.status = 200
response.body = { "ImageID" => id }
else
View
17 tests/ibm/models/compute/image_tests.rb
@@ -1,10 +1,25 @@
Shindo.tests('Fog::Compute[:ibm] | image', ['ibm']) do
@image_id = '20010001'
- @image = Fog::Compute[:ibm].images.get(@image_id)
+ @clone_name = 'fog-test-clone-image-' + Time.now.to_i.to_s(32)
tests('success') do
+ tests("Fog::Compute[:ibm].images.get('#{@image_id}')") do
+ @image = Fog::Compute[:ibm].images.get(@image_id)
+ returns(@image_id) { @image.id }
+ end
+
+ tests("Fog::Compute::Image#clone") do
+ clone_id = @image.clone(@clone_name, @clone_name)
+ @clone = Fog::Compute[:ibm].images.get(clone_id)
+ returns(@clone_name) { @clone.name }
+ end
+
+ tests("Fog::Compute::Image#destroy") do
+ returns(true) { @clone.destroy }
+ end
+
end
end
View
2 tests/ibm/models/compute/server_tests.rb
@@ -43,7 +43,7 @@
returns(true) { @server.ready? }
end
- tests('Fog::Compute::IBM::Server#status') do
+ tests('Fog::Compute::IBM::Server#state') do
returns("Active") { @server.state }
end
View
4 tests/ibm/models/storage/volume_tests.rb
@@ -47,8 +47,8 @@
returns(true) { @volume.ready? }
end
- tests('Fog::Storage::IBM::Volume#status') do
- returns("Detached") { @volume.status }
+ tests('Fog::Storage::IBM::Volume#state') do
+ returns("Detached") { @volume.state }
end
tests('Fog::Storage::IBM::Volume#destroy') do

0 comments on commit 62488b4

Please sign in to comment.
Something went wrong with that request. Please try again.