deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject git commit: Restore mock network operations removed by commit d4d8e38897152671a2f99edeab95c3a146a231cf
Date Wed, 20 Feb 2013 17:32:46 GMT
Updated Branches:
  refs/heads/master 58db7bd2e -> 324ef9535


Restore mock network operations removed by commit d4d8e38897152671a2f99edeab95c3a146a231cf

part of DTACLOUD-470 https://issues.apache.org/jira/browse/DTACLOUD-470


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

Branch: refs/heads/master
Commit: 324ef95352ebe67743a093be7081478a9c8cf301
Parents: 58db7bd
Author: marios <marios@redhat.com>
Authored: Mon Feb 18 15:53:17 2013 +0200
Committer: marios <marios@redhat.com>
Committed: Wed Feb 20 19:32:24 2013 +0200

----------------------------------------------------------------------
 server/lib/deltacloud/drivers/mock/mock_client.rb  |   14 ++++
 .../drivers/mock/mock_driver_cimi_methods.rb       |   52 +++++++++++++++
 2 files changed, 66 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/324ef953/server/lib/deltacloud/drivers/mock/mock_client.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/mock_client.rb b/server/lib/deltacloud/drivers/mock/mock_client.rb
index eb37176..d3ac437 100644
--- a/server/lib/deltacloud/drivers/mock/mock_client.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_client.rb
@@ -93,6 +93,17 @@ module Deltacloud::Drivers::Mock
       FileUtils.rm(fname) if File::exists?(fname)
     end
 
+    def store_cimi(collection, obj)
+      raise "Why no obj.name?" unless obj.name
+      File::open(cimi_file(collection, obj.name), "w") { |f| f.write(obj.to_json) }
+    end
+
+    def destroy_cimi(collection, id)
+      fname = cimi_file(collection, id)
+      raise "No such object: #{id} in #{collection} collection" unless File::exists?(fname)
+      FileUtils.rm(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)}
@@ -110,6 +121,9 @@ module Deltacloud::Drivers::Mock
       File::join(@storage_root, "cimi", collection.to_s)
     end
 
+
+
+
     private
 
     def collection_name(klass)

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/324ef953/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb b/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb
index 336f77b..e410c5a 100644
--- a/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb
@@ -20,6 +20,7 @@
 module Deltacloud::Drivers::Mock
 
   class MockDriver < Deltacloud::BaseDriver
+
     def networks(credentials, opts={})
       check_credentials(credentials)
       if opts[:id].nil?
@@ -31,6 +32,48 @@ module Deltacloud::Drivers::Mock
       end
     end
 
+    def create_network(credentials, opts={})
+      check_credentials(credentials)
+      id = "#{opts[:env].send("networks_url")}/#{opts[:name]}"
+      net_hsh = { "id"=> id,
+                  "name" => opts[:name],
+                  "description" => opts[:description],
+                  "created" => Time.now,
+                  "state" => "STARTED",
+                  "networkType" => opts[:network_config].network_type,
+                  "mtu" =>  opts[:network_config].mtu,
+                  "classOfService" => opts[:network_config].class_of_service,
+
+
+                  "forwardingGroup"=> { "href" => opts[:forwarding_group].id },
+                  "operations" => [{"rel"=>"edit", "href"=> id},
+                                   {"rel"=>"delete", "href"=> id}]    }
+      network = CIMI::Model::Network.from_json(JSON.generate(net_hsh))
+
+      @client.store_cimi(:network, network)
+      network
+    end
+
+    def delete_network(credentials, id)
+      check_credentials(credentials)
+      @client.destroy_cimi(:network, id)
+    end
+
+    def start_network(credentials, id)
+      check_credentials(credentials)
+      update_object_state(id, "Network", "STARTED")
+    end
+
+    def stop_network(credentials, id)
+      check_credentials(credentials)
+      update_object_state(id, "Network", "STOPPED")
+    end
+
+    def suspend_network(credentials, id)
+      check_credentials(credentials)
+      update_object_state(id, "Network", "SUSPENDED")
+    end
+
     def network_configurations(credentials, opts={})
       check_credentials(credentials)
       if opts[:id].nil?
@@ -163,6 +206,15 @@ module Deltacloud::Drivers::Mock
       end
     end
 
+    def update_object_state(id, object, new_state)
+      klass = CIMI::Model.const_get("#{object}")
+      symbol = object.to_s.downcase.singularize.intern
+      obj = klass.from_json(@client.load_cimi(symbol, id))
+      obj.state = new_state
+      @client.store_cimi(symbol, obj)
+      obj
+    end
+
   end
 
 end


Mime
View raw message