Merge "Add '--dhcp' and '--no-dhcp' options to os subnet list cmd"
This commit is contained in:
		| @@ -152,6 +152,7 @@ List subnets | ||||
|     os subnet list | ||||
|         [--long] | ||||
|         [--ip-version {4,6}] | ||||
|         [--dhcp | --no-dhcp] | ||||
|  | ||||
| .. option:: --long | ||||
|  | ||||
| @@ -162,6 +163,14 @@ List subnets | ||||
|     List only subnets of given IP version in output. | ||||
|     Allowed values for IP version are 4 and 6. | ||||
|  | ||||
| .. option:: --dhcp | ||||
|  | ||||
|     List subnets which have DHCP enabled | ||||
|  | ||||
| .. option:: --no-dhcp | ||||
|  | ||||
|     List subnets which have DHCP disabled | ||||
|  | ||||
| subnet set | ||||
| ---------- | ||||
|  | ||||
|   | ||||
| @@ -341,12 +341,27 @@ class ListSubnet(command.Lister): | ||||
|             help=_("List only subnets of given IP version in output." | ||||
|                    "Allowed values for IP version are 4 and 6."), | ||||
|         ) | ||||
|         dhcp_enable_group = parser.add_mutually_exclusive_group() | ||||
|         dhcp_enable_group.add_argument( | ||||
|             '--dhcp', | ||||
|             action='store_true', | ||||
|             help=_("List subnets which have DHCP enabled") | ||||
|         ) | ||||
|         dhcp_enable_group.add_argument( | ||||
|             '--no-dhcp', | ||||
|             action='store_true', | ||||
|             help=_("List subnets which have DHCP disabled") | ||||
|         ) | ||||
|         return parser | ||||
|  | ||||
|     def take_action(self, parsed_args): | ||||
|         filters = {} | ||||
|         if parsed_args.ip_version: | ||||
|             filters['ip_version'] = parsed_args.ip_version | ||||
|         if parsed_args.dhcp: | ||||
|             filters['enable_dhcp'] = True | ||||
|         elif parsed_args.no_dhcp: | ||||
|             filters['enable_dhcp'] = False | ||||
|         data = self.app.client_manager.network.subnets(**filters) | ||||
|  | ||||
|         headers = ('ID', 'Name', 'Network', 'Subnet') | ||||
|   | ||||
| @@ -584,6 +584,38 @@ class TestListSubnet(TestSubnet): | ||||
|         self.assertEqual(self.columns, columns) | ||||
|         self.assertEqual(self.data, list(data)) | ||||
|  | ||||
|     def test_subnet_list_dhcp(self): | ||||
|         arglist = [ | ||||
|             '--dhcp', | ||||
|         ] | ||||
|         verifylist = [ | ||||
|             ('dhcp', True), | ||||
|         ] | ||||
|         parsed_args = self.check_parser(self.cmd, arglist, verifylist) | ||||
|  | ||||
|         columns, data = self.cmd.take_action(parsed_args) | ||||
|         filters = {'enable_dhcp': True} | ||||
|  | ||||
|         self.network.subnets.assert_called_once_with(**filters) | ||||
|         self.assertEqual(self.columns, columns) | ||||
|         self.assertEqual(self.data, list(data)) | ||||
|  | ||||
|     def test_subnet_list_no_dhcp(self): | ||||
|         arglist = [ | ||||
|             '--no-dhcp', | ||||
|         ] | ||||
|         verifylist = [ | ||||
|             ('no_dhcp', True), | ||||
|         ] | ||||
|         parsed_args = self.check_parser(self.cmd, arglist, verifylist) | ||||
|  | ||||
|         columns, data = self.cmd.take_action(parsed_args) | ||||
|         filters = {'enable_dhcp': False} | ||||
|  | ||||
|         self.network.subnets.assert_called_once_with(**filters) | ||||
|         self.assertEqual(self.columns, columns) | ||||
|         self.assertEqual(self.data, list(data)) | ||||
|  | ||||
|  | ||||
| class TestSetSubnet(TestSubnet): | ||||
|  | ||||
|   | ||||
							
								
								
									
										7
									
								
								releasenotes/notes/bug-1610883-e6345c32a35cc290.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								releasenotes/notes/bug-1610883-e6345c32a35cc290.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | ||||
| --- | ||||
| features: | ||||
|   - | | ||||
|     Make ``subnet list`` command supports listing up subnets with | ||||
|     dhcp enabled/disabled by adding ``--dhcp`` and ``--no-dhcp`` | ||||
|     options to the command. | ||||
|     [Bug `1610883 <https://bugs.launchpad.net/bugs/1610883>`_] | ||||
		Reference in New Issue
	
	Block a user
	 Jenkins
					Jenkins