bbrowning-deltacloud-core 0.0.3.1 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +10 -3
- data/bin/deltacloudd +67 -35
- data/config.ru +1 -1
- data/deltacloud.rb +1 -0
- data/lib/deltacloud/base_driver/base_driver.rb +29 -0
- data/lib/deltacloud/base_driver/features.rb +7 -0
- data/lib/deltacloud/base_driver/mock_driver.rb +4 -1
- data/lib/deltacloud/drivers/ec2/ec2_driver.rb +98 -31
- data/lib/deltacloud/drivers/gogrid/gogrid_client.rb +7 -2
- data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +39 -34
- data/lib/deltacloud/drivers/gogrid/test.rb +13 -0
- data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +54 -23
- data/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb +47 -27
- data/lib/deltacloud/drivers/terremark/terremark_driver.rb +53 -29
- data/lib/deltacloud/helpers/application_helper.rb +6 -0
- data/lib/deltacloud/models/base_model.rb +2 -2
- data/lib/deltacloud/models/key.rb +35 -0
- data/lib/sinatra/url_for.rb +7 -4
- data/server.rb +54 -2
- data/tests/url_for_test.rb +50 -0
- data/views/errors/backend_error.html.haml +3 -1
- data/views/images/index.html.haml +1 -1
- data/views/instances/index.html.haml +1 -1
- data/views/instances/show.xml.haml +31 -22
- 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
- metadata +337 -320
- data/support/torquebox/torquebox-ec2-config.ru +0 -8
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'gogrid_client'
|
2
|
+
require 'ap'
|
3
|
+
|
4
|
+
user='fbb1de3897597ccf'
|
5
|
+
password='ngieth10'
|
6
|
+
|
7
|
+
client=GoGridClient.new('https://api.gogrid.com/api', user, password)
|
8
|
+
|
9
|
+
ap client.request('grid/ip/list', {
|
10
|
+
'ip.type' => '1',
|
11
|
+
'ip.state' => '1',
|
12
|
+
'datacenter' => '1'
|
13
|
+
})
|
@@ -29,11 +29,13 @@ class RackspaceDriver < Deltacloud::BaseDriver
|
|
29
29
|
|
30
30
|
def hardware_profiles(credentials, opts = nil)
|
31
31
|
racks = new_client( credentials )
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
safely do
|
33
|
+
results = racks.list_flavors.map do |flav|
|
34
|
+
HardwareProfile.new(flav["id"].to_s) do
|
35
|
+
architecture 'x86_64'
|
36
|
+
memory flav["ram"].to_i
|
37
|
+
storage flav["disk"].to_i
|
38
|
+
end
|
37
39
|
end
|
38
40
|
end
|
39
41
|
filter_hardware_profiles(results, opts)
|
@@ -41,14 +43,16 @@ class RackspaceDriver < Deltacloud::BaseDriver
|
|
41
43
|
|
42
44
|
def images(credentials, opts=nil)
|
43
45
|
racks = new_client( credentials )
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
46
|
+
safely do
|
47
|
+
results = racks.list_images.map do |img|
|
48
|
+
Image.new( {
|
49
|
+
:id=>img["id"].to_s,
|
50
|
+
:name=>img["name"],
|
51
|
+
:description => img["name"] + " " + img["status"] + "",
|
52
|
+
:owner_id=>"root",
|
53
|
+
:architecture=>'x86_64'
|
54
|
+
} )
|
55
|
+
end
|
52
56
|
end
|
53
57
|
results.sort_by{|e| [e.description]}
|
54
58
|
results = filter_on( results, :id, opts )
|
@@ -66,7 +70,14 @@ class RackspaceDriver < Deltacloud::BaseDriver
|
|
66
70
|
|
67
71
|
def reboot_instance(credentials, id)
|
68
72
|
racks = new_client(credentials)
|
69
|
-
|
73
|
+
safely do
|
74
|
+
racks.reboot_server(id)
|
75
|
+
end
|
76
|
+
Instance.new( {
|
77
|
+
:id => id,
|
78
|
+
:state => "REBOOT",
|
79
|
+
:actions => instance_actions_for( state ),
|
80
|
+
} )
|
70
81
|
end
|
71
82
|
|
72
83
|
def stop_instance(credentials, id)
|
@@ -75,7 +86,14 @@ class RackspaceDriver < Deltacloud::BaseDriver
|
|
75
86
|
|
76
87
|
def destroy_instance(credentials, id)
|
77
88
|
racks = new_client(credentials)
|
78
|
-
|
89
|
+
safely do
|
90
|
+
racks.delete_server(id)
|
91
|
+
end
|
92
|
+
Instance.new( {
|
93
|
+
:id => id,
|
94
|
+
:state => "STOPPED",
|
95
|
+
:actions => instance_actions_for( "STOPPED" ),
|
96
|
+
} )
|
79
97
|
end
|
80
98
|
|
81
99
|
|
@@ -88,7 +106,9 @@ class RackspaceDriver < Deltacloud::BaseDriver
|
|
88
106
|
hwp_id = opts[:hwp_id] || 1
|
89
107
|
name = Time.now.to_s
|
90
108
|
if (opts[:name]) then name = opts[:name] end
|
91
|
-
|
109
|
+
safely do
|
110
|
+
return convert_srv_to_instance(racks.start_server(image_id, hwp_id, name))
|
111
|
+
end
|
92
112
|
end
|
93
113
|
|
94
114
|
#
|
@@ -97,12 +117,14 @@ class RackspaceDriver < Deltacloud::BaseDriver
|
|
97
117
|
def instances(credentials, opts=nil)
|
98
118
|
racks = new_client(credentials)
|
99
119
|
instances = []
|
100
|
-
|
101
|
-
|
102
|
-
|
120
|
+
safely do
|
121
|
+
if (opts.nil?)
|
122
|
+
instances = racks.list_servers.map do |srv|
|
123
|
+
convert_srv_to_instance(srv)
|
124
|
+
end
|
125
|
+
else
|
126
|
+
instances << convert_srv_to_instance(racks.load_server_details(opts[:id]))
|
103
127
|
end
|
104
|
-
else
|
105
|
-
instances << convert_srv_to_instance(racks.load_server_details(opts[:id]))
|
106
128
|
end
|
107
129
|
instances = filter_on( instances, :id, opts )
|
108
130
|
instances = filter_on( instances, :state, opts )
|
@@ -111,7 +133,6 @@ class RackspaceDriver < Deltacloud::BaseDriver
|
|
111
133
|
|
112
134
|
|
113
135
|
def convert_srv_to_instance(srv)
|
114
|
-
status = srv["status"] == "ACTIVE" ? "RUNNING" : "PENDING"
|
115
136
|
inst = Instance.new(:id => srv["id"].to_s,
|
116
137
|
:owner_id => "root",
|
117
138
|
:realm_id => "us")
|
@@ -128,7 +149,9 @@ class RackspaceDriver < Deltacloud::BaseDriver
|
|
128
149
|
end
|
129
150
|
|
130
151
|
def new_client(credentials)
|
131
|
-
|
152
|
+
safely do
|
153
|
+
return RackspaceClient.new(credentials.user, credentials.password)
|
154
|
+
end
|
132
155
|
end
|
133
156
|
|
134
157
|
define_instance_states do
|
@@ -144,6 +167,14 @@ class RackspaceDriver < Deltacloud::BaseDriver
|
|
144
167
|
stopped.to( :finish ) .automatically
|
145
168
|
end
|
146
169
|
|
170
|
+
def safely(&block)
|
171
|
+
begin
|
172
|
+
block.call
|
173
|
+
rescue Exception => e
|
174
|
+
raise Deltacloud::BackendError.new(500, e.class.to_s, e.message, e.backtrace)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
147
178
|
end
|
148
179
|
|
149
180
|
end
|
@@ -29,15 +29,17 @@ class RimuHostingDriver < Deltacloud::BaseDriver
|
|
29
29
|
feature :instances, :user_name
|
30
30
|
|
31
31
|
def images(credentails, opts=nil)
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
41
43
|
end
|
42
44
|
images.sort_by{|e| [e.description]}
|
43
45
|
images = filter_on( images, :id, opts)
|
@@ -45,15 +47,17 @@ class RimuHostingDriver < Deltacloud::BaseDriver
|
|
45
47
|
end
|
46
48
|
|
47
49
|
def hardware_profiles(credentials, opts = nil)
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
57
61
|
end
|
58
62
|
end
|
59
63
|
filter_hardware_profiles(results, opts)
|
@@ -68,9 +72,11 @@ class RimuHostingDriver < Deltacloud::BaseDriver
|
|
68
72
|
end
|
69
73
|
|
70
74
|
def instances(credentials, opts=nil)
|
71
|
-
|
72
|
-
|
73
|
-
|
75
|
+
safely do
|
76
|
+
rh = RimuHostingClient.new(credentials)
|
77
|
+
instances = rh.list_nodes.map do | inst |
|
78
|
+
convert_srv_to_instance(inst)
|
79
|
+
end
|
74
80
|
end
|
75
81
|
instances = filter_on( instances, :id, opts)
|
76
82
|
instances = filter_on( instances, :state, opts )
|
@@ -78,13 +84,17 @@ class RimuHostingDriver < Deltacloud::BaseDriver
|
|
78
84
|
end
|
79
85
|
|
80
86
|
def reboot_instance(credentials, id)
|
81
|
-
|
82
|
-
|
87
|
+
safely do
|
88
|
+
rh = RimuHostingClient.new(credentials)
|
89
|
+
rh.set_server_state(id, :RESTARTING)
|
90
|
+
end
|
83
91
|
end
|
84
92
|
|
85
93
|
def start_instance(credentials, id)
|
86
|
-
|
87
|
-
|
94
|
+
safely do
|
95
|
+
rh = RimuHostingClient.new(credentials)
|
96
|
+
rh.set_server_state(id, :STARTED)
|
97
|
+
end
|
88
98
|
end
|
89
99
|
|
90
100
|
def stop_instance(credentials, id)
|
@@ -92,8 +102,10 @@ class RimuHostingDriver < Deltacloud::BaseDriver
|
|
92
102
|
end
|
93
103
|
|
94
104
|
def destroy_instance(credentials, id)
|
95
|
-
|
96
|
-
|
105
|
+
safely do
|
106
|
+
rh = RimuHostingClient.new(credentials)
|
107
|
+
return rh.delete_server(id)
|
108
|
+
end
|
97
109
|
end
|
98
110
|
|
99
111
|
def create_instance(credentials, image_id, opts)
|
@@ -138,6 +150,14 @@ class RimuHostingDriver < Deltacloud::BaseDriver
|
|
138
150
|
stopped.to( :finish ) .automatically
|
139
151
|
end
|
140
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
|
+
|
141
161
|
|
142
162
|
end
|
143
163
|
|
@@ -57,15 +57,17 @@ VAPP_STATE_MAP = { "0" => "PENDING", "1" => "PENDING", "2" => "STOPPED", "4"
|
|
57
57
|
def images(credentials, opts=nil)
|
58
58
|
image_list = []
|
59
59
|
terremark_client = new_client(credentials)
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
60
|
+
safely do
|
61
|
+
vdc_id = terremark_client.default_vdc_id
|
62
|
+
catalogItems = terremark_client.get_catalog(vdc_id).body['CatalogItems']
|
63
|
+
catalogItems.each{ |catalog_item|
|
64
|
+
current_item_id = catalog_item['href'].split('/').last
|
65
|
+
current_item = terremark_client.get_catalog_item(current_item_id).body['Entity']
|
66
|
+
if(current_item['type'] == 'application/vnd.vmware.vcloud.vAppTemplate+xml')
|
67
|
+
image_list << convert_image(current_item, credentials.user)
|
68
|
+
end
|
69
|
+
} #end of catalogItems.each
|
70
|
+
end
|
69
71
|
image_list = filter_on( image_list, :id, opts )
|
70
72
|
image_list = filter_on( image_list, :architecture, opts )
|
71
73
|
image_list = filter_on( image_list, :owner_id, opts )
|
@@ -91,14 +93,16 @@ VAPP_STATE_MAP = { "0" => "PENDING", "1" => "PENDING", "2" => "STOPPED", "4"
|
|
91
93
|
def instances(credentials, opts=nil)
|
92
94
|
instances = []
|
93
95
|
terremark_client = new_client(credentials)
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
96
|
+
safely do
|
97
|
+
vdc_items = terremark_client.get_vdc(terremark_client.default_vdc_id()).body['ResourceEntities']
|
98
|
+
vdc_items.each{|current_item|
|
99
|
+
if(current_item['type'] == 'application/vnd.vmware.vcloud.vApp+xml')
|
100
|
+
vapp_id = current_item['href'].split('/').last
|
101
|
+
vapp = terremark_client.get_vapp(vapp_id)
|
102
|
+
instances << convert_instance(vapp, terremark_client, credentials.user)
|
103
|
+
end
|
104
|
+
}#end vdc_items.each
|
105
|
+
end
|
102
106
|
instances = filter_on( instances, :id, opts )
|
103
107
|
instances
|
104
108
|
end
|
@@ -114,7 +118,7 @@ VAPP_STATE_MAP = { "0" => "PENDING", "1" => "PENDING", "2" => "STOPPED", "4"
|
|
114
118
|
running.to(:running) .on( :reboot )
|
115
119
|
running.to(:shutting_down) .on( :stop )
|
116
120
|
shutting_down.to(:stopped) .automatically
|
117
|
-
stopped.to(:
|
121
|
+
stopped.to(:finish) .on( :destroy )
|
118
122
|
end
|
119
123
|
|
120
124
|
|
@@ -135,37 +139,45 @@ VAPP_STATE_MAP = { "0" => "PENDING", "1" => "PENDING", "2" => "STOPPED", "4"
|
|
135
139
|
end
|
136
140
|
vapp_opts['cpus'] = opts[:hwp_cpu]
|
137
141
|
vapp_opts['memory'] = opts[:hwp_memory]
|
138
|
-
|
142
|
+
safely do
|
143
|
+
terremark_client = new_client(credentials)
|
139
144
|
#######
|
140
145
|
#FIXME# what happens if there is an issue getting the new vapp id? (eg even though created succesfully)
|
141
146
|
#######
|
142
|
-
|
143
|
-
|
144
|
-
|
147
|
+
vapp_id = terremark_client.instantiate_vapp_template(name, image_id, vapp_opts).body['href'].split('/').last
|
148
|
+
new_vapp = terremark_client.get_vapp(vapp_id)
|
149
|
+
return convert_instance(new_vapp, terremark_client, credentials.user) #return an Instance object
|
150
|
+
end
|
145
151
|
end
|
146
152
|
|
147
153
|
#--
|
148
154
|
# REBOOT INSTANCE
|
149
155
|
#--
|
150
156
|
def reboot_instance(credentials, id)
|
151
|
-
|
152
|
-
|
157
|
+
safely do
|
158
|
+
terremark_client = new_client(credentials)
|
159
|
+
return terremark_client.power_reset(id)
|
160
|
+
end
|
153
161
|
end
|
154
162
|
|
155
163
|
#--
|
156
164
|
# START INSTANCE
|
157
165
|
#--
|
158
166
|
def start_instance(credentials, id)
|
167
|
+
safely do
|
159
168
|
terremark_client = new_client(credentials)
|
160
|
-
terremark_client.power_on(id)
|
169
|
+
return terremark_client.power_on(id)
|
170
|
+
end
|
161
171
|
end
|
162
172
|
|
163
173
|
#--
|
164
174
|
# STOP INSTANCE
|
165
175
|
#--
|
166
176
|
def stop_instance(credentials, id)
|
177
|
+
safely do
|
167
178
|
terremark_client = new_client(credentials)
|
168
|
-
terremark_client.power_shutdown(id)
|
179
|
+
return terremark_client.power_shutdown(id)
|
180
|
+
end
|
169
181
|
end
|
170
182
|
|
171
183
|
#--
|
@@ -173,8 +185,10 @@ end
|
|
173
185
|
#--
|
174
186
|
#shuts down... in terremark need to do a futher delete to get rid of a vapp entirely
|
175
187
|
def destroy_instance(credentials, id)
|
188
|
+
safely do
|
176
189
|
terremark_client = new_client(credentials)
|
177
|
-
terremark_client.delete_vapp(id)
|
190
|
+
return terremark_client.delete_vapp(id)
|
191
|
+
end
|
178
192
|
end
|
179
193
|
|
180
194
|
#--
|
@@ -246,14 +260,24 @@ end
|
|
246
260
|
def new_client(credentials)
|
247
261
|
#Fog constructor expecting credentials[:terremark_password] and credentials[:terremark_username]
|
248
262
|
terremark_credentials = {:terremark_vcloud_username => "#{credentials.user}", :terremark_vcloud_password => "#{credentials.password}" }
|
249
|
-
|
250
|
-
|
263
|
+
safely do
|
264
|
+
terremark_client = Fog::Terremark::Vcloud.new(terremark_credentials)
|
265
|
+
vdc_id = terremark_client.default_vdc_id
|
266
|
+
end
|
251
267
|
if (vdc_id.nil?)
|
252
268
|
raise DeltaCloud::AuthException.new
|
253
269
|
end
|
254
270
|
terremark_client
|
255
271
|
end
|
256
272
|
|
273
|
+
def safely(&block)
|
274
|
+
begin
|
275
|
+
block.call
|
276
|
+
rescue Exception => e
|
277
|
+
raise Deltacloud::BackendError.new(500, e.class.to_s, e.message, e.backtrace)
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
257
281
|
|
258
282
|
end
|
259
283
|
|
@@ -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
|