deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject svn commit: r1232042 - in /deltacloud/trunk/server/lib: cimi/model/network.rb deltacloud/drivers/mock/mock_client.rb deltacloud/drivers/mock/mock_driver.rb
Date Mon, 16 Jan 2012 15:47:01 GMT
Author: marios
Date: Mon Jan 16 15:47:01 2012
New Revision: 1232042

URL: http://svn.apache.org/viewvc?rev=1232042&view=rev
Log:
Adds mocking of CIMI::Network to deltacloud mock driver/client

Modified:
    deltacloud/trunk/server/lib/cimi/model/network.rb
    deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_client.rb
    deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb

Modified: deltacloud/trunk/server/lib/cimi/model/network.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/cimi/model/network.rb?rev=1232042&r1=1232041&r2=1232042&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/cimi/model/network.rb (original)
+++ deltacloud/trunk/server/lib/cimi/model/network.rb Mon Jan 16 15:47:01 2012
@@ -44,9 +44,9 @@ class CIMI::Model::Network < CIMI::Model
   def self.find(id, context)
     networks=[]
     if id==:all
-#FIXME
+      networks = context.driver.networks(context.credentials, {:env=>context})
     else
-#FIXME
+      networks = context.driver.networks(context.credentials, {:id=>id, :env=>context})
     end
     networks
   end

Modified: deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_client.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_client.rb?rev=1232042&r1=1232041&r2=1232042&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_client.rb (original)
+++ deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_client.rb Mon Jan 16 15:47:01
2012
@@ -91,6 +91,23 @@ module Deltacloud::Drivers::Mock
       FileUtils.rm(fname) if File::exists?(fname)
     end
 
+    def load_all_cimi(model_name)
+        model_files = Dir[File::join(cimi_dir(model_name), "*.json")]
+        model_files.map{|f| File.read(f)}
+    end
+
+    def load_cimi(model_name, id)
+        File.read(cimi_file(model_name, id))
+    end
+
+    def cimi_file(collection, id)
+      File::join(cimi_dir(collection), "#{id}.json")
+    end
+
+    def cimi_dir(collection)
+      File::join(@storage_root, "cimi", collection.to_s)
+    end
+
     private
 
     def collection_name(klass)

Modified: deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb?rev=1232042&r1=1232041&r2=1232042&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb (original)
+++ deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb Mon Jan 16 15:47:01
2012
@@ -441,6 +441,17 @@ module Deltacloud::Drivers::Mock
       return false
     end
 
+    def networks(credentials, opts={})
+      check_credentials(credentials)
+      if opts[:id].nil?
+        networks = @client.load_all_cimi(:network).map{|net| CIMI::Model::Network.from_json(net)}
+        networks.map{|net|convert_cimi_network(net,opts[:env])}.flatten
+      else
+        network = CIMI::Model::Network.from_json(@client.load_cimi(:network, opts[:id]))
+        convert_cimi_network(network, opts[:env])
+      end
+    end
+
     private
 
     def check_credentials(credentials)
@@ -477,6 +488,13 @@ module Deltacloud::Drivers::Mock
       StorageVolume.new(volume)
     end
 
+    def convert_cimi_network(network, context)
+      uri=context.network_url(network.name)
+      network.uri=uri
+      network.operations.each{|op| op.href=uri}
+      network
+    end
+
     exceptions do
 
       on /AuthFailure/ do



Mime
View raw message