Exemplo n.º 1
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share
        result = 0

        for share in parsed_args.share:
            try:
                share_obj = apiutils.find_resource(share_client.shares, share)
                share_client.shares.unmanage(share_obj)

                if parsed_args.wait:
                    # 'wait_for_delete' checks that the resource is no longer
                    # retrievable with the given 'res_id' so we can use it
                    # to check that the share has been abandoned
                    if not oscutils.wait_for_delete(
                            manager=share_client.shares, res_id=share_obj.id):
                        result += 1

            except Exception as e:
                result += 1
                LOG.error(
                    _("Failed to abandon share with "
                      "name or ID '%(share)s': %(e)s"), {
                          'share': share,
                          'e': e
                      })

        if result > 0:
            total = len(parsed_args.share)
            msg = (_("Failed to abandon %(result)s out of %(total)s shares.") %
                   {
                       'result': result,
                       'total': total
                   })
            raise exceptions.CommandError(msg)
Exemplo n.º 2
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share
        result = 0

        for share_group in parsed_args.share_group:
            try:
                share_group_obj = osc_utils.find_resource(
                    share_client.share_groups, share_group)

                share_client.share_groups.delete(share_group_obj,
                                                 force=parsed_args.force)

                if parsed_args.wait:
                    if not osc_utils.wait_for_delete(
                            manager=share_client.share_groups,
                            res_id=share_group_obj.id):
                        result += 1

            except Exception as e:
                result += 1
                LOG.error(
                    _("Failed to delete share group with "
                      "name or ID '%(share_group)s': %(e)s"), {
                          'share_group': share_group,
                          'e': e
                      })

        if result > 0:
            total = len(parsed_args.share_group)
            msg = (_("%(result)s of %(total)s share groups failed "
                     "to delete.") % {
                         'result': result,
                         'total': total
                     })
            raise exceptions.CommandError(msg)
Exemplo n.º 3
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share
        result = 0

        for share in parsed_args.shares:
            try:
                share_obj = apiutils.find_resource(share_client.shares, share)
                share_group_id = (share_group_id
                                  if parsed_args.share_group else None)
                if parsed_args.force:
                    share_client.shares.force_delete(share_obj)
                else:
                    share_client.shares.delete(share_obj, share_group_id)
                if parsed_args.wait:
                    if not oscutils.wait_for_delete(
                            manager=share_client.shares, res_id=share_obj.id):
                        result += 1

            except Exception as exc:
                result += 1
                LOG.error(
                    _("Failed to delete share with "
                      "name or ID '%(share)s': %(e)s"), {
                          'share': share,
                          'e': exc
                      })

        if result > 0:
            total = len(parsed_args.shares)
            msg = (_("%(result)s of %(total)s shares failed "
                     "to delete.") % {
                         'result': result,
                         'total': total
                     })
            raise exceptions.CommandError(msg)
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share
        number_of_deletion_failures = 0

        for instance in parsed_args.instance:
            try:
                share_instance = apiutils.find_resource(
                    share_client.share_instances, instance)

                share_client.share_instances.force_delete(share_instance)

                if parsed_args.wait:
                    if not osc_utils.wait_for_delete(
                            manager=share_client.share_instances,
                            res_id=share_instance.id):
                        number_of_deletion_failures += 1

            except Exception as e:
                number_of_deletion_failures += 1
                LOG.error(
                    _("Failed to delete a share instance with "
                      "ID '%(instance)s': %(e)s"), {
                          'instance': instance,
                          'e': e
                      })
        if number_of_deletion_failures > 0:
            msg = (
                _("%(number_of_deletion_failures)s of "
                  "%(total_of_instances)s instances failed "
                  "to delete.") %
                {
                    'number_of_deletion_failures': number_of_deletion_failures,
                    'total_of_instances': len(parsed_args.instance)
                })
            raise exceptions.CommandError(msg)
Exemplo n.º 5
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share
        result = 0

        for snapshot in parsed_args.snapshot:
            snapshot_obj = utils.find_resource(share_client.share_snapshots,
                                               snapshot)
            try:
                share_client.share_snapshots.unmanage(snapshot_obj)
                if parsed_args.wait:
                    if not utils.wait_for_delete(
                            manager=share_client.share_snapshots,
                            res_id=snapshot_obj.id):
                        result += 1
            except Exception as e:
                result += 1
                LOG.error(
                    _("Failed to abandon share snapshot with "
                      "name or ID '%(snapshot)s': %(e)s"), {
                          'snapshot': snapshot,
                          'e': e
                      })

        if result > 0:
            total = len(parsed_args.snapshot)
            msg = (_("%(result)s of %(total)s snapshots failed "
                     "to abandon.") % {
                         'result': result,
                         'total': total
                     })
            raise exceptions.CommandError(msg)
Exemplo n.º 6
0
 def test_wait_for_delete_error_with_overrides_exception(self, mock_sleep):
     # Tests that we succeed if the resource is specific exception
     mock_get = mock.Mock(side_effect=Exception)
     manager = mock.MagicMock(get=mock_get)
     res_id = str(uuid.uuid4())
     self.assertTrue(utils.wait_for_delete(manager, res_id,
                                           exception_name=['Exception']))
     mock_sleep.assert_not_called()
Exemplo n.º 7
0
 def test_wait_for_delete_error_with_overrides_exception(self, mock_sleep):
     # Tests that we succeed if the resource is specific exception
     mock_get = mock.Mock(side_effect=Exception)
     manager = mock.MagicMock(get=mock_get)
     res_id = str(uuid.uuid4())
     self.assertTrue(utils.wait_for_delete(manager, res_id,
                                           exception_name=['Exception']))
     mock_sleep.assert_not_called()
 def test_wait_for_delete_error(self, mock_sleep):
     # Tests that we fail if the resource goes to error state while waiting.
     resource = mock.MagicMock(status='ERROR')
     mock_get = mock.Mock(return_value=resource)
     manager = mock.MagicMock(get=mock_get)
     res_id = str(uuid.uuid4())
     self.assertFalse(utils.wait_for_delete(manager, res_id))
     mock_sleep.assert_not_called()
Exemplo n.º 9
0
 def test_wait_for_delete_error(self, mock_sleep):
     # Tests that we fail if the resource goes to error state while waiting.
     resource = mock.MagicMock(status='ERROR')
     mock_get = mock.Mock(return_value=resource)
     manager = mock.MagicMock(get=mock_get)
     res_id = str(uuid.uuid4())
     self.assertFalse(utils.wait_for_delete(manager, res_id))
     mock_sleep.assert_not_called()
 def test_wait_for_delete_timeout(self, mock_sleep):
     # Tests that we fail if the resource is not deleted before the timeout.
     resource = mock.MagicMock(status='ACTIVE')
     mock_get = mock.Mock(return_value=resource)
     manager = mock.MagicMock(get=mock_get)
     res_id = str(uuid.uuid4())
     self.assertFalse(
         utils.wait_for_delete(manager, res_id, sleep_time=1, timeout=1))
     mock_sleep.assert_called_once_with(1)
Exemplo n.º 11
0
 def test_wait_for_delete_timeout(self, mock_sleep):
     # Tests that we fail if the resource is not deleted before the timeout.
     resource = mock.MagicMock(status='ACTIVE')
     mock_get = mock.Mock(return_value=resource)
     manager = mock.MagicMock(get=mock_get)
     res_id = str(uuid.uuid4())
     self.assertFalse(utils.wait_for_delete(manager, res_id, sleep_time=1,
                                            timeout=1))
     mock_sleep.assert_called_once_with(1)
Exemplo n.º 12
0
 def test_wait_for_delete_error_with_overrides(self, mock_sleep):
     # Tests that we fail if the resource is my_status=failed
     resource = mock.MagicMock(my_status='FAILED')
     mock_get = mock.Mock(return_value=resource)
     manager = mock.MagicMock(get=mock_get)
     res_id = str(uuid.uuid4())
     self.assertFalse(utils.wait_for_delete(manager, res_id,
                                            status_field='my_status',
                                            error_status=['failed']))
     mock_sleep.assert_not_called()
Exemplo n.º 13
0
 def test_wait_for_delete_error_with_overrides(self, mock_sleep):
     # Tests that we fail if the resource is my_status=failed
     resource = mock.MagicMock(my_status='FAILED')
     mock_get = mock.Mock(return_value=resource)
     manager = mock.MagicMock(get=mock_get)
     res_id = str(uuid.uuid4())
     self.assertFalse(utils.wait_for_delete(manager, res_id,
                                            status_field='my_status',
                                            error_status=['failed']))
     mock_sleep.assert_not_called()
 def test_wait_for_delete_ok(self, mock_sleep):
     # Tests the normal flow that the resource is deleted with a 404 coming
     # back on the 2nd iteration of the wait loop.
     resource = mock.MagicMock(status='ACTIVE', progress=None)
     mock_get = mock.Mock(side_effect=[resource, exceptions.NotFound(404)])
     manager = mock.MagicMock(get=mock_get)
     res_id = str(uuid.uuid4())
     callback = mock.Mock()
     self.assertTrue(
         utils.wait_for_delete(manager, res_id, callback=callback))
     mock_sleep.assert_called_once_with(5)
     callback.assert_called_once_with(0)
Exemplo n.º 15
0
 def test_wait_for_delete_ok(self, mock_sleep):
     # Tests the normal flow that the resource is deleted with a 404 coming
     # back on the 2nd iteration of the wait loop.
     resource = mock.MagicMock(status='ACTIVE', progress=None)
     mock_get = mock.Mock(side_effect=[resource,
                                       exceptions.NotFound(404)])
     manager = mock.MagicMock(get=mock_get)
     res_id = str(uuid.uuid4())
     callback = mock.Mock()
     self.assertTrue(utils.wait_for_delete(manager, res_id,
                                           callback=callback))
     mock_sleep.assert_called_once_with(5)
     callback.assert_called_once_with(0)
 def execute(self, server_id, config):
     logging.debug("deprovisioning instance %s" % server_id)
     nc = get_openstack_nova_client(config)
     try:
         server = nc.servers.get(server_id)
     except NotFound:
         logging.warn("Server %s not found" % server_id)
         return
     if hasattr(server, "security_groups"):
         for sg in server.security_groups:
             try:
                 server.remove_security_group(sg['name'])
             except:
                 logging.warn("Unable to remove security group from server (%s)" % sg)
     else:
         logging.warn("no security groups on server!")
     try:
         nc.servers.delete(server_id)
         wait_for_delete(nc.servers, server_id)
     except Exception as e:
         logging.warn("Unable to deprovision server %s" % e)
     return server.name
Exemplo n.º 17
0
 def execute(self, server_id, config):
     logging.debug("deprovisioning instance %s" % server_id)
     nc = get_openstack_nova_client(config)
     try:
         server = nc.servers.get(server_id)
     except NotFound:
         logging.warn("Server %s not found" % server_id)
         return
     if hasattr(server, "security_groups"):
         for sg in server.security_groups:
             try:
                 server.remove_security_group(sg['name'])
             except:
                 logging.warn(
                     "Unable to remove security group from server (%s)" %
                     sg)
     else:
         logging.warn("no security groups on server!")
     try:
         nc.servers.delete(server_id)
         wait_for_delete(nc.servers, server_id)
     except Exception as e:
         logging.warn("Unable to deprovision server %s" % e)
     return server.name
Exemplo n.º 18
0
def wait_for_delete(status_f,
                    res_id,
                    status_field=constants.PROVISIONING_STATUS):
    class Getter(object):
        @staticmethod
        def get(id):
            return munch.Munch(status_f(id))

    try:
        success = utils.wait_for_delete(manager=Getter,
                                        res_id=res_id,
                                        status_field=status_field,
                                        sleep_time=3)
        if not success:
            raise exceptions.OctaviaClientException(
                code="n/a",
                message="The resource could not be successfully deleted.")
    except exceptions.OctaviaClientException as e:
        if e.code != 404:
            raise
Exemplo n.º 19
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share

        share = apiutils.find_resource(share_client.shares, parsed_args.share)
        error = None
        try:
            share.deny(parsed_args.id)
            if parsed_args.wait:
                if not oscutils.wait_for_delete(
                        manager=share_client.share_access_rules,
                        res_id=parsed_args.id):
                    error = _(
                        "Failed to delete share access rule with ID: %s" %
                        parsed_args.id)
        except Exception as e:
            error = e
        if error:
            raise exceptions.CommandError(
                _("Failed to delete share access rule for share "
                  "'%s': %s" % (share, error)))
Exemplo n.º 20
0
    def take_action(self, parsed_args):
        share_client = self.app.client_manager.share
        result = 0

        for share_network in parsed_args.share_network:
            try:
                share_network_obj = oscutils.find_resource(
                    share_client.share_networks, share_network)
                share_client.share_networks.delete(share_network_obj)

                if parsed_args.wait:
                    if not oscutils.wait_for_delete(
                            manager=share_client.share_networks,
                            res_id=share_network_obj.id):
                        result += 1
            except Exception as e:
                result += 1
                LOG.error(f"Failed to delete share network with "
                          f"name or ID {share_network}: {e}")

        if result > 0:
            total = len(parsed_args.share_network)
            msg = f"{result} of {total} share networks failed to be deleted."
            raise exceptions.CommandError(msg)