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:
parent
612e33ac17
commit
7cff96bfd3
5 changed files with 66 additions and 0 deletions
|
@ -74,6 +74,8 @@ module Fog
|
|||
request :server_diagnostics
|
||||
request :boot_from_snapshot
|
||||
request :reset_server_state
|
||||
request :add_security_group
|
||||
request :remove_security_group
|
||||
|
||||
# Server Extenstions
|
||||
request :get_console_output
|
||||
|
|
24
lib/fog/openstack/requests/compute/add_security_group.rb
Normal file
24
lib/fog/openstack/requests/compute/add_security_group.rb
Normal 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
|
24
lib/fog/openstack/requests/compute/remove_security_group.rb
Normal file
24
lib/fog/openstack/requests/compute/remove_security_group.rb
Normal 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
|
|
@ -35,3 +35,8 @@ def set_password_enabled
|
|||
pw_enabled = ENV['OPENSTACK_SET_PASSWORD_ENABLED'] || "true"
|
||||
return pw_enabled == "true"
|
||||
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
|
||||
|
|
|
@ -49,6 +49,7 @@ Shindo.tests('Fog::Compute[:openstack] | server requests', ['openstack']) do
|
|||
@image_id = get_image_ref
|
||||
@snapshot_id = nil
|
||||
@flavor_id = get_flavor_ref
|
||||
@security_group_name = get_security_group_ref
|
||||
|
||||
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']
|
||||
|
@ -112,6 +113,16 @@ Shindo.tests('Fog::Compute[:openstack] | server requests', ['openstack']) do
|
|||
Fog::Compute[:openstack].update_server(@server_id, :name => 'fogupdatedserver')
|
||||
end
|
||||
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
|
||||
tests("#create_image(#{@server_id}, 'fog')").formats('image' => @image_format) do
|
||||
|
|
Loading…
Reference in a new issue