deltacloud-core 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. data/COPYING +502 -0
  2. data/Rakefile +108 -0
  3. data/bin/deltacloudd +88 -0
  4. data/config.ru +5 -0
  5. data/deltacloud.rb +14 -0
  6. data/lib/converters/xml_converter.rb +133 -0
  7. data/lib/deltacloud/base_driver.rb +19 -0
  8. data/lib/deltacloud/base_driver/base_driver.rb +189 -0
  9. data/lib/deltacloud/base_driver/features.rb +144 -0
  10. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +318 -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 +239 -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/rimu/rimu_hosting_client.rb +87 -0
  22. data/lib/deltacloud/drivers/rimu/rimu_hosting_driver.rb +143 -0
  23. data/lib/deltacloud/hardware_profile.rb +131 -0
  24. data/lib/deltacloud/helpers.rb +5 -0
  25. data/lib/deltacloud/helpers/application_helper.rb +38 -0
  26. data/lib/deltacloud/helpers/conversion_helper.rb +39 -0
  27. data/lib/deltacloud/helpers/hardware_profiles_helper.rb +35 -0
  28. data/lib/deltacloud/models/base_model.rb +58 -0
  29. data/lib/deltacloud/models/image.rb +26 -0
  30. data/lib/deltacloud/models/instance.rb +37 -0
  31. data/lib/deltacloud/models/instance_profile.rb +47 -0
  32. data/lib/deltacloud/models/realm.rb +25 -0
  33. data/lib/deltacloud/models/storage_snapshot.rb +26 -0
  34. data/lib/deltacloud/models/storage_volume.rb +27 -0
  35. data/lib/deltacloud/state_machine.rb +84 -0
  36. data/lib/deltacloud/validation.rb +70 -0
  37. data/lib/drivers.rb +37 -0
  38. data/lib/sinatra/lazy_auth.rb +56 -0
  39. data/lib/sinatra/rabbit.rb +272 -0
  40. data/lib/sinatra/respond_to.rb +262 -0
  41. data/lib/sinatra/static_assets.rb +83 -0
  42. data/lib/sinatra/url_for.rb +44 -0
  43. data/public/favicon.ico +0 -0
  44. data/public/images/grid.png +0 -0
  45. data/public/images/logo-wide.png +0 -0
  46. data/public/images/rails.png +0 -0
  47. data/public/images/topbar-bg.png +0 -0
  48. data/public/javascripts/application.js +2 -0
  49. data/public/javascripts/controls.js +963 -0
  50. data/public/javascripts/dragdrop.js +973 -0
  51. data/public/javascripts/effects.js +1128 -0
  52. data/public/javascripts/prototype.js +4320 -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 +340 -0
  58. data/tests/deltacloud_test.rb +60 -0
  59. data/tests/images_test.rb +94 -0
  60. data/tests/instances_test.rb +136 -0
  61. data/tests/realms_test.rb +56 -0
  62. data/tests/storage_snapshots_test.rb +48 -0
  63. data/tests/storage_volumes_test.rb +48 -0
  64. data/views/accounts/index.html.haml +11 -0
  65. data/views/accounts/show.html.haml +30 -0
  66. data/views/api/show.html.haml +15 -0
  67. data/views/api/show.xml.haml +5 -0
  68. data/views/docs/collection.html.haml +37 -0
  69. data/views/docs/collection.xml.haml +14 -0
  70. data/views/docs/index.html.haml +15 -0
  71. data/views/docs/index.xml.haml +5 -0
  72. data/views/docs/operation.html.haml +31 -0
  73. data/views/docs/operation.xml.haml +10 -0
  74. data/views/errors/auth_exception.html.haml +8 -0
  75. data/views/errors/auth_exception.xml.haml +2 -0
  76. data/views/errors/backend_error.html.haml +17 -0
  77. data/views/errors/backend_error.xml.haml +8 -0
  78. data/views/errors/validation_failure.html.haml +11 -0
  79. data/views/errors/validation_failure.xml.haml +7 -0
  80. data/views/hardware_profiles/index.html.haml +25 -0
  81. data/views/hardware_profiles/index.xml.haml +4 -0
  82. data/views/hardware_profiles/show.html.haml +19 -0
  83. data/views/hardware_profiles/show.xml.haml +17 -0
  84. data/views/images/index.html.haml +30 -0
  85. data/views/images/index.xml.haml +7 -0
  86. data/views/images/show.html.haml +21 -0
  87. data/views/images/show.xml.haml +5 -0
  88. data/views/instance_states/show.gv.erb +45 -0
  89. data/views/instance_states/show.html.haml +31 -0
  90. data/views/instance_states/show.xml.haml +8 -0
  91. data/views/instances/index.html.haml +29 -0
  92. data/views/instances/index.xml.haml +23 -0
  93. data/views/instances/new.html.haml +49 -0
  94. data/views/instances/show.html.haml +42 -0
  95. data/views/instances/show.xml.haml +28 -0
  96. data/views/layout.html.haml +23 -0
  97. data/views/realms/index.html.haml +29 -0
  98. data/views/realms/index.xml.haml +12 -0
  99. data/views/realms/show.html.haml +15 -0
  100. data/views/realms/show.xml.haml +10 -0
  101. data/views/root/index.html.haml +4 -0
  102. data/views/storage_snapshots/index.html.haml +20 -0
  103. data/views/storage_snapshots/index.xml.haml +11 -0
  104. data/views/storage_snapshots/show.html.haml +14 -0
  105. data/views/storage_snapshots/show.xml.haml +9 -0
  106. data/views/storage_volumes/index.html.haml +21 -0
  107. data/views/storage_volumes/index.xml.haml +13 -0
  108. data/views/storage_volumes/show.html.haml +20 -0
  109. data/views/storage_volumes/show.xml.haml +13 -0
  110. metadata +311 -0
@@ -0,0 +1,131 @@
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 include?(prop, v)
121
+ p = @properties[prop]
122
+ p.nil? || p.include?(v)
123
+ end
124
+
125
+ def params
126
+ @properties.values.inject([]) { |m, prop|
127
+ m << prop.to_param
128
+ }.compact
129
+ end
130
+ end
131
+ 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,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
+ # 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='/'>&#948</a></li>"
23
+ url = request.path.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=\"#{link}\">#{level.gsub(/_/, ' ')}</a></li>\n"
33
+ end
34
+ end
35
+ end
36
+ s+="</ul>"
37
+ end
38
+ end
@@ -0,0 +1,39 @@
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
+ require 'converters/xml_converter'
21
+
22
+ module ConversionHelper
23
+
24
+ def convert_to_json(type, obj)
25
+ if ( [ :flavor, :account, :image, :realm, :instance, :storage_volume, :storage_snapshot ].include?( type ) )
26
+ if Array.eql?(obj.class)
27
+ data = obj.collect do |o|
28
+ o.to_hash.merge({ :href => self.send(:"#{type}_url", o.id ) })
29
+ end
30
+ type = type.to_s.pluralize
31
+ else
32
+ data = obj.to_hash
33
+ data.merge!({ :href => self.send(:"#{type}_url", data[:id]) })
34
+ end
35
+ return { :"#{type}" => data }.to_json
36
+ end
37
+ end
38
+
39
+ 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,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
@@ -0,0 +1,37 @@
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 Instance < BaseModel
20
+
21
+ attr_accessor :owner_id
22
+ attr_accessor :image_id
23
+ attr_accessor :name
24
+ attr_accessor :realm_id
25
+ attr_accessor :state
26
+ attr_accessor :actions
27
+ attr_accessor :public_addresses
28
+ attr_accessor :private_addresses
29
+ attr_accessor :instance_profile
30
+
31
+ def initialize(init=nil)
32
+ super(init)
33
+ self.actions = [] if self.actions.nil?
34
+ self.public_addresses = [] if self.public_addresses.nil?
35
+ self.private_addresses = [] if self.private_addresses.nil?
36
+ end
37
+ end
@@ -0,0 +1,47 @@
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
+ # Model to store the hardware profile applied to an instance together with
19
+ # any instance-specific overrides
20
+ class InstanceProfile < BaseModel
21
+ attr_accessor :memory
22
+ attr_accessor :storage
23
+ attr_accessor :architecture
24
+ attr_accessor :cpu
25
+
26
+ def initialize(hwp_name, args = {})
27
+ opts = args.inject({ :id => hwp_name.to_s }) do |m, e|
28
+ k, v = e
29
+ m[$1] = v if k.to_s =~ /^hwp_(.*)$/
30
+ m
31
+ end
32
+ super(opts)
33
+ end
34
+
35
+ def name
36
+ id
37
+ end
38
+
39
+ def overrides
40
+ [:memory, :storage, :architecture, :cpu].inject({}) do |h, p|
41
+ if v = instance_variable_get("@#{p}")
42
+ h[p] = v
43
+ end
44
+ h
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,25 @@
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 Realm < BaseModel
20
+
21
+ attr_accessor :name
22
+ attr_accessor :limit
23
+ attr_accessor :state
24
+
25
+ end