deltacloud-core 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +40 -28
- data/bin/deltacloud-db-upgrade +24 -0
- data/bin/deltacloudd +20 -9
- data/config.ru +12 -53
- data/db/migrations/1_add_realm_to_machine_template.rb +23 -0
- data/deltacloud-core.gemspec +11 -5
- data/lib/cimi/collections.rb +4 -31
- data/lib/cimi/collections/address_templates.rb +2 -5
- data/lib/cimi/collections/addresses.rb +2 -5
- data/lib/cimi/collections/base.rb +18 -6
- data/lib/cimi/collections/credentials.rb +2 -5
- data/lib/cimi/collections/machine_images.rb +2 -1
- data/lib/cimi/collections/machine_templates.rb +2 -5
- data/lib/cimi/collections/machines.rb +6 -9
- data/lib/cimi/collections/network_ports.rb +3 -3
- data/lib/cimi/collections/networks.rb +5 -8
- data/lib/cimi/collections/system_templates.rb +72 -0
- data/lib/cimi/collections/systems.rb +194 -0
- data/lib/cimi/collections/volume_configurations.rb +1 -1
- data/lib/cimi/collections/volume_images.rb +2 -1
- data/lib/cimi/collections/volume_templates.rb +3 -2
- data/lib/cimi/collections/volumes.rb +2 -2
- data/lib/cimi/dependencies.rb +0 -2
- data/lib/cimi/helpers/cimi_helper.rb +12 -57
- data/lib/cimi/helpers/database_helper.rb +0 -4
- data/lib/cimi/models.rb +25 -14
- data/lib/cimi/models/address.rb +4 -31
- data/lib/cimi/models/address_create.rb +51 -0
- data/lib/cimi/models/address_template.rb +8 -52
- data/lib/cimi/models/address_template_create.rb +44 -0
- data/lib/cimi/models/base.rb +44 -6
- data/lib/cimi/models/cloud_entry_point.rb +1 -1
- data/lib/cimi/models/credential.rb +1 -1
- data/lib/cimi/models/credential_create.rb +46 -0
- data/lib/cimi/models/credential_template.rb +24 -0
- data/lib/cimi/models/machine.rb +1 -71
- data/lib/cimi/models/machine_configuration.rb +3 -3
- data/lib/cimi/models/machine_create.rb +49 -0
- data/lib/cimi/models/machine_image.rb +2 -25
- data/lib/cimi/models/machine_image_create.rb +41 -0
- data/lib/cimi/models/machine_template.rb +14 -34
- data/lib/cimi/models/machine_template_create.rb +33 -0
- data/lib/cimi/models/network.rb +0 -38
- data/lib/cimi/models/network_create.rb +43 -0
- data/lib/cimi/models/network_port.rb +17 -17
- data/lib/cimi/models/network_template.rb +2 -3
- data/lib/cimi/models/resource.rb +22 -3
- data/lib/cimi/models/schema.rb +94 -8
- data/lib/cimi/models/system.rb +67 -0
- data/lib/cimi/models/system_template.rb +63 -0
- data/lib/cimi/models/volume.rb +2 -42
- data/lib/cimi/models/volume_configuration.rb +4 -4
- data/lib/cimi/models/volume_create.rb +58 -0
- data/lib/cimi/models/volume_image.rb +8 -17
- data/lib/cimi/models/volume_image_create.rb +47 -0
- data/lib/cimi/models/volume_template.rb +6 -19
- data/lib/cimi/models/volume_template_create.rb +33 -0
- data/lib/db.rb +14 -22
- data/lib/db/volume_template.rb +1 -1
- data/lib/deltacloud/api.rb +6 -5
- data/lib/deltacloud/collections.rb +4 -27
- data/lib/deltacloud/collections/base.rb +4 -0
- data/lib/deltacloud/collections/images.rb +1 -1
- data/lib/deltacloud/collections/instances.rb +2 -2
- data/lib/deltacloud/core_ext/array.rb +1 -0
- data/lib/deltacloud/core_ext/integer.rb +13 -9
- data/lib/deltacloud/core_ext/string.rb +45 -28
- data/lib/deltacloud/drivers/arubacloud/arubacloud_driver.rb +0 -9
- data/lib/deltacloud/drivers/base_driver.rb +45 -16
- data/lib/deltacloud/drivers/digitalocean/digitalocean_driver.rb +78 -8
- data/lib/deltacloud/drivers/ec2/ec2_driver.rb +13 -9
- data/lib/deltacloud/drivers/fgcp/fgcp_client.rb +44 -0
- data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +164 -90
- data/lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb +74 -0
- data/lib/deltacloud/drivers/mock/data/instances/inst0.yml +3 -3
- data/lib/deltacloud/drivers/mock/data/instances/inst1.yml +3 -3
- data/lib/deltacloud/drivers/mock/data/instances/inst2.yml +3 -3
- data/lib/deltacloud/drivers/mock/mock_client.rb +17 -1
- data/lib/deltacloud/drivers/mock/mock_driver.rb +161 -204
- data/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb +80 -0
- data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +6 -1
- data/lib/deltacloud/drivers/openstack/openstack_driver.rb +61 -68
- data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +0 -9
- data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +11 -6
- data/lib/deltacloud/drivers/terremark/terremark_driver.rb +0 -8
- data/lib/deltacloud/drivers/vsphere/vsphere_client.rb +11 -4
- data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +0 -12
- data/lib/deltacloud/helpers/collection_helper.rb +106 -0
- data/lib/deltacloud/helpers/deltacloud_helper.rb +12 -8
- data/lib/deltacloud/models/address.rb +19 -17
- data/lib/deltacloud/models/base_model.rb +29 -26
- data/lib/deltacloud/models/blob.rb +22 -20
- data/lib/deltacloud/models/bucket.rb +21 -16
- data/lib/deltacloud/models/firewall.rb +18 -16
- data/lib/deltacloud/models/firewall_rule.rb +22 -20
- data/lib/deltacloud/models/image.rb +29 -28
- data/lib/deltacloud/models/instance.rb +92 -94
- data/lib/deltacloud/models/instance_address.rb +42 -40
- data/lib/deltacloud/models/instance_profile.rb +28 -26
- data/lib/deltacloud/models/key.rb +47 -45
- data/lib/deltacloud/models/load_balancer.rb +32 -31
- data/lib/deltacloud/models/metric.rb +76 -29
- data/lib/deltacloud/models/provider.rb +15 -13
- data/lib/deltacloud/models/realm.rb +15 -21
- data/lib/deltacloud/models/storage_snapshot.rb +23 -19
- data/lib/deltacloud/models/storage_volume.rb +35 -34
- data/lib/deltacloud/version.rb +1 -1
- data/lib/deltacloud_rack.rb +22 -0
- data/lib/initialize.rb +28 -0
- data/lib/initializers/database_initialize.rb +76 -0
- data/lib/initializers/frontend_initialize.rb +42 -0
- data/lib/initializers/mock_initialize.rb +33 -0
- data/lib/sinatra/rack_logger.rb +35 -24
- data/tests/cimi/collections/cloud_entry_point_test.rb +1 -7
- data/tests/cimi/collections/machine_images_test.rb +2 -2
- data/tests/cimi/collections/machine_templates_test.rb +75 -0
- data/tests/cimi/collections/machines_test.rb +2 -2
- data/tests/cimi/collections/system_templates_test.rb +41 -0
- data/tests/cimi/collections/systems_test.rb +50 -0
- data/tests/cimi/db/database_helper_test.rb +17 -25
- data/tests/cimi/db/db_helper.rb +1 -12
- data/tests/cimi/db/entity_test.rb +7 -8
- data/tests/cimi/model/machine_create_spec.rb +44 -0
- data/tests/cimi/model/machine_template_spec.rb +29 -0
- data/tests/cimi/model/resource_spec.rb +40 -0
- data/tests/cimi/model/schema_spec.rb +37 -0
- data/tests/cimi/spec_helper.rb +3 -0
- data/tests/deltacloud/collections/buckets_collection_test.rb +1 -1
- data/tests/deltacloud/collections/drivers_collection_test.rb +2 -2
- data/tests/deltacloud/collections/hardware_profiles_collection_test.rb +2 -2
- data/tests/deltacloud/collections/images_collection_test.rb +2 -2
- data/tests/deltacloud/collections/instance_states_collection_test.rb +1 -1
- data/tests/deltacloud/collections/instances_collection_test.rb +6 -3
- data/tests/deltacloud/collections/keys_collection_test.rb +2 -2
- data/tests/deltacloud/collections/realms_collection_test.rb +2 -2
- data/tests/deltacloud/collections/storage_snapshots_collection_test.rb +2 -2
- data/tests/deltacloud/collections/storage_volumes_collection_test.rb +2 -2
- data/tests/deltacloud/collections_test.rb +5 -5
- data/tests/deltacloud/common.rb +2 -13
- data/tests/deltacloud/launcher_test.rb +3 -3
- data/tests/deltacloud/rack_test.rb +2 -2
- data/tests/deltacloud/server_test.rb +1 -1
- data/tests/drivers/base/base_driver_test.rb +5 -5
- data/tests/drivers/base/common.rb +2 -12
- data/tests/drivers/ec2/buckets_test.rb +1 -1
- data/tests/drivers/ec2/images_test.rb +2 -2
- data/tests/drivers/ec2/instance_test.rb +6 -6
- data/tests/drivers/ec2/keys_test.rb +3 -3
- data/tests/drivers/ec2/realms_test.rb +2 -2
- data/tests/drivers/ec2/storage_snapshots_test.rb +1 -1
- data/tests/drivers/fgcp/common.rb +32 -0
- data/tests/drivers/fgcp/firewall_test.rb +70 -0
- data/tests/drivers/fgcp/hardware_profiles_test.rb +61 -0
- data/tests/drivers/fgcp/images_test.rb +46 -0
- data/tests/drivers/fgcp/provider_test.rb +27 -0
- data/tests/drivers/fgcp/realms_test.rb +53 -0
- data/tests/drivers/fgcp/storage_volumes_test.rb +58 -0
- data/tests/drivers/gogrid/images_test.rb +2 -2
- data/tests/drivers/gogrid/instances_test.rb +2 -2
- data/tests/drivers/gogrid/realms_test.rb +2 -2
- data/tests/drivers/mock/images_test.rb +4 -4
- data/tests/drivers/mock/instances_test.rb +9 -9
- data/tests/drivers/mock/keys_test.rb +3 -3
- data/tests/drivers/mock/realms_test.rb +2 -2
- data/tests/drivers/mock/storage_snapshots_test.rb +2 -2
- data/tests/drivers/mock/storage_volumes_test.rb +4 -4
- data/tests/drivers/models/instance_test.rb +2 -2
- data/tests/drivers/openstack/images_test.rb +2 -2
- data/tests/drivers/openstack/instances_test.rb +2 -3
- data/tests/drivers/openstack/keys_test.rb +1 -1
- data/tests/drivers/openstack/realms_test.rb +2 -11
- data/tests/drivers/rhevm/common.rb +33 -12
- data/tests/drivers/rhevm/images_test.rb +20 -12
- data/tests/drivers/rhevm/instance_test.rb +62 -46
- data/tests/drivers/rhevm/provider_test.rb +12 -6
- data/tests/drivers/rhevm/realms_test.rb +15 -9
- data/tests/ec2/query_parser_test.rb +1 -1
- data/tests/test_helper.rb +68 -12
- data/views/addresses/show.html.haml +1 -1
- data/views/buckets/show.html.haml +1 -1
- data/views/errors/{500.html.haml → common.html.haml} +0 -0
- data/views/errors/common.xml.haml +17 -0
- data/views/firewalls/index.xml.haml +2 -2
- data/views/firewalls/new.html.haml +2 -2
- data/views/images/show.html.haml +1 -1
- data/views/instances/run_command.html.haml +1 -1
- data/views/instances/show.html.haml +3 -3
- data/views/keys/index.html.haml +1 -0
- data/views/keys/show.html.haml +8 -4
- data/views/keys/show.xml.haml +3 -2
- data/views/load_balancers/new.html.haml +1 -1
- data/views/load_balancers/show.html.haml +2 -2
- data/views/metrics/show.html.haml +1 -1
- data/views/realms/index.html.haml +0 -2
- data/views/realms/show.html.haml +0 -4
- data/views/realms/show.xml.haml +0 -3
- data/views/storage_snapshots/index.html.haml +1 -1
- data/views/storage_snapshots/new.html.haml +1 -1
- data/views/storage_volumes/new.html.haml +2 -2
- data/views/storage_volumes/show.html.haml +3 -3
- metadata +90 -41
- data/views/errors/400.html.haml +0 -41
- data/views/errors/400.xml.haml +0 -3
- data/views/errors/401.html.haml +0 -26
- data/views/errors/401.xml.haml +0 -3
- data/views/errors/403.html.haml +0 -42
- data/views/errors/403.xml.haml +0 -9
- data/views/errors/404.html.haml +0 -28
- data/views/errors/404.xml.haml +0 -3
- data/views/errors/405.html.haml +0 -29
- data/views/errors/405.xml.haml +0 -5
- data/views/errors/409.html.haml +0 -47
- data/views/errors/409.xml.haml +0 -11
- data/views/errors/500.xml.haml +0 -13
- data/views/errors/501.html.haml +0 -44
- data/views/errors/501.xml.haml +0 -1
- data/views/errors/502.html.haml +0 -44
- data/views/errors/502.xml.haml +0 -1
- data/views/errors/504.html.haml +0 -43
- data/views/errors/504.xml.haml +0 -1
data/lib/initialize.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright ownership. The
|
4
|
+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
5
|
+
# "License"); you may not use this file except in compliance with the
|
6
|
+
# License. You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless require_relatived by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
13
|
+
# License for the specific language governing permissions and limitations
|
14
|
+
# under the License.
|
15
|
+
|
16
|
+
# Deltacloud server initialization scripts:
|
17
|
+
|
18
|
+
require 'require_relative' if RUBY_VERSION < '1.9'
|
19
|
+
|
20
|
+
# Initialize storage for mock and CIMI database
|
21
|
+
require_relative './initializers/mock_initialize'
|
22
|
+
|
23
|
+
# Configure available frontends
|
24
|
+
require_relative './initializers/frontend_initialize'
|
25
|
+
|
26
|
+
if Deltacloud::need_database?
|
27
|
+
require_relative './initializers/database_initialize'
|
28
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright ownership. The
|
4
|
+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
5
|
+
# "License"); you may not use this file except in compliance with the
|
6
|
+
# License. You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
13
|
+
# License for the specific language governing permissions and limitations
|
14
|
+
# under the License.
|
15
|
+
|
16
|
+
# Initialize the storage layer we use to persist some CIMI entities
|
17
|
+
# and attributes.
|
18
|
+
#
|
19
|
+
# By default the database backend is sqlite3
|
20
|
+
|
21
|
+
require 'sequel'
|
22
|
+
require 'logger'
|
23
|
+
|
24
|
+
require_relative '../db'
|
25
|
+
|
26
|
+
# We want to enable validation plugin for all database models
|
27
|
+
#
|
28
|
+
Sequel::Model.plugin :validation_class_methods
|
29
|
+
|
30
|
+
# Enable Sequel migrations extension
|
31
|
+
Sequel.extension :migration
|
32
|
+
|
33
|
+
# The default sqlite3 database can be overridden with the 'DATABASE_LOCATION'
|
34
|
+
# environment variable.
|
35
|
+
#
|
36
|
+
# For more details about possible values see:
|
37
|
+
# http://sequel.rubyforge.org/rdoc/files/doc/opening_databases_rdoc.html
|
38
|
+
#
|
39
|
+
unless location = ENV['DATABASE_LOCATION']
|
40
|
+
if ENV['RACK_ENV'] == 'test'
|
41
|
+
if RUBY_PLATFORM=='java'
|
42
|
+
location = 'jdbc:sqlite::memory'
|
43
|
+
else
|
44
|
+
location = 'sqlite:/'
|
45
|
+
end
|
46
|
+
else
|
47
|
+
sequel_driver = (RUBY_PLATFORM=='java') ? 'jdbc:sqlite:' : 'sqlite://'
|
48
|
+
location = "#{sequel_driver}#{File.join(BASE_STORAGE_DIR, 'db.sqlite')}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
if RUBY_PLATFORM == 'java'
|
53
|
+
require 'jdbc/sqlite3'
|
54
|
+
Jdbc::SQLite3.load_driver
|
55
|
+
end
|
56
|
+
|
57
|
+
database = Deltacloud::initialize_database(location)
|
58
|
+
|
59
|
+
# Detect if there are some pending migrations to run.
|
60
|
+
# We don't actually run migrations during server startup, just print
|
61
|
+
# a warning to console
|
62
|
+
#
|
63
|
+
|
64
|
+
DATABASE_MIGRATIONS_DIR = File.join(File.dirname(__FILE__), '..', '..', 'db', 'migrations')
|
65
|
+
|
66
|
+
unless Sequel::Migrator.is_current?(database, DATABASE_MIGRATIONS_DIR)
|
67
|
+
# Do not exit when this intitializer is included from deltacloud-db-upgrade
|
68
|
+
# script
|
69
|
+
#
|
70
|
+
if ENV['RACK_ENV'] == 'test' || ENV['DB_UPGRADE']
|
71
|
+
Sequel::Migrator.apply(database, DATABASE_MIGRATIONS_DIR)
|
72
|
+
else
|
73
|
+
warn "WARNING: The database needs to be upgraded. Run: 'deltacloud-db-upgrade' command."
|
74
|
+
exit(1)
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright ownership. The
|
4
|
+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
5
|
+
# "License"); you may not use this file except in compliance with the
|
6
|
+
# License. You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless require_relatived by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
13
|
+
# License for the specific language governing permissions and limitations
|
14
|
+
# under the License.
|
15
|
+
|
16
|
+
# The default driver if the API_DRIVER environment variable is not set:
|
17
|
+
ENV['API_DRIVER'] ||= 'mock'
|
18
|
+
|
19
|
+
# The default frontend if the API_FRONTEND environment variable is not set:
|
20
|
+
ENV['API_FRONTEND'] ||= 'deltacloud'
|
21
|
+
|
22
|
+
require_relative './../deltacloud_rack'
|
23
|
+
|
24
|
+
# This will configure the URL mapping, verions and different servers
|
25
|
+
# that multiple frontends require. You might not need to change this :)
|
26
|
+
Deltacloud::configure do |server|
|
27
|
+
server.root_url '/api'
|
28
|
+
server.version Deltacloud::API_VERSION
|
29
|
+
server.klass 'Deltacloud::API'
|
30
|
+
end
|
31
|
+
|
32
|
+
Deltacloud::configure(:cimi) do |server|
|
33
|
+
server.root_url '/cimi'
|
34
|
+
server.version Deltacloud::CIMI_API_VERSION
|
35
|
+
server.klass 'CIMI::API'
|
36
|
+
end
|
37
|
+
|
38
|
+
Deltacloud::configure(:ec2) do |server|
|
39
|
+
server.root_url '/ec2'
|
40
|
+
server.version '2012-04-01'
|
41
|
+
server.klass 'Deltacloud::EC2::API'
|
42
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
2
|
+
# contributor license agreements. See the NOTICE file distributed with
|
3
|
+
# this work for additional information regarding copyright ownership. The
|
4
|
+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
5
|
+
# "License"); you may not use this file except in compliance with the
|
6
|
+
# License. You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
13
|
+
# License for the specific language governing permissions and limitations
|
14
|
+
# under the License.
|
15
|
+
|
16
|
+
require 'fileutils'
|
17
|
+
|
18
|
+
# This will create the directory we use for storing Mock driver
|
19
|
+
# data and also CIMI database file
|
20
|
+
#
|
21
|
+
|
22
|
+
# By default the location is /var/tmp/deltacloud-{USER}/
|
23
|
+
#
|
24
|
+
BASE_STORAGE_DIR = File.join('/', 'var', 'tmp', "deltacloud-#{ENV['USER']}")
|
25
|
+
|
26
|
+
# The mock driver YAML files are stored in BASE_STORAGE_DIR/mock
|
27
|
+
# You can overide this by setting 'DELTACLOUD_MOCK_STORAGE' environment variable
|
28
|
+
#
|
29
|
+
MOCK_STORAGE_DIR = ENV['DELTACLOUD_MOCK_STORAGE'] || File.join(BASE_STORAGE_DIR, 'mock')
|
30
|
+
|
31
|
+
[BASE_STORAGE_DIR, MOCK_STORAGE_DIR].each do |p|
|
32
|
+
FileUtils.mkpath(p, :mode => 0750) unless File.directory?(p)
|
33
|
+
end
|
data/lib/sinatra/rack_logger.rb
CHANGED
@@ -26,33 +26,40 @@ module Rack
|
|
26
26
|
# rack.errors by default.
|
27
27
|
class DeltacloudLogger
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
class << self
|
30
|
+
def log_path(path=nil)
|
31
|
+
@log_file ||= path
|
32
|
+
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
def verbose?
|
35
|
+
@verbose
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
38
|
+
def verbose(v=nil)
|
39
|
+
@verbose ||= v
|
40
|
+
end
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
42
|
+
def setup(path, be_verbose=false)
|
43
|
+
verbose(be_verbose)
|
44
|
+
return self if path.nil?
|
45
|
+
dir = ::File.dirname(path)
|
46
|
+
if ::File.exists?(dir) and ::File.writable?(dir)
|
47
|
+
log_path(path)
|
48
|
+
else
|
49
|
+
warn "Warning: The log directory (#{dir}) is not writeable."
|
50
|
+
end
|
51
|
+
self
|
49
52
|
end
|
50
|
-
self
|
51
|
-
end
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
|
54
|
+
def logger
|
55
|
+
@logger ||= ::Logger.new(log_path || $stdout)
|
56
|
+
end
|
57
|
+
|
58
|
+
[:error, :warn, :info].each do |method_name|
|
59
|
+
define_method method_name do |msg, &block|
|
60
|
+
logger.send(method_name, msg, &block)
|
61
|
+
end
|
62
|
+
end
|
56
63
|
end
|
57
64
|
|
58
65
|
# Common Log Format: http://httpd.apache.org/docs/1.3/logs.html#common
|
@@ -62,10 +69,14 @@ module Rack
|
|
62
69
|
|
63
70
|
VERBOSE_FORMAT = %{%s - %s [%s] "%s %s%s%s %s" %s %s %d %s %0.4f\n}
|
64
71
|
|
72
|
+
# If Deltacloud is started with the -L/--log option then
|
73
|
+
# we set logger to this file, otherwise use the default
|
74
|
+
# Sinatra logger facility
|
75
|
+
#
|
65
76
|
def initialize(app, logger=nil)
|
66
77
|
@app = app
|
67
|
-
|
68
|
-
@logger =
|
78
|
+
if self.class.log_path
|
79
|
+
@logger = self.class.logger
|
69
80
|
else
|
70
81
|
@logger = logger
|
71
82
|
end
|
@@ -12,13 +12,7 @@ describe CIMI::Collections::CloudEntryPoint do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'has index operation' do
|
15
|
-
@collection.operation(:index).must_equal
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'set the CIMI-Version header' do
|
19
|
-
get root_url
|
20
|
-
headers['CIMI-Specification-Version'].wont_be_nil
|
21
|
-
headers['CIMI-Specification-Version'].must_equal '1.0.0'
|
15
|
+
@collection.operation(:index).must_equal CIMI::Rabbit::CloudentrypointCollection::IndexOperation
|
22
16
|
end
|
23
17
|
|
24
18
|
it 'advertise CIMI collections in XML format' do
|
@@ -12,11 +12,11 @@ describe CIMI::Collections::MachineImages do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'has index operation' do
|
15
|
-
@collection.operation(:index).must_equal
|
15
|
+
@collection.operation(:index).must_equal CIMI::Rabbit::MachineImagesCollection::IndexOperation
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'has show operation' do
|
19
|
-
@collection.operation(:show).must_equal
|
19
|
+
@collection.operation(:show).must_equal CIMI::Rabbit::MachineImagesCollection::ShowOperation
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'returns list of images in various formats with index operation' do
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'require_relative' if RUBY_VERSION < '1.9'
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require_relative './common.rb'
|
5
|
+
|
6
|
+
describe CIMI::Collections::MachineTemplates do
|
7
|
+
|
8
|
+
before do
|
9
|
+
def app; run_frontend(:cimi) end
|
10
|
+
authorize 'mockuser', 'mockpassword'
|
11
|
+
@collection = CIMI::Collections.collection(:machine_images)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should return bad request creating template with scrambled JSON' do
|
15
|
+
json_body = '{
|
16
|
+
"resourceURI": "http://schemas.dmtf.org/cimi/1/MachineTemplateCreate",
|
17
|
+
"name": "myMachineDemoTemplate",
|
18
|
+
"description": "My very loved machine template",
|
19
|
+
"machineConfig": { "href": "http://localhost:3001/cimi/machine_configurations/m1-xlarge" }
|
20
|
+
"machineImage": { "href": "http://localhost:3001/cimi/machine_images/img1" }
|
21
|
+
}'
|
22
|
+
header 'Content-Type', 'application/json'
|
23
|
+
header 'Accept', 'application/json'
|
24
|
+
post root_url('/machine_templates'), json_body
|
25
|
+
status.must_equal 400
|
26
|
+
json['code'].must_equal 400
|
27
|
+
json['message'].must_equal "Bad request (expected ',' or '}' in object at '\"machineImage\": { \"h'!)"
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should return validation error when missing required attribute in JSON' do
|
31
|
+
json_body = '{
|
32
|
+
"resourceURI": "http://schemas.dmtf.org/cimi/1/MachineTemplateCreate",
|
33
|
+
"name": "myMachineDemoTemplate",
|
34
|
+
"description": "My very loved machine template",
|
35
|
+
"machineConfig": { "href": "http://localhost:3001/cimi/machine_configurations/m1-xlarge" }
|
36
|
+
}'
|
37
|
+
header 'Content-Type', 'application/json'
|
38
|
+
header 'Accept', 'application/json'
|
39
|
+
post root_url('/machine_templates'), json_body
|
40
|
+
status.must_equal 400
|
41
|
+
json['message'].must_equal "Required attributes not set: machineImage"
|
42
|
+
json['error'].must_equal 'CIMI::Model::ValidationError'
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should return bad request creating template with scrambled XML' do
|
46
|
+
xml_body = '
|
47
|
+
<MachineTemplateCreate>
|
48
|
+
<name>myXmlTestMachineTemplate1</name>
|
49
|
+
<description>Description of my MachineTemplate</description>
|
50
|
+
operty key="test">value</property>
|
51
|
+
<machineConfig href="http://localhost:3001/cimi/machine_configurations/m1-xlarge"/>
|
52
|
+
<machineImage href="http://localhost:3001/cimi/machine_images/img3"/>
|
53
|
+
</MachineTemplateCreate>'
|
54
|
+
header 'Content-Type', 'text/xml'
|
55
|
+
header 'Accept', 'text/xml'
|
56
|
+
post root_url('/machine_templates'), xml_body
|
57
|
+
status.must_equal 400
|
58
|
+
xml.at('/error/message').text.must_equal 'Bad Request'
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should return validation error when missing required attribute in XML' do
|
62
|
+
xml_body = '
|
63
|
+
<MachineTemplateCreate>
|
64
|
+
<name>myXmlTestMachineTemplate1</name>
|
65
|
+
<description>Description of my MachineTemplate</description>
|
66
|
+
<machineConfig href="http://localhost:3001/cimi/machine_configurations/m1-xlarge"/>
|
67
|
+
</MachineTemplateCreate>'
|
68
|
+
header 'Content-Type', 'text/xml'
|
69
|
+
header 'Accept', 'text/xml'
|
70
|
+
post root_url('/machine_templates'), xml_body
|
71
|
+
status.must_equal 400
|
72
|
+
xml.at('/error/message').text.must_equal "Required attributes not set: machineImage"
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
@@ -14,11 +14,11 @@ describe CIMI::Collections::Machines do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'has index operation' do
|
17
|
-
@collection.operation(:index).must_equal
|
17
|
+
@collection.operation(:index).must_equal CIMI::Rabbit::MachinesCollection::IndexOperation
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'has show operation' do
|
21
|
-
@collection.operation(:show).must_equal
|
21
|
+
@collection.operation(:show).must_equal CIMI::Rabbit::MachinesCollection::ShowOperation
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'returns list of machines in various formats with index operation' do
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'require_relative' if RUBY_VERSION < '1.9'
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require_relative './common.rb'
|
5
|
+
|
6
|
+
describe CIMI::Collections::SystemTemplates do
|
7
|
+
|
8
|
+
before do
|
9
|
+
def app; run_frontend(:cimi) end
|
10
|
+
authorize 'mockuser', 'mockpassword'
|
11
|
+
@collection = CIMI::Collections.collection(:system_templates)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'has index operation' do
|
15
|
+
@collection.operation(:index).must_equal CIMI::Rabbit::SystemTemplatesCollection::IndexOperation
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'has show operation' do
|
19
|
+
@collection.operation(:show).must_equal CIMI::Rabbit::SystemTemplatesCollection::ShowOperation
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'returns list of system templates in various formats with index operation' do
|
23
|
+
formats.each do |format|
|
24
|
+
header 'Accept', format
|
25
|
+
get root_url + '/system_templates'
|
26
|
+
status.must_equal 200
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should allow to retrieve the single system template' do
|
31
|
+
get root_url '/system_templates/template1'
|
32
|
+
status.must_equal 200
|
33
|
+
xml.root.name.must_equal 'SystemTemplate'
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should not return non-existing system_template' do
|
37
|
+
get root_url '/system_templates/unknown-system_template'
|
38
|
+
status.must_equal 404
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'require_relative' if RUBY_VERSION < '1.9'
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require_relative './common.rb'
|
5
|
+
|
6
|
+
describe CIMI::Collections::Systems do
|
7
|
+
|
8
|
+
before do
|
9
|
+
def app; run_frontend(:cimi) end
|
10
|
+
authorize 'mockuser', 'mockpassword'
|
11
|
+
@collection = CIMI::Collections.collection(:systems)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'has index operation' do
|
15
|
+
@collection.operation(:index).must_equal CIMI::Rabbit::SystemsCollection::IndexOperation
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'has show operation' do
|
19
|
+
@collection.operation(:show).must_equal CIMI::Rabbit::SystemsCollection::ShowOperation
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'returns list of systems in various formats with index operation' do
|
23
|
+
formats.each do |format|
|
24
|
+
header 'Accept', format
|
25
|
+
get root_url + '/systems'
|
26
|
+
status.must_equal 200
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should allow to retrieve the single system' do
|
31
|
+
get root_url '/systems/system1'
|
32
|
+
status.must_equal 200
|
33
|
+
xml.root.name.must_equal 'System'
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should have legal status' do
|
37
|
+
get root_url '/systems'
|
38
|
+
status.must_equal 200
|
39
|
+
(xml/'Collection/System').each do |s|
|
40
|
+
(s/'state').wont_be_empty
|
41
|
+
(s/'state').inner_text.must_equal 'STOPPED'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should not return non-existing system' do
|
46
|
+
get root_url '/systems/unknown-system'
|
47
|
+
status.must_equal 404
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|