occi 1.2.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -0
- data/.project +32 -0
- data/.rspec +1 -0
- data/.travis.yml +8 -0
- data/.yardopts +1 -0
- data/AUTHORS +8 -0
- data/Gemfile +35 -14
- data/Gemfile.lock +89 -32
- data/LICENSE +13 -4
- data/README.md +70 -21
- data/Rakefile +25 -21
- data/lib/OpenNebula/Acl.rb +256 -0
- data/lib/OpenNebula/AclPool.rb +53 -0
- data/lib/OpenNebula/Group.rb +147 -0
- data/lib/OpenNebula/GroupPool.rb +54 -0
- data/lib/OpenNebula/Host.rb +143 -0
- data/lib/OpenNebula/HostPool.rb +55 -0
- data/lib/OpenNebula/Image.rb +256 -0
- data/lib/OpenNebula/ImagePool.rb +74 -0
- data/lib/OpenNebula/OpenNebula.rb +137 -0
- data/lib/OpenNebula/Pool.rb +285 -0
- data/lib/OpenNebula/Template.rb +173 -0
- data/lib/OpenNebula/TemplatePool.rb +74 -0
- data/lib/OpenNebula/User.rb +157 -0
- data/lib/OpenNebula/UserPool.rb +53 -0
- data/lib/OpenNebula/VirtualMachine.rb +319 -0
- data/lib/OpenNebula/VirtualMachinePool.rb +120 -0
- data/lib/OpenNebula/VirtualNetwork.rb +229 -0
- data/lib/OpenNebula/VirtualNetworkPool.rb +74 -0
- data/lib/OpenNebula/XMLUtils.rb +337 -0
- data/lib/occi/antlr/.gitignore +18 -0
- data/lib/occi/antlr/OCCI.g +164 -0
- data/lib/occi/antlr/OCCI.tokens +75 -0
- data/lib/occi/antlr/OCCILexer.rb +1532 -0
- data/lib/occi/antlr/OCCIParser.rb +2472 -0
- data/lib/occi/antlr/README.md +2 -0
- data/lib/occi/backend/dummy.rb +232 -0
- data/lib/occi/backend/ec2/Compute.rb +310 -0
- data/lib/occi/backend/ec2/compute.rb +310 -0
- data/lib/occi/backend/ec2/ec2.rb +215 -0
- data/lib/occi/backend/manager.rb +131 -0
- data/lib/occi/backend/opennebula/compute.rb +360 -0
- data/lib/occi/backend/opennebula/network.rb +143 -0
- data/lib/occi/backend/opennebula/opennebula.rb +188 -0
- data/lib/occi/backend/opennebula/storage.rb +175 -0
- data/lib/occi/configuration.rb +118 -0
- data/lib/occi/core/action.rb +29 -0
- data/lib/occi/core/attribute_properties.rb +54 -0
- data/lib/occi/core/attributes.rb +40 -0
- data/lib/occi/core/category.rb +62 -0
- data/lib/occi/core/collection.rb +27 -0
- data/lib/occi/core/entity.rb +135 -0
- data/lib/occi/core/kind.rb +55 -0
- data/lib/occi/core/link.rb +88 -0
- data/lib/occi/core/mixin.rb +43 -0
- data/lib/occi/core/resource.rb +73 -0
- data/lib/occi/exceptions.rb +59 -0
- data/lib/occi/extensions/monitoring/cpu.rb +51 -0
- data/lib/occi/extensions/monitoring/memory.rb +49 -0
- data/lib/occi/extensions/monitoring/metric.rb +54 -0
- data/lib/occi/extensions/monitoring/netrx.rb +49 -0
- data/lib/occi/extensions/monitoring/nettx.rb +55 -0
- data/lib/occi/extensions/one/VNC.rb +58 -0
- data/lib/occi/extensions/one/vnc.rb +58 -0
- data/lib/occi/log.rb +47 -0
- data/lib/occi/parse.rb +164 -0
- data/lib/occi/registry.rb +87 -0
- data/lib/occi/server.rb +594 -0
- data/lib/occi/version.rb +3 -0
- data/occi.gemspec +18 -96
- data/spec/occi/antlr/parser_spec.rb +82 -0
- data/spec/spec_helper.rb +6 -0
- metadata +100 -208
- data/.autotest +0 -21
- data/.rvmrc +0 -1
- data/VERSION +0 -1
- data/lib/occi.rb +0 -1
- data/lib/occi/client.rb +0 -36
- data/lib/occi/compute.rb +0 -4
- data/lib/occi/network.rb +0 -4
- data/lib/occi/resource.rb +0 -59
- data/lib/occi/storage.rb +0 -7
- data/test/fixtures/cassettes/compute_all.yml +0 -28
- data/test/fixtures/cassettes/compute_create.yml +0 -45
- data/test/fixtures/cassettes/compute_destroy.yml +0 -22
- data/test/fixtures/cassettes/compute_find.yml +0 -28
- data/test/fixtures/cassettes/compute_update.yml +0 -35
- data/test/fixtures/cassettes/network_all.yml +0 -28
- data/test/fixtures/cassettes/network_create.yml +0 -37
- data/test/fixtures/cassettes/network_destroy.yml +0 -22
- data/test/fixtures/cassettes/network_find.yml +0 -28
- data/test/fixtures/cassettes/storage_all.yml +0 -28
- data/test/fixtures/cassettes/storage_create.yml +0 -50
- data/test/fixtures/cassettes/storage_destroy.yml +0 -22
- data/test/fixtures/cassettes/storage_find.yml +0 -28
- data/test/lib/occi/compute_test.rb +0 -91
- data/test/lib/occi/network_test.rb +0 -57
- data/test/lib/occi/storage_test.rb +0 -67
- data/test/test_helper.rb +0 -48
@@ -0,0 +1,143 @@
|
|
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: OpenNebula Backend
|
19
|
+
# Author(s): Hayati Bice, Florian Feldhaus, Piotr Kasprzak
|
20
|
+
##############################################################################
|
21
|
+
|
22
|
+
require 'occi/log'
|
23
|
+
require 'erubis'
|
24
|
+
require 'ipaddr'
|
25
|
+
|
26
|
+
module OCCI
|
27
|
+
module Backend
|
28
|
+
module OpenNebula
|
29
|
+
|
30
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
31
|
+
module Network
|
32
|
+
|
33
|
+
TEMPLATENETWORKRAWFILE = 'network.erb'
|
34
|
+
|
35
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
36
|
+
# private
|
37
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
38
|
+
|
39
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
40
|
+
def network_parse_backend_object(backend_object)
|
41
|
+
|
42
|
+
# get information on storage object from OpenNebula backend
|
43
|
+
backend_object.info
|
44
|
+
|
45
|
+
network_kind = OCCI::Registry.get_by_id("http://schemas.ogf.org/occi/infrastructure#network")
|
46
|
+
|
47
|
+
network = Hashie::Mash.new
|
48
|
+
|
49
|
+
network.kind = storage_kind.type_identifier
|
50
|
+
network.mixins = %w|http://opennebula.org/occi/infrastructure#network http://schemas.ogf.org/occi/infrastructure#ipnetwork|
|
51
|
+
network.id = self.generate_occi_id(network_kind, backend_object.id.to_s)
|
52
|
+
network.title = backend_object['NAME']
|
53
|
+
network.summary = backend_object['TEMPLATE/DESCRIPTION'] if backend_object['TEMPLATE/DESCRIPTION']
|
54
|
+
|
55
|
+
network.attributes!.occi!.network!.address = backend_object['TEMPLATE/NETWORK_ADDRESS'] if backend_object['TEMPLATE/NETWORK_ADDRESS']
|
56
|
+
network.attributes!.occi!.network!.gateway = backend_object['TEMPLATE/GATEWAY'] if backend_object['TEMPLATE/GATEWAY']
|
57
|
+
network.attributes!.occi!.network!.vlan = backend_object['TEMPLATE/VLAN_ID'] if backend_object['TEMPLATE/VLAN_ID']
|
58
|
+
network.attributes!.occi!.network!.allocation = "static" if backend_object['TEMPLATE/TYPE'].downcase == "fixed"
|
59
|
+
network.attributes!.occi!.network!.allocation = "dynamic" if backend_object['TEMPLATE/TYPE'].downcase == "ranged"
|
60
|
+
|
61
|
+
network.attributes!.org!.opennebula!.network!.vlan = backend_object['TEMPLATE/VLAN'] if backend_object['TEMPLATE/VLAN']
|
62
|
+
network.attributes!.org!.opennebula!.network!.phydev = backend_object['TEMPLATE/PHYDEV'] if backend_object['TEMPLATE/PHYDEV']
|
63
|
+
network.attributes!.org!.opennebula!.network!.bridge = backend_object['TEMPLATE/BRIDGE'] if backend_object['TEMPLATE/BRIDGE']
|
64
|
+
|
65
|
+
network.attributes!.org!.opennebula!.network!.ip_start = backend_object['TEMPLATE/IP_START'] if backend_object['TEMPLATE/IP_START']
|
66
|
+
network.attributes!.org!.opennebula!.network!.ip_end = backend_object['TEMPLATE/IP_END'] if backend_object['TEMPLATE/IP_END']
|
67
|
+
|
68
|
+
network = OCCI::Core::Resource.new(network)
|
69
|
+
|
70
|
+
network_set_state(backend_object, network)
|
71
|
+
|
72
|
+
network_kind.entities << network
|
73
|
+
end
|
74
|
+
|
75
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
76
|
+
public
|
77
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
78
|
+
|
79
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
80
|
+
def network_deploy(network)
|
81
|
+
|
82
|
+
backend_object = VirtualNetwork.new(VirtualNetwork.build_xml(), @one_client)
|
83
|
+
|
84
|
+
template_location = OCCI::Server.config["TEMPLATE_LOCATION"] + TEMPLATENETWORKRAWFILE
|
85
|
+
template = Erubis::Eruby.new(File.read(template_raw)).evaluate(network)
|
86
|
+
|
87
|
+
OCCI::Log.debug("Parsed template #{template}")
|
88
|
+
rc = backend_object.allocate(template)
|
89
|
+
check_rc(rc)
|
90
|
+
|
91
|
+
backend_object.info
|
92
|
+
network.id = self.generate_occi_id(OCCI::Registry.get_by_id(network.kind), backend_object['ID'].to_s)
|
93
|
+
|
94
|
+
network_set_state(backend_object, network)
|
95
|
+
|
96
|
+
OCCI::Log.debug("OpenNebula ID of virtual network: #{network.backend[:id]}")
|
97
|
+
end
|
98
|
+
|
99
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
100
|
+
def network_set_state(backend_object, network)
|
101
|
+
network.attributes!.occi!.network!.state = "active"
|
102
|
+
end
|
103
|
+
|
104
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
105
|
+
def network_delete(network)
|
106
|
+
backend_object = VirtualNetwork.new(VirtualNetwork.build_xml(network.backend[:id]), @one_client)
|
107
|
+
rc = backend_object.delete
|
108
|
+
check_rc(rc)
|
109
|
+
end
|
110
|
+
|
111
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
112
|
+
def network_register_all_instances
|
113
|
+
occi_objects = []
|
114
|
+
backend_object_pool=VirtualNetworkPool.new(@one_client, OCCI::Backend::OpenNebula::OpenNebula::INFO_ACL)
|
115
|
+
backend_object_pool.info
|
116
|
+
backend_object_pool.each { |backend_object| network_parse_backend_object(backend_object) }
|
117
|
+
end
|
118
|
+
|
119
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
120
|
+
# STORAGE ACTIONS
|
121
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
122
|
+
|
123
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
124
|
+
def network_action_dummy(network, parameters)
|
125
|
+
end
|
126
|
+
|
127
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
128
|
+
def network_up(network, parameters)
|
129
|
+
backend_object = VirtualNetwork.new(VirtualNetwork.build_xml(network.backend[:id]), @one_client)
|
130
|
+
# not implemented in OpenNebula
|
131
|
+
end
|
132
|
+
|
133
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
134
|
+
def network_down(network, parameters)
|
135
|
+
backend_object = VirtualNetwork.new(VirtualNetwork.build_xml(network.backend[:id]), @one_client)
|
136
|
+
# not implemented in OpenNebula
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
@@ -0,0 +1,188 @@
|
|
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: OpenNebula Backend
|
19
|
+
# Author(s): Hayati Bice, Florian Feldhaus, Piotr Kasprzak
|
20
|
+
##############################################################################
|
21
|
+
|
22
|
+
require 'rubygems'
|
23
|
+
require 'uuidtools'
|
24
|
+
require 'OpenNebula/OpenNebula'
|
25
|
+
require 'occi/registry'
|
26
|
+
|
27
|
+
# OpenNebula backend
|
28
|
+
require 'occi/backend/opennebula/compute'
|
29
|
+
require 'occi/backend/opennebula/network'
|
30
|
+
require 'occi/backend/opennebula/storage'
|
31
|
+
|
32
|
+
# OpenNebula backend based mixins
|
33
|
+
#require 'occi/extensions/one/Image'
|
34
|
+
#require 'occi/extensions/one/Network'
|
35
|
+
#require 'occi/extensions/one/VirtualMachine'
|
36
|
+
#require 'occi/extensions/one/VNC'
|
37
|
+
|
38
|
+
#require 'occi/extensions/Reservation'
|
39
|
+
|
40
|
+
require 'occi/log'
|
41
|
+
|
42
|
+
include OpenNebula
|
43
|
+
|
44
|
+
module OCCI
|
45
|
+
module Backend
|
46
|
+
module OpenNebula
|
47
|
+
|
48
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
49
|
+
class OpenNebula
|
50
|
+
|
51
|
+
# The ACL level to be used when querying resource in OpenNebula:
|
52
|
+
# - INFO_ALL returns all resources and works only when running under the oneadmin account
|
53
|
+
# - INFO_GROUP returns the resources of the account + his group (= default)
|
54
|
+
# - INFO_MINE returns only the resources of the account
|
55
|
+
INFO_ACL = OpenNebula::Pool::INFO_GROUP
|
56
|
+
|
57
|
+
include Compute
|
58
|
+
include Network
|
59
|
+
include Storage
|
60
|
+
|
61
|
+
|
62
|
+
# Operation mappings
|
63
|
+
|
64
|
+
OPERATIONS = {}
|
65
|
+
|
66
|
+
OPERATIONS["http://schemas.ogf.org/occi/infrastructure#compute"] = {
|
67
|
+
|
68
|
+
# Generic resource operations
|
69
|
+
:deploy => :compute_deploy,
|
70
|
+
:update_state => :compute_update_state,
|
71
|
+
:delete => :compute_delete,
|
72
|
+
|
73
|
+
# Compute specific resource operations
|
74
|
+
:start => :compute_start,
|
75
|
+
:stop => :compute_stop,
|
76
|
+
:restart => :compute_restart,
|
77
|
+
:suspend => :compute_suspend
|
78
|
+
}
|
79
|
+
|
80
|
+
OPERATIONS["http://schemas.ogf.org/occi/infrastructure#network"] = {
|
81
|
+
|
82
|
+
# Generic resource operations
|
83
|
+
:deploy => :network_deploy,
|
84
|
+
:update_state => :network_update_state,
|
85
|
+
:delete => :network_delete,
|
86
|
+
|
87
|
+
# Network specific resource operations
|
88
|
+
:up => :network_up,
|
89
|
+
:down => :network_down
|
90
|
+
}
|
91
|
+
|
92
|
+
OPERATIONS["http://schemas.ogf.org/occi/infrastructure#storage"] = {
|
93
|
+
|
94
|
+
# Generic resource operations
|
95
|
+
:deploy => :storage_deploy,
|
96
|
+
:update_state => :storage_update_state,
|
97
|
+
:delete => :storage_delete,
|
98
|
+
|
99
|
+
# Network specific resource operations
|
100
|
+
:online => :storage_online,
|
101
|
+
:offline => :storage_offline,
|
102
|
+
:backup => :storage_backup,
|
103
|
+
:snapshot => :storage_snapshot,
|
104
|
+
:resize => :storage_resize
|
105
|
+
}
|
106
|
+
|
107
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
108
|
+
# Register backend specific mixins
|
109
|
+
begin
|
110
|
+
#OCCI::CategoryRegistry.register(OCCI::Backend::ONE::Image::MIXIN)
|
111
|
+
#OCCI::CategoryRegistry.register(OCCI::Backend::ONE::Network::MIXIN)
|
112
|
+
#OCCI::CategoryRegistry.register(OCCI::Backend::ONE::VirtualMachine::MIXIN)
|
113
|
+
#OCCI::CategoryRegistry.register(OCCI::Mixins::Reservation::MIXIN)
|
114
|
+
end
|
115
|
+
|
116
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
117
|
+
# private
|
118
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
119
|
+
|
120
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
121
|
+
def check_rc(rc)
|
122
|
+
if rc.class == Error
|
123
|
+
raise OCCI::BackendError, "Error message from OpenNebula: #{rc.to_str}"
|
124
|
+
# TODO: return failed!
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
129
|
+
# Generate a new occi id for resources created directly in OpenNebula using a seed id and the kind identifier
|
130
|
+
def generate_occi_id(kind, seed_id)
|
131
|
+
# Use strings as kind ids
|
132
|
+
kind = kind.type_identifier if kind.kind_of?(OCCI::Core::Kind)
|
133
|
+
return UUIDTools::UUID.sha1_create(UUIDTools::UUID_DNS_NAMESPACE, "#{kind}:#{seed_id}").to_s
|
134
|
+
end
|
135
|
+
|
136
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
137
|
+
public
|
138
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
139
|
+
|
140
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
141
|
+
def initialize(user, password)
|
142
|
+
|
143
|
+
# TODO: create mixins from existing templates
|
144
|
+
|
145
|
+
# initialize OpenNebula connection
|
146
|
+
OCCI::Log.debug("### Initializing connection with OpenNebula")
|
147
|
+
|
148
|
+
# TODO: check for error!
|
149
|
+
# @one_client = Client.new(OCCI::Server.config['one_user'] + ':' + OCCI::Server.config['one_password'], OCCI::Server.config['one_xmlrpc'])
|
150
|
+
@one_client = Client.new(user + ':' + password, OCCI::Server.config['one_xmlrpc'])
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
155
|
+
def register_existing_resources
|
156
|
+
# get all compute objects
|
157
|
+
resource_template_register
|
158
|
+
os_template_register
|
159
|
+
compute_register_all_instances
|
160
|
+
network_register_all_instances
|
161
|
+
storage_register_all_instances
|
162
|
+
end
|
163
|
+
|
164
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
165
|
+
def resource_template_register
|
166
|
+
# currently not directly supported by OpenNebula
|
167
|
+
end
|
168
|
+
|
169
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
170
|
+
def os_template_register
|
171
|
+
backend_object_pool=TemplatePool.new(@one_client, INFO_ACL)
|
172
|
+
backend_object_pool.info
|
173
|
+
backend_object_pool.each do |backend_object|
|
174
|
+
related = OCCI::Registry.get_by_id('http://schemas.ogf.org/occi/infrastructure#os_tpl')
|
175
|
+
term = backend_object['NAME'].downcase.chomp.gsub(/\W/, '_')
|
176
|
+
# TODO: implement correct schema for service provider
|
177
|
+
scheme = "http://schemas.opennebula.org/occi/infrastructure/os_tpl#"
|
178
|
+
title = backend_object['NAME']
|
179
|
+
mixin = OCCI::Core::Mixin.new(:related => related, :term=>term, :scheme=>scheme,:title=>title)
|
180
|
+
OCCI::CategoryRegistry.register(mixin)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
185
|
+
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
@@ -0,0 +1,175 @@
|
|
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: OpenNebula Backend
|
19
|
+
# Author(s): Hayati Bice, Florian Feldhaus, Piotr Kasprzak
|
20
|
+
##############################################################################
|
21
|
+
|
22
|
+
require 'occi/log'
|
23
|
+
require 'erubis'
|
24
|
+
|
25
|
+
module OCCI
|
26
|
+
module Backend
|
27
|
+
module OpenNebula
|
28
|
+
|
29
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
30
|
+
module Storage
|
31
|
+
|
32
|
+
TEMPLATESTORAGERAWFILE = 'storage.erb'
|
33
|
+
|
34
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
35
|
+
# private
|
36
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
37
|
+
|
38
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
39
|
+
def storage_parse_backend_object(backend_object)
|
40
|
+
|
41
|
+
# get information on storage object from OpenNebula backend
|
42
|
+
backend_object.info
|
43
|
+
|
44
|
+
storage_kind = OCCI::Registry.get_by_id("http://schemas.ogf.org/occi/infrastructure#storage")
|
45
|
+
|
46
|
+
storage = Hashie::Mash.new
|
47
|
+
|
48
|
+
storage.kind = storage_kind.type_identifier
|
49
|
+
storage.mixins = %w|http://opennebula.org/occi/infrastructure#storage|
|
50
|
+
storage.id = self.generate_occi_id(storage_kind, backend_object.id.to_s)
|
51
|
+
storage.title = backend_object['NAME']
|
52
|
+
storage.summary = backend_object['TEMPLATE/DESCRIPTION'] if backend_object['TEMPLATE/DESCRIPTION']
|
53
|
+
|
54
|
+
storage.attributes!.occi!.storage!.size = backend_object['TEMPLATE/SIZE'].to_f/1000 if backend_object['TEMPLATE/SIZE']
|
55
|
+
|
56
|
+
storage.attributes!.org!.opennebula!.storage!.type = backend_object['TEMPLATE/TYPE'] if backend_object['TEMPLATE/TYPE']
|
57
|
+
storage.attributes!.org!.opennebula!.storage!.persistent = backend_object['TEMPLATE/PERSISTENT'] if backend_object['TEMPLATE/PERSISTENT']
|
58
|
+
storage.attributes!.org!.opennebula!.storage!.dev_prefix = backend_object['TEMPLATE/DEV_PREFIX'] if backend_object['TEMPLATE/DEV_PREFIX']
|
59
|
+
storage.attributes!.org!.opennebula!.storage!.bus = backend_object['TEMPLATE/BUS'] if backend_object['TEMPLATE/BUS']
|
60
|
+
storage.attributes!.org!.opennebula!.storage!.driver = backend_object['TEMPLATE/DRIVER'] if backend_object['TEMPLATE/DRIVER']
|
61
|
+
|
62
|
+
storage = OCCI::Core::Resource.new(storage)
|
63
|
+
|
64
|
+
storage_set_state(backend_object, storage)
|
65
|
+
|
66
|
+
storage_kind.entities << storage
|
67
|
+
end
|
68
|
+
|
69
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
70
|
+
public
|
71
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
72
|
+
|
73
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
74
|
+
def storage_deploy(storage)
|
75
|
+
|
76
|
+
backend_object = Image.new(Image.build_xml, @one_client)
|
77
|
+
|
78
|
+
template_location = OCCI::Server.config["TEMPLATE_LOCATION"] + TEMPLATESTORAGERAWFILE
|
79
|
+
template = Erubis::Eruby.new(File.read(template_raw)).evaluate(storage)
|
80
|
+
|
81
|
+
OCCI::Log.debug("Parsed template #{template}")
|
82
|
+
rc = backend_object.allocate(template)
|
83
|
+
check_rc(rc)
|
84
|
+
OCCI::Log.debug("OpenNebula ID of image: #{storage.backend[:id]}")
|
85
|
+
|
86
|
+
backend_object.info
|
87
|
+
storage.id = self.generate_occi_id(OCCI::Registry.get_by_id(storage.kind), backend_object['ID'].to_s)
|
88
|
+
|
89
|
+
storage_set_state(backend_object, storage)
|
90
|
+
end
|
91
|
+
|
92
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
93
|
+
def storage_set_state(backend_object, storage)
|
94
|
+
OCCI::Log.debug("current Image state is: #{backend_object.state_str}")
|
95
|
+
storage.links = []
|
96
|
+
case backend_object.state_str
|
97
|
+
when "READY", "USED", "LOCKED" then
|
98
|
+
storage.attributes!.occi!.storage!.state = "online"
|
99
|
+
storage.links << OCCI::Core::Link.new(:target=>storage.location + '?action=offline',:rel=>'http://schemas.ogf.org/occi/infrastructure/storage/action#offline')
|
100
|
+
storage.links << OCCI::Core::Link.new(:target=>storage.location + '?action=backup',:rel=>'http://schemas.ogf.org/occi/infrastructure/storage/action#backup')
|
101
|
+
storage.links << OCCI::Core::Link.new(:target=>storage.location + '?action=snapshot',:rel=>'http://schemas.ogf.org/occi/infrastructure/storage/action#snapshot')
|
102
|
+
storage.links << OCCI::Core::Link.new(:target=>storage.location + '?action=resize',:rel=>'http://schemas.ogf.org/occi/infrastructure/storage/action#resize')
|
103
|
+
when "ERROR" then
|
104
|
+
storage.attributes!.occi!.storage!.state = "degraded"
|
105
|
+
storage.links << OCCI::Core::Link.new(:target=>storage.location + '?action=online',:rel=>'http://schemas.ogf.org/occi/infrastructure/storage/action#online')
|
106
|
+
else
|
107
|
+
storage.attributes!.occi!.storage!.state = "offline"
|
108
|
+
storage.links << OCCI::Core::Link.new(:target=>storage.location + '?action=online',:rel=>'http://schemas.ogf.org/occi/infrastructure/storage/action#online')
|
109
|
+
storage.links << OCCI::Core::Link.new(:target=>storage.location + '?action=backup',:rel=>'http://schemas.ogf.org/occi/infrastructure/storage/action#backup')
|
110
|
+
storage.links << OCCI::Core::Link.new(:target=>storage.location + '?action=snapshot',:rel=>'http://schemas.ogf.org/occi/infrastructure/storage/action#snapshot')
|
111
|
+
storage.links << OCCI::Core::Link.new(:target=>storage.location + '?action=resize',:rel=>'http://schemas.ogf.org/occi/infrastructure/storage/action#resize')
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
116
|
+
def storage_delete(storage)
|
117
|
+
backend_object = Image.new(Image.build_xml(storage.backend.id), @one_client)
|
118
|
+
rc = backend_object.delete
|
119
|
+
check_rc(rc)
|
120
|
+
end
|
121
|
+
|
122
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
123
|
+
def storage_register_all_instances
|
124
|
+
occi_objects = []
|
125
|
+
backend_object_pool=ImagePool.new(@one_client, OCCI::Backend::OpenNebula::OpenNebula::INFO_ACL)
|
126
|
+
backend_object_pool.info
|
127
|
+
backend_object_pool.each { |backend_object| storage_parse_backend_object(backend_object) }
|
128
|
+
end
|
129
|
+
|
130
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
131
|
+
# STORAGE ACTIONS
|
132
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
133
|
+
|
134
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
135
|
+
def storage_action_dummy(storage, parameters)
|
136
|
+
end
|
137
|
+
|
138
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
139
|
+
# Action online
|
140
|
+
def storage_online(network, parameters)
|
141
|
+
backend_object = Image.new(Image.build_xml(network.backend.id), @one_client)
|
142
|
+
rc = backend_object.enable
|
143
|
+
check_rc(rc)
|
144
|
+
end
|
145
|
+
|
146
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
147
|
+
# Action offline
|
148
|
+
def storage_offline(network, parameters)
|
149
|
+
backend_object = Image.new(Image.build_xml(network.backend.id), @one_client)
|
150
|
+
rc = backend_object.disable
|
151
|
+
check_rc(rc)
|
152
|
+
end
|
153
|
+
|
154
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
155
|
+
# Action backup
|
156
|
+
def storage_backup(network, parameters)
|
157
|
+
OCCI::Log.debug("not yet implemented")
|
158
|
+
end
|
159
|
+
|
160
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
161
|
+
# Action snapshot
|
162
|
+
def storage_snapshot(network, parameters)
|
163
|
+
OCCI::Log.debug("not yet implemented")
|
164
|
+
end
|
165
|
+
|
166
|
+
# ---------------------------------------------------------------------------------------------------------------------
|
167
|
+
# Action resize
|
168
|
+
def storage_resize(network, parameters)
|
169
|
+
OCCI::Log.debug("not yet implemented")
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|