diff options
| author | Jenkins <jenkins@review.openstack.org> | 2017-05-22 23:09:02 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2017-05-22 23:09:02 +0000 |
| commit | 3fabbe9b397b12125821303ca393011f9df60368 (patch) | |
| tree | 04e3956743a844bddeeeef7773529fd7456c20e7 /openstackclient/compute/v2 | |
| parent | 78cee3fff78be6ebdbb015d0371f983a11d76c21 (diff) | |
| parent | 45496feee6ae781dc0c1df4a0e5bd71b05653748 (diff) | |
| download | python-openstackclient-3fabbe9b397b12125821303ca393011f9df60368.tar.gz | |
Merge "Create server with security group ID and name"
Diffstat (limited to 'openstackclient/compute/v2')
| -rw-r--r-- | openstackclient/compute/v2/server.py | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index 66bdeae8..e8846d16 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -407,7 +407,7 @@ class CreateServer(command.ShowOne): ) parser.add_argument( '--security-group', - metavar='<security-group-name>', + metavar='<security-group>', action='append', default=[], help=_('Security group to assign to this server (name or ID) ' @@ -695,6 +695,22 @@ class CreateServer(command.ShowOne): # decide the default behavior. nics = [] + # Check security group exist and convert ID to name + security_group_names = [] + if self.app.client_manager.is_network_endpoint_enabled(): + network_client = self.app.client_manager.network + for each_sg in parsed_args.security_group: + sg = network_client.find_security_group(each_sg, + ignore_missing=False) + # Use security group ID to avoid multiple security group have + # same name in neutron networking backend + security_group_names.append(sg.id) + else: + # Handle nova-network case + for each_sg in parsed_args.security_group: + sg = compute_client.api.security_group_find(each_sg) + security_group_names.append(sg['name']) + hints = {} for hint in parsed_args.hint: key, _sep, value = hint.partition('=') @@ -724,7 +740,7 @@ class CreateServer(command.ShowOne): reservation_id=None, min_count=parsed_args.min, max_count=parsed_args.max, - security_groups=parsed_args.security_group, + security_groups=security_group_names, userdata=userdata, key_name=parsed_args.key_name, availability_zone=parsed_args.availability_zone, |
