diff options
Diffstat (limited to 'quantumclient/quantum')
| -rw-r--r-- | quantumclient/quantum/client.py | 3 | ||||
| -rw-r--r-- | quantumclient/quantum/v2_0/__init__.py | 40 | ||||
| -rw-r--r-- | quantumclient/quantum/v2_0/port.py | 15 |
3 files changed, 52 insertions, 6 deletions
diff --git a/quantumclient/quantum/client.py b/quantumclient/quantum/client.py index e2c059f..7aa1f15 100644 --- a/quantumclient/quantum/client.py +++ b/quantumclient/quantum/client.py @@ -64,5 +64,6 @@ def make_client(instance): region_name=instance._region_name, auth_url=instance._auth_url, endpoint_url=url, - token=instance._token) + token=instance._token, + auth_strategy=instance._auth_strategy) return client diff --git a/quantumclient/quantum/v2_0/__init__.py b/quantumclient/quantum/v2_0/__init__.py index 89c1c7a..e1402af 100644 --- a/quantumclient/quantum/v2_0/__init__.py +++ b/quantumclient/quantum/v2_0/__init__.py @@ -70,11 +70,12 @@ def parse_args_to_dict(values_specs): current_arg = None _values_specs = [] _value_number = 0 + _list_flag = False current_item = None for _item in values_specs: if _item.startswith('--'): if current_arg is not None: - if _value_number > 1: + if _value_number > 1 or _list_flag: current_arg.update({'nargs': '+'}) elif _value_number == 0: current_arg.update({'action': 'store_true'}) @@ -93,12 +94,16 @@ def parse_args_to_dict(values_specs): _type_str = _item.split('=', 2)[1] current_arg.update({'type': eval(_type_str)}) if _type_str == 'bool': - current_arg.update({'type': utils.__str2bool}) + current_arg.update({'type': utils.str2bool}) + elif _type_str == 'dict': + current_arg.update({'type': utils.str2dict}) continue else: raise exceptions.CommandError( "invalid values_specs %s" % ' '.join(values_specs)) - + elif _item == 'list=true': + _list_flag = True + continue if not _item.startswith('--'): if not current_item or '=' in current_item: raise exceptions.CommandError( @@ -110,9 +115,10 @@ def parse_args_to_dict(values_specs): _value_number = 1 else: _value_number = 0 + _list_flag = False _values_specs.append(_item) if current_arg is not None: - if _value_number > 1: + if _value_number > 1 or _list_flag: current_arg.update({'nargs': '+'}) elif _value_number == 0: current_arg.update({'action': 'store_true'}) @@ -188,6 +194,19 @@ class CreateCommand(QuantumCommand, show.ShowOne): print >>self.app.stdout, _('Created a new %s:' % self.resource) else: info = {'': ''} + for k, v in info.iteritems(): + if isinstance(v, list): + value = "" + for _item in v: + if value: + value += "\n" + if isinstance(_item, dict): + value += utils.dumps(_item) + else: + value += str(_item) + info[k] = value + elif v is None: + info[k] = '' return zip(*sorted(info.iteritems())) @@ -334,6 +353,19 @@ class ShowCommand(QuantumCommand, show.ShowOne): "show_%s" % self.resource) data = obj_showor(parsed_args.id, **params) if self.resource in data: + for k, v in data[self.resource].iteritems(): + if isinstance(v, list): + value = "" + for _item in v: + if value: + value += "\n" + if isinstance(_item, dict): + value += utils.dumps(_item) + else: + value += str(_item) + data[self.resource][k] = value + elif v is None: + data[self.resource][k] = '' return zip(*sorted(data[self.resource].iteritems())) else: return None diff --git a/quantumclient/quantum/v2_0/port.py b/quantumclient/quantum/v2_0/port.py index 9b8af12..bd213f8 100644 --- a/quantumclient/quantum/v2_0/port.py +++ b/quantumclient/quantum/v2_0/port.py @@ -17,6 +17,7 @@ import logging +from quantumclient import utils from quantumclient.quantum.v2_0 import CreateCommand from quantumclient.quantum.v2_0 import DeleteCommand from quantumclient.quantum.v2_0 import ListCommand @@ -26,7 +27,7 @@ from quantumclient.quantum.v2_0 import UpdateCommand def _format_fixed_ips(port): try: - return '\n'.join(port['fixed_ips']) + return '\n'.join([utils.dumps(ip) for ip in port['fixed_ips']]) except Exception: return '' @@ -75,6 +76,12 @@ class CreatePort(CreateCommand): '--device-id', help='device id of this port') parser.add_argument( + '--fixed-ip', + action='append', + help='desired Ip for this port: ' + 'subnet_id=<id>,ip_address=<ip>, ' + 'can be repeated') + parser.add_argument( 'network_id', help='Network id of this port belongs to') @@ -87,6 +94,12 @@ class CreatePort(CreateCommand): body['port'].update({'device_id': parsed_args.device_id}) if parsed_args.tenant_id: body['port'].update({'tenant_id': parsed_args.tenant_id}) + ips = [] + if parsed_args.fixed_ip: + for ip_spec in parsed_args.fixed_ip: + ips.append(utils.str2dict(ip_spec)) + if ips: + body['port'].update({'fixed_ips': ips}) return body |
