Declare a new feature
# File lib/deltacloud/base_driver/features.rb, line 117 def self.declare_feature(collection, name, &block) feature_decls[collection] ||= [] raise DuplicateFeatureDeclError if feature_decl_for(collection, name) feature_decls[collection] << FeatureDecl.new(name, &block) end
# File lib/deltacloud/base_driver/base_driver.rb, line 33 def self.define_hardware_profile(name,&block) @hardware_profiles ||= [] hw_profile = @hardware_profiles.find{|e| e.name == name} return if hw_profile hw_profile = ::Deltacloud::HardwareProfile.new( name, &block ) @hardware_profiles << hw_profile hw_params = hw_profile.params unless hw_params.empty? feature :instances, :hardware_profiles do decl.operation(:create) { add_params(hw_params) } end end end
# File lib/deltacloud/base_driver/base_driver.rb, line 92 def self.define_instance_states(&block) machine = ::Deltacloud::StateMachine.new(&block) @instance_state_machine = machine end
# File lib/deltacloud/base_driver/base_driver.rb, line 29 def self.exceptions(&block) ExceptionHandler::exceptions(&block) end
Declare in a driver that it supports a specific feature
The same feature can be declared multiple times in a driver, so that it can be changed successively by passing in different blocks.
# File lib/deltacloud/base_driver/features.rb, line 131 def self.feature(collection, name, &block) features[collection] ||= [] if f = features[collection].find { |f| f.name == name } f.instance_eval(&block) if block_given? return f end unless decl = feature_decl_for(collection, name) raise UndeclaredFeatureError, "No feature #{name} for #{collection}" end features[collection] << Feature.new(decl, &block) end
# File lib/deltacloud/base_driver/features.rb, line 107 def self.feature_decl_for(collection, name) decls = feature_decls[collection] if decls decls.find { |dcl| dcl.name == name } else nil end end
# File lib/deltacloud/base_driver/features.rb, line 103 def self.feature_decls @@feature_decls ||= {} end
# File lib/deltacloud/base_driver/features.rb, line 123 def self.features @features ||= {} end
# File lib/deltacloud/base_driver/base_driver.rb, line 234 def api_provider Thread.current[:provider] || ENV['API_PROVIDER'] end
# File lib/deltacloud/base_driver/base_driver.rb, line 188 def blob(credentials, opts = {}) blobs(credentials, opts).first if has_capability?(:blobs) end
# File lib/deltacloud/base_driver/base_driver.rb, line 183 def bucket(credentials, opts = {}) #list of objects within bucket buckets(credentials, opts).first if has_capability?(:buckets) end
# File lib/deltacloud/base_driver/base_driver.rb, line 230 def catched_exceptions_list { :error => [], :auth => [], :glob => [] } end
Return an array of the providers statically configured in the driver's YAML file
# File lib/deltacloud/base_driver/base_driver.rb, line 240 def configured_providers [] end
# File lib/deltacloud/base_driver/features.rb, line 143 def features(collection) self.class.features[collection] || [] end
# File lib/deltacloud/base_driver/features.rb, line 147 def features_for_operation(collection, operation) features(collection).select do |f| f.operations.detect { |o| o.name == operation } end end
# File lib/deltacloud/base_driver/base_driver.rb, line 61 def filter_hardware_profiles(profiles, opts) if opts if v = opts[:architecture] profiles = profiles.select { |hwp| hwp.include?(:architecture, v) } end # As a request param, we call 'name' 'id' if v = opts[:id] profiles = profiles.select { |hwp| hwp.name == v } end end profiles end
# File lib/deltacloud/base_driver/base_driver.rb, line 211 def filter_on(collection, attribute, opts) return collection if opts.nil? return collection if opts[attribute].nil? filter = opts[attribute] if ( filter.is_a?( Array ) ) return collection.select{|e| filter.include?( e.send(attribute) ) } else return collection.select{|e| filter == e.send(attribute) } end end
# File lib/deltacloud/base_driver/base_driver.rb, line 74 def find_hardware_profile(credentials, name, image_id) hwp = nil if name unless hwp = hardware_profiles(credentials, :id => name).first raise BackendError.new(400, "bad-hardware-profile-name", "Hardware profile '#{name}' does not exist", nil) end else unless image = image(credentials, :id=>image_id) raise BackendError.new(400, "bad-image-id", "Image with ID '#{image_id}' does not exist", nil) end hwp = hardware_profiles(credentials, :architecture=>image.architecture).first end return hwp end
# File lib/deltacloud/base_driver/base_driver.rb, line 196 def firewall(credentials, opts={}) firewalls(credentials, opts).first if has_capability?(:firewalls) end
# File lib/deltacloud/base_driver/base_driver.rb, line 57 def hardware_profile(credentials, name) hardware_profiles(credentials, :id => name).first end
# File lib/deltacloud/base_driver/base_driver.rb, line 52 def hardware_profiles(credentials, opts = nil) results = self.class.hardware_profiles filter_hardware_profiles(results, opts) end
# File lib/deltacloud/base_driver/base_driver.rb, line 203 def has_capability?(capability) if MEMBER_SHOW_METHODS.include?(capability.to_sym) has_capability?(capability.to_s.pluralize) else respond_to?(capability) end end
# File lib/deltacloud/base_driver/base_driver.rb, line 226 def has_collection?(collection) supported_collections.include?(collection) end
# File lib/deltacloud/base_driver/base_driver.rb, line 167 def image(credentials, opts) images(credentials, opts).first if has_capability?(:images) end
# File lib/deltacloud/base_driver/base_driver.rb, line 171 def instance(credentials, opts) instances(credentials, opts).first if has_capability?(:instances) end
# File lib/deltacloud/base_driver/base_driver.rb, line 105 def instance_actions_for(state) actions = [] state_key = state.downcase.to_sym states = instance_state_machine.states() current_state = states.find{|e| e.name == state.underscore.to_sym } if ( current_state ) actions = current_state.transitions.collect{|e|e.action} actions.reject!{|e| e.nil?} end actions end
# File lib/deltacloud/base_driver/base_driver.rb, line 101 def instance_state_machine self.class.instance_state_machine end
# File lib/deltacloud/base_driver/base_driver.rb, line 192 def key(credentials, opts=nil) keys(credentials, opts).first if has_capability?(:keys) end
# File lib/deltacloud/base_driver/base_driver.rb, line 25 def name self.class.name.split('::').last.gsub('Driver', '').downcase end
Capabilities
The rabbit dsl supports declaring a capability that is required in the backend driver for the call to succeed. A driver can provide a capability by implementing the method with the same name as the capability. Below is a list of the capabilities as the expected method signatures.
Following the capability list are the resource member show methods. They each require that the corresponding collection method be defined
TODO: standardize all of these to the same signature (credentials, opts)
def realms(credentials, opts=nil)
def images(credentials, ops)
def instances(credentials, ops) def create_instance(credentials, image_id, opts) def start_instance(credentials, id) def stop_instance(credentials, id) def reboot_instance(credentials, id)
def storage_volumes(credentials, ops)
def storage_snapshots(credentials, ops)
def buckets(credentials, opts = nil) def create_bucket(credentials, name, opts=nil) def delete_bucket(credentials, name, opts=nil)
def blobs(credentials, opts = nil) def blob_data(credentials, bucket_id, blob_id, opts) def create_blob(credentials, bucket_id, blob_id, blob_data, opts=nil) def delete_blob(credentials, bucket_id, blob_id, opts=nil)
def keys(credentials, opts) def create_key(credentials, opts) def destroy_key(credentials, opts)
def firewalls(credentials, opts) def create_firewall(credentials, opts) def delete_firewall(credentials, opts) def create_firewall_rule(credentials, opts) def delete_firewall_rule(credentials, opts) def providers(credentials)
# File lib/deltacloud/base_driver/base_driver.rb, line 163 def realm(credentials, opts) realms = realms(credentials, opts).first if has_capability?(:realms) end
# File lib/deltacloud/base_driver/base_driver.rb, line 179 def storage_snapshot(credentials, opts) storage_snapshots(credentials, opts).first if has_capability?(:storage_snapshots) end
Generated with the Darkfish Rdoc Generator 2.