mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
cleaned out print statements. Refactored disk(s) to be created the same way as other models. Fixed wait_for on disks to properly work.
This commit is contained in:
parent
54ca80e015
commit
3d2c383816
5 changed files with 58 additions and 11 deletions
|
@ -11,11 +11,18 @@ module Fog
|
|||
attribute :kind, :aliases => 'kind'
|
||||
attribute :id, :aliases => 'id'
|
||||
attribute :creation_timestamp, :aliases => 'creationTimestamp'
|
||||
attribute :zone, :aliases => 'zone'
|
||||
attribute :zone_name, :aliases => 'zone'
|
||||
attribute :status, :aliases => 'status'
|
||||
attribute :description, :aliases => 'description'
|
||||
attribute :size_gb, :aliases => 'sizeGb'
|
||||
attribute :self_link, :aliases => 'selfLink'
|
||||
attribute :image_name, :aliases => 'image'
|
||||
|
||||
def save
|
||||
data = service.insert_disk(name, size_gb, zone_name, image_name).body
|
||||
data = service.get_disk(self.name, zone_name).body
|
||||
service.disks.merge_attributes(data)
|
||||
end
|
||||
|
||||
def get_as_boot_disk(writable=true)
|
||||
mode = writable ? 'READ_WRITE' : 'READ_ONLY'
|
||||
|
@ -28,6 +35,47 @@ module Fog
|
|||
}
|
||||
end
|
||||
|
||||
def ready?
|
||||
data = service.get_disk(self.name, self.zone_name).body
|
||||
data['zone_name'] = self.zone_name
|
||||
self.merge_attributes(data)
|
||||
self.status == RUNNING_STATE
|
||||
end
|
||||
|
||||
def wait_for(timeout=Fog.timeout, interval=1, &block)
|
||||
reload_has_succeeded = false
|
||||
duration = Fog.wait_for(timeout, interval) do # Note that duration = false if it times out
|
||||
if reload
|
||||
reload_has_succeeded = true
|
||||
instance_eval(&block)
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
if reload_has_succeeded
|
||||
return duration # false if timeout; otherwise {:duration => elapsed time }
|
||||
else
|
||||
raise Fog::Errors::Error.new("Reload failed, #{self.class} #{self.identity} not present.")
|
||||
end
|
||||
end
|
||||
|
||||
def reload
|
||||
requires :identity
|
||||
requires :zone_name
|
||||
|
||||
return unless data = begin
|
||||
collection.get(identity, zone_name)
|
||||
rescue Excon::Errors::SocketError
|
||||
nil
|
||||
end
|
||||
|
||||
new_attributes = data.attributes
|
||||
merge_attributes(new_attributes)
|
||||
self
|
||||
end
|
||||
|
||||
RUNNING_STATE = "READY"
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -21,10 +21,12 @@ module Fog
|
|||
nil
|
||||
end
|
||||
|
||||
def create(name, size, zone=@default_zone, image=nil)
|
||||
data = service.insert_disk(name, size, zone, image).body
|
||||
new(data)
|
||||
end
|
||||
|
||||
|
||||
#def create(name, size, zone=@default_zone, image=nil)
|
||||
# data = service.insert_disk(name, size, zone, image).body
|
||||
# new(data)
|
||||
#end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -13,6 +13,9 @@ module Fog
|
|||
class Real
|
||||
|
||||
def get_disk(disk_name, zone_name=@default_zone)
|
||||
if zone_name.start_with? 'http'
|
||||
zone_name = zone_name.split('/')[-1]
|
||||
end
|
||||
api_method = @compute.disks.get
|
||||
parameters = {
|
||||
'project' => @project,
|
||||
|
|
|
@ -33,12 +33,8 @@ module Fog
|
|||
|
||||
result = self.build_result(api_method, parameters,
|
||||
body_object)
|
||||
puts result.class
|
||||
disk_name = MultiJson.load(result.body)["targetLink"].split('/')[-1]
|
||||
return get_disk(disk_name, zone_name)
|
||||
#response = self.build_response(result)
|
||||
#puts response.inspect
|
||||
#response
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -62,8 +62,6 @@ module Fog
|
|||
|
||||
result = self.build_result(api_method, parameters,
|
||||
body_object=body_object)
|
||||
puts result.inspect
|
||||
puts result.request.body.inspect
|
||||
response = self.build_response(result)
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue