1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Fixes insert and delete

This commit is contained in:
Nat Welch 2013-04-29 19:41:08 -07:00
parent 2fd2d1c4ff
commit 0bb807fbde
6 changed files with 35 additions and 15 deletions

View file

@ -27,6 +27,12 @@ module Fog
end
def ready?
data = service.get_server(self.name, self.zone_name).body
data.delete("zone")
data.delete("machineType")
data.delete("image")
data.delete("networkInterfaces")
self.merge_attributes(data)
self.state == RUNNING_STATE
end
@ -46,7 +52,12 @@ module Fog
zone_name,
machine_type)
service.servers.merge_attributes()
data = service.get_server(self.name, self.zone_name).body
data.delete("zone")
data.delete("machineType")
data.delete("image")
data.delete("networkInterfaces")
service.servers.merge_attributes(data)
end
end

View file

@ -50,7 +50,7 @@ module Fog
}
server = create(defaults.merge(new_attributes))
server.wait_for { ready? }
server.wait_for(Fog.timeout, 30) { ready? }
server
end

View file

@ -14,10 +14,11 @@ module Fog
def delete_server(server_name, zone_name=nil)
if zone_name.nil?
service.list_zones.body['items'].each do |zone|
service.get_server(identity, zone['name']).body
zone_name = zone['name']
break if data["code"] == 200
list_zones.body['items'].each do |zone|
data = get_server(server_name, zone['name']).body
if data["error"].nil?
zone_name = zone['name']
end
end
end

View file

@ -12,11 +12,11 @@ module Fog
class Real
def get_image(image_name)
def get_image(image_name, project=@project)
api_method = @compute.images.get
parameters = {
'image' => image_name,
'project' => @project,
'project' => project,
}
result = self.build_result(api_method, parameters)

View file

@ -16,6 +16,13 @@ module Fog
zone_name, machine_name,
network_name=@default_network)
# We need to check if the image is owned by the user or a global image.
if get_image(image_name, @project).data['code'] == 200
image_url = @api_url + @project + "/global/images/#{image_name}"
else
image_url = @api_url + "google/global/images/#{image_name}"
end
api_method = @compute.instances.insert
parameters = {
'project' => @project,
@ -23,7 +30,7 @@ module Fog
}
body_object = {
'name' => server_name,
'image' => @api_url + @project + "/global/images/#{image_name}",
'image' => image_url,
'machineType' => @api_url + @project + "/global/machineTypes/#{machine_name}",
'networkInterfaces' => [{
'network' => @api_url + @project + "/global/networks/#{network_name}"

View file

@ -1,14 +1,15 @@
Shindo.tests("Fog::Compute[:google] | server model", ['google']) do
tests('bootstrap') do
@instance = Fog::Compute[:google].servers.bootstrap
test('#ready?') do
@insance.ready?
tests('servers') do
@instance = nil
test('#bootstrap') do
@instance = Fog::Compute[:google].servers.bootstrap
@instance.ready?
end
test('#destroy') do
@instance.destroy
response = @instance.destroy
response.body['operationType'] == 'delete'
end
end
end