forked from autotest/autotest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
frontend: add XMLRPC lookup of profile information from install serve…
…r to get_hosts Signed-off-by: Nishanth Aravamudan <[email protected]>
- Loading branch information
Showing
2 changed files
with
45 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,14 +29,15 @@ | |
|
||
__author__ = '[email protected] (Steve Howard)' | ||
|
||
import datetime | ||
import datetime, xmlrpclib | ||
try: | ||
import autotest.common as common | ||
except ImportError: | ||
import common | ||
from autotest.frontend.afe import models, model_logic, model_attributes | ||
from autotest.frontend.afe import control_file, rpc_utils | ||
from autotest.frontend.afe import control_file, rpc_utils, rpcserver_logging | ||
from autotest.client.shared import global_config | ||
from autotest.server.hosts.remote import get_install_server_info | ||
|
||
|
||
# labels | ||
|
@@ -192,6 +193,15 @@ def get_hosts(multiple_labels=(), exclude_only_if_needed_labels=False, | |
'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() | ||
|
@@ -201,7 +211,39 @@ def get_hosts(multiple_labels=(), exclude_only_if_needed_labels=False, | |
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' | ||
rpcserver_logging.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 | ||
rpcserver_logging.rpc_logger.error(msg, host_dict['hostname']) | ||
|
||
else: | ||
system = system_list[0] | ||
|
||
if host_dict['platform']: | ||
error_encountered = False | ||
profile_params = {"comment":"*%s*" % host_dict['platform']} | ||
profiles = install_server.find_profile(profile_params) | ||
host_dict['profiles'] = profiles | ||
host_dict['current_profile'] = system['profile'] | ||
|
||
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) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters