steamcannon-deltacloud-core 0.0.7.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. data/COPYING +176 -0
  2. data/Rakefile +106 -0
  3. data/bin/deltacloudd +120 -0
  4. data/config.ru +5 -0
  5. data/deltacloud.rb +20 -0
  6. data/lib/deltacloud/base_driver/base_driver.rb +259 -0
  7. data/lib/deltacloud/base_driver/features.rb +173 -0
  8. data/lib/deltacloud/base_driver/mock_driver.rb +58 -0
  9. data/lib/deltacloud/base_driver.rb +20 -0
  10. data/lib/deltacloud/drivers/azure/azure_driver.rb +127 -0
  11. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +580 -0
  12. data/lib/deltacloud/drivers/ec2/ec2_mock_driver.rb +170 -0
  13. data/lib/deltacloud/drivers/gogrid/gogrid_client.rb +50 -0
  14. data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +343 -0
  15. data/lib/deltacloud/drivers/gogrid/test.rb +13 -0
  16. data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob1.yml +5 -0
  17. data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob2.yml +5 -0
  18. data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob3.yml +5 -0
  19. data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob4.yml +5 -0
  20. data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob5.yml +5 -0
  21. data/lib/deltacloud/drivers/mock/data/buckets/bucket1.yml +2 -0
  22. data/lib/deltacloud/drivers/mock/data/buckets/bucket2.yml +2 -0
  23. data/lib/deltacloud/drivers/mock/data/images/img1.yml +3 -0
  24. data/lib/deltacloud/drivers/mock/data/images/img2.yml +3 -0
  25. data/lib/deltacloud/drivers/mock/data/images/img3.yml +3 -0
  26. data/lib/deltacloud/drivers/mock/data/instances/inst0.yml +16 -0
  27. data/lib/deltacloud/drivers/mock/data/instances/inst1.yml +9 -0
  28. data/lib/deltacloud/drivers/mock/data/instances/inst2.yml +9 -0
  29. data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap1.yml +4 -0
  30. data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap2.yml +4 -0
  31. data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap3.yml +4 -0
  32. data/lib/deltacloud/drivers/mock/data/storage_volumes/vol1.yml +6 -0
  33. data/lib/deltacloud/drivers/mock/data/storage_volumes/vol2.yml +6 -0
  34. data/lib/deltacloud/drivers/mock/data/storage_volumes/vol3.yml +6 -0
  35. data/lib/deltacloud/drivers/mock/mock_driver.rb +356 -0
  36. data/lib/deltacloud/drivers/opennebula/cloud_client.rb +116 -0
  37. data/lib/deltacloud/drivers/opennebula/occi_client.rb +204 -0
  38. data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +241 -0
  39. data/lib/deltacloud/drivers/rackspace/rackspace_client.rb +130 -0
  40. data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +290 -0
  41. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +258 -0
  42. data/lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb +85 -0
  43. data/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb +166 -0
  44. data/lib/deltacloud/drivers/terremark/terremark_driver.rb +295 -0
  45. data/lib/deltacloud/hardware_profile.rb +153 -0
  46. data/lib/deltacloud/helpers/application_helper.rb +122 -0
  47. data/lib/deltacloud/helpers/blob_stream.rb +51 -0
  48. data/lib/deltacloud/helpers/conversion_helper.rb +39 -0
  49. data/lib/deltacloud/helpers/hardware_profiles_helper.rb +35 -0
  50. data/lib/deltacloud/helpers.rb +5 -0
  51. data/lib/deltacloud/method_serializer.rb +85 -0
  52. data/lib/deltacloud/models/base_model.rb +59 -0
  53. data/lib/deltacloud/models/blob.rb +26 -0
  54. data/lib/deltacloud/models/bucket.rb +24 -0
  55. data/lib/deltacloud/models/image.rb +27 -0
  56. data/lib/deltacloud/models/instance.rb +38 -0
  57. data/lib/deltacloud/models/instance_profile.rb +48 -0
  58. data/lib/deltacloud/models/key.rb +35 -0
  59. data/lib/deltacloud/models/realm.rb +26 -0
  60. data/lib/deltacloud/models/storage_snapshot.rb +27 -0
  61. data/lib/deltacloud/models/storage_volume.rb +28 -0
  62. data/lib/deltacloud/state_machine.rb +84 -0
  63. data/lib/deltacloud/validation.rb +70 -0
  64. data/lib/drivers.rb +51 -0
  65. data/lib/sinatra/accept_media_types.rb +128 -0
  66. data/lib/sinatra/lazy_auth.rb +56 -0
  67. data/lib/sinatra/rabbit.rb +279 -0
  68. data/lib/sinatra/respond_to.rb +238 -0
  69. data/lib/sinatra/static_assets.rb +83 -0
  70. data/lib/sinatra/url_for.rb +53 -0
  71. data/public/favicon.ico +0 -0
  72. data/public/images/grid.png +0 -0
  73. data/public/images/logo-wide.png +0 -0
  74. data/public/images/rails.png +0 -0
  75. data/public/images/topbar-bg.png +0 -0
  76. data/public/javascripts/application.js +32 -0
  77. data/public/javascripts/jquery-1.4.2.min.js +154 -0
  78. data/public/stylesheets/compiled/application.css +613 -0
  79. data/public/stylesheets/compiled/ie.css +31 -0
  80. data/public/stylesheets/compiled/print.css +27 -0
  81. data/public/stylesheets/compiled/screen.css +456 -0
  82. data/server.rb +516 -0
  83. data/support/fedora/deltacloudd +68 -0
  84. data/support/fedora/rubygem-deltacloud-core.spec +91 -0
  85. data/tests/api_test.rb +37 -0
  86. data/tests/hardware_profiles_test.rb +120 -0
  87. data/tests/images_test.rb +111 -0
  88. data/tests/instance_states_test.rb +51 -0
  89. data/tests/instances_test.rb +222 -0
  90. data/tests/realms_test.rb +78 -0
  91. data/tests/url_for_test.rb +50 -0
  92. data/views/accounts/index.html.haml +11 -0
  93. data/views/accounts/show.html.haml +30 -0
  94. data/views/api/show.html.haml +15 -0
  95. data/views/api/show.xml.haml +5 -0
  96. data/views/blobs/show.html.haml +20 -0
  97. data/views/blobs/show.xml.haml +7 -0
  98. data/views/buckets/index.html.haml +33 -0
  99. data/views/buckets/index.xml.haml +10 -0
  100. data/views/buckets/new.html.haml +13 -0
  101. data/views/buckets/show.html.haml +19 -0
  102. data/views/buckets/show.xml.haml +8 -0
  103. data/views/docs/collection.html.haml +37 -0
  104. data/views/docs/collection.xml.haml +14 -0
  105. data/views/docs/index.html.haml +15 -0
  106. data/views/docs/index.xml.haml +5 -0
  107. data/views/docs/operation.html.haml +31 -0
  108. data/views/docs/operation.xml.haml +10 -0
  109. data/views/errors/auth_exception.html.haml +8 -0
  110. data/views/errors/auth_exception.xml.haml +2 -0
  111. data/views/errors/backend_error.html.haml +19 -0
  112. data/views/errors/backend_error.xml.haml +8 -0
  113. data/views/errors/not_found.html.haml +6 -0
  114. data/views/errors/not_found.xml.haml +2 -0
  115. data/views/errors/validation_failure.html.haml +11 -0
  116. data/views/errors/validation_failure.xml.haml +7 -0
  117. data/views/hardware_profiles/index.html.haml +25 -0
  118. data/views/hardware_profiles/index.xml.haml +4 -0
  119. data/views/hardware_profiles/show.html.haml +19 -0
  120. data/views/hardware_profiles/show.xml.haml +18 -0
  121. data/views/images/index.html.haml +30 -0
  122. data/views/images/index.xml.haml +8 -0
  123. data/views/images/show.html.haml +21 -0
  124. data/views/images/show.xml.haml +5 -0
  125. data/views/instance_states/show.html.haml +31 -0
  126. data/views/instance_states/show.png.erb +45 -0
  127. data/views/instance_states/show.xml.haml +8 -0
  128. data/views/instances/index.html.haml +30 -0
  129. data/views/instances/index.xml.haml +21 -0
  130. data/views/instances/new.html.haml +55 -0
  131. data/views/instances/show.html.haml +43 -0
  132. data/views/instances/show.xml.haml +49 -0
  133. data/views/keys/index.html.haml +26 -0
  134. data/views/keys/index.xml.haml +4 -0
  135. data/views/keys/new.html.haml +8 -0
  136. data/views/keys/show.html.haml +22 -0
  137. data/views/keys/show.xml.haml +20 -0
  138. data/views/layout.html.haml +26 -0
  139. data/views/realms/index.html.haml +29 -0
  140. data/views/realms/index.xml.haml +10 -0
  141. data/views/realms/show.html.haml +15 -0
  142. data/views/realms/show.xml.haml +9 -0
  143. data/views/root/index.html.haml +4 -0
  144. data/views/storage_snapshots/index.html.haml +20 -0
  145. data/views/storage_snapshots/index.xml.haml +9 -0
  146. data/views/storage_snapshots/show.html.haml +14 -0
  147. data/views/storage_snapshots/show.xml.haml +7 -0
  148. data/views/storage_volumes/index.html.haml +21 -0
  149. data/views/storage_volumes/index.xml.haml +23 -0
  150. data/views/storage_volumes/show.html.haml +20 -0
  151. data/views/storage_volumes/show.xml.haml +24 -0
  152. metadata +367 -0
@@ -0,0 +1,258 @@
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 'deltacloud/base_driver'
20
+ require 'yaml'
21
+
22
+ module Deltacloud
23
+ module Drivers
24
+ module RHEVM
25
+
26
+ class RHEVMDriver < Deltacloud::BaseDriver
27
+
28
+ SCRIPT_DIR = File.dirname(__FILE__) + '/scripts'
29
+ CONFIG = YAML.load_file(File.dirname(__FILE__) + '/../../../../config/rhevm_config.yml')
30
+ SCRIPT_DIR_ARG = '"' + SCRIPT_DIR + '"'
31
+ DELIM_BEGIN="<_OUTPUT>"
32
+ DELIM_END="</_OUTPUT>"
33
+ POWERSHELL="c:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"
34
+ NO_OWNER=""
35
+
36
+ feature :instances, :user_name
37
+
38
+ #
39
+ # Execute a Powershell command, and convert the output
40
+ # to YAML in order to get back an array of maps.
41
+ #
42
+ def execute(credentials, command, *args)
43
+ args = args.to_a
44
+ argString = genArgString(credentials, args)
45
+ puts argString
46
+ outputMaps = {}
47
+ output = `#{POWERSHELL} -command "&{#{File.join(SCRIPT_DIR, command)} #{argString}; exit $LASTEXITCODE}`
48
+ exitStatus = $?.exitstatus
49
+ puts(output)
50
+ puts("EXITSTATUS #{exitStatus}")
51
+ st = output.index(DELIM_BEGIN)
52
+ if (st)
53
+ st += DELIM_BEGIN.length
54
+ ed = output.index(DELIM_END)
55
+ output = output.slice(st, (ed-st))
56
+ # Lets make it yaml
57
+ output.strip!
58
+ if (output.length > 0)
59
+ outputMaps = YAML.load(self.toYAML(output))
60
+ end
61
+ end
62
+ outputMaps
63
+ end
64
+
65
+ def genArgString(credentials, args)
66
+ commonArgs = [SCRIPT_DIR_ARG, credentials.user, credentials.password, CONFIG["domain"]]
67
+ commonArgs.concat(args)
68
+ commonArgs.join(" ")
69
+ end
70
+
71
+ def toYAML(output)
72
+ yOutput = "- \n" + output
73
+ yOutput.gsub!(/^(\w*)[ ]*:[ ]*([A-Z0-9a-z._ -:{}]*)/,' \1: "\2"')
74
+ yOutput.gsub!(/^[ ]*$/,"- ")
75
+ puts(yOutput)
76
+ yOutput
77
+ end
78
+
79
+ def statify(state)
80
+ st = state.nil? ? "" : state.upcase()
81
+ case st
82
+ when "UP"
83
+ "RUNNING"
84
+ when "DOWN"
85
+ "STOPPED"
86
+ when "POWERING UP"
87
+ "PENDING"
88
+ end
89
+
90
+ define_hardware_profile 'rhevm'
91
+
92
+ #
93
+ # Realms
94
+ #
95
+
96
+ def realms(credentials, opts=nil)
97
+ domains = execute(credentials, "storageDomains.ps1")
98
+ if (!opts.nil? && opts[:id])
99
+ domains = domains.select{|d| opts[:id] == d["StorageId"]}
100
+ end
101
+
102
+ realms = []
103
+ domains.each do |dom|
104
+ realms << domain_to_realm(dom)
105
+ end
106
+ realms
107
+ end
108
+
109
+ def domain_to_realm(dom)
110
+ Realm.new({
111
+ :id => dom["StorageId"],
112
+ :name => dom["Name"],
113
+ :limit => dom["AvailableDiskSize"]
114
+ })
115
+ end
116
+
117
+
118
+
119
+ #
120
+ # Images
121
+ #
122
+
123
+ def images(credentials, opts=nil )
124
+ templates = []
125
+ if (opts.nil?)
126
+ templates = execute(credentials, "templates.ps1")
127
+ else
128
+ if (opts[:id])
129
+ templates = execute(credentials, "templateById.ps1", opts[:id])
130
+ end
131
+ end
132
+ images = []
133
+ templates.each do |templ|
134
+ images << template_to_image(templ)
135
+ end
136
+ images
137
+ end
138
+
139
+ def template_to_image(templ)
140
+ Image.new({
141
+ :id => templ["TemplateId"],
142
+ :name => templ["Name"],
143
+ :description => templ["Description"],
144
+ :architecture => templ["OperatingSystem"],
145
+ :owner_id => NO_OWNER,
146
+ :mem_size_md => templ["MemSizeMb"],
147
+ :instance_count => templ["ChildCount"],
148
+ :state => templ["Status"],
149
+ :capacity => templ["SizeGB"]
150
+ })
151
+ end
152
+
153
+ #
154
+ # Instances
155
+ #
156
+
157
+ define_instance_states do
158
+ start.to(:stopped) .on( :create )
159
+
160
+ pending.to(:shutting_down) .on( :stop )
161
+ pending.to(:running) .automatically
162
+
163
+ running.to(:pending) .on( :reboot )
164
+ running.to(:shutting_down) .on( :stop )
165
+
166
+ shutting_down.to(:stopped) .automatically
167
+ stopped.to(:pending) .on( :start )
168
+ stopped.to(:finish) .on( :destroy )
169
+ end
170
+
171
+ def instances(credentials, opts=nil)
172
+ vms = []
173
+ if (opts.nil?)
174
+ vms = execute(credentials, "vms.ps1")
175
+ else
176
+ if (opts[:id])
177
+ vms = execute(credentials, "vmById.ps1", opts[:id])
178
+ end
179
+ end
180
+ instances = []
181
+ vms.each do |vm|
182
+ instances << vm_to_instance(vm)
183
+ end
184
+ instances = filter_on( instances, :id, opts )
185
+ instances = filter_on( instances, :state, opts )
186
+ instances
187
+ end
188
+
189
+ def vm_to_instance(vm)
190
+ Instance.new({
191
+ :id => vm["VmId"],
192
+ :description => vm["Description"],
193
+ :name => vm["Name"],
194
+ :architecture => vm["OperatingSystem"],
195
+ :owner_id => NO_OWNER,
196
+ :image_id => vm["TemplateId"],
197
+ :state => statify(vm["Status"]),
198
+ :instance_profile => InstanceProfile.new("rhevm"),
199
+ :actions => instance_actions_for(statify(vm["Status"])),
200
+ })
201
+ end
202
+
203
+ def start_instance(credentials, image_id)
204
+ vm = execute(credentials, "startVm.ps1", image_id)
205
+ vm_to_instance(vm[0])
206
+ end
207
+
208
+ def stop_instance(credentials, image_id)
209
+ vm = execute(credentials, "stopVm.ps1", image_id)
210
+ vm_to_instance(vm[0])
211
+ end
212
+
213
+ def create_instance(credentials, image_id, opts)
214
+ name = opts[:name]
215
+ name = "Inst-#{rand(10000)}" if (name.nil? or name.empty?)
216
+ realm_id = opts[:realm_id]
217
+ if (realm_id.nil?)
218
+ realms = filter_on(realms(credentials, opts), :name, :name => "data")
219
+ puts realms[0]
220
+ realm_id = realms[0].id
221
+ end
222
+ vm = execute(credentials, "addVm.ps1", image_id, name, realm_id)
223
+ vm_to_instance(vm[0])
224
+ end
225
+
226
+ def reboot_instance(credentials, image_id)
227
+ vm = execute(credentials, "rebootVm.ps1", image_id)
228
+ vm_to_instance(vm[0])
229
+ end
230
+
231
+ def destroy_instance(credentials, image_id)
232
+ vm = execute(credentials, "deleteVm.ps1", image_id)
233
+ vm_to_instance(vm[0])
234
+ end
235
+
236
+ #
237
+ # Storage Volumes
238
+ #
239
+
240
+ def storage_volumes(credentials, ids=nil)
241
+ volumes = []
242
+ volumes
243
+ end
244
+
245
+ #
246
+ # Storage Snapshots
247
+ #
248
+
249
+ def storage_snapshots(credentials, ids=nil)
250
+ snapshots = []
251
+ snapshots
252
+ end
253
+
254
+ end
255
+
256
+ end
257
+ end
258
+ end
@@ -0,0 +1,85 @@
1
+ #
2
+ # Copyright (C) 2009 RimuHosting Ltd
3
+ # Author: Ivan Meredith <ivan@ivan.net.nz>
4
+ #
5
+ # Licensed to the Apache Software Foundation (ASF) under one or more
6
+ # contributor license agreements. See the NOTICE file distributed with
7
+ # this work for additional information regarding copyright ownership. The
8
+ # ASF licenses this file to you under the Apache License, Version 2.0 (the
9
+ # "License"); you may not use this file except in compliance with the
10
+ # License. You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17
+ # License for the specific language governing permissions and limitations
18
+ # under the License.
19
+
20
+ require "net/http"
21
+ require "net/https"
22
+ require "rubygems"
23
+ require "json"
24
+ require "deltacloud/base_driver"
25
+
26
+ module Deltacloud
27
+ module Drivers
28
+ module RimuHosting
29
+
30
+ class RimuHostingClient
31
+ def initialize(credentials ,baseuri = 'https://rimuhosting.com/r')
32
+ @uri = URI.parse(baseuri)
33
+ @service = Net::HTTP.new(@uri.host, @uri.port)
34
+ @service.use_ssl = true
35
+ @auth = "rimuhosting apikey=#{credentials.password}"
36
+ end
37
+
38
+ def request(resource, data='', method='GET')
39
+ headers = {"Accept" => "application/json", "Content-Type" => "application/json"}
40
+ if(!@auth.nil?)
41
+ headers["Authorization"] = @auth
42
+ end
43
+ r = @service.send_request(method, @uri.path + resource, data, headers)
44
+ puts r.body
45
+ res = JSON.parse(r.body)
46
+ res = res[res.keys[0]]
47
+
48
+ if(res['response_type'] == "ERROR" and ( (res['error_info']['error_class'] == "PermissionException") or
49
+ (res['error_info']['error_class'] == "LoginRequired") ))
50
+ raise Deltacloud::AuthException.new
51
+ end
52
+ res
53
+ end
54
+
55
+ def list_images
56
+ request('/distributions')["distro_infos"]
57
+ end
58
+
59
+ def list_plans
60
+ request('/pricing-plans;server-type=VPS')["pricing_plan_infos"]
61
+ end
62
+
63
+ def list_nodes
64
+ request('/orders;include_inactive=N')["about_orders"]
65
+ end
66
+
67
+ def set_server_state(id, state)
68
+ json = {"reboot_request" => {"running_state" => state}}.to_json
69
+ request("/orders/order-#{id}-a/vps/running-state", json, 'PUT')
70
+ end
71
+
72
+ def delete_server(id)
73
+ request("/orders/order-#{id}-a/vps",'', 'DELETE')
74
+ end
75
+
76
+ def create_server(image_id, plan_code, name)
77
+ json = {:new_vps => {:instantiation_options => {:domain_name => name, :distro => image_id},
78
+ :pricing_plan_code => plan_code}}.to_json
79
+ request('/orders/new-vps',json, 'POST')[:about_order]
80
+ end
81
+ end
82
+
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,166 @@
1
+ #
2
+ # Copyright (C) 2009 RimuHosting Ltd
3
+ # Author: Ivan Meredith <ivan@ivan.net.nz>
4
+ #
5
+ # Licensed to the Apache Software Foundation (ASF) under one or more
6
+ # contributor license agreements. See the NOTICE file distributed with
7
+ # this work for additional information regarding copyright ownership. The
8
+ # ASF licenses this file to you under the Apache License, Version 2.0 (the
9
+ # "License"); you may not use this file except in compliance with the
10
+ # License. You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17
+ # License for the specific language governing permissions and limitations
18
+ # under the License.
19
+
20
+ require "deltacloud/base_driver"
21
+ require "deltacloud/drivers/rimuhosting/rimuhosting_client"
22
+
23
+ module Deltacloud
24
+ module Drivers
25
+ module RimuHosting
26
+
27
+ class RimuHostingDriver < Deltacloud::BaseDriver
28
+
29
+ feature :instances, :user_name
30
+
31
+ def images(credentails, opts=nil)
32
+ safely do
33
+ rh = RimuHostingClient.new(credentails)
34
+ images = rh.list_images.map do | image |
35
+ Image.new({
36
+ :id => image["distro_code"].gsub(/\./,"-"),
37
+ :name => image["distro_code"],
38
+ :description => image["distro_description"],
39
+ :owner_id => "root",
40
+ :architecture => "x86"
41
+ })
42
+ end
43
+ end
44
+ images.sort_by{|e| [e.description]}
45
+ images = filter_on( images, :id, opts)
46
+ images
47
+ end
48
+
49
+ def hardware_profiles(credentials, opts = nil)
50
+ safely do
51
+ rh = RimuHostingClient.new(credentials)
52
+ results = rh.list_plans.map do |plan|
53
+ # FIXME: x86 is not a valid architecture; what is Rimu offering ?
54
+ # FIXME: VPS plans offer a range of memory/storage, but that's
55
+ # not contained in hte pricing_plan_infos
56
+ HardwareProfile.new(plan["pricing_plan_code"]) do
57
+ memory plan["minimum_memory_mb"].to_f
58
+ storage plan["minimum_disk_gb"].to_i
59
+ architecture "x86"
60
+ end
61
+ end
62
+ end
63
+ filter_hardware_profiles(results, opts)
64
+ end
65
+
66
+ def realms(credentials, opts=nil)
67
+ [Realm.new( {
68
+ :id=>"rimu",
69
+ :name=>"RimuHosting",
70
+ :state=> "AVAILABLE"
71
+ } )]
72
+ end
73
+
74
+ def instances(credentials, opts=nil)
75
+ safely do
76
+ rh = RimuHostingClient.new(credentials)
77
+ instances = rh.list_nodes.map do | inst |
78
+ convert_srv_to_instance(inst)
79
+ end
80
+ end
81
+ instances = filter_on( instances, :id, opts)
82
+ instances = filter_on( instances, :state, opts )
83
+ instances
84
+ end
85
+
86
+ def reboot_instance(credentials, id)
87
+ safely do
88
+ rh = RimuHostingClient.new(credentials)
89
+ rh.set_server_state(id, :RESTARTING)
90
+ end
91
+ end
92
+
93
+ def start_instance(credentials, id)
94
+ safely do
95
+ rh = RimuHostingClient.new(credentials)
96
+ rh.set_server_state(id, :STARTED)
97
+ end
98
+ end
99
+
100
+ def stop_instance(credentials, id)
101
+ destroy_instance(credentials, id)
102
+ end
103
+
104
+ def destroy_instance(credentials, id)
105
+ safely do
106
+ rh = RimuHostingClient.new(credentials)
107
+ return rh.delete_server(id)
108
+ end
109
+ end
110
+
111
+ def create_instance(credentials, image_id, opts)
112
+ rh = RimuHostingClient.new(credentials)
113
+ # really need to raise an exception here.
114
+ hwp_id = opts[:hwp_id] || 1
115
+ # really bad, but at least its a fqdn
116
+ name = Time.now.to_s + '.com'
117
+ if (opts[:name]) then
118
+ name = opts[:name]
119
+ end
120
+ convert_srv_to_instance(rh.create_server(image_id, hwp_id, name))
121
+
122
+ end
123
+
124
+ def convert_srv_to_instance( inst )
125
+ Instance.new({
126
+ :id => inst["order_oid"].to_s,
127
+ :name => inst["domain_name"],
128
+ :image_id => "lenny",
129
+ :state => "RUNNING",
130
+ :name => inst["domain_name"],
131
+ :realm_id => "RH",
132
+ :owner_id => "root",
133
+ :instance_profile => InstanceProfile.new("none"),
134
+ :actions => instance_actions_for("RUNNING"),
135
+ :public_addresses => inst["allocated_ips"]["primary_ip"],
136
+ :launch_time => inst["billing_info"]["order_date"]["iso_format"]
137
+ })
138
+ end
139
+
140
+ define_instance_states do
141
+ start.to( :pending ) .automatically
142
+
143
+ pending.to( :running ) .automatically
144
+
145
+ running.to( :running ) .on(:reboot)
146
+ running.to( :shutting_down ) .on(:stop)
147
+
148
+ shutting_down.to( :stopped ) .automatically
149
+
150
+ stopped.to( :finish ) .automatically
151
+ end
152
+
153
+ def safely(&block)
154
+ begin
155
+ block.call
156
+ rescue Exception => e
157
+ raise Deltacloud::BackendError.new(500, e.class.to_s, e.message, e.backtrace)
158
+ end
159
+ end
160
+
161
+
162
+ end
163
+
164
+ end
165
+ end
166
+ end