occi 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/occi/version.rb +1 -1
- metadata +1 -17
- data/lib/occi/backend/dummy.rb +0 -232
- data/lib/occi/backend/ec2/Compute.rb +0 -310
- data/lib/occi/backend/ec2/compute.rb +0 -310
- data/lib/occi/backend/ec2/ec2.rb +0 -215
- data/lib/occi/backend/manager.rb +0 -131
- data/lib/occi/backend/opennebula/compute.rb +0 -360
- data/lib/occi/backend/opennebula/network.rb +0 -143
- data/lib/occi/backend/opennebula/opennebula.rb +0 -188
- data/lib/occi/backend/opennebula/storage.rb +0 -175
- data/lib/occi/extensions/monitoring/cpu.rb +0 -51
- data/lib/occi/extensions/monitoring/memory.rb +0 -49
- data/lib/occi/extensions/monitoring/metric.rb +0 -54
- data/lib/occi/extensions/monitoring/netrx.rb +0 -49
- data/lib/occi/extensions/monitoring/nettx.rb +0 -55
- data/lib/occi/extensions/one/VNC.rb +0 -58
- data/lib/occi/extensions/one/vnc.rb +0 -58
data/lib/occi/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: occi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -38,15 +38,6 @@ files:
|
|
38
38
|
- lib/occi/antlr/OCCILexer.rb
|
39
39
|
- lib/occi/antlr/OCCIParser.rb
|
40
40
|
- lib/occi/antlr/README.md
|
41
|
-
- lib/occi/backend/dummy.rb
|
42
|
-
- lib/occi/backend/ec2/Compute.rb
|
43
|
-
- lib/occi/backend/ec2/compute.rb
|
44
|
-
- lib/occi/backend/ec2/ec2.rb
|
45
|
-
- lib/occi/backend/manager.rb
|
46
|
-
- lib/occi/backend/opennebula/compute.rb
|
47
|
-
- lib/occi/backend/opennebula/network.rb
|
48
|
-
- lib/occi/backend/opennebula/opennebula.rb
|
49
|
-
- lib/occi/backend/opennebula/storage.rb
|
50
41
|
- lib/occi/core/action.rb
|
51
42
|
- lib/occi/core/attribute_properties.rb
|
52
43
|
- lib/occi/core/attributes.rb
|
@@ -58,13 +49,6 @@ files:
|
|
58
49
|
- lib/occi/core/mixin.rb
|
59
50
|
- lib/occi/core/resource.rb
|
60
51
|
- lib/occi/exceptions.rb
|
61
|
-
- lib/occi/extensions/monitoring/cpu.rb
|
62
|
-
- lib/occi/extensions/monitoring/memory.rb
|
63
|
-
- lib/occi/extensions/monitoring/metric.rb
|
64
|
-
- lib/occi/extensions/monitoring/netrx.rb
|
65
|
-
- lib/occi/extensions/monitoring/nettx.rb
|
66
|
-
- lib/occi/extensions/one/VNC.rb
|
67
|
-
- lib/occi/extensions/one/vnc.rb
|
68
52
|
- lib/occi/log.rb
|
69
53
|
- lib/occi/parse.rb
|
70
54
|
- lib/occi/registry.rb
|
data/lib/occi/backend/dummy.rb
DELETED
@@ -1,232 +0,0 @@
|
|
1
|
-
##############################################################################
|
2
|
-
# Copyright 2011 Service Computing group, TU Dortmund
|
3
|
-
#
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
# you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain a copy of the License at
|
7
|
-
#
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
# See the License for the specific language governing permissions and
|
14
|
-
# limitations under the License.
|
15
|
-
##############################################################################
|
16
|
-
|
17
|
-
##############################################################################
|
18
|
-
# Description: Dummy Backend
|
19
|
-
# Author(s): Hayati Bice, Florian Feldhaus, Piotr Kasprzak
|
20
|
-
##############################################################################
|
21
|
-
|
22
|
-
require 'occi/backend/manager'
|
23
|
-
require 'hashie/hash'
|
24
|
-
require 'occi/log'
|
25
|
-
require 'uuidtools'
|
26
|
-
require 'pstore'
|
27
|
-
|
28
|
-
module OCCI
|
29
|
-
module Backend
|
30
|
-
|
31
|
-
# ---------------------------------------------------------------------------------------------------------------------
|
32
|
-
class Dummy
|
33
|
-
|
34
|
-
def initialize
|
35
|
-
@store = PStore.new('collection')
|
36
|
-
@store.transaction do
|
37
|
-
@store['resources'] ||= []
|
38
|
-
@store['links'] ||= []
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
# ---------------------------------------------------------------------------------------------------------------------
|
43
|
-
# Operation mappings
|
44
|
-
|
45
|
-
OPERATIONS = {}
|
46
|
-
|
47
|
-
OPERATIONS["http://schemas.ogf.org/occi/infrastructure#compute"] = {
|
48
|
-
|
49
|
-
# Generic resource operations
|
50
|
-
:deploy => :compute_deploy,
|
51
|
-
:update_state => :resource_update_state,
|
52
|
-
:delete => :resource_delete,
|
53
|
-
|
54
|
-
# network specific resource operations
|
55
|
-
:start => :compute_action_start,
|
56
|
-
:stop => :compute_action_stop,
|
57
|
-
:restart => :compute_action_restart,
|
58
|
-
:suspend => :compute_action_suspend
|
59
|
-
}
|
60
|
-
|
61
|
-
OPERATIONS["http://schemas.ogf.org/occi/infrastructure#network"] = {
|
62
|
-
|
63
|
-
# Generic resource operations
|
64
|
-
:deploy => :network_deploy,
|
65
|
-
:update_state => :resource_update_state,
|
66
|
-
:delete => :resource_delete,
|
67
|
-
|
68
|
-
# Network specific resource operations
|
69
|
-
:up => :network_action_up,
|
70
|
-
:down => :network_action_down
|
71
|
-
}
|
72
|
-
|
73
|
-
OPERATIONS["http://schemas.ogf.org/occi/infrastructure#storage"] = {
|
74
|
-
|
75
|
-
# Generic resource operations
|
76
|
-
:deploy => :storage_deploy,
|
77
|
-
:update_state => :resource_update_state,
|
78
|
-
:delete => :resource_delete,
|
79
|
-
|
80
|
-
# Network specific resource operations
|
81
|
-
:online => :storage_action_online,
|
82
|
-
:offline => :storage_action_offline,
|
83
|
-
:backup => :storage_action_backup,
|
84
|
-
:snapshot => :storage_action_snapshot,
|
85
|
-
:resize => :storage_action_resize
|
86
|
-
}
|
87
|
-
|
88
|
-
# ---------------------------------------------------------------------------------------------------------------------
|
89
|
-
def register_existing_resources
|
90
|
-
@store.transaction(read_only=true) do
|
91
|
-
entities = @store['resources'] + @store['links']
|
92
|
-
entities.each do |entity|
|
93
|
-
kind = OCCI::Registry.get_by_id(entity.kind)
|
94
|
-
kind.entities << entity
|
95
|
-
OCCI::Log.debug("#### Number of entities in kind #{kind.type_identifier}: #{kind.entities.size}")
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
# TODO: register user defined mixins
|
101
|
-
|
102
|
-
def compute_deploy(compute)
|
103
|
-
compute.id = UUIDTools::UUID.timestamp_create.to_s
|
104
|
-
compute_action_start(compute)
|
105
|
-
store(compute)
|
106
|
-
end
|
107
|
-
|
108
|
-
def storage_deploy(storage)
|
109
|
-
storage.id = UUIDTools::UUID.timestamp_create.to_s
|
110
|
-
storage_action_online(storage)
|
111
|
-
store(storage)
|
112
|
-
end
|
113
|
-
|
114
|
-
def network_deploy(network)
|
115
|
-
network.id = UUIDTools::UUID.timestamp_create.to_s
|
116
|
-
network_action_up(network)
|
117
|
-
store(network)
|
118
|
-
end
|
119
|
-
|
120
|
-
# ---------------------------------------------------------------------------------------------------------------------
|
121
|
-
def store(resource)
|
122
|
-
OCCI::Log.debug("### DUMMY: Deploying resource with id #{resource.id}")
|
123
|
-
@store.transaction do
|
124
|
-
@store['resources'].delete_if { |res| res.id == resource.id }
|
125
|
-
@store['resources'] << resource
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
# ---------------------------------------------------------------------------------------------------------------------
|
130
|
-
def resource_update_state(resource)
|
131
|
-
OCCI::Log.debug("Updating state of resource '#{resource.attributes['occi.core.title']}'...")
|
132
|
-
end
|
133
|
-
|
134
|
-
# ---------------------------------------------------------------------------------------------------------------------
|
135
|
-
def resource_delete(resource)
|
136
|
-
OCCI::Log.debug("Deleting resource '#{resource.attributes['occi.core.title']}'...")
|
137
|
-
@store.transaction do
|
138
|
-
@store['resources'].delete_if { |res| res.id == resource.id }
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
# ---------------------------------------------------------------------------------------------------------------------
|
143
|
-
# ACTIONS
|
144
|
-
# ---------------------------------------------------------------------------------------------------------------------
|
145
|
-
|
146
|
-
def compute_action_start(compute, parameters=nil)
|
147
|
-
action_dummy(compute)
|
148
|
-
compute.attributes!.occi!.compute!.state = 'active'
|
149
|
-
compute.links << OCCI::Core::Link.new(:target => compute.location + '?action=stop', :rel => 'http://schemas.ogf.org/occi/infrastructure/compute/action#start')
|
150
|
-
compute.links << OCCI::Core::Link.new(:target => compute.location + '?action=restart', :rel => 'http://schemas.ogf.org/occi/infrastructure/compute/action#restart')
|
151
|
-
compute.links << OCCI::Core::Link.new(:target => compute.location + '?action=suspend', :rel => 'http://schemas.ogf.org/occi/infrastructure/compute/action#suspend')
|
152
|
-
store(compute)
|
153
|
-
end
|
154
|
-
|
155
|
-
def compute_action_stop(compute, parameters=nil)
|
156
|
-
action_dummy(compute)
|
157
|
-
compute.attributes!.occi!.compute!.state = 'inactive'
|
158
|
-
compute.links << OCCI::Core::Link.new(:target => compute.location + '?action=start', :rel => 'http://schemas.ogf.org/occi/infrastructure/compute/action#start')
|
159
|
-
store(compute)
|
160
|
-
end
|
161
|
-
|
162
|
-
def compute_action_restart(compute, parameters=nil)
|
163
|
-
compute_action_start(compute)
|
164
|
-
end
|
165
|
-
|
166
|
-
def compute_action_suspend(compute, parameters=nil)
|
167
|
-
action_dummy(compute)
|
168
|
-
compute.attributes!.occi!.compute!.state = 'suspended'
|
169
|
-
compute.links << OCCI::Core::Link.new(:target => compute.location + '?action=start', :rel => 'http://schemas.ogf.org/occi/infrastructure/compute/action#start')
|
170
|
-
store(compute)
|
171
|
-
end
|
172
|
-
|
173
|
-
def storage_action_online(storage, parameters=nil)
|
174
|
-
action_dummy(storage)
|
175
|
-
storage.attributes!.occi!.storage!.state = 'online'
|
176
|
-
storage.links << OCCI::Core::Link.new(:target => storage.location + '?action=offline', :rel => 'http://schemas.ogf.org/occi/infrastructure/storage/action#offline')
|
177
|
-
storage.links << OCCI::Core::Link.new(:target => storage.location + '?action=backup', :rel => 'http://schemas.ogf.org/occi/infrastructure/storage/action#restart')
|
178
|
-
storage.links << OCCI::Core::Link.new(:target => storage.location + '?action=snapshot', :rel => 'http://schemas.ogf.org/occi/infrastructure/storage/action#suspend')
|
179
|
-
storage.links << OCCI::Core::Link.new(:target => storage.location + '?action=resize', :rel => 'http://schemas.ogf.org/occi/infrastructure/storage/action#resize')
|
180
|
-
store(storage)
|
181
|
-
end
|
182
|
-
|
183
|
-
def storage_action_offline(storage, parameters=nil)
|
184
|
-
action_dummy(storage)
|
185
|
-
storage.attributes!.occi!.storage!.state = 'offline'
|
186
|
-
storage.links << OCCI::Core::Link.new(:target => storage.location + '?action=online', :rel => 'http://schemas.ogf.org/occi/infrastructure/storage/action#online')
|
187
|
-
storage.links << OCCI::Core::Link.new(:target => storage.location + '?action=backup', :rel => 'http://schemas.ogf.org/occi/infrastructure/storage/action#restart')
|
188
|
-
storage.links << OCCI::Core::Link.new(:target => storage.location + '?action=snapshot', :rel => 'http://schemas.ogf.org/occi/infrastructure/storage/action#suspend')
|
189
|
-
storage.links << OCCI::Core::Link.new(:target => storage.location + '?action=resize', :rel => 'http://schemas.ogf.org/occi/infrastructure/storage/action#resize')
|
190
|
-
store(storage)
|
191
|
-
end
|
192
|
-
|
193
|
-
def storage_action_backup(storage, parameters=nil)
|
194
|
-
# nothing to do, state and actions stay the same after the backup which is instant for the dummy
|
195
|
-
end
|
196
|
-
|
197
|
-
def storage_action_snapshot(storage, parameters=nil)
|
198
|
-
# nothing to do, state and actions stay the same after the snapshot which is instant for the dummy
|
199
|
-
end
|
200
|
-
|
201
|
-
def storage_action_resize(storage, parameters=nil)
|
202
|
-
puts "Parameters: #{parameters}"
|
203
|
-
storage.attributes!.occi!.storage!.size = parameters[:size].to_i
|
204
|
-
# state and actions stay the same after the resize which is instant for the dummy
|
205
|
-
store(storage)
|
206
|
-
end
|
207
|
-
|
208
|
-
def network_action_up(network, parameters=nil)
|
209
|
-
action_dummy(network)
|
210
|
-
network.attributes!.occi!.network!.state = 'up'
|
211
|
-
network.links << OCCI::Core::Link.new(:target => network.location + '?action=down', :rel => 'http://schemas.ogf.org/occi/infrastructure/network/action#down')
|
212
|
-
store(network)
|
213
|
-
end
|
214
|
-
|
215
|
-
def network_action_down(network, parameters=nil)
|
216
|
-
action_dummy(network)
|
217
|
-
network.attributes!.occi!.network!.state = 'down'
|
218
|
-
network.links << OCCI::Core::Link.new(:target => network.location + '?action=up', :rel => 'http://schemas.ogf.org/occi/infrastructure/network/action#up')
|
219
|
-
store(network)
|
220
|
-
end
|
221
|
-
|
222
|
-
# ---------------------------------------------------------------------------------------------------------------------
|
223
|
-
def action_dummy(resource, parameters=nil)
|
224
|
-
OCCI::Log.debug("Calling method for resource '#{resource.attributes['occi.core.title']}' with parameters: #{parameters.inspect}")
|
225
|
-
resource.links ||= []
|
226
|
-
resource.links.delete_if { |link| link.rel.include? 'action' }
|
227
|
-
end
|
228
|
-
|
229
|
-
end
|
230
|
-
|
231
|
-
end
|
232
|
-
end
|
@@ -1,310 +0,0 @@
|
|
1
|
-
##############################################################################
|
2
|
-
# Copyright 2011 Service Computing group, TU Dortmund
|
3
|
-
#
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
# you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain a copy of the License at
|
7
|
-
#
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
-
#
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
# See the License for the specific language governing permissions and
|
14
|
-
# limitations under the License.
|
15
|
-
##############################################################################
|
16
|
-
|
17
|
-
##############################################################################
|
18
|
-
# Description: EC2 Backend
|
19
|
-
# Author(s): Max Guenther
|
20
|
-
##############################################################################
|
21
|
-
|
22
|
-
require 'aws-sdk'
|
23
|
-
require 'occi/log'
|
24
|
-
|
25
|
-
module OCCI
|
26
|
-
module Backend
|
27
|
-
module EC2
|
28
|
-
|
29
|
-
# ---------------------------------------------------------------------------------------------------------------------
|
30
|
-
module Compute
|
31
|
-
|
32
|
-
# ---------------------------------------------------------------------------------------------------------------------
|
33
|
-
private
|
34
|
-
# ---------------------------------------------------------------------------------------------------------------------
|
35
|
-
|
36
|
-
def get_backend_instance(compute)
|
37
|
-
# get the ec2 interface
|
38
|
-
ec2 = OCCI::Backend::EC2.get_ec2_interface()
|
39
|
-
|
40
|
-
# get the ec2 backend instance
|
41
|
-
backend_instance = ec2.instances[compute.backend[:id]]
|
42
|
-
|
43
|
-
raise "Problems refreshing compute instance: An instance with the EC2 ID #{compute.backend[:id]} could not be found." if backend_instance.nil?
|
44
|
-
# return the instance
|
45
|
-
return backend_instance
|
46
|
-
end
|
47
|
-
|
48
|
-
def has_console_link(compute)
|
49
|
-
compute.links.each do |link|
|
50
|
-
OCCI::Log.debug("Link: #{link}")
|
51
|
-
if link.kind.term == "console"
|
52
|
-
return true
|
53
|
-
end
|
54
|
-
end
|
55
|
-
return false
|
56
|
-
end
|
57
|
-
|
58
|
-
def key_pair_exists(key_name)
|
59
|
-
ec2 = OCCI::Backend::EC2.get_ec2_interface()
|
60
|
-
|
61
|
-
ec2.key_pairs.each do |key|
|
62
|
-
if key.name == "default_occi_key"
|
63
|
-
return true
|
64
|
-
end
|
65
|
-
end
|
66
|
-
return false
|
67
|
-
end
|
68
|
-
|
69
|
-
public
|
70
|
-
# ---------------------------------------------------------------------------------------------------------------------
|
71
|
-
|
72
|
-
# ---------------------------------------------------------------------------------------------------------------------
|
73
|
-
def compute_deploy(compute)
|
74
|
-
OCCI::Log.debug("Deploying EC2 instance.")
|
75
|
-
|
76
|
-
# look what template and instance type to use
|
77
|
-
image_id = "ami-973b06e3" # fallback os template
|
78
|
-
instance_type = "t1.micro" # fallback resource template
|
79
|
-
compute.mixins.each do |mixin|
|
80
|
-
mixin.related.each do |related|
|
81
|
-
if related.term == "os_tpl"
|
82
|
-
image_id = mixin.term
|
83
|
-
break # use the first template found
|
84
|
-
elsif related.term == "resource_tpl"
|
85
|
-
instance_type = mixin.term
|
86
|
-
break # use the first template found
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
# get the ec2 interface
|
92
|
-
ec2 = OCCI::Backend::EC2.get_ec2_interface()
|
93
|
-
|
94
|
-
# create an instance
|
95
|
-
if key_pair_exists("default_occi_key")
|
96
|
-
backend_instance = ec2.instances.create(:image_id => image_id,
|
97
|
-
:instance_type => instance_type,
|
98
|
-
:key_name => "default_occi_key")
|
99
|
-
else
|
100
|
-
backend_instance = ec2.instances.create(:image_id => image_id,
|
101
|
-
:instance_type => instance_type)
|
102
|
-
end
|
103
|
-
|
104
|
-
# save the id of the instance
|
105
|
-
compute.backend[:id] = backend_instance.id
|
106
|
-
|
107
|
-
# link it to the private ec2 network
|
108
|
-
OCCI::Log.debug("Linking instance to \"/network/ec2_private_network\".")
|
109
|
-
private_network = OCCI::Rendering::HTTP::LocationRegistry.get_object("/network/ec2_private_network")
|
110
|
-
attributes = OCCI::Core::Attributes.new()
|
111
|
-
attributes["occi.networkinterface.interface"] = ""
|
112
|
-
attributes["occi.core.source"] = compute.get_location
|
113
|
-
attributes["occi.core.target"] = "/network/ec2_private_network"
|
114
|
-
ipnetwork = OCCI::CategoryRegistry.get_by_id("http://schemas.ogf.org/occi/infrastructure/networkinterface#ipnetworkinterface")
|
115
|
-
ipnetwork.backend[:network] = "private"
|
116
|
-
mixins = [ipnetwork]
|
117
|
-
private_networkinterface = OCCI::Infrastructure::Networkinterface.new(attributes, mixins)
|
118
|
-
# save the id of the compute backend instance in the network link for future identification
|
119
|
-
private_networkinterface.backend[:backend_id] = backend_instance.id
|
120
|
-
private_networkinterface.backend[:network] = "ec2_private_network"
|
121
|
-
compute.links << private_networkinterface
|
122
|
-
private_network.links << private_networkinterface
|
123
|
-
OCCI::Rendering::HTTP::LocationRegistry.register(private_networkinterface.get_location, private_networkinterface)
|
124
|
-
|
125
|
-
# link it to the public ec2 network
|
126
|
-
OCCI::Log.debug("Linking instance to \"/network/ec2_public_network\".")
|
127
|
-
public_network = OCCI::Rendering::HTTP::LocationRegistry.get_object("/network/ec2_public_network")
|
128
|
-
attributes = OCCI::Core::Attributes.new()
|
129
|
-
attributes["occi.networkinterface.interface"] = ""
|
130
|
-
attributes["occi.core.source"] = compute.get_location
|
131
|
-
attributes["occi.core.target"] = "/network/ec2_public_network"
|
132
|
-
ipnetwork = OCCI::CategoryRegistry.get_by_id("http://schemas.ogf.org/occi/infrastructure/networkinterface#ipnetworkinterface")
|
133
|
-
ipnetwork.backend[:network] = "ec2_public_network"
|
134
|
-
mixins = [ipnetwork]
|
135
|
-
public_networkinterface = OCCI::Infrastructure::Networkinterface.new(attributes, mixins)
|
136
|
-
# save the id of the compute backend instance in the network link for future identification
|
137
|
-
public_networkinterface.backend[:backend_id] = backend_instance.id
|
138
|
-
public_networkinterface.backend[:network] = "public"
|
139
|
-
compute.links << public_networkinterface
|
140
|
-
public_network.links << public_networkinterface
|
141
|
-
OCCI::Rendering::HTTP::LocationRegistry.register(public_networkinterface.get_location, public_networkinterface)
|
142
|
-
|
143
|
-
OCCI::Log.debug("Deployed EC2 instance with EC2 ID: #{compute.backend[:id]}")
|
144
|
-
end
|
145
|
-
|
146
|
-
# ---------------------------------------------------------------------------------------------------------------------
|
147
|
-
def compute_refresh(compute)
|
148
|
-
OCCI::Log.debug("Refreshing EC2 compute object with backend ID: #{compute.backend[:id]}")
|
149
|
-
|
150
|
-
# get the ec2 backend instance
|
151
|
-
backend_instance = get_backend_instance(compute)
|
152
|
-
|
153
|
-
# check if there are any problems with the backend instance
|
154
|
-
if backend_instance.nil?
|
155
|
-
OCCI::Log.debug("Problems refreshing compute instance: An instance with the EC2 ID #{compute.backend[:id]} could not be found.")
|
156
|
-
return
|
157
|
-
end
|
158
|
-
|
159
|
-
# update the state
|
160
|
-
compute_update_state(compute)
|
161
|
-
OCCI::Log.debug("Refreshed EC2 compute object with backend ID: #{compute.backend[:id]}")
|
162
|
-
|
163
|
-
# setting the architecture
|
164
|
-
compute.attributes["occi.compute.architecture"] = backend_instance.architecture.to_s
|
165
|
-
compute.attributes["ec2.compute.platform"] = backend_instance.platform
|
166
|
-
compute.attributes["ec2.compute.kernel_id"] = backend_instance.kernel_id
|
167
|
-
|
168
|
-
# update public and private ip
|
169
|
-
compute.links.each do |link|
|
170
|
-
if link.kind.term == "networkinterface" and link.backend[:backend_id] == backend_instance.id
|
171
|
-
if link.backend[:network] == "public" and backend_instance.ip_address != nil
|
172
|
-
link.mixins.each do |mixin|
|
173
|
-
if mixin.backend[:network] == "ec2_public_network"
|
174
|
-
link.attributes["occi.networkinterface.address"] = backend_instance.ip_address
|
175
|
-
state = OCCI::Infrastructure::Networkinterface::STATE_ACTIVE
|
176
|
-
link.state_machine.set_state(state)
|
177
|
-
link.attributes['occi.networkinterface.state'] = "active"
|
178
|
-
end
|
179
|
-
end
|
180
|
-
elsif link.backend[:network] == "private" and backend_instance.private_ip_address != nil
|
181
|
-
link.mixins.each do |mixin|
|
182
|
-
if mixin.backend[:network] == "ec2_private_network"
|
183
|
-
link.attributes["occi.networkinterface.address"] = backend_instance.private_ip_address
|
184
|
-
state = OCCI::Infrastructure::Networkinterface::STATE_ACTIVE
|
185
|
-
link.state_machine.set_state(state)
|
186
|
-
link.attributes['occi.networkinterface.state'] = "active"
|
187
|
-
end
|
188
|
-
end
|
189
|
-
end
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
# create the console link if not already existent and if in state active
|
194
|
-
if compute.state_machine.current_state == OCCI::Infrastructure::Compute::STATE_ACTIVE and not has_console_link(compute) and backend_instance.key_name == "default_occi_key"
|
195
|
-
# create a ConsoleLink
|
196
|
-
OCCI::Log.debug("Creating a ConsoleLink to the EC2 Compute instance.")
|
197
|
-
attributes = OCCI::Core::Attributes.new()
|
198
|
-
attributes['occi.core.target'] = "ssh://" + backend_instance.public_dns_name
|
199
|
-
attributes['occi.core.source'] = compute.get_location
|
200
|
-
mixins = []
|
201
|
-
console_link = OCCI::Infrastructure::ConsoleLink.new(attributes, mixins)
|
202
|
-
# save the id of the compute backend instance in the network link for future identification
|
203
|
-
console_link.backend[:backend_id] = backend_instance.id
|
204
|
-
# link and register
|
205
|
-
location = console_link.get_location
|
206
|
-
compute.links << console_link
|
207
|
-
OCCI::Rendering::HTTP::LocationRegistry.register(location, console_link)
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
# ---------------------------------------------------------------------------------------------------------------------
|
212
|
-
def compute_update_state(compute)
|
213
|
-
# get the ec2 backend instance
|
214
|
-
backend_instance = get_backend_instance(compute)
|
215
|
-
|
216
|
-
# map the ec2 state to an OCCI state
|
217
|
-
OCCI::Log.debug("Current EC2 VM state is: #{backend_instance.status}")
|
218
|
-
state = case backend_instance.status
|
219
|
-
when :running then
|
220
|
-
OCCI::Infrastructure::Compute::STATE_ACTIVE
|
221
|
-
when :pending, :shutting_down, :stopping, :terminated then
|
222
|
-
OCCI::Infrastructure::Compute::STATE_INACTIVE
|
223
|
-
when :stopped then
|
224
|
-
OCCI::Infrastructure::Compute::STATE_SUSPENDED
|
225
|
-
else
|
226
|
-
OCCI::Infrastructure::Compute::STATE_INACTIVE
|
227
|
-
end
|
228
|
-
# set the state
|
229
|
-
compute.state_machine.set_state(state)
|
230
|
-
compute.attributes['occi.compute.state'] = compute.state_machine.current_state.name
|
231
|
-
end
|
232
|
-
|
233
|
-
# ---------------------------------------------------------------------------------------------------------------------
|
234
|
-
def compute_delete(compute)
|
235
|
-
OCCI::Log.debug("Deleting EC2 Compute instance with EC2 ID #{compute.backend[:id]}")
|
236
|
-
|
237
|
-
# get the ec2 backend instance
|
238
|
-
backend_instance = get_backend_instance(compute)
|
239
|
-
|
240
|
-
if backend_instance.nil?
|
241
|
-
OCCI::Log.debug("Problems refreshing compute instance: An instance with the EC2 ID #{compute.backend[:id]} could not be found.")
|
242
|
-
return
|
243
|
-
end
|
244
|
-
# terminate the instance
|
245
|
-
backend_instance.terminate()
|
246
|
-
|
247
|
-
# delete networklinks to the private and public network and the ConsoleLink
|
248
|
-
compute.links.each do |link|
|
249
|
-
if link.backend[:backend_id] == backend_instance.id
|
250
|
-
location = OCCI::Rendering::HTTP::LocationRegistry.get_location_of_object(link)
|
251
|
-
OCCI::Log.debug("Deleting link to #{location}")
|
252
|
-
OCCI::Rendering::HTTP::LocationRegistry.unregister(location)
|
253
|
-
end
|
254
|
-
end
|
255
|
-
OCCI::Log.debug("Deleted EC2 Compute instance with EC2 ID #{compute.backend[:id]}")
|
256
|
-
end
|
257
|
-
|
258
|
-
# ---------------------------------------------------------------------------------------------------------------------
|
259
|
-
# COMPUTE ACTIONS
|
260
|
-
# ---------------------------------------------------------------------------------------------------------------------
|
261
|
-
# COMPUTE Action start
|
262
|
-
def compute_start(compute, parameters=nil)
|
263
|
-
OCCI::Log.debug("Starting EC2 VM with EC2 instance ID #{compute.backend[:id]}")
|
264
|
-
|
265
|
-
# get the ec2 backend instance
|
266
|
-
backend_instance = get_backend_instance(compute)
|
267
|
-
|
268
|
-
# suspend the instance (in EC2 lingo stop it)
|
269
|
-
backend_instance.start()
|
270
|
-
OCCI::Log.debug("Started EC2 VM with EC2 instance ID #{compute.backend[:id]}")
|
271
|
-
end
|
272
|
-
|
273
|
-
# ---------------------------------------------------------------------------------------------------------------------
|
274
|
-
# Action stop
|
275
|
-
def compute_stop(compute, parameters=nil)
|
276
|
-
OCCI::Log.debug("Stopping EC2 VM with EC2 instance ID #{compute.backend[:id]}")
|
277
|
-
|
278
|
-
# get the ec2 backend instance
|
279
|
-
backend_instance = get_backend_instance(compute)
|
280
|
-
|
281
|
-
# stop the instance
|
282
|
-
backend_instance.stop()
|
283
|
-
OCCI::Log.debug("Stopped EC2 VM with EC2 instance ID #{compute.backend[:id]}")
|
284
|
-
end
|
285
|
-
|
286
|
-
# ---------------------------------------------------------------------------------------------------------------------
|
287
|
-
# Action restart
|
288
|
-
def compute_restart(compute, parameters=nil)
|
289
|
-
OCCI::Log.debug("Restarting EC2 VM with EC2 instance ID #{compute.backend[:id]}")
|
290
|
-
|
291
|
-
# get the ec2 backend instance
|
292
|
-
backend_instance = get_backend_instance(compute)
|
293
|
-
|
294
|
-
# restart the instance
|
295
|
-
backend_instance.reboot()
|
296
|
-
OCCI::Log.debug("Restarted EC2 VM with EC2 instance ID #{compute.backend[:id]}")
|
297
|
-
end
|
298
|
-
|
299
|
-
# ---------------------------------------------------------------------------------------------------------------------
|
300
|
-
# Action suspend
|
301
|
-
def compute_suspend(compute, parameters=nil)
|
302
|
-
OCCI::Log.warning("Stop suspend is not supported on EC2 Compute instances.")
|
303
|
-
end
|
304
|
-
|
305
|
-
end
|
306
|
-
|
307
|
-
end
|
308
|
-
end
|
309
|
-
end
|
310
|
-
|