Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Replaced boto with libcloud

  • Loading branch information...
commit 2f22c1c32ce961bb5b9a45a302a8bc3e38bded93 1 parent 8bfeb72
Felipe Reyes authored March 26, 2012
33  cirrus/conn.py
... ...
@@ -1,6 +1,8 @@
  1
+import urlparse
1 2
 from cirrus.config import settings
2 3
 from cirrus.exception import AccountError
3  
-from boto.ec2.connection import EC2Connection as BotoEC2Connection
  4
+from libcloud.compute.types import Provider
  5
+from libcloud.compute.providers import get_driver
4 6
 
5 7
 
6 8
 class Account(object):
@@ -9,13 +11,20 @@ def __init__(self, name):
9 11
         try:
10 12
             self.access_key = settings["accounts"][name]["access_key"]
11 13
             self.secret_key = settings["accounts"][name]["secret_key"]
12  
-            self.account_id = settings["accounts"][name]["account_id"]
  14
+            self.type = settings["accounts"][name].get("type", "").upper()
  15
+            self.endpoint = settings["accounts"][name].get("endpoint")
  16
+
  17
+            if self.endpoint:
  18
+                parsed = urlparse.urlparse(self.endpoint)
  19
+                self.secure = (parsed.scheme == "https")
  20
+                self.host = parsed.hostname
  21
+                self.port = parsed.port
13 22
         except KeyError, ex:
14 23
             raise
15 24
             raise AccountError("missing %s from account %s" % (ex, name))
16 25
 
17 26
 
18  
-class EC2Connection(BotoEC2Connection):
  27
+class Adapter(object):
19 28
 
20 29
     def __init__(self, account, region=None):
21 30
         if isinstance(account, basestring):
@@ -23,12 +32,16 @@ def __init__(self, account, region=None):
23 32
         else:
24 33
             self.account = account
25 34
 
26  
-        super(EC2Connection, self).__init__(self.account.access_key,
27  
-                                            self.account.secret_key)
  35
+        self.driver_klass = get_driver(getattr(Provider, self.account.type))
  36
+        kwargs = {}
  37
+        if self.account.type == "OPENSTACK":
  38
+            kwargs["secure"] = self.account.secure
  39
+            kwargs["host"] = self.account.host
  40
+            kwargs["ex_force_auth_url"] = self.account.endpoint + "/tokens"
  41
+            kwargs["port"] = self.account.port
28 42
 
29  
-        if region != None:
30  
-            region = self.get_all_regions(filters={"region_name": region})
  43
+        print kwargs
31 44
 
32  
-            super(EC2Connection, self).__init__(self.account.access_key,
33  
-                                                self.account.secret_key,
34  
-                                                region=region)
  45
+        self.conn = self.driver_klass(self.account.access_key,
  46
+                                      self.account.secret_key,
  47
+                                      **kwargs)
7  cirrus/ec2.py
... ...
@@ -1,5 +1,5 @@
1 1
 import threading
2  
-from cirrus.conn import EC2Connection
  2
+from cirrus.conn import Adapter
3 3
 from gi.repository import GObject
4 4
 
5 5
 
@@ -20,9 +20,8 @@ def __init__(self, account, region=None, filters=None):
20 20
         self.instance_ids = None
21 21
 
22 22
     def run(self):
23  
-        conn = EC2Connection(self.account, self.region)
24  
-        reservations = conn.get_all_instances(instance_ids=self.instance_ids,
25  
-                                              filters=self.filters)
  23
+        adapter = Adapter(self.account)
  24
+        reservations = adapter.conn.list_nodes()
26 25
 
27 26
         instances = []
28 27
         for r in reservations:
8  cirrus/ui/ui.glade
@@ -150,10 +150,6 @@
150 150
   </object>
151 151
   <object class="GtkWindow" id="wnd_console_output">
152 152
     <property name="can_focus">False</property>
153  
-    <property name="margin_left">5</property>
154  
-    <property name="margin_right">5</property>
155  
-    <property name="margin_top">5</property>
156  
-    <property name="margin_bottom">5</property>
157 153
     <property name="default_width">440</property>
158 154
     <property name="default_height">250</property>
159 155
     <child>
@@ -169,6 +165,10 @@
169 165
               <object class="GtkLabel" id="lbl_console_output">
170 166
                 <property name="visible">True</property>
171 167
                 <property name="can_focus">False</property>
  168
+                <property name="margin_left">5</property>
  169
+                <property name="margin_right">5</property>
  170
+                <property name="margin_top">5</property>
  171
+                <property name="margin_bottom">5</property>
172 172
                 <property name="label" translatable="yes">label</property>
173 173
               </object>
174 174
             </child>
2  setup.py
@@ -2,7 +2,7 @@
2 2
 from setuptools import setup, find_packages
3 3
 from cirrus import __version__
4 4
 
5  
-dependencies = ["boto", "PyYAML"]
  5
+dependencies = ["apache-libcloud", "PyYAML"]
6 6
 
7 7
 
8 8
 def read(fname):

0 notes on commit 2f22c1c

Please sign in to comment.
Something went wrong with that request. Please try again.