Esempio n. 1
0
 def post(self, *args, **kwargs):
     self.set_network()
     if 'scan' in self.request.POST and self.network:
         autoscan.autoscan_network(self.network)
         messages.success(self.request, "Network scan scheduled.")
     elif 'bury' in self.request.POST:
         selected = self.request.POST.getlist('select')
         addresses = IPAddress.objects.filter(id__in=selected)
         for address in addresses:
             address.is_buried = True
             address.save(update_last_seen=False)
         messages.success(
             self.request,
             "%d addresses buried." % len(addresses),
         )
     elif 'resurrect' in self.request.POST:
         selected = self.request.POST.getlist('select')
         addresses = IPAddress.objects.filter(id__in=selected)
         for address in addresses:
             address.is_buried = False
             address.save(update_last_seen=False)
         messages.success(
             self.request,
             "%d addresses resurrected." % len(addresses),
         )
     return HttpResponseRedirect(self.request.path)
Esempio n. 2
0
 def handle(self, *args, **kwargs):
     if sum([
         kwargs['network'],
         kwargs['data_center'],
         kwargs['environment'],
         kwargs['queue']
     ]) > 1:
         raise SystemExit(
             "You can't mix networks, environments, data centers and "
             "queues.",
         )
     if not args:
         raise SystemExit("Please specify the addresses to scan.")
     if kwargs['network']:
         try:
             for network in [
                 find_network(network_spec) for network_spec in args
             ]:
                 autoscan_network(network)
         except (Error, Network.DoesNotExist) as e:
             raise SystemExit(e)
     elif kwargs['environment']:
         try:
             for environment in [
                 Environment.objects.get(name=name) for name in args
             ]:
                 autoscan_environment(environment)
         except (Error, Environment.DoesNotExist) as e:
             raise SystemExit(e)
     elif kwargs['data_center']:
         try:
             for data_center in [
                 DataCenter.objects.get(name=name) for name in args
             ]:
                 for environment in data_center.environment_set.filter(
                     queue__isnull=False,
                 ):
                     autoscan_environment(environment)
         except (Error, DataCenter.DoesNotExist) as e:
             raise SystemExit(e)
     elif kwargs['queue']:
         try:
             for queue in [
                 DiscoveryQueue.objects.get(name=name) for name in args
             ]:
                 for environment in queue.environment_set.all():
                     autoscan_environment(environment)
         except (Error, DiscoveryQueue.DoesNotExist) as e:
             raise SystemExit(e)
     else:
         try:
             addresses = [str(ipaddr.IPAddress(ip)) for ip in args]
             for address in addresses:
                 autoscan_address(address)
         except (Error, ValueError) as e:
             raise SystemExit(e)
Esempio n. 3
0
 def handle(self, *args, **kwargs):
     if sum([
         kwargs['network'],
         kwargs['data_center'],
         kwargs['queue']
     ]) > 1:
         raise SystemExit("You can't mix networks, data centers and queues.")
     if not args:
         raise SystemExit("Please specify the addresses to scan.")
     if kwargs['network']:
         try:
             networks = [
                 find_network(network_spec) for network_spec in args
             ]
             for network in networks:
                 autoscan_network(network)
         except (Error, Network.DoesNotExist) as e:
             raise SystemExit(e)
     elif kwargs['data_center']:
         try:
             data_centers = [
                 DataCenter.objects.get(name=name) for name in args
             ]
             for data_center in data_centers:
                 autoscan_data_center(data_center)
         except (Error, DataCenter.DoesNotExist) as e:
             raise SystemExit(e)
     elif kwargs['queue']:
         try:
             queues = [
                 DiscoveryQueue.objects.get(name=name) for name in args
             ]
             for queue in queues:
                 for network in queue.network_set.all():
                     autoscan_network(network)
         except (Error, DiscoveryQueue.DoesNotExist) as e:
             raise SystemExit(e)
     else:
         try:
             addresses = [str(ipaddr.IPAddress(ip)) for ip in args]
             for address in addresses:
                 autoscan_address(address)
         except (Error, ValueError) as e:
             raise SystemExit(e)