Merge "add multi-delete support for compute/image/net/volume"
This commit is contained in:
commit
a24d6e7c6f
@ -117,15 +117,15 @@ Create a new server
|
|||||||
:option:`<server-name>`
|
:option:`<server-name>`
|
||||||
New server name
|
New server name
|
||||||
|
|
||||||
server delete
|
server(s) delete
|
||||||
-------------
|
----------------
|
||||||
|
|
||||||
Delete server command
|
Delete server(s) command
|
||||||
|
|
||||||
.. code:: bash
|
.. code:: bash
|
||||||
|
|
||||||
os server delete
|
os server delete
|
||||||
<server>
|
<server> [<server> ...]
|
||||||
|
|
||||||
:option:`<server>`
|
:option:`<server>`
|
||||||
Server (name or ID)
|
Server (name or ID)
|
||||||
|
@ -511,25 +511,27 @@ class CreateServerImage(show.ShowOne):
|
|||||||
|
|
||||||
|
|
||||||
class DeleteServer(command.Command):
|
class DeleteServer(command.Command):
|
||||||
"""Delete server command"""
|
"""Delete server(s)"""
|
||||||
|
|
||||||
log = logging.getLogger(__name__ + '.DeleteServer')
|
log = logging.getLogger(__name__ + '.DeleteServer')
|
||||||
|
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(DeleteServer, self).get_parser(prog_name)
|
parser = super(DeleteServer, self).get_parser(prog_name)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'server',
|
'servers',
|
||||||
metavar='<server>',
|
metavar='<server>',
|
||||||
help=_('Server (name or ID)'),
|
nargs="+",
|
||||||
|
help=_('Server(s) to delete (name or ID)'),
|
||||||
)
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
self.log.debug('take_action(%s)', parsed_args)
|
self.log.debug('take_action(%s)', parsed_args)
|
||||||
compute_client = self.app.client_manager.compute
|
compute_client = self.app.client_manager.compute
|
||||||
server = utils.find_resource(
|
for server in parsed_args.servers:
|
||||||
compute_client.servers, parsed_args.server)
|
server_obj = utils.find_resource(
|
||||||
compute_client.servers.delete(server.id)
|
compute_client.servers, server)
|
||||||
|
compute_client.servers.delete(server_obj.id)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
@ -262,16 +262,17 @@ class CreateImage(show.ShowOne):
|
|||||||
|
|
||||||
|
|
||||||
class DeleteImage(command.Command):
|
class DeleteImage(command.Command):
|
||||||
"""Delete an image"""
|
"""Delete image(s)"""
|
||||||
|
|
||||||
log = logging.getLogger(__name__ + ".DeleteImage")
|
log = logging.getLogger(__name__ + ".DeleteImage")
|
||||||
|
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(DeleteImage, self).get_parser(prog_name)
|
parser = super(DeleteImage, self).get_parser(prog_name)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"image",
|
"images",
|
||||||
metavar="<image>",
|
metavar="<image>",
|
||||||
help="Name or ID of image to delete",
|
nargs="+",
|
||||||
|
help="Image(s) to delete (name or ID)",
|
||||||
)
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
@ -279,11 +280,12 @@ class DeleteImage(command.Command):
|
|||||||
self.log.debug("take_action(%s)", parsed_args)
|
self.log.debug("take_action(%s)", parsed_args)
|
||||||
|
|
||||||
image_client = self.app.client_manager.image
|
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,
|
image_client.images,
|
||||||
parsed_args.image,
|
image,
|
||||||
)
|
)
|
||||||
image_client.images.delete(image.id)
|
image_client.images.delete(image_obj.id)
|
||||||
|
|
||||||
|
|
||||||
class ListImage(lister.Lister):
|
class ListImage(lister.Lister):
|
||||||
|
@ -27,16 +27,17 @@ from openstackclient.common import utils
|
|||||||
|
|
||||||
|
|
||||||
class DeleteImage(command.Command):
|
class DeleteImage(command.Command):
|
||||||
"""Delete an image"""
|
"""Delete image(s)"""
|
||||||
|
|
||||||
log = logging.getLogger(__name__ + ".DeleteImage")
|
log = logging.getLogger(__name__ + ".DeleteImage")
|
||||||
|
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(DeleteImage, self).get_parser(prog_name)
|
parser = super(DeleteImage, self).get_parser(prog_name)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"image",
|
"images",
|
||||||
metavar="<image>",
|
metavar="<image>",
|
||||||
help="Name or ID of image to delete",
|
nargs="+",
|
||||||
|
help="Image(s) to delete (name or ID)",
|
||||||
)
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
@ -44,11 +45,12 @@ class DeleteImage(command.Command):
|
|||||||
self.log.debug("take_action(%s)", parsed_args)
|
self.log.debug("take_action(%s)", parsed_args)
|
||||||
|
|
||||||
image_client = self.app.client_manager.image
|
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,
|
image_client.images,
|
||||||
parsed_args.image,
|
image,
|
||||||
)
|
)
|
||||||
image_client.images.delete(image.id)
|
image_client.images.delete(image_obj.id)
|
||||||
|
|
||||||
|
|
||||||
class ListImage(lister.Lister):
|
class ListImage(lister.Lister):
|
||||||
|
@ -86,25 +86,26 @@ class CreateNetwork(show.ShowOne):
|
|||||||
|
|
||||||
|
|
||||||
class DeleteNetwork(command.Command):
|
class DeleteNetwork(command.Command):
|
||||||
"""Delete a network"""
|
"""Delete network(s)"""
|
||||||
|
|
||||||
log = logging.getLogger(__name__ + '.DeleteNetwork')
|
log = logging.getLogger(__name__ + '.DeleteNetwork')
|
||||||
|
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(DeleteNetwork, self).get_parser(prog_name)
|
parser = super(DeleteNetwork, self).get_parser(prog_name)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'identifier',
|
'networks',
|
||||||
metavar="<network>",
|
metavar="<network>",
|
||||||
help=("Name or identifier of network to delete")
|
nargs="+",
|
||||||
|
help=("Network(s) to delete (name or ID)")
|
||||||
)
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
self.log.debug('take_action(%s)' % parsed_args)
|
self.log.debug('take_action(%s)' % parsed_args)
|
||||||
client = self.app.client_manager.network
|
client = self.app.client_manager.network
|
||||||
_id = common.find(client, 'network', 'networks',
|
|
||||||
parsed_args.identifier)
|
|
||||||
delete_method = getattr(client, "delete_network")
|
delete_method = getattr(client, "delete_network")
|
||||||
|
for network in parsed_args.networks:
|
||||||
|
_id = common.find(client, 'network', 'networks', network)
|
||||||
delete_method(_id)
|
delete_method(_id)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -232,7 +232,7 @@ class TestServerDelete(TestServer):
|
|||||||
compute_fakes.server_id,
|
compute_fakes.server_id,
|
||||||
]
|
]
|
||||||
verifylist = [
|
verifylist = [
|
||||||
('server', compute_fakes.server_id),
|
('servers', [compute_fakes.server_id]),
|
||||||
]
|
]
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
@ -288,7 +288,7 @@ class TestImageDelete(TestImage):
|
|||||||
image_fakes.image_id,
|
image_fakes.image_id,
|
||||||
]
|
]
|
||||||
verifylist = [
|
verifylist = [
|
||||||
('image', image_fakes.image_id),
|
('images', [image_fakes.image_id]),
|
||||||
]
|
]
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ class TestImageDelete(TestImage):
|
|||||||
image_fakes.image_id,
|
image_fakes.image_id,
|
||||||
]
|
]
|
||||||
verifylist = [
|
verifylist = [
|
||||||
('image', image_fakes.image_id),
|
('images', [image_fakes.image_id]),
|
||||||
]
|
]
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ class TestDeleteNetwork(common.TestNetworkBase):
|
|||||||
FAKE_NAME,
|
FAKE_NAME,
|
||||||
]
|
]
|
||||||
verifylist = [
|
verifylist = [
|
||||||
('identifier', FAKE_NAME),
|
('networks', [FAKE_NAME]),
|
||||||
]
|
]
|
||||||
lister = mock.Mock(return_value={RESOURCES: [RECORD]})
|
lister = mock.Mock(return_value={RESOURCES: [RECORD]})
|
||||||
self.app.client_manager.network.list_networks = lister
|
self.app.client_manager.network.list_networks = lister
|
||||||
|
@ -73,24 +73,26 @@ class CreateBackup(show.ShowOne):
|
|||||||
|
|
||||||
|
|
||||||
class DeleteBackup(command.Command):
|
class DeleteBackup(command.Command):
|
||||||
"""Delete backup command"""
|
"""Delete backup(s)"""
|
||||||
|
|
||||||
log = logging.getLogger(__name__ + '.DeleteBackup')
|
log = logging.getLogger(__name__ + '.DeleteBackup')
|
||||||
|
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(DeleteBackup, self).get_parser(prog_name)
|
parser = super(DeleteBackup, self).get_parser(prog_name)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'backup',
|
'backups',
|
||||||
metavar='<backup>',
|
metavar='<backup>',
|
||||||
help='Name or ID of backup to delete',
|
nargs="+",
|
||||||
|
help='Backup(s) to delete (name or ID)',
|
||||||
)
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
self.log.debug('take_action(%s)', parsed_args)
|
self.log.debug('take_action(%s)', parsed_args)
|
||||||
volume_client = self.app.client_manager.volume
|
volume_client = self.app.client_manager.volume
|
||||||
|
for backup in parsed_args.backups:
|
||||||
backup_id = utils.find_resource(volume_client.backups,
|
backup_id = utils.find_resource(volume_client.backups,
|
||||||
parsed_args.backup).id
|
backup).id
|
||||||
volume_client.backups.delete(backup_id)
|
volume_client.backups.delete(backup_id)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -74,24 +74,26 @@ class CreateSnapshot(show.ShowOne):
|
|||||||
|
|
||||||
|
|
||||||
class DeleteSnapshot(command.Command):
|
class DeleteSnapshot(command.Command):
|
||||||
"""Delete snapshot command"""
|
"""Delete snapshot(s)"""
|
||||||
|
|
||||||
log = logging.getLogger(__name__ + '.DeleteSnapshot')
|
log = logging.getLogger(__name__ + '.DeleteSnapshot')
|
||||||
|
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(DeleteSnapshot, self).get_parser(prog_name)
|
parser = super(DeleteSnapshot, self).get_parser(prog_name)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'snapshot',
|
'snapshots',
|
||||||
metavar='<snapshot>',
|
metavar='<snapshot>',
|
||||||
help='Name or ID of snapshot to delete',
|
nargs="+",
|
||||||
|
help='Snapshot(s) to delete (name or ID)',
|
||||||
)
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
self.log.debug('take_action(%s)', parsed_args)
|
self.log.debug('take_action(%s)', parsed_args)
|
||||||
volume_client = self.app.client_manager.volume
|
volume_client = self.app.client_manager.volume
|
||||||
|
for snapshot in parsed_args.snapshots:
|
||||||
snapshot_id = utils.find_resource(volume_client.volume_snapshots,
|
snapshot_id = utils.find_resource(volume_client.volume_snapshots,
|
||||||
parsed_args.snapshot).id
|
snapshot).id
|
||||||
volume_client.volume_snapshots.delete(snapshot_id)
|
volume_client.volume_snapshots.delete(snapshot_id)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -155,35 +155,37 @@ class CreateVolume(show.ShowOne):
|
|||||||
|
|
||||||
|
|
||||||
class DeleteVolume(command.Command):
|
class DeleteVolume(command.Command):
|
||||||
"""Delete a volume"""
|
"""Delete volume(s)"""
|
||||||
|
|
||||||
log = logging.getLogger(__name__ + '.DeleteVolume')
|
log = logging.getLogger(__name__ + '.DeleteVolume')
|
||||||
|
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(DeleteVolume, self).get_parser(prog_name)
|
parser = super(DeleteVolume, self).get_parser(prog_name)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'volume',
|
'volumes',
|
||||||
metavar='<volume>',
|
metavar='<volume>',
|
||||||
help='Volume to delete (name or ID)',
|
nargs="+",
|
||||||
|
help='Volume(s) to delete (name or ID)',
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--force',
|
'--force',
|
||||||
dest='force',
|
dest='force',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
default=False,
|
default=False,
|
||||||
help='Attempt forced removal of a volume, regardless of state',
|
help='Attempt forced removal of volume(s), regardless of state',
|
||||||
)
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
self.log.debug('take_action(%s)', parsed_args)
|
self.log.debug('take_action(%s)', parsed_args)
|
||||||
volume_client = self.app.client_manager.volume
|
volume_client = self.app.client_manager.volume
|
||||||
volume = utils.find_resource(
|
for volume in parsed_args.volumes:
|
||||||
volume_client.volumes, parsed_args.volume)
|
volume_obj = utils.find_resource(
|
||||||
|
volume_client.volumes, volume)
|
||||||
if parsed_args.force:
|
if parsed_args.force:
|
||||||
volume_client.volumes.force_delete(volume.id)
|
volume_client.volumes.force_delete(volume_obj.id)
|
||||||
else:
|
else:
|
||||||
volume_client.volumes.delete(volume.id)
|
volume_client.volumes.delete(volume_obj.id)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user