Commit ab7f53b9 by Őry Máté

vm: rename Instance.destoryed to destroyed_at

parent b2b4580c
...@@ -1344,7 +1344,7 @@ ...@@ -1344,7 +1344,7 @@
"pk": 1, "pk": 1,
"model": "vm.instance", "model": "vm.instance",
"fields": { "fields": {
"destroyed": null, "destroyed_at": null,
"disks": [ "disks": [
1 1
], ],
...@@ -1375,7 +1375,7 @@ ...@@ -1375,7 +1375,7 @@
"pk": 12, "pk": 12,
"model": "vm.instance", "model": "vm.instance",
"fields": { "fields": {
"destroyed": null, "destroyed_at": null,
"disks": [], "disks": [],
"boot_menu": false, "boot_menu": false,
"owner": 1, "owner": 1,
......
...@@ -88,7 +88,7 @@ class IndexView(LoginRequiredMixin, TemplateView): ...@@ -88,7 +88,7 @@ class IndexView(LoginRequiredMixin, TemplateView):
favs = Instance.objects.filter(favourite__user=self.request.user) favs = Instance.objects.filter(favourite__user=self.request.user)
instances = Instance.get_objects_with_level( instances = Instance.get_objects_with_level(
'user', user).filter(destroyed=None) 'user', user).filter(destroyed_at=None)
display = list(favs) + list(set(instances) - set(favs)) display = list(favs) + list(set(instances) - set(favs))
for d in display: for d in display:
d.fav = True if d in favs else False d.fav = True if d in favs else False
...@@ -882,7 +882,7 @@ class VmList(LoginRequiredMixin, ListView): ...@@ -882,7 +882,7 @@ class VmList(LoginRequiredMixin, ListView):
favourite__user=self.request.user).values_list('pk', flat=True) favourite__user=self.request.user).values_list('pk', flat=True)
instances = Instance.get_objects_with_level( instances = Instance.get_objects_with_level(
'user', self.request.user).filter( 'user', self.request.user).filter(
destroyed=None).all() destroyed_at=None).all()
instances = [{ instances = [{
'pk': i.pk, 'pk': i.pk,
'name': i.name, 'name': i.name,
...@@ -899,7 +899,7 @@ class VmList(LoginRequiredMixin, ListView): ...@@ -899,7 +899,7 @@ class VmList(LoginRequiredMixin, ListView):
logger.debug('VmList.get_queryset() called. User: %s', logger.debug('VmList.get_queryset() called. User: %s',
unicode(self.request.user)) unicode(self.request.user))
queryset = Instance.get_objects_with_level( queryset = Instance.get_objects_with_level(
'user', self.request.user).filter(destroyed=None) 'user', self.request.user).filter(destroyed_at=None)
s = self.request.GET.get("s") s = self.request.GET.get("s")
if s: if s:
queryset = queryset.filter(name__icontains=s) queryset = queryset.filter(name__icontains=s)
......
...@@ -162,7 +162,7 @@ class DomainDetail(LoginRequiredMixin, SuperuserRequiredMixin, ...@@ -162,7 +162,7 @@ class DomainDetail(LoginRequiredMixin, SuperuserRequiredMixin,
domain=self.object, domain=self.object,
host__in=Host.objects.filter( host__in=Host.objects.filter(
interface__in=Interface.objects.filter( interface__in=Interface.objects.filter(
instance__destroyed=None) instance__destroyed_at=None)
) )
) )
context['record_list'] = SmallRecordTable(q) context['record_list'] = SmallRecordTable(q)
...@@ -618,7 +618,7 @@ class VlanDetail(LoginRequiredMixin, SuperuserRequiredMixin, ...@@ -618,7 +618,7 @@ class VlanDetail(LoginRequiredMixin, SuperuserRequiredMixin,
context = super(VlanDetail, self).get_context_data(**kwargs) context = super(VlanDetail, self).get_context_data(**kwargs)
q = Host.objects.filter(interface__in=Interface.objects.filter( q = Host.objects.filter(interface__in=Interface.objects.filter(
vlan=self.object, instance__destroyed=None vlan=self.object, instance__destroyed_at=None
)) ))
context['host_list'] = SmallHostTable(q) context['host_list'] = SmallHostTable(q)
......
...@@ -70,7 +70,7 @@ class InstanceActiveManager(Manager): ...@@ -70,7 +70,7 @@ class InstanceActiveManager(Manager):
def get_query_set(self): def get_query_set(self):
return super(InstanceActiveManager, return super(InstanceActiveManager,
self).get_query_set().filter(destroyed=None) self).get_query_set().filter(destroyed_at=None)
class VirtualMachineDescModel(BaseResourceConfigModel): class VirtualMachineDescModel(BaseResourceConfigModel):
...@@ -203,9 +203,9 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel): ...@@ -203,9 +203,9 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
help_text=_("TCP port where VNC console listens."), help_text=_("TCP port where VNC console listens."),
unique=True, verbose_name=_('vnc_port')) unique=True, verbose_name=_('vnc_port'))
owner = ForeignKey(User) owner = ForeignKey(User)
destroyed = DateTimeField(blank=True, null=True, destroyed_at = DateTimeField(blank=True, null=True,
help_text=_("The virtual machine's time of " help_text=_("The virtual machine's time of "
"destruction.")) "destruction."))
objects = Manager() objects = Manager()
active = InstanceActiveManager() active = InstanceActiveManager()
...@@ -752,7 +752,7 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel): ...@@ -752,7 +752,7 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
asynchronously. asynchronously.
:type task_uuid: str :type task_uuid: str
""" """
if self.destroyed: if self.destroyed_at:
raise self.InstanceDestroyedError(self) raise self.InstanceDestroyedError(self)
def __on_commit(activity): def __on_commit(activity):
...@@ -901,7 +901,7 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel): ...@@ -901,7 +901,7 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
asynchronously. asynchronously.
:type task_uuid: str :type task_uuid: str
""" """
if self.destroyed: if self.destroyed_at:
return # already destroyed, nothing to do here return # already destroyed, nothing to do here
def __on_commit(activity): def __on_commit(activity):
...@@ -921,7 +921,7 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel): ...@@ -921,7 +921,7 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
self.__cleanup_after_destroy_vm(act) self.__cleanup_after_destroy_vm(act)
self.destroyed = timezone.now() self.destroyed_at = timezone.now()
self.save() self.save()
def destroy_async(self, user=None): def destroy_async(self, user=None):
......
...@@ -59,7 +59,7 @@ class Interface(Model): ...@@ -59,7 +59,7 @@ class Interface(Model):
@property @property
def destroyed(self): def destroyed(self):
return self.instance.destroyed return self.instance.destroyed_at
@property @property
def mac(self): def mac(self):
......
...@@ -25,7 +25,7 @@ def garbage_collector(timeout=15): ...@@ -25,7 +25,7 @@ def garbage_collector(timeout=15):
:type timeout: int :type timeout: int
""" """
now = timezone.now() now = timezone.now()
for i in Instance.objects.filter(destroyed=None).all(): for i in Instance.objects.filter(destroyed_at=None).all():
if i.time_of_delete and now > i.time_of_delete: if i.time_of_delete and now > i.time_of_delete:
i.destroy_async() i.destroy_async()
logger.info("Expired instance %d destroyed.", i.pk) logger.info("Expired instance %d destroyed.", i.pk)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment