Skip to content

Commit

Permalink
Merge pull request fog#2571 from TranscendComputing/master
Browse files Browse the repository at this point in the history
Added OpenStack support for add/remove_security_group functionality
  • Loading branch information
Kyle Rames committed Jan 14, 2014
2 parents 8e393db + 819e2cd commit 5dad9a5
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/fog/openstack/compute.rb
Expand Up @@ -74,6 +74,8 @@ class OpenStack < Fog::Service
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
Expand Down
24 changes: 24 additions & 0 deletions lib/fog/openstack/requests/compute/add_security_group.rb
@@ -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 add_security_group(server_id, group_name)
response = Excon::Response.new
response.status = 200
response
end

end
end
end
end
24 changes: 24 additions & 0 deletions lib/fog/openstack/requests/compute/remove_security_group.rb
@@ -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 remove_security_group(server_id, group_name)
response = Excon::Response.new
response.status = 200
response
end

end
end
end
end
5 changes: 5 additions & 0 deletions tests/openstack/requests/compute/helper.rb
Expand Up @@ -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
11 changes: 11 additions & 0 deletions tests/openstack/requests/compute/server_tests.rb
Expand Up @@ -49,6 +49,7 @@
@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']
Expand Down Expand Up @@ -112,6 +113,16 @@
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
Expand Down

0 comments on commit 5dad9a5

Please sign in to comment.