| OLD | NEW |
| 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import logging, os, utils | 5 import logging, os, utils |
| 6 | 6 |
| 7 # Host attributes are specified a strings with the format: | 7 # Host attributes are specified a strings with the format: |
| 8 # <key>{,<value>}? | 8 # <key>{,<value>}? |
| 9 # | 9 # |
| 10 # A machine may have a list of strings for attributes like: | 10 # A machine may have a list of strings for attributes like: |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 class HostAttributes(object): | 71 class HostAttributes(object): |
| 72 | 72 |
| 73 | 73 |
| 74 def __init__(self, host): | 74 def __init__(self, host): |
| 75 """ | 75 """ |
| 76 Create an instance of HostAttribute for the given hostname. | 76 Create an instance of HostAttribute for the given hostname. |
| 77 We look up the host in both the hardcoded configuration and | 77 We look up the host in both the hardcoded configuration and |
| 78 the AFE models if they can be found. | 78 the AFE models if they can be found. |
| 79 """ | 79 """ |
| 80 self._add_attributes(_DEFAULT_ATTRIBUTES) | 80 self._add_attributes(_DEFAULT_ATTRIBUTES) |
| 81 if private_host_attributes is not None: |
| 82 logging.info('Using your private_host_attributes file') |
| 81 if host in private_host_attributes: | 83 if host in private_host_attributes: |
| 84 logging.info('Using private_host_attributes file for %s' % host) |
| 82 self._add_attributes(private_host_attributes[host]) | 85 self._add_attributes(private_host_attributes[host]) |
| 83 if has_models: | 86 if has_models: |
| 84 host_obj = models.Host.valid_objects.get(hostname=host) | 87 host_obj = models.Host.valid_objects.get(hostname=host) |
| 85 self._add_attributes([label.name for label in | 88 self._add_attributes([label.name for label in |
| 86 host_obj.labels.all()]) | 89 host_obj.labels.all()]) |
| 87 for key, value in self.__dict__.items(): | 90 for key, value in self.__dict__.items(): |
| 88 logging.info('Host attribute: %s => %s', key, value) | 91 logging.info('Host attribute: %s => %s', key, value) |
| 89 | 92 |
| 90 | 93 |
| 91 def _add_attributes(self, attributes): | 94 def _add_attributes(self, attributes): |
| 92 for attribute in attributes: | 95 for attribute in attributes: |
| 93 splitnames = attribute.split(',') | 96 splitnames = attribute.split(',') |
| 94 value = ','.join(splitnames[1:]) | 97 value = ','.join(splitnames[1:]) |
| 95 if len(splitnames) == 1: | 98 if len(splitnames) == 1: |
| 96 continue | 99 continue |
| 97 if value == 'True': | 100 if value == 'True': |
| 98 value = True | 101 value = True |
| 99 elif value == 'False': | 102 elif value == 'False': |
| 100 value = False | 103 value = False |
| 101 elif splitnames[1] == 'string' and len(splitnames) > 2: | 104 elif splitnames[1] == 'string' and len(splitnames) > 2: |
| 102 value = ','.join(splitnames[2:]) | 105 value = ','.join(splitnames[2:]) |
| 103 else: | 106 else: |
| 104 logging.info('Non-attribute string "%s" is ignored' % attribute) | 107 logging.info('Non-attribute string "%s" is ignored' % attribute) |
| 105 continue | 108 continue |
| 106 setattr(self, splitnames[0], value) | 109 setattr(self, splitnames[0], value) |
| OLD | NEW |