예제 #1
0
 def disable(self):
     self.cloud.enabled = False
     self.cloud.save()
     # We schedule a task to set the `missing_since` of resources associated
     # with `self.cloud` with a small delay. Since the poller syncs with the
     # db every 20 sec, there is a good chance that the poller will not pick
     # up the change to `self.cloud.enabled` in time to stop scheduling
     # further polling tasks. This may result in `missing_since` being reset
     # to `None`. For that, we schedule a task in the future to ensure that
     # celery has executed all respective poller tasks first.
     from mist.api.tasks import set_missing_since
     set_missing_since.apply_async((self.cloud.id, ), countdown=30)
예제 #2
0
    def delete(self, expire=False):
        """Delete a Cloud.

        By default the corresponding mongodb document is not actually deleted,
        but rather marked as deleted.

        :param expire: if True, the document is expired from its collection.

        """
        if expire:
            # FIXME: Set reverse_delete_rule=me.CASCADE?
            from mist.api.machines.models import Machine
            Machine.objects(cloud=self.cloud).delete()
            self.cloud.delete()
        else:
            from mist.api.tasks import set_missing_since
            self.cloud.deleted = datetime.datetime.utcnow()
            self.cloud.save()
            set_missing_since.apply_async((self.cloud.id, ), countdown=30)