You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2011/09/24 13:02:04 UTC
svn commit: r1175154 - /libcloud/trunk/libcloud/common/base.py
Author: tomaz
Date: Sat Sep 24 11:02:04 2011
New Revision: 1175154
URL: http://svn.apache.org/viewvc?rev=1175154&view=rev
Log:
dd a new BaseDriver class from which all the driver classes should inherit from.
Modified:
libcloud/trunk/libcloud/common/base.py
Modified: libcloud/trunk/libcloud/common/base.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/common/base.py?rev=1175154&r1=1175153&r2=1175154&view=diff
==============================================================================
--- libcloud/trunk/libcloud/common/base.py (original)
+++ libcloud/trunk/libcloud/common/base.py Sat Sep 24 11:02:04 2011
@@ -500,3 +500,57 @@ class ConnectionUserAndKey(ConnectionKey
super(ConnectionUserAndKey, self).__init__(key, secure=secure,
host=host, port=port, url=url)
self.user_id = user_id
+
+
+class BaseDriver(object):
+ """
+ Base driver class from which other classes can inherit from.
+ """
+
+ connectionCls = ConnectionKey
+
+ def __init__(self, key, secret=None, secure=True, host=None, port=None):
+ """
+ @keyword key: API key or username to used
+ @type key: str
+
+ @keyword secret: Secret password to be used
+ @type secret: str
+
+ @keyword secure: Weither to use HTTPS or HTTP. Note: Some providers
+ only support HTTPS, and it is on by default.
+ @type secure: bool
+
+ @keyword host: Override hostname used for connections.
+ @type host: str
+
+ @keyword port: Override port used for connections.
+ @type port: int
+ """
+ self.key = key
+ self.secret = secret
+ self.secure = secure
+ args = [self.key]
+
+ if self.secret is not None:
+ args.append(self.secret)
+
+ args.append(secure)
+
+ if host is not None:
+ args.append(host)
+
+ if port is not None:
+ args.append(port)
+
+ self.connection = self.connectionCls(*args, **self._ex_connection_class_kwargs())
+
+ self.connection.driver = self
+ self.connection.connect()
+
+ def _ex_connection_class_kwargs(self):
+ """
+ Return extra connection keyword arguments which are passed to the
+ Connection class constructor.
+ """
+ return {}