mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
commit
62488b4335
7 changed files with 73 additions and 46 deletions
|
@ -55,6 +55,15 @@ module Fog
|
|||
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
|
||||
|
|
|
@ -6,24 +6,24 @@ module Fog
|
|||
|
||||
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 @@ module Fog
|
|||
end
|
||||
|
||||
def state
|
||||
STATES[attributes[:state].to_i]
|
||||
STATES[attributes[:state]]
|
||||
end
|
||||
|
||||
def ready?
|
||||
|
|
|
@ -5,23 +5,23 @@ module Fog
|
|||
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 @@ module Fog
|
|||
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 @@ module Fog
|
|||
|
||||
# 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 @@ module Fog
|
|||
true
|
||||
end
|
||||
|
||||
def status
|
||||
STATUS[attributes[:state].to_i]
|
||||
def state
|
||||
STATES[attributes[:state]]
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -33,7 +33,7 @@ module Fog
|
|||
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -43,7 +43,7 @@ Shindo.tests('Fog::Compute[:ibm] | server', ['ibm']) do
|
|||
returns(true) { @server.ready? }
|
||||
end
|
||||
|
||||
tests('Fog::Compute::IBM::Server#status') do
|
||||
tests('Fog::Compute::IBM::Server#state') do
|
||||
returns("Active") { @server.state }
|
||||
end
|
||||
|
||||
|
|
|
@ -47,8 +47,8 @@ Shindo.tests('Fog::Storage[:ibm] | volume', ['ibm']) do
|
|||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue