deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [5/5] git commit: Adds Address collection support for Mock driver
Date Wed, 26 Sep 2012 09:04:52 GMT
Adds Address collection support for Mock driver

Signed-off-by: marios <marios@redhat.com>


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/e58f73ed
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/e58f73ed
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/e58f73ed

Branch: refs/heads/master
Commit: e58f73ed2f62f4e77150ecb2f7b23d6388c813ed
Parents: 54a51e8
Author: marios <marios@redhat.com>
Authored: Tue Sep 18 16:33:19 2012 +0300
Committer: marios <marios@redhat.com>
Committed: Tue Sep 25 11:13:50 2012 +0300

----------------------------------------------------------------------
 .../drivers/mock/data/addresses/192.168.0.1.yml    |    3 +
 .../drivers/mock/data/addresses/192.168.0.2.yml    |    3 +
 .../drivers/mock/data/addresses/192.168.0.3.yml    |    3 +
 .../drivers/mock/data/addresses/192.168.0.4.yml    |    3 +
 server/lib/deltacloud/drivers/mock/mock_driver.rb  |   62 +++++++++++++++
 5 files changed, 74 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/e58f73ed/server/lib/deltacloud/drivers/mock/data/addresses/192.168.0.1.yml
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/data/addresses/192.168.0.1.yml b/server/lib/deltacloud/drivers/mock/data/addresses/192.168.0.1.yml
new file mode 100644
index 0000000..e34604a
--- /dev/null
+++ b/server/lib/deltacloud/drivers/mock/data/addresses/192.168.0.1.yml
@@ -0,0 +1,3 @@
+---
+:id: 192.168.0.1
+:instance_id: 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/e58f73ed/server/lib/deltacloud/drivers/mock/data/addresses/192.168.0.2.yml
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/data/addresses/192.168.0.2.yml b/server/lib/deltacloud/drivers/mock/data/addresses/192.168.0.2.yml
new file mode 100644
index 0000000..929c4cc
--- /dev/null
+++ b/server/lib/deltacloud/drivers/mock/data/addresses/192.168.0.2.yml
@@ -0,0 +1,3 @@
+---
+:id: 192.168.0.2
+:instance_id: 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/e58f73ed/server/lib/deltacloud/drivers/mock/data/addresses/192.168.0.3.yml
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/data/addresses/192.168.0.3.yml b/server/lib/deltacloud/drivers/mock/data/addresses/192.168.0.3.yml
new file mode 100644
index 0000000..9862f21
--- /dev/null
+++ b/server/lib/deltacloud/drivers/mock/data/addresses/192.168.0.3.yml
@@ -0,0 +1,3 @@
+---
+:id: "192.168.0.3"
+:instance_id:

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/e58f73ed/server/lib/deltacloud/drivers/mock/data/addresses/192.168.0.4.yml
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/data/addresses/192.168.0.4.yml b/server/lib/deltacloud/drivers/mock/data/addresses/192.168.0.4.yml
new file mode 100644
index 0000000..64124f7
--- /dev/null
+++ b/server/lib/deltacloud/drivers/mock/data/addresses/192.168.0.4.yml
@@ -0,0 +1,3 @@
+---
+:id: "192.168.0.4"
+:instance_id:

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/e58f73ed/server/lib/deltacloud/drivers/mock/mock_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/mock_driver.rb b/server/lib/deltacloud/drivers/mock/mock_driver.rb
index b02e653..e765a9f 100644
--- a/server/lib/deltacloud/drivers/mock/mock_driver.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_driver.rb
@@ -17,6 +17,7 @@
 require 'yaml'
 require 'base64'
 require 'etc'
+require 'ipaddr'
 
 require_relative 'mock_client'
 require_relative 'mock_driver_cimi_methods'
@@ -333,6 +334,48 @@ module Deltacloud::Drivers::Mock
       @client.destroy(:keys, key.id)
     end
 
+    def addresses(credentials, opts={})
+      check_credentials(credentials)
+      addresses = @client.build_all(Address)
+      addresses = filter_on( addresses, :id, opts )
+    end
+
+    def create_address(credentials, opts={})
+      check_credentials(credentials)
+      address = {:id => allocate_mock_address.to_s, :instance_id=>nil}
+      @client.store(:addresses, address)
+      Address.new(address)
+    end
+
+    def destroy_address(credentials, opts={})
+      check_credentials(credentials)
+      address = @client.load(:addresses, opts[:id])
+      raise "AddressInUse" unless address[:instance_id].nil?
+      @client.destroy(:addresses, opts[:id])
+    end
+
+    def associate_address(credentials, opts={})
+      check_credentials(credentials)
+      address = @client.load(:addresses, opts[:id])
+      raise "AddressInUse" unless address[:instance_id].nil?
+      instance = @client.load(:instances, opts[:instance_id])
+      address[:instance_id] = instance[:id]
+      instance[:public_addresses] = [InstanceAddress.new(address[:id])]
+      @client.store(:addresses, address)
+      @client.store(:instances, instance)
+    end
+
+    def disassociate_address(credentials, opts={})
+      check_credentials(credentials)
+      address = @client.load(:addresses, opts[:id])
+      raise "AddressNotInUse" unless address[:instance_id]
+      instance = @client.load(:instances, address[:instance_id])
+      address[:instance_id] = nil
+      instance[:public_addresses] = [InstanceAddress.new("#{instance[:image_id]}.#{instance[:id]}.public.com",
:type => :hostname)]
+      @client.store(:addresses, address)
+      @client.store(:instances, instance)
+    end
+
     #--
     # Buckets
     #--
@@ -530,6 +573,17 @@ module Deltacloud::Drivers::Mock
       end
     end
 
+    #Mock allocation of 'new' address
+    #There is a synchronization problem (but it's the mock driver,
+    #mutex seemed overkill)
+    def allocate_mock_address
+      addresses = []
+      @client.members(:addresses).each do |addr|
+        addresses << IPAddr.new("#{addr}").to_i
+      end
+      IPAddr.new(addresses.sort.pop+1, Socket::AF_INET)
+    end
+
     def attach_volume_instance(volume_id, device, instance_id)
       volume = @client.load(:storage_volumes, volume_id)
       instance = @client.load(:instances, instance_id)
@@ -597,6 +651,14 @@ module Deltacloud::Drivers::Mock
         message "Key with same name already exists"
       end
 
+      on /AddressInUse/ do
+        status 403
+      end
+
+      on /AddressNotInUse/ do
+        status 403
+      end
+
       on /BucketNotExist/ do
         status 404
       end


Mime
View raw message