| OLD | NEW |
| 1 # Copyright 2016 The LUCI Authors. All rights reserved. | 1 # Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # that can be found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
| 4 | 4 |
| 5 """Utilities for reading GCE Backend configuration.""" | 5 """Utilities for reading GCE Backend configuration.""" |
| 6 | 6 |
| 7 import collections | 7 import collections |
| 8 import logging | 8 import logging |
| 9 | 9 |
| 10 from components import utils | 10 from components import utils |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 'template.cfg', configuration.template_config, | 58 'template.cfg', configuration.template_config, |
| 59 config_pb2.InstanceTemplateConfig() | 59 config_pb2.InstanceTemplateConfig() |
| 60 ) | 60 ) |
| 61 manager_cfg = _adds_cfg_to_message( | 61 manager_cfg = _adds_cfg_to_message( |
| 62 'manager.cfg', configuration.manager_config, | 62 'manager.cfg', configuration.manager_config, |
| 63 config_pb2.InstanceGroupManagerConfig() | 63 config_pb2.InstanceGroupManagerConfig() |
| 64 ) | 64 ) |
| 65 return template_cfg, manager_cfg | 65 return template_cfg, manager_cfg |
| 66 | 66 |
| 67 | 67 |
| 68 def count_instances(): |
| 69 """Counts the numbers of instances configured by each instance template. |
| 70 |
| 71 Returns: |
| 72 A dict mapping instance template name to a list of (min, max). |
| 73 """ |
| 74 # Aggregate the numbers of instances configured in each instance group manager |
| 75 # created for each instance template. |
| 76 totals = collections.defaultdict(lambda: [0, 0]) |
| 77 _, manager_cfg = Configuration.load() |
| 78 for manager in manager_cfg.managers: |
| 79 totals[manager.template_base_name][0] += manager.minimum_size |
| 80 totals[manager.template_base_name][1] += manager.maximum_size |
| 81 return totals |
| 82 |
| 83 |
| 68 def update_template_configs(): | 84 def update_template_configs(): |
| 69 """Updates the local template configuration from the config service. | 85 """Updates the local template configuration from the config service. |
| 70 | 86 |
| 71 Ensures that all config files are at the same path revision. | 87 Ensures that all config files are at the same path revision. |
| 72 """ | 88 """ |
| 73 template_revision, template_config = config.get_self_config( | 89 template_revision, template_config = config.get_self_config( |
| 74 TEMPLATES_CFG_FILENAME, config_pb2.InstanceTemplateConfig, | 90 TEMPLATES_CFG_FILENAME, config_pb2.InstanceTemplateConfig, |
| 75 store_last_good=True) | 91 store_last_good=True) |
| 76 manager_revision, manager_config = config.get_self_config( | 92 manager_revision, manager_config = config.get_self_config( |
| 77 MANAGERS_CFG_FILENAME, config_pb2.InstanceGroupManagerConfig, | 93 MANAGERS_CFG_FILENAME, config_pb2.InstanceGroupManagerConfig, |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 if cfg.mp_server != current_config.instance_url: | 210 if cfg.mp_server != current_config.instance_url: |
| 195 logging.info('Updating Machine Provider server to %s', cfg.mp_server) | 211 logging.info('Updating Machine Provider server to %s', cfg.mp_server) |
| 196 current_config.modify(instance_url=cfg.mp_server) | 212 current_config.modify(instance_url=cfg.mp_server) |
| 197 return rev, cfg | 213 return rev, cfg |
| 198 | 214 |
| 199 | 215 |
| 200 @utils.cache_with_expiration(60) | 216 @utils.cache_with_expiration(60) |
| 201 def settings(): | 217 def settings(): |
| 202 """Loads settings from an NDB-based cache or a default one if not present.""" | 218 """Loads settings from an NDB-based cache or a default one if not present.""" |
| 203 return _get_settings()[1] | 219 return _get_settings()[1] |
| OLD | NEW |