Permalink
Browse files

Replaced boto with libcloud

  • Loading branch information...
freyes committed Mar 27, 2012
1 parent 8bfeb72 commit 2f22c1c32ce961bb5b9a45a302a8bc3e38bded93
Showing with 31 additions and 19 deletions.
  1. +23 −10 cirrus/conn.py
  2. +3 −4 cirrus/ec2.py
  3. +4 −4 cirrus/ui/ui.glade
  4. +1 −1 setup.py
View
@@ -1,6 +1,8 @@
+import urlparse
from cirrus.config import settings
from cirrus.exception import AccountError
-from boto.ec2.connection import EC2Connection as BotoEC2Connection
+from libcloud.compute.types import Provider
+from libcloud.compute.providers import get_driver
class Account(object):
@@ -9,26 +11,37 @@ def __init__(self, name):
try:
self.access_key = settings["accounts"][name]["access_key"]
self.secret_key = settings["accounts"][name]["secret_key"]
- self.account_id = settings["accounts"][name]["account_id"]
+ self.type = settings["accounts"][name].get("type", "").upper()
+ self.endpoint = settings["accounts"][name].get("endpoint")
+
+ if self.endpoint:
+ parsed = urlparse.urlparse(self.endpoint)
+ self.secure = (parsed.scheme == "https")
+ self.host = parsed.hostname
+ self.port = parsed.port
except KeyError, ex:
raise
raise AccountError("missing %s from account %s" % (ex, name))
-class EC2Connection(BotoEC2Connection):
+class Adapter(object):
def __init__(self, account, region=None):
if isinstance(account, basestring):
self.account = Account(account)
else:
self.account = account
- super(EC2Connection, self).__init__(self.account.access_key,
- self.account.secret_key)
+ self.driver_klass = get_driver(getattr(Provider, self.account.type))
+ kwargs = {}
+ if self.account.type == "OPENSTACK":
+ kwargs["secure"] = self.account.secure
+ kwargs["host"] = self.account.host
+ kwargs["ex_force_auth_url"] = self.account.endpoint + "/tokens"
+ kwargs["port"] = self.account.port
- if region != None:
- region = self.get_all_regions(filters={"region_name": region})
+ print kwargs
- super(EC2Connection, self).__init__(self.account.access_key,
- self.account.secret_key,
- region=region)
+ self.conn = self.driver_klass(self.account.access_key,
+ self.account.secret_key,
+ **kwargs)
View
@@ -1,5 +1,5 @@
import threading
-from cirrus.conn import EC2Connection
+from cirrus.conn import Adapter
from gi.repository import GObject
@@ -20,9 +20,8 @@ def __init__(self, account, region=None, filters=None):
self.instance_ids = None
def run(self):
- conn = EC2Connection(self.account, self.region)
- reservations = conn.get_all_instances(instance_ids=self.instance_ids,
- filters=self.filters)
+ adapter = Adapter(self.account)
+ reservations = adapter.conn.list_nodes()
instances = []
for r in reservations:
View
@@ -150,10 +150,6 @@
</object>
<object class="GtkWindow" id="wnd_console_output">
<property name="can_focus">False</property>
- <property name="margin_left">5</property>
- <property name="margin_right">5</property>
- <property name="margin_top">5</property>
- <property name="margin_bottom">5</property>
<property name="default_width">440</property>
<property name="default_height">250</property>
<child>
@@ -169,6 +165,10 @@
<object class="GtkLabel" id="lbl_console_output">
<property name="visible">True</property>
<property name="can_focus">False</property>
+ <property name="margin_left">5</property>
+ <property name="margin_right">5</property>
+ <property name="margin_top">5</property>
+ <property name="margin_bottom">5</property>
<property name="label" translatable="yes">label</property>
</object>
</child>
View
@@ -2,7 +2,7 @@
from setuptools import setup, find_packages
from cirrus import __version__
-dependencies = ["boto", "PyYAML"]
+dependencies = ["apache-libcloud", "PyYAML"]
def read(fname):

0 comments on commit 2f22c1c

Please sign in to comment.