Merge "add multi-delete support for compute/image/net/volume"

This commit is contained in:
Jenkins 2014-12-23 22:23:45 +00:00 committed by Gerrit Code Review
commit a24d6e7c6f
12 changed files with 71 additions and 58 deletions

View File

@ -117,15 +117,15 @@ Create a new server
:option:`<server-name>`
New server name
server delete
-------------
server(s) delete
----------------
Delete server command
Delete server(s) command
.. code:: bash
os server delete
<server>
<server> [<server> ...]
:option:`<server>`
Server (name or ID)

View File

@ -511,25 +511,27 @@ class CreateServerImage(show.ShowOne):
class DeleteServer(command.Command):
"""Delete server command"""
"""Delete server(s)"""
log = logging.getLogger(__name__ + '.DeleteServer')
def get_parser(self, prog_name):
parser = super(DeleteServer, self).get_parser(prog_name)
parser.add_argument(
'server',
'servers',
metavar='<server>',
help=_('Server (name or ID)'),
nargs="+",
help=_('Server(s) to delete (name or ID)'),
)
return parser
def take_action(self, parsed_args):
self.log.debug('take_action(%s)', parsed_args)
compute_client = self.app.client_manager.compute
server = utils.find_resource(
compute_client.servers, parsed_args.server)
compute_client.servers.delete(server.id)
for server in parsed_args.servers:
server_obj = utils.find_resource(
compute_client.servers, server)
compute_client.servers.delete(server_obj.id)
return

View File

@ -262,16 +262,17 @@ class CreateImage(show.ShowOne):
class DeleteImage(command.Command):
"""Delete an image"""
"""Delete image(s)"""
log = logging.getLogger(__name__ + ".DeleteImage")
def get_parser(self, prog_name):
parser = super(DeleteImage, self).get_parser(prog_name)
parser.add_argument(
"image",
"images",
metavar="<image>",
help="Name or ID of image to delete",
nargs="+",
help="Image(s) to delete (name or ID)",
)
return parser
@ -279,11 +280,12 @@ class DeleteImage(command.Command):
self.log.debug("take_action(%s)", parsed_args)
image_client = self.app.client_manager.image
image = utils.find_resource(
for image in parsed_args.images:
image_obj = utils.find_resource(
image_client.images,
parsed_args.image,
image,
)
image_client.images.delete(image.id)
image_client.images.delete(image_obj.id)
class ListImage(lister.Lister):

View File

@ -27,16 +27,17 @@ from openstackclient.common import utils
class DeleteImage(command.Command):
"""Delete an image"""
"""Delete image(s)"""
log = logging.getLogger(__name__ + ".DeleteImage")
def get_parser(self, prog_name):
parser = super(DeleteImage, self).get_parser(prog_name)
parser.add_argument(
"image",
"images",
metavar="<image>",
help="Name or ID of image to delete",
nargs="+",
help="Image(s) to delete (name or ID)",
)
return parser
@ -44,11 +45,12 @@ class DeleteImage(command.Command):
self.log.debug("take_action(%s)", parsed_args)
image_client = self.app.client_manager.image
image = utils.find_resource(
for image in parsed_args.images:
image_obj = utils.find_resource(
image_client.images,
parsed_args.image,
image,
)
image_client.images.delete(image.id)
image_client.images.delete(image_obj.id)
class ListImage(lister.Lister):

View File

@ -86,25 +86,26 @@ class CreateNetwork(show.ShowOne):
class DeleteNetwork(command.Command):
"""Delete a network"""
"""Delete network(s)"""
log = logging.getLogger(__name__ + '.DeleteNetwork')
def get_parser(self, prog_name):
parser = super(DeleteNetwork, self).get_parser(prog_name)
parser.add_argument(
'identifier',
'networks',
metavar="<network>",
help=("Name or identifier of network to delete")
nargs="+",
help=("Network(s) to delete (name or ID)")
)
return parser
def take_action(self, parsed_args):
self.log.debug('take_action(%s)' % parsed_args)
client = self.app.client_manager.network
_id = common.find(client, 'network', 'networks',
parsed_args.identifier)
delete_method = getattr(client, "delete_network")
for network in parsed_args.networks:
_id = common.find(client, 'network', 'networks', network)
delete_method(_id)
return

View File

@ -232,7 +232,7 @@ class TestServerDelete(TestServer):
compute_fakes.server_id,
]
verifylist = [
('server', compute_fakes.server_id),
('servers', [compute_fakes.server_id]),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)

View File

@ -288,7 +288,7 @@ class TestImageDelete(TestImage):
image_fakes.image_id,
]
verifylist = [
('image', image_fakes.image_id),
('images', [image_fakes.image_id]),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)

View File

@ -51,7 +51,7 @@ class TestImageDelete(TestImage):
image_fakes.image_id,
]
verifylist = [
('image', image_fakes.image_id),
('images', [image_fakes.image_id]),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)

View File

@ -120,7 +120,7 @@ class TestDeleteNetwork(common.TestNetworkBase):
FAKE_NAME,
]
verifylist = [
('identifier', FAKE_NAME),
('networks', [FAKE_NAME]),
]
lister = mock.Mock(return_value={RESOURCES: [RECORD]})
self.app.client_manager.network.list_networks = lister

View File

@ -73,24 +73,26 @@ class CreateBackup(show.ShowOne):
class DeleteBackup(command.Command):
"""Delete backup command"""
"""Delete backup(s)"""
log = logging.getLogger(__name__ + '.DeleteBackup')
def get_parser(self, prog_name):
parser = super(DeleteBackup, self).get_parser(prog_name)
parser.add_argument(
'backup',
'backups',
metavar='<backup>',
help='Name or ID of backup to delete',
nargs="+",
help='Backup(s) to delete (name or ID)',
)
return parser
def take_action(self, parsed_args):
self.log.debug('take_action(%s)', parsed_args)
volume_client = self.app.client_manager.volume
for backup in parsed_args.backups:
backup_id = utils.find_resource(volume_client.backups,
parsed_args.backup).id
backup).id
volume_client.backups.delete(backup_id)
return

View File

@ -74,24 +74,26 @@ class CreateSnapshot(show.ShowOne):
class DeleteSnapshot(command.Command):
"""Delete snapshot command"""
"""Delete snapshot(s)"""
log = logging.getLogger(__name__ + '.DeleteSnapshot')
def get_parser(self, prog_name):
parser = super(DeleteSnapshot, self).get_parser(prog_name)
parser.add_argument(
'snapshot',
'snapshots',
metavar='<snapshot>',
help='Name or ID of snapshot to delete',
nargs="+",
help='Snapshot(s) to delete (name or ID)',
)
return parser
def take_action(self, parsed_args):
self.log.debug('take_action(%s)', parsed_args)
volume_client = self.app.client_manager.volume
for snapshot in parsed_args.snapshots:
snapshot_id = utils.find_resource(volume_client.volume_snapshots,
parsed_args.snapshot).id
snapshot).id
volume_client.volume_snapshots.delete(snapshot_id)
return

View File

@ -155,35 +155,37 @@ class CreateVolume(show.ShowOne):
class DeleteVolume(command.Command):
"""Delete a volume"""
"""Delete volume(s)"""
log = logging.getLogger(__name__ + '.DeleteVolume')
def get_parser(self, prog_name):
parser = super(DeleteVolume, self).get_parser(prog_name)
parser.add_argument(
'volume',
'volumes',
metavar='<volume>',
help='Volume to delete (name or ID)',
nargs="+",
help='Volume(s) to delete (name or ID)',
)
parser.add_argument(
'--force',
dest='force',
action='store_true',
default=False,
help='Attempt forced removal of a volume, regardless of state',
help='Attempt forced removal of volume(s), regardless of state',
)
return parser
def take_action(self, parsed_args):
self.log.debug('take_action(%s)', parsed_args)
volume_client = self.app.client_manager.volume
volume = utils.find_resource(
volume_client.volumes, parsed_args.volume)
for volume in parsed_args.volumes:
volume_obj = utils.find_resource(
volume_client.volumes, volume)
if parsed_args.force:
volume_client.volumes.force_delete(volume.id)
volume_client.volumes.force_delete(volume_obj.id)
else:
volume_client.volumes.delete(volume.id)
volume_client.volumes.delete(volume_obj.id)
return