[pkg-eucalyptus-commits] [SCM] managing cloud instances for Eucalyptus branch, master, updated. 3.0.0-alpha3-257-g1da8e3a

Garrett Holmstrom gholms at fedoraproject.org
Sun Jun 16 02:30:24 UTC 2013


The following commit has been merged in the master branch:
commit 6cde43ae86b982bd8a58e6e0a5b52bf282e88554
Author: Garrett Holmstrom <gholms at fedoraproject.org>
Date:   Wed Feb 20 14:09:13 2013 -0800

    Move suite-defined methods into their own class

diff --git a/euca2ools/commands/__init__.py b/euca2ools/commands/__init__.py
index 50df0bf..f829b62 100644
--- a/euca2ools/commands/__init__.py
+++ b/euca2ools/commands/__init__.py
@@ -31,97 +31,40 @@
 import glob
 import os.path
 import platform
-import requestbuilder.command
-import requestbuilder.request
+import requestbuilder
 import requests
 import sys
 from .. import __version__
 
-class Euca2oolsCommand(requestbuilder.command.BaseCommand):
-    def __init__(self, **kwargs):
-        self._config_files = None
-        requestbuilder.request.BaseCommand.__init__(self, **kwargs)
+class Euca2ools(object):
+    '''
+    A class with attributes and methods that define the entire euca2ools suite
+    '''
 
-    @property
-    def config_files(self):
-        if self._config_files is None:
-            self._config_files = _list_config_files()
-        return self._config_files
-
-    @staticmethod
-    def print_version_and_exit():
-        _print_version_and_exit()
-
-
-# FIXME:  Duplicating requestbuilder's hierarchy is dumb
-class Euca2oolsRequest(requestbuilder.request.BaseRequest):
-    def __init__(self, **kwargs):
-        self._config_files = None
+    def __init__(self):
         self.__user_agent = None
-        requestbuilder.request.BaseRequest.__init__(self, **kwargs)
-
-    @property
-    def config_files(self):
-        if self._config_files is None:
-            self._config_files = _list_config_files()
-        return self._config_files
-
-    @property
-    def user_agent(self):
-        if self.__user_agent is None:
-            user_agent_bits = ['euca2ools/{0}'.format(__version__)]
-
-            tokens = []
-            impl = platform.python_implementation()
-            if impl == 'PyPy':
-                impl_version = '{0}.{1}.{2}'.format(
-                        sys.pypy_version_info.major,
-                        sys.pypy_version_info.minor,
-                        sys.pypy_version_info.micro)
-                if sys.pypy_version_info.releaselevel != 'final':
-                    impl_version += sys.pypy_version_info.releaselevel
-            else:
-                # I'm guessing for non-CPython implementations; feel free to
-                # submit patches or the needed implementation-specific API
-                # references.
-                impl_version = platform.python_version()
-            tokens.append('{0} {1}'.format(impl, impl_version))
-            plat = []
-            try:
-                plat.append(platform.system())
-                plat.append(platform.release())
-            except IOError:
-                pass
-            if plat:
-                tokens.append(' '.join(plat))
-            tokens.append(platform.machine())
-            user_agent_bits.append('({0})'.format('; '.join(tokens)))
-
-            user_agent_bits.append('requestbuilder/{0}'.format(
-                    requestbuilder.__version__))
-            user_agent_bits.append('requests/{0}'.format(requests.__version__))
-            self.__user_agent = ' '.join(user_agent_bits)
-        return self.__user_agent
 
     @staticmethod
     def print_version_and_exit():
-        _print_version_and_exit()
+        print >> sys.stderr, 'euca2ools', __version__, '(Sparta)'
+        try:
+            if os.path.isfile('/etc/eucalyptus/eucalyptus-version'):
+                with open('/etc/eucalyptus/eucalyptus-version') as ver_file:
+                    euca_version = ver_file.readline().strip()
+                print >> sys.stderr, 'eucalyptus', euca_version
+        except:
+            # Those were just more crunchy bits.  If they don't work, oh well!
+            pass
+        sys.exit()
 
+    @staticmethod
+    def list_config_files():
+        sys_config_files = ['/etc/euca2ools.ini']
+        user_glob = os.path.join(os.path.expanduser('~/.euca'), '*.ini')
+        user_config_files = sorted(glob.glob(user_glob))
+        return sys_config_files + user_config_files
 
-class Euca2oolsQueryRequest(requestbuilder.request.AWSQueryRequest):
-    def __init__(self, **kwargs):
-        self._config_files = None
-        self.__user_agent = None
-        requestbuilder.request.AWSQueryRequest.__init__(self, **kwargs)
-
-    @property
-    def config_files(self):
-        if self._config_files is None:
-            self._config_files = _list_config_files()
-        return self._config_files
-
-    @property
-    def user_agent(self):
+    def get_user_agent(self):
         if self.__user_agent is None:
             user_agent_bits = ['euca2ools/{0}'.format(__version__)]
 
@@ -156,22 +99,3 @@ class Euca2oolsQueryRequest(requestbuilder.request.AWSQueryRequest):
             user_agent_bits.append('requests/{0}'.format(requests.__version__))
             self.__user_agent = ' '.join(user_agent_bits)
         return self.__user_agent
-
-    @staticmethod
-    def print_version_and_exit():
-        _print_version_and_exit()
-
-
-def _list_config_files():
-    sys_config_files = ['/etc/euca2ools.ini']
-    user_glob = os.path.join(os.path.expanduser('~/.euca'), '*.ini')
-    user_config_files = sorted(glob.glob(user_glob))
-    return sys_config_files + user_config_files
-
-
-def _print_version_and_exit():
-    print >> sys.stderr, 'euca2ools {0} (Sparta)'.format(__version__)
-    if os.path.isfile('/etc/eucalyptus/eucalyptus-version'):
-        with open('/etc/eucalyptus/eucalyptus-version') as version_file:
-            print 'eucalyptus {0}'.format(version_file.readline().strip())
-    sys.exit()
diff --git a/euca2ools/commands/euare/__init__.py b/euca2ools/commands/euare/__init__.py
index df2405c..40b7c4c 100644
--- a/euca2ools/commands/euare/__init__.py
+++ b/euca2ools/commands/euare/__init__.py
@@ -1,6 +1,6 @@
 # Software License Agreement (BSD License)
 #
-# Copyright (c) 2009-2012, Eucalyptus Systems, Inc.
+# Copyright (c) 2009-2013, Eucalyptus Systems, Inc.
 # All rights reserved.
 #
 # Redistribution and use of this software in source and binary forms, with or
@@ -31,8 +31,9 @@
 from euca2ools.exceptions import AWSError
 from requestbuilder import Arg, MutuallyExclusiveArgList, SERVICE
 import requestbuilder.auth
+import requestbuilder.request
 import requestbuilder.service
-from .. import Euca2oolsQueryRequest
+from .. import Euca2ools
 
 class Euare(requestbuilder.service.BaseService):
     NAME = 'iam'
@@ -52,12 +53,14 @@ class Euare(requestbuilder.service.BaseService):
         raise AWSError(response)
 
 
-class EuareRequest(Euca2oolsQueryRequest):
+class EuareRequest(requestbuilder.request.AWSQueryRequest):
+    SUITE = Euca2ools
     SERVICE_CLASS = Euare
     METHOD = 'POST'
 
     def parse_response(self, response):
-        response_dict = Euca2oolsQueryRequest.parse_response(self, response)
+        response_dict = requestbuilder.request.AWSQueryRequest.parse_response(
+            self, response)
         # EUARE responses enclose their useful data inside FooResponse
         # elements.  If that's all we have after stripping out ResponseMetadata
         # then just return its contents.
diff --git a/euca2ools/commands/euca/__init__.py b/euca2ools/commands/euca/__init__.py
index ad19ad7..c738c2e 100644
--- a/euca2ools/commands/euca/__init__.py
+++ b/euca2ools/commands/euca/__init__.py
@@ -36,12 +36,13 @@ from requestbuilder import Arg, MutuallyExclusiveArgList, AUTH, SERVICE
 from requestbuilder.auth import QuerySigV2Auth
 from requestbuilder.exceptions import AuthError
 from requestbuilder.mixins import TabifyingCommand
+import requestbuilder.request
 import requestbuilder.service
 import requests
 import shlex
 from string import Template
 import sys
-from .. import Euca2oolsQueryRequest
+from .. import Euca2ools
 
 class EC2CompatibleQuerySigV2Auth(QuerySigV2Auth):
     # -a and -s are deprecated; remove them in 3.2
@@ -164,16 +165,18 @@ class Eucalyptus(requestbuilder.service.BaseService):
         raise AWSError(response)
 
 
-class EucalyptusRequest(Euca2oolsQueryRequest, TabifyingCommand):
+class EucalyptusRequest(requestbuilder.request.AWSQueryRequest,
+                        TabifyingCommand):
+    SUITE = Euca2ools
     SERVICE_CLASS = Eucalyptus
+    METHOD = 'POST'
 
     def __init__(self, **kwargs):
-        Euca2oolsQueryRequest.__init__(self, **kwargs)
-        self.method = 'POST'  ## FIXME
+        requestbuilder.request.AWSQueryRequest.__init__(self, **kwargs)
 
     def parse_http_response(self, response_body):
-        response = Euca2oolsQueryRequest.parse_http_response(self,
-                                                             response_body)
+        response = requestbuilder.request.AWSQueryRequest.parse_http_response(
+            self, response_body)
         # Compute cloud controller responses enclose their useful data inside
         # FooResponse elements.  If that's all we have after stripping out
         # RequestId then just return its contents.
diff --git a/euca2ools/commands/walrus/__init__.py b/euca2ools/commands/walrus/__init__.py
index c16aa4b..6e2f1a7 100644
--- a/euca2ools/commands/walrus/__init__.py
+++ b/euca2ools/commands/walrus/__init__.py
@@ -36,7 +36,7 @@ import requestbuilder.service
 from requestbuilder.xmlparse import parse_aws_xml
 import string
 import urlparse
-from .. import Euca2oolsRequest
+from .. import Euca2ools
 
 class Walrus(requestbuilder.service.BaseService):
     NAME = 's3'
@@ -55,11 +55,12 @@ class Walrus(requestbuilder.service.BaseService):
         raise AWSError(response)
 
 
-class WalrusRequest(Euca2oolsRequest):
+class WalrusRequest(requestbuilder.request.BaseRequest):
+    SUITE = Euca2ools
     SERVICE_CLASS = Walrus
 
     def __init__(self, **kwargs):
-        Euca2oolsRequest.__init__(self, **kwargs)
+        requestbuilder.request.BaseRequest.__init__(self, **kwargs)
         self.redirects_left = 3
 
     def handle_server_error(self, err):

-- 
managing cloud instances for Eucalyptus



More information about the pkg-eucalyptus-commits mailing list