steamcannon-deltacloud-core 0.0.7.1-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYING +176 -0
- data/Rakefile +106 -0
- data/bin/deltacloudd +120 -0
- data/config.ru +5 -0
- data/deltacloud.rb +20 -0
- data/lib/deltacloud/base_driver/base_driver.rb +259 -0
- data/lib/deltacloud/base_driver/features.rb +173 -0
- data/lib/deltacloud/base_driver/mock_driver.rb +58 -0
- data/lib/deltacloud/base_driver.rb +20 -0
- data/lib/deltacloud/drivers/azure/azure_driver.rb +127 -0
- data/lib/deltacloud/drivers/ec2/ec2_driver.rb +580 -0
- data/lib/deltacloud/drivers/ec2/ec2_mock_driver.rb +170 -0
- data/lib/deltacloud/drivers/gogrid/gogrid_client.rb +50 -0
- data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +343 -0
- data/lib/deltacloud/drivers/gogrid/test.rb +13 -0
- data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob1.yml +5 -0
- data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob2.yml +5 -0
- data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob3.yml +5 -0
- data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob4.yml +5 -0
- data/lib/deltacloud/drivers/mock/data/buckets/blobs/blob5.yml +5 -0
- data/lib/deltacloud/drivers/mock/data/buckets/bucket1.yml +2 -0
- data/lib/deltacloud/drivers/mock/data/buckets/bucket2.yml +2 -0
- data/lib/deltacloud/drivers/mock/data/images/img1.yml +3 -0
- data/lib/deltacloud/drivers/mock/data/images/img2.yml +3 -0
- data/lib/deltacloud/drivers/mock/data/images/img3.yml +3 -0
- data/lib/deltacloud/drivers/mock/data/instances/inst0.yml +16 -0
- data/lib/deltacloud/drivers/mock/data/instances/inst1.yml +9 -0
- data/lib/deltacloud/drivers/mock/data/instances/inst2.yml +9 -0
- data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap1.yml +4 -0
- data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap2.yml +4 -0
- data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap3.yml +4 -0
- data/lib/deltacloud/drivers/mock/data/storage_volumes/vol1.yml +6 -0
- data/lib/deltacloud/drivers/mock/data/storage_volumes/vol2.yml +6 -0
- data/lib/deltacloud/drivers/mock/data/storage_volumes/vol3.yml +6 -0
- data/lib/deltacloud/drivers/mock/mock_driver.rb +356 -0
- data/lib/deltacloud/drivers/opennebula/cloud_client.rb +116 -0
- data/lib/deltacloud/drivers/opennebula/occi_client.rb +204 -0
- data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +241 -0
- data/lib/deltacloud/drivers/rackspace/rackspace_client.rb +130 -0
- data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +290 -0
- data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +258 -0
- data/lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb +85 -0
- data/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb +166 -0
- data/lib/deltacloud/drivers/terremark/terremark_driver.rb +295 -0
- data/lib/deltacloud/hardware_profile.rb +153 -0
- data/lib/deltacloud/helpers/application_helper.rb +122 -0
- data/lib/deltacloud/helpers/blob_stream.rb +51 -0
- data/lib/deltacloud/helpers/conversion_helper.rb +39 -0
- data/lib/deltacloud/helpers/hardware_profiles_helper.rb +35 -0
- data/lib/deltacloud/helpers.rb +5 -0
- data/lib/deltacloud/method_serializer.rb +85 -0
- data/lib/deltacloud/models/base_model.rb +59 -0
- data/lib/deltacloud/models/blob.rb +26 -0
- data/lib/deltacloud/models/bucket.rb +24 -0
- data/lib/deltacloud/models/image.rb +27 -0
- data/lib/deltacloud/models/instance.rb +38 -0
- data/lib/deltacloud/models/instance_profile.rb +48 -0
- data/lib/deltacloud/models/key.rb +35 -0
- data/lib/deltacloud/models/realm.rb +26 -0
- data/lib/deltacloud/models/storage_snapshot.rb +27 -0
- data/lib/deltacloud/models/storage_volume.rb +28 -0
- data/lib/deltacloud/state_machine.rb +84 -0
- data/lib/deltacloud/validation.rb +70 -0
- data/lib/drivers.rb +51 -0
- data/lib/sinatra/accept_media_types.rb +128 -0
- data/lib/sinatra/lazy_auth.rb +56 -0
- data/lib/sinatra/rabbit.rb +279 -0
- data/lib/sinatra/respond_to.rb +238 -0
- data/lib/sinatra/static_assets.rb +83 -0
- data/lib/sinatra/url_for.rb +53 -0
- data/public/favicon.ico +0 -0
- data/public/images/grid.png +0 -0
- data/public/images/logo-wide.png +0 -0
- data/public/images/rails.png +0 -0
- data/public/images/topbar-bg.png +0 -0
- data/public/javascripts/application.js +32 -0
- data/public/javascripts/jquery-1.4.2.min.js +154 -0
- data/public/stylesheets/compiled/application.css +613 -0
- data/public/stylesheets/compiled/ie.css +31 -0
- data/public/stylesheets/compiled/print.css +27 -0
- data/public/stylesheets/compiled/screen.css +456 -0
- data/server.rb +516 -0
- data/support/fedora/deltacloudd +68 -0
- data/support/fedora/rubygem-deltacloud-core.spec +91 -0
- data/tests/api_test.rb +37 -0
- data/tests/hardware_profiles_test.rb +120 -0
- data/tests/images_test.rb +111 -0
- data/tests/instance_states_test.rb +51 -0
- data/tests/instances_test.rb +222 -0
- data/tests/realms_test.rb +78 -0
- data/tests/url_for_test.rb +50 -0
- data/views/accounts/index.html.haml +11 -0
- data/views/accounts/show.html.haml +30 -0
- data/views/api/show.html.haml +15 -0
- data/views/api/show.xml.haml +5 -0
- data/views/blobs/show.html.haml +20 -0
- data/views/blobs/show.xml.haml +7 -0
- data/views/buckets/index.html.haml +33 -0
- data/views/buckets/index.xml.haml +10 -0
- data/views/buckets/new.html.haml +13 -0
- data/views/buckets/show.html.haml +19 -0
- data/views/buckets/show.xml.haml +8 -0
- data/views/docs/collection.html.haml +37 -0
- data/views/docs/collection.xml.haml +14 -0
- data/views/docs/index.html.haml +15 -0
- data/views/docs/index.xml.haml +5 -0
- data/views/docs/operation.html.haml +31 -0
- data/views/docs/operation.xml.haml +10 -0
- data/views/errors/auth_exception.html.haml +8 -0
- data/views/errors/auth_exception.xml.haml +2 -0
- data/views/errors/backend_error.html.haml +19 -0
- data/views/errors/backend_error.xml.haml +8 -0
- data/views/errors/not_found.html.haml +6 -0
- data/views/errors/not_found.xml.haml +2 -0
- data/views/errors/validation_failure.html.haml +11 -0
- data/views/errors/validation_failure.xml.haml +7 -0
- data/views/hardware_profiles/index.html.haml +25 -0
- data/views/hardware_profiles/index.xml.haml +4 -0
- data/views/hardware_profiles/show.html.haml +19 -0
- data/views/hardware_profiles/show.xml.haml +18 -0
- data/views/images/index.html.haml +30 -0
- data/views/images/index.xml.haml +8 -0
- data/views/images/show.html.haml +21 -0
- data/views/images/show.xml.haml +5 -0
- data/views/instance_states/show.html.haml +31 -0
- data/views/instance_states/show.png.erb +45 -0
- data/views/instance_states/show.xml.haml +8 -0
- data/views/instances/index.html.haml +30 -0
- data/views/instances/index.xml.haml +21 -0
- data/views/instances/new.html.haml +55 -0
- data/views/instances/show.html.haml +43 -0
- data/views/instances/show.xml.haml +49 -0
- 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
- data/views/layout.html.haml +26 -0
- data/views/realms/index.html.haml +29 -0
- data/views/realms/index.xml.haml +10 -0
- data/views/realms/show.html.haml +15 -0
- data/views/realms/show.xml.haml +9 -0
- data/views/root/index.html.haml +4 -0
- data/views/storage_snapshots/index.html.haml +20 -0
- data/views/storage_snapshots/index.xml.haml +9 -0
- data/views/storage_snapshots/show.html.haml +14 -0
- data/views/storage_snapshots/show.xml.haml +7 -0
- data/views/storage_volumes/index.html.haml +21 -0
- data/views/storage_volumes/index.xml.haml +23 -0
- data/views/storage_volumes/show.html.haml +20 -0
- data/views/storage_volumes/show.xml.haml +24 -0
- metadata +367 -0
|
@@ -0,0 +1,580 @@
|
|
|
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
|
+
|
|
20
|
+
require 'deltacloud/base_driver'
|
|
21
|
+
require 'active_support'
|
|
22
|
+
require 'AWS'
|
|
23
|
+
require 'right_aws'
|
|
24
|
+
|
|
25
|
+
class Instance
|
|
26
|
+
attr_accessor :keyname
|
|
27
|
+
attr_accessor :authn_error
|
|
28
|
+
|
|
29
|
+
def authn_feature_failed?
|
|
30
|
+
return true unless authn_error.nil?
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
module Deltacloud
|
|
36
|
+
module Drivers
|
|
37
|
+
module EC2
|
|
38
|
+
class EC2Driver < Deltacloud::BaseDriver
|
|
39
|
+
|
|
40
|
+
def supported_collections
|
|
41
|
+
DEFAULT_COLLECTIONS + [ :keys, :buckets ]
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
feature :instances, :user_data
|
|
45
|
+
feature :instances, :authentication_key
|
|
46
|
+
feature :images, :owner_id
|
|
47
|
+
feature :buckets, :bucket_location
|
|
48
|
+
|
|
49
|
+
define_hardware_profile('m1.small') do
|
|
50
|
+
cpu 1
|
|
51
|
+
memory 1.7 * 1024
|
|
52
|
+
storage 160
|
|
53
|
+
architecture 'i386'
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
define_hardware_profile('m1.large') do
|
|
57
|
+
cpu 4
|
|
58
|
+
memory 7.5 * 1024
|
|
59
|
+
storage 850
|
|
60
|
+
architecture 'x86_64'
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
define_hardware_profile('m1.xlarge') do
|
|
64
|
+
cpu 8
|
|
65
|
+
memory 15 * 1024
|
|
66
|
+
storage 1690
|
|
67
|
+
architecture 'x86_64'
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
define_hardware_profile('c1.medium') do
|
|
71
|
+
cpu 5
|
|
72
|
+
memory 1.7 * 1024
|
|
73
|
+
storage 350
|
|
74
|
+
architecture 'i386'
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
define_hardware_profile('c1.xlarge') do
|
|
78
|
+
cpu 20
|
|
79
|
+
memory 7 * 1024
|
|
80
|
+
storage 1690
|
|
81
|
+
architecture 'x86_64'
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
define_hardware_profile('m2.xlarge') do
|
|
85
|
+
cpu 6.5
|
|
86
|
+
memory 17.1 * 1024
|
|
87
|
+
storage 420
|
|
88
|
+
architecture 'x86_64'
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
define_hardware_profile('m2.2xlarge') do
|
|
92
|
+
cpu 13
|
|
93
|
+
memory 34.2 * 1024
|
|
94
|
+
storage 850
|
|
95
|
+
architecture 'x86_64'
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
define_hardware_profile('m2.4xlarge') do
|
|
99
|
+
cpu 26
|
|
100
|
+
memory 68.4 * 1024
|
|
101
|
+
storage 1690
|
|
102
|
+
architecture 'x86_64'
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
define_instance_states do
|
|
106
|
+
start.to( :pending ) .automatically
|
|
107
|
+
pending.to( :running ) .automatically
|
|
108
|
+
pending.to( :stopping ) .on( :stop )
|
|
109
|
+
pending.to( :stopped ) .automatically
|
|
110
|
+
stopped.to( :running ) .on( :start )
|
|
111
|
+
running.to( :running ) .on( :reboot )
|
|
112
|
+
running.to( :stopping ) .on( :stop )
|
|
113
|
+
shutting_down.to( :stopped ) .automatically
|
|
114
|
+
stopped.to( :finish ) .automatically
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
#
|
|
118
|
+
# Images
|
|
119
|
+
#
|
|
120
|
+
|
|
121
|
+
def images(credentials, opts={} )
|
|
122
|
+
ec2 = new_client(credentials)
|
|
123
|
+
img_arr = []
|
|
124
|
+
# if we know the image_id, we don't want to limit by owner_id, since this
|
|
125
|
+
# will exclude public images
|
|
126
|
+
if (opts and opts[:id])
|
|
127
|
+
config = { :image_id => opts[:id] }
|
|
128
|
+
else
|
|
129
|
+
config = { :owner_id => "amazon" }
|
|
130
|
+
config.merge!({ :owner_id => opts[:owner_id] }) if opts and opts[:owner_id]
|
|
131
|
+
end
|
|
132
|
+
safely do
|
|
133
|
+
ec2.describe_images(config).imagesSet.item.each do |image|
|
|
134
|
+
img_arr << convert_image(image)
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
img_arr = filter_on( img_arr, :architecture, opts )
|
|
138
|
+
img_arr.sort_by{|e| [e.owner_id, e.name]}
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
#
|
|
142
|
+
# Realms
|
|
143
|
+
#
|
|
144
|
+
|
|
145
|
+
def realms(credentials, opts=nil)
|
|
146
|
+
ec2 = new_client(credentials)
|
|
147
|
+
realms = []
|
|
148
|
+
safely do
|
|
149
|
+
ec2.describe_availability_zones.availabilityZoneInfo.item.each do |ec2_realm|
|
|
150
|
+
realms << convert_realm( ec2_realm )
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
realms
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
#
|
|
157
|
+
# Instances
|
|
158
|
+
#
|
|
159
|
+
def instances(credentials, opts=nil)
|
|
160
|
+
ec2 = new_client(credentials)
|
|
161
|
+
instances = []
|
|
162
|
+
safely do
|
|
163
|
+
param = opts.nil? ? nil : opts[:id]
|
|
164
|
+
ec2_instances = ec2.describe_instances.reservationSet
|
|
165
|
+
return [] unless ec2_instances
|
|
166
|
+
ec2_instances.item.each do |item|
|
|
167
|
+
item.instancesSet.item.each do |ec2_instance|
|
|
168
|
+
instances << convert_instance( ec2_instance, item.ownerId )
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
instances = filter_on( instances, :id, opts )
|
|
173
|
+
instances = filter_on( instances, :state, opts )
|
|
174
|
+
instances
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def create_instance(credentials, image_id, opts)
|
|
179
|
+
ec2 = new_client( credentials )
|
|
180
|
+
realm_id = opts[:realm_id]
|
|
181
|
+
safely do
|
|
182
|
+
image = image(credentials, :id => image_id )
|
|
183
|
+
hwp = find_hardware_profile(credentials, opts[:hwp_id], image.id)
|
|
184
|
+
ec2_instances = ec2.run_instances(
|
|
185
|
+
:image_id => image.id,
|
|
186
|
+
:user_data => opts[:user_data],
|
|
187
|
+
:key_name => opts[:keyname],
|
|
188
|
+
:availability_zone => realm_id,
|
|
189
|
+
:monitoring_enabled => true,
|
|
190
|
+
:instance_type => hwp.name,
|
|
191
|
+
:disable_api_termination => false,
|
|
192
|
+
:instance_initiated_shutdown_behavior => 'terminate',
|
|
193
|
+
:security_group => opts[:security_group]
|
|
194
|
+
)
|
|
195
|
+
return convert_instance( ec2_instances.instancesSet.item.first, 'pending' )
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
def generate_instance(ec2, id, backup)
|
|
200
|
+
begin
|
|
201
|
+
this_instance = ec2.describe_instances( :instance_id => id ).reservationSet.item.first.instancesSet.item.first
|
|
202
|
+
convert_instance(this_instance, this_instance.ownerId)
|
|
203
|
+
rescue Exception => e
|
|
204
|
+
puts "WARNING: ignored error during instance refresh: #{e.message}"
|
|
205
|
+
# at this point, the action has succeeded but our follow-up
|
|
206
|
+
# "describe_instances" failed for some reason. Create a simple Instance
|
|
207
|
+
# object with only the ID and new state in place
|
|
208
|
+
state = convert_state(backup.instancesSet.item.first.currentState.name)
|
|
209
|
+
Instance.new( {
|
|
210
|
+
:id => id,
|
|
211
|
+
:state => state,
|
|
212
|
+
:actions => instance_actions_for( state ),
|
|
213
|
+
} )
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
def reboot_instance(credentials, id)
|
|
218
|
+
ec2 = new_client(credentials)
|
|
219
|
+
backup = ec2.reboot_instances( :instance_id => id )
|
|
220
|
+
|
|
221
|
+
generate_instance(ec2, id, backup)
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
def stop_instance(credentials, id)
|
|
225
|
+
ec2 = new_client(credentials)
|
|
226
|
+
backup = ec2.terminate_instances( :instance_id => id )
|
|
227
|
+
|
|
228
|
+
generate_instance(ec2, id, backup)
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
def destroy_instance(credentials, id)
|
|
232
|
+
ec2 = new_client(credentials)
|
|
233
|
+
backup = ec2.terminate_instances( :instance_id => id )
|
|
234
|
+
|
|
235
|
+
generate_instance(ec2, id, backup)
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
#
|
|
239
|
+
# Storage Volumes
|
|
240
|
+
#
|
|
241
|
+
|
|
242
|
+
def storage_volumes(credentials, opts=nil)
|
|
243
|
+
ec2 = new_client( credentials )
|
|
244
|
+
volumes = []
|
|
245
|
+
safely do
|
|
246
|
+
if (opts)
|
|
247
|
+
ec2.describe_volumes(:volume_id => opts[:id]).volumeSet.item.each do |ec2_volume|
|
|
248
|
+
volumes << convert_volume( ec2_volume )
|
|
249
|
+
end
|
|
250
|
+
else
|
|
251
|
+
ec2_volumes = ec2.describe_volumes.volumeSet
|
|
252
|
+
return [] unless ec2_volumes
|
|
253
|
+
ec2_volumes.item.each do |ec2_volume|
|
|
254
|
+
volumes << convert_volume( ec2_volume )
|
|
255
|
+
end
|
|
256
|
+
end
|
|
257
|
+
end
|
|
258
|
+
volumes
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
def create_storage_volume(credentials, opts)
|
|
262
|
+
ec2 = new_client( credentials )
|
|
263
|
+
safely do
|
|
264
|
+
ec2_volume = ec2.create_volume(
|
|
265
|
+
:availability_zone => opts[:realm_id],
|
|
266
|
+
:size => opts[:capacity]
|
|
267
|
+
)
|
|
268
|
+
return convert_volume( ec2_volume )
|
|
269
|
+
end
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
def destroy_storage_volume(credentials, id)
|
|
273
|
+
ec2 = new_client(credentials)
|
|
274
|
+
ec2.delete_volume( :volume_id => id )
|
|
275
|
+
storage_volumes( credentials, :id => id ).first
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
def attach_storage_volume(credentials, opts)
|
|
279
|
+
ec2 = new_client(credentials)
|
|
280
|
+
id = opts[:id]
|
|
281
|
+
ec2.attach_volume(
|
|
282
|
+
:volume_id => id,
|
|
283
|
+
:instance_id => opts[:instance_id],
|
|
284
|
+
:device => opts[:device]
|
|
285
|
+
)
|
|
286
|
+
storage_volumes( credentials, :id => id ).first
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
def detach_storage_volume(credentials, id)
|
|
290
|
+
ec2 = new_client(credentials)
|
|
291
|
+
ec2.detach_volume( :volume_id => id )
|
|
292
|
+
storage_volumes( credentials, :id => id ).first
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
#
|
|
296
|
+
# Storage Snapshots
|
|
297
|
+
#
|
|
298
|
+
|
|
299
|
+
def storage_snapshots(credentials, opts=nil)
|
|
300
|
+
ec2 = new_client( credentials )
|
|
301
|
+
snapshots = []
|
|
302
|
+
safely do
|
|
303
|
+
if (opts)
|
|
304
|
+
ec2.describe_snapshots(:owner => 'self', :snapshot_id => opts[:id]).snapshotSet.item.each do |ec2_snapshot|
|
|
305
|
+
snapshots << convert_snapshot( ec2_snapshot )
|
|
306
|
+
end
|
|
307
|
+
else
|
|
308
|
+
ec2_snapshots = ec2.describe_snapshots(:owner => 'self').snapshotSet
|
|
309
|
+
return [] unless ec2_snapshots
|
|
310
|
+
ec2_snapshots.item.each do |ec2_snapshot|
|
|
311
|
+
snapshots << convert_snapshot( ec2_snapshot )
|
|
312
|
+
end
|
|
313
|
+
end
|
|
314
|
+
end
|
|
315
|
+
snapshots
|
|
316
|
+
end
|
|
317
|
+
|
|
318
|
+
def key(credentials, opts=nil)
|
|
319
|
+
keys(credentials, opts).first
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
def keys(credentials, opts=nil)
|
|
323
|
+
ec2 = new_client( credentials )
|
|
324
|
+
opts[:key_name] = opts[:id] if opts and opts[:id]
|
|
325
|
+
keypairs = ec2.describe_keypairs(opts || {})
|
|
326
|
+
result = []
|
|
327
|
+
safely do
|
|
328
|
+
keypairs.keySet.item.each do |keypair|
|
|
329
|
+
result << convert_key(keypair)
|
|
330
|
+
end
|
|
331
|
+
end
|
|
332
|
+
result
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
def create_key(credentials, opts={})
|
|
336
|
+
key = Key.new
|
|
337
|
+
ec2 = new_client( credentials )
|
|
338
|
+
safely do
|
|
339
|
+
key = convert_key(ec2.create_keypair(opts))
|
|
340
|
+
end
|
|
341
|
+
return key
|
|
342
|
+
end
|
|
343
|
+
|
|
344
|
+
def destroy_key(credentials, opts={})
|
|
345
|
+
safely do
|
|
346
|
+
ec2 = new_client( credentials )
|
|
347
|
+
ec2.delete_keypair(opts)
|
|
348
|
+
end
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
def valid_credentials?(credentials)
|
|
352
|
+
client = new_client(credentials)
|
|
353
|
+
# FIXME: We need to do this call to determine if
|
|
354
|
+
# EC2 is working with given credentials. There is no
|
|
355
|
+
# other way to check, if given credentials are valid or not.
|
|
356
|
+
realms = client.describe_availability_zones rescue false
|
|
357
|
+
return realms ? true : false
|
|
358
|
+
end
|
|
359
|
+
|
|
360
|
+
#--
|
|
361
|
+
# Buckets
|
|
362
|
+
#-- get a list of your buckets from the s3 service
|
|
363
|
+
def buckets(credentials, opts)
|
|
364
|
+
buckets = []
|
|
365
|
+
safely do
|
|
366
|
+
s3_client = s3_client(credentials)
|
|
367
|
+
bucket_list = s3_client.buckets
|
|
368
|
+
bucket_list.each do |current|
|
|
369
|
+
buckets << convert_bucket(current)
|
|
370
|
+
end
|
|
371
|
+
end
|
|
372
|
+
buckets = filter_on(buckets, :id, opts)
|
|
373
|
+
buckets
|
|
374
|
+
end
|
|
375
|
+
|
|
376
|
+
#--
|
|
377
|
+
# Create bucket
|
|
378
|
+
#--
|
|
379
|
+
#valid values for bucket location: 'EU'|'us-west1'|'ap-southeast-1' - if you
|
|
380
|
+
#don't specify a location then by default buckets are created in 'us-east'
|
|
381
|
+
#[but if you *do* specify 'us-east' things blow up]
|
|
382
|
+
def create_bucket(credentials, name, opts={})
|
|
383
|
+
bucket = nil
|
|
384
|
+
safely do
|
|
385
|
+
begin
|
|
386
|
+
s3_client = s3_client(credentials)
|
|
387
|
+
bucket_location = opts['location']
|
|
388
|
+
if bucket_location
|
|
389
|
+
bucket = RightAws::S3::Bucket.create(s3_client, name, true, nil, :location => bucket_location)
|
|
390
|
+
else
|
|
391
|
+
bucket = RightAws::S3::Bucket.create(s3_client, name, true)
|
|
392
|
+
end #if
|
|
393
|
+
rescue RightAws::AwsError => e
|
|
394
|
+
raise e unless e.message =~ /BucketAlreadyExists/
|
|
395
|
+
raise Deltacloud::BackendError.new(409, e.class.to_s, e.message, e.backtrace)
|
|
396
|
+
end #begin
|
|
397
|
+
end #do
|
|
398
|
+
convert_bucket(bucket)
|
|
399
|
+
end
|
|
400
|
+
|
|
401
|
+
#--
|
|
402
|
+
# Delete_bucket
|
|
403
|
+
#--
|
|
404
|
+
def delete_bucket(credentials, name, opts={})
|
|
405
|
+
s3_client = s3_client(credentials)
|
|
406
|
+
safely do
|
|
407
|
+
s3_client.interface.delete_bucket(name)
|
|
408
|
+
end
|
|
409
|
+
end
|
|
410
|
+
|
|
411
|
+
#--
|
|
412
|
+
# Blobs
|
|
413
|
+
#--
|
|
414
|
+
def blobs(credentials, opts = nil)
|
|
415
|
+
s3_client = s3_client(credentials)
|
|
416
|
+
blobs = []
|
|
417
|
+
safely do
|
|
418
|
+
s3_bucket = s3_client.bucket(opts['bucket'])
|
|
419
|
+
s3_bucket.keys({}, true).each do |s3_object|
|
|
420
|
+
blobs << convert_object(s3_object)
|
|
421
|
+
end
|
|
422
|
+
end
|
|
423
|
+
blobs = filter_on(blobs, :id, opts)
|
|
424
|
+
blobs
|
|
425
|
+
end
|
|
426
|
+
|
|
427
|
+
#--
|
|
428
|
+
# Blob data
|
|
429
|
+
#--
|
|
430
|
+
def blob_data(credentials, bucket_id, blob_id, opts)
|
|
431
|
+
s3_client = s3_client(credentials)
|
|
432
|
+
s3_client.interface.get(bucket_id, blob_id) do |chunk|
|
|
433
|
+
yield chunk
|
|
434
|
+
end
|
|
435
|
+
end
|
|
436
|
+
|
|
437
|
+
private
|
|
438
|
+
|
|
439
|
+
def new_client(credentials)
|
|
440
|
+
opts = {
|
|
441
|
+
:access_key_id => credentials.user,
|
|
442
|
+
:secret_access_key => credentials.password
|
|
443
|
+
}
|
|
444
|
+
opts[:server] = ENV['DCLOUD_EC2_URL'] if ENV['DCLOUD_EC2_URL']
|
|
445
|
+
safely do
|
|
446
|
+
AWS::EC2::Base.new(opts)
|
|
447
|
+
end
|
|
448
|
+
end
|
|
449
|
+
|
|
450
|
+
def convert_key(key)
|
|
451
|
+
Key.new({
|
|
452
|
+
:id => key['keyName'],
|
|
453
|
+
:fingerprint => key['keyFingerprint'],
|
|
454
|
+
:credential_type => :key,
|
|
455
|
+
:pem_rsa_key => key['keyMaterial']
|
|
456
|
+
})
|
|
457
|
+
end
|
|
458
|
+
|
|
459
|
+
def convert_image(ec2_image)
|
|
460
|
+
Image.new( {
|
|
461
|
+
:id=>ec2_image['imageId'],
|
|
462
|
+
:name=>ec2_image['name'] || ec2_image['imageId'],
|
|
463
|
+
:description=>ec2_image['description'] || ec2_image['imageLocation'] || '',
|
|
464
|
+
:owner_id=>ec2_image['imageOwnerId'],
|
|
465
|
+
:architecture=>ec2_image['architecture'],
|
|
466
|
+
} )
|
|
467
|
+
end
|
|
468
|
+
|
|
469
|
+
def convert_realm(ec2_realm)
|
|
470
|
+
Realm.new( {
|
|
471
|
+
:id=>ec2_realm['zoneName'],
|
|
472
|
+
:name=>ec2_realm['regionName'],
|
|
473
|
+
:limit=>ec2_realm['zoneState'].eql?('available') ? :unlimited : 0,
|
|
474
|
+
:state=>ec2_realm['zoneState'].upcase,
|
|
475
|
+
} )
|
|
476
|
+
end
|
|
477
|
+
|
|
478
|
+
def convert_state(ec2_state)
|
|
479
|
+
case ec2_state
|
|
480
|
+
when "terminated"
|
|
481
|
+
"STOPPED"
|
|
482
|
+
when "stopped"
|
|
483
|
+
"STOPPED"
|
|
484
|
+
when "running"
|
|
485
|
+
"RUNNING"
|
|
486
|
+
when "pending"
|
|
487
|
+
"PENDING"
|
|
488
|
+
when "shutting-down"
|
|
489
|
+
"STOPPED"
|
|
490
|
+
end
|
|
491
|
+
end
|
|
492
|
+
|
|
493
|
+
def convert_instance(ec2_instance, owner_id)
|
|
494
|
+
state = convert_state(ec2_instance['instanceState']['name'])
|
|
495
|
+
realm_id = ec2_instance['placement']['availabilityZone']
|
|
496
|
+
(realm_id = nil ) if ( realm_id == '' )
|
|
497
|
+
hwp_name = ec2_instance['instanceType']
|
|
498
|
+
instance = Instance.new( {
|
|
499
|
+
:id=>ec2_instance['instanceId'],
|
|
500
|
+
:name => ec2_instance['imageId'],
|
|
501
|
+
:state=>state,
|
|
502
|
+
:image_id=>ec2_instance['imageId'],
|
|
503
|
+
:owner_id=>owner_id,
|
|
504
|
+
:realm_id=>realm_id,
|
|
505
|
+
:public_addresses=>( ec2_instance['dnsName'] == '' ? [] : [ec2_instance['dnsName']] ),
|
|
506
|
+
:private_addresses=>( ec2_instance['privateDnsName'] == '' ? [] : [ec2_instance['privateDnsName']] ),
|
|
507
|
+
:instance_profile =>InstanceProfile.new(hwp_name),
|
|
508
|
+
:actions=>instance_actions_for( state ),
|
|
509
|
+
:keyname => ec2_instance['keyName'],
|
|
510
|
+
:launch_time => ec2_instance['launchTime']
|
|
511
|
+
} )
|
|
512
|
+
instance.authn_error = "Key not set for instance" unless ec2_instance['keyName']
|
|
513
|
+
return instance
|
|
514
|
+
end
|
|
515
|
+
|
|
516
|
+
def convert_volume(ec2_volume)
|
|
517
|
+
attachment = ec2_volume.attachmentSet.item.first if ec2_volume.attachmentSet
|
|
518
|
+
attachment ||= { }
|
|
519
|
+
StorageVolume.new( {
|
|
520
|
+
:id=>ec2_volume['volumeId'],
|
|
521
|
+
:created=>ec2_volume['createTime'],
|
|
522
|
+
:state=>ec2_volume['status'].upcase,
|
|
523
|
+
:capacity=>ec2_volume['size'],
|
|
524
|
+
:instance_id=>attachment['instanceId'],
|
|
525
|
+
:device=>attachment['device'],
|
|
526
|
+
} )
|
|
527
|
+
end
|
|
528
|
+
|
|
529
|
+
def convert_snapshot(ec2_snapshot)
|
|
530
|
+
StorageSnapshot.new( {
|
|
531
|
+
:id=>ec2_snapshot['snapshotId'],
|
|
532
|
+
:state=>ec2_snapshot['status'].upcase,
|
|
533
|
+
:storage_volume_id=>ec2_snapshot['volumeId'],
|
|
534
|
+
:created=>ec2_snapshot['startTime'],
|
|
535
|
+
} )
|
|
536
|
+
end
|
|
537
|
+
|
|
538
|
+
def s3_client(credentials)
|
|
539
|
+
safely do
|
|
540
|
+
s3_client = RightAws::S3.new(credentials.user, credentials.password)
|
|
541
|
+
end
|
|
542
|
+
end
|
|
543
|
+
|
|
544
|
+
def convert_bucket(s3_bucket)
|
|
545
|
+
#get blob list:
|
|
546
|
+
blob_list = []
|
|
547
|
+
s3_bucket.keys.each do |s3_object|
|
|
548
|
+
blob_list << s3_object.name
|
|
549
|
+
end
|
|
550
|
+
#can use AWS::S3::Owner.current.display_name or current.id
|
|
551
|
+
Bucket.new( { :id => s3_bucket.name,
|
|
552
|
+
:name => s3_bucket.name,
|
|
553
|
+
:size => s3_bucket.keys.length,
|
|
554
|
+
:blob_list => blob_list
|
|
555
|
+
}
|
|
556
|
+
)
|
|
557
|
+
end
|
|
558
|
+
|
|
559
|
+
def convert_object(s3_object)
|
|
560
|
+
Blob.new({ :id => s3_object.name,
|
|
561
|
+
:bucket => s3_object.bucket.name.to_s,
|
|
562
|
+
:content_length => s3_object.size,
|
|
563
|
+
:content_type => s3_object.content_type,
|
|
564
|
+
:last_modified => s3_object.last_modified
|
|
565
|
+
})
|
|
566
|
+
end
|
|
567
|
+
|
|
568
|
+
def catched_exceptions_list
|
|
569
|
+
{
|
|
570
|
+
:auth => [ AWS::AuthFailure ],
|
|
571
|
+
:error => [],
|
|
572
|
+
:glob => [ /AWS::(\w+)/ ]
|
|
573
|
+
}
|
|
574
|
+
end
|
|
575
|
+
|
|
576
|
+
end
|
|
577
|
+
|
|
578
|
+
end
|
|
579
|
+
end
|
|
580
|
+
end
|