deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [9/11] git commit: CIMI: Adds CIMI::Network status change methods for mock driver/client
Date Wed, 11 Apr 2012 15:33:08 GMT
CIMI: Adds CIMI::Network status change methods for mock driver/client


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

Branch: refs/heads/master
Commit: b17629ad7898f2307874e1ca494eb20720f1dc89
Parents: a96745c
Author: marios <marios@redhat.com>
Authored: Mon Apr 2 14:01:59 2012 +0300
Committer: marios <marios@redhat.com>
Committed: Wed Apr 11 18:32:07 2012 +0300

----------------------------------------------------------------------
 server/lib/deltacloud/drivers/mock/mock_client.rb  |    4 +-
 .../drivers/mock/mock_driver_cimi_methods.rb       |   28 +++++++++++++-
 2 files changed, 28 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/b17629ad/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 7d446db..3de8254 100644
--- a/server/lib/deltacloud/drivers/mock/mock_client.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_client.rb
@@ -92,8 +92,8 @@ module Deltacloud::Drivers::Mock
     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(JSON.generate(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)

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/b17629ad/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 8ffaa23..81f13c2 100644
--- a/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb
@@ -35,7 +35,7 @@ module Deltacloud::Drivers::Mock
     def create_network(credentials, opts={})
       check_credentials(credentials)
       id = "#{opts[:env].send("networks_url")}/#{opts[:name]}"
-      network = { "id"=> id,
+      net_hsh = { "id"=> id,
                   "name" => opts[:name],
                   "description" => opts[:description],
                   "created" => Time.now,
@@ -49,8 +49,10 @@ module Deltacloud::Drivers::Mock
                   "routingGroup"=> { "href" => opts[:routing_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)
-      CIMI::Model::Network.from_json(@client.load_cimi(:network, opts[:name]))
+      network
     end
 
     def delete_network(credentials, id)
@@ -58,6 +60,21 @@ module Deltacloud::Drivers::Mock
       @client.destroy_cimi(:network, id)
     end
 
+    def start_network(credentials, id)
+      check_credentials(credentials)
+      update_network_state(id, "STARTED")
+    end
+
+    def stop_network(credentials, id)
+      check_credentials(credentials)
+      update_network_state(id, "STOPPED")
+    end
+
+    def suspend_network(credentials, id)
+      check_credentials(credentials)
+      update_network_state(id, "SUSPENDED")
+    end
+
     def network_configurations(credentials, opts={})
       check_credentials(credentials)
       if opts[:id].nil?
@@ -166,6 +183,13 @@ module Deltacloud::Drivers::Mock
       end
     end
 
+    def update_network_state(id, new_state)
+      network = CIMI::Model::Network.from_json(@client.load_cimi(:network, id))
+      network.state = new_state
+      @client.store_cimi(:network, network)
+      network
+    end
+
   end
 
 end


Mime
View raw message