incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@apache.org
Subject svn commit: r962007 - in /incubator/deltacloud/trunk/framework: config/ lib/drivers/ mock/ mock/images/ mock/instances/ mock/storage_snapshots/ mock/storage_volumes/
Date Thu, 08 Jul 2010 23:16:30 GMT
Author: lutter
Date: Thu Jul  8 23:16:29 2010
New Revision: 962007

URL: http://svn.apache.org/viewvc?rev=962007&view=rev
Log:
Add some mock data for the mock driver.

Added:
    incubator/deltacloud/trunk/framework/mock/
    incubator/deltacloud/trunk/framework/mock/images/
    incubator/deltacloud/trunk/framework/mock/images/.gitignore
    incubator/deltacloud/trunk/framework/mock/images/img1.yml
    incubator/deltacloud/trunk/framework/mock/images/img2.yml
    incubator/deltacloud/trunk/framework/mock/images/img3.yml
    incubator/deltacloud/trunk/framework/mock/instances/
    incubator/deltacloud/trunk/framework/mock/instances/.gitignore
    incubator/deltacloud/trunk/framework/mock/instances/inst1.yml
    incubator/deltacloud/trunk/framework/mock/instances/inst2.yml
    incubator/deltacloud/trunk/framework/mock/storage_snapshots/
    incubator/deltacloud/trunk/framework/mock/storage_snapshots/.gitignore
    incubator/deltacloud/trunk/framework/mock/storage_volumes/
    incubator/deltacloud/trunk/framework/mock/storage_volumes/.gitignore
Modified:
    incubator/deltacloud/trunk/framework/config/environment.rb
    incubator/deltacloud/trunk/framework/lib/drivers/mock.rb

Modified: incubator/deltacloud/trunk/framework/config/environment.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/framework/config/environment.rb?rev=962007&r1=962006&r2=962007&view=diff
==============================================================================
--- incubator/deltacloud/trunk/framework/config/environment.rb (original)
+++ incubator/deltacloud/trunk/framework/config/environment.rb Thu Jul  8 23:16:29 2010
@@ -50,4 +50,5 @@ Rails::Initializer.run do |config|
   # config.i18n.default_locale = :de
 end
 
-DRIVER = :ec2
+#DRIVER = :ec2
+DRIVER = :mock

Modified: incubator/deltacloud/trunk/framework/lib/drivers/mock.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/framework/lib/drivers/mock.rb?rev=962007&r1=962006&r2=962007&view=diff
==============================================================================
--- incubator/deltacloud/trunk/framework/lib/drivers/mock.rb (original)
+++ incubator/deltacloud/trunk/framework/lib/drivers/mock.rb Thu Jul  8 23:16:29 2010
@@ -5,6 +5,8 @@ module Drivers
 
   class Mock < BaseDriver
 
+    STORAGE_ROOT = RAILS_ROOT + '/mock'
+
     # 
     # Flavors
     # 
@@ -52,7 +54,20 @@ module Drivers
     # 
 
     def images(credentials, ids_or_owner=nil )
+      check_credentials( credentials )
       images = []
+      Dir[ "#{STORAGE_ROOT}/images/*.yml" ].each do |image_file|
+        image = YAML.load( File.read( image_file ) )
+        image[:id] = File.basename( image_file, ".yml" )
+        images << image
+      end
+      if ( ids_or_owner.is_a?( Array ) )
+        images = images.select{|e| ids_or_owner.include?( e[:id] )} 
+      elsif ( ids_or_owner == 'self' )
+        images = images.select{|e| e[:owner_id] == credentials[:name] }
+      elsif ( ! ids_or_owner.nil? )
+        images = images.select{|e| e[:owner_id] == ids_or_owner }
+      end
       images.sort_by{|e| [e[:owner_id],e[:description]]}
     end
 
@@ -62,6 +77,16 @@ module Drivers
 
     def instances(credentials, ids=nil)
       instances = []
+      Dir[ "#{STORAGE_ROOT}/instances/*.yml" ].each do |instance_file|
+        instance = YAML.load( File.read( instance_file ) )
+        if ( instance[:owner_id] == credentials[:name] )
+          instance[:id] = File.basename( instance_file, ".yml" )
+          instances << instance
+        end
+      end
+      unless ( ids.nil? || ids.empty? )
+        instances = instances.select{|e| ids.include?( e[:id] )} 
+      end
       instances
     end
 
@@ -94,6 +119,16 @@ module Drivers
 
     private
 
+    def check_credentials(credentials)
+      if ( credentials[:name] != 'mockuser' )
+        raise Drivers::AuthException.new
+      end
+
+      if ( credentials[:password] != 'mockpassword' )
+        raise Drivers::AuthException.new
+      end
+    end
+
 
   end
 

Added: incubator/deltacloud/trunk/framework/mock/images/.gitignore
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/framework/mock/images/.gitignore?rev=962007&view=auto
==============================================================================
    (empty)

Added: incubator/deltacloud/trunk/framework/mock/images/img1.yml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/framework/mock/images/img1.yml?rev=962007&view=auto
==============================================================================
--- incubator/deltacloud/trunk/framework/mock/images/img1.yml (added)
+++ incubator/deltacloud/trunk/framework/mock/images/img1.yml Thu Jul  8 23:16:29 2010
@@ -0,0 +1,3 @@
+:description: Fedora 10
+:owner_id: fedoraproject
+:architecture: x86_64

Added: incubator/deltacloud/trunk/framework/mock/images/img2.yml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/framework/mock/images/img2.yml?rev=962007&view=auto
==============================================================================
--- incubator/deltacloud/trunk/framework/mock/images/img2.yml (added)
+++ incubator/deltacloud/trunk/framework/mock/images/img2.yml Thu Jul  8 23:16:29 2010
@@ -0,0 +1,3 @@
+:description: Fedora 10
+:owner_id: fedoraproject
+:architecture: i386

Added: incubator/deltacloud/trunk/framework/mock/images/img3.yml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/framework/mock/images/img3.yml?rev=962007&view=auto
==============================================================================
--- incubator/deltacloud/trunk/framework/mock/images/img3.yml (added)
+++ incubator/deltacloud/trunk/framework/mock/images/img3.yml Thu Jul  8 23:16:29 2010
@@ -0,0 +1,3 @@
+:description: JBoss
+:owner_id: mockuser
+:architecture: i386

Added: incubator/deltacloud/trunk/framework/mock/instances/.gitignore
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/framework/mock/instances/.gitignore?rev=962007&view=auto
==============================================================================
    (empty)

Added: incubator/deltacloud/trunk/framework/mock/instances/inst1.yml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/framework/mock/instances/inst1.yml?rev=962007&view=auto
==============================================================================
--- incubator/deltacloud/trunk/framework/mock/instances/inst1.yml (added)
+++ incubator/deltacloud/trunk/framework/mock/instances/inst1.yml Thu Jul  8 23:16:29 2010
@@ -0,0 +1,6 @@
+:state: running
+:image_id: img3
+:owner_id: mockuser
+:public_address: 123.123.123.123
+:private_address: 10.10.10.10
+:flavor_id: m1-small

Added: incubator/deltacloud/trunk/framework/mock/instances/inst2.yml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/framework/mock/instances/inst2.yml?rev=962007&view=auto
==============================================================================
--- incubator/deltacloud/trunk/framework/mock/instances/inst2.yml (added)
+++ incubator/deltacloud/trunk/framework/mock/instances/inst2.yml Thu Jul  8 23:16:29 2010
@@ -0,0 +1,6 @@
+:state: running
+:image_id: img1
+:owner_id: anotheruser
+:public_address: 123.123.123.123
+:private_address: 10.10.10.10
+:flavor_id: m1-small

Added: incubator/deltacloud/trunk/framework/mock/storage_snapshots/.gitignore
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/framework/mock/storage_snapshots/.gitignore?rev=962007&view=auto
==============================================================================
    (empty)

Added: incubator/deltacloud/trunk/framework/mock/storage_volumes/.gitignore
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/framework/mock/storage_volumes/.gitignore?rev=962007&view=auto
==============================================================================
    (empty)



Mime
View raw message