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 2013/10/07 13:15:58 UTC
[2/5] git commit: Fix pep8 issues.
Fix pep8 issues.
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/4bdf8462
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/4bdf8462
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/4bdf8462
Branch: refs/heads/trunk
Commit: 4bdf8462a846579270f279e1c90feb623e985ba9
Parents: da2fd8d
Author: Tomaz Muraus <to...@apache.org>
Authored: Mon Oct 7 13:07:06 2013 +0200
Committer: Tomaz Muraus <to...@apache.org>
Committed: Mon Oct 7 13:07:06 2013 +0200
----------------------------------------------------------------------
libcloud/compute/drivers/nephoscale.py | 51 ++++++++++++-----------------
1 file changed, 21 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/4bdf8462/libcloud/compute/drivers/nephoscale.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/nephoscale.py b/libcloud/compute/drivers/nephoscale.py
index 80dba81..5d532c2 100644
--- a/libcloud/compute/drivers/nephoscale.py
+++ b/libcloud/compute/drivers/nephoscale.py
@@ -21,17 +21,10 @@ Created by Markos Gogoulos (https://mist.io)
import base64
import sys
-import string
-import random
import time
import os
import binascii
-try:
- import simplejson as json
-except:
- import json
-
from libcloud.utils.py3 import httplib
from libcloud.utils.py3 import b
from libcloud.utils.py3 import urlencode
@@ -40,9 +33,9 @@ from libcloud.compute.providers import Provider
from libcloud.compute.base import is_private_subnet
from libcloud.common.base import JsonResponse, ConnectionUserAndKey
from libcloud.compute.types import (NodeState, InvalidCredsError,
- LibcloudError)
+ LibcloudError)
from libcloud.compute.base import (Node, NodeDriver, NodeImage, NodeSize,
- NodeLocation)
+ NodeLocation)
API_HOST = 'api.nephoscale.com'
@@ -115,7 +108,6 @@ class NephoscaleNodeDriver(NodeDriver):
"""
Nephoscale node driver class.
- >>> from libcloud.compute.types import Provider
>>> from libcloud.compute.providers import get_driver
>>> driver = get_driver('nephoscale')
>>> conn = driver('nepho_user','nepho_password')
@@ -161,7 +153,7 @@ class NephoscaleNodeDriver(NodeDriver):
'cores': value.get('cores'),
'uri': value.get('uri'),
'storage': value.get('storage'),
- }
+ }
image = NodeImage(id=value.get('id'),
name=value.get('friendly_name'),
driver=self,
@@ -273,7 +265,7 @@ get all keys call with no arguments')
return keys
def ex_create_keypair(self, name, public_key=None, password=None,
- key_group=None):
+ key_group=None):
"""Creates a key, ssh or password, for server or console
The group for the key (key_group) is 1 for Server and 4 for Console
Returns the id of the created key
@@ -289,7 +281,7 @@ get all keys call with no arguments')
}
params = urlencode(data)
result = self.connection.request('/key/sshrsa/', data=params,
- method='POST').object
+ method='POST').object
else:
if not key_group:
key_group = 4
@@ -302,7 +294,7 @@ get all keys call with no arguments')
}
params = urlencode(data)
result = self.connection.request('/key/password/', data=params,
- method='POST').object
+ method='POST').object
return result.get('data', {}).get('id', '')
def ex_delete_keypair(self, key_id, ssh=False):
@@ -313,7 +305,7 @@ get all keys call with no arguments')
method='DELETE').object
else:
result = self.connection.request('/key/password/%s/' % key_id,
- method='DELETE').object
+ method='DELETE').object
return result.get('response') in VALID_RESPONSE_CODES
def create_node(self, name, size, image, server_key=None,
@@ -324,7 +316,6 @@ get all keys call with no arguments')
times until the server is created and assigned a public IP address,
so that deploy_node can be run
- >>> from libcloud.compute.types import Provider
>>> from libcloud.compute.providers import get_driver
>>> driver = get_driver('nephoscale')
>>> conn = driver('nepho_user','nepho_password')
@@ -347,7 +338,7 @@ get all keys call with no arguments')
We can also create an ssh key, plus a console key and
deploy node with them
- >>> server_key = conn.ex_create_keypair(name, public_key=key)
+ >>> server_key = conn.ex_create_keypair(name, public_key='123')
71211
>>> console_key = conn.ex_create_keypair(name, key_group=4)
71213
@@ -358,13 +349,13 @@ get all keys call with no arguments')
We can also specify the location
>>> location = conn.list_locations()[0]
>>> node = conn.create_node(name=name,
- size=size,
- image=image,
- console_key=console_key,
- server_key=server_key,
- connect_attempts=10,
- nowait=True,
- zone=location.id)
+ ... size=size,
+ ... image=image,
+ ... console_key=console_key,
+ ... server_key=server_key,
+ ... connect_attempts=10,
+ ... nowait=True,
+ ... zone=location.id)
"""
try:
hostname = kwargs.get('hostname', name)
@@ -383,7 +374,7 @@ get all keys call with no arguments')
'server_key': server_key,
'console_key': console_key,
'zone': zone
- }
+ }
params = urlencode(data)
try:
@@ -406,7 +397,7 @@ get all keys call with no arguments')
while connect_attempts > 0:
nodes = self.list_nodes()
created_node = [c_node for c_node in nodes if
- c_node.name == name]
+ c_node.name == name]
if created_node:
return created_node[0]
else:
@@ -448,10 +439,10 @@ get all keys call with no arguments')
def _to_key(self, data):
return NodeKey(id=data.get('id'),
- name=data.get('name'),
- password=data.get('password'),
- key_group=data.get('key_group'),
- public_key=data.get('public_key'))
+ name=data.get('name'),
+ password=data.get('password'),
+ key_group=data.get('key_group'),
+ public_key=data.get('public_key'))
def random_password(self, size=8):
value = os.urandom(size)