def load_instance_config(self, config): """ Attempt to load the results from the cache. If no cache exists, run a new scan and cache those results :param data: configuration data from the settings.py file :return: None """ global results # remove "/" from network name so we can use it for our cache cache_network_name = self.get_config_value("network").replace("/", "-") cache_key_name = "NmapDiscovery_%s" % cache_network_name # query the cache results = cache.get(cache_key_name) if results is None: print "No results found - performing new scan" ps = PortScanner() results = ps.scan(hosts=self.get_config_value("network"), arguments="-sP") cache.set(cache_key_name, results, int(self.get_config_value("cache_timeout"))) self.iterator = iter(results["scan"].iteritems()) return
def get_endpoint_by_id(self, endpoint_ip): """ for NmapDiscovery, id is always == endpoint_ip run a new scan only on that ip. Ignores cache :param endpoint_ip: :return: endpoint pyobject """ ps = PortScanner() r = ps.scan(hosts=endpoint_ip, arguments="-sP") print r return self.create_endpoint((endpoint_ip, r["scan"][endpoint_ip]))
class Config(): """Configuration values. Static object.""" client = DockerClient('unix://var/run/docker.sock', version='1.37') default_nginx_webroot = join(root, 'usr', 'share', 'quick_deployments', 'nginx_default', 'webroot') default_nginx_config = join(root, 'usr', 'share', 'quick_deployments', 'nginx_default', 'configuration') port_scanner = PortScanner() @staticmethod @strict def all_image_tags() -> List[str]: """Return a list of all available image tags.""" tags = [] for image in Config.client.images.list(): for tag in image.tags: tags.append(tag) return tags