Skip to content

Commit

Permalink
Merge pull request #910 from andrzej-jankowski/new_postprocessing
Browse files Browse the repository at this point in the history
  • Loading branch information
xor-xor committed Jun 3, 2014
2 parents ff1622f + 94b8e14 commit cab29ff
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 27 deletions.
11 changes: 0 additions & 11 deletions src/ralph/scan/automerger.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

from django.conf import settings
from django.db import models as db
from django.utils.importlib import import_module

from ralph.discovery.models_device import Device
from ralph.discovery.models_network import IPAddress
Expand Down Expand Up @@ -234,16 +233,6 @@ def _save_job_results(job_id, start_ts):
device_from_data(selected_data, save_priority=SAVE_PRIORITY)
# mark this scan results
update_scan_summary(job)
# run postprocess plugins...
if not job.args:
return # it's from API... ingnore postprocess
for plugin_name in getattr(settings, 'SCAN_POSTPROCESS_ENABLED_JOBS', []):
try:
module = import_module(plugin_name)
except ImportError as e:
logger.error(unicode(e))
else:
module.run_job(job.args[0]) # job.args[0] == ip_address...


def save_job_results(job_id):
Expand Down
29 changes: 26 additions & 3 deletions src/ralph/scan/manual.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ def queue_scan_address(
job = queue.enqueue_call(
func=scan_address_job,
args=(ip_address, plugins),
kwargs={'automerge': automerge},
kwargs={
'automerge': automerge,
'called_from_ui': called_from_ui,
},
timeout=300,
result_ttl=86400,
)
Expand Down Expand Up @@ -316,6 +319,7 @@ def scan_address_job(
plugins=None,
results=None,
automerge=AUTOMERGE_MODE,
called_from_ui=False,
**kwargs
):
"""The function that is actually running on the worker."""
Expand Down Expand Up @@ -346,8 +350,27 @@ def scan_address_job(
results = _run_plugins(ip_address, plugins, job, **kwargs)
if run_postprocessing:
_scan_postprocessing(results, job, ip_address)
# Run only when automerge mode is enabled and some change was detected.
# When `change` state is not available just run it...
if automerge and job.meta.get('changed', True):
# Run only when automerge mode is enabled and some change was
# detected. When `change` state is not available just run it...
save_job_results(job.id)
elif not called_from_ui and job.args and job.meta.get('changed', True):
# Run only when some change was detected. When `change` state is
# not available just run it...
try:
ip_obj = IPAddress.objects.select_related().get(
address=job.args[0] # job.args[0] == ip_address
)
except IPAddress.DoesNotExist:
pass
else:
for plugin_name in getattr(
settings, 'SCAN_POSTPROCESS_ENABLED_JOBS', []
):
try:
module = import_module(plugin_name)
except ImportError as e:
logger.error(unicode(e))
else:
module.run_job(ip_obj)
return results
7 changes: 1 addition & 6 deletions src/ralph/scan/postprocess/cache_price.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@
from __future__ import unicode_literals

from ralph.util import pricing
from ralph.discovery.models import IPAddress


def run_job(ip_address):
try:
ip = IPAddress.objects.select_related().get(address=ip_address)
except IPAddress.DoesNotExist:
return
def run_job(ip):
device = ip.device
if not device:
return # no device...
Expand Down
9 changes: 2 additions & 7 deletions src/ralph/scan/postprocess/position.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
Device,
DeviceModel,
DeviceType,
IPAddress,
Network,
)

Expand Down Expand Up @@ -65,11 +64,7 @@ def _connect_dc(ip_address, device):
device.save()


def run_job(ip_address):
try:
ip = IPAddress.objects.select_related().get(address=ip_address)
except IPAddress.DoesNotExist:
return
def run_job(ip):
device = ip.device
if not device:
return # no device...
Expand All @@ -81,4 +76,4 @@ def run_job(ip_address):
)
):
return # has parent...
_connect_dc(ip_address, device)
_connect_dc(ip.address, device)

0 comments on commit cab29ff

Please sign in to comment.