diff options
Diffstat (limited to 'openstackclient')
| -rw-r--r-- | openstackclient/identity/v2_0/role_assignment.py | 7 | ||||
| -rw-r--r-- | openstackclient/network/v2/network_agent.py | 41 | ||||
| -rw-r--r-- | openstackclient/network/v2/subnet.py | 15 | ||||
| -rw-r--r-- | openstackclient/tests/identity/v2_0/test_role_assignment.py | 3 | ||||
| -rw-r--r-- | openstackclient/tests/network/v2/test_network_agent.py | 75 | ||||
| -rw-r--r-- | openstackclient/tests/network/v2/test_subnet.py | 32 | ||||
| -rw-r--r-- | openstackclient/tests/volume/v2/test_backup.py | 10 | ||||
| -rw-r--r-- | openstackclient/volume/v1/backup.py | 116 | ||||
| -rw-r--r-- | openstackclient/volume/v2/backup.py | 115 |
9 files changed, 375 insertions, 39 deletions
diff --git a/openstackclient/identity/v2_0/role_assignment.py b/openstackclient/identity/v2_0/role_assignment.py index 406508ac..44f55c3b 100644 --- a/openstackclient/identity/v2_0/role_assignment.py +++ b/openstackclient/identity/v2_0/role_assignment.py @@ -13,9 +13,10 @@ """Identity v2 Assignment action implementations """ -from openstackclient.common import command -from openstackclient.common import exceptions -from openstackclient.common import utils +from osc_lib.command import command +from osc_lib import exceptions +from osc_lib import utils + from openstackclient.i18n import _ # noqa diff --git a/openstackclient/network/v2/network_agent.py b/openstackclient/network/v2/network_agent.py index 1fb70a50..fdb34bb7 100644 --- a/openstackclient/network/v2/network_agent.py +++ b/openstackclient/network/v2/network_agent.py @@ -99,6 +99,47 @@ class ListNetworkAgent(command.Lister): ) for s in data)) +class SetNetworkAgent(command.Command): + """Set network agent properties""" + + def get_parser(self, prog_name): + parser = super(SetNetworkAgent, self).get_parser(prog_name) + parser.add_argument( + 'network_agent', + metavar="<network-agent>", + help=(_("Network agent to modify (ID only)")) + ) + parser.add_argument( + '--description', + metavar='<description>', + help=_("Set network agent description") + ) + admin_group = parser.add_mutually_exclusive_group() + admin_group.add_argument( + '--enable', + action='store_true', + help=_("Enable network agent") + ) + admin_group.add_argument( + '--disable', + action='store_true', + help=_("Disable network agent") + ) + return parser + + def take_action(self, parsed_args): + client = self.app.client_manager.network + obj = client.get_agent(parsed_args.network_agent, ignore_missing=False) + attrs = {} + if parsed_args.description is not None: + attrs['description'] = str(parsed_args.description) + if parsed_args.enable: + attrs['admin_state_up'] = True + if parsed_args.disable: + attrs['admin_state_up'] = False + client.update_agent(obj, **attrs) + + class ShowNetworkAgent(command.ShowOne): """Display network agent details""" diff --git a/openstackclient/network/v2/subnet.py b/openstackclient/network/v2/subnet.py index f26f6804..22452809 100644 --- a/openstackclient/network/v2/subnet.py +++ b/openstackclient/network/v2/subnet.py @@ -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') diff --git a/openstackclient/tests/identity/v2_0/test_role_assignment.py b/openstackclient/tests/identity/v2_0/test_role_assignment.py index ab48c2f4..a356ae0a 100644 --- a/openstackclient/tests/identity/v2_0/test_role_assignment.py +++ b/openstackclient/tests/identity/v2_0/test_role_assignment.py @@ -14,7 +14,8 @@ import copy import mock -from openstackclient.common import exceptions +from osc_lib import exceptions + from openstackclient.identity.v2_0 import role_assignment from openstackclient.tests import fakes from openstackclient.tests.identity.v2_0 import fakes as identity_fakes diff --git a/openstackclient/tests/network/v2/test_network_agent.py b/openstackclient/tests/network/v2/test_network_agent.py index 3cf9a530..269d4e1d 100644 --- a/openstackclient/tests/network/v2/test_network_agent.py +++ b/openstackclient/tests/network/v2/test_network_agent.py @@ -160,6 +160,81 @@ class TestListNetworkAgent(TestNetworkAgent): self.assertEqual(self.data, list(data)) +class TestSetNetworkAgent(TestNetworkAgent): + + _network_agent = ( + network_fakes.FakeNetworkAgent.create_one_network_agent()) + + def setUp(self): + super(TestSetNetworkAgent, self).setUp() + self.network.update_agent = mock.Mock(return_value=None) + self.network.get_agent = mock.Mock(return_value=self._network_agent) + + # Get the command object to test + self.cmd = network_agent.SetNetworkAgent(self.app, self.namespace) + + def test_set_nothing(self): + arglist = [ + self._network_agent.id, + ] + verifylist = [ + ('network_agent', self._network_agent.id), + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + result = self.cmd.take_action(parsed_args) + + attrs = {} + self.network.update_agent.assert_called_once_with( + self._network_agent, **attrs) + self.assertIsNone(result) + + def test_set_all(self): + arglist = [ + '--description', 'new_description', + '--enable', + self._network_agent.id, + ] + verifylist = [ + ('description', 'new_description'), + ('enable', True), + ('disable', False), + ('network_agent', self._network_agent.id), + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + result = self.cmd.take_action(parsed_args) + + attrs = { + 'description': 'new_description', + 'admin_state_up': True, + } + self.network.update_agent.assert_called_once_with( + self._network_agent, **attrs) + self.assertIsNone(result) + + def test_set_with_disable(self): + arglist = [ + '--disable', + self._network_agent.id, + ] + verifylist = [ + ('enable', False), + ('disable', True), + ('network_agent', self._network_agent.id), + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + result = self.cmd.take_action(parsed_args) + + attrs = { + 'admin_state_up': False, + } + self.network.update_agent.assert_called_once_with( + self._network_agent, **attrs) + self.assertIsNone(result) + + class TestShowNetworkAgent(TestNetworkAgent): _network_agent = ( diff --git a/openstackclient/tests/network/v2/test_subnet.py b/openstackclient/tests/network/v2/test_subnet.py index e7f3e748..ba757c98 100644 --- a/openstackclient/tests/network/v2/test_subnet.py +++ b/openstackclient/tests/network/v2/test_subnet.py @@ -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): diff --git a/openstackclient/tests/volume/v2/test_backup.py b/openstackclient/tests/volume/v2/test_backup.py index 3c2b3948..67064352 100644 --- a/openstackclient/tests/volume/v2/test_backup.py +++ b/openstackclient/tests/volume/v2/test_backup.py @@ -77,7 +77,7 @@ class TestBackupCreate(TestBackup): self.backups_mock.create.return_value = self.new_backup # Get the command object to test - self.cmd = backup.CreateBackup(self.app, None) + self.cmd = backup.CreateVolumeBackup(self.app, None) def test_backup_create(self): arglist = [ @@ -154,7 +154,7 @@ class TestBackupDelete(TestBackup): self.backups_mock.delete.return_value = None # Get the command object to mock - self.cmd = backup.DeleteBackup(self.app, None) + self.cmd = backup.DeleteVolumeBackup(self.app, None) def test_backup_delete(self): arglist = [ @@ -281,7 +281,7 @@ class TestBackupList(TestBackup): self.volumes_mock.list.return_value = [self.volume] self.backups_mock.list.return_value = self.backups # Get the command to test - self.cmd = backup.ListBackup(self.app, None) + self.cmd = backup.ListVolumeBackup(self.app, None) def test_backup_list_without_options(self): arglist = [] @@ -317,7 +317,7 @@ class TestBackupRestore(TestBackup): self.volumes_mock.get.return_value = self.volume self.restores_mock.restore.return_value = None # Get the command object to mock - self.cmd = backup.RestoreBackup(self.app, None) + self.cmd = backup.RestoreVolumeBackup(self.app, None) def test_backup_restore(self): arglist = [ @@ -370,7 +370,7 @@ class TestBackupShow(TestBackup): self.backups_mock.get.return_value = self.backup # Get the command object to test - self.cmd = backup.ShowBackup(self.app, None) + self.cmd = backup.ShowVolumeBackup(self.app, None) def test_backup_show(self): arglist = [ diff --git a/openstackclient/volume/v1/backup.py b/openstackclient/volume/v1/backup.py index 5f34a2c5..539ed369 100644 --- a/openstackclient/volume/v1/backup.py +++ b/openstackclient/volume/v1/backup.py @@ -16,6 +16,7 @@ """Volume v1 Backup action implementations""" import copy +import logging from osc_lib.command import command from osc_lib import utils @@ -24,11 +25,11 @@ import six from openstackclient.i18n import _ -class CreateBackup(command.ShowOne): - """Create new backup""" +class CreateVolumeBackup(command.ShowOne): + """Create new volume backup""" def get_parser(self, prog_name): - parser = super(CreateBackup, self).get_parser(prog_name) + parser = super(CreateVolumeBackup, self).get_parser(prog_name) parser.add_argument( 'volume', metavar='<volume>', @@ -67,11 +68,28 @@ class CreateBackup(command.ShowOne): return zip(*sorted(six.iteritems(backup._info))) -class DeleteBackup(command.Command): - """Delete backup(s)""" +class CreateBackup(CreateVolumeBackup): + """Create new backup""" + + # TODO(Huanxuan Ao): Remove this class and ``backup create`` command + # two cycles after Newton. + + # This notifies cliff to not display the help for this command + deprecated = True + + log = logging.getLogger('deprecated') + + def take_action(self, parsed_args): + self.log.warning(_('This command has been deprecated. ' + 'Please use "volume backup create" instead.')) + return super(CreateBackup, self).take_action(parsed_args) + + +class DeleteVolumeBackup(command.Command): + """Delete volume backup(s)""" def get_parser(self, prog_name): - parser = super(DeleteBackup, self).get_parser(prog_name) + parser = super(DeleteVolumeBackup, self).get_parser(prog_name) parser.add_argument( 'backups', metavar='<backup>', @@ -88,11 +106,28 @@ class DeleteBackup(command.Command): volume_client.backups.delete(backup_id) -class ListBackup(command.Lister): - """List backups""" +class DeleteBackup(DeleteVolumeBackup): + """Delete backup(s)""" + + # TODO(Huanxuan Ao): Remove this class and ``backup delete`` command + # two cycles after Newton. + + # This notifies cliff to not display the help for this command + deprecated = True + + log = logging.getLogger('deprecated') + + def take_action(self, parsed_args): + self.log.warning(_('This command has been deprecated. ' + 'Please use "volume backup delete" instead.')) + return super(DeleteBackup, self).take_action(parsed_args) + + +class ListVolumeBackup(command.Lister): + """List volume backups""" def get_parser(self, prog_name): - parser = super(ListBackup, self).get_parser(prog_name) + parser = super(ListVolumeBackup, self).get_parser(prog_name) parser.add_argument( '--long', action='store_true', @@ -142,11 +177,28 @@ class ListBackup(command.Lister): ) for s in data)) -class RestoreBackup(command.Command): - """Restore backup""" +class ListBackup(ListVolumeBackup): + """List backups""" + + # TODO(Huanxuan Ao): Remove this class and ``backup list`` command + # two cycles after Newton. + + # This notifies cliff to not display the help for this command + deprecated = True + + log = logging.getLogger('deprecated') + + def take_action(self, parsed_args): + self.log.warning(_('This command has been deprecated. ' + 'Please use "volume backup list" instead.')) + return super(ListBackup, self).take_action(parsed_args) + + +class RestoreVolumeBackup(command.Command): + """Restore volume backup""" def get_parser(self, prog_name): - parser = super(RestoreBackup, self).get_parser(prog_name) + parser = super(RestoreVolumeBackup, self).get_parser(prog_name) parser.add_argument( 'backup', metavar='<backup>', @@ -169,11 +221,28 @@ class RestoreBackup(command.Command): destination_volume.id) -class ShowBackup(command.ShowOne): - """Display backup details""" +class RestoreBackup(RestoreVolumeBackup): + """Restore backup""" + + # TODO(Huanxuan Ao): Remove this class and ``backup restore`` command + # two cycles after Newton. + + # This notifies cliff to not display the help for this command + deprecated = True + + log = logging.getLogger('deprecated') + + def take_action(self, parsed_args): + self.log.warning(_('This command has been deprecated. ' + 'Please use "volume backup restore" instead.')) + return super(RestoreBackup, self).take_action(parsed_args) + + +class ShowVolumeBackup(command.ShowOne): + """Display volume backup details""" def get_parser(self, prog_name): - parser = super(ShowBackup, self).get_parser(prog_name) + parser = super(ShowVolumeBackup, self).get_parser(prog_name) parser.add_argument( 'backup', metavar='<backup>', @@ -187,3 +256,20 @@ class ShowBackup(command.ShowOne): parsed_args.backup) backup._info.pop('links') return zip(*sorted(six.iteritems(backup._info))) + + +class ShowBackup(ShowVolumeBackup): + """Display backup details""" + + # TODO(Huanxuan Ao): Remove this class and ``backup show`` command + # two cycles after Newton. + + # This notifies cliff to not display the help for this command + deprecated = True + + log = logging.getLogger('deprecated') + + def take_action(self, parsed_args): + self.log.warning(_('This command has been deprecated. ' + 'Please use "volume backup show" instead.')) + return super(ShowBackup, self).take_action(parsed_args) diff --git a/openstackclient/volume/v2/backup.py b/openstackclient/volume/v2/backup.py index 3d27c121..07c1c94f 100644 --- a/openstackclient/volume/v2/backup.py +++ b/openstackclient/volume/v2/backup.py @@ -28,11 +28,11 @@ from openstackclient.i18n import _ LOG = logging.getLogger(__name__) -class CreateBackup(command.ShowOne): - """Create new backup""" +class CreateVolumeBackup(command.ShowOne): + """Create new volume backup""" def get_parser(self, prog_name): - parser = super(CreateBackup, self).get_parser(prog_name) + parser = super(CreateVolumeBackup, self).get_parser(prog_name) parser.add_argument( "volume", metavar="<volume>", @@ -93,11 +93,28 @@ class CreateBackup(command.ShowOne): return zip(*sorted(six.iteritems(backup._info))) -class DeleteBackup(command.Command): - """Delete backup(s)""" +class CreateBackup(CreateVolumeBackup): + """Create new backup""" + + # TODO(Huanxuan Ao): Remove this class and ``backup create`` command + # two cycles after Newton. + + # This notifies cliff to not display the help for this command + deprecated = True + + log = logging.getLogger('deprecated') + + def take_action(self, parsed_args): + self.log.warning(_('This command has been deprecated. ' + 'Please use "volume backup create" instead.')) + return super(CreateBackup, self).take_action(parsed_args) + + +class DeleteVolumeBackup(command.Command): + """Delete volume backup(s)""" def get_parser(self, prog_name): - parser = super(DeleteBackup, self).get_parser(prog_name) + parser = super(DeleteVolumeBackup, self).get_parser(prog_name) parser.add_argument( "backups", metavar="<backup>", @@ -134,11 +151,28 @@ class DeleteBackup(command.Command): raise exceptions.CommandError(msg) -class ListBackup(command.Lister): - """List backups""" +class DeleteBackup(DeleteVolumeBackup): + """Delete backup(s)""" + + # TODO(Huanxuan Ao): Remove this class and ``backup delete`` command + # two cycles after Newton. + + # This notifies cliff to not display the help for this command + deprecated = True + + log = logging.getLogger('deprecated') + + def take_action(self, parsed_args): + self.log.warning(_('This command has been deprecated. ' + 'Please use "volume backup delete" instead.')) + return super(DeleteBackup, self).take_action(parsed_args) + + +class ListVolumeBackup(command.Lister): + """List volume backups""" def get_parser(self, prog_name): - parser = super(ListBackup, self).get_parser(prog_name) + parser = super(ListVolumeBackup, self).get_parser(prog_name) parser.add_argument( "--long", action="store_true", @@ -188,11 +222,28 @@ class ListBackup(command.Lister): ) for s in data)) -class RestoreBackup(command.ShowOne): - """Restore backup""" +class ListBackup(ListVolumeBackup): + """List backups""" + + # TODO(Huanxuan Ao): Remove this class and ``backup list`` command + # two cycles after Newton. + + # This notifies cliff to not display the help for this command + deprecated = True + + log = logging.getLogger('deprecated') + + def take_action(self, parsed_args): + self.log.warning(_('This command has been deprecated. ' + 'Please use "volume backup list" instead.')) + return super(ListBackup, self).take_action(parsed_args) + + +class RestoreVolumeBackup(command.ShowOne): + """Restore volume backup""" def get_parser(self, prog_name): - parser = super(RestoreBackup, self).get_parser(prog_name) + parser = super(RestoreVolumeBackup, self).get_parser(prog_name) parser.add_argument( "backup", metavar="<backup>", @@ -213,11 +264,28 @@ class RestoreBackup(command.ShowOne): return volume_client.restores.restore(backup.id, destination_volume.id) -class ShowBackup(command.ShowOne): - """Display backup details""" +class RestoreBackup(RestoreVolumeBackup): + """Restore backup""" + + # TODO(Huanxuan Ao): Remove this class and ``backup restore`` command + # two cycles after Newton. + + # This notifies cliff to not display the help for this command + deprecated = True + + log = logging.getLogger('deprecated') + + def take_action(self, parsed_args): + self.log.warning(_('This command has been deprecated. ' + 'Please use "volume backup restore" instead.')) + return super(RestoreBackup, self).take_action(parsed_args) + + +class ShowVolumeBackup(command.ShowOne): + """Display volume backup details""" def get_parser(self, prog_name): - parser = super(ShowBackup, self).get_parser(prog_name) + parser = super(ShowVolumeBackup, self).get_parser(prog_name) parser.add_argument( "backup", metavar="<backup>", @@ -231,3 +299,20 @@ class ShowBackup(command.ShowOne): parsed_args.backup) backup._info.pop("links", None) return zip(*sorted(six.iteritems(backup._info))) + + +class ShowBackup(ShowVolumeBackup): + """Display backup details""" + + # TODO(Huanxuan Ao): Remove this class and ``backup show`` command + # two cycles after Newton. + + # This notifies cliff to not display the help for this command + deprecated = True + + log = logging.getLogger('deprecated') + + def take_action(self, parsed_args): + self.log.warning(_('This command has been deprecated. ' + 'Please use "volume backup show" instead.')) + return super(ShowBackup, self).take_action(parsed_args) |
