deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@redhat.com
Subject [PATCH 3/3] Networks initial impl. for EC2 driver
Date Mon, 05 Nov 2012 14:42:19 GMT
From: marios <marios@redhat.com>


Signed-off-by: marios <marios@redhat.com>
---
 server/lib/deltacloud/drivers/base_driver.rb    |  3 +++
 server/lib/deltacloud/drivers/ec2/ec2_driver.rb | 35 +++++++++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/server/lib/deltacloud/drivers/base_driver.rb b/server/lib/deltacloud/drivers/base_driver.rb
index cfb689d..895ad4d 100644
--- a/server/lib/deltacloud/drivers/base_driver.rb
+++ b/server/lib/deltacloud/drivers/base_driver.rb
@@ -255,6 +255,9 @@ module Deltacloud
       addresses(credentials, opts).first if has_capability?(:addresses)
     end
 
+    def network(credentials, opts={})
+      networks(credentials, opts).first if has_capability?(:networks)
+    end
 
     MEMBER_SHOW_METHODS = [ :realm, :image, :instance, :storage_volume, :bucket, :blob,
                             :key, :firewall ] unless defined?(MEMBER_SHOW_METHODS)
diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index c7bed05..a65e834 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -800,6 +800,33 @@ module Deltacloud
           end
         end
 
+        #Deltacloud Networks == Amazon VPC
+        def networks(credentials, opts={})
+          ec2 = new_client(credentials)
+          networks=[]
+          safely do
+            ec2.describe_vpcs.each do |vpc|
+              networks << convert_vpc(vpc)
+            end
+          end
+          networks = filter_on(networks, :id, opts)
+        end
+
+        def create_network(credentials, opts={})
+          ec2 = new_client(credentials)
+          safely do
+            network = ec2.create_vpc(opts[:address_block]).first
+            convert_vpc(network)
+          end
+        end
+
+        def destroy_network(credentials, opts={})
+          ec2 = new_client(credentials)
+          safely do
+            ec2.delete_vpc(opts[:id])
+          end
+        end
+
         def providers(credentials, opts={})
           ec2 = new_client(credentials)
           @providers ||= ec2.describe_regions.map{|r| Provider.new( {:id=>r, :name=>r,
@@ -1119,6 +1146,14 @@ module Deltacloud
           end
         end
 
+        def convert_vpc(vpc)
+          Network.new({ :id => vpc[:vpc_id],
+                        :name => vpc[:vpc_id],
+                        :state=> vpc[:state],
+                        :address_block=> vpc[:cidr_block] })
+        end
+
+
         exceptions do
           on /(AuthFailure|InvalidAccessKeyId)/ do
             status 401
-- 
1.7.11.7


Mime
View raw message