-
Notifications
You must be signed in to change notification settings - Fork 341
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract group functions into a utility module.
This patch extracts group checking functions into a dedicated module so that resource implementations are simplified. The module could later be used by the autoscaling engine as well. Change-Id: I99cdd8c9e8fe377e6923ab047a9c2ef08d1defad partial-blueprint: reorg-asg-code partial-blueprint: as-lib
- Loading branch information
Showing
11 changed files
with
242 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
import six | ||
|
||
|
||
def get_size(group): | ||
"""Get number of member resources managed by the specified group. | ||
The list of members are not sorted or returned. | ||
""" | ||
if group.nested(): | ||
resources = [r for r in six.itervalues(group.nested()) | ||
if r.status != r.FAILED] | ||
return len(resources) | ||
else: | ||
return 0 | ||
|
||
|
||
def get_members(group): | ||
"""Get a list of member resources managed by the specified group. | ||
Sort the list of instances first by created_time then by name. | ||
""" | ||
resources = [] | ||
if group.nested(): | ||
resources = [r for r in six.itervalues(group.nested()) | ||
if r.status != r.FAILED] | ||
|
||
return sorted(resources, key=lambda r: (r.created_time, r.name)) | ||
|
||
|
||
def get_member_refids(group, exclude=None): | ||
"""Get a list of member resources managed by the specified group. | ||
The list of resources is sorted first by created_time then by name. | ||
""" | ||
members = get_members(group) | ||
if len(members) == 0: | ||
return [] | ||
|
||
if exclude is None: | ||
exclude = [] | ||
return [r.FnGetRefId() for r in members | ||
if r.FnGetRefId() not in exclude] | ||
|
||
|
||
def get_member_names(group): | ||
"""Get a list of resource names of the resources in the specified group. | ||
Failed resources will be ignored. | ||
""" | ||
return [r.name for r in get_members(group)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.