You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by pq...@apache.org on 2010/01/05 00:46:26 UTC
svn commit: r895828 - in /incubator/libcloud/trunk: libcloud/base.py
libcloud/drivers/linode.py libcloud/interface.py test/test_linode.py
Author: pquerna
Date: Mon Jan 4 23:46:25 2010
New Revision: 895828
URL: http://svn.apache.org/viewvc?rev=895828&view=rev
Log:
Convert create_node to be kwargs based, updating linode driver to match
Modified:
incubator/libcloud/trunk/libcloud/base.py
incubator/libcloud/trunk/libcloud/drivers/linode.py
incubator/libcloud/trunk/libcloud/interface.py
incubator/libcloud/trunk/test/test_linode.py
Modified: incubator/libcloud/trunk/libcloud/base.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/base.py?rev=895828&r1=895827&r2=895828&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/base.py (original)
+++ incubator/libcloud/trunk/libcloud/base.py Mon Jan 4 23:46:25 2010
@@ -117,22 +117,6 @@
return (('<NodeLocation: id=%s, name=%s, country=%s, driver=%s>')
% (self.id, self.name, self.country, self.driver.name))
-class NodeOptions(object):
- """
- A base NodeLocation class to derive from.
- """
- interface.implements(INodeOptions)
- interface.classProvides(INodeOptionsFactory)
- def __init__(self, location=None, image=None, size=None, auth=None, driver=None):
- self.location = location
- self.image = image
- self.size = size
- self.auth = auth
- self.driver = driver
- def __repr__(self):
- return (('<NodeOptions: location=%s, image=%s, size=%s, driver=%s>')
- % (self.location, self.image, self.size, self.driver.name))
-
class NodeAuthSSHKey(object):
def __init__(self, pubkey):
self.pubkey = pubkey
@@ -368,9 +352,27 @@
name = None
type = None
features = {"create_node": []}
+ """List of available features for a driver.
+ - L{create_node}
+ - ssh_key: Supports L{NodeAuthSSHKey} as an authentication method
+ for nodes.
+ - password: Supports L{NodeAuthPassword} as an authentication method
+ for nodes.
+ """
NODE_STATE_MAP = {}
def __init__(self, key, secret=None, secure=True):
+ """
+ @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
+ """
self.key = key
self.secret = secret
self.secure = secure
@@ -382,7 +384,27 @@
self.connection.driver = self
self.connection.connect()
- def create_node(self, name, options, **kwargs):
+ def create_node(self, **kwargs):
+ """Create a new node instance.
+
+ @keyword name: String with a name for this new node (required)
+ @type name: str
+
+ @keyword size: The size of resources allocated to this node. (required)
+ @type size: L{NodeSize}
+
+ @keyword image: OS Image to boot on node. (required)
+ @type image: L{NodeImage}
+
+ @keyword location: Which data center to create a node in. If empty,
+ undefined behavoir will be selected. (optional)
+ @type location: L{NodeLocation}
+
+ @keyword auth: Initial authentication information for the node (optional)
+ @type auth: L{NodeAuthSSHKey} or L{NodeAuthPassword}
+
+ @return: The newly created L{Node}.
+ """
raise NotImplementedError, 'create_node not implemented for this driver'
def destroy_node(self, node):
Modified: incubator/libcloud/trunk/libcloud/drivers/linode.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/drivers/linode.py?rev=895828&r1=895827&r2=895828&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/drivers/linode.py (original)
+++ incubator/libcloud/trunk/libcloud/drivers/linode.py Mon Jan 4 23:46:25 2010
@@ -161,7 +161,7 @@
self.connection.request(LINODE_ROOT, params=params)
return True
- def create_node(self, name, options, **kwargs):
+ def create_node(self, **kwargs):
# Create
#
# Creates a Linode instance.
@@ -201,9 +201,11 @@
#
# Please note that for safety, only 5 Linodes can be created per hour.
- chosen = options.location.id
- image = options.image
- size = options.size
+ name = kwargs["name"]
+ chosen = kwargs["location"].id
+ image = kwargs["image"]
+ size = kwargs["size"]
+ auth = kwargs["auth"]
# Step 0: Parameter validation before we purchase
# We're especially careful here so we don't fail after purchase, rather
@@ -222,10 +224,10 @@
ssh = None
root = None
# SSH key and/or root password
- if isinstance(options.auth, NodeAuthSSHKey):
- ssh = options.auth.pubkey
- elif isinstance(options.auth, NodeAuthPassword):
- root = options.auth.password
+ if isinstance(auth, NodeAuthSSHKey):
+ ssh = auth.pubkey
+ elif isinstance(auth, NodeAuthPassword):
+ root = auth.password
if not ssh and not root:
raise LinodeException(0xFB, "Need SSH key or root password")
Modified: incubator/libcloud/trunk/libcloud/interface.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/interface.py?rev=895828&r1=895827&r2=895828&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/interface.py (original)
+++ incubator/libcloud/trunk/libcloud/interface.py Mon Jan 4 23:46:25 2010
@@ -150,7 +150,7 @@
NODE_STATE_MAP = Attribute("""A mapping of states found in the response to
their standard type. This is a constant.""")
- def create_node(name, options, **kwargs):
+ def create_node(**kwargs):
"""
Creates a new node based on provided params. Name is ignored on some providers.
Modified: incubator/libcloud/trunk/test/test_linode.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/test/test_linode.py?rev=895828&r1=895827&r2=895828&view=diff
==============================================================================
--- incubator/libcloud/trunk/test/test_linode.py (original)
+++ incubator/libcloud/trunk/test/test_linode.py Mon Jan 4 23:46:25 2010
@@ -18,7 +18,7 @@
#
from libcloud.drivers.linode import LinodeNodeDriver
-from libcloud.base import Node, NodeOptions, NodeAuthPassword
+from libcloud.base import Node, NodeAuthPassword
from test import MockHttp, TestCaseMixin
import unittest
@@ -53,11 +53,11 @@
def test_create_node(self):
# Will exception on failure
- no = NodeOptions(location=self.driver.list_locations()[0],
+ node = self.driver.create_node(name="Test",
+ location=self.driver.list_locations()[0],
size=self.driver.list_sizes()[0],
image=self.driver.list_images()[6],
- auth=NodeAuthPassword("test123"), driver=self.driver)
- node = self.driver.create_node("Test", no)
+ auth=NodeAuthPassword("test123"))
def test_list_sizes(self):
sizes = self.driver.list_sizes()
@@ -71,11 +71,11 @@
def test_create_node_response(self):
# should return a node object
- no = NodeOptions(location=self.driver.list_locations()[0],
+ node = self.driver.create_node(name="node-name",
+ location=self.driver.list_locations()[0],
size=self.driver.list_sizes()[0],
image=self.driver.list_images()[0],
- auth=NodeAuthPassword("foobar"), driver=self.driver)
- node = self.driver.create_node("node-name", no)
+ auth=NodeAuthPassword("foobar"))
self.assertTrue(isinstance(node, Node))