def _disable_host_installation(self, host): server_info = remote.get_install_server_info() if remote.install_server_is_configured(): timeout = settings.get_value('INSTALL_SERVER', 'default_install_timeout', type=int, default=3600) end_time = time.time() + (timeout / 10) step = int(timeout / 100) ServerInterface = remote.RemoteHost.INSTALL_SERVER_MAPPING[ server_info['type']] server_interface = None while time.time() < end_time: try: server_interface = ServerInterface(**server_info) break except socket.error: logging.error( 'Install server unavailable. Trying ' 'again in %s s...', step) time.sleep(step) if server_interface is None: raise InstallServerUnavailable( "%s install server at (%s) " "unavailable. Tried to " "communicate for %s s" % (server_info['type'], server_info['xmlrpc_url'], timeout / 10)) server_interface._disable_host_installation(host)
def _disable_host_installation(self, host): server_info = remote.get_install_server_info() if remote.install_server_is_configured(): timeout = settings.get_value('INSTALL_SERVER', 'default_install_timeout', type=int, default=3600) end_time = time.time() + (timeout / 10) step = int(timeout / 100) ServerInterface = remote.RemoteHost.INSTALL_SERVER_MAPPING[server_info['type']] server_interface = None while time.time() < end_time: try: server_interface = ServerInterface(**server_info) break except socket.error: logging.error('Install server unavailable. Trying ' 'again in %s s...', step) time.sleep(step) if server_interface is None: raise InstallServerUnavailable("%s install server at (%s) " "unavailable. Tried to " "communicate for %s s" % (server_info['type'], server_info['xmlrpc_url'], timeout / 10)) server_interface._disable_host_installation(host)
def get_install_server_profiles(): 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) if install_server is None: return None return install_server.get_item_names("profile")
def get_install_server_profiles(): 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) if install_server is None: return None return install_server.get_item_names('profile')
def get_install_server_profiles(): 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) if install_server is None: return None return install_server.get_item_names('profile')
def get_install_server_profiles(): """ Get install server profiles. :return: Sequence of profiles. """ 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 = xmlrpc.client.ServerProxy(install_server_url) if install_server is None: return None return install_server.get_item_names('profile')
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)
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)
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)