class Deltacloud::BaseDriver

Constants

MEMBER_SHOW_METHODS
STATE_MACHINE_OPTS

Public Class Methods

constraints(opts={}) click to toggle source
# File lib/deltacloud/drivers/base_driver.rb, line 51
def self.constraints(opts={})
  if opts[:collection] and opts[:feature]
    return [] unless @constraints.has_key? opts[:collection]
    return @constraints[opts[:collection]][opts[:feature]]
  end
  @constraints ||= {}
end
define_hardware_profile(profile_id, &block) click to toggle source
# File lib/deltacloud/drivers/base_driver.rb, line 67
def self.define_hardware_profile(profile_id, &block)
  @hardware_profiles ||= []
  hw_profile = @hardware_profiles.find{|e| e.id == profile_id }
  return if hw_profile
  hw_profile = ::Deltacloud::HardwareProfile.new(profile_id, &block )
  @hardware_profiles << hw_profile
  hw_profile.params
end
define_instance_states(&block) click to toggle source
# File lib/deltacloud/drivers/base_driver.rb, line 121
def self.define_instance_states(&block)
  machine = ::Deltacloud::StateMachine.new(STATE_MACHINE_OPTS, &block)
  @instance_state_machine = machine
end
driver_name() click to toggle source
# File lib/deltacloud/drivers/base_driver.rb, line 33
def self.driver_name
  name.split('::').last.gsub('Driver', '').downcase
end
feature(collection, feature_name) { || ... } click to toggle source
# File lib/deltacloud/drivers/base_driver.rb, line 42
def self.feature(collection, feature_name)
  return if has_feature?(collection, feature_name)
  constraints[collection] ||= {}
  constraints[collection][feature_name] ||= {}
  constraints[collection][feature_name].merge!(yield) if block_given?
  features[collection] ||= []
  features[collection] << feature_name
end
features() click to toggle source
# File lib/deltacloud/drivers/base_driver.rb, line 37
def self.features
  @features ||= {}
end
hardware_profiles() click to toggle source
# File lib/deltacloud/drivers/base_driver.rb, line 76
def self.hardware_profiles
  @hardware_profiles ||= []
  @hardware_profiles
end
has_feature?(collection, feature_name) click to toggle source
# File lib/deltacloud/drivers/base_driver.rb, line 59
def self.has_feature?(collection, feature_name)
  features.has_key?(collection) and features[collection].include?(feature_name)
end
instance_state_machine() click to toggle source
# File lib/deltacloud/drivers/base_driver.rb, line 126
def self.instance_state_machine
  @instance_state_machine
end

Public Instance Methods

address(credentials, opts={}) click to toggle source
# File lib/deltacloud/drivers/base_driver.rb, line 254
def address(credentials, opts={})
  addresses(credentials, opts).first if has_capability?(:addresses)
end
api_provider() click to toggle source
# File lib/deltacloud/drivers/base_driver.rb, line 277
def api_provider
  Thread.current[:provider] || ENV['API_PROVIDER']
end
blob(credentials, opts = {}) click to toggle source
# File lib/deltacloud/drivers/base_driver.rb, line 242
def blob(credentials, opts = {})
  blobs(credentials, opts).first if has_capability?(:blobs)
end
bucket(credentials, opts = {}) click to toggle source
# File lib/deltacloud/drivers/base_driver.rb, line 237
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/drivers/base_driver.rb, line 273
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/drivers/base_driver.rb, line 283
def configured_providers
  []
end
filter_hardware_profiles(profiles, opts) click to toggle source
# File lib/deltacloud/drivers/base_driver.rb, line 91
def filter_hardware_profiles(profiles, opts)
  if opts
    if v = opts[:architecture]
      profiles = profiles.select { |hwp| hwp.include?(:architecture, v) }
    end
    if v = opts[:id]
      profiles = profiles.select { |hwp| hwp.id == v }
    end
  end
  profiles
end
filter_on(collection, attribute, opts) click to toggle source
# File lib/deltacloud/drivers/base_driver.rb, line 262
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, profile_id, image_id) click to toggle source
# File lib/deltacloud/drivers/base_driver.rb, line 103
def find_hardware_profile(credentials, profile_id, image_id)
  hwp = nil
  if name
    unless hwp = hardware_profile(credentials, profile_id)
      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/drivers/base_driver.rb, line 250
def firewall(credentials, opts={})
  firewalls(credentials, opts).first if has_capability?(:firewalls)
end
hardware_profile(credentials, profile_id) click to toggle source
# File lib/deltacloud/drivers/base_driver.rb, line 86
def hardware_profile(credentials, profile_id)
  profile_id = profile_id[:id] if profile_id.kind_of? Hash
  hardware_profiles(credentials, :id => profile_id).first
end
hardware_profiles(credentials, opts = {}) click to toggle source
# File lib/deltacloud/drivers/base_driver.rb, line 81
def hardware_profiles(credentials, opts = {})
  results = self.class.hardware_profiles
  filter_hardware_profiles(results, opts)
end
has_capability?(method) click to toggle source
# File lib/deltacloud/drivers/base_driver.rb, line 145
def has_capability?(method)
  method = (RUBY_VERSION =~ %r^1\.9/) ? method : method.to_s
  # Prevent has_capability fail when driver is inherited from another
  # driver, like Eucalyptus
  superclass_methods = self.class.superclass.name == 'Deltacloud::BaseDriver' ?
    self.class.superclass.instance_methods : []
  (self.class.instance_methods - superclass_methods).include? method
end
image(credentials, opts) click to toggle source
# File lib/deltacloud/drivers/base_driver.rb, line 221
def image(credentials, opts)
  images(credentials, opts).first if has_capability?(:images)
end
instance(credentials, opts) click to toggle source
# File lib/deltacloud/drivers/base_driver.rb, line 225
def instance(credentials, opts)
  instances(credentials, opts).first if has_capability?(:instances)
end
instance_actions_for(state) click to toggle source
# File lib/deltacloud/drivers/base_driver.rb, line 134
def instance_actions_for(state)
  actions = []
  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/drivers/base_driver.rb, line 130
def instance_state_machine
  self.class.instance_state_machine
end
key(credentials, opts=nil) click to toggle source
# File lib/deltacloud/drivers/base_driver.rb, line 246
def key(credentials, opts=nil)
  keys(credentials, opts).first if has_capability?(:keys)
end
name() click to toggle source
# File lib/deltacloud/drivers/base_driver.rb, line 63
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/drivers/base_driver.rb, line 217
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/drivers/base_driver.rb, line 233
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/drivers/base_driver.rb, line 229
def storage_volume(credentials, opts)
  storage_volumes(credentials, opts).first if has_capability?(:storage_volumes)
end
supported_collections(credentials) { |c| ... } click to toggle source
# File lib/deltacloud/drivers/base_driver.rb, line 154
def supported_collections(credentials)
  collection_arr = []
  Deltacloud::Collections.deltacloud_modules.each do |m|
    m.collections.each do |c|
      # Get the required capability for the :index operation (like 'realms' or 'instance_state_machine')
      index_operation_capability = c.operation(:index).required_capability
      # Then use this capability to check if the 'capability' lambda defined
      # for the Sinatra::Base class evaluate to 'true'
      next if m.settings.respond_to?(:capability) and !m.settings.capability(index_operation_capability)
      yield c if block_given?
      collection_arr << c
    end
  end
  collection_arr
end