Skip to content

Commit 7cff96b

Browse files
author
Adan Saenz
committed
Added Openstack compute support for add_security_group and remove_security_group
1 parent 612e33a commit 7cff96b

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed

lib/fog/openstack/compute.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ class OpenStack < Fog::Service
7474
request :server_diagnostics
7575
request :boot_from_snapshot
7676
request :reset_server_state
77+
request :add_security_group
78+
request :remove_security_group
7779

7880
# Server Extenstions
7981
request :get_console_output
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module Fog
2+
module Compute
3+
class OpenStack
4+
class Real
5+
6+
def add_security_group(server_id, group_name)
7+
body = {'addSecurityGroup' => { "name" => group_name } }
8+
server_action(server_id, body)
9+
end
10+
11+
end
12+
13+
class Mock
14+
15+
def update_server(server_id, group_name)
16+
response = Excon::Response.new
17+
response.status = 200
18+
response
19+
end
20+
21+
end
22+
end
23+
end
24+
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module Fog
2+
module Compute
3+
class OpenStack
4+
class Real
5+
6+
def remove_security_group(server_id, group_name)
7+
body = {'removeSecurityGroup' => { "name" => group_name } }
8+
server_action(server_id, body)
9+
end
10+
11+
end
12+
13+
class Mock
14+
15+
def update_server(server_id, group_name)
16+
response = Excon::Response.new
17+
response.status = 200
18+
response
19+
end
20+
21+
end
22+
end
23+
end
24+
end

tests/openstack/requests/compute/helper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,8 @@ def set_password_enabled
3535
pw_enabled = ENV['OPENSTACK_SET_PASSWORD_ENABLED'] || "true"
3636
return pw_enabled == "true"
3737
end
38+
39+
def get_security_group_ref
40+
compute = Fog::Compute[:openstack]
41+
ENV['OPENSTACK_SECURITY_GROUP_REF'] || compute.list_security_groups.body['security_groups'].first['name']
42+
end

tests/openstack/requests/compute/server_tests.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
@image_id = get_image_ref
5050
@snapshot_id = nil
5151
@flavor_id = get_flavor_ref
52+
@security_group_name = get_security_group_ref
5253

5354
tests('#create_server("test", #{@image_id} , 19)').formats(@create_format, false) do
5455
data = Fog::Compute[:openstack].create_server("test", @image_id, @flavor_id).body['server']
@@ -112,6 +113,16 @@
112113
Fog::Compute[:openstack].update_server(@server_id, :name => 'fogupdatedserver')
113114
end
114115
Fog::Compute[:openstack].servers.get(@server_id).wait_for { ready? }
116+
117+
#ADD SECURITY GROUP
118+
tests("#add_security_group(#{@server_id}, #{@security_group_name})").succeeds do
119+
Fog::Compute[:openstack].add_security_group(@server_id, @security_group_name)
120+
end
121+
122+
#REMOVE SECURITY GROUP
123+
tests("#remove_security_group(#{@server_id}, #{@security_group_name})").succeeds do
124+
Fog::Compute[:openstack].remove_security_group(@server_id, @security_group_name)
125+
end
115126

116127
#CREATE IMAGE WITH METADATA
117128
tests("#create_image(#{@server_id}, 'fog')").formats('image' => @image_format) do

0 commit comments

Comments
 (0)