Sfoglia il codice sorgente

Added debug_mode option to config. Fixed some typos.

Nuwan Goonasekera 10 anni fa
parent
commit
2739168566

+ 18 - 1
cloudbridge/cloud/base.py

@@ -4,6 +4,7 @@ Implementation of common methods across cloud providers.
 
 import itertools
 import logging
+import os
 import time
 
 import six
@@ -13,6 +14,7 @@ from cloudbridge.cloud.interfaces.resources \
     import InvalidConfigurationException
 from cloudbridge.cloud.interfaces.resources import Bucket
 from cloudbridge.cloud.interfaces.resources import BucketObject
+from cloudbridge.cloud.interfaces.resources import Configuration
 from cloudbridge.cloud.interfaces.resources import Instance
 from cloudbridge.cloud.interfaces.resources import InstanceState
 from cloudbridge.cloud.interfaces.resources import InstanceType
@@ -52,7 +54,7 @@ log = logging.getLogger(__name__)
 DEFAULT_RESULT_LIMIT = 50
 
 
-class BaseConfiguration(dict):
+class BaseConfiguration(Configuration):
 
     def __init__(self, user_config):
         self.update(user_config)
@@ -68,6 +70,21 @@ class BaseConfiguration(dict):
         """
         return self.get('result_limit', DEFAULT_RESULT_LIMIT)
 
+    @property
+    def debug_mode(self):
+        """
+        A flag indicating whether CloudBridge is in debug mode. Setting
+        this to True will cause the underlying provider's debug
+        output to be turned on.
+
+        The flag can be toggled by sending in the cb_debug value via
+        the config dictionary, or setting the CB_DEBUG environment variable.
+
+        :rtype: ``bool``
+        :return: Whether debug mode is on.
+        """
+        return self.get('cb_debug', os.environ.get('CB_DEBUG', False))
+
 
 class BaseCloudProvider(CloudProvider):
 

+ 16 - 2
cloudbridge/cloud/interfaces/resources.py

@@ -68,6 +68,20 @@ class Configuration(dict):
         """
         pass
 
+    @abstractproperty
+    def debug_mode(self):
+        """
+        A flag indicating whether CloudBridge is in debug mode. Setting
+        this to True will cause the underlying provider's debug
+        output to be turned on.
+
+        The flag can be toggled by sending in the cb_debug value via
+        the config dictionary, or setting the CB_DEBUG environment variable.
+
+        :rtype: ``bool``
+        :return: Whether debug mode is on.
+        """
+
 
 class ObjectLifeCycleMixin(object):
 
@@ -539,7 +553,7 @@ class LaunchConfig(object):
         lc.add_network_interface(...)
 
         inst = provider.compute.instances.create(name, image, instance_type,
-                                               launch_configuration=lc)
+                                               launch_config=lc)
     """
 
     @abstractmethod
@@ -604,7 +618,7 @@ class LaunchConfig(object):
             lc.add_volume_device(source=snap)
 
             # 3. Create+attach a volume based on an image and set it as root
-            img = provider.images.get('<my_image_id>')
+            img = provider.compute.images.get('<my_image_id>')
             lc.add_volume_device(source=img, size=100, is_root=True)
 
         :type  source: ``Volume``, ``Snapshot``, ``Image`` or None.

+ 2 - 1
cloudbridge/cloud/providers/aws/impl.py

@@ -90,7 +90,8 @@ class AWSCloudProvider(BaseCloudProvider):
             region=r,
             port=self.ec2_port,
             path=self.ec2_conn_path,
-            validate_certs=False)
+            validate_certs=False,
+            debug=2 if self.config.debug_mode else 0)
         return ec2_conn
 
     def _connect_s3(self):

+ 6 - 1
cloudbridge/cloud/providers/openstack/impl.py

@@ -12,6 +12,7 @@ from keystoneclient import session
 from keystoneclient.auth.identity import Password
 from neutronclient.v2_0 import client as neutron_client
 from novaclient import client as nova_client
+from novaclient import shell as nova_shell
 from swiftclient import client as swift_client
 
 from cloudbridge.cloud.base import BaseCloudProvider
@@ -116,10 +117,14 @@ class OpenStackCloudProvider(BaseCloudProvider):
             'nova_service_name',
             os.environ.get('NOVA_SERVICE_NAME', None))
 
+        if self.config.debug_mode:
+            nova_shell.OpenStackComputeShell().setup_debugging(True)
+
         return nova_client.Client(
             api_version, username=self.username, api_key=self.password,
             project_id=self.tenant_name, auth_url=self.auth_url,
-            region_name=self.region_name, service_name=service_name)
+            region_name=self.region_name, service_name=service_name,
+            http_log_debug=True if self.config.debug_mode else False)
 
     def _connect_keystone(self):
         """