deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core 04/51] Core: Drivers are now loaded on demand and the 'require "base_driver"' is not longer required in driver
Date Mon, 21 May 2012 10:06:45 GMT
From: Michal Fojtik <mfojtik@redhat.com>


Signed-off-by: Michal fojtik <mfojtik@redhat.com>
---
 server/lib/deltacloud/drivers.rb                   |   48 +------
 .../lib/deltacloud/drivers/azure/azure_driver.rb   |    4 -
 server/lib/deltacloud/drivers/base_driver.rb       |    7 +-
 .../lib/deltacloud/drivers/condor/condor_driver.rb |    7 -
 server/lib/deltacloud/drivers/ec2/ec2_driver.rb    |   15 +--
 .../drivers/eucalyptus/eucalyptus_driver.rb        |    4 -
 server/lib/deltacloud/drivers/features.rb          |  111 ++++++++++++++++
 .../lib/deltacloud/drivers/gogrid/gogrid_driver.rb |    6 -
 .../lib/deltacloud/drivers/google/google_driver.rb |    3 -
 server/lib/deltacloud/drivers/mock/mock_client.rb  |   11 --
 server/lib/deltacloud/drivers/mock/mock_driver.rb  |   21 +--
 .../drivers/mock/mock_driver_cimi_methods.rb       |  139 --------------------
 .../drivers/opennebula/opennebula_driver.rb        |    4 -
 .../drivers/openstack/openstack_driver.rb          |    6 +-
 .../drivers/rackspace/rackspace_driver.rb          |    9 +-
 .../lib/deltacloud/drivers/rhevm/rhevm_driver.rb   |   17 +--
 .../drivers/rimuhosting/rimuhosting_driver.rb      |    7 +-
 .../drivers/terremark/terremark_driver.rb          |    3 +-
 .../deltacloud/drivers/vsphere/vsphere_driver.rb   |   11 +-
 server/lib/deltacloud/helpers/driver_helper.rb     |    5 +-
 server/lib/deltacloud/models.rb                    |   25 +++-
 server/lib/deltacloud/models/state_machine.rb      |   19 ++-
 22 files changed, 184 insertions(+), 298 deletions(-)
 create mode 100644 server/lib/deltacloud/drivers/features.rb

diff --git a/server/lib/deltacloud/drivers.rb b/server/lib/deltacloud/drivers.rb
index dfc998d..14e7ee0 100644
--- a/server/lib/deltacloud/drivers.rb
+++ b/server/lib/deltacloud/drivers.rb
@@ -13,25 +13,15 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 
-module Deltacloud
+require_relative 'drivers/exceptions'
+require_relative 'drivers/base_driver'
+require_relative 'drivers/features'
+require 'yaml'
 
+module Deltacloud
   module Drivers
 
-    require 'yaml'
-
-    DEFAULT_COLLECTIONS = [
-      :hardware_profiles,
-      :images,
-      :instances,
-      :instance_states,
-      :realms,
-      :storage_volumes,
-      :storage_snapshots
-    ]
-
-    DRIVER=ENV['API_DRIVER'] ? ENV['API_DRIVER'].to_sym : :mock
-
-    def driver_config
+    def self.driver_config
       if Thread::current[:drivers].nil?
         Thread::current[:drivers] = {}
         top_srcdir = File.join(File.dirname(__FILE__), '..', '..')
@@ -42,31 +32,5 @@ module Deltacloud
       Thread::current[:drivers]
     end
 
-    def driver_symbol
-      (Thread.current[:driver] || DRIVER).to_sym
-    end
-
-    def driver_name
-      driver_config[:"#{driver_symbol}"][:name]
-    end
-
-    def driver_class
-      basename = driver_config[:"#{driver_symbol}"][:class] || "#{driver_name}Driver"
-      Deltacloud::Drivers.const_get(driver_name).const_get(basename)
-    end
-
-    def driver_source_name
-      File.join("deltacloud", "drivers", "#{driver_symbol}", "#{driver_symbol}_driver.rb")
-    end
-
-    def driver_mock_source_name
-      return File.join('deltacloud', 'drivers', "#{driver_symbol}",
-		       "#{driver_symbol}_driver.rb") if driver_name.eql? 'Mock'
-    end
-
-    def driver
-      require driver_source_name
-      @driver ||= driver_class.new
-    end
   end
 end
diff --git a/server/lib/deltacloud/drivers/azure/azure_driver.rb b/server/lib/deltacloud/drivers/azure/azure_driver.rb
index 24feeb7..db2b6c6 100644
--- a/server/lib/deltacloud/drivers/azure/azure_driver.rb
+++ b/server/lib/deltacloud/drivers/azure/azure_driver.rb
@@ -15,7 +15,6 @@
 # under the License.
 
 #Windows Azure (WAZ) gem at http://github.com/johnnyhalife/waz-storage
-require 'deltacloud/base_driver'
 require 'waz-blobs'
 
 module Deltacloud
@@ -24,9 +23,6 @@ module Deltacloud
 
 class AzureDriver < Deltacloud::BaseDriver
 
-  def supported_collections; [:buckets]
-  end
-
 #--
 # Buckets
 #--
diff --git a/server/lib/deltacloud/drivers/base_driver.rb b/server/lib/deltacloud/drivers/base_driver.rb
index 5fb1a79..f3637b7 100644
--- a/server/lib/deltacloud/drivers/base_driver.rb
+++ b/server/lib/deltacloud/drivers/base_driver.rb
@@ -20,6 +20,11 @@ module Deltacloud
 
     include ExceptionHandler
 
+    STATE_MACHINE_OPTS = {
+      :all_states => [:start, :pending, :running, :stopping, :stopped, :finish],
+      :all_actions => [:create, :reboot, :stop, :start, :destroy]
+    }
+
     def self.driver_name
       name.split('::').last.gsub('Driver', '').downcase
     end
@@ -114,7 +119,7 @@ module Deltacloud
     end
 
     def self.define_instance_states(&block)
-      machine = ::Deltacloud::StateMachine.new(&block)
+      machine = ::Deltacloud::StateMachine.new(STATE_MACHINE_OPTS, &block)
       @instance_state_machine = machine
     end
 
diff --git a/server/lib/deltacloud/drivers/condor/condor_driver.rb b/server/lib/deltacloud/drivers/condor/condor_driver.rb
index f5cb741..b0564f9 100644
--- a/server/lib/deltacloud/drivers/condor/condor_driver.rb
+++ b/server/lib/deltacloud/drivers/condor/condor_driver.rb
@@ -14,9 +14,6 @@
 # under the License.
 #
 
-require 'deltacloud/base_driver'
-
-
 class Instance
   def self.convert_condor_state(state_id)
     case state_id
@@ -44,10 +41,6 @@ module Deltacloud
         feature :instances, :user_data
         feature :instances, :authentication_password
 
-        def supported_collections
-          DEFAULT_COLLECTIONS - [ :storage_volumes, :storage_snapshots ]
-        end
-
         CONDOR_MAPPER_DIR = ENV['CONDOR_MAPPER_DIR'] || '/var/tmp'
 
         def hardware_profiles(credentials, opts={})
diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index 2ebb6c2..f7559a3 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -14,7 +14,6 @@
 # under the License.
 #
 
-require 'deltacloud/base_driver'
 require 'aws'
 
 class Instance
@@ -29,13 +28,8 @@ end
 
 module Deltacloud
   module Drivers
-    module EC2
-      class EC2Driver < Deltacloud::BaseDriver
-
-        def supported_collections
-
-          DEFAULT_COLLECTIONS + [ :keys, :buckets, :load_balancers, :addresses, :firewalls,
:metrics ]
-        end
+    module Ec2
+      class Ec2Driver < Deltacloud::BaseDriver
 
         feature :instances, :user_data
         feature :instances, :authentication_key
@@ -444,9 +438,7 @@ module Deltacloud
           safely do
             s3_bucket = s3_client.bucket(opts['bucket'])
             if(opts[:id])
-              s3_key = s3_bucket.key(opts[:id], true)
-              raise "Blob #{opts[:id]} in Bucket #{opts['bucket']} NotFound" unless s3_key.exists?
-              blobs << convert_object(s3_key)
+              blobs << convert_object(s3_bucket.key(opts[:id], true))
             else
               s3_bucket.keys({}, true).each do |s3_object|
                 blobs << convert_object(s3_object)
@@ -502,7 +494,6 @@ module Deltacloud
           blob_meta = {}
           safely do
             the_blob = s3_client.bucket(opts['bucket']).key(opts[:id], true)
-            raise "Blob #{opts[:id]} in Bucket #{opts['bucket']} NotFound" unless the_blob.exists?
             blob_meta = the_blob.meta_headers
           end
         end
diff --git a/server/lib/deltacloud/drivers/eucalyptus/eucalyptus_driver.rb b/server/lib/deltacloud/drivers/eucalyptus/eucalyptus_driver.rb
index 8737a27..1872cf3 100644
--- a/server/lib/deltacloud/drivers/eucalyptus/eucalyptus_driver.rb
+++ b/server/lib/deltacloud/drivers/eucalyptus/eucalyptus_driver.rb
@@ -21,10 +21,6 @@ module Deltacloud
     module Eucalyptus
       class EucalyptusDriver < Ec2::Ec2Driver
 
-        def supported_collections
-          DEFAULT_COLLECTIONS + [ :keys, :buckets, :addresses, :firewalls ]
-        end
-
         feature :instances, :user_data
         feature :instances, :authentication_key
         feature :instances, :firewalls
diff --git a/server/lib/deltacloud/drivers/features.rb b/server/lib/deltacloud/drivers/features.rb
new file mode 100644
index 0000000..01d8656
--- /dev/null
+++ b/server/lib/deltacloud/drivers/features.rb
@@ -0,0 +1,111 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.  The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License.  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+module Deltacloud
+  module InstanceFeatures
+
+    def self.included(k)
+      current_features = features
+      k.instance_eval do
+        features(&current_features)
+      end
+    end
+
+    def self.features(&block)
+      block_given? ? @features = block : @features || Proc.new{}
+    end
+
+    features do
+
+      feature :user_name, :for => :instances do
+        description "Allow to set user-defined name for the instance"
+        operation :create do
+          param :name, :string, :optional
+        end
+      end
+
+      feature :user_data, :for => :instances do
+        description "Allow to pass user-defined data into the instance"
+        operation :create do
+          param :user_data, :string, :optional
+        end
+      end
+
+      feature :user_iso, :for => :instances do
+        description  "Base64 encoded gzipped ISO file will be accessible as CD-ROM drive
in instance"
+        operation :create do
+          param :user_iso, :string, :optional
+        end
+      end
+
+      feature :firewalls, :for => :instances do
+        description "Put instance in one or more firewalls (security groups) on launch"
+        operation :create do
+          param :firewalls, :array, :optional, nil, "Array of firewall ID strings"
+          "Array of firewall (security group) id"
+        end
+      end
+
+      feature :authentication_key, :for => :instances do
+        operation :create do
+          param :keyname, :string,  :optional, [], "Key authentification method"
+        end
+        operation :show do
+        end
+      end
+
+      feature :authentication_password, :for => :instances do
+        operation :create do
+          param :password, :string, :optional
+        end
+      end
+
+      feature :hardware_profiles, :for => :instances do
+        description "Size instances according to changes to a hardware profile"
+        # The parameters are filled in from the hardware profiles
+      end
+
+      feature :register_to_load_balancer, :for => :instances do
+        description "Register instance to load balancer"
+        operation :create do
+          param :load_balancer_id, :string, :optional
+        end
+      end
+
+      feature :instance_count, :for => :instances do
+        description "Number of instances to be launch with at once"
+        operation :create do
+          param :instance_count,  :string,  :optional
+        end
+      end
+
+      feature :attach_snapshot, :for => :instances do
+        description "Attach an snapshot to instance on create"
+        operation :create do
+          param :snapshot_id,  :string,  :optional
+          param :device_name,  :string,  :optional
+        end
+      end
+
+      feature :sandboxing, :for => :instances do
+        description "Allow lanuching sandbox images"
+        operation :create do
+          param :sandbox, :string,  :optional
+        end
+      end
+    end
+
+  end
+end
diff --git a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
index c6336cd..ee08afe 100644
--- a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
+++ b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
@@ -14,7 +14,6 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 
-require 'deltacloud/base_driver'
 require 'deltacloud/drivers/gogrid/gogrid_client'
 
 class Instance
@@ -61,11 +60,6 @@ class GogridDriver < Deltacloud::BaseDriver
     @hardware_profiles
   end
 
-  def supported_collections
-    DEFAULT_COLLECTIONS.reject! { |c| [ :storage_volumes, :storage_snapshots ].include?(c)
}
-    DEFAULT_COLLECTIONS + [ :keys, :load_balancers ]
-  end
-
   def images(credentials, opts=nil)
     imgs = []
     if opts and opts[:id]
diff --git a/server/lib/deltacloud/drivers/google/google_driver.rb b/server/lib/deltacloud/drivers/google/google_driver.rb
index 2ffb5f8..8bc6f25 100644
--- a/server/lib/deltacloud/drivers/google/google_driver.rb
+++ b/server/lib/deltacloud/drivers/google/google_driver.rb
@@ -21,9 +21,6 @@ module Deltacloud
 
 class GoogleDriver < Deltacloud::BaseDriver
 
-  def supported_collections; [:buckets]
-  end
-
   feature :buckets, :bucket_location
 
 #--
diff --git a/server/lib/deltacloud/drivers/mock/mock_client.rb b/server/lib/deltacloud/drivers/mock/mock_client.rb
index 956df44..4c27a66 100644
--- a/server/lib/deltacloud/drivers/mock/mock_client.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_client.rb
@@ -91,17 +91,6 @@ 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)}
diff --git a/server/lib/deltacloud/drivers/mock/mock_driver.rb b/server/lib/deltacloud/drivers/mock/mock_driver.rb
index aaa60ca..cd7534b 100644
--- a/server/lib/deltacloud/drivers/mock/mock_driver.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_driver.rb
@@ -14,28 +14,16 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 
-
 require 'yaml'
 require 'base64'
 require 'etc'
-require 'deltacloud/base_driver'
-require 'deltacloud/drivers/mock/mock_client'
-require 'deltacloud/drivers/mock/mock_driver_cimi_methods'
+require_relative 'mock_client'
+require_relative 'mock_driver_cimi_methods'
 
 module Deltacloud::Drivers::Mock
 
   class MockDriver < Deltacloud::BaseDriver
 
-    # If the provider is set to storage, pretend to be a storage-only
-    # driver
-    def supported_collections
-      if api_provider == 'storage'
-        [:buckets]
-      else
-        DEFAULT_COLLECTIONS + [:buckets, :keys]
-      end
-    end
-
     ( REALMS = [
       Realm.new({
         :id=>'us',
@@ -312,11 +300,6 @@ module Deltacloud::Drivers::Mock
       snapshots
     end
 
-    def destroy_storage_snapshot(credentials, opts={})
-      check_credentials(credentials)
-      @client.destroy(:storage_snapshots, opts[:id])
-    end
-
     def keys(credentials, opts={})
       check_credentials(credentials)
       result = @client.build_all(Key)
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 2dec66b..bebc45c 100644
--- a/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb
@@ -32,49 +32,6 @@ 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",
-                  "access" => opts[:network_config].access,
-                  "bandwithLimit" => opts[:network_config].bandwidth_limit,
-                  "trafficPriority" => opts[:network_config].traffic_priority,
-                  "maxTrafficDelay" => opts[:network_config].max_traffic_delay,
-                  "maxTrafficLoss" =>opts[:network_config].max_traffic_loss,
-                  "maxTrafficJitter" =>opts[:network_config].max_traffic_jitter,
-                  "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)
-      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?
@@ -130,43 +87,6 @@ module Deltacloud::Drivers::Mock
       end
     end
 
-    def create_vsp(credentials, opts={})
-      check_credentials(credentials)
-      id = "#{opts[:env].send("vsps_url")}/#{opts[:name]}"
-      vsp_hash = { "id"    => id,
-                    "name"  => opts[:name],
-                    "description" => opts[:description],
-                    "state" => "STARTED",
-                    "created" => Time.now,
-                    "bandwidthReservation"=>opts[:vsp_config].bandwidth_reservation,
-                    "trafficPriority"=>opts[:vsp_config].traffic_priority,
-                    "maxTrafficDelay"=>opts[:vsp_config].max_traffic_delay,
-                    "maxTrafficLoss"=>opts[:vsp_config].max_traffic_loss,
-                    "maxTrafficJitter"=>opts[:vsp_config].max_traffic_jitter,
-                    "network" => {"href" => opts[:network].id},
-                    "operations" => [{"rel"=>"edit", "href"=> id},
-                                     {"rel"=>"delete", "href"=> id}]
-                   }
-      vsp = CIMI::Model::VSP.from_json(JSON.generate(vsp_hash))
-      @client.store_cimi(:vsp, vsp)
-      vsp
-    end
-
-    def start_vsp(credentials, id)
-      check_credentials(credentials)
-      update_object_state(id, "VSP", "STARTED")
-    end
-
-    def stop_vsp(credentials, id)
-      check_credentials(credentials)
-      update_object_state(id, "VSP", "STOPPED")
-    end
-
-    def delete_vsp(credentials, id)
-      check_credentials(credentials)
-      @client.destroy_cimi(:vsp, id)
-    end
-
     def vsp_configurations(credentials, opts={})
       check_credentials(credentials)
       if opts[:id].nil?
@@ -189,56 +109,6 @@ module Deltacloud::Drivers::Mock
       end
     end
 
-    def addresses(credentials, opts={})
-      check_credentials(credentials)
-      if opts[:id].nil?
-        addresses = @client.load_all_cimi(:address).map{|addr| CIMI::Model::Address.from_json(addr)}
-        addresses.map{|addr|convert_cimi_mock_urls(:address, addr, opts[:env])}.flatten
-      else
-        address = CIMI::Model::Address.from_json(@client.load_cimi(:address, opts[:id]))
-        convert_cimi_mock_urls(:address, address, opts[:env])
-      end
-    end
-
-    def create_address(credentials, opts={})
-      check_credentials(credentials)
-      id = "#{opts[:env].send("addresses_url")}/#{opts[:name]}"
-      addr_hash = { "id"    => id,
-                    "name"  => opts[:name],
-                    "description" => opts[:description],
-                    "created" => Time.now,
-                    "hostName" => opts[:address_template].hostname,
-                    "allocation" => opts[:address_template].allocation,
-                    "defaultGateway" => opts[:address_template].default_gateway,
-                    "dns" => opts[:address_template].dns,
-                    "macAddress" => opts[:address_template].mac_address,
-                    "protocol" => opts[:address_template].protocol,
-                    "mask" => opts[:address_template].mask,
-                    "network" => {"href" => opts[:address_template].network.href},
-                    "operations" => [{"rel"=>"edit", "href"=> id},
-                                     {"rel"=>"delete", "href"=> id}]
-                   }
-      address = CIMI::Model::Address.from_json(JSON.generate(addr_hash))
-      @client.store_cimi(:address, address)
-      address
-    end
-
-    def delete_address(credentials, id)
-      check_credentials(credentials)
-      @client.destroy_cimi(:address, id)
-    end
-
-    def address_templates(credentials, opts={})
-      check_credentials(credentials)
-      if opts[:id].nil?
-        address_templates = @client.load_all_cimi(:address_template).map{|addr_templ| CIMI::Model::AddressTemplate.from_json(addr_templ)}
-        address_templates.map{|addr_templ|convert_cimi_mock_urls(:address_template, addr_templ,
opts[:env])}.flatten
-      else
-        address_template = CIMI::Model::AddressTemplate.from_json(@client.load_cimi(:address_template,
opts[:id]))
-        convert_cimi_mock_urls(:address_template, address_template, opts[:env])
-      end
-    end
-
     private
 
     def convert_cimi_mock_urls(model_name, cimi_object, context)
@@ -270,15 +140,6 @@ 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
diff --git a/server/lib/deltacloud/drivers/opennebula/opennebula_driver.rb b/server/lib/deltacloud/drivers/opennebula/opennebula_driver.rb
index cc05332..2c6203b 100644
--- a/server/lib/deltacloud/drivers/opennebula/opennebula_driver.rb
+++ b/server/lib/deltacloud/drivers/opennebula/opennebula_driver.rb
@@ -27,10 +27,6 @@ module Deltacloud
 
 class OpennebulaDriver < Deltacloud::BaseDriver
 
-  def supported_collections
-    DEFAULT_COLLECTIONS - [:storage_volumes, :storage_snapshots]
-  end
-
   ######################################################################
   # Hardware profiles
   #####################################################################
diff --git a/server/lib/deltacloud/drivers/openstack/openstack_driver.rb b/server/lib/deltacloud/drivers/openstack/openstack_driver.rb
index c9ec95b..12dadef 100644
--- a/server/lib/deltacloud/drivers/openstack/openstack_driver.rb
+++ b/server/lib/deltacloud/drivers/openstack/openstack_driver.rb
@@ -14,9 +14,9 @@
 # under the License.
 #
 
-require 'deltacloud/base_driver'
 require 'openstack/compute'
 require 'tempfile'
+
 module Deltacloud
   module Drivers
     module Openstack
@@ -27,10 +27,6 @@ module Deltacloud
         feature :instances, :user_files
         feature :images, :user_name
 
-        def supported_collections
-          DEFAULT_COLLECTIONS - [ :storage_snapshots, :storage_volumes  ] #+ [ :buckets ]
-        end
-
         define_instance_states do
           start.to( :pending )          .on( :create )
           pending.to( :running )        .automatically
diff --git a/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb b/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
index a578180..c8030ad 100644
--- a/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
+++ b/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
@@ -14,7 +14,6 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 
-require 'deltacloud/base_driver'
 require 'cloudfiles'
 require 'cloudservers'
 require 'base64'
@@ -30,10 +29,6 @@ class RackspaceDriver < Deltacloud::BaseDriver
   feature :instances, :user_files
   feature :images, :user_name
 
-  def supported_collections
-    DEFAULT_COLLECTIONS + [ :buckets ] - [ :storage_snapshots, :storage_volumes ]
-  end
-
   def hardware_profiles(credentials, opts = {})
     rs = new_client( credentials )
     results = []
@@ -194,8 +189,8 @@ class RackspaceDriver < Deltacloud::BaseDriver
     start.to( :pending )          .on( :create )
     pending.to( :running )        .automatically
     running.to( :running )        .on( :reboot )
-    running.to( :stopping )       .on( :stop )
-    stopping.to( :stopped )       .automatically
+    running.to( :shutting_down )  .on( :stop )
+    shutting_down.to( :stopped )  .automatically
     stopped.to( :finish )         .automatically
   end
 
diff --git a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
index 1c96df7..f138f03 100644
--- a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
+++ b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
@@ -14,27 +14,24 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 
-require 'deltacloud/base_driver'
 require 'rbovirt'
 
 module Deltacloud
   module Drivers
-    module RHEVM
+    module Rhevm
 
-class RHEVMDriver < Deltacloud::BaseDriver
+class RhevmDriver < Deltacloud::BaseDriver
 
-  def supported_collections
-    DEFAULT_COLLECTIONS - [:storage_snapshots]
-  end
-
-  feature :instances, :user_name do
-    constraint :max_length, 50
+  Sinatra::Rabbit::InstancesCollection.features do
+    feature :user_name, :for => :instances do
+      constrain :max_length, 50
+    end
   end
 
   feature :instances, :user_data
   feature :images, :user_name
 
-  USER_NAME_MAX = feature(:instances, :user_name).constraints[:max_length]
+  USER_NAME_MAX = Sinatra::Rabbit::InstancesCollection.feature(:user_name).constraints[:max_length]
 
   # FIXME: These values are just for ilustration
   # Also I choosed 'SERVER' and 'DESKTOP' names
diff --git a/server/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb b/server/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb
index 4c2c3aa..55eec11 100644
--- a/server/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb
+++ b/server/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb
@@ -16,7 +16,6 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 
-require "deltacloud/base_driver"
 require "deltacloud/drivers/rimuhosting/rimuhosting_client"
 
 module Deltacloud
@@ -131,9 +130,9 @@ class RimuhostingDriver < Deltacloud::BaseDriver
             :owner_id => "root",
             :instance_profile => InstanceProfile.new("none"),
             :actions => instance_actions_for("RUNNING"),
-            :public_addresses => [ InstanceAddress.new(inst["allocated_ips"]["primary_ip"]
) ],
-            :launch_time => inst["billing_info"]["order_date"]["iso_format"]
-    })
+            :public_addresses => [ InstanceAddress.new(inst["allocated_ips"]["primary_ip"]
)],
+            :launch_time => inst["billing_info"]["order_date"]["iso_format"]}
+                )
   end
 
   define_instance_states do
diff --git a/server/lib/deltacloud/drivers/terremark/terremark_driver.rb b/server/lib/deltacloud/drivers/terremark/terremark_driver.rb
index 9cc442c..3260c47 100644
--- a/server/lib/deltacloud/drivers/terremark/terremark_driver.rb
+++ b/server/lib/deltacloud/drivers/terremark/terremark_driver.rb
@@ -19,8 +19,7 @@
 # https://community.vcloudexpress.terremark.com/en-us/product_docs/w/wiki/d-complete-vcloud-express-api-document.aspx
 #
 # 02 May 2010
-#
-require 'deltacloud/base_driver'
+
 require 'fog'
 require 'excon'
 require 'nokogiri'
diff --git a/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb b/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
index e16be2f..a6a1e58 100644
--- a/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
+++ b/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
@@ -14,18 +14,17 @@
 # under the License.
 #
 
-require 'deltacloud/base_driver'
 require 'rbvmomi'
 require 'deltacloud/drivers/vsphere/vsphere_client'
 
-module Deltacloud::Drivers::VSphere
+module Deltacloud::Drivers::Vsphere
 
   MAPPER_STORAGE_ROOT = File::join("/var/tmp", "deltacloud-vsphere-#{ENV["USER"]}")
 
-  class VSphereDriver < Deltacloud::BaseDriver
+  class VsphereDriver < Deltacloud::BaseDriver
 
     include Deltacloud::Drivers::VSphere::Helper
-    include Deltacloud::Drivers::VSphere::FileManager
+    include VSphere::FileManager
 
     # You can use 'user_iso' feature to set 'user_iso' parameter when creating
     # a new instance where this parameter can hold gzipped CDROM iso which will
@@ -34,10 +33,6 @@ module Deltacloud::Drivers::VSphere
     feature :instances, :user_data
     feature :instances, :user_name
 
-    def supported_collections
-      DEFAULT_COLLECTIONS - [:storage_volumes, :storage_snapshots]
-    end
-
     # There is just one hardware profile where memory is measured using maximum
     # memory available on ESX for virtual machines and CPU using maximum free
     # CPU cores in ESX.
diff --git a/server/lib/deltacloud/helpers/driver_helper.rb b/server/lib/deltacloud/helpers/driver_helper.rb
index f620744..8ae61c0 100644
--- a/server/lib/deltacloud/helpers/driver_helper.rb
+++ b/server/lib/deltacloud/helpers/driver_helper.rb
@@ -47,8 +47,9 @@ module Deltacloud::Helpers
       begin
         require_relative driver_source_name
         driver_class
-      rescue LoadError
-        raise "[ERROR] The driver '#{driver_name}' is unknown or not installed (#{driver_source_name})"
+      rescue LoadError => e
+        raise "[ERROR] The driver '#{driver_name}' is unknown or not installed (#{driver_source_name})\n"
+
+          "\n#{e.message}\n"
       end
     end
 
diff --git a/server/lib/deltacloud/models.rb b/server/lib/deltacloud/models.rb
index 099afda..e6020e6 100644
--- a/server/lib/deltacloud/models.rb
+++ b/server/lib/deltacloud/models.rb
@@ -14,10 +14,21 @@
 # under the License.
 
 require_relative 'models/base_model'
-
-# Include all models
-
-Dir[File.join(File::dirname(__FILE__), "models", "*.rb")].each do |model|
-  next if model =~ /base_model\.rb$/
-  require model
-end
+require_relative 'models/address'
+require_relative 'models/blob'
+require_relative 'models/bucket'
+require_relative 'models/firewall'
+require_relative 'models/firewall_rule'
+require_relative 'models/hardware_profile'
+require_relative 'models/image'
+require_relative 'models/instance'
+require_relative 'models/instance_address'
+require_relative 'models/instance_profile'
+require_relative 'models/key'
+require_relative 'models/load_balancer'
+require_relative 'models/metric'
+require_relative 'models/provider'
+require_relative 'models/realm'
+require_relative 'models/state_machine'
+require_relative 'models/storage_snapshot'
+require_relative 'models/storage_volume'
diff --git a/server/lib/deltacloud/models/state_machine.rb b/server/lib/deltacloud/models/state_machine.rb
index 19fb9f2..cbdaf4a 100644
--- a/server/lib/deltacloud/models/state_machine.rb
+++ b/server/lib/deltacloud/models/state_machine.rb
@@ -18,7 +18,10 @@ module Deltacloud
   class StateMachine
 
     attr_reader :states
-    def initialize(&block)
+
+    def initialize(opts={}, &block)
+      @all_states = opts[:all_states]
+      @all_actions = opts[:all_actions]
       @states  = []
       instance_eval &block if block
     end
@@ -32,6 +35,9 @@ module Deltacloud
     end
 
     def state(name)
+      unless valid_state_name?(name)
+        raise "State '#{name}' not in list of allowed states"
+      end
       state = @states.find{|e| e.name == name.to_sym}
       if ( state.nil? )
         state = State.new( self, name.to_sym )
@@ -40,6 +46,14 @@ module Deltacloud
       state
     end
 
+    def valid_state_name?(name)
+      @all_states.nil? || @all_states.include?(name.to_sym)
+    end
+
+    def valid_action_name?(name)
+      @all_actions.nil? || @all_actions.include?(name.to_sym)
+    end
+
     def method_missing(sym,*args)
       return state( sym ) if ( args.empty? )
       super( sym, *args )
@@ -90,6 +104,9 @@ module Deltacloud
       end
 
       def on(action)
+        unless @machine.valid_action_name?(action)
+          raise "Action '#{action}' not in list of allowed actions"
+        end
         @action = action
       end
 
-- 
1.7.10.1


Mime
View raw message