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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 """ | 72 """ |
73 Create an instance of HostAttribute for the given hostname. | 73 Create an instance of HostAttribute for the given hostname. |
74 We look up the host in both the hardcoded configuration and | 74 We look up the host in both the hardcoded configuration and |
75 the AFE models if they can be found. | 75 the AFE models if they can be found. |
76 """ | 76 """ |
77 self._add_attributes(_DEFAULT_ATTRIBUTES) | 77 self._add_attributes(_DEFAULT_ATTRIBUTES) |
78 if host in private_host_attributes: | 78 if host in private_host_attributes: |
79 self._add_attributes(private_host_attributes[host]) | 79 self._add_attributes(private_host_attributes[host]) |
80 if has_models: | 80 if has_models: |
81 host_obj = models.Host.valid_objects.get(hostname=host) | 81 host_obj = models.Host.valid_objects.get(hostname=host) |
82 self._add_attributes(host_obj.labels.all()) | 82 self._add_attributes([label.name for label in |
| 83 host_obj.labels.all()]) |
83 for key, value in self.__dict__.items(): | 84 for key, value in self.__dict__.items(): |
84 logging.info('Host attribute: %s => %s', key, value) | 85 logging.info('Host attribute: %s => %s', key, value) |
85 | 86 |
86 | 87 |
87 def _add_attributes(self, attributes): | 88 def _add_attributes(self, attributes): |
88 for attribute in attributes: | 89 for attribute in attributes: |
89 splitnames = attribute.split(',') | 90 splitnames = attribute.split(',') |
90 value = ','.join(splitnames[1:]) | 91 value = ','.join(splitnames[1:]) |
| 92 if len(splitnames) == 1: |
| 93 continue |
91 if value == 'True': | 94 if value == 'True': |
92 value = True | 95 value = True |
93 elif value == 'False': | 96 elif value == 'False': |
94 value = False | 97 value = False |
95 elif splitnames[1] == 'string': | 98 elif splitnames[1] == 'string': |
96 value = ','.join(splitnames[2:]) | 99 logging.info('Non-attribute string "%s" is ignored' % attribute) |
97 else: | |
98 log.info('Non-attribute string "%s" is ignored' % attribute) | |
99 continue | 100 continue |
100 setattr(self, splitnames[0], value) | 101 setattr(self, splitnames[0], value) |
OLD | NEW |