Skip to content

Commit

Permalink
Add post_send on device to AddVM (#2663)
Browse files Browse the repository at this point in the history
Add post_send on ``device`` to ``AddVM``
  • Loading branch information
ar4s authored and mkurek committed Aug 3, 2016
1 parent a80558e commit 1c25a07
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ralph/discovery/models_device.py
Expand Up @@ -616,7 +616,7 @@ def __unicode__(self):
@classmethod
def create(cls, ethernets=None, sn=None, model=None, model_name=None,
model_type=None, device=None, allow_stub=False, priority=0,
**kwargs):
handle_post_save=True, **kwargs):
if 'parent' in kwargs and kwargs['parent'] is None:
del kwargs['parent']
if not model and (not model_name or not model_type):
Expand Down Expand Up @@ -708,6 +708,7 @@ def create(cls, ethernets=None, sn=None, model=None, model_name=None,
user = kwargs.get('user')
except KeyError:
user = None
dev._handle_post_save = handle_post_save
dev.save(user=user, update_last_seen=True, priority=priority)
for eth in ethernets:
ethernet, eth_created = Ethernet.concurrent_get_or_create(
Expand Down
6 changes: 6 additions & 0 deletions src/ralph/ui/views/deploy.py
Expand Up @@ -16,6 +16,7 @@
from django.conf import settings
from django.contrib import messages
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.shortcuts import get_object_or_404
from django.utils.translation import ugettext_lazy as _
from lck.django.common import nested_commit_on_success
Expand Down Expand Up @@ -484,6 +485,7 @@ def post(self, request, *args, **kwargs):
model_type=DeviceType.virtual_server,
model_name=settings.ADD_VM_MODEL_NAME,
verified=True,
handle_post_save=False,
)
device.name = hostname
device.parent = parent
Expand All @@ -503,6 +505,10 @@ def post(self, request, *args, **kwargs):
resp['Location'] = LATEST_API.canonical_resource_for(
'dev'
).get_resource_uri(device)
device._handle_post_save = True
post_save.send(
sender=Device, instance=device, raw=None, using='default'
)
return resp

@csrf_exempt
Expand Down

0 comments on commit 1c25a07

Please sign in to comment.