Merge "Allow tenant_id positional in quota syntax"
This commit is contained in:
commit
8f8063222b
@ -29,8 +29,8 @@ from neutronclient.i18n import _
|
|||||||
from neutronclient.neutron import v2_0 as neutronV20
|
from neutronclient.neutron import v2_0 as neutronV20
|
||||||
|
|
||||||
|
|
||||||
def get_tenant_id(tenant_id, client):
|
def get_tenant_id(args, client):
|
||||||
return (tenant_id if tenant_id else
|
return (args.pos_tenant_id or args.tenant_id or
|
||||||
client.get_quotas_tenant()['tenant']['tenant_id'])
|
client.get_quotas_tenant()['tenant']['tenant_id'])
|
||||||
|
|
||||||
|
|
||||||
@ -48,13 +48,15 @@ class DeleteQuota(neutronV20.NeutronCommand):
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--tenant_id',
|
'--tenant_id',
|
||||||
help=argparse.SUPPRESS)
|
help=argparse.SUPPRESS)
|
||||||
|
parser.add_argument(
|
||||||
|
'pos_tenant_id',
|
||||||
|
help=argparse.SUPPRESS, nargs='?')
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def run(self, parsed_args):
|
def run(self, parsed_args):
|
||||||
self.log.debug('run(%s)' % parsed_args)
|
self.log.debug('run(%s)' % parsed_args)
|
||||||
neutron_client = self.get_client()
|
neutron_client = self.get_client()
|
||||||
tenant_id = get_tenant_id(parsed_args.tenant_id,
|
tenant_id = get_tenant_id(parsed_args, neutron_client)
|
||||||
neutron_client)
|
|
||||||
obj_deleter = getattr(neutron_client,
|
obj_deleter = getattr(neutron_client,
|
||||||
"delete_%s" % self.resource)
|
"delete_%s" % self.resource)
|
||||||
obj_deleter(tenant_id)
|
obj_deleter(tenant_id)
|
||||||
@ -107,13 +109,18 @@ class ShowQuota(neutronV20.NeutronCommand, show.ShowOne):
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--tenant_id',
|
'--tenant_id',
|
||||||
help=argparse.SUPPRESS)
|
help=argparse.SUPPRESS)
|
||||||
|
# allow people to do neutron quota-show <tenant-id>.
|
||||||
|
# we use a different name for this because the default will
|
||||||
|
# override whatever is in the named arg otherwise.
|
||||||
|
parser.add_argument(
|
||||||
|
'pos_tenant_id',
|
||||||
|
help=argparse.SUPPRESS, nargs='?')
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def get_data(self, parsed_args):
|
def get_data(self, parsed_args):
|
||||||
self.log.debug('get_data(%s)', parsed_args)
|
self.log.debug('get_data(%s)', parsed_args)
|
||||||
neutron_client = self.get_client()
|
neutron_client = self.get_client()
|
||||||
tenant_id = get_tenant_id(parsed_args.tenant_id,
|
tenant_id = get_tenant_id(parsed_args, neutron_client)
|
||||||
neutron_client)
|
|
||||||
params = {}
|
params = {}
|
||||||
obj_shower = getattr(neutron_client,
|
obj_shower = getattr(neutron_client,
|
||||||
"show_%s" % self.resource)
|
"show_%s" % self.resource)
|
||||||
@ -183,6 +190,9 @@ class UpdateQuota(neutronV20.NeutronCommand, show.ShowOne):
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--health-monitor', metavar='health_monitors',
|
'--health-monitor', metavar='health_monitors',
|
||||||
help=_('The limit of health monitors.'))
|
help=_('The limit of health monitors.'))
|
||||||
|
parser.add_argument(
|
||||||
|
'pos_tenant_id',
|
||||||
|
help=argparse.SUPPRESS, nargs='?')
|
||||||
|
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
@ -219,8 +229,7 @@ class UpdateQuota(neutronV20.NeutronCommand, show.ShowOne):
|
|||||||
body[self.resource] = _extra_values
|
body[self.resource] = _extra_values
|
||||||
obj_updator = getattr(neutron_client,
|
obj_updator = getattr(neutron_client,
|
||||||
"update_%s" % self.resource)
|
"update_%s" % self.resource)
|
||||||
tenant_id = get_tenant_id(parsed_args.tenant_id,
|
tenant_id = get_tenant_id(parsed_args, neutron_client)
|
||||||
neutron_client)
|
|
||||||
data = obj_updator(tenant_id, body)
|
data = obj_updator(tenant_id, body)
|
||||||
if self.resource in data:
|
if self.resource in data:
|
||||||
for k, v in six.iteritems(data[self.resource]):
|
for k, v in six.iteritems(data[self.resource]):
|
||||||
|
@ -42,3 +42,20 @@ class CLITestV20Quota(test_cli20.CLITestV20Base):
|
|||||||
def test_delete_quota_get_parser(self):
|
def test_delete_quota_get_parser(self):
|
||||||
cmd = test_cli20.MyApp(sys.stdout)
|
cmd = test_cli20.MyApp(sys.stdout)
|
||||||
test_quota.DeleteQuota(cmd, None).get_parser(cmd)
|
test_quota.DeleteQuota(cmd, None).get_parser(cmd)
|
||||||
|
|
||||||
|
def test_show_quota_positional(self):
|
||||||
|
resource = 'quota'
|
||||||
|
cmd = test_quota.ShowQuota(
|
||||||
|
test_cli20.MyApp(sys.stdout), None)
|
||||||
|
args = [self.test_id]
|
||||||
|
self._test_show_resource(resource, cmd, self.test_id, args)
|
||||||
|
|
||||||
|
def test_update_quota_positional(self):
|
||||||
|
resource = 'quota'
|
||||||
|
cmd = test_quota.UpdateQuota(
|
||||||
|
test_cli20.MyApp(sys.stdout), None)
|
||||||
|
args = [self.test_id, '--network', 'test']
|
||||||
|
self.assertRaises(
|
||||||
|
exceptions.NeutronClientException, self._test_update_resource,
|
||||||
|
resource, cmd, self.test_id, args=args,
|
||||||
|
extrafields={'network': 'new'})
|
||||||
|
Loading…
Reference in New Issue
Block a user