diff options
Diffstat (limited to 'openstackclient/compute')
| -rw-r--r-- | openstackclient/compute/v2/security_group.py | 54 | ||||
| -rw-r--r-- | openstackclient/compute/v2/server.py | 10 | ||||
| -rw-r--r-- | openstackclient/compute/v2/service.py | 2 |
3 files changed, 44 insertions, 22 deletions
diff --git a/openstackclient/compute/v2/security_group.py b/openstackclient/compute/v2/security_group.py index e3f542b5..6395e102 100644 --- a/openstackclient/compute/v2/security_group.py +++ b/openstackclient/compute/v2/security_group.py @@ -62,6 +62,23 @@ def _xform_security_group_rule(sgroup): return info +def _xform_and_trim_security_group_rule(sgroup): + info = _xform_security_group_rule(sgroup) + # Trim parent security group ID since caller has this information. + info.pop('parent_group_id', None) + # Trim keys with empty string values. + keys_to_trim = [ + 'ip_protocol', + 'ip_range', + 'port_range', + 'remote_security_group', + ] + for key in keys_to_trim: + if key in info and not info[key]: + info.pop(key) + return info + + class CreateSecurityGroup(show.ShowOne): """Create a new security group""" @@ -276,6 +293,7 @@ class ListSecurityGroupRule(lister.Lister): parser.add_argument( 'group', metavar='<group>', + nargs='?', help='List all rules in this security group (name or ID)', ) return parser @@ -284,26 +302,35 @@ class ListSecurityGroupRule(lister.Lister): self.log.debug("take_action(%s)", parsed_args) compute_client = self.app.client_manager.compute - group = utils.find_resource( - compute_client.security_groups, - parsed_args.group, + columns = column_headers = ( + "ID", + "IP Protocol", + "IP Range", + "Port Range", + "Remote Security Group", ) + rules_to_list = [] + if parsed_args.group: + group = utils.find_resource( + compute_client.security_groups, + parsed_args.group, + ) + rules_to_list = group.rules + else: + columns = columns + ('parent_group_id',) + column_headers = column_headers + ('Security Group',) + for group in compute_client.security_groups.list(): + rules_to_list.extend(group.rules) + # Argh, the rules are not Resources... rules = [] - for rule in group.rules: + for rule in rules_to_list: rules.append(security_group_rules.SecurityGroupRule( compute_client.security_group_rules, _xform_security_group_rule(rule), )) - columns = column_headers = ( - "ID", - "IP Protocol", - "IP Range", - "Port Range", - "Remote Security Group", - ) return (column_headers, (utils.get_item_properties( s, columns, @@ -386,11 +413,12 @@ class ShowSecurityGroup(show.ShowOne): )._info) rules = [] for r in info['rules']: - rules.append(utils.format_dict(_xform_security_group_rule(r))) + formatted_rule = _xform_and_trim_security_group_rule(r) + rules.append(utils.format_dict(formatted_rule)) # Format rules into a list of strings info.update( - {'rules': rules} + {'rules': utils.format_list(rules, separator='\n')} ) # Map 'tenant_id' column to 'project_id' info.update( diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py index be0ad8cb..7afd18f2 100644 --- a/openstackclient/compute/v2/server.py +++ b/openstackclient/compute/v2/server.py @@ -257,10 +257,6 @@ class CreateServer(show.ShowOne): log = logging.getLogger(__name__ + '.CreateServer') - def _is_neutron_enabled(self): - service_catalog = self.app.client_manager.auth_ref.service_catalog - return 'network' in service_catalog.get_endpoints() - def get_parser(self, prog_name): parser = super(CreateServer, self).get_parser(prog_name) parser.add_argument( @@ -460,8 +456,6 @@ class CreateServer(show.ShowOne): block_device_mapping.update({dev_key: block_volume}) nics = [] - if parsed_args.nic: - neutron_enabled = self._is_neutron_enabled() for nic_str in parsed_args.nic: nic_info = {"net-id": "", "v4-fixed-ip": "", "v6-fixed-ip": "", "port-id": ""} @@ -471,7 +465,7 @@ class CreateServer(show.ShowOne): msg = _("either net-id or port-id should be specified " "but not both") raise exceptions.CommandError(msg) - if neutron_enabled: + if self.app.client_manager.is_network_endpoint_enabled(): network_client = self.app.client_manager.network if nic_info["net-id"]: net = network_client.find_network( @@ -489,7 +483,7 @@ class CreateServer(show.ShowOne): ).id if nic_info["port-id"]: msg = _("can't create server with port specified " - "since neutron not enabled") + "since network endpoint not enabled") raise exceptions.CommandError(msg) nics.append(nic_info) diff --git a/openstackclient/compute/v2/service.py b/openstackclient/compute/v2/service.py index 0a3a5fe4..af3e940a 100644 --- a/openstackclient/compute/v2/service.py +++ b/openstackclient/compute/v2/service.py @@ -100,7 +100,7 @@ class SetService(command.Command): "--enable", dest="enabled", default=True, - help="Enable a service", + help="Enable a service (default)", action="store_true") enabled_group.add_argument( "--disable", |
