[pkg-eucalyptus-commits] [euca2ools] 12/41: Implement auto-scaling DescribeTags
Charles Plessy
plessy at alioth.debian.org
Sat Oct 12 03:24:13 UTC 2013
This is an automated email from the git hooks/post-receive script.
plessy pushed a commit to branch master
in repository euca2ools.
commit 38192e85c0a55a16f5d781f18edc46f67aa75a9e
Author: Garrett Holmstrom <gholms at fedoraproject.org>
Date: Tue Jul 9 17:44:13 2013 -0700
Implement auto-scaling DescribeTags
Fixes half of TOOLS-351
---
bin/euscale-describe-tags | 6 ++
euca2ools/commands/autoscaling/argtypes.py | 19 +++++++
.../autoscaling/{argtypes.py => describetags.py} | 58 +++++++++-----------
man/euscale-describe-tags.1 | 40 ++++++++++++++
4 files changed, 91 insertions(+), 32 deletions(-)
diff --git a/bin/euscale-describe-tags b/bin/euscale-describe-tags
new file mode 100755
index 0000000..989317c
--- /dev/null
+++ b/bin/euscale-describe-tags
@@ -0,0 +1,6 @@
+#!/usr/bin/python -tt
+
+import euca2ools.commands.autoscaling.describetags
+
+if __name__ == '__main__':
+ euca2ools.commands.autoscaling.describetags.DescribeTags.run()
diff --git a/euca2ools/commands/autoscaling/argtypes.py b/euca2ools/commands/autoscaling/argtypes.py
index 7c22c41..8b0f3e4 100644
--- a/euca2ools/commands/autoscaling/argtypes.py
+++ b/euca2ools/commands/autoscaling/argtypes.py
@@ -27,6 +27,24 @@
from argparse import ArgumentTypeError
+def autoscaling_filter_def(filter_str):
+ filter_dict = {}
+ pieces = filter_str.split(',')
+ for piece in pieces:
+ piece = piece.strip()
+ if '=' not in piece:
+ raise ArgumentTypeError(
+ "invalid filter: each segment of '{0}' must have format "
+ "KEY=VALUE".format(piece))
+ key, val = piece.split('=', 1)
+ filter_dict.setdefault(key.strip(), [])
+ filter_dict[key.strip()].append(val.strip())
+ filter_list = []
+ for key, values in filter_dict.iteritems():
+ filter_list.append({'Name': key, 'Values': values})
+ return filter_list
+
+
def autoscaling_tag_def(tag_str):
tag_dict = {}
pieces = tag_str.split(',')
@@ -58,3 +76,4 @@ def autoscaling_tag_def(tag_str):
raise ArgumentTypeError(
"tag '{0}' must contain a 'k=' segment with a non-empty value")
return tag_dict
+
diff --git a/euca2ools/commands/autoscaling/argtypes.py b/euca2ools/commands/autoscaling/describetags.py
similarity index 52%
copy from euca2ools/commands/autoscaling/argtypes.py
copy to euca2ools/commands/autoscaling/describetags.py
index 7c22c41..992fad6 100644
--- a/euca2ools/commands/autoscaling/argtypes.py
+++ b/euca2ools/commands/autoscaling/describetags.py
@@ -23,38 +23,32 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+from euca2ools.commands.autoscaling import AutoScalingRequest
+from euca2ools.commands.autoscaling.argtypes import autoscaling_filter_def
+from requestbuilder import Arg
+from requestbuilder.mixins import TabifyingMixin
+from requestbuilder.response import PaginatedResponse
-from argparse import ArgumentTypeError
+class DescribeTags(AutoScalingRequest, TabifyingMixin):
+ DESCRIPTION = 'Describe auto-scaling tags'
+ ARGS = [Arg('--filter', dest='Filters.member',type=autoscaling_filter_def,
+ metavar='NAME=VALUE,...', action='append',
+ help='restrict results to those that meet criteria')]
+ LIST_TAGS = ['Tags']
-def autoscaling_tag_def(tag_str):
- tag_dict = {}
- pieces = tag_str.split(',')
- for piece in pieces:
- piece = piece.strip()
- if '=' not in piece:
- raise ArgumentTypeError(
- "invalid tag definition: each segment of '{0}' must have "
- "format KEY=VALUE".format(piece))
- key, val = piece.split('=', 1)
- if key == 'k':
- tag_dict['Key'] = val
- elif key == 'id':
- tag_dict['ResourceId'] = val
- elif key == 't':
- tag_dict['ResourceType'] = val
- elif key == 'v':
- tag_dict['Value'] = val
- elif key == 'p':
- if val.lower() in ('true', 'false'):
- tag_dict['PropagateAtLaunch'] = val.lower()
- else:
- raise ArgumentTypeError(
- "value for to 'p=' must be 'true' or 'false'")
- else:
- raise ArgumentTypeError(
- "unrecognized tag segment '{0}'".format(piece))
- if not tag_dict.get('Key'):
- raise ArgumentTypeError(
- "tag '{0}' must contain a 'k=' segment with a non-empty value")
- return tag_dict
+ def main(self):
+ return PaginatedResponse(self, (None,), ('Tags',))
+
+ def prepare_for_page(self, page):
+ # Pages are defined by NextToken
+ self.params['NextToken'] = page
+
+ def get_next_page(self, response):
+ return response.get('NextToken') or None
+
+ def print_result(self, result):
+ for tag in result.get('Tags', []):
+ print self.tabify(('TAG', tag.get('ResourceId'),
+ tag.get('ResourceType'), tag.get('Key'),
+ tag.get('Value'), tag.get('PropagateAtLaunch')))
diff --git a/man/euscale-describe-tags.1 b/man/euscale-describe-tags.1
new file mode 100644
index 0000000..22b7ef3
--- /dev/null
+++ b/man/euscale-describe-tags.1
@@ -0,0 +1,40 @@
+.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.41.2.
+.TH EUSCALE-DESCRIBE-TAGS "1" "July 2013" "euca2ools 3.0.0" "User Commands"
+.SH NAME
+euscale-describe-tags \- Describe auto-scaling tags
+.SH SYNOPSIS
+euscale\-describe\-tags [\-\-filter NAME=VALUE,...] [\-\-show\-empty\-fields]
+[\-\-region USER at REGION | \fB\-U\fR URL] [\-I KEY_ID]
+[\-S KEY] [\-\-debug] [\-\-debugger] [\-\-version] [\-h]
+.SH DESCRIPTION
+Describe auto\-scaling tags
+.SS "optional arguments:"
+.TP
+\fB\-\-filter\fR NAME=VALUE,...
+restrict results to those that meet criteria
+.TP
+\fB\-\-show\-empty\-fields\fR
+show empty values as "(nil)"
+.TP
+\fB\-\-region\fR USER at REGION
+name of the region and/or user in config files to use
+to connect to the service
+.TP
+\fB\-U\fR URL, \fB\-\-url\fR URL
+auto\-scaling service endpoint URL
+.HP
+\fB\-I\fR KEY_ID, \fB\-\-access\-key\-id\fR KEY_ID
+.HP
+\fB\-S\fR KEY, \fB\-\-secret\-key\fR KEY
+.TP
+\fB\-\-debug\fR
+show debugging output
+.TP
+\fB\-\-debugger\fR
+launch interactive debugger on error
+.TP
+\fB\-\-version\fR
+show the program's version and exit
+.TP
+\fB\-h\fR, \fB\-\-help\fR
+show this help message and exit
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-eucalyptus/euca2ools.git
More information about the pkg-eucalyptus-commits
mailing list