Exemple #1
0
def get_hosts(multiple_labels=(), exclude_only_if_needed_labels=False,
              exclude_atomic_group_hosts=False, valid_only=True, **filter_data):
    """
    @param multiple_labels: match hosts in all of the labels given.  Should
            be a list of label names.
    @param exclude_only_if_needed_labels: Exclude hosts with at least one
            "only_if_needed" label applied.
    @param exclude_atomic_group_hosts: Exclude hosts that have one or more
            atomic group labels associated with them.
    """
    hosts = rpc_utils.get_host_query(multiple_labels,
                                     exclude_only_if_needed_labels,
                                     exclude_atomic_group_hosts,
                                     valid_only, filter_data)
    hosts = list(hosts)
    models.Host.objects.populate_relationships(hosts, models.Label,
                                               'label_list')
    models.Host.objects.populate_relationships(hosts, models.AclGroup,
                                               'acl_list')
    models.Host.objects.populate_relationships(hosts, models.HostAttribute,
                                               'attribute_list')
    host_dicts = []
    for host_obj in hosts:
        host_dict = host_obj.get_object_dict()
        host_dict['labels'] = [label.name for label in host_obj.label_list]
        host_dict['platform'], host_dict['atomic_group'] = (rpc_utils.
                find_platform_and_atomic_group(host_obj))
        host_dict['acls'] = [acl.name for acl in host_obj.acl_list]
        host_dict['attributes'] = dict((attribute.attribute, attribute.value)
                                       for attribute in host_obj.attribute_list)
        host_dicts.append(host_dict)
    return rpc_utils.prepare_for_serialization(host_dicts)
Exemple #2
0
def get_num_hosts(multiple_labels=(), exclude_only_if_needed_labels=False,
                  exclude_atomic_group_hosts=False, valid_only=True,
                  **filter_data):
    """
    Get the number of hosts. Same parameters as get_hosts().

    :return: The number of matching hosts.
    """
    hosts = rpc_utils.get_host_query(multiple_labels,
                                     exclude_only_if_needed_labels,
                                     exclude_atomic_group_hosts,
                                     valid_only, filter_data)
    return hosts.count()
def get_num_hosts(multiple_labels=(), exclude_only_if_needed_labels=False,
                  exclude_atomic_group_hosts=False, valid_only=True,
                  **filter_data):
    """
    Get the number of hosts. Same parameters as get_hosts().

    :return: The number of matching hosts.
    """
    hosts = rpc_utils.get_host_query(multiple_labels,
                                     exclude_only_if_needed_labels,
                                     exclude_atomic_group_hosts,
                                     valid_only, filter_data)
    return hosts.count()
Exemple #4
0
def get_hosts(multiple_labels=(),
              exclude_only_if_needed_labels=False,
              exclude_atomic_group_hosts=False,
              valid_only=True,
              **filter_data):
    """
    @param multiple_labels: match hosts in all of the labels given.  Should
            be a list of label names.
    @param exclude_only_if_needed_labels: Exclude hosts with at least one
            "only_if_needed" label applied.
    @param exclude_atomic_group_hosts: Exclude hosts that have one or more
            atomic group labels associated with them.
    """
    hosts = rpc_utils.get_host_query(multiple_labels,
                                     exclude_only_if_needed_labels,
                                     exclude_atomic_group_hosts, valid_only,
                                     filter_data)
    hosts = list(hosts)
    models.Host.objects.populate_relationships(hosts, models.Label,
                                               'label_list')
    models.Host.objects.populate_relationships(hosts, models.AclGroup,
                                               'acl_list')
    models.Host.objects.populate_relationships(hosts, models.HostAttribute,
                                               'attribute_list')
    host_dicts = []
    for host_obj in hosts:
        host_dict = host_obj.get_object_dict()
        host_dict['labels'] = [label.name for label in host_obj.label_list]
        host_dict['platform'], host_dict['atomic_group'] = (
            rpc_utils.find_platform_and_atomic_group(host_obj))
        host_dict['acls'] = [acl.name for acl in host_obj.acl_list]
        host_dict['attributes'] = dict(
            (attribute.attribute, attribute.value)
            for attribute in host_obj.attribute_list)
        host_dicts.append(host_dict)
    return rpc_utils.prepare_for_serialization(host_dicts)
Exemple #5
0
def get_hosts(multiple_labels=(), exclude_only_if_needed_labels=False,
              exclude_atomic_group_hosts=False, valid_only=True, **filter_data):
    """
    Get hosts.

    :param multiple_labels: match hosts in all of the labels given (optional).
    Should be a list of label names.
    :param exclude_only_if_needed_labels: Exclude hosts with
    at least one "only_if_needed" label applied (optional).
    :param exclude_atomic_group_hosts: Exclude hosts that have one or more
            atomic group labels associated with them.
    :param valid_only: Filter valid hosts (optional).
    :param filter_data: Filters out which hosts to get.
    :return: Sequence of hosts.
    """
    hosts = rpc_utils.get_host_query(multiple_labels,
                                     exclude_only_if_needed_labels,
                                     exclude_atomic_group_hosts,
                                     valid_only, filter_data)
    hosts = list(hosts)
    models.Host.objects.populate_relationships(hosts, models.Label,
                                               'label_list')
    models.Host.objects.populate_relationships(hosts, models.AclGroup,
                                               'acl_list')
    models.Host.objects.populate_relationships(hosts, models.HostAttribute,
                                               'attribute_list')

    install_server = None
    install_server_info = get_install_server_info()
    install_server_type = install_server_info.get('type', None)
    install_server_url = install_server_info.get('xmlrpc_url', None)

    if install_server_type == 'cobbler' and install_server_url:
        install_server = xmlrpclib.ServerProxy(install_server_url)

    host_dicts = []
    for host_obj in hosts:
        host_dict = host_obj.get_object_dict()
        host_dict['labels'] = [label.name for label in host_obj.label_list]
        host_dict['platform'], host_dict['atomic_group'] = (rpc_utils.
                                                            find_platform_and_atomic_group(host_obj))
        host_dict['acls'] = [acl.name for acl in host_obj.acl_list]
        host_dict['attributes'] = dict((attribute.attribute, attribute.value)
                                       for attribute in host_obj.attribute_list)

        error_encountered = True
        if install_server is not None:
            system_params = {"name": host_dict['hostname']}
            system_list = install_server.find_system(system_params, True)

            if len(system_list) < 1:
                msg = 'System "%s" not found on install server'
                rpc_logger = logging.getLogger('rpc_logger')
                rpc_logger.info(msg, host_dict['hostname'])

            elif len(system_list) > 1:
                msg = 'Found multiple systems on install server named %s'

                if install_server_type == 'cobbler':
                    msg = '%s. This should never happen on cobbler' % msg
                rpc_logger = logging.getLogger('rpc_logger')
                rpc_logger.error(msg, host_dict['hostname'])

            else:
                system = system_list[0]

                if host_dict['platform']:
                    error_encountered = False
                    profiles = sorted(install_server.get_item_names('profile'))
                    host_dict['profiles'] = profiles
                    host_dict['profiles'].insert(0, 'Do_not_install')
                    use_current_profile = settings.get_value('INSTALL_SERVER',
                                                             'use_current_profile', type=bool, default=True)
                    if use_current_profile:
                        host_dict['current_profile'] = system['profile']
                    else:
                        host_dict['current_profile'] = 'Do_not_install'

        if error_encountered:
            host_dict['profiles'] = ['N/A']
            host_dict['current_profile'] = 'N/A'

        host_dicts.append(host_dict)

    return rpc_utils.prepare_for_serialization(host_dicts)
Exemple #6
0
def get_hosts(
    multiple_labels=(),
    exclude_only_if_needed_labels=False,
    exclude_atomic_group_hosts=False,
    valid_only=True,
    **filter_data
):
    """
    :param multiple_labels: match hosts in all of the labels given.  Should
            be a list of label names.
    :param exclude_only_if_needed_labels: Exclude hosts with at least one
            "only_if_needed" label applied.
    :param exclude_atomic_group_hosts: Exclude hosts that have one or more
            atomic group labels associated with them.
    """
    hosts = rpc_utils.get_host_query(
        multiple_labels, exclude_only_if_needed_labels, exclude_atomic_group_hosts, valid_only, filter_data
    )
    hosts = list(hosts)
    models.Host.objects.populate_relationships(hosts, models.Label, "label_list")
    models.Host.objects.populate_relationships(hosts, models.AclGroup, "acl_list")
    models.Host.objects.populate_relationships(hosts, models.HostAttribute, "attribute_list")

    install_server = None
    install_server_info = get_install_server_info()
    install_server_type = install_server_info.get("type", None)
    install_server_url = install_server_info.get("xmlrpc_url", None)

    if install_server_type == "cobbler" and install_server_url:
        install_server = xmlrpclib.ServerProxy(install_server_url)

    host_dicts = []
    for host_obj in hosts:
        host_dict = host_obj.get_object_dict()
        host_dict["labels"] = [label.name for label in host_obj.label_list]
        host_dict["platform"], host_dict["atomic_group"] = rpc_utils.find_platform_and_atomic_group(host_obj)
        host_dict["acls"] = [acl.name for acl in host_obj.acl_list]
        host_dict["attributes"] = dict((attribute.attribute, attribute.value) for attribute in host_obj.attribute_list)

        error_encountered = True
        if install_server is not None:
            system_params = {"name": host_dict["hostname"]}
            system_list = install_server.find_system(system_params, True)

            if len(system_list) < 1:
                msg = 'System "%s" not found on install server'
                rpc_logger = logging.getLogger("rpc_logger")
                rpc_logger.info(msg, host_dict["hostname"])

            elif len(system_list) > 1:
                msg = "Found multiple systems on install server named %s"

                if install_server_type == "cobbler":
                    msg = "%s. This should never happen on cobbler" % msg
                rpc_logger = logging.getLogger("rpc_logger")
                rpc_logger.error(msg, host_dict["hostname"])

            else:
                system = system_list[0]

                if host_dict["platform"]:
                    error_encountered = False
                    profiles = sorted(install_server.get_item_names("profile"))
                    host_dict["profiles"] = profiles
                    host_dict["profiles"].insert(0, "Do_not_install")
                    use_current_profile = settings.get_value(
                        "INSTALL_SERVER", "use_current_profile", type=bool, default=True
                    )
                    if use_current_profile:
                        host_dict["current_profile"] = system["profile"]
                    else:
                        host_dict["current_profile"] = "Do_not_install"

        if error_encountered:
            host_dict["profiles"] = ["N/A"]
            host_dict["current_profile"] = "N/A"

        host_dicts.append(host_dict)

    return rpc_utils.prepare_for_serialization(host_dicts)
Exemple #7
0
def get_hosts(multiple_labels=(),
              exclude_only_if_needed_labels=False,
              exclude_atomic_group_hosts=False,
              valid_only=True,
              **filter_data):
    """
    Get hosts.

    :param multiple_labels: match hosts in all of the labels given (optional).
    Should be a list of label names.
    :param exclude_only_if_needed_labels: Exclude hosts with
    at least one "only_if_needed" label applied (optional).
    :param exclude_atomic_group_hosts: Exclude hosts that have one or more
            atomic group labels associated with them.
    :param valid_only: Filter valid hosts (optional).
    :param filter_data: Filters out which hosts to get.
    :return: Sequence of hosts.
    """
    hosts = rpc_utils.get_host_query(multiple_labels,
                                     exclude_only_if_needed_labels,
                                     exclude_atomic_group_hosts, valid_only,
                                     filter_data)
    hosts = list(hosts)
    models.Host.objects.populate_relationships(hosts, models.Label,
                                               'label_list')
    models.Host.objects.populate_relationships(hosts, models.AclGroup,
                                               'acl_list')
    models.Host.objects.populate_relationships(hosts, models.HostAttribute,
                                               'attribute_list')

    install_server = None
    install_server_info = get_install_server_info()
    install_server_type = install_server_info.get('type', None)
    install_server_url = install_server_info.get('xmlrpc_url', None)

    if install_server_type == 'cobbler' and install_server_url:
        install_server = xmlrpclib.ServerProxy(install_server_url)

    host_dicts = []
    for host_obj in hosts:
        host_dict = host_obj.get_object_dict()
        host_dict['labels'] = [label.name for label in host_obj.label_list]
        host_dict['platform'], host_dict['atomic_group'] = (
            rpc_utils.find_platform_and_atomic_group(host_obj))
        host_dict['acls'] = [acl.name for acl in host_obj.acl_list]
        host_dict['attributes'] = dict(
            (attribute.attribute, attribute.value)
            for attribute in host_obj.attribute_list)

        error_encountered = True
        if install_server is not None:
            system_params = {"name": host_dict['hostname']}
            system_list = install_server.find_system(system_params, True)

            if len(system_list) < 1:
                msg = 'System "%s" not found on install server'
                rpc_logger = logging.getLogger('rpc_logger')
                rpc_logger.info(msg, host_dict['hostname'])

            elif len(system_list) > 1:
                msg = 'Found multiple systems on install server named %s'

                if install_server_type == 'cobbler':
                    msg = '%s. This should never happen on cobbler' % msg
                rpc_logger = logging.getLogger('rpc_logger')
                rpc_logger.error(msg, host_dict['hostname'])

            else:
                system = system_list[0]

                if host_dict['platform']:
                    error_encountered = False
                    profiles = sorted(install_server.get_item_names('profile'))
                    host_dict['profiles'] = profiles
                    host_dict['profiles'].insert(0, 'Do_not_install')
                    use_current_profile = settings.get_value(
                        'INSTALL_SERVER',
                        'use_current_profile',
                        type=bool,
                        default=True)
                    if use_current_profile:
                        host_dict['current_profile'] = system['profile']
                    else:
                        host_dict['current_profile'] = 'Do_not_install'

        if error_encountered:
            host_dict['profiles'] = ['N/A']
            host_dict['current_profile'] = 'N/A'

        host_dicts.append(host_dict)

    return rpc_utils.prepare_for_serialization(host_dicts)