Skip to content

Commit

Permalink
frontend: add XMLRPC lookup of profile information from install serve…
Browse files Browse the repository at this point in the history
…r to get_hosts

Signed-off-by: Nishanth Aravamudan <[email protected]>
  • Loading branch information
Nishanth Aravamudan authored and lmr committed Jun 28, 2012
1 parent 1ec1559 commit c7af452
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
46 changes: 44 additions & 2 deletions frontend/afe/rpc_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion server/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
http://docs.djangoproject.com/en/dev/ref/models/querysets/#queryset-api
"""

import getpass, os, time, traceback, re
import getpass, os, time, traceback, re, xmlrpclib
try:
import autotest.common as common
except ImportError:
Expand Down

0 comments on commit c7af452

Please sign in to comment.