bbrowning-deltacloud-core 0.0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. data/COPYING +502 -0
  2. data/Rakefile +85 -0
  3. data/bin/deltacloudd +88 -0
  4. data/config.ru +5 -0
  5. data/deltacloud.rb +14 -0
  6. data/lib/deltacloud/base_driver.rb +19 -0
  7. data/lib/deltacloud/base_driver/base_driver.rb +189 -0
  8. data/lib/deltacloud/base_driver/features.rb +159 -0
  9. data/lib/deltacloud/base_driver/mock_driver.rb +37 -0
  10. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +340 -0
  11. data/lib/deltacloud/drivers/ec2/ec2_mock_driver.rb +170 -0
  12. data/lib/deltacloud/drivers/gogrid/gogrid_client.rb +45 -0
  13. data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +322 -0
  14. data/lib/deltacloud/drivers/mock/mock_driver.rb +275 -0
  15. data/lib/deltacloud/drivers/opennebula/cloud_client.rb +116 -0
  16. data/lib/deltacloud/drivers/opennebula/occi_client.rb +204 -0
  17. data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +241 -0
  18. data/lib/deltacloud/drivers/rackspace/rackspace_client.rb +129 -0
  19. data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +150 -0
  20. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +254 -0
  21. data/lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb +84 -0
  22. data/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb +144 -0
  23. data/lib/deltacloud/drivers/terremark/terremark_driver.rb +261 -0
  24. data/lib/deltacloud/hardware_profile.rb +153 -0
  25. data/lib/deltacloud/helpers.rb +5 -0
  26. data/lib/deltacloud/helpers/application_helper.rb +56 -0
  27. data/lib/deltacloud/helpers/conversion_helper.rb +38 -0
  28. data/lib/deltacloud/helpers/hardware_profiles_helper.rb +35 -0
  29. data/lib/deltacloud/method_serializer.rb +84 -0
  30. data/lib/deltacloud/models/base_model.rb +58 -0
  31. data/lib/deltacloud/models/image.rb +26 -0
  32. data/lib/deltacloud/models/instance.rb +37 -0
  33. data/lib/deltacloud/models/instance_profile.rb +47 -0
  34. data/lib/deltacloud/models/realm.rb +25 -0
  35. data/lib/deltacloud/models/storage_snapshot.rb +26 -0
  36. data/lib/deltacloud/models/storage_volume.rb +27 -0
  37. data/lib/deltacloud/state_machine.rb +84 -0
  38. data/lib/deltacloud/validation.rb +70 -0
  39. data/lib/drivers.rb +38 -0
  40. data/lib/sinatra/accept_media_types.rb +128 -0
  41. data/lib/sinatra/lazy_auth.rb +56 -0
  42. data/lib/sinatra/rabbit.rb +272 -0
  43. data/lib/sinatra/respond_to.rb +269 -0
  44. data/lib/sinatra/static_assets.rb +83 -0
  45. data/lib/sinatra/url_for.rb +51 -0
  46. data/public/favicon.ico +0 -0
  47. data/public/images/grid.png +0 -0
  48. data/public/images/logo-wide.png +0 -0
  49. data/public/images/rails.png +0 -0
  50. data/public/images/topbar-bg.png +0 -0
  51. data/public/javascripts/application.js +32 -0
  52. data/public/javascripts/jquery-1.4.2.min.js +154 -0
  53. data/public/stylesheets/compiled/application.css +613 -0
  54. data/public/stylesheets/compiled/ie.css +31 -0
  55. data/public/stylesheets/compiled/print.css +27 -0
  56. data/public/stylesheets/compiled/screen.css +456 -0
  57. data/server.rb +342 -0
  58. data/support/fedora/deltacloudd +68 -0
  59. data/support/fedora/rubygem-deltacloud-core.spec +91 -0
  60. data/tests/deltacloud_test.rb +60 -0
  61. data/tests/images_test.rb +94 -0
  62. data/tests/instances_test.rb +136 -0
  63. data/tests/realms_test.rb +56 -0
  64. data/tests/storage_snapshots_test.rb +48 -0
  65. data/tests/storage_volumes_test.rb +48 -0
  66. data/torquebox-ec2-config.ru +8 -0
  67. data/views/accounts/index.html.haml +11 -0
  68. data/views/accounts/show.html.haml +30 -0
  69. data/views/api/show.html.haml +15 -0
  70. data/views/api/show.xml.haml +5 -0
  71. data/views/docs/collection.html.haml +37 -0
  72. data/views/docs/collection.xml.haml +14 -0
  73. data/views/docs/index.html.haml +15 -0
  74. data/views/docs/index.xml.haml +5 -0
  75. data/views/docs/operation.html.haml +31 -0
  76. data/views/docs/operation.xml.haml +10 -0
  77. data/views/errors/auth_exception.html.haml +8 -0
  78. data/views/errors/auth_exception.xml.haml +2 -0
  79. data/views/errors/backend_error.html.haml +17 -0
  80. data/views/errors/backend_error.xml.haml +8 -0
  81. data/views/errors/validation_failure.html.haml +11 -0
  82. data/views/errors/validation_failure.xml.haml +7 -0
  83. data/views/hardware_profiles/index.html.haml +25 -0
  84. data/views/hardware_profiles/index.xml.haml +4 -0
  85. data/views/hardware_profiles/show.html.haml +19 -0
  86. data/views/hardware_profiles/show.xml.haml +17 -0
  87. data/views/images/index.html.haml +30 -0
  88. data/views/images/index.xml.haml +7 -0
  89. data/views/images/show.html.haml +21 -0
  90. data/views/images/show.xml.haml +5 -0
  91. data/views/instance_states/show.gv.erb +45 -0
  92. data/views/instance_states/show.html.haml +31 -0
  93. data/views/instance_states/show.xml.haml +8 -0
  94. data/views/instances/index.html.haml +30 -0
  95. data/views/instances/index.xml.haml +23 -0
  96. data/views/instances/new.html.haml +55 -0
  97. data/views/instances/show.html.haml +43 -0
  98. data/views/instances/show.xml.haml +41 -0
  99. data/views/layout.html.haml +26 -0
  100. data/views/realms/index.html.haml +29 -0
  101. data/views/realms/index.xml.haml +12 -0
  102. data/views/realms/show.html.haml +15 -0
  103. data/views/realms/show.xml.haml +10 -0
  104. data/views/root/index.html.haml +4 -0
  105. data/views/storage_snapshots/index.html.haml +20 -0
  106. data/views/storage_snapshots/index.xml.haml +11 -0
  107. data/views/storage_snapshots/show.html.haml +14 -0
  108. data/views/storage_snapshots/show.xml.haml +9 -0
  109. data/views/storage_volumes/index.html.haml +21 -0
  110. data/views/storage_volumes/index.xml.haml +13 -0
  111. data/views/storage_volumes/show.html.haml +20 -0
  112. data/views/storage_volumes/show.xml.haml +13 -0
  113. metadata +361 -0
@@ -0,0 +1,153 @@
1
+
2
+ module Deltacloud
3
+ class HardwareProfile
4
+
5
+ UNITS = {
6
+ :memory => "MB",
7
+ :storage => "GB",
8
+ :architecture => "label",
9
+ :cpu => "count"
10
+ }
11
+
12
+ def self.unit(name)
13
+ UNITS[name]
14
+ end
15
+
16
+ class Property
17
+ attr_reader :name, :kind, :default
18
+ # kind == :range
19
+ attr_reader :first, :last
20
+ # kind == :enum
21
+ attr_reader :values
22
+ # kind == :fixed
23
+ attr_reader :value
24
+
25
+ def initialize(name, values, opts = {})
26
+ @name = name
27
+ if values.is_a?(Range)
28
+ @kind = :range
29
+ @first = values.first
30
+ @last = values.last
31
+ @default = values.first
32
+ elsif values.is_a?(Array)
33
+ @kind = :enum
34
+ @values = values
35
+ @default = values.first
36
+ else
37
+ @kind = :fixed
38
+ @value = values
39
+ @default = @value
40
+ end
41
+ @default = opts[:default] if opts[:default]
42
+ end
43
+
44
+ def unit
45
+ HardwareProfile.unit(name)
46
+ end
47
+
48
+ def param
49
+ "hwp_#{name}"
50
+ end
51
+
52
+ def fixed?
53
+ kind == :fixed
54
+ end
55
+
56
+ def to_param
57
+ return nil if kind == :fixed
58
+ if kind == :range
59
+ # FIXME: We can't validate ranges currently
60
+ args = [param, :string, :optional]
61
+ else
62
+ args = [param, :string, :optional, values.collect { |v| v.to_s} ]
63
+ end
64
+ Validation::Param.new(args)
65
+ end
66
+
67
+ def include?(v)
68
+ if kind == :fixed
69
+ return v == value
70
+ elsif kind == :range
71
+ return v >= first && v <= last
72
+ else
73
+ return values.include?(v)
74
+ end
75
+ end
76
+ end
77
+
78
+ class << self
79
+ def property(prop)
80
+ define_method(prop) do |*args|
81
+ values, opts, *ignored = *args
82
+ instvar = :"@#{prop}"
83
+ unless values.nil?
84
+ @properties[prop] = Property.new(prop, values, opts || {})
85
+ end
86
+ @properties[prop]
87
+ end
88
+ end
89
+ end
90
+
91
+ attr_reader :name
92
+ property :cpu
93
+ property :architecture
94
+ property :memory
95
+ property :storage
96
+
97
+ def initialize(name,&block)
98
+ @properties = {}
99
+ @name = name
100
+ instance_eval &block if block_given?
101
+ end
102
+
103
+ def each_property(&block)
104
+ @properties.each_value { |prop| yield prop }
105
+ end
106
+
107
+ def properties
108
+ @properties.values
109
+ end
110
+
111
+ def property(name)
112
+ @properties[name.to_sym]
113
+ end
114
+
115
+ def default?(prop, v)
116
+ p = @properties[prop.to_sym]
117
+ p && p.default.to_s == v
118
+ end
119
+
120
+ def to_hash
121
+ props = []
122
+ self.each_property do |p|
123
+ if p.kind.eql? :fixed
124
+ props << { :kind => p.kind, :value => p.value, :name => p.name, :unit => p.unit }
125
+ else
126
+ param = { :operation => "create", :method => "post", :name => p.name }
127
+ if p.kind.eql? :range
128
+ param[:range] = { :first => p.first, :last => p.last }
129
+ elsif p.kind.eql? :enum
130
+ param[:enum] = p.values.collect { |v| { :entry => v } }
131
+ end
132
+ param
133
+ props << { :kind => p.kind, :value => p.default, :name => p.name, :unit => p.unit, :param => param }
134
+ end
135
+ end
136
+ {
137
+ :id => self.name,
138
+ :properties => props
139
+ }
140
+ end
141
+
142
+ def include?(prop, v)
143
+ p = @properties[prop]
144
+ p.nil? || p.include?(v)
145
+ end
146
+
147
+ def params
148
+ @properties.values.inject([]) { |m, prop|
149
+ m << prop.to_param
150
+ }.compact
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,5 @@
1
+ require 'deltacloud/helpers/application_helper'
2
+ require 'deltacloud/helpers/conversion_helper'
3
+ require 'deltacloud/helpers/hardware_profiles_helper'
4
+
5
+ helpers ApplicationHelper, ConversionHelper, HardwareProfilesHelper
@@ -0,0 +1,56 @@
1
+ #
2
+ # Copyright (C) 2009 Red Hat, Inc.
3
+ #
4
+ # This library is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU Lesser General Public
6
+ # License as published by the Free Software Foundation; either
7
+ # version 2.1 of the License, or (at your option) any later version.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
+
18
+ # Methods added to this helper will be available to all templates in the application.
19
+ module ApplicationHelper
20
+
21
+ def bread_crumb
22
+ s = "<ul class='breadcrumb'><li class='first'><a href='#{url_for('/')}'>&#948</a></li>"
23
+ url = request.path_info.split('?') #remove extra query string parameters
24
+ levels = url[0].split('/') #break up url into different levels
25
+ levels.each_with_index do |level, index|
26
+ unless level.blank?
27
+ if index == levels.size-1 ||
28
+ (level == levels[levels.size-2] && levels[levels.size-1].to_i > 0)
29
+ s += "<li class='subsequent'>#{level.gsub(/_/, ' ')}</li>\n" unless level.to_i > 0
30
+ else
31
+ link = levels.slice(0, index+1).join("/")
32
+ s += "<li class='subsequent'><a href=\"#{url_for(link)}\">#{level.gsub(/_/, ' ')}</a></li>\n"
33
+ end
34
+ end
35
+ end
36
+ s+="</ul>"
37
+ end
38
+
39
+ def instance_action_method(action)
40
+ collections[:instances].operations[action.to_sym].method
41
+ end
42
+
43
+ def driver_has_feature?(feature_name)
44
+ not driver.features(:instances).select{ |f| f.name.eql?(feature_name) }.empty?
45
+ end
46
+
47
+ def driver_has_auth_features?
48
+ driver_has_feature?(:authentication_password) || driver_has_feature?(:authentication_key)
49
+ end
50
+
51
+ def driver_auth_feature_name
52
+ return 'key' if driver_has_feature?(:authentication_key)
53
+ return 'password' if driver_has_feature?(:authentication_password)
54
+ end
55
+
56
+ end
@@ -0,0 +1,38 @@
1
+ #
2
+ # Copyright (C) 2009 Red Hat, Inc.
3
+ #
4
+ # This library is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU Lesser General Public
6
+ # License as published by the Free Software Foundation; either
7
+ # version 2.1 of the License, or (at your option) any later version.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
+
18
+
19
+ require 'deltacloud/base_driver'
20
+
21
+ module ConversionHelper
22
+
23
+ def convert_to_json(type, obj)
24
+ if ( [ :flavor, :account, :image, :realm, :instance, :storage_volume, :storage_snapshot, :hardware_profile ].include?( type ) )
25
+ if Array.eql?(obj.class)
26
+ data = obj.collect do |o|
27
+ o.to_hash.merge({ :href => self.send(:"#{type}_url", type.eql?(:hardware_profile) ? o.name : o.id ) })
28
+ end
29
+ type = type.to_s.pluralize
30
+ else
31
+ data = obj.to_hash
32
+ data.merge!({ :href => self.send(:"#{type}_url", data[:id]) })
33
+ end
34
+ return { :"#{type}" => data }.to_json
35
+ end
36
+ end
37
+
38
+ end
@@ -0,0 +1,35 @@
1
+ module HardwareProfilesHelper
2
+
3
+ def format_hardware_property(prop)
4
+ return "&empty;" unless prop
5
+ u = hardware_property_unit(prop)
6
+ case prop.kind
7
+ when :range
8
+ "#{prop.first} #{u} - #{prop.last} #{u} (default: #{prop.default} #{u})"
9
+ when :enum
10
+ prop.values.collect{ |v| "#{v} #{u}"}.join(', ') + " (default: #{prop.default} #{u})"
11
+ else
12
+ "#{prop.value} #{u}"
13
+ end
14
+ end
15
+
16
+ def format_instance_profile(ip)
17
+ o = ip.overrides.collect do |p, v|
18
+ u = hardware_property_unit(p)
19
+ "#{p} = #{v} #{u}"
20
+ end
21
+ if o.empty?
22
+ ""
23
+ else
24
+ "with #{o.join(", ")}"
25
+ end
26
+ end
27
+
28
+ private
29
+ def hardware_property_unit(prop)
30
+ u = ::Deltacloud::HardwareProfile::unit(prop)
31
+ u = "" if ["label", "count"].include?(u)
32
+ u = "vcpus" if prop == :cpu
33
+ u
34
+ end
35
+ end
@@ -0,0 +1,84 @@
1
+ #
2
+ # Copyright (C) 2009 Red Hat, Inc.
3
+ #
4
+ # This library is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU Lesser General Public
6
+ # License as published by the Free Software Foundation; either
7
+ # version 2.1 of the License, or (at your option) any later version.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
+
18
+ require 'base64'
19
+ require 'digest'
20
+
21
+ module MethodSerializer
22
+
23
+ module Cache
24
+
25
+ def cache_dir
26
+ storage_dir = $methods_cache_dir || File.join(File.dirname(__FILE__), 'cache')
27
+ class_dir = self.class.name.split('::').last
28
+ class_dir ||= self.class.name
29
+ File.join(storage_dir, class_dir.downcase)
30
+ end
31
+
32
+ def serialize_data(method_name, args, data)
33
+ File.open(cache_file_name(method_name, args), 'w') do |f|
34
+ f.puts(Base64.encode64(Marshal.dump(data)))
35
+ end
36
+ return data
37
+ end
38
+
39
+ def deserialize_data(method_name, args)
40
+ begin
41
+ data = File.readlines(cache_file_name(method_name, args)).join
42
+ Marshal.load(Base64.decode64(data))
43
+ rescue Errno::ENOENT
44
+ return false
45
+ end
46
+ end
47
+
48
+ def args_hash(args)
49
+ if args.class == Hash
50
+ args = args.to_a.collect {|i| [i[0].to_s, i[1]]}.sort
51
+ end
52
+ Digest::SHA1.hexdigest(args.to_s)
53
+ end
54
+
55
+ def cache_file_name(method_name, args)
56
+ FileUtils.mkdir_p(cache_dir) unless File.directory?(cache_dir)
57
+ method_name = $scenario_prefix ? "#{$scenario_prefix}_#{method_name}" : method_name
58
+ File.join(cache_dir, "#{method_name}.#{args_hash(args)}")
59
+ end
60
+
61
+ def self.wrap_methods(c, opts={})
62
+ $methods_cache_dir = opts[:cache_dir]
63
+ $scenario_prefix = nil
64
+ c.class_eval do
65
+ cached_methods.each do |m|
66
+ next if c.instance_methods(false).include?("original_#{m}")
67
+ alias_method "original_#{m}".to_sym, m.to_sym
68
+ define_method m.to_sym do |*args|
69
+ args = args.first if args.size.eql?(1) and not args.first.class.eql?(Array)
70
+ output = deserialize_data(m, args)
71
+ unless output
72
+ output = method("original_#{m}".to_sym).to_proc[args]
73
+ return serialize_data(m, args, output)
74
+ else
75
+ return output
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ end
83
+
84
+ end
@@ -0,0 +1,58 @@
1
+ #
2
+ # Copyright (C) 2009 Red Hat, Inc.
3
+ #
4
+ # This library is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU Lesser General Public
6
+ # License as published by the Free Software Foundation; either
7
+ # version 2.1 of the License, or (at your option) any later version.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
+
18
+
19
+ class BaseModel
20
+
21
+ def initialize(init=nil)
22
+ if ( init )
23
+ @id=init[:id]
24
+ init.each{|k,v|
25
+ self.send( "#{k}=", v ) if ( self.respond_to?( "#{k}=" ) )
26
+ }
27
+ end
28
+ end
29
+
30
+ def self.attr_accessor(*vars)
31
+ @attributes ||= [:id]
32
+ @attributes.concat vars
33
+ super
34
+ end
35
+
36
+ def self.attributes
37
+ @attributes
38
+ end
39
+
40
+ def attributes
41
+ self.class.attributes
42
+ end
43
+
44
+ def id
45
+ @id
46
+ end
47
+
48
+ def to_hash
49
+ out = {}
50
+ self.attributes.each { |attribute| out.merge!({ attribute => self.send(:"#{attribute}") } ) }
51
+ out
52
+ end
53
+
54
+ def to_json
55
+ self.to_hash.to_json
56
+ end
57
+
58
+ end
@@ -0,0 +1,26 @@
1
+ #
2
+ # Copyright (C) 2009 Red Hat, Inc.
3
+ #
4
+ # This library is free software; you can redistribute it and/or
5
+ # modify it under the terms of the GNU Lesser General Public
6
+ # License as published by the Free Software Foundation; either
7
+ # version 2.1 of the License, or (at your option) any later version.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
+
18
+
19
+ class Image < BaseModel
20
+
21
+ attr_accessor :name
22
+ attr_accessor :owner_id
23
+ attr_accessor :description
24
+ attr_accessor :architecture
25
+
26
+ end