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:
parent
8407d32472
commit
d1ba5ab787
2 changed files with 64 additions and 25 deletions
|
@ -13,7 +13,10 @@ module Fog
|
||||||
}
|
}
|
||||||
|
|
||||||
vanilla_options = ['metadata', 'accessIPv4', 'accessIPv6',
|
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|
|
vanilla_options.select{|o| options[o]}.each do |key|
|
||||||
data['server'][key] = options[key]
|
data['server'][key] = options[key]
|
||||||
end
|
end
|
||||||
|
@ -107,33 +110,37 @@ module Fog
|
||||||
|
|
||||||
|
|
||||||
mock_data = {
|
mock_data = {
|
||||||
'addresses' => {},
|
'addresses' => {},
|
||||||
'flavor' => {"id" => flavor_ref, "links"=>[{"href"=>"http://nova1:8774/admin/flavors/1", "rel"=>"bookmark"}]},
|
'flavor' => {"id" => flavor_ref, "links"=>[{"href"=>"http://nova1:8774/admin/flavors/1", "rel"=>"bookmark"}]},
|
||||||
'id' => server_id,
|
'id' => server_id,
|
||||||
'image' => {"id" => image_ref, "links"=>[{"href"=>"http://nova1:8774/admin/images/#{image_ref}", "rel"=>"bookmark"}]},
|
'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"}],
|
'links' => [{"href"=>"http://nova1:8774/v1.1/admin/servers/5", "rel"=>"self"}, {"href"=>"http://nova1:8774/admin/servers/5", "rel"=>"bookmark"}],
|
||||||
'hostId' => "123456789ABCDEF01234567890ABCDEF",
|
'hostId' => "123456789ABCDEF01234567890ABCDEF",
|
||||||
'metadata' => options['metadata'] || {},
|
'metadata' => options['metadata'] || {},
|
||||||
'name' => name || "server_#{rand(999)}",
|
'name' => name || "server_#{rand(999)}",
|
||||||
'accessIPv4' => options['accessIPv4'] || "",
|
'accessIPv4' => options['accessIPv4'] || "",
|
||||||
'accessIPv6' => options['accessIPv6'] || "",
|
'accessIPv6' => options['accessIPv6'] || "",
|
||||||
'progress' => 0,
|
'progress' => 0,
|
||||||
'status' => 'BUILD',
|
'status' => 'BUILD',
|
||||||
'created' => '2012-09-27T00:04:18Z',
|
'created' => '2012-09-27T00:04:18Z',
|
||||||
'updated' => '2012-09-27T00:04:27Z',
|
'updated' => '2012-09-27T00:04:27Z',
|
||||||
'user_id' => @openstack_username,
|
'user_id' => @openstack_username,
|
||||||
'config_drive' => options['config_drive'] || '',
|
'config_drive' => options['config_drive'] || '',
|
||||||
}
|
}
|
||||||
|
|
||||||
response_data = {
|
response_data = {}
|
||||||
'adminPass' => 'password',
|
if options['return_reservation_id'] == 'True' then
|
||||||
'id' => server_id,
|
response_data = { 'reservation_id' => "r-#{Fog::Mock.random_numbers(6).to_s}" }
|
||||||
'links' => mock_data['links'],
|
else
|
||||||
}
|
response_data = {
|
||||||
|
'adminPass' => 'password',
|
||||||
|
'id' => server_id,
|
||||||
|
'links' => mock_data['links'],
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
self.data[:last_modified][:servers][server_id] = Time.now
|
self.data[:last_modified][:servers][server_id] = Time.now
|
||||||
self.data[:servers][server_id] = mock_data
|
self.data[:servers][server_id] = mock_data
|
||||||
|
|
||||||
if security_groups = options['security_groups'] then
|
if security_groups = options['security_groups'] then
|
||||||
groups = Array(options['security_groups']).map do |sg|
|
groups = Array(options['security_groups']).map do |sg|
|
||||||
if sg.is_a?(Fog::Compute::OpenStack::SecurityGroup) then
|
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[:last_modified][:servers][server_id] = Time.now
|
||||||
self.data[:servers][server_id] = mock_data
|
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
|
response
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -25,6 +25,10 @@ Shindo.tests('Fog::Compute[:openstack] | server requests', ['openstack']) do
|
||||||
'links' => Array,
|
'links' => Array,
|
||||||
'security_groups' => Fog::Nullable::Array,
|
'security_groups' => Fog::Nullable::Array,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@reservation_format = {
|
||||||
|
'reservation_id' => String,
|
||||||
|
}
|
||||||
|
|
||||||
@image_format = {
|
@image_format = {
|
||||||
'created' => Fog::Nullable::String,
|
'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']
|
Fog::Compute[:openstack].get_server_details(@server_id).body['server']
|
||||||
end
|
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
|
#LIST
|
||||||
#NOTE: we can remove strict=false if we remove uuid from GET /servers
|
#NOTE: we can remove strict=false if we remove uuid from GET /servers
|
||||||
tests('#list_servers').formats({'servers' => [OpenStack::Compute::Formats::SUMMARY]}, false) do
|
tests('#list_servers').formats({'servers' => [OpenStack::Compute::Formats::SUMMARY]}, false) do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue