incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core 2/3] Fix Mock driver speed in case you have a lot of YAML files
Date Mon, 08 Nov 2010 11:38:25 GMT
From: Michal Fojtik <mfojtik@redhat.com>

---
 server/lib/deltacloud/drivers/mock/mock_driver.rb |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/server/lib/deltacloud/drivers/mock/mock_driver.rb b/server/lib/deltacloud/drivers/mock/mock_driver.rb
index 847319b..52c63b7 100644
--- a/server/lib/deltacloud/drivers/mock/mock_driver.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_driver.rb
@@ -130,12 +130,23 @@ class MockDriver < Deltacloud::BaseDriver
   #
   # Instances
   #
+  require 'ruby-prof'
+
+  def instance(credentials, opts={})
+    check_credentials( credentials )
+    instance_filename = File.join(@storage_root, 'instances', "#{opts[:id]}.yml")
+    return nil unless File.exists?(instance_filename)
+    instance = YAML::load_file(instance_filename)
+    instance[:actions] = instance_actions_for( instance[:state] )
+    instance[:id] = File::basename(instance_filename, ".yml")
+    Instance.new(instance)
+  end
 
   def instances(credentials, opts=nil)
     check_credentials( credentials )
     instances = []
     Dir[ "#{@storage_root}/instances/*.yml" ].each do |instance_file|
-      instance = YAML.load( File.read( instance_file ) )
+      instance = YAML::load_file(instance_file)
       if ( instance[:owner_id] == credentials.user )
         instance[:id] = File.basename( instance_file, ".yml" )
         instance[:actions] = instance_actions_for( instance[:state] )
-- 
1.7.2.3


Mime
View raw message