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

Added Openstack compute support for add_security_group and remove_security_group

This commit is contained in:
Adan Saenz 2014-01-13 12:27:14 -06:00
parent 612e33ac17
commit 7cff96bfd3
5 changed files with 66 additions and 0 deletions

View file

@ -74,6 +74,8 @@ module Fog
request :server_diagnostics request :server_diagnostics
request :boot_from_snapshot request :boot_from_snapshot
request :reset_server_state request :reset_server_state
request :add_security_group
request :remove_security_group
# Server Extenstions # Server Extenstions
request :get_console_output request :get_console_output

View file

@ -0,0 +1,24 @@
module Fog
module Compute
class OpenStack
class Real
def add_security_group(server_id, group_name)
body = {'addSecurityGroup' => { "name" => group_name } }
server_action(server_id, body)
end
end
class Mock
def update_server(server_id, group_name)
response = Excon::Response.new
response.status = 200
response
end
end
end
end
end

View file

@ -0,0 +1,24 @@
module Fog
module Compute
class OpenStack
class Real
def remove_security_group(server_id, group_name)
body = {'removeSecurityGroup' => { "name" => group_name } }
server_action(server_id, body)
end
end
class Mock
def update_server(server_id, group_name)
response = Excon::Response.new
response.status = 200
response
end
end
end
end
end

View file

@ -35,3 +35,8 @@ def set_password_enabled
pw_enabled = ENV['OPENSTACK_SET_PASSWORD_ENABLED'] || "true" pw_enabled = ENV['OPENSTACK_SET_PASSWORD_ENABLED'] || "true"
return pw_enabled == "true" return pw_enabled == "true"
end end
def get_security_group_ref
compute = Fog::Compute[:openstack]
ENV['OPENSTACK_SECURITY_GROUP_REF'] || compute.list_security_groups.body['security_groups'].first['name']
end

View file

@ -49,6 +49,7 @@ Shindo.tests('Fog::Compute[:openstack] | server requests', ['openstack']) do
@image_id = get_image_ref @image_id = get_image_ref
@snapshot_id = nil @snapshot_id = nil
@flavor_id = get_flavor_ref @flavor_id = get_flavor_ref
@security_group_name = get_security_group_ref
tests('#create_server("test", #{@image_id} , 19)').formats(@create_format, false) do tests('#create_server("test", #{@image_id} , 19)').formats(@create_format, false) do
data = Fog::Compute[:openstack].create_server("test", @image_id, @flavor_id).body['server'] data = Fog::Compute[:openstack].create_server("test", @image_id, @flavor_id).body['server']
@ -112,6 +113,16 @@ Shindo.tests('Fog::Compute[:openstack] | server requests', ['openstack']) do
Fog::Compute[:openstack].update_server(@server_id, :name => 'fogupdatedserver') Fog::Compute[:openstack].update_server(@server_id, :name => 'fogupdatedserver')
end end
Fog::Compute[:openstack].servers.get(@server_id).wait_for { ready? } Fog::Compute[:openstack].servers.get(@server_id).wait_for { ready? }
#ADD SECURITY GROUP
tests("#add_security_group(#{@server_id}, #{@security_group_name})").succeeds do
Fog::Compute[:openstack].add_security_group(@server_id, @security_group_name)
end
#REMOVE SECURITY GROUP
tests("#remove_security_group(#{@server_id}, #{@security_group_name})").succeeds do
Fog::Compute[:openstack].remove_security_group(@server_id, @security_group_name)
end
#CREATE IMAGE WITH METADATA #CREATE IMAGE WITH METADATA
tests("#create_image(#{@server_id}, 'fog')").formats('image' => @image_format) do tests("#create_image(#{@server_id}, 'fog')").formats('image' => @image_format) do