mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
refactor image lookup code.
This commit is contained in:
parent
23d4c7c95e
commit
e3fef7fc8c
2 changed files with 34 additions and 8 deletions
|
@ -12,6 +12,37 @@ module Fog
|
|||
attribute :creation_timestamp, :aliases => 'creationTimestamp'
|
||||
attribute :description
|
||||
attribute :preferred_kernel, :aliases => 'preferredKernel'
|
||||
attribute :project
|
||||
|
||||
def reload
|
||||
requires :name
|
||||
|
||||
data = {}
|
||||
if project
|
||||
data = service.get_image(name, project).body
|
||||
elsif
|
||||
[ 'google', 'debian-cloud', 'centos-cloud' ].each do |owner|
|
||||
begin
|
||||
data = service.get_image(name, owner).body
|
||||
data[:project] = owner
|
||||
rescue
|
||||
end
|
||||
end
|
||||
end
|
||||
self.merge_attributes(data)
|
||||
|
||||
self
|
||||
end
|
||||
|
||||
def save
|
||||
requires :name
|
||||
|
||||
reload
|
||||
end
|
||||
|
||||
def resource_url
|
||||
"#{self.project}/global/images/#{name}"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,14 +20,9 @@ module Fog
|
|||
zone_name, machine_name, metadata,
|
||||
network_name=@default_network)
|
||||
|
||||
# We need to get the right owner for an image.
|
||||
owners = [ @project, 'google', 'debian-cloud', 'centos-cloud' ]
|
||||
@image_url = @api_url + "google/global/images/#{image_name}"
|
||||
for owner in owners do
|
||||
if self.get_image(image_name, owner).status == 200
|
||||
@image_url = @api_url + owner + "/global/images/#{image_name}"
|
||||
end
|
||||
end
|
||||
# We don't know the owner of the image.
|
||||
image = images.create({:name => image_name})
|
||||
@image_url = @api_url + image.resource_url
|
||||
|
||||
api_method = @compute.instances.insert
|
||||
parameters = {
|
||||
|
|
Loading…
Add table
Reference in a new issue