Browse Source

Add some filter options to load balancer list command

This patch adds the following options: '--vip-network-id',
'--vip-subnet-id', '--vip-qos-policy-id', '--vip-port-id',
'--provisioning-status', '--operating-status', '--provider'
to load balancer list command.

Change-Id: If48529bd32771aba248f10248d2125279a7464a3
Task: 22717
Story: 2002806
changes/22/580322/6
yanpuqing 3 years ago
parent
commit
7a816d4f43
5 changed files with 169 additions and 3 deletions
  1. +49
    -0
      octaviaclient/osc/v2/load_balancer.py
  2. +4
    -1
      octaviaclient/osc/v2/utils.py
  3. +4
    -1
      octaviaclient/tests/unit/osc/v2/constants.py
  4. +107
    -1
      octaviaclient/tests/unit/osc/v2/test_load_balancer.py
  5. +5
    -0
      releasenotes/notes/load-balancer-commands-options-83cfdbb1bc5d8998.yaml

+ 49
- 0
octaviaclient/osc/v2/load_balancer.py View File

@ -22,6 +22,12 @@ from oslo_serialization import jsonutils
from octaviaclient.osc.v2 import constants as const
from octaviaclient.osc.v2 import utils as v2_utils
PROVISIONING_STATUS = ['ACTIVE', 'DELETED', 'ERROR', 'PENDING_CREATE',
'PENDING_UPDATE', 'PENDING_DELETE']
OPERATING_STATUS = ['ONLINE', 'DRAINING', 'OFFLINE', 'DEGRADED', 'ERROR',
'NO_MONITOR']
class CreateLoadBalancer(command.ShowOne):
"""Create a load balancer"""
@ -205,6 +211,49 @@ class ListLoadBalancer(lister.Lister):
metavar='<project-id>',
help="List load balancers according to their project (name or ID)."
)
parser.add_argument(
'--vip-network-id',
metavar='<vip_network_id>',
help="List load balancers according to their VIP network "
"(name or ID)."
)
parser.add_argument(
'--vip-subnet-id',
metavar='<vip_subnet_id>',
help="List load balancers according to their VIP subnet "
"(name or ID)."
)
parser.add_argument(
'--vip-qos-policy-id',
metavar='<vip_qos_policy_id>',
help="List load balancers according to their VIP Qos policy "
"(name or ID)."
)
parser.add_argument(
'--vip-port-id',
metavar='<vip_port_id>',
help="List load balancers according to their VIP port "
"(name or ID)."
)
parser.add_argument(
'--provisioning-status',
metavar='{' + ','.join(PROVISIONING_STATUS) + '}',
choices=PROVISIONING_STATUS,
type=lambda s: s.upper(),
help="List load balancers according to their provisioning status."
)
parser.add_argument(
'--operating-status',
metavar='{' + ','.join(OPERATING_STATUS) + '}',
choices=OPERATING_STATUS,
type=lambda s: s.upper(),
help="List load balancers according to their operating status."
)
parser.add_argument(
'--provider',
metavar='<provider>',
help="List load balancers according to their provider."
)
return parser


+ 4
- 1
octaviaclient/osc/v2/utils.py View File

@ -158,7 +158,10 @@ def get_loadbalancer_attrs(client_manager, parsed_args):
),
'enable': ('admin_state_up', lambda x: True),
'disable': ('admin_state_up', lambda x: False),
'cascade': ('cascade', lambda x: True)
'cascade': ('cascade', lambda x: True),
'provisioning_status': ('provisioning_status', str),
'operating_status': ('operating_status', str),
'provider': ('provider', str)
}
_attrs = vars(parsed_args)


+ 4
- 1
octaviaclient/tests/unit/osc/v2/constants.py View File

@ -80,7 +80,10 @@ LOADBALANCER_ATTRS = {
"project_id": uuidutils.generate_uuid(dashed=True),
"vip_address": "192.0.2.124",
"vip_network_id": uuidutils.generate_uuid(dashed=True),
"provisioning_status": "ONLINE",
"vip_subnet_id": uuidutils.generate_uuid(dashed=True),
"vip_qos_policy_id": uuidutils.generate_uuid(dashed=True),
"provisioning_status": "ACTIVE",
"operating_status": "ONLINE",
"provider": "octavia",
}


+ 107
- 1
octaviaclient/tests/unit/osc/v2/test_load_balancer.py View File

@ -61,7 +61,7 @@ class TestLoadBalancerList(TestLoadBalancer):
self.assertEqual(self.columns, columns)
self.assertEqual(self.datalist, tuple(data))
def test_load_balancer_list_with_options(self):
def test_load_balancer_list_with_name(self):
arglist = ['--name', 'rainbarrel']
verifylist = [('name', 'rainbarrel')]
@ -72,6 +72,112 @@ class TestLoadBalancerList(TestLoadBalancer):
self.assertEqual(self.columns, columns)
self.assertEqual(self.datalist, tuple(data))
@mock.patch('octaviaclient.osc.v2.utils.get_loadbalancer_attrs')
def test_load_balancer_list_with_network(self, mock_client):
mock_client.return_value = {
'vip_network_id': self._lb.vip_network_id,
}
arglist = [
'--vip-network-id', self._lb.vip_network_id,
]
verify_list = [
('vip_network_id', self._lb.vip_network_id),
]
parsed_args = self.check_parser(self.cmd, arglist, verify_list)
columns, data = self.cmd.take_action(parsed_args)
self.assertEqual(self.columns, columns)
self.assertEqual(self.datalist, tuple(data))
@mock.patch('octaviaclient.osc.v2.utils.get_loadbalancer_attrs')
def test_load_balancer_list_with_subnet(self, mock_client):
mock_client.return_value = {
'vip_subnet_id': self._lb.vip_subnet_id,
}
arglist = [
'--vip-subnet-id', self._lb.vip_subnet_id,
]
verify_list = [
('vip_subnet_id', self._lb.vip_subnet_id),
]
parsed_args = self.check_parser(self.cmd, arglist, verify_list)
columns, data = self.cmd.take_action(parsed_args)
self.assertEqual(self.columns, columns)
self.assertEqual(self.datalist, tuple(data))
@mock.patch('octaviaclient.osc.v2.utils.get_loadbalancer_attrs')
def test_load_balancer_list_with_qos_policy(self, mock_client):
mock_client.return_value = {
'vip_qos_policy_id': self._lb.vip_qos_policy_id,
}
arglist = [
'--vip-qos-policy-id', self._lb.vip_qos_policy_id,
]
verify_list = [
('vip_qos_policy_id', self._lb.vip_qos_policy_id),
]
parsed_args = self.check_parser(self.cmd, arglist, verify_list)
columns, data = self.cmd.take_action(parsed_args)
self.assertEqual(self.columns, columns)
self.assertEqual(self.datalist, tuple(data))
@mock.patch('octaviaclient.osc.v2.utils.get_loadbalancer_attrs')
def test_load_balancer_list_with_provisioning_status(self, mock_client):
mock_client.return_value = {
'provisioning_status': self._lb.provisioning_status,
}
arglist = [
'--provisioning-status', 'active',
]
verify_list = [
('provisioning_status', 'ACTIVE'),
]
parsed_args = self.check_parser(self.cmd, arglist, verify_list)
columns, data = self.cmd.take_action(parsed_args)
self.assertEqual(self.columns, columns)
self.assertEqual(self.datalist, tuple(data))
@mock.patch('octaviaclient.osc.v2.utils.get_loadbalancer_attrs')
def test_load_balancer_list_with_operating_status(self, mock_client):
mock_client.return_value = {
'operating_status': self._lb.operating_status,
}
arglist = [
'--operating-status', 'ONLiNE',
]
verify_list = [
('operating_status', 'ONLINE'),
]
parsed_args = self.check_parser(self.cmd, arglist, verify_list)
columns, data = self.cmd.take_action(parsed_args)
self.assertEqual(self.columns, columns)
self.assertEqual(self.datalist, tuple(data))
@mock.patch('octaviaclient.osc.v2.utils.get_loadbalancer_attrs')
def test_load_balancer_list_with_provider(self, mock_client):
mock_client.return_value = {
'provider': self._lb.provider,
}
arglist = [
'--provider', 'octavia',
]
verify_list = [
('provider', 'octavia'),
]
parsed_args = self.check_parser(self.cmd, arglist, verify_list)
columns, data = self.cmd.take_action(parsed_args)
self.assertEqual(self.columns, columns)
self.assertEqual(self.datalist, tuple(data))
class TestLoadBalancerDelete(TestLoadBalancer):


+ 5
- 0
releasenotes/notes/load-balancer-commands-options-83cfdbb1bc5d8998.yaml View File

@ -0,0 +1,5 @@
---
features:
- Add the following options "--vip-network-id", "--vip-subnet-id",
"--vip-qos-policy-id", "--vip-port-id", "--provisioning-status",
"--operating-status", "--provider" to "load balancer list" command.

Loading…
Cancel
Save