From: marios <mar...@redhat.com>

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

Signed-off-by: marios <mar...@redhat.com>
---
 server/lib/cimi/models/network.rb                  | 12 ++---
 server/lib/deltacloud/drivers/mock/mock_client.rb  | 14 ++++++
 .../drivers/mock/mock_driver_cimi_methods.rb       | 52 ++++++++++++++++++++++
 3 files changed, 72 insertions(+), 6 deletions(-)

diff --git a/server/lib/cimi/models/network.rb 
b/server/lib/cimi/models/network.rb
index f415664..e9d133f 100644
--- a/server/lib/cimi/models/network.rb
+++ b/server/lib/cimi/models/network.rb
@@ -55,7 +55,7 @@ class CIMI::Model::Network < CIMI::Model::Base
   def self.create(request_body, context, type)
     input = (type == :xml)? XmlSimple.xml_in(request_body, 
{"ForceArray"=>false,"NormaliseSpace"=>2}) : JSON.parse(request_body)
     if input["networkTemplate"]["href"] #template by reference
-      network_config, routing_group = get_by_reference(input, context)
+      network_config, forwarding_group = get_by_reference(input, context)
     else
       if input["networkTemplate"]["networkConfig"]["href"] # configuration by 
reference
         network_config = 
CIMI::Model::NetworkConfiguration.find(context.href_id(input["networkTemplate"]["networkConfig"]["href"],
@@ -63,10 +63,10 @@ class CIMI::Model::Network < CIMI::Model::Base
       else #configuration by value
         network_config = get_by_value(request_body, type)
       end
-      routing_group = 
CIMI::Model::RoutingGroup.find(context.href_id(input["networkTemplate"]["routingGroup"]["href"],
-                                                                     
:routing_groups), context)
+      forwarding_group = 
CIMI::Model::ForwardingGroup.find(context.href_id(input["networkTemplate"]["forwardingGroup"]["href"],
+                                                                     
:forwarding_groups), context)
     end
-    params = {:network_config => network_config, :routing_group => 
routing_group, :name=>input["name"],
+    params = {:network_config => network_config, :forwarding_group => 
forwarding_group, :name=>input["name"],
               :description=>input["description"], :env=>context}
     raise CIMI::Model::BadRequest.new("Bad request - missing required 
parameters. Client sent: #{request_body} which produced #{params.inspect}")  if 
params.has_value?(nil)
     context.driver.create_network(context.credentials, params)
@@ -93,8 +93,8 @@ class CIMI::Model::Network < CIMI::Model::Base
   def self.get_by_reference(input, context)
     network_template = 
CIMI::Model::NetworkTemplate.find(context.href_id(input["networkTemplate"]["href"],
 :network_templates), context)
     network_config = 
CIMI::Model::NetworkConfiguration.find(context.href_id(network_template.network_config.href,
 :network_configurations), context)
-    routing_group = 
CIMI::Model::RoutingGroup.find(context.href_id(network_template.routing_group.href,
 :routing_groups), context)
-    return network_config, routing_group
+    forwarding_group = 
CIMI::Model::ForwardingGroup.find(context.href_id(network_template.forwarding_group.href,
 :forwarding_groups), context)
+    return network_config, forwarding_group
   end
 
   def self.get_by_value(request_body, type)
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)
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
-- 
1.7.11.7

  • DTACLOUD-470 marios
    • [PATCH] Restore mock network operations removed by commit d4d8... marios

Reply via email to