Skip to content

Commit ea2dd8e

Browse files
committed
Refactor security group create to use SDK
Refactored the 'os security group create' command to use the SDK when neutron is enabled, but continue to use the nova client when nova network is enabled. Added a release note for the change in security group rules output due to Network v2. The tenant_id column name was fixed to align with the 'os security group show' command. Change-Id: Ib29df42edcddcc73a123fff6a64743a6bfcb7fbf Partial-Bug: #1519511 Implements: blueprint neutron-client
1 parent 564c8ff commit ea2dd8e

6 files changed

Lines changed: 217 additions & 166 deletions

File tree

openstackclient/compute/v2/security_group.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -56,38 +56,6 @@ def _xform_security_group_rule(sgroup):
5656
return info
5757

5858

59-
class CreateSecurityGroup(command.ShowOne):
60-
"""Create a new security group"""
61-
62-
def get_parser(self, prog_name):
63-
parser = super(CreateSecurityGroup, self).get_parser(prog_name)
64-
parser.add_argument(
65-
"name",
66-
metavar="<name>",
67-
help="New security group name",
68-
)
69-
parser.add_argument(
70-
"--description",
71-
metavar="<description>",
72-
help="Security group description",
73-
)
74-
return parser
75-
76-
def take_action(self, parsed_args):
77-
compute_client = self.app.client_manager.compute
78-
79-
description = parsed_args.description or parsed_args.name
80-
81-
data = compute_client.security_groups.create(
82-
parsed_args.name,
83-
description,
84-
)
85-
86-
info = {}
87-
info.update(data._info)
88-
return zip(*sorted(six.iteritems(info)))
89-
90-
9159
class CreateSecurityGroupRule(command.ShowOne):
9260
"""Create a new security group rule"""
9361

openstackclient/network/v2/security_group.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,56 @@ def _get_columns(item):
9191
return tuple(display_columns), property_columns
9292

9393

94+
class CreateSecurityGroup(common.NetworkAndComputeShowOne):
95+
"""Create a new security group"""
96+
97+
def update_parser_common(self, parser):
98+
parser.add_argument(
99+
"name",
100+
metavar="<name>",
101+
help="New security group name",
102+
)
103+
parser.add_argument(
104+
"--description",
105+
metavar="<description>",
106+
help="Security group description",
107+
)
108+
return parser
109+
110+
def _get_description(self, parsed_args):
111+
if parsed_args.description is not None:
112+
return parsed_args.description
113+
else:
114+
return parsed_args.name
115+
116+
def take_action_network(self, client, parsed_args):
117+
attrs = {}
118+
attrs['name'] = parsed_args.name
119+
attrs['description'] = self._get_description(parsed_args)
120+
obj = client.create_security_group(**attrs)
121+
display_columns, property_columns = _get_columns(obj)
122+
data = utils.get_item_properties(
123+
obj,
124+
property_columns,
125+
formatters=_formatters_network
126+
)
127+
return (display_columns, data)
128+
129+
def take_action_compute(self, client, parsed_args):
130+
description = self._get_description(parsed_args)
131+
obj = client.security_groups.create(
132+
parsed_args.name,
133+
description,
134+
)
135+
display_columns, property_columns = _get_columns(obj._info)
136+
data = utils.get_dict_properties(
137+
obj._info,
138+
property_columns,
139+
formatters=_formatters_compute
140+
)
141+
return (display_columns, data)
142+
143+
94144
class DeleteSecurityGroup(common.NetworkAndComputeCommand):
95145
"""Delete a security group"""
96146

openstackclient/tests/compute/v2/test_security_group.py

Lines changed: 0 additions & 127 deletions
This file was deleted.

0 commit comments

Comments
 (0)