Module: Deltacloud

Defined in:
lib/db.rb,
lib/db/entity.rb,
lib/db/provider.rb,
lib/ec2/helpers.rb,
lib/deltacloud/api.rb,
lib/deltacloud_rack.rb,
lib/deltacloud/runner.rb,
lib/deltacloud/server.rb,
lib/db/volume_template.rb,
lib/deltacloud/drivers.rb,
lib/deltacloud/version.rb,
lib/db/address_template.rb,
lib/db/machine_template.rb,
lib/deltacloud/collections.rb,
lib/db/volume_configuration.rb,
lib/deltacloud/drivers/features.rb,
lib/cimi/helpers/database_helper.rb,
lib/deltacloud/drivers/exceptions.rb,
lib/deltacloud/drivers/base_driver.rb,
lib/deltacloud/models/state_machine.rb,
lib/deltacloud/drivers/ec2/ec2_driver.rb,
lib/deltacloud/drivers/sbc/sbc_client.rb,
lib/deltacloud/drivers/sbc/sbc_driver.rb,
lib/deltacloud/models/hardware_profile.rb,
lib/deltacloud/drivers/fgcp/fgcp_client.rb,
lib/deltacloud/drivers/fgcp/fgcp_driver.rb,
lib/deltacloud/drivers/azure/azure_driver.rb,
lib/deltacloud/drivers/rhevm/rhevm_driver.rb,
lib/deltacloud/drivers/condor/condor_driver.rb,
lib/deltacloud/drivers/gogrid/gogrid_driver.rb,
lib/deltacloud/drivers/google/google_driver.rb,
lib/deltacloud/drivers/openstack/openstack_driver.rb,
lib/deltacloud/drivers/rackspace/rackspace_driver.rb,
lib/deltacloud/drivers/terremark/terremark_driver.rb,
lib/deltacloud/drivers/arubacloud/arubacloud_driver.rb,
lib/deltacloud/drivers/eucalyptus/eucalyptus_driver.rb,
lib/deltacloud/drivers/opennebula/opennebula_driver.rb,
lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb,
lib/deltacloud/drivers/digitalocean/digitalocean_driver.rb

Overview

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.

Defined Under Namespace

Modules: Collections, Database, Drivers, EC2, Exceptions, Features, Helpers, Runner Classes: API, BaseDriver, HardwareProfile, IndexApp, Library, Server, StateMachine

Constant Summary collapse

DATABASE_LOCATION =
ENV['DATABASE_LOCATION'] ||
'sqlite://'+File.join('/', 'var', 'tmp', "deltacloud-mock-#{ENV['USER']}", 'db.sqlite')
API_VERSION =
'1.1.1'
CIMI_API_VERSION =
'1.0.1'

Class Method Summary collapse

Class Method Details

.[](frontend = :deltacloud) ⇒ Object



35
36
37
# File 'lib/deltacloud_rack.rb', line 35

def self.[](frontend=:deltacloud)
  config[frontend.to_sym]
end

.collection_namesObject



21
22
23
# File 'lib/deltacloud/collections.rb', line 21

def self.collection_names
  @collections.map { |c| c.collection_name }
end

.collectionsObject



25
26
27
# File 'lib/deltacloud/collections.rb', line 25

def self.collections
  @collections ||= []
end

.configObject



25
26
27
# File 'lib/deltacloud_rack.rb', line 25

def self.config
  @config ||= {}
end

.configure(frontend = :deltacloud, &block) ⇒ Object



29
30
31
32
33
# File 'lib/deltacloud_rack.rb', line 29

def self.configure(frontend=:deltacloud, &block)
  frontend = frontend.to_sym
  config[frontend] ||= Server.new(frontend, &block)
  self
end

.database(opts = {}) ⇒ Object



36
37
38
39
# File 'lib/db.rb', line 36

def self.database(opts={})
  opts[:logger] = ::Logger.new($stdout) if ENV['API_VERBOSE']
  @db ||=  Sequel.connect(DATABASE_LOCATION, opts)
end

.default_frontend(frontend = nil) ⇒ Object



54
55
56
57
58
# File 'lib/deltacloud_rack.rb', line 54

def self.default_frontend(frontend=nil)
  @default_frontend = frontend unless frontend.nil?
  raise "Could not determine default API frontend" if @default_frontend.nil? and !config[:deltacloud]
  @default_frontend || config[:deltacloud]
end

.driversObject



71
72
73
# File 'lib/deltacloud/api.rb', line 71

def self.drivers
  Drivers.driver_config
end

.enabled_frontendsObject



46
47
48
# File 'lib/deltacloud_rack.rb', line 46

def self.enabled_frontends
  @config.keys.select { |k| frontend_required?(k) }.map { |f| Deltacloud[f] }
end

.frontend_required?(frontend) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/deltacloud_rack.rb', line 50

def self.frontend_required?(frontend)
  true unless Deltacloud[frontend].klass.kind_of? String
end

.initialize_databaseObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/db.rb', line 41

def self.initialize_database
  db = database

  db.create_table?(:providers) {
    primary_key :id

    column :driver, :string, { :null => false }
    column :url, :string
    index [ :url, :driver ] if !db.table_exists?(:providers)
  }

  db.create_table?(:entities) {
    primary_key :id

    unless db.table_exists?(:entities)
      foreign_key :provider_id, :providers, { :index => true, :null => false }
    end

    column :created_at, :timestamp

    # Base
    unless db.table_exists?(:entities)
      column :model, :string, { :index => true, :null => false, :default => 'entity' }
    end

    # Map Entity to Deltacloud model
    # (like: Machine => Instance)
    column :be_kind, :string
    column :be_id, :string

    # Entity
    column :name, :string
    column :description, :string
    column :ent_properties, :string, { :text => true }


    column :machine_config, :string
    column :machine_image, :string

    column :network, :string
    column :ip, :string
    column :hostname, :string
    column :allocation, :string
    column :default_gateway, :string
    column :dns, :string
    column :protocol, :string
    column :mask, :string

    column :format, :string
    column :capacity, :string

    column :volume_config, :string
    column :volume_image, :string
  }
end

.new(driver_name, opts = {}, &block) ⇒ Object



127
128
129
# File 'lib/deltacloud/api.rb', line 127

def self.new(driver_name, opts={}, &block)
  Library.new(driver_name, opts, &block)
end

.require_frontend!(frontend = :deltacloud) ⇒ Object



39
40
41
42
43
44
# File 'lib/deltacloud_rack.rb', line 39

def self.require_frontend!(frontend=:deltacloud)
  frontend = frontend.to_sym
  return false if frontend_required?(frontend)
  require_relative File.join(frontend.to_s, 'server.rb')
  Deltacloud[frontend].klass eval('::'+Deltacloud[frontend].klass)
end

.test_environment?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/db.rb', line 18

def self.test_environment?
  ENV['RACK_ENV'] == 'test'
end