Module: Deltacloud
- Extended by:
- CollectionMethods
- Included in:
- BaseDriver, Drivers::Mock::Client
- 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/models/key.rb,
lib/deltacloud/collections.rb,
lib/deltacloud/models/blob.rb,
lib/db/volume_configuration.rb,
lib/deltacloud/models/image.rb,
lib/deltacloud/models/realm.rb,
lib/deltacloud/models/bucket.rb,
lib/deltacloud/models/metric.rb,
lib/deltacloud/models/address.rb,
lib/deltacloud/models/firewall.rb,
lib/deltacloud/models/instance.rb,
lib/deltacloud/models/provider.rb,
lib/deltacloud/drivers/features.rb,
lib/cimi/helpers/database_helper.rb,
lib/deltacloud/models/base_model.rb,
lib/deltacloud/drivers/exceptions.rb,
lib/deltacloud/drivers/base_driver.rb,
lib/deltacloud/models/firewall_rule.rb,
lib/deltacloud/models/load_balancer.rb,
lib/deltacloud/models/state_machine.rb,
lib/deltacloud/models/storage_volume.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/models/instance_address.rb,
lib/deltacloud/models/instance_profile.rb,
lib/deltacloud/models/storage_snapshot.rb,
lib/deltacloud/drivers/fgcp/fgcp_client.rb,
lib/deltacloud/drivers/fgcp/fgcp_driver.rb,
lib/deltacloud/helpers/collection_helper.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: CollectionHelper, CollectionMethods, Collections, Database, Drivers, EC2, Exceptions, Features, Helpers, Runner Classes: API, Address, BaseDriver, BaseModel, Blob, Bucket, Firewall, FirewallRule, HardwareProfile, Image, IndexApp, Instance, InstanceAddress, InstanceProfile, Key, Library, LoadBalancer, Metric, Provider, Realm, Server, StateMachine, StorageSnapshot, StorageVolume
Constant Summary collapse
- API_VERSION =
'1.1.2'
- CIMI_API_VERSION =
'1.0.1'
Class Method Summary collapse
- .[](frontend = :deltacloud) ⇒ Object
- .config ⇒ Object
- .configure(frontend = :deltacloud, &block) ⇒ Object
- .connect(location) ⇒ Object
- .database ⇒ Object
- .default_frontend(frontend = nil) ⇒ Object
- .drivers ⇒ Object
- .enabled_frontends ⇒ Object
- .frontend_required?(frontend) ⇒ Boolean
- .frontends ⇒ Object
- .generate_routes ⇒ Object
- .initialize_database(location) ⇒ Object
- .need_database? ⇒ Boolean
- .new(driver_name, opts = {}, &block) ⇒ Object
- .require_frontend!(frontend = :deltacloud) ⇒ Object
Methods included from CollectionMethods
collection_exists?, collection_names, collections
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 |
.config ⇒ Object
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 |
.connect(location) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/db.rb', line 18 def self.connect(location) if ENV['API_VERBOSE'] if Deltacloud.respond_to? :config logger = Deltacloud.config[:cimi].logger else logger = ::Logger.new($stdout) end end @db = Sequel.connect(location, :logger => logger) end |
.database ⇒ Object
29 30 31 |
# File 'lib/db.rb', line 29 def self.database @db 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 |
.drivers ⇒ Object
72 73 74 |
# File 'lib/deltacloud/api.rb', line 72 def self.drivers Drivers.driver_config end |
.enabled_frontends ⇒ Object
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
50 51 52 |
# File 'lib/deltacloud_rack.rb', line 50 def self.frontend_required?(frontend) true unless Deltacloud[frontend].klass.kind_of? String end |
.frontends ⇒ Object
73 74 75 76 |
# File 'lib/deltacloud_rack.rb', line 73 def self.frontends ENV['API_FRONTEND'] ||= 'deltacloud' ENV['API_FRONTEND'].split(',') end |
.generate_routes ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/deltacloud_rack.rb', line 60 def self.generate_routes frontends.inject({}) do |result, frontend| frontend = frontend.strip if Deltacloud[frontend.to_sym].nil? puts "ERROR: Unknown frontend (#{frontend}). Valid values are 'deltacloud,cimi,ec2'" exit(1) end Deltacloud[frontend.to_sym].require! result[Deltacloud[frontend].root_url] = Deltacloud[frontend].klass result end end |
.initialize_database(location) ⇒ Object
33 34 35 36 37 38 39 40 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 |
# File 'lib/db.rb', line 33 def self.initialize_database(location) db = connect(location) 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 } db end |
.need_database? ⇒ Boolean
78 79 80 |
# File 'lib/deltacloud_rack.rb', line 78 def self.need_database? frontends.include?('cimi') || ENV['RACK_ENV'] == 'test' end |
.new(driver_name, opts = {}, &block) ⇒ Object
128 129 130 |
# File 'lib/deltacloud/api.rb', line 128 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 |