deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core 3/4] Core: Updated all drivers to support common way to handle IP addresses using InstanceAddress
Date Wed, 02 Nov 2011 14:05:31 GMT
From: Michal Fojtik <mfojtik@redhat.com>


Signed-off-by: Michal fojtik <mfojtik@redhat.com>
---
 .../lib/deltacloud/drivers/condor/condor_driver.rb |    3 ++-
 server/lib/deltacloud/drivers/ec2/ec2_driver.rb    |    8 ++++----
 .../lib/deltacloud/drivers/gogrid/gogrid_driver.rb |    2 +-
 .../drivers/mock/data/instances/inst0.yml          |    8 ++++++--
 .../drivers/mock/data/instances/inst1.yml          |    8 ++++++--
 .../drivers/mock/data/instances/inst2.yml          |    8 ++++++--
 server/lib/deltacloud/drivers/mock/mock_driver.rb  |    4 ++--
 .../drivers/opennebula/opennebula_driver.rb        |    2 +-
 .../drivers/rackspace/rackspace_driver.rb          |    8 ++++----
 .../drivers/rimuhosting/rimuhosting_driver.rb      |    2 +-
 server/lib/deltacloud/drivers/sbc/sbc_driver.rb    |    2 +-
 .../drivers/terremark/terremark_driver.rb          |    4 ++--
 .../deltacloud/drivers/vsphere/vsphere_driver.rb   |    9 +++++++--
 server/lib/deltacloud/models.rb                    |    1 +
 14 files changed, 44 insertions(+), 25 deletions(-)

diff --git a/server/lib/deltacloud/drivers/condor/condor_driver.rb b/server/lib/deltacloud/drivers/condor/condor_driver.rb
index ad444d5..f48c9d3 100644
--- a/server/lib/deltacloud/drivers/condor/condor_driver.rb
+++ b/server/lib/deltacloud/drivers/condor/condor_driver.rb
@@ -105,7 +105,8 @@ module Deltacloud
                 :realm_id => 'default',
                 :instance_profile => InstanceProfile::new(instance.instance_profile.name),
                 :image_id => instance.image_id,
-                :public_addresses => [ ip_address ],
+                :public_addresses => [ InstanceAddress.new(ip_address) ],
+                :private_addresses => [],
                 :owner_id => instance.owner_id,
                 :description => instance.name,
                 :architecture => 'x86_64',
diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index dd52fa8..12f4fb3 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -134,7 +134,7 @@ module Deltacloud
           opts ||= {}
           if opts[:id]
             safely do
-              img_arr = ec2.describe_images(opts[:id]).collect do |image|
+              img_arr = ec2.describe_images([opts[:id]]).collect do |image|
                 convert_image(image)
               end
             end
@@ -142,7 +142,7 @@ module Deltacloud
           end
           owner_id = opts[:owner_id] || default_image_owner
           safely do
-            img_arr = ec2.describe_images_by_owner(owner_id, default_image_type).collect
do |image|
+            img_arr = ec2.describe_images_by_owner([owner_id], default_image_type).collect
do |image|
               convert_image(image)
             end
           end
@@ -794,8 +794,8 @@ module Deltacloud
             :launch_time => instance[:aws_launch_time],
             :instance_profile => InstanceProfile.new(instance[:aws_instance_type], inst_profile_opts),
             :realm_id => instance[:aws_availability_zone],
-            :private_addresses => instance[:private_dns_name],
-            :public_addresses => instance[:dns_name],
+            :public_addresses => [InstanceAddress.new(instance[:dns_name], :type =>
:hostname)],
+            :private_addresses => [InstanceAddress.new(instance[:private_dns_name], :type
=> :hostname)],
             :firewalls => instance[:aws_groups],
             :create_image => can_create_image
           )
diff --git a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
index 5e20c6a..285f58f 100644
--- a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
+++ b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
@@ -471,7 +471,7 @@ class GogridDriver < Deltacloud::BaseDriver
       :realm_id => instance['ip']['datacenter']['id'],
       :state => state,
       :actions => instance_actions_for(state),
-      :public_addresses => [ instance['ip']['ip'] ],
+      :public_addresses => [ InstanceAddress.new(instance['ip']['ip']) ],
       :private_addresses => [],
       :username => instance['username'],
       :password => instance['password'],
diff --git a/server/lib/deltacloud/drivers/mock/data/instances/inst0.yml b/server/lib/deltacloud/drivers/mock/data/instances/inst0.yml
index 447a99c..c6a9b11 100644
--- a/server/lib/deltacloud/drivers/mock/data/instances/inst0.yml
+++ b/server/lib/deltacloud/drivers/mock/data/instances/inst0.yml
@@ -8,9 +8,13 @@
 - :stop
 :owner_id: mockuser
 :public_addresses:
-- img1.inst0.public.com
+- !ruby/object:InstanceAddress
+  address: img1.inst0.public.com
+  address_type: :hostname
 :private_addresses:
-- img1.inst0.private.com
+- !ruby/object:InstanceAddress
+  address: img1.inst0.private.com
+  address_type: :hostname
 :create_image: true
 :image_id: img1
 :name: Mock Instance With Profile Change
diff --git a/server/lib/deltacloud/drivers/mock/data/instances/inst1.yml b/server/lib/deltacloud/drivers/mock/data/instances/inst1.yml
index f0bed5c..7befa88 100644
--- a/server/lib/deltacloud/drivers/mock/data/instances/inst1.yml
+++ b/server/lib/deltacloud/drivers/mock/data/instances/inst1.yml
@@ -4,9 +4,13 @@
 :realm_id: us
 :owner_id: mockuser
 :public_addresses:
-- img3.inst1.public.com
+- !ruby/object:InstanceAddress
+  address: img1.inst1.public.com
+  address_type: :hostname
 :private_addresses:
-- img3.inst1.private.com
+- !ruby/object:InstanceAddress
+  address: img1.inst1.private.com
+  address_type: :hostname
 :create_image: true
 :image_id: img3
 :name: MockUserInstance
diff --git a/server/lib/deltacloud/drivers/mock/data/instances/inst2.yml b/server/lib/deltacloud/drivers/mock/data/instances/inst2.yml
index a6fcd43..2acb937 100644
--- a/server/lib/deltacloud/drivers/mock/data/instances/inst2.yml
+++ b/server/lib/deltacloud/drivers/mock/data/instances/inst2.yml
@@ -4,9 +4,13 @@
 :realm_id: us
 :owner_id: anotheruser
 :public_addresses:
-- img1.inst2.public.com
+- !ruby/object:InstanceAddress
+  address: img1.inst2.public.com
+  address_type: :hostname
 :private_addresses:
-- img1.inst2.private.com
+- !ruby/object:InstanceAddress
+  address: img1.inst2.private.com
+  address_type: :hostname
 :create_image: true
 :image_id: img1
 :name: AnotherInstance
diff --git a/server/lib/deltacloud/drivers/mock/mock_driver.rb b/server/lib/deltacloud/drivers/mock/mock_driver.rb
index 29d18ef..c4eb03a 100644
--- a/server/lib/deltacloud/drivers/mock/mock_driver.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_driver.rb
@@ -195,8 +195,8 @@ module Deltacloud::Drivers::Mock
         :keyname => opts[:keyname],
         :image_id=>image_id,
         :owner_id=>credentials.user,
-        :public_addresses=>["#{image_id}.#{next_id}.public.com"],
-        :private_addresses=>["#{image_id}.#{next_id}.private.com"],
+        :public_addresses=>[ InstanceAddress.new("#{image_id}.#{next_id}.public.com",
:type => :hostname) ],
+        :private_addresses=>[ InstanceAddress.new("#{image_id}.#{next_id}.private.com",
:type => :hostname) ],
         :instance_profile => InstanceProfile.new(hwp.name, opts),
         :realm_id=>realm_id,
         :create_image=>true,
diff --git a/server/lib/deltacloud/drivers/opennebula/opennebula_driver.rb b/server/lib/deltacloud/drivers/opennebula/opennebula_driver.rb
index 84cf99d..e4f8f4d 100644
--- a/server/lib/deltacloud/drivers/opennebula/opennebula_driver.rb
+++ b/server/lib/deltacloud/drivers/opennebula/opennebula_driver.rb
@@ -190,7 +190,7 @@ class OpennebulaDriver < Deltacloud::BaseDriver
 
 	networks = []
 	(computehash['NETWORK'].each do |n|
-		networks << n.attributes['ip']
+		networks << InstanceAddress.new(n.attributes['ip'])
 	end) unless computehash['NETWORK'].nil?
 
 	Instance.new( {
diff --git a/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb b/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
index dd4099d..4a0ec54 100644
--- a/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
+++ b/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
@@ -394,8 +394,8 @@ class RackspaceDriver < Deltacloud::BaseDriver
       :architecture => 'x86_64',
       :image_id => server.imageId.to_s,
       :instance_profile => InstanceProfile::new(server.flavorId.to_s),
-      :public_addresses => server.addresses[:public],
-      :private_addresses => server.addresses[:private],
+      :public_addresses => server.addresses[:public].collect { |ip| InstanceAddress.new(ip)
},
+      :private_addresses => server.addresses[:private].collect { |ip| InstanceAddress.new(ip)
},
       :username => 'root',
       :password => password ? password : nil
     )
@@ -415,8 +415,8 @@ class RackspaceDriver < Deltacloud::BaseDriver
       :architecture => 'x86_64',
       :image_id => server[:imageId].to_s,
       :instance_profile => InstanceProfile::new(server[:flavorId].to_s),
-      :public_addresses => server[:addresses][:public],
-      :private_addresses => server[:addresses][:private]
+      :public_addresses => server[:addresses][:public].collect { |ip| InstanceAddress.new(ip)
},
+      :private_addresses => server[:addresses][:private].collect { |ip| InstanceAddress.new(ip)
},
     )
     inst.create_image = 'RUNNING'.eql?(inst.state)
     inst.actions = instance_actions_for(inst.state)
diff --git a/server/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb b/server/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb
index e39c877..9f786d0 100644
--- a/server/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb
+++ b/server/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb
@@ -131,7 +131,7 @@ class RimuHostingDriver < Deltacloud::BaseDriver
             :owner_id => "root",
             :instance_profile => InstanceProfile.new("none"),
             :actions => instance_actions_for("RUNNING"),
-            :public_addresses => inst["allocated_ips"]["primary_ip"],
+            :public_addresses => [ InstanceAddress.new(inst["allocated_ips"]["primary_ip"]
),
             :launch_time => inst["billing_info"]["order_date"]["iso_format"]
     })
   end
diff --git a/server/lib/deltacloud/drivers/sbc/sbc_driver.rb b/server/lib/deltacloud/drivers/sbc/sbc_driver.rb
index 2e5b39c..90f566d 100644
--- a/server/lib/deltacloud/drivers/sbc/sbc_driver.rb
+++ b/server/lib/deltacloud/drivers/sbc/sbc_driver.rb
@@ -206,7 +206,7 @@ class SBCDriver < Deltacloud::BaseDriver
       :realm_id => instance["location"],
       :state => state,
       :actions => instance_actions_for(state),
-      :public_addresses => [instance["primaryIP"]["ip"]],
+      :public_addresses => [ InstanceAddress.new(instance["primaryIP"]["ip"]) ],
       :private_addresses => [],
       :instance_profile => InstanceProfile.new(instance["instanceType"].gsub('/', '-')),
       :launch_time => instance["launchTime"],
diff --git a/server/lib/deltacloud/drivers/terremark/terremark_driver.rb b/server/lib/deltacloud/drivers/terremark/terremark_driver.rb
index ba5209d..c93bfb3 100644
--- a/server/lib/deltacloud/drivers/terremark/terremark_driver.rb
+++ b/server/lib/deltacloud/drivers/terremark/terremark_driver.rb
@@ -262,8 +262,8 @@ end
                     :realm_id => "US-Miami",
                     :state => current_state,
                     :actions => instance_actions_for(current_state),
-                    :public_addresses => vapp_public_ip,
-                    :private_addresses => vapp_private_ip,
+                    :public_addresses => [ InstanceAddress.new(vapp_public_ip) ],
+                    :private_addresses => [ InstanceAddress.new(vapp_private_ip) ],
                     :instance_profile => profile
                     } )
   end
diff --git a/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb b/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
index a31c1f1..22f4196 100644
--- a/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
+++ b/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
@@ -174,7 +174,12 @@ module Deltacloud::Drivers::VSphere
           # We're getting IP address from 'vmware guest tools'.
           # If guest tools are not installed, we return list of MAC addresses
           # assigned to this instance.
-          instance_address = vm.guest[:net].empty? ? vm.macs.values.first : vm.guest[:net].first[:ipAddress].first
+          public_addresses = []
+          if vm.guest[:net].empty?
+            public_addresses = vm.macs.values.collect { |mac_address| InstanceAddress.new(mac_address,
:type => :mac) }
+          else
+            public_addresses = InstanceAddress.new(vm.guest[:net].first[:ipAddress].first)
+          end
           Instance.new(
             :id => properties[:name],
             :name => properties[:name],
@@ -183,7 +188,7 @@ module Deltacloud::Drivers::VSphere
             :description => properties[:full_name],
             :realm_id => realm_id,
             :state => instance_state,
-            :public_addresses => instance_address,
+            :public_addresses => public_addresses,
             :private_addresses => [],
             :instance_profile => instance_profile,
             :actions => instance_actions_for( instance_state ),
diff --git a/server/lib/deltacloud/models.rb b/server/lib/deltacloud/models.rb
index 8317232..e8cd035 100644
--- a/server/lib/deltacloud/models.rb
+++ b/server/lib/deltacloud/models.rb
@@ -20,6 +20,7 @@ require 'deltacloud/models/image'
 require 'deltacloud/models/instance'
 require 'deltacloud/models/key'
 require 'deltacloud/models/address'
+require 'deltacloud/models/instance_address'
 require 'deltacloud/models/instance_profile'
 require 'deltacloud/models/storage_snapshot'
 require 'deltacloud/models/storage_volume'
-- 
1.7.4.4


Mime
View raw message