# # Copyright 2008 Google Inc. All Rights Reserved. """ The host module contains the objects and method used to manage a host in Autotest. The valid actions are: create: adds host(s) delete: deletes host(s) list: lists host(s) stat: displays host(s) information mod: modifies host(s) jobs: lists all jobs that ran on host(s) The common options are: -M|--mlist: file containing a list of machines See topic_common.py for a High Level Design and Algorithm. """ import re from autotest_lib.cli import action_common, topic_common from autotest_lib.client.common_lib import host_protections class host(topic_common.atest): """Host class atest host [create|delete|list|stat|mod|jobs] """ usage_action = '[create|delete|list|stat|mod|jobs]' topic = msg_topic = 'host' msg_items = '' protections = host_protections.Protection.names def __init__(self): """Add to the parser the options common to all the host actions""" super(host, self).__init__() self.parser.add_option('-M', '--mlist', help='File listing the machines', type='string', default=None, metavar='MACHINE_FLIST') self.topic_parse_info = topic_common.item_parse_info( attribute_name='hosts', filename_option='mlist', use_leftover=True) def _parse_lock_options(self, options): if options.lock and options.unlock: self.invalid_syntax('Only specify one of ' '--lock and --unlock.') if options.lock: self.data['locked'] = True self.messages.append('Locked host') elif options.unlock: self.data['locked'] = False self.data['lock_reason'] = '' self.messages.append('Unlocked host') if options.lock and options.lock_reason: self.data['lock_reason'] = options.lock_reason def _cleanup_labels(self, labels, platform=None): """Removes the platform label from the overall labels""" if platform: return [label for label in labels if label != platform] else: try: return [label for label in labels if not label['platform']] except TypeError: # This is a hack - the server will soon # do this, so all this code should be removed. return labels def get_items(self): return self.hosts class host_help(host): """Just here to get the atest logic working. Usage is set by its parent""" pass class host_list(action_common.atest_list, host): """atest host list [--mlist |] [--label