*-list command shows only limited fields normally.
Bug #1036051 We add list_columns in list commands to limit the output columns. The behaviour is overriden if we use -c in command. Change-Id: I0fa6c73cd7270d86aff01d3790d59c8d4e8a235a
This commit is contained in:
parent
5e2f6fd375
commit
62f508939e
@ -74,11 +74,11 @@ tenant_id=tenant_a
|
|||||||
tenant_id_b=tenant_b
|
tenant_id_b=tenant_b
|
||||||
quantum quota-update --tenant_id $tenant_id --network 30 || die "fail to update quota for tenant $tenant_id"
|
quantum quota-update --tenant_id $tenant_id --network 30 || die "fail to update quota for tenant $tenant_id"
|
||||||
quantum quota-update --tenant_id $tenant_id_b --network 20 || die "fail to update quota for tenant $tenant_id"
|
quantum quota-update --tenant_id $tenant_id_b --network 20 || die "fail to update quota for tenant $tenant_id"
|
||||||
networks=`quantum quota-list | grep $tenant_id | awk '{print $2}'`
|
networks=`quantum quota-list -c network -c tenant_id | grep $tenant_id | awk '{print $2}'`
|
||||||
if [ $networks -ne 30 ]; then
|
if [ $networks -ne 30 ]; then
|
||||||
die "networks quota should be 30"
|
die "networks quota should be 30"
|
||||||
fi
|
fi
|
||||||
networks=`quantum quota-list | grep $tenant_id_b | awk '{print $2}'`
|
networks=`quantum quota-list -c network -c tenant_id | grep $tenant_id_b | awk '{print $2}'`
|
||||||
if [ $networks -ne 20 ]; then
|
if [ $networks -ne 20 ]; then
|
||||||
die "networks quota should be 20"
|
die "networks quota should be 20"
|
||||||
fi
|
fi
|
||||||
@ -100,7 +100,7 @@ if [ "t$NOAUTH" = "t" ]; then
|
|||||||
die "ports quota should be 99"
|
die "ports quota should be 99"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ports=`quantum quota-list | grep 99 | awk '{print $4}'`
|
ports=`quantum quota-list -c port | grep 99 | awk '{print $2}'`
|
||||||
if [ $ports -ne 99 ]; then
|
if [ $ports -ne 99 ]; then
|
||||||
die "ports quota should be 99"
|
die "ports quota should be 99"
|
||||||
fi
|
fi
|
||||||
|
@ -339,6 +339,7 @@ class ListCommand(QuantumCommand, lister.Lister):
|
|||||||
resource = None
|
resource = None
|
||||||
log = None
|
log = None
|
||||||
_formatters = None
|
_formatters = None
|
||||||
|
list_columns = []
|
||||||
|
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(ListCommand, self).get_parser(prog_name)
|
parser = super(ListCommand, self).get_parser(prog_name)
|
||||||
@ -374,7 +375,13 @@ class ListCommand(QuantumCommand, lister.Lister):
|
|||||||
info = data[collection]
|
info = data[collection]
|
||||||
_columns = len(info) > 0 and sorted(info[0].keys()) or []
|
_columns = len(info) > 0 and sorted(info[0].keys()) or []
|
||||||
if not _columns:
|
if not _columns:
|
||||||
|
# clean the parsed_args.columns so that cliff will not break
|
||||||
parsed_args.columns = []
|
parsed_args.columns = []
|
||||||
|
elif not parsed_args.columns and self.list_columns:
|
||||||
|
# if no -c(s) by user and list_columns, we use columns in
|
||||||
|
# both list_columns and returned resource.
|
||||||
|
# Also Keep their order the same as in list_columns
|
||||||
|
_columns = [x for x in self.list_columns if x in _columns]
|
||||||
return (_columns, (utils.get_item_properties(
|
return (_columns, (utils.get_item_properties(
|
||||||
s, _columns, formatters=self._formatters, )
|
s, _columns, formatters=self._formatters, )
|
||||||
for s in info), )
|
for s in info), )
|
||||||
|
@ -38,6 +38,7 @@ class ListNetwork(ListCommand):
|
|||||||
resource = 'network'
|
resource = 'network'
|
||||||
log = logging.getLogger(__name__ + '.ListNetwork')
|
log = logging.getLogger(__name__ + '.ListNetwork')
|
||||||
_formatters = {'subnets': _format_subnets, }
|
_formatters = {'subnets': _format_subnets, }
|
||||||
|
list_columns = ['id', 'name', 'tenant_id', 'subnets']
|
||||||
|
|
||||||
|
|
||||||
class ShowNetwork(ShowCommand):
|
class ShowNetwork(ShowCommand):
|
||||||
|
@ -40,6 +40,7 @@ class ListPort(ListCommand):
|
|||||||
resource = 'port'
|
resource = 'port'
|
||||||
log = logging.getLogger(__name__ + '.ListPort')
|
log = logging.getLogger(__name__ + '.ListPort')
|
||||||
_formatters = {'fixed_ips': _format_fixed_ips, }
|
_formatters = {'fixed_ips': _format_fixed_ips, }
|
||||||
|
list_columns = ['id', 'name', 'mac_address', 'fixed_ips']
|
||||||
|
|
||||||
|
|
||||||
class ShowPort(ShowCommand):
|
class ShowPort(ShowCommand):
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from quantumclient.common import exceptions
|
||||||
from quantumclient.common import utils
|
from quantumclient.common import utils
|
||||||
from quantumclient.quantum import v2_0 as quantumv20
|
from quantumclient.quantum import v2_0 as quantumv20
|
||||||
from quantumclient.quantum.v2_0 import CreateCommand
|
from quantumclient.quantum.v2_0 import CreateCommand
|
||||||
@ -59,6 +60,7 @@ class ListSubnet(ListCommand):
|
|||||||
_formatters = {'allocation_pools': _format_allocation_pools,
|
_formatters = {'allocation_pools': _format_allocation_pools,
|
||||||
'dns_nameservers': _format_dns_nameservers,
|
'dns_nameservers': _format_dns_nameservers,
|
||||||
'host_routes': _format_host_routes, }
|
'host_routes': _format_host_routes, }
|
||||||
|
list_columns = ['id', 'name', 'cidr', 'allocation_pools']
|
||||||
|
|
||||||
|
|
||||||
class ShowSubnet(ShowCommand):
|
class ShowSubnet(ShowCommand):
|
||||||
|
@ -20,7 +20,6 @@ Command-line interface to the Quantum APIs
|
|||||||
"""
|
"""
|
||||||
import argparse
|
import argparse
|
||||||
import gettext
|
import gettext
|
||||||
import itertools
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
@ -424,15 +423,8 @@ class QuantumShell(App):
|
|||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def itertools_compressdef(data, selectors):
|
|
||||||
# patch 2.6 compress('ABCDEF', [1,0,1,0,1,1]) --> A C E F
|
|
||||||
return (d for d, s in itertools.izip(data, selectors) if s)
|
|
||||||
|
|
||||||
|
|
||||||
def main(argv=sys.argv[1:]):
|
def main(argv=sys.argv[1:]):
|
||||||
try:
|
try:
|
||||||
if not getattr(itertools, 'compress', None):
|
|
||||||
setattr(itertools, 'compress', itertools_compressdef)
|
|
||||||
return QuantumShell(QUANTUM_API_VERSION).run(argv)
|
return QuantumShell(QUANTUM_API_VERSION).run(argv)
|
||||||
except exc.QuantumClientException:
|
except exc.QuantumClientException:
|
||||||
return 1
|
return 1
|
||||||
|
@ -25,6 +25,7 @@ from mox import Comparator
|
|||||||
from quantumclient.quantum import v2_0 as quantumv20
|
from quantumclient.quantum import v2_0 as quantumv20
|
||||||
from quantumclient.v2_0.client import Client
|
from quantumclient.v2_0.client import Client
|
||||||
|
|
||||||
|
|
||||||
API_VERSION = "2.0"
|
API_VERSION = "2.0"
|
||||||
FORMAT = 'json'
|
FORMAT = 'json'
|
||||||
TOKEN = 'testtoken'
|
TOKEN = 'testtoken'
|
||||||
@ -172,6 +173,27 @@ class CLITestV20Base(unittest.TestCase):
|
|||||||
self.assertTrue(myid in _str)
|
self.assertTrue(myid in _str)
|
||||||
self.assertTrue(name in _str)
|
self.assertTrue(name in _str)
|
||||||
|
|
||||||
|
def _test_list_columns(self, cmd, resources_collection,
|
||||||
|
resources_out, args=['-f', 'json']):
|
||||||
|
self.mox.StubOutWithMock(cmd, "get_client")
|
||||||
|
self.mox.StubOutWithMock(self.client.httpclient, "request")
|
||||||
|
cmd.get_client().MultipleTimes().AndReturn(self.client)
|
||||||
|
resstr = self.client.serialize(resources_out)
|
||||||
|
|
||||||
|
path = getattr(self.client, resources_collection + "_path")
|
||||||
|
self.client.httpclient.request(
|
||||||
|
end_url(path), 'GET',
|
||||||
|
body=None,
|
||||||
|
headers=ContainsKeyValue('X-Auth-Token',
|
||||||
|
TOKEN)).AndReturn((MyResp(200), resstr))
|
||||||
|
self.mox.ReplayAll()
|
||||||
|
cmd_parser = cmd.get_parser("list_" + resources_collection)
|
||||||
|
|
||||||
|
parsed_args = cmd_parser.parse_args(args)
|
||||||
|
cmd.run(parsed_args)
|
||||||
|
self.mox.VerifyAll()
|
||||||
|
self.mox.UnsetStubs()
|
||||||
|
|
||||||
def _test_list_resources(self, resources, cmd, detail=False, tags=[],
|
def _test_list_resources(self, resources, cmd, detail=False, tags=[],
|
||||||
fields_1=[], fields_2=[]):
|
fields_1=[], fields_2=[]):
|
||||||
self.mox.StubOutWithMock(cmd, "get_client")
|
self.mox.StubOutWithMock(cmd, "get_client")
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from quantumclient.common import exceptions
|
from quantumclient.common import exceptions
|
||||||
|
from quantumclient.common import utils
|
||||||
from quantumclient.tests.unit import test_cli20
|
from quantumclient.tests.unit import test_cli20
|
||||||
from quantumclient.tests.unit.test_cli20 import CLITestV20Base
|
from quantumclient.tests.unit.test_cli20 import CLITestV20Base
|
||||||
from quantumclient.tests.unit.test_cli20 import MyApp
|
from quantumclient.tests.unit.test_cli20 import MyApp
|
||||||
@ -92,7 +93,7 @@ class CLITestV20Network(CLITestV20Base):
|
|||||||
position_names, position_values,
|
position_names, position_values,
|
||||||
admin_state_up=False)
|
admin_state_up=False)
|
||||||
|
|
||||||
def test_lsit_nets_empty_with_column(self):
|
def test_list_nets_empty_with_column(self):
|
||||||
resources = "networks"
|
resources = "networks"
|
||||||
cmd = ListNetwork(MyApp(sys.stdout), None)
|
cmd = ListNetwork(MyApp(sys.stdout), None)
|
||||||
self.mox.StubOutWithMock(cmd, "get_client")
|
self.mox.StubOutWithMock(cmd, "get_client")
|
||||||
@ -146,6 +147,38 @@ class CLITestV20Network(CLITestV20Base):
|
|||||||
self._test_list_resources(resources, cmd,
|
self._test_list_resources(resources, cmd,
|
||||||
fields_1=['a', 'b'], fields_2=['c', 'd'])
|
fields_1=['a', 'b'], fields_2=['c', 'd'])
|
||||||
|
|
||||||
|
def test_list_nets_defined_column(self):
|
||||||
|
resources = 'networks'
|
||||||
|
cmd = ListNetwork(MyApp(sys.stdout), None)
|
||||||
|
returned_body = {"networks": [{"name": "buildname3",
|
||||||
|
"id": "id3",
|
||||||
|
"tenant_id": "tenant_3",
|
||||||
|
"subnets": []}]}
|
||||||
|
self._test_list_columns(cmd, resources, returned_body,
|
||||||
|
args=['-f', 'json', '-c', 'id'])
|
||||||
|
_str = self.fake_stdout.make_string()
|
||||||
|
returned_networks = utils.loads(_str)
|
||||||
|
self.assertEquals(1, len(returned_networks))
|
||||||
|
network = returned_networks[0]
|
||||||
|
self.assertEquals(1, len(network))
|
||||||
|
self.assertEquals("id", network.keys()[0])
|
||||||
|
|
||||||
|
def test_list_nets_with_default_column(self):
|
||||||
|
resources = 'networks'
|
||||||
|
cmd = ListNetwork(MyApp(sys.stdout), None)
|
||||||
|
returned_body = {"networks": [{"name": "buildname3",
|
||||||
|
"id": "id3",
|
||||||
|
"tenant_id": "tenant_3",
|
||||||
|
"subnets": []}]}
|
||||||
|
self._test_list_columns(cmd, resources, returned_body)
|
||||||
|
_str = self.fake_stdout.make_string()
|
||||||
|
returned_networks = utils.loads(_str)
|
||||||
|
self.assertEquals(1, len(returned_networks))
|
||||||
|
network = returned_networks[0]
|
||||||
|
self.assertEquals(4, len(network))
|
||||||
|
self.assertEquals(0, len(set(network) ^
|
||||||
|
set(cmd.list_columns)))
|
||||||
|
|
||||||
def test_update_network_exception(self):
|
def test_update_network_exception(self):
|
||||||
"""Update net: myid."""
|
"""Update net: myid."""
|
||||||
resource = 'network'
|
resource = 'network'
|
||||||
|
@ -439,7 +439,7 @@ class Client(object):
|
|||||||
# Add format and tenant_id
|
# Add format and tenant_id
|
||||||
action += ".%s" % self.format
|
action += ".%s" % self.format
|
||||||
action = self.action_prefix + action
|
action = self.action_prefix + action
|
||||||
if type(params) is dict:
|
if type(params) is dict and params:
|
||||||
action += '?' + urllib.urlencode(params, doseq=1)
|
action += '?' + urllib.urlencode(params, doseq=1)
|
||||||
if body:
|
if body:
|
||||||
body = self.serialize(body)
|
body = self.serialize(body)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
cliff>=0.6.0
|
cliff>=1.2.1
|
||||||
argparse
|
argparse
|
||||||
httplib2
|
httplib2
|
||||||
prettytable>=0.6.0
|
prettytable>=0.6.0
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
distribute>=0.6.24
|
distribute>=0.6.24
|
||||||
cliff>=0.6.0
|
cliff-tablib>=1.0
|
||||||
argparse
|
|
||||||
httplib2
|
|
||||||
prettytable>=0.6.0
|
|
||||||
simplejson
|
|
||||||
mox
|
mox
|
||||||
nose
|
nose
|
||||||
nose-exclude
|
nose-exclude
|
||||||
|
Loading…
Reference in New Issue
Block a user