示例#1
0
    def hosts_facts(self):
        """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)
        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()

        for host in hosts:
            last_checkin = str(host.get(LAST_CHECKIN, ''))
            self.host_details(host.get(ID), host.get(NAME), last_checkin,
                              virtual_hosts, virtual_guests, physical_hosts)
示例#2
0
    def virtual_hosts(self):
        """Obtain the virtual host data.

        :returns: tuple of (list of virtual host ids,
            dictionary of virtual guest id to virtual_host_id)
        """
        virt_hosts = []
        virtual_hosts = {}
        virtual_guests = {}
        client, user, password = utils.get_sat5_client(self.connect_scan_task)
        try:
            key = client.auth.login(user, password)
            virt_hosts = client.system.list_virtual_hosts(key)
            for virt_host in virt_hosts:
                virt_host_id = virt_host.get(ID)
                virt_host_name = virt_host.get(NAME)
                uuid = client.system.get_uuid(key, virt_host_id)
                if uuid is None or uuid == '':
                    uuid = virt_host_id
                virtual_host = {ID: virt_host_id,
                                NAME: virt_host_name,
                                UUID: uuid}
                virtual_hosts[virt_host_id] = virtual_host
            client.auth.logout(key)
        except xmlrpc.client.Fault as xml_error:
            raise SatelliteException(str(xml_error))

        for virt_host in virt_hosts:
            virt_host_id = virt_host.get(ID)
            virtual_host = virtual_hosts.get(virt_host_id)
            guests, guest_count = self.virtual_guests(virt_host_id)
            virtual_guests.update(guests)
            virtual_host[NUM_VIRTUAL_GUESTS] = guest_count

        return(virtual_hosts, virtual_guests)
示例#3
0
def request_host_details(host_id, host_name, last_checkin, scan_task,
                         request_options, logging_options):
    """Execute http responses to gather satellite data.

    :param host_id: The identifier of the host
    :param host_name: The name of the host
    :param last_checkin: The date of last checkin
    :param scan_task: The current scan task
    :param request_options: A dictionary containing the host, port,
        user, and password for the source
    :param: logging_options: A dictionary containing the scan_task type,
        scan_task id, and source_type, and the source_name
    """
    unique_name = '%s_%s' % (host_name, host_id)
    results = {}
    client, user, password = utils.get_sat5_client(scan_task,
                                                   request_options)
    try:
        message = 'REQUESTING HOST DETAILS: %s' % unique_name
        scan_task.log_message(message, logging.INFO,
                              logging_options)

        key = client.auth.login(user, password)
        uuid = client.system.get_uuid(key, host_id)
        cpu = client.system.get_cpu(key, host_id)
        system_details = client.system.get_details(key, host_id)
        kernel = client.system.get_running_kernel(key, host_id)
        subs = client.system.get_entitlements(key, host_id)

        network_devices = client.system.get_network_devices(key, host_id)
        registration_date = client.system.get_registration_date(key,
                                                                host_id)

        client.auth.logout(key)
        system_inspection_result = SystemInspectionResult.SUCCESS
        results['uuid'] = uuid
        results['cpu'] = cpu
        results['system_details'] = system_details
        results['kernel'] = kernel
        results['subs'] = subs
        results['network_devices'] = network_devices
        results['registration_date'] = registration_date

    except xmlrpc.client.Fault as xml_error:
        error_message = 'Satellite 5 fault error encountered: %s\n' \
                        % xml_error
        logger.error(error_message)
        system_inspection_result = SystemInspectionResult.FAILED

    results['host_name'] = host_name
    results['host_id'] = host_id
    results['last_checkin'] = last_checkin
    results['system_inspection_result'] = system_inspection_result

    return results
示例#4
0
 def host_count(self):
     """Obtain the count of managed hosts."""
     systems_count = 0
     client, user, password = utils.get_sat5_client(self.scan_task)
     try:
         key = client.auth.login(user, password)
         systems = client.system.list_user_systems(key)
         systems_count = len(systems)
         client.auth.logout(key)
     except xmlrpc.client.Fault as xml_error:
         raise SatelliteException(str(xml_error))
     self.initialize_stats(systems_count)
     return systems_count
示例#5
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)
示例#6
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)
示例#7
0
    def physical_hosts(self):
        """Obtain the physical host data.

        :returns: list of phyiscal host ids
        """
        physical_hosts = []
        client, user, password = utils.get_sat5_client(self.connect_scan_task)
        try:
            key = client.auth.login(user, password)
            physical_systems = client.system.list_physical_systems(key)
            for system in physical_systems:
                host_id = system.get(ID)
                if host_id:
                    physical_hosts.append(host_id)
            client.auth.logout(key)
        except xmlrpc.client.Fault as xml_error:
            raise SatelliteException(str(xml_error))

        return physical_hosts
示例#8
0
    def hosts(self):
        """Obtain the managed hosts."""
        hosts = []
        credential = utils.get_credential(self.scan_task)
        client, user, password = utils.get_sat5_client(self.scan_task)
        try:
            key = client.auth.login(user, password)
            systems = client.system.list_user_systems(key)
            client.auth.logout(key)

            for system in systems:
                name = system.get(NAME)
                if name is not None:
                    hosts.append(name)
                    self.record_conn_result(name, credential)

        except xmlrpc.client.Fault as xml_error:
            raise SatelliteException(str(xml_error))

        return hosts
示例#9
0
    def hosts_facts(self):
        """Obtain the managed hosts detail raw facts."""
        systems_count = len(self.conn_result.systems.all())
        self.initialize_stats(systems_count)

        hosts = []
        client, user, password = utils.get_sat5_client(self.scan_task)
        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()

        for host in hosts:
            last_checkin = str(host.get(LAST_CHECKIN, ''))
            self.host_details(host.get(ID), host.get(NAME), last_checkin,
                              virtual_hosts, virtual_guests)
示例#10
0
    def virtual_guests(self, virtual_host_id):
        """Obtain the virtual guest information for a virtual host.

        :param virtual_host_id: The identifier for a virtual host
        :returns: a tuple of a dictionary of virtual guest id, virtual_host_id
            and the number of guests
        """
        virtual_guests = {}
        virt_guests = []
        client, user, password = utils.get_sat5_client(self.connect_scan_task)
        try:
            key = client.auth.login(user, password)
            virt_guests = client.system.list_virtual_guests(
                key, virtual_host_id)
            client.auth.logout(key)
        except xmlrpc.client.Fault as xml_error:
            raise SatelliteException(str(xml_error))

        for guest in virt_guests:
            virt_id = guest.get(ID)
            virtual_guests[virt_id] = virtual_host_id

        return (virtual_guests, len(virt_guests))
示例#11
0
 def test_get_sat5_client(self):
     """Test the sat5 client helper."""
     client, user, password = get_sat5_client(self.scan_task)
     self.assertIsNotNone(client)
     self.assertEqual(user, 'username')
     self.assertEqual(password, 'password')
示例#12
0
    def host_details(self, host_id, host_name, last_checkin, virtual_hosts,
                     virtual_guests):
        """Obtain the details for a given host id and name.

        :param host_id: The identifier of the host
        :param host_name: The name of the host
        :param last_checkin: The date of last checkin
        :param virtual_hosts: A dictionary of virtual host data
        :param virtual_guests: A dictionary of guest to host data
        :returns: dictionary of host details
        """
        details = {}
        sys_result = self.inspect_result.systems.filter(name=host_name).first()

        if sys_result:
            logger.debug('Results already captured for host_name=%s',
                         host_name)
            return details
        client, user, password = utils.get_sat5_client(self.scan_task)
        try:
            key = client.auth.login(user, password)
            uuid = client.system.get_uuid(key, host_id)
            if uuid is None or uuid == '':
                uuid = host_id

            cpu = client.system.get_cpu(key, host_id)
            arch = cpu.get(ARCH, UNKNOWN)
            cpu_count = cpu.get(COUNT)
            cpu_core_count = cpu_count
            cpu_socket_count = cpu.get(SOCKET_COUNT)

            system_details = client.system.get_details(key, host_id)
            hostname = system_details.get(HOSTNAME)
            release = system_details.get(RELEASE)

            kernel = client.system.get_running_kernel(key, host_id)

            entitlements = []
            subs = client.system.get_entitlements(key, host_id)
            for sub in subs:
                entitlement = {NAME: sub}
                entitlements.append(entitlement)

            network_devices = client.system.get_network_devices(key, host_id)
            ip_addresses = []
            mac_addresses = []
            for device in network_devices:
                interface = device.get(INTERFACE)
                if interface and interface.startswith(ETHERNET):
                    ip_addr = device.get(IP)
                    if ip_addr:
                        ip_addresses.append(ip_addr)
                    mac = device.get(HARDWARE_ADDRESS)
                    if mac:
                        mac_addresses.append(mac)
            registration_date = client.system.get_registration_date(
                key, host_id)

            details[UUID] = uuid
            details[NAME] = host_name
            details[HOSTNAME] = hostname
            details[LAST_CHECKIN_TIME] = last_checkin
            details[REGISTRATION_TIME] = str(registration_date)
            details[ARCHITECTURE] = arch
            details[KERNEL] = kernel
            details[CORES] = cpu_core_count
            details[SOCKETS] = cpu_socket_count
            details[OS_RELEASE] = release
            details[ENTITLEMENTS] = entitlements
            details[IP_ADDRESSES] = ip_addresses
            details[MAC_ADDRESSES] = mac_addresses

            if virtual_hosts.get(host_id):
                virtual_host = virtual_hosts.get(host_id)
                details[VIRTUAL] = HYPERVISOR
                guests = virtual_host.get(NUM_VIRTUAL_GUESTS, 0)
                details[NUM_VIRTUAL_GUESTS] = guests
                details[IS_VIRT] = False

            elif virtual_guests.get(host_id):
                virt_host_id = virtual_guests.get(host_id)
                virtual_host = virtual_hosts.get(virt_host_id)
                details[IS_VIRT] = True
                if virtual_host.get(UUID):
                    details[VIRTUAL_HOST] = virtual_host.get(UUID)
                if virtual_host.get(NAME):
                    details[VIRTUAL_HOST_NAME] = virtual_host.get(NAME)

            client.auth.logout(key)
        except xmlrpc.client.Fault as xml_error:
            raise SatelliteException(str(xml_error))

        self.record_inspect_result(host_name, details)
        logger.debug('host_id=%s, host_details=%s', host_id, details)
        return details