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

openstack | add min_count, max_count, return_reservation_id

This commit is contained in:
Eric Stonfer 2013-09-10 10:56:38 -04:00
parent 8407d32472
commit d1ba5ab787
2 changed files with 64 additions and 25 deletions

View file

@ -13,7 +13,10 @@ module Fog
}
vanilla_options = ['metadata', 'accessIPv4', 'accessIPv6',
'availability_zone', 'user_data', 'key_name', 'adminPass', 'config_drive']
'availability_zone', 'user_data', 'key_name',
'adminPass', 'config_drive', 'min_count', 'max_count',
'return_reservation_id'
]
vanilla_options.select{|o| options[o]}.each do |key|
data['server'][key] = options[key]
end
@ -107,33 +110,37 @@ module Fog
mock_data = {
'addresses' => {},
'flavor' => {"id" => flavor_ref, "links"=>[{"href"=>"http://nova1:8774/admin/flavors/1", "rel"=>"bookmark"}]},
'id' => server_id,
'image' => {"id" => image_ref, "links"=>[{"href"=>"http://nova1:8774/admin/images/#{image_ref}", "rel"=>"bookmark"}]},
'links' => [{"href"=>"http://nova1:8774/v1.1/admin/servers/5", "rel"=>"self"}, {"href"=>"http://nova1:8774/admin/servers/5", "rel"=>"bookmark"}],
'hostId' => "123456789ABCDEF01234567890ABCDEF",
'metadata' => options['metadata'] || {},
'name' => name || "server_#{rand(999)}",
'accessIPv4' => options['accessIPv4'] || "",
'accessIPv6' => options['accessIPv6'] || "",
'progress' => 0,
'status' => 'BUILD',
'created' => '2012-09-27T00:04:18Z',
'updated' => '2012-09-27T00:04:27Z',
'user_id' => @openstack_username,
'addresses' => {},
'flavor' => {"id" => flavor_ref, "links"=>[{"href"=>"http://nova1:8774/admin/flavors/1", "rel"=>"bookmark"}]},
'id' => server_id,
'image' => {"id" => image_ref, "links"=>[{"href"=>"http://nova1:8774/admin/images/#{image_ref}", "rel"=>"bookmark"}]},
'links' => [{"href"=>"http://nova1:8774/v1.1/admin/servers/5", "rel"=>"self"}, {"href"=>"http://nova1:8774/admin/servers/5", "rel"=>"bookmark"}],
'hostId' => "123456789ABCDEF01234567890ABCDEF",
'metadata' => options['metadata'] || {},
'name' => name || "server_#{rand(999)}",
'accessIPv4' => options['accessIPv4'] || "",
'accessIPv6' => options['accessIPv6'] || "",
'progress' => 0,
'status' => 'BUILD',
'created' => '2012-09-27T00:04:18Z',
'updated' => '2012-09-27T00:04:27Z',
'user_id' => @openstack_username,
'config_drive' => options['config_drive'] || '',
}
response_data = {
'adminPass' => 'password',
'id' => server_id,
'links' => mock_data['links'],
}
response_data = {}
if options['return_reservation_id'] == 'True' then
response_data = { 'reservation_id' => "r-#{Fog::Mock.random_numbers(6).to_s}" }
else
response_data = {
'adminPass' => 'password',
'id' => server_id,
'links' => mock_data['links'],
}
end
self.data[:last_modified][:servers][server_id] = Time.now
self.data[:servers][server_id] = mock_data
if security_groups = options['security_groups'] then
groups = Array(options['security_groups']).map do |sg|
if sg.is_a?(Fog::Compute::OpenStack::SecurityGroup) then
@ -149,10 +156,13 @@ module Fog
self.data[:last_modified][:servers][server_id] = Time.now
self.data[:servers][server_id] = mock_data
response.body = { 'server' => response_data }
if options['return_reservation_id'] == 'True' then
response.body = response_data
else
response.body = { 'server' => response_data }
end
response
end
end
end
end
end

View file

@ -25,6 +25,10 @@ Shindo.tests('Fog::Compute[:openstack] | server requests', ['openstack']) do
'links' => Array,
'security_groups' => Fog::Nullable::Array,
}
@reservation_format = {
'reservation_id' => String,
}
@image_format = {
'created' => Fog::Nullable::String,
@ -59,6 +63,31 @@ Shindo.tests('Fog::Compute[:openstack] | server requests', ['openstack']) do
Fog::Compute[:openstack].get_server_details(@server_id).body['server']
end
#MULTI_CREATE
tests('#create_server("test", #{@image_id} , 19, {"min_count" => 2, "return_reservation_id" => "True"})').formats(@reservation_format, false) do
data = Fog::Compute[:openstack].create_server("test", @image_id, @flavor_id, {"min_count" => 2, "return_reservation_id" => "True"}).body
@reservation_id = data['reservation_id']
data
end
tests('#validate_multi_create') do
passed = false
@multi_create_servers = []
if Fog.mocking?
@multi_create_servers = [Fog::Mock.random_numbers(6).to_s, Fog::Mock.random_numbers(6).to_s]
else
@multi_create_servers = Fog::Compute[:openstack].list_servers_detail({'reservation_id' => @reservation_id}).body['servers'].map{|server| server['id']}
end
if (@multi_create_servers.size == 2)
passed = true
end
end
unless Fog.mocking?
@multi_create_servers.each {|server|
Fog::Compute[:openstack].servers.get(server).destroy
}
end
#LIST
#NOTE: we can remove strict=false if we remove uuid from GET /servers
tests('#list_servers').formats({'servers' => [OpenStack::Compute::Formats::SUMMARY]}, false) do