Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: appengine/gce-backend/instance_group_managers.py

Issue 2996623002: Include zone in GCE instance base name (Closed)
Patch Set: Unit test Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | appengine/gce-backend/instance_group_managers_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 operating on instance group managers.""" 5 """Utilities for operating on instance group managers."""
6 6
7 import collections 7 import collections
8 import json 8 import json
9 import logging 9 import logging
10 import math 10 import math
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 """Returns the base name to use when creating an instance group manager. 58 """Returns the base name to use when creating an instance group manager.
59 59
60 The base name is suffixed randomly by GCE when naming instances. 60 The base name is suffixed randomly by GCE when naming instances.
61 61
62 Args: 62 Args:
63 instance_group_manager: models.InstanceGroupManager. 63 instance_group_manager: models.InstanceGroupManager.
64 64
65 Returns: 65 Returns:
66 A string. 66 A string.
67 """ 67 """
68 # <base-name>-<abbreviated-revision> 68 # <base-name>-<abbreviated-revision>-<zone>
69 return '%s-%s' % ( 69 # TODO(smut): Ensure this name is < 59 characters because the final
70 # instance name must be < 64 characters and the instance group manager
71 # will add a 5 character random suffix when creating instances.
72 return '%s-%s-%s' % (
70 instance_group_manager.key.parent().parent().id(), 73 instance_group_manager.key.parent().parent().id(),
71 instance_group_manager.key.parent().id()[:8], 74 instance_group_manager.key.parent().id()[:8],
75 instance_group_manager.key.id(),
72 ) 76 )
73 77
74 78
75 @ndb.transactional 79 @ndb.transactional
76 def set_instances(key, keys): 80 def set_instances(key, keys):
77 """Associates the given Instances with the given InstanceGroupManager. 81 """Associates the given Instances with the given InstanceGroupManager.
78 82
79 Args: 83 Args:
80 key: ndb.Key for a models.InstanceGroupManager entity. 84 key: ndb.Key for a models.InstanceGroupManager entity.
81 keys: List of ndb.Keys for models.Instance entities. 85 keys: List of ndb.Keys for models.Instance entities.
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 Returns: 405 Returns:
402 A dict mapping instance template name to count of instances. 406 A dict mapping instance template name to count of instances.
403 """ 407 """
404 # Aggregate the number of instances owned by each instance group manager 408 # Aggregate the number of instances owned by each instance group manager
405 # created for each instance template. 409 # created for each instance template.
406 totals = collections.defaultdict(int) 410 totals = collections.defaultdict(int)
407 for instance_group_manager in models.InstanceGroupManager.query(): 411 for instance_group_manager in models.InstanceGroupManager.query():
408 instance_template_name = instance_group_manager.key.parent().parent().id() 412 instance_template_name = instance_group_manager.key.parent().parent().id()
409 totals[instance_template_name] += len(instance_group_manager.instances) 413 totals[instance_template_name] += len(instance_group_manager.instances)
410 return totals 414 return totals
OLDNEW
« no previous file with comments | « no previous file | appengine/gce-backend/instance_group_managers_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698