Parent

Included Modules

Class/Module Index [+]

Quicksearch

Deltacloud::BaseDriver

Public Class Methods

declare_feature(collection, name, &block) click to toggle source

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
define_hardware_profile(name,&block) click to toggle source
# 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
define_instance_states(&block) click to toggle source
# 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
exceptions(&block) click to toggle source
# File lib/deltacloud/base_driver/base_driver.rb, line 29
def self.exceptions(&block)
  ExceptionHandler::exceptions(&block)
end
feature(collection, name, &block) click to toggle source

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
feature_decl_for(collection, name) click to toggle source
# 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
feature_decls() click to toggle source
# File lib/deltacloud/base_driver/features.rb, line 103
def self.feature_decls
  @@feature_decls ||= {}
end
features() click to toggle source
# File lib/deltacloud/base_driver/features.rb, line 123
def self.features
  @features ||= {}
end
hardware_profiles() click to toggle source
# File lib/deltacloud/base_driver/base_driver.rb, line 47
def self.hardware_profiles
  @hardware_profiles ||= []
  @hardware_profiles
end
instance_state_machine() click to toggle source
# File lib/deltacloud/base_driver/base_driver.rb, line 97
def self.instance_state_machine
  @instance_state_machine
end

Public Instance Methods

api_provider() click to toggle source
# File lib/deltacloud/base_driver/base_driver.rb, line 234
def api_provider
  Thread.current[:provider] || ENV['API_PROVIDER']
end
blob(credentials, opts = {}) click to toggle source
# File lib/deltacloud/base_driver/base_driver.rb, line 188
def blob(credentials, opts = {})
  blobs(credentials, opts).first if has_capability?(:blobs)
end
bucket(credentials, opts = {}) click to toggle source
# 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
catched_exceptions_list() click to toggle source
# File lib/deltacloud/base_driver/base_driver.rb, line 230
def catched_exceptions_list
  { :error => [], :auth => [], :glob => [] }
end
configured_providers() click to toggle source

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
features(collection) click to toggle source
# File lib/deltacloud/base_driver/features.rb, line 143
def features(collection)
  self.class.features[collection] || []
end
features_for_operation(collection, operation) click to toggle source
# 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
filter_hardware_profiles(profiles, opts) click to toggle source
# 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
filter_on(collection, attribute, opts) click to toggle source
# 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
find_hardware_profile(credentials, name, image_id) click to toggle source
# 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
firewall(credentials, opts={}) click to toggle source
# File lib/deltacloud/base_driver/base_driver.rb, line 196
def firewall(credentials, opts={})
  firewalls(credentials, opts).first if has_capability?(:firewalls)
end
hardware_profile(credentials, name) click to toggle source
# File lib/deltacloud/base_driver/base_driver.rb, line 57
def hardware_profile(credentials, name)
  hardware_profiles(credentials, :id => name).first
end
hardware_profiles(credentials, opts = nil) click to toggle source
# 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
has_capability?(capability) click to toggle source
# 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
has_collection?(collection) click to toggle source
# File lib/deltacloud/base_driver/base_driver.rb, line 226
def has_collection?(collection)
  supported_collections.include?(collection)
end
image(credentials, opts) click to toggle source
# File lib/deltacloud/base_driver/base_driver.rb, line 167
def image(credentials, opts)
  images(credentials, opts).first if has_capability?(:images)
end
instance(credentials, opts) click to toggle source
# File lib/deltacloud/base_driver/base_driver.rb, line 171
def instance(credentials, opts)
  instances(credentials, opts).first if has_capability?(:instances)
end
instance_actions_for(state) click to toggle source
# 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
instance_state_machine() click to toggle source
# File lib/deltacloud/base_driver/base_driver.rb, line 101
def instance_state_machine
  self.class.instance_state_machine
end
key(credentials, opts=nil) click to toggle source
# File lib/deltacloud/base_driver/base_driver.rb, line 192
def key(credentials, opts=nil)
  keys(credentials, opts).first if has_capability?(:keys)
end
name() click to toggle source
# File lib/deltacloud/base_driver/base_driver.rb, line 25
def name
  self.class.name.split('::').last.gsub('Driver', '').downcase
end
realm(credentials, opts) click to toggle source
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
storage_snapshot(credentials, opts) click to toggle source
# 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
storage_volume(credentials, opts) click to toggle source
# File lib/deltacloud/base_driver/base_driver.rb, line 175
def storage_volume(credentials, opts)
  storage_volumes(credentials, opts).first if has_capability?(:storage_volumes)
end
supported_collections() click to toggle source
# File lib/deltacloud/base_driver/base_driver.rb, line 222
def supported_collections
  DEFAULT_COLLECTIONS
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.