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.
Files changed (220) hide show
  1. data/Rakefile +40 -28
  2. data/bin/deltacloud-db-upgrade +24 -0
  3. data/bin/deltacloudd +20 -9
  4. data/config.ru +12 -53
  5. data/db/migrations/1_add_realm_to_machine_template.rb +23 -0
  6. data/deltacloud-core.gemspec +11 -5
  7. data/lib/cimi/collections.rb +4 -31
  8. data/lib/cimi/collections/address_templates.rb +2 -5
  9. data/lib/cimi/collections/addresses.rb +2 -5
  10. data/lib/cimi/collections/base.rb +18 -6
  11. data/lib/cimi/collections/credentials.rb +2 -5
  12. data/lib/cimi/collections/machine_images.rb +2 -1
  13. data/lib/cimi/collections/machine_templates.rb +2 -5
  14. data/lib/cimi/collections/machines.rb +6 -9
  15. data/lib/cimi/collections/network_ports.rb +3 -3
  16. data/lib/cimi/collections/networks.rb +5 -8
  17. data/lib/cimi/collections/system_templates.rb +72 -0
  18. data/lib/cimi/collections/systems.rb +194 -0
  19. data/lib/cimi/collections/volume_configurations.rb +1 -1
  20. data/lib/cimi/collections/volume_images.rb +2 -1
  21. data/lib/cimi/collections/volume_templates.rb +3 -2
  22. data/lib/cimi/collections/volumes.rb +2 -2
  23. data/lib/cimi/dependencies.rb +0 -2
  24. data/lib/cimi/helpers/cimi_helper.rb +12 -57
  25. data/lib/cimi/helpers/database_helper.rb +0 -4
  26. data/lib/cimi/models.rb +25 -14
  27. data/lib/cimi/models/address.rb +4 -31
  28. data/lib/cimi/models/address_create.rb +51 -0
  29. data/lib/cimi/models/address_template.rb +8 -52
  30. data/lib/cimi/models/address_template_create.rb +44 -0
  31. data/lib/cimi/models/base.rb +44 -6
  32. data/lib/cimi/models/cloud_entry_point.rb +1 -1
  33. data/lib/cimi/models/credential.rb +1 -1
  34. data/lib/cimi/models/credential_create.rb +46 -0
  35. data/lib/cimi/models/credential_template.rb +24 -0
  36. data/lib/cimi/models/machine.rb +1 -71
  37. data/lib/cimi/models/machine_configuration.rb +3 -3
  38. data/lib/cimi/models/machine_create.rb +49 -0
  39. data/lib/cimi/models/machine_image.rb +2 -25
  40. data/lib/cimi/models/machine_image_create.rb +41 -0
  41. data/lib/cimi/models/machine_template.rb +14 -34
  42. data/lib/cimi/models/machine_template_create.rb +33 -0
  43. data/lib/cimi/models/network.rb +0 -38
  44. data/lib/cimi/models/network_create.rb +43 -0
  45. data/lib/cimi/models/network_port.rb +17 -17
  46. data/lib/cimi/models/network_template.rb +2 -3
  47. data/lib/cimi/models/resource.rb +22 -3
  48. data/lib/cimi/models/schema.rb +94 -8
  49. data/lib/cimi/models/system.rb +67 -0
  50. data/lib/cimi/models/system_template.rb +63 -0
  51. data/lib/cimi/models/volume.rb +2 -42
  52. data/lib/cimi/models/volume_configuration.rb +4 -4
  53. data/lib/cimi/models/volume_create.rb +58 -0
  54. data/lib/cimi/models/volume_image.rb +8 -17
  55. data/lib/cimi/models/volume_image_create.rb +47 -0
  56. data/lib/cimi/models/volume_template.rb +6 -19
  57. data/lib/cimi/models/volume_template_create.rb +33 -0
  58. data/lib/db.rb +14 -22
  59. data/lib/db/volume_template.rb +1 -1
  60. data/lib/deltacloud/api.rb +6 -5
  61. data/lib/deltacloud/collections.rb +4 -27
  62. data/lib/deltacloud/collections/base.rb +4 -0
  63. data/lib/deltacloud/collections/images.rb +1 -1
  64. data/lib/deltacloud/collections/instances.rb +2 -2
  65. data/lib/deltacloud/core_ext/array.rb +1 -0
  66. data/lib/deltacloud/core_ext/integer.rb +13 -9
  67. data/lib/deltacloud/core_ext/string.rb +45 -28
  68. data/lib/deltacloud/drivers/arubacloud/arubacloud_driver.rb +0 -9
  69. data/lib/deltacloud/drivers/base_driver.rb +45 -16
  70. data/lib/deltacloud/drivers/digitalocean/digitalocean_driver.rb +78 -8
  71. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +13 -9
  72. data/lib/deltacloud/drivers/fgcp/fgcp_client.rb +44 -0
  73. data/lib/deltacloud/drivers/fgcp/fgcp_driver.rb +164 -90
  74. data/lib/deltacloud/drivers/fgcp/fgcp_driver_cimi_methods.rb +74 -0
  75. data/lib/deltacloud/drivers/mock/data/instances/inst0.yml +3 -3
  76. data/lib/deltacloud/drivers/mock/data/instances/inst1.yml +3 -3
  77. data/lib/deltacloud/drivers/mock/data/instances/inst2.yml +3 -3
  78. data/lib/deltacloud/drivers/mock/mock_client.rb +17 -1
  79. data/lib/deltacloud/drivers/mock/mock_driver.rb +161 -204
  80. data/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb +80 -0
  81. data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +6 -1
  82. data/lib/deltacloud/drivers/openstack/openstack_driver.rb +61 -68
  83. data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +0 -9
  84. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +11 -6
  85. data/lib/deltacloud/drivers/terremark/terremark_driver.rb +0 -8
  86. data/lib/deltacloud/drivers/vsphere/vsphere_client.rb +11 -4
  87. data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +0 -12
  88. data/lib/deltacloud/helpers/collection_helper.rb +106 -0
  89. data/lib/deltacloud/helpers/deltacloud_helper.rb +12 -8
  90. data/lib/deltacloud/models/address.rb +19 -17
  91. data/lib/deltacloud/models/base_model.rb +29 -26
  92. data/lib/deltacloud/models/blob.rb +22 -20
  93. data/lib/deltacloud/models/bucket.rb +21 -16
  94. data/lib/deltacloud/models/firewall.rb +18 -16
  95. data/lib/deltacloud/models/firewall_rule.rb +22 -20
  96. data/lib/deltacloud/models/image.rb +29 -28
  97. data/lib/deltacloud/models/instance.rb +92 -94
  98. data/lib/deltacloud/models/instance_address.rb +42 -40
  99. data/lib/deltacloud/models/instance_profile.rb +28 -26
  100. data/lib/deltacloud/models/key.rb +47 -45
  101. data/lib/deltacloud/models/load_balancer.rb +32 -31
  102. data/lib/deltacloud/models/metric.rb +76 -29
  103. data/lib/deltacloud/models/provider.rb +15 -13
  104. data/lib/deltacloud/models/realm.rb +15 -21
  105. data/lib/deltacloud/models/storage_snapshot.rb +23 -19
  106. data/lib/deltacloud/models/storage_volume.rb +35 -34
  107. data/lib/deltacloud/version.rb +1 -1
  108. data/lib/deltacloud_rack.rb +22 -0
  109. data/lib/initialize.rb +28 -0
  110. data/lib/initializers/database_initialize.rb +76 -0
  111. data/lib/initializers/frontend_initialize.rb +42 -0
  112. data/lib/initializers/mock_initialize.rb +33 -0
  113. data/lib/sinatra/rack_logger.rb +35 -24
  114. data/tests/cimi/collections/cloud_entry_point_test.rb +1 -7
  115. data/tests/cimi/collections/machine_images_test.rb +2 -2
  116. data/tests/cimi/collections/machine_templates_test.rb +75 -0
  117. data/tests/cimi/collections/machines_test.rb +2 -2
  118. data/tests/cimi/collections/system_templates_test.rb +41 -0
  119. data/tests/cimi/collections/systems_test.rb +50 -0
  120. data/tests/cimi/db/database_helper_test.rb +17 -25
  121. data/tests/cimi/db/db_helper.rb +1 -12
  122. data/tests/cimi/db/entity_test.rb +7 -8
  123. data/tests/cimi/model/machine_create_spec.rb +44 -0
  124. data/tests/cimi/model/machine_template_spec.rb +29 -0
  125. data/tests/cimi/model/resource_spec.rb +40 -0
  126. data/tests/cimi/model/schema_spec.rb +37 -0
  127. data/tests/cimi/spec_helper.rb +3 -0
  128. data/tests/deltacloud/collections/buckets_collection_test.rb +1 -1
  129. data/tests/deltacloud/collections/drivers_collection_test.rb +2 -2
  130. data/tests/deltacloud/collections/hardware_profiles_collection_test.rb +2 -2
  131. data/tests/deltacloud/collections/images_collection_test.rb +2 -2
  132. data/tests/deltacloud/collections/instance_states_collection_test.rb +1 -1
  133. data/tests/deltacloud/collections/instances_collection_test.rb +6 -3
  134. data/tests/deltacloud/collections/keys_collection_test.rb +2 -2
  135. data/tests/deltacloud/collections/realms_collection_test.rb +2 -2
  136. data/tests/deltacloud/collections/storage_snapshots_collection_test.rb +2 -2
  137. data/tests/deltacloud/collections/storage_volumes_collection_test.rb +2 -2
  138. data/tests/deltacloud/collections_test.rb +5 -5
  139. data/tests/deltacloud/common.rb +2 -13
  140. data/tests/deltacloud/launcher_test.rb +3 -3
  141. data/tests/deltacloud/rack_test.rb +2 -2
  142. data/tests/deltacloud/server_test.rb +1 -1
  143. data/tests/drivers/base/base_driver_test.rb +5 -5
  144. data/tests/drivers/base/common.rb +2 -12
  145. data/tests/drivers/ec2/buckets_test.rb +1 -1
  146. data/tests/drivers/ec2/images_test.rb +2 -2
  147. data/tests/drivers/ec2/instance_test.rb +6 -6
  148. data/tests/drivers/ec2/keys_test.rb +3 -3
  149. data/tests/drivers/ec2/realms_test.rb +2 -2
  150. data/tests/drivers/ec2/storage_snapshots_test.rb +1 -1
  151. data/tests/drivers/fgcp/common.rb +32 -0
  152. data/tests/drivers/fgcp/firewall_test.rb +70 -0
  153. data/tests/drivers/fgcp/hardware_profiles_test.rb +61 -0
  154. data/tests/drivers/fgcp/images_test.rb +46 -0
  155. data/tests/drivers/fgcp/provider_test.rb +27 -0
  156. data/tests/drivers/fgcp/realms_test.rb +53 -0
  157. data/tests/drivers/fgcp/storage_volumes_test.rb +58 -0
  158. data/tests/drivers/gogrid/images_test.rb +2 -2
  159. data/tests/drivers/gogrid/instances_test.rb +2 -2
  160. data/tests/drivers/gogrid/realms_test.rb +2 -2
  161. data/tests/drivers/mock/images_test.rb +4 -4
  162. data/tests/drivers/mock/instances_test.rb +9 -9
  163. data/tests/drivers/mock/keys_test.rb +3 -3
  164. data/tests/drivers/mock/realms_test.rb +2 -2
  165. data/tests/drivers/mock/storage_snapshots_test.rb +2 -2
  166. data/tests/drivers/mock/storage_volumes_test.rb +4 -4
  167. data/tests/drivers/models/instance_test.rb +2 -2
  168. data/tests/drivers/openstack/images_test.rb +2 -2
  169. data/tests/drivers/openstack/instances_test.rb +2 -3
  170. data/tests/drivers/openstack/keys_test.rb +1 -1
  171. data/tests/drivers/openstack/realms_test.rb +2 -11
  172. data/tests/drivers/rhevm/common.rb +33 -12
  173. data/tests/drivers/rhevm/images_test.rb +20 -12
  174. data/tests/drivers/rhevm/instance_test.rb +62 -46
  175. data/tests/drivers/rhevm/provider_test.rb +12 -6
  176. data/tests/drivers/rhevm/realms_test.rb +15 -9
  177. data/tests/ec2/query_parser_test.rb +1 -1
  178. data/tests/test_helper.rb +68 -12
  179. data/views/addresses/show.html.haml +1 -1
  180. data/views/buckets/show.html.haml +1 -1
  181. data/views/errors/{500.html.haml → common.html.haml} +0 -0
  182. data/views/errors/common.xml.haml +17 -0
  183. data/views/firewalls/index.xml.haml +2 -2
  184. data/views/firewalls/new.html.haml +2 -2
  185. data/views/images/show.html.haml +1 -1
  186. data/views/instances/run_command.html.haml +1 -1
  187. data/views/instances/show.html.haml +3 -3
  188. data/views/keys/index.html.haml +1 -0
  189. data/views/keys/show.html.haml +8 -4
  190. data/views/keys/show.xml.haml +3 -2
  191. data/views/load_balancers/new.html.haml +1 -1
  192. data/views/load_balancers/show.html.haml +2 -2
  193. data/views/metrics/show.html.haml +1 -1
  194. data/views/realms/index.html.haml +0 -2
  195. data/views/realms/show.html.haml +0 -4
  196. data/views/realms/show.xml.haml +0 -3
  197. data/views/storage_snapshots/index.html.haml +1 -1
  198. data/views/storage_snapshots/new.html.haml +1 -1
  199. data/views/storage_volumes/new.html.haml +2 -2
  200. data/views/storage_volumes/show.html.haml +3 -3
  201. metadata +90 -41
  202. data/views/errors/400.html.haml +0 -41
  203. data/views/errors/400.xml.haml +0 -3
  204. data/views/errors/401.html.haml +0 -26
  205. data/views/errors/401.xml.haml +0 -3
  206. data/views/errors/403.html.haml +0 -42
  207. data/views/errors/403.xml.haml +0 -9
  208. data/views/errors/404.html.haml +0 -28
  209. data/views/errors/404.xml.haml +0 -3
  210. data/views/errors/405.html.haml +0 -29
  211. data/views/errors/405.xml.haml +0 -5
  212. data/views/errors/409.html.haml +0 -47
  213. data/views/errors/409.xml.haml +0 -11
  214. data/views/errors/500.xml.haml +0 -13
  215. data/views/errors/501.html.haml +0 -44
  216. data/views/errors/501.xml.haml +0 -1
  217. data/views/errors/502.html.haml +0 -44
  218. data/views/errors/502.xml.haml +0 -1
  219. data/views/errors/504.html.haml +0 -43
  220. data/views/errors/504.xml.haml +0 -1
@@ -14,45 +14,46 @@
14
14
  # License for the specific language governing permissions and limitations
15
15
  # under the License.
16
16
 
17
+ module Deltacloud
18
+ class LoadBalancer < BaseModel
17
19
 
18
- class LoadBalancer < BaseModel
20
+ attr_accessor :realms
21
+ attr_accessor :listeners
22
+ attr_accessor :instances
23
+ attr_accessor :public_addresses
24
+ attr_accessor :created_at
19
25
 
20
- attr_accessor :realms
21
- attr_accessor :listeners
22
- attr_accessor :instances
23
- attr_accessor :public_addresses
24
- attr_accessor :created_at
25
-
26
- def add_listener(opts)
27
- @listeners << Listener.new(opts)
28
- end
29
-
30
- def to_hash(context)
31
- {
32
- :id => self.id,
33
- :href => context.load_balancer_url(self.id),
34
- :realms => realms,
35
- :listeners => listeners.map { |l| l.to_hash(context) },
36
- :instances => instances.map { |i| i.to_hash(context) },
37
- :public_addresses => public_addresses,
38
- :created_at => created_at
39
- }
40
- end
41
-
42
- class Listener < BaseModel
43
- attr_accessor :protocol
44
- attr_accessor :load_balancer_port
45
- attr_accessor :instance_port
26
+ def add_listener(opts)
27
+ @listeners << Listener.new(opts)
28
+ end
46
29
 
47
30
  def to_hash(context)
48
31
  {
49
32
  :id => self.id,
50
- :protocol => protocol,
51
- :load_balancer_port => load_balancer_port,
52
- :instance_port => instance_port
33
+ :href => context.load_balancer_url(self.id),
34
+ :realms => realms,
35
+ :listeners => listeners.map { |l| l.to_hash(context) },
36
+ :instances => instances.map { |i| i.to_hash(context) },
37
+ :public_addresses => public_addresses,
38
+ :created_at => created_at
53
39
  }
54
40
  end
41
+
42
+ class Listener < BaseModel
43
+ attr_accessor :protocol
44
+ attr_accessor :load_balancer_port
45
+ attr_accessor :instance_port
46
+
47
+ def to_hash(context)
48
+ {
49
+ :id => self.id,
50
+ :protocol => protocol,
51
+ :load_balancer_port => load_balancer_port,
52
+ :instance_port => instance_port
53
+ }
54
+ end
55
+ end
56
+
55
57
  end
56
58
 
57
59
  end
58
-
@@ -13,44 +13,91 @@
13
13
  # License for the specific language governing permissions and limitations
14
14
  # under the License.
15
15
 
16
- class Metric < BaseModel
16
+ module Deltacloud
17
+ class Metric < BaseModel
17
18
 
18
- attr_accessor :entity
19
- attr_accessor :properties
19
+ attr_accessor :entity
20
+ attr_accessor :properties
20
21
 
21
- def unknown?
22
- self.entity == :unknown
23
- end
24
-
25
- def add_property(name, values=nil)
26
- self.properties ||= []
27
- return self if self.properties.any? { |p| p.name == name }
28
- self.properties << Property.new(name, values)
29
- self
30
- end
31
-
32
- def to_hash(context)
33
- {
34
- :id => self.id,
35
- :href => context.matric_url(self.id),
36
- :entity => entity,
37
- :properties => properties.map { |p| p.to_hash(context) }
38
- }
39
- end
22
+ MOCK_METRICS_NAMES = [
23
+ 'cpuUtilization',
24
+ 'diskReadRequestCount',
25
+ 'diskReadSector',
26
+ 'diskWriteRequestCount',
27
+ 'diskWriteSector',
28
+ 'nicInputByte',
29
+ 'nicInputPacket',
30
+ 'nicOutputByte',
31
+ 'nicOutputPacket'
32
+ ]
40
33
 
41
- class Property
42
- attr_accessor :name, :values
34
+ def unknown?
35
+ self.entity == :unknown
36
+ end
43
37
 
44
- def initialize(name, values=nil)
45
- @name, @values = name, values
38
+ def add_property(name, values=nil)
39
+ self.properties ||= []
40
+ return self if self.properties.any? { |p| p.name == name }
41
+ self.properties << Property.new(name, values)
42
+ self
46
43
  end
47
44
 
48
45
  def to_hash(context)
49
46
  {
50
- :name => name,
51
- :values => values
47
+ :id => self.id,
48
+ :href => context.metric_url(self.id),
49
+ :entity => entity,
50
+ :properties => properties.map { |p| p.to_hash(context) }
52
51
  }
53
52
  end
54
- end
55
53
 
54
+ class Property
55
+ attr_accessor :name, :values
56
+
57
+ def initialize(name, values=nil)
58
+ @name, @values = name, values
59
+ end
60
+
61
+ def to_hash(context)
62
+ {
63
+ :name => name,
64
+ :values => values
65
+ }
66
+ end
67
+
68
+ def generate_mock_values!
69
+ generator = lambda { |name, kind|
70
+ v = {
71
+ :min => (1+(rand(49))),
72
+ :max => (50+(rand(50)))
73
+ }
74
+ (name == 'cpuUtilization') ? v[kind].to_f/100 : v[kind]
75
+ }
76
+ @values = (0..5).map do |v_id|
77
+ {
78
+ :minimum => min = generator.call(@name, :min),
79
+ :maximum => max = generator.call(@name, :max),
80
+ :average => (min+max)/2,
81
+ :timestamp => (Time.now-v_id).to_i,
82
+ :unit => unit_for(@name)
83
+ }
84
+ end
85
+ end
86
+
87
+ private
88
+
89
+ def unit_for(name)
90
+ case name
91
+ when /Utilization/ then 'Percent'
92
+ when /Byte/ then 'Bytes'
93
+ when /Sector/ then 'Count'
94
+ when /Count/ then 'Count'
95
+ when /Packet/ then 'Count'
96
+ else 'None'
97
+ end
98
+ end
99
+
100
+ end
101
+
102
+ end
56
103
  end
@@ -16,20 +16,22 @@
16
16
  # Model to store the hardware profile applied to an instance together with
17
17
  # any instance-specific overrides
18
18
 
19
- class Provider < BaseModel
20
- attr_accessor :url
21
- attr_accessor :name
19
+ module Deltacloud
20
+ class Provider < BaseModel
21
+ attr_accessor :url
22
+ attr_accessor :name
22
23
 
23
- def initialize(opts={})
24
- super(opts)
25
- end
24
+ def initialize(opts={})
25
+ super(opts)
26
+ end
26
27
 
27
- def to_hash(context)
28
- {
29
- :id => self.id,
30
- :name => name,
31
- :url => url
32
- }
33
- end
28
+ def to_hash(context)
29
+ {
30
+ :id => self.id,
31
+ :name => name,
32
+ :url => url
33
+ }
34
+ end
34
35
 
36
+ end
35
37
  end
@@ -14,29 +14,23 @@
14
14
  # License for the specific language governing permissions and limitations
15
15
  # under the License.
16
16
 
17
+ module Deltacloud
18
+ class Realm < BaseModel
17
19
 
18
- class Realm < BaseModel
20
+ attr_accessor :name
21
+ attr_accessor :limit
22
+ attr_accessor :state
19
23
 
20
- attr_accessor :name
21
- attr_accessor :limit
22
- attr_accessor :state
23
- attr_accessor :resource_types
24
+ def to_hash(context)
25
+ r = {
26
+ :id => self.id,
27
+ :href => context.realm_url(self.id),
28
+ :name => name,
29
+ :state => state,
30
+ :limit => limit
31
+ }
32
+ r
33
+ end
24
34
 
25
- def initialize(init=nil)
26
- super(init)
27
- self.resource_types ||= []
28
35
  end
29
-
30
- def to_hash(context)
31
- r = {
32
- :id => self.id,
33
- :href => context.realm_url(self.id),
34
- :name => name,
35
- :state => state,
36
- :limit => limit
37
- }
38
- r.merge!({:resource_types => resource_types}) if resource_types
39
- r
40
- end
41
-
42
36
  end
@@ -14,28 +14,32 @@
14
14
  # License for the specific language governing permissions and limitations
15
15
  # under the License.
16
16
 
17
+ module Deltacloud
18
+ class StorageSnapshot < BaseModel
17
19
 
20
+ attr_accessor :state
21
+ attr_accessor :storage_volume_id
22
+ attr_accessor :created
23
+ attr_accessor :name
24
+ attr_accessor :description
18
25
 
19
- class StorageSnapshot < BaseModel
26
+ def is_completed?
27
+ state == 'completed'
28
+ end
20
29
 
21
- attr_accessor :state
22
- attr_accessor :storage_volume_id
23
- attr_accessor :created
24
- attr_accessor :name
25
- attr_accessor :description
30
+ def to_hash(context)
31
+ {
32
+ :id => self.id,
33
+ :href => context.storage_snapshot_url(self.id),
34
+ :state => state,
35
+ :storage_volume => {
36
+ :id => storage_volume_id,
37
+ :href => context.storage_volume_url(storage_volume_id),
38
+ :rel => :storage_volume
39
+ },
40
+ :created => created
41
+ }
42
+ end
26
43
 
27
- def is_completed?
28
- state == 'completed'
29
44
  end
30
-
31
- def to_hash(context)
32
- {
33
- :id => self.id,
34
- :href => context.storage_snapshot_url(self.id),
35
- :state => state,
36
- :storage_volume => { :id => storage_volume_id, :href => context.storage_volume_url(storage_volume_id), :rel => :storage_volume },
37
- :created => created
38
- }
39
- end
40
-
41
45
  end
@@ -14,42 +14,43 @@
14
14
  # License for the specific language governing permissions and limitations
15
15
  # under the License.
16
16
 
17
+ module Deltacloud
18
+ class StorageVolume < BaseModel
17
19
 
18
- class StorageVolume < BaseModel
20
+ attr_accessor :created
21
+ attr_accessor :state
22
+ attr_accessor :capacity
23
+ attr_accessor :instance_id
24
+ attr_accessor :device
25
+ attr_accessor :realm_id
26
+ attr_accessor :actions
27
+ attr_accessor :name
28
+ attr_accessor :kind
29
+ attr_accessor :description # openstack volumes have a display_description attr
19
30
 
20
- attr_accessor :created
21
- attr_accessor :state
22
- attr_accessor :capacity
23
- attr_accessor :instance_id
24
- attr_accessor :device
25
- attr_accessor :realm_id
26
- attr_accessor :actions
27
- attr_accessor :name
28
- attr_accessor :kind
29
- attr_accessor :description # openstack volumes have a display_description attr
30
-
31
- def to_hash(context)
32
- r = {
33
- :id => self.id,
34
- :href => context.storage_volume_url(self.id),
35
- :name => name,
36
- :description => description,
37
- :state => state,
38
- :created => created,
39
- :realm => { :id => realm_id, :href => context.realm_url(realm_id), :rel => :realm },
40
- :device => device,
41
- :kind => kind,
42
- :capacity => capacity,
43
- }
44
- r[:actions] = (actions || []).map { |a|
45
- { :href => context.send("#{a}_storage_volume_url", self.id), :rel => a }
46
- }
47
- if instance_id
48
- r[:instance] = { :id => instance_id, :href => context.instance_url(instance_id), :rel => :instance }
49
- else
50
- r[:instance] = {}
31
+ def to_hash(context)
32
+ r = {
33
+ :id => self.id,
34
+ :href => context.storage_volume_url(self.id),
35
+ :name => name,
36
+ :description => description,
37
+ :state => state,
38
+ :created => created,
39
+ :realm => { :id => realm_id, :href => context.realm_url(realm_id), :rel => :realm },
40
+ :device => device,
41
+ :kind => kind,
42
+ :capacity => capacity,
43
+ }
44
+ r[:actions] = (actions || []).map { |a|
45
+ { :href => context.send("#{a}_storage_volume_url", self.id), :rel => a }
46
+ }
47
+ if instance_id
48
+ r[:instance] = { :id => instance_id, :href => context.instance_url(instance_id), :rel => :instance }
49
+ else
50
+ r[:instance] = {}
51
+ end
52
+ r
51
53
  end
52
- r
53
- end
54
54
 
55
+ end
55
56
  end
@@ -15,6 +15,6 @@
15
15
  # under the License.
16
16
 
17
17
  module Deltacloud
18
- API_VERSION = '1.1.1'
18
+ API_VERSION = '1.1.2'
19
19
  CIMI_API_VERSION = '1.0.1'
20
20
  end
@@ -57,6 +57,28 @@ module Deltacloud
57
57
  @default_frontend || config[:deltacloud]
58
58
  end
59
59
 
60
+ def self.generate_routes
61
+ frontends.inject({}) do |result, frontend|
62
+ frontend = frontend.strip
63
+ if Deltacloud[frontend.to_sym].nil?
64
+ puts "ERROR: Unknown frontend (#{frontend}). Valid values are 'deltacloud,cimi,ec2'"
65
+ exit(1)
66
+ end
67
+ Deltacloud[frontend.to_sym].require!
68
+ result[Deltacloud[frontend].root_url] = Deltacloud[frontend].klass
69
+ result
70
+ end
71
+ end
72
+
73
+ def self.frontends
74
+ ENV['API_FRONTEND'] ||= 'deltacloud'
75
+ ENV['API_FRONTEND'].split(',')
76
+ end
77
+
78
+ def self.need_database?
79
+ frontends.include?('cimi') || ENV['RACK_ENV'] == 'test'
80
+ end
81
+
60
82
  require 'sinatra/base'
61
83
  require_relative './deltacloud/helpers/deltacloud_helper'
62
84
  require_relative './sinatra/rack_accept'