bbrowning-deltacloud-core 0.0.4-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYING +176 -0
- data/Rakefile +99 -0
- data/bin/deltacloudd +120 -0
- data/config.ru +5 -0
- data/deltacloud.rb +18 -0
- data/lib/deltacloud/base_driver/base_driver.rb +229 -0
- data/lib/deltacloud/base_driver/features.rb +166 -0
- data/lib/deltacloud/base_driver/mock_driver.rb +40 -0
- data/lib/deltacloud/base_driver.rb +20 -0
- data/lib/deltacloud/drivers/ec2/ec2_driver.rb +410 -0
- data/lib/deltacloud/drivers/ec2/ec2_mock_driver.rb +170 -0
- data/lib/deltacloud/drivers/gogrid/gogrid_client.rb +50 -0
- data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +332 -0
- data/lib/deltacloud/drivers/gogrid/test.rb +13 -0
- data/lib/deltacloud/drivers/mock/data/images/img1.yml +3 -0
- data/lib/deltacloud/drivers/mock/data/images/img2.yml +3 -0
- data/lib/deltacloud/drivers/mock/data/images/img3.yml +3 -0
- data/lib/deltacloud/drivers/mock/data/instances/inst0.yml +16 -0
- data/lib/deltacloud/drivers/mock/data/instances/inst1.yml +9 -0
- data/lib/deltacloud/drivers/mock/data/instances/inst2.yml +9 -0
- data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap1.yml +4 -0
- data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap2.yml +4 -0
- data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap3.yml +4 -0
- data/lib/deltacloud/drivers/mock/data/storage_volumes/vol1.yml +6 -0
- data/lib/deltacloud/drivers/mock/data/storage_volumes/vol2.yml +6 -0
- data/lib/deltacloud/drivers/mock/data/storage_volumes/vol3.yml +6 -0
- data/lib/deltacloud/drivers/mock/mock_driver.rb +277 -0
- data/lib/deltacloud/drivers/opennebula/cloud_client.rb +116 -0
- data/lib/deltacloud/drivers/opennebula/occi_client.rb +204 -0
- data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +241 -0
- data/lib/deltacloud/drivers/rackspace/rackspace_client.rb +130 -0
- data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +182 -0
- data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +255 -0
- data/lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb +85 -0
- data/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb +166 -0
- data/lib/deltacloud/drivers/terremark/terremark_driver.rb +286 -0
- data/lib/deltacloud/hardware_profile.rb +153 -0
- data/lib/deltacloud/helpers/application_helper.rb +115 -0
- data/lib/deltacloud/helpers/conversion_helper.rb +39 -0
- data/lib/deltacloud/helpers/hardware_profiles_helper.rb +35 -0
- data/lib/deltacloud/helpers.rb +5 -0
- data/lib/deltacloud/method_serializer.rb +85 -0
- data/lib/deltacloud/models/base_model.rb +59 -0
- data/lib/deltacloud/models/image.rb +27 -0
- data/lib/deltacloud/models/instance.rb +38 -0
- data/lib/deltacloud/models/instance_profile.rb +48 -0
- data/lib/deltacloud/models/key.rb +35 -0
- data/lib/deltacloud/models/realm.rb +26 -0
- data/lib/deltacloud/models/storage_snapshot.rb +27 -0
- data/lib/deltacloud/models/storage_volume.rb +28 -0
- data/lib/deltacloud/state_machine.rb +84 -0
- data/lib/deltacloud/validation.rb +70 -0
- data/lib/drivers.rb +50 -0
- data/lib/sinatra/accept_media_types.rb +128 -0
- data/lib/sinatra/lazy_auth.rb +56 -0
- data/lib/sinatra/rabbit.rb +273 -0
- data/lib/sinatra/respond_to.rb +272 -0
- data/lib/sinatra/static_assets.rb +83 -0
- data/lib/sinatra/url_for.rb +53 -0
- data/public/favicon.ico +0 -0
- data/public/images/grid.png +0 -0
- data/public/images/logo-wide.png +0 -0
- data/public/images/rails.png +0 -0
- data/public/images/topbar-bg.png +0 -0
- data/public/javascripts/application.js +32 -0
- data/public/javascripts/jquery-1.4.2.min.js +154 -0
- data/public/stylesheets/compiled/application.css +613 -0
- data/public/stylesheets/compiled/ie.css +31 -0
- data/public/stylesheets/compiled/print.css +27 -0
- data/public/stylesheets/compiled/screen.css +456 -0
- data/server.rb +354 -0
- data/support/fedora/deltacloudd +68 -0
- data/support/fedora/rubygem-deltacloud-core.spec +91 -0
- data/tests/api_test.rb +37 -0
- data/tests/hardware_profiles_test.rb +120 -0
- data/tests/images_test.rb +111 -0
- data/tests/instance_states_test.rb +52 -0
- data/tests/instances_test.rb +219 -0
- data/tests/realms_test.rb +78 -0
- data/tests/url_for_test.rb +50 -0
- data/views/accounts/index.html.haml +11 -0
- data/views/accounts/show.html.haml +30 -0
- data/views/api/show.html.haml +15 -0
- data/views/api/show.xml.haml +5 -0
- data/views/docs/collection.html.haml +37 -0
- data/views/docs/collection.xml.haml +14 -0
- data/views/docs/index.html.haml +15 -0
- data/views/docs/index.xml.haml +5 -0
- data/views/docs/operation.html.haml +31 -0
- data/views/docs/operation.xml.haml +10 -0
- data/views/errors/auth_exception.html.haml +8 -0
- data/views/errors/auth_exception.xml.haml +2 -0
- data/views/errors/backend_error.html.haml +19 -0
- data/views/errors/backend_error.xml.haml +8 -0
- data/views/errors/not_found.html.haml +6 -0
- data/views/errors/not_found.xml.haml +2 -0
- data/views/errors/validation_failure.html.haml +11 -0
- data/views/errors/validation_failure.xml.haml +7 -0
- data/views/hardware_profiles/index.html.haml +25 -0
- data/views/hardware_profiles/index.xml.haml +4 -0
- data/views/hardware_profiles/show.html.haml +19 -0
- data/views/hardware_profiles/show.xml.haml +18 -0
- data/views/images/index.html.haml +30 -0
- data/views/images/index.xml.haml +8 -0
- data/views/images/show.html.haml +21 -0
- data/views/images/show.xml.haml +5 -0
- data/views/instance_states/show.gv.erb +45 -0
- data/views/instance_states/show.html.haml +31 -0
- data/views/instance_states/show.xml.haml +8 -0
- data/views/instances/index.html.haml +30 -0
- data/views/instances/index.xml.haml +21 -0
- data/views/instances/new.html.haml +55 -0
- data/views/instances/show.html.haml +43 -0
- data/views/instances/show.xml.haml +49 -0
- data/views/keys/index.html.haml +26 -0
- data/views/keys/index.xml.haml +4 -0
- data/views/keys/new.html.haml +8 -0
- data/views/keys/show.html.haml +22 -0
- data/views/keys/show.xml.haml +20 -0
- data/views/layout.html.haml +26 -0
- data/views/realms/index.html.haml +29 -0
- data/views/realms/index.xml.haml +10 -0
- data/views/realms/show.html.haml +15 -0
- data/views/realms/show.xml.haml +9 -0
- data/views/root/index.html.haml +4 -0
- data/views/storage_snapshots/index.html.haml +20 -0
- data/views/storage_snapshots/index.xml.haml +9 -0
- data/views/storage_snapshots/show.html.haml +14 -0
- data/views/storage_snapshots/show.xml.haml +7 -0
- data/views/storage_volumes/index.html.haml +21 -0
- data/views/storage_volumes/index.xml.haml +13 -0
- data/views/storage_volumes/show.html.haml +20 -0
- data/views/storage_volumes/show.xml.haml +11 -0
- metadata +334 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (C) 2009 Red Hat, Inc.
|
|
3
|
+
#
|
|
4
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
5
|
+
# contributor license agreements. See the NOTICE file distributed with
|
|
6
|
+
# this work for additional information regarding copyright ownership. The
|
|
7
|
+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
8
|
+
# "License"); you may not use this file except in compliance with the
|
|
9
|
+
# License. You may obtain a copy of the License at
|
|
10
|
+
#
|
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
#
|
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
15
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
16
|
+
# License for the specific language governing permissions and limitations
|
|
17
|
+
# under the License.
|
|
18
|
+
|
|
19
|
+
require 'base64'
|
|
20
|
+
require 'digest'
|
|
21
|
+
|
|
22
|
+
module MethodSerializer
|
|
23
|
+
|
|
24
|
+
module Cache
|
|
25
|
+
|
|
26
|
+
def cache_dir
|
|
27
|
+
storage_dir = $methods_cache_dir || File.join(File.dirname(__FILE__), 'cache')
|
|
28
|
+
class_dir = self.class.name.split('::').last
|
|
29
|
+
class_dir ||= self.class.name
|
|
30
|
+
File.join(storage_dir, class_dir.downcase)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def serialize_data(method_name, args, data)
|
|
34
|
+
File.open(cache_file_name(method_name, args), 'w') do |f|
|
|
35
|
+
f.puts(Base64.encode64(Marshal.dump(data)))
|
|
36
|
+
end
|
|
37
|
+
return data
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def deserialize_data(method_name, args)
|
|
41
|
+
begin
|
|
42
|
+
data = File.readlines(cache_file_name(method_name, args)).join
|
|
43
|
+
Marshal.load(Base64.decode64(data))
|
|
44
|
+
rescue Errno::ENOENT
|
|
45
|
+
return false
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def args_hash(args)
|
|
50
|
+
if args.class == Hash
|
|
51
|
+
args = args.to_a.collect {|i| [i[0].to_s, i[1]]}.sort
|
|
52
|
+
end
|
|
53
|
+
Digest::SHA1.hexdigest(args.to_s)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def cache_file_name(method_name, args)
|
|
57
|
+
FileUtils.mkdir_p(cache_dir) unless File.directory?(cache_dir)
|
|
58
|
+
method_name = $scenario_prefix ? "#{$scenario_prefix}_#{method_name}" : method_name
|
|
59
|
+
File.join(cache_dir, "#{method_name}.#{args_hash(args)}")
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def self.wrap_methods(c, opts={})
|
|
63
|
+
$methods_cache_dir = opts[:cache_dir]
|
|
64
|
+
$scenario_prefix = nil
|
|
65
|
+
c.class_eval do
|
|
66
|
+
cached_methods.each do |m|
|
|
67
|
+
next if c.instance_methods(false).include?("original_#{m}")
|
|
68
|
+
alias_method "original_#{m}".to_sym, m.to_sym
|
|
69
|
+
define_method m.to_sym do |*args|
|
|
70
|
+
args = args.first if args.size.eql?(1) and not args.first.class.eql?(Array)
|
|
71
|
+
output = deserialize_data(m, args)
|
|
72
|
+
unless output
|
|
73
|
+
output = method("original_#{m}".to_sym).to_proc[args]
|
|
74
|
+
return serialize_data(m, args, output)
|
|
75
|
+
else
|
|
76
|
+
return output
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (C) 2009 Red Hat, Inc.
|
|
3
|
+
#
|
|
4
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
5
|
+
# contributor license agreements. See the NOTICE file distributed with
|
|
6
|
+
# this work for additional information regarding copyright ownership. The
|
|
7
|
+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
8
|
+
# "License"); you may not use this file except in compliance with the
|
|
9
|
+
# License. You may obtain a copy of the License at
|
|
10
|
+
#
|
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
#
|
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
15
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
16
|
+
# License for the specific language governing permissions and limitations
|
|
17
|
+
# under the License.
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class BaseModel
|
|
21
|
+
|
|
22
|
+
def initialize(init=nil)
|
|
23
|
+
if ( init )
|
|
24
|
+
@id=init[:id]
|
|
25
|
+
init.each{|k,v|
|
|
26
|
+
self.send( "#{k}=", v ) if ( self.respond_to?( "#{k}=" ) )
|
|
27
|
+
}
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def self.attr_accessor(*vars)
|
|
32
|
+
@attributes ||= [:id]
|
|
33
|
+
@attributes.concat vars
|
|
34
|
+
super
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.attributes
|
|
38
|
+
@attributes
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def attributes
|
|
42
|
+
self.class.attributes
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def id
|
|
46
|
+
@id
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def to_hash
|
|
50
|
+
out = {}
|
|
51
|
+
self.attributes.each { |attribute| out.merge!({ attribute => self.send(:"#{attribute}") } ) }
|
|
52
|
+
out
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def to_json(*a)
|
|
56
|
+
self.to_hash.to_json(*a)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (C) 2009 Red Hat, Inc.
|
|
3
|
+
#
|
|
4
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
5
|
+
# contributor license agreements. See the NOTICE file distributed with
|
|
6
|
+
# this work for additional information regarding copyright ownership. The
|
|
7
|
+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
8
|
+
# "License"); you may not use this file except in compliance with the
|
|
9
|
+
# License. You may obtain a copy of the License at
|
|
10
|
+
#
|
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
#
|
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
15
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
16
|
+
# License for the specific language governing permissions and limitations
|
|
17
|
+
# under the License.
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class Image < BaseModel
|
|
21
|
+
|
|
22
|
+
attr_accessor :name
|
|
23
|
+
attr_accessor :owner_id
|
|
24
|
+
attr_accessor :description
|
|
25
|
+
attr_accessor :architecture
|
|
26
|
+
|
|
27
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (C) 2009 Red Hat, Inc.
|
|
3
|
+
#
|
|
4
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
5
|
+
# contributor license agreements. See the NOTICE file distributed with
|
|
6
|
+
# this work for additional information regarding copyright ownership. The
|
|
7
|
+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
8
|
+
# "License"); you may not use this file except in compliance with the
|
|
9
|
+
# License. You may obtain a copy of the License at
|
|
10
|
+
#
|
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
#
|
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
15
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
16
|
+
# License for the specific language governing permissions and limitations
|
|
17
|
+
# under the License.
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class Instance < BaseModel
|
|
21
|
+
|
|
22
|
+
attr_accessor :owner_id
|
|
23
|
+
attr_accessor :image_id
|
|
24
|
+
attr_accessor :name
|
|
25
|
+
attr_accessor :realm_id
|
|
26
|
+
attr_accessor :state
|
|
27
|
+
attr_accessor :actions
|
|
28
|
+
attr_accessor :public_addresses
|
|
29
|
+
attr_accessor :private_addresses
|
|
30
|
+
attr_accessor :instance_profile
|
|
31
|
+
attr_accessor :launch_time
|
|
32
|
+
def initialize(init=nil)
|
|
33
|
+
super(init)
|
|
34
|
+
self.actions = [] if self.actions.nil?
|
|
35
|
+
self.public_addresses = [] if self.public_addresses.nil?
|
|
36
|
+
self.private_addresses = [] if self.private_addresses.nil?
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (C) 2009 Red Hat, Inc.
|
|
3
|
+
#
|
|
4
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
5
|
+
# contributor license agreements. See the NOTICE file distributed with
|
|
6
|
+
# this work for additional information regarding copyright ownership. The
|
|
7
|
+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
8
|
+
# "License"); you may not use this file except in compliance with the
|
|
9
|
+
# License. You may obtain a copy of the License at
|
|
10
|
+
#
|
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
#
|
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
15
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
16
|
+
# License for the specific language governing permissions and limitations
|
|
17
|
+
# under the License.
|
|
18
|
+
|
|
19
|
+
# Model to store the hardware profile applied to an instance together with
|
|
20
|
+
# any instance-specific overrides
|
|
21
|
+
class InstanceProfile < BaseModel
|
|
22
|
+
attr_accessor :memory
|
|
23
|
+
attr_accessor :storage
|
|
24
|
+
attr_accessor :architecture
|
|
25
|
+
attr_accessor :cpu
|
|
26
|
+
|
|
27
|
+
def initialize(hwp_name, args = {})
|
|
28
|
+
opts = args.inject({ :id => hwp_name.to_s }) do |m, e|
|
|
29
|
+
k, v = e
|
|
30
|
+
m[$1] = v if k.to_s =~ /^hwp_(.*)$/
|
|
31
|
+
m
|
|
32
|
+
end
|
|
33
|
+
super(opts)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def name
|
|
37
|
+
id
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def overrides
|
|
41
|
+
[:memory, :storage, :architecture, :cpu].inject({}) do |h, p|
|
|
42
|
+
if v = instance_variable_get("@#{p}")
|
|
43
|
+
h[p] = v
|
|
44
|
+
end
|
|
45
|
+
h
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (C) 2009 Red Hat, Inc.
|
|
3
|
+
#
|
|
4
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
5
|
+
# contributor license agreements. See the NOTICE file distributed with
|
|
6
|
+
# this work for additional information regarding copyright ownership. The
|
|
7
|
+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
8
|
+
# "License"); you may not use this file except in compliance with the
|
|
9
|
+
# License. You may obtain a copy of the License at
|
|
10
|
+
#
|
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
#
|
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
15
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
16
|
+
# License for the specific language governing permissions and limitations
|
|
17
|
+
# under the License.
|
|
18
|
+
|
|
19
|
+
class Key < BaseModel
|
|
20
|
+
|
|
21
|
+
attr_accessor :credential_type
|
|
22
|
+
attr_accessor :fingerprint
|
|
23
|
+
attr_accessor :username
|
|
24
|
+
attr_accessor :password
|
|
25
|
+
attr_accessor :pem_rsa_key
|
|
26
|
+
|
|
27
|
+
def is_password?
|
|
28
|
+
true if @credential_type.eql?(:password)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def is_key?
|
|
32
|
+
true if @credential_type.eql?(:key)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (C) 2009 Red Hat, Inc.
|
|
3
|
+
#
|
|
4
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
5
|
+
# contributor license agreements. See the NOTICE file distributed with
|
|
6
|
+
# this work for additional information regarding copyright ownership. The
|
|
7
|
+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
8
|
+
# "License"); you may not use this file except in compliance with the
|
|
9
|
+
# License. You may obtain a copy of the License at
|
|
10
|
+
#
|
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
#
|
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
15
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
16
|
+
# License for the specific language governing permissions and limitations
|
|
17
|
+
# under the License.
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class Realm < BaseModel
|
|
21
|
+
|
|
22
|
+
attr_accessor :name
|
|
23
|
+
attr_accessor :limit
|
|
24
|
+
attr_accessor :state
|
|
25
|
+
|
|
26
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (C) 2009 Red Hat, Inc.
|
|
3
|
+
#
|
|
4
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
5
|
+
# contributor license agreements. See the NOTICE file distributed with
|
|
6
|
+
# this work for additional information regarding copyright ownership. The
|
|
7
|
+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
8
|
+
# "License"); you may not use this file except in compliance with the
|
|
9
|
+
# License. You may obtain a copy of the License at
|
|
10
|
+
#
|
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
#
|
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
15
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
16
|
+
# License for the specific language governing permissions and limitations
|
|
17
|
+
# under the License.
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class StorageSnapshot < BaseModel
|
|
22
|
+
|
|
23
|
+
attr_accessor :state
|
|
24
|
+
attr_accessor :storage_volume_id
|
|
25
|
+
attr_accessor :created
|
|
26
|
+
|
|
27
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright (C) 2009 Red Hat, Inc.
|
|
3
|
+
#
|
|
4
|
+
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
5
|
+
# contributor license agreements. See the NOTICE file distributed with
|
|
6
|
+
# this work for additional information regarding copyright ownership. The
|
|
7
|
+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
8
|
+
# "License"); you may not use this file except in compliance with the
|
|
9
|
+
# License. You may obtain a copy of the License at
|
|
10
|
+
#
|
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
#
|
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
15
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
16
|
+
# License for the specific language governing permissions and limitations
|
|
17
|
+
# under the License.
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class StorageVolume < BaseModel
|
|
21
|
+
|
|
22
|
+
attr_accessor :created
|
|
23
|
+
attr_accessor :state
|
|
24
|
+
attr_accessor :capacity
|
|
25
|
+
attr_accessor :instance_id
|
|
26
|
+
attr_accessor :device
|
|
27
|
+
|
|
28
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
|
|
2
|
+
module Deltacloud
|
|
3
|
+
class StateMachine
|
|
4
|
+
|
|
5
|
+
attr_reader :states
|
|
6
|
+
def initialize(&block)
|
|
7
|
+
@states = []
|
|
8
|
+
instance_eval &block if block
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def start()
|
|
12
|
+
state(:start)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def finish()
|
|
16
|
+
state(:finish)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def state(name)
|
|
20
|
+
state = @states.find{|e| e.name == name.to_sym}
|
|
21
|
+
if ( state.nil? )
|
|
22
|
+
state = State.new( self, name.to_sym )
|
|
23
|
+
@states << state
|
|
24
|
+
end
|
|
25
|
+
state
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def method_missing(sym,*args)
|
|
29
|
+
return state( sym ) if ( args.empty? )
|
|
30
|
+
super( sym, *args )
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
class State
|
|
34
|
+
|
|
35
|
+
attr_reader :name
|
|
36
|
+
attr_reader :transitions
|
|
37
|
+
|
|
38
|
+
def initialize(machine, name)
|
|
39
|
+
@machine = machine
|
|
40
|
+
@name = name
|
|
41
|
+
@transitions = []
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def to_s
|
|
45
|
+
self.name.to_s
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def to(destination_name)
|
|
49
|
+
destination = @machine.state(destination_name)
|
|
50
|
+
transition = Transition.new( @machine, destination )
|
|
51
|
+
@transitions << transition
|
|
52
|
+
transition
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
class Transition
|
|
58
|
+
|
|
59
|
+
attr_reader :destination
|
|
60
|
+
attr_reader :action
|
|
61
|
+
|
|
62
|
+
def initialize(machine, destination)
|
|
63
|
+
@machine = machine
|
|
64
|
+
@destination = destination
|
|
65
|
+
@auto = false
|
|
66
|
+
@action = nil
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def automatically
|
|
70
|
+
@auto = true
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def automatically?
|
|
74
|
+
@auto
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def on(action)
|
|
78
|
+
@action = action
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
module Deltacloud::Validation
|
|
2
|
+
|
|
3
|
+
class Failure < StandardError
|
|
4
|
+
attr_reader :param
|
|
5
|
+
def initialize(param, msg='')
|
|
6
|
+
super(msg)
|
|
7
|
+
@param = param
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def name
|
|
11
|
+
param.name
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
class Param
|
|
16
|
+
attr_reader :name, :klass, :type, :options, :description
|
|
17
|
+
|
|
18
|
+
def initialize(args)
|
|
19
|
+
@name = args[0]
|
|
20
|
+
@klass = args[1] || :string
|
|
21
|
+
@type = args[2] || :optional
|
|
22
|
+
@options = args[3] || []
|
|
23
|
+
@description = args[4] || ''
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def required?
|
|
27
|
+
type.eql?(:required)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def optional?
|
|
31
|
+
type.eql?(:optional)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def param(*args)
|
|
36
|
+
raise DuplicateParamException if params[args[0]]
|
|
37
|
+
p = Param.new(args)
|
|
38
|
+
params[p.name] = p
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def params
|
|
42
|
+
@params ||= {}
|
|
43
|
+
@params
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Add the parameters in hash +new+ to already existing parameters. If
|
|
47
|
+
# +new+ contains a parameter with an already existing name, the old
|
|
48
|
+
# definition is clobbered.
|
|
49
|
+
def add_params(new)
|
|
50
|
+
# We do not check for duplication on purpose: multiple calls
|
|
51
|
+
# to add_params should be cumulative
|
|
52
|
+
new.each { |p| @params[p.name] = p }
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def each_param(&block)
|
|
56
|
+
params.each_value { |p| yield p }
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def validate(values)
|
|
60
|
+
each_param do |p|
|
|
61
|
+
if p.required? and not values[p.name]
|
|
62
|
+
raise Failure.new(p, "Required parameter #{p.name} not found")
|
|
63
|
+
end
|
|
64
|
+
if values[p.name] and not p.options.empty? and
|
|
65
|
+
not p.options.include?(values[p.name])
|
|
66
|
+
raise Failure.new(p, "Parameter #{p.name} has value #{values[p.name]} which is not in #{p.options.join(", ")}")
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
data/lib/drivers.rb
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
DRIVERS = {
|
|
2
|
+
:ec2 => { :name => "EC2" },
|
|
3
|
+
:rackspace => { :name => "Rackspace" },
|
|
4
|
+
:gogrid => { :name => "Gogrid" },
|
|
5
|
+
:rhevm => { :name => "RHEVM" },
|
|
6
|
+
:rimuhosting => { :name => "RimuHosting"},
|
|
7
|
+
:opennebula => { :name => "Opennebula", :class => "OpennebulaDriver" },
|
|
8
|
+
:terremark => { :name => "Terremark"},
|
|
9
|
+
:mock => { :name => "Mock" }
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
DEFAULT_COLLECTIONS = [
|
|
13
|
+
:hardware_profiles,
|
|
14
|
+
:images,
|
|
15
|
+
:instances,
|
|
16
|
+
:instance_states,
|
|
17
|
+
:realms,
|
|
18
|
+
:storage_volumes,
|
|
19
|
+
:storage_snapshots
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
DRIVER=ENV['API_DRIVER'] ? ENV['API_DRIVER'].to_sym : :mock
|
|
23
|
+
|
|
24
|
+
def driver_name
|
|
25
|
+
DRIVERS[DRIVER][:name]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def driver_class_name
|
|
29
|
+
basename = DRIVERS[DRIVER][:class] || "#{driver_name}Driver"
|
|
30
|
+
"Deltacloud::Drivers::#{driver_name}::#{basename}"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def driver_source_name
|
|
34
|
+
File.join("deltacloud", "drivers", "#{DRIVER}", "#{DRIVER}_driver.rb")
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def driver_mock_source_name
|
|
38
|
+
return File.join('deltacloud', 'drivers', DRIVER.to_s, "#{DRIVER}_driver.rb") if driver_name.eql? 'Mock'
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def driver
|
|
42
|
+
require driver_source_name
|
|
43
|
+
#require 'deltacloud/base_driver/mock_driver.rb'
|
|
44
|
+
|
|
45
|
+
if Sinatra::Application.environment.eql? :test
|
|
46
|
+
require driver_mock_source_name if driver_mock_source_name
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
@driver ||= eval( driver_class_name ).new
|
|
50
|
+
end
|