Skip to content

Commit

Permalink
Some style fixes and release 1.1 ready to be uploaded
Browse files Browse the repository at this point in the history
  • Loading branch information
koalalorenzo committed Dec 23, 2014
1 parent f22f1d7 commit 732899e
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 69 deletions.
5 changes: 3 additions & 2 deletions digitalocean/Account.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from .baseapi import BaseAPI


class Account(BaseAPI):
def __init__(self, *args, **kwargs):
self.droplet_limit = None
Expand All @@ -25,7 +26,7 @@ def load(self):
account = data['account']

for attr in account.keys():
setattr(self,attr,account[attr])
setattr(self, attr, account[attr])

def __str__(self):
return "%s" % self.email
return "%s" % self.email
7 changes: 4 additions & 3 deletions digitalocean/Action.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from .baseapi import BaseAPI


class Action(BaseAPI):
def __init__(self, *args, **kwargs):
self.id = None
Expand Down Expand Up @@ -32,7 +33,7 @@ def load_directly(self):
action = action[u'action']
# Loading attributes
for attr in action.keys():
setattr(self,attr,action[attr])
setattr(self, attr, action[attr])

def load(self):
action = self.get_data(
Expand All @@ -45,7 +46,7 @@ def load(self):
action = action[u'action']
# Loading attributes
for attr in action.keys():
setattr(self,attr,action[attr])
setattr(self, attr, action[attr])

def __str__(self):
return "%s %s [%s]" % (self.id, self.type, self.status)
return "%s %s [%s]" % (self.id, self.type, self.status)
13 changes: 7 additions & 6 deletions digitalocean/Domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .Record import Record
from .baseapi import BaseAPI


class Domain(BaseAPI):
def __init__(self, *args, **kwargs):
self.name = None
Expand All @@ -27,7 +28,7 @@ def load(self):
domain = domains['domain']

for attr in domain.keys():
setattr(self,attr,domain[attr])
setattr(self, attr, domain[attr])

def destroy(self):
"""
Expand Down Expand Up @@ -62,7 +63,7 @@ def create_new_domain_record(self, *args, **kwargs):
"data": kwargs.get("data", None)
}

# Optional Args
#  Optional Args
if kwargs.get("priority", None):
data['priority'] = kwargs.get("priority", None)

Expand All @@ -84,9 +85,9 @@ def create(self):
"""
# URL https://api.digitalocean.com/v2/domains
data = {
"name": self.name,
"ip_address": self.ip_address,
}
"name": self.name,
"ip_address": self.ip_address,
}

domain = self.get_data(
"domains",
Expand Down Expand Up @@ -115,4 +116,4 @@ def get_records(self):
return records

def __str__(self):
return "%s" % self.name
return "%s" % self.name
35 changes: 20 additions & 15 deletions digitalocean/Droplet.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
# -*- coding: utf-8 -*-
import requests
from .Action import Action
from .Image import Image
from .Kernel import Kernel
from .baseapi import BaseAPI, Error
from .SSHKey import SSHKey


class DropletError(Error):
"""Base exception class for this module"""
pass


class BadKernelObject(DropletError):
pass


class BadSSHKeyFormat(DropletError):
pass


class Droplet(BaseAPI):
""""Droplet managment
Expand Down Expand Up @@ -124,7 +127,7 @@ def load(self):
droplet = droplets['droplet']

for attr in droplet.keys():
setattr(self,attr,droplet[attr])
setattr(self, attr, droplet[attr])

for net in self.networks['v4']:
if net['type'] == 'private':
Expand Down Expand Up @@ -228,7 +231,7 @@ def restore(self, image_id):
return self.get_data(
"droplets/%s/actions/" % self.id,
type="POST",
params={"type":"restore", "image": image_id}
params={"type": "restore", "image": image_id}
)

def rebuild(self, image_id=None):
Expand Down Expand Up @@ -315,7 +318,7 @@ def change_kernel(self, kernel):
return self.get_data(
"droplets/%s/actions/" % self.id,
type="POST",
params={'type' : 'change_kernel', 'kernel': kernel.id}
params={'type': 'change_kernel', 'kernel': kernel.id}
)

def __get_ssh_keys_id(self):
Expand All @@ -327,7 +330,7 @@ def __get_ssh_keys_id(self):
ssh_keys_id = list()
for ssh_key in self.ssh_keys:
if type(ssh_key) in [int, long]:
ssh_keys_id.append( int(ssh_key) )
ssh_keys_id.append(int(ssh_key))

elif type(ssh_key) == SSHKey:
ssh_keys_id.append(ssh_key.id)
Expand All @@ -337,7 +340,7 @@ def __get_ssh_keys_id(self):
key.token = self.token
results = key.load_by_pub_key(ssh_key)

if results == None:
if results is None:
key.public_key = ssh_key
key.name = "SSH Key %s" % self.name
key.create()
Expand All @@ -346,7 +349,9 @@ def __get_ssh_keys_id(self):

ssh_keys_id.append(key.id)
else:
raise BadSSHKeyFormat("Droplet.ssh_keys should be a list of IDs or public keys")
raise BadSSHKeyFormat(
"Droplet.ssh_keys should be a list of IDs or public keys"
)

return ssh_keys_id

Expand All @@ -358,19 +363,19 @@ def create(self, *args, **kwargs):
assigned to the object.
"""
for attr in kwargs.keys():
setattr(self,attr,kwargs[attr])
setattr(self, attr, kwargs[attr])

# Provide backwards compatibility
if not self.size_slug and self.size:
self.size_slug = self.size

data = {
"name": self.name,
"size": self.size_slug,
"image": self.image,
"region": self.region,
"ssh_keys[]": self.__get_ssh_keys_id(),
}
"name": self.name,
"size": self.size_slug,
"image": self.image,
"region": self.region,
"ssh_keys[]": self.__get_ssh_keys_id(),
}

if self.backups:
data['backups'] = True
Expand Down Expand Up @@ -463,7 +468,7 @@ def get_kernel_available(self):
if not url:
break
data = self.get_data(url)
except KeyError: # No links.
except KeyError: # No links.
break

return kernels
Expand Down
8 changes: 4 additions & 4 deletions digitalocean/Image.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
import requests
from .baseapi import BaseAPI


class Image(BaseAPI):
def __init__(self, *args, **kwargs):
self.id = None
Expand All @@ -28,9 +28,9 @@ def load(self):
data = self.get_data("images/%s" % self.id)
image_dict = data['image']

#Setting the attribute values
# Setting the attribute values
for attr in image_dict.keys():
setattr(self,attr,image_dict[attr])
setattr(self, attr, image_dict[attr])

return self

Expand Down Expand Up @@ -64,4 +64,4 @@ def rename(self, new_name):
)

def __str__(self):
return "%s %s %s" % (self.id, self.name, self.distribution)
return "%s %s %s" % (self.id, self.name, self.distribution)
3 changes: 2 additions & 1 deletion digitalocean/Kernel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from .baseapi import BaseAPI


class Kernel(BaseAPI):
def __init__(self, *args, **kwargs):
self.name = ""
Expand All @@ -9,4 +10,4 @@ def __init__(self, *args, **kwargs):
super(Kernel, self).__init__(*args, **kwargs)

def __str__(self):
return "%s %s" % (self.name, self.version)
return "%s %s" % (self.name, self.version)
2 changes: 1 addition & 1 deletion digitalocean/Manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __deal_with_pagination(self, url, data, params):
values.append(value)
data = {}
data[key] = values
except KeyError: # No pages.
except KeyError: # No pages.
pass

return data
Expand Down
5 changes: 3 additions & 2 deletions digitalocean/Metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from .baseapi import BaseAPI


class Metadata(BaseAPI):
"""
Metadata API: Provide useful information about the current Droplet.
Expand Down Expand Up @@ -37,9 +38,9 @@ def load(self):
metadata = self.get_data("v1.json")

for attr in metadata.keys():
setattr(self,attr,metadata[attr])
setattr(self, attr, metadata[attr])

return self

def __str__(self):
return "%s" % self.droplet_id
return "%s" % self.droplet_id
20 changes: 10 additions & 10 deletions digitalocean/Record.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
import requests
from .baseapi import BaseAPI


class Record(BaseAPI):
def __init__(self, domain_name=None, *args, **kwargs):
self.domain = domain_name if domain_name else ""
Expand Down Expand Up @@ -29,13 +29,13 @@ def create(self):
Create a record for a domain
"""
input_params = {
"type": self.type,
"data": self.data,
"name": self.name,
"priority": self.priority,
"port": self.port,
"weight": self.weight
}
"type": self.type,
"data": self.data,
"name": self.name,
"priority": self.priority,
"port": self.port,
"weight": self.weight
}

data = self.get_data(
"domains/%s/records" % (self.domain),
Expand Down Expand Up @@ -79,9 +79,9 @@ def load(self):
if record:
record = record[u'domain_record']

#Setting the attribute values
# Setting the attribute values
for attr in record.keys():
setattr(self,attr,record[attr])
setattr(self, attr, record[attr])

def __str__(self):
return "%s %s" % (self.id, self.domain)
3 changes: 2 additions & 1 deletion digitalocean/Region.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from .baseapi import BaseAPI


class Region(BaseAPI):
def __init__(self, *args, **kwargs):
self.name = None
Expand All @@ -11,4 +12,4 @@ def __init__(self, *args, **kwargs):
super(Region, self).__init__(*args, **kwargs)

def __str__(self):
return "%s" % self.name
return "%s" % self.name
18 changes: 9 additions & 9 deletions digitalocean/SSHKey.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from .baseapi import BaseAPI
import requests


class SSHKey(BaseAPI):
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -28,9 +28,9 @@ def load(self):

ssh_key = data['ssh_key']

#Setting the attribute values
# Setting the attribute values
for attr in ssh_key.keys():
setattr(self,attr,ssh_key[attr])
setattr(self, attr, ssh_key[attr])
self.id = ssh_key['id']

def load_by_pub_key(self, public_key):
Expand All @@ -53,9 +53,9 @@ def create(self):
Create the SSH Key
"""
input_params = {
"name": self.name,
"public_key": self.public_key,
}
"name": self.name,
"public_key": self.public_key,
}

data = self.get_data(
"account/keys/",
Expand All @@ -71,9 +71,9 @@ def edit(self):
Edit the SSH Key
"""
input_params = {
"name": self.name,
"public_key": self.public_key,
}
"name": self.name,
"public_key": self.public_key,
}

data = self.get_data(
"account/keys/%s" % self.id,
Expand Down
Loading

0 comments on commit 732899e

Please sign in to comment.