Exemple #1
0
    def hosts_facts(self, manager_interrupt):
        """Obtain the managed hosts detail raw facts."""
        systems_count = len(
            self.connect_scan_task.connection_result.systems.all())
        if self.inspect_scan_task is None:
            raise SatelliteException(
                'hosts_facts cannot be called for a connection scan')
        self.inspect_scan_task.update_stats('INITIAL STATELLITE STATS',
                                            sys_count=systems_count)
        deduplicated_hosts = []

        # pylint: disable=too-many-nested-blocks
        with Pool(processes=self.max_concurrency) as pool:
            orgs = self.get_orgs()
            for org_id in orgs:
                jsonresult = {}
                page = 0
                per_page = 100
                while (page == 0 or int(jsonresult.get(PER_PAGE, 0)) == len(
                        jsonresult.get(RESULTS, []))):
                    page += 1
                    params = {PAGE: page, PER_PAGE: per_page, THIN: 1}
                    response, url = \
                        utils.execute_request(self.inspect_scan_task,
                                              url=HOSTS_V1_URL,
                                              org_id=org_id,
                                              query_params=params)
                    # pylint: disable=no-member
                    if response.status_code != requests.codes.ok:
                        raise SatelliteException('Invalid response code %s'
                                                 ' for url: %s' %
                                                 (response.status_code, url))
                    jsonresult = response.json()

                    hosts_before_dedup = jsonresult.get(RESULTS, [])
                    hosts_after_dedup = []
                    for host in hosts_before_dedup:
                        if host not in deduplicated_hosts:
                            hosts_after_dedup.append(host)
                            deduplicated_hosts.append(host)
                    hosts = hosts_after_dedup
                    chunks = [
                        hosts[i:i + self.max_concurrency]
                        for i in range(0, len(hosts), self.max_concurrency)
                    ]
                    for chunk in chunks:
                        if manager_interrupt.value == \
                                ScanJob.JOB_TERMINATE_CANCEL:
                            raise SatelliteCancelException()

                        if manager_interrupt.value == \
                                ScanJob.JOB_TERMINATE_PAUSE:
                            raise SatellitePauseException()

                        host_params = self.prepare_host(chunk)
                        results = pool.starmap(request_host_details,
                                               host_params)
                        process_results(self, results, 1)
        utils.validate_task_stats(self.inspect_scan_task)
Exemple #2
0
    def hosts_facts(self, manager_interrupt):
        """Obtain the managed hosts detail raw facts."""
        systems_count = len(
            self.connect_scan_task.connection_result.systems.all())
        if self.inspect_scan_task is None:
            raise SatelliteException(
                'hosts_facts cannot be called for a connection scan')
        self.inspect_scan_task.update_stats('INITIAL STATELLITE STATS',
                                            sys_count=systems_count)

        with Pool(processes=self.max_concurrency) as pool:
            jsonresult = {}
            page = 0
            per_page = 100
            while (page == 0 or int(jsonresult.get(PER_PAGE, 0)) == len(
                    jsonresult.get(RESULTS, []))):
                page += 1
                params = {PAGE: page, PER_PAGE: per_page, THIN: 1}
                response, url = utils.execute_request(self.inspect_scan_task,
                                                      url=HOSTS_V2_URL,
                                                      query_params=params)
                # pylint: disable=no-member
                if response.status_code != requests.codes.ok:
                    raise SatelliteException('Invalid response code %s'
                                             ' for url: %s' %
                                             (response.status_code, url))
                jsonresult = response.json()

                hosts = jsonresult.get(RESULTS, [])
                chunks = [
                    hosts[i:i + self.max_concurrency]
                    for i in range(0, len(hosts), self.max_concurrency)
                ]
                for chunk in chunks:
                    if manager_interrupt.value == ScanJob.JOB_TERMINATE_CANCEL:
                        raise SatelliteCancelException()

                    if manager_interrupt.value == ScanJob.JOB_TERMINATE_PAUSE:
                        raise SatellitePauseException()

                    host_params = [(host.get(ID), host.get(NAME))
                                   for host in chunk]
                    results = pool.starmap(self.host_details, host_params)
                    for result in results:
                        if result is not None:
                            self.record_inspect_result(result.get('name'),
                                                       result.get('details'),
                                                       result.get('status'))

        utils.validate_task_stats(self.inspect_scan_task)
Exemple #3
0
    def hosts_facts(self, manager_interrupt):
        """Obtain the managed hosts detail raw facts."""
        if self.inspect_scan_task is None:
            raise SatelliteException(
                'hosts_facts cannot be called for a connection scan')
        systems_count = len(
            self.connect_scan_task.connection_result.systems.all())
        self.inspect_scan_task.update_stats(
            'INITIAL STATELLITE STATS', sys_count=systems_count)

        hosts = []
        client, user, password = utils.get_sat5_client(self.inspect_scan_task)
        with Pool(processes=self.max_concurrency) as pool:
            try:
                key = client.auth.login(user, password)
                hosts = client.system.list_user_systems(key)
                client.auth.logout(key)
            except xmlrpc.client.Fault as xml_error:
                raise SatelliteException(str(xml_error))
            virtual_hosts, virtual_guests = self.virtual_hosts()
            physical_hosts = self.physical_hosts()

            chunks = [hosts[i:i + self.max_concurrency]
                      for i in range(0, len(hosts), self.max_concurrency)]
            for chunk in chunks:
                if manager_interrupt.value == ScanJob.JOB_TERMINATE_CANCEL:
                    raise SatelliteCancelException()

                if manager_interrupt.value == ScanJob.JOB_TERMINATE_PAUSE:
                    raise SatellitePauseException()

                host_params = [(host.get(ID),
                                host.get(NAME),
                                str(host.get(LAST_CHECKIN, '')),
                                virtual_hosts,
                                virtual_guests,
                                physical_hosts)
                               for host in chunk]
                results = pool.starmap(self.host_details, host_params)
                for result in results:
                    if result is not None:
                        self.record_inspect_result(
                            result.get('name'),
                            result.get('details'),
                            result.get('status'))

        utils.validate_task_stats(self.inspect_scan_task)
Exemple #4
0
    def hosts_facts(self, manager_interrupt):
        """Obtain the managed hosts detail raw facts."""
        if self.inspect_scan_task is None:
            raise SatelliteException(
                'hosts_facts cannot be called for a connection scan')
        systems_count = len(
            self.connect_scan_task.connection_result.systems.all())
        self.inspect_scan_task.update_stats('INITIAL STATELLITE STATS',
                                            sys_count=systems_count)

        hosts_before_dedup = []
        deduplicated_hosts = []
        client, user, password = utils.get_sat5_client(self.inspect_scan_task)
        with Pool(processes=self.max_concurrency) as pool:
            try:
                key = client.auth.login(user, password)
                hosts_before_dedup = client.system.list_user_systems(key)
                client.auth.logout(key)
            except xmlrpc.client.Fault as xml_error:
                raise SatelliteException(str(xml_error))
            virtual_hosts, virtual_guests = self.virtual_hosts()
            physical_hosts = self.physical_hosts()
            hosts_after_dedup = []
            for host in hosts_before_dedup:
                if host not in deduplicated_hosts:
                    hosts_after_dedup.append(host)
                    deduplicated_hosts.append(host)
            hosts = hosts_before_dedup
            chunks = [
                hosts[i:i + self.max_concurrency]
                for i in range(0, len(hosts), self.max_concurrency)
            ]
            for chunk in chunks:
                if manager_interrupt.value == ScanJob.JOB_TERMINATE_CANCEL:
                    raise SatelliteCancelException()

                if manager_interrupt.value == ScanJob.JOB_TERMINATE_PAUSE:
                    raise SatellitePauseException()
                host_params = self.prepare_host(chunk)
                results = pool.starmap(request_host_details, host_params)
                self.process_results(results, virtual_hosts, virtual_guests,
                                     physical_hosts)

        utils.validate_task_stats(self.inspect_scan_task)