occi 3.0.0.beta.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -26
- data/Gemfile.lock +43 -35
- data/README.md +40 -4
- data/bin/occi +67 -64
- data/ext/mkrf_conf.rb +25 -0
- data/features/cassettes/Create_an_OCCI_Resource/_http_http___141_5_99_69__text_plain_201_.yml +186 -0
- data/features/cassettes/Delete_an_OCCI_Resource/_http_http___141_5_99_69__text_plain_201_.yml +186 -0
- data/features/cassettes/Discovery_Interface/Retrieving_all_OCCI_Categories_supported_by_the_OCCI_Server/_http_http___141_5_99_69__application_json_200_.yml +173 -0
- data/features/cassettes/Discovery_Interface/Retrieving_all_OCCI_Categories_supported_by_the_OCCI_Server/_http_http___141_5_99_69__text_plain_200_.yml +325 -0
- data/features/cassettes/Discovery_Interface/Retrieving_all_OCCI_Categories_supported_by_the_OCCI_Server/_http_http___141_5_99_69__text_plain_200_action_.yml +186 -0
- data/features/cassettes/Miscellaneous_operation_on_an_OCCI_Resource/_http_http___141_5_99_69__text_plain_201_.yml +186 -0
- data/features/cassettes/Read_an_OCCI_Resource/_http_http___141_5_99_69__text_plain_201_.yml +186 -0
- data/features/cassettes/Update_an_OCCI_Resource/_http_http___141_5_99_69__text_plain_201_.yml +186 -0
- data/features/occi/core/create/create.feature +3 -2
- data/features/occi/core/delete/delete.feature +6 -2
- data/features/occi/core/discovery_interface/discovery_interface.feature +4 -2
- data/features/occi/core/miscellaneous/miscellaneous.feature +6 -2
- data/features/occi/core/read/read.feature +6 -2
- data/features/occi/core/update/update.feature +6 -2
- data/features/occi/infrastructure/create/create.feature +6 -2
- data/features/support/env.rb +13 -1
- data/lib/occi/api/client/client_http.rb +914 -820
- data/lib/occi/api/client/http/net_http_fix.rb +7 -36
- data/lib/occi/api/dsl.rb +32 -2
- data/lib/occi/bin/occi_opts.rb +15 -1
- data/lib/occi/collection.rb +26 -15
- data/lib/occi/core/categories.rb +9 -1
- data/lib/occi/core/category.rb +20 -11
- data/lib/occi/core/link.rb +4 -5
- data/lib/occi/model.rb +2 -2
- data/lib/occi/parser.rb +51 -49
- data/lib/occi/version.rb +1 -1
- data/occi.gemspec +16 -3
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/creates_a_new_compute_resource.yml +222 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/creates_a_new_network_resource.yml +222 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/creates_a_new_storage_resource.yml +222 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/deletes_a_compute_resource.yml +222 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/deletes_a_network_resource.yml +222 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/deletes_a_storage_resource.yml +222 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/deploys_an_instance_based_on_OVF_OVA_file.yml +222 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/describes_all_available_mixins.yml +222 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/describes_compute_resources.yml +324 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/describes_network_resources.yml +326 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/describes_os_tpl_mixins.yml +222 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/describes_resource_tpl_mixins.yml +222 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/describes_storage_resources.yml +386 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/establishes_connection.yml +222 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/instantiates_a_compute_resource_using_type_identifier.yml +222 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/instantiates_a_compute_resource_using_type_name.yml +222 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/instantiates_a_network_resource_using_type_identifier.yml +222 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/instantiates_a_network_resource_using_type_name.yml +222 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/instantiates_a_storage_resource_using_type_identifier.yml +222 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/instantiates_a_storage_resource_using_type_name.yml +222 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_all_available_entity_type_identifiers.yml +222 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_all_available_entity_types.yml +222 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_all_available_link_type_identifiers.yml +222 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_all_available_link_types.yml +222 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_all_available_mixin_type_identifiers.yml +222 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_all_available_mixin_types.yml +222 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_all_available_mixins.yml +222 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_all_available_resource_type_identifiers.yml +222 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_all_available_resource_types.yml +222 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_compute_resources.yml +264 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_network_resources.yml +264 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_os_tpl_mixins.yml +222 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_resource_tpl_mixins.yml +222 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/lists_storage_resources.yml +266 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/refreshes_its_model.yml +397 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/triggers_an_action_on_a_compute_resource.yml +222 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/triggers_an_action_on_a_network_resource.yml +222 -0
- data/spec/cassettes/Occi_Api_Client_ClientHttp/using_media_type_text_plain/triggers_an_action_on_a_storage_resource.yml +222 -0
- data/spec/occi/api/client/client_amqp_spec.rb +10 -2
- data/spec/occi/api/client/client_http_spec.rb +111 -117
- data/spec/occi/api/dsl_spec.rb +22 -0
- data/spec/occi/collection_spec.rb +11 -2
- data/spec/occi/core/resource_spec.rb +1 -1
- data/spec/occi/infrastructure/compute_spec.rb +3 -3
- data/spec/occi/log_spec.rb +1 -1
- data/spec/occi/model_spec.rb +4 -8
- data/spec/occi/parser_spec.rb +4 -4
- data/spec/spec_helper.rb +3 -2
- metadata +264 -12
- data/spec/cassettes/client_http_text_plain.yml +0 -1066
- data/spec/occi/api/client/client_http_0.5_spec.rb +0 -292
@@ -2,49 +2,20 @@
|
|
2
2
|
## Net::HTTP hack allowing the use of X.509 proxy certificates.
|
3
3
|
##############################################################################
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
# detect jRuby
|
9
|
-
if RUBY_ENGINE == 'jruby'
|
10
|
-
#TODO: add jRuby support, this doesn't work
|
11
|
-
module Net
|
12
|
-
class HTTP
|
5
|
+
module Net
|
6
|
+
class HTTP
|
13
7
|
|
8
|
+
if defined? SSL_ATTRIBUTES
|
9
|
+
# For Rubies 1.9.x
|
14
10
|
old_verbose, $VERBOSE = $VERBOSE, nil
|
15
11
|
SSL_ATTRIBUTES = SSL_ATTRIBUTES.concat %w(extra_chain_cert)
|
16
12
|
$VERBOSE = old_verbose
|
17
13
|
|
18
|
-
# An Array of certificates that will be sent to the client.
|
19
14
|
attr_accessor :extra_chain_cert
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
else
|
24
|
-
net_http_fix_rby_ver = RUBY_VERSION.split('.')
|
25
|
-
|
26
|
-
# detect old Rubies, tested with 1.8.7-p371
|
27
|
-
if net_http_fix_rby_ver[1] == "8"
|
28
|
-
module Net
|
29
|
-
class HTTP
|
30
|
-
|
31
|
-
# An Array of certificates that will be sent to the client.
|
32
|
-
ssl_context_accessor :extra_chain_cert
|
33
|
-
|
34
|
-
end
|
15
|
+
else
|
16
|
+
# For legacy Rubies 1.8.x
|
17
|
+
ssl_context_accessor :extra_chain_cert
|
35
18
|
end
|
36
|
-
else
|
37
|
-
module Net
|
38
|
-
class HTTP
|
39
|
-
|
40
|
-
old_verbose, $VERBOSE = $VERBOSE, nil
|
41
|
-
SSL_ATTRIBUTES = SSL_ATTRIBUTES.concat %w(extra_chain_cert)
|
42
|
-
$VERBOSE = old_verbose
|
43
19
|
|
44
|
-
# An Array of certificates that will be sent to the client.
|
45
|
-
attr_accessor :extra_chain_cert
|
46
|
-
|
47
|
-
end
|
48
|
-
end
|
49
20
|
end
|
50
21
|
end
|
data/lib/occi/api/dsl.rb
CHANGED
@@ -84,14 +84,44 @@ module Occi
|
|
84
84
|
@client.get_mixin_types
|
85
85
|
end
|
86
86
|
|
87
|
-
def
|
87
|
+
def entity_types
|
88
88
|
check
|
89
89
|
|
90
|
-
@client.
|
90
|
+
@client.get_entity_types
|
91
|
+
end
|
92
|
+
|
93
|
+
def entity_type_identifiers
|
94
|
+
check
|
95
|
+
|
96
|
+
@client.get_entity_type_identifiers
|
97
|
+
end
|
98
|
+
|
99
|
+
def entity_types_related_to(*args)
|
100
|
+
check
|
101
|
+
|
102
|
+
@client.get_entity_types_related_to(*args)
|
103
|
+
end
|
104
|
+
|
105
|
+
def link_types
|
106
|
+
check
|
107
|
+
|
108
|
+
@client.get_link_types
|
109
|
+
end
|
110
|
+
|
111
|
+
def link_type_identifiers
|
112
|
+
check
|
113
|
+
|
114
|
+
@client.get_link_type_identifiers
|
91
115
|
end
|
92
116
|
|
93
117
|
###
|
94
118
|
|
119
|
+
def mixins(*args)
|
120
|
+
check
|
121
|
+
|
122
|
+
@client.get_mixins(*args)
|
123
|
+
end
|
124
|
+
|
95
125
|
def resource(*args)
|
96
126
|
check
|
97
127
|
|
data/lib/occi/bin/occi_opts.rb
CHANGED
@@ -23,6 +23,7 @@ module Occi
|
|
23
23
|
options.log[:out] = STDERR
|
24
24
|
options.log[:level] = Occi::Log::WARN
|
25
25
|
|
26
|
+
options.filter = nil
|
26
27
|
options.dump_model = false
|
27
28
|
|
28
29
|
options.interactive = false
|
@@ -35,6 +36,7 @@ module Occi
|
|
35
36
|
options.auth[:ca_path] = "/etc/grid-security/certificates"
|
36
37
|
options.auth[:username] = "anonymous"
|
37
38
|
options.auth[:ca_file] = nil
|
39
|
+
options.auth[:proxy_ca] = nil
|
38
40
|
|
39
41
|
options.output_format = :plain
|
40
42
|
|
@@ -94,6 +96,11 @@ module Occi
|
|
94
96
|
options.auth[:ca_file] = ca_file
|
95
97
|
end
|
96
98
|
|
99
|
+
opts.on("-F",
|
100
|
+
"--filter CATEGORY", String, "Category type identifier to filter categories from model, must be used together with the -m option") do |filter|
|
101
|
+
options.filter = filter
|
102
|
+
end
|
103
|
+
|
97
104
|
opts.on("-x",
|
98
105
|
"--user-cred PATH",
|
99
106
|
String,
|
@@ -170,7 +177,7 @@ module Occi
|
|
170
177
|
|
171
178
|
opts.on_tail("-m",
|
172
179
|
"--dump-model",
|
173
|
-
"Contact the endpoint and dump its model") do |dump_model|
|
180
|
+
"Contact the endpoint and dump its model, cannot be used with the interactive mode") do |dump_model|
|
174
181
|
options.dump_model = dump_model
|
175
182
|
end
|
176
183
|
|
@@ -219,6 +226,13 @@ module Occi
|
|
219
226
|
exit!
|
220
227
|
end
|
221
228
|
|
229
|
+
if !options.dump_model && options.filter
|
230
|
+
puts "You cannot use '--filter' without '--dump-model'!"
|
231
|
+
puts opts
|
232
|
+
|
233
|
+
exit!
|
234
|
+
end
|
235
|
+
|
222
236
|
if !(options.interactive or options.dump_model)
|
223
237
|
mandatory = []
|
224
238
|
|
data/lib/occi/collection.rb
CHANGED
@@ -6,14 +6,14 @@ module Occi
|
|
6
6
|
# Initialize a new OCCI Collection by initializing all supplied OCCI objects
|
7
7
|
#
|
8
8
|
# @param [Hash] collection including one or more of the keys kinds, mixins, actions, resources, links
|
9
|
-
def initialize(collection={
|
9
|
+
def initialize(collection={}, model = Occi::Model.new)
|
10
10
|
collection = Hashie::Mash.new(collection) unless collection.kind_of? Occi::Collection
|
11
11
|
|
12
|
-
@kinds
|
13
|
-
@mixins
|
14
|
-
@actions
|
12
|
+
@kinds = Occi::Core::Kinds.new
|
13
|
+
@mixins = Occi::Core::Mixins.new
|
14
|
+
@actions = Occi::Core::Actions.new
|
15
15
|
@resources = Occi::Core::Resources.new
|
16
|
-
@links
|
16
|
+
@links = Occi::Core::Links.new
|
17
17
|
|
18
18
|
self.model = model if model
|
19
19
|
|
@@ -29,25 +29,25 @@ module Occi
|
|
29
29
|
not intersect(category).empty?
|
30
30
|
end
|
31
31
|
|
32
|
-
# @return [
|
32
|
+
# @return [Occi::Core::Categories] categories combined list of all kinds, mixins and actions
|
33
33
|
def categories
|
34
|
-
@kinds + @mixins + @actions
|
34
|
+
Occi::Core::Categories.new(@kinds + @mixins + @actions)
|
35
35
|
end
|
36
36
|
|
37
|
-
# @return [
|
37
|
+
# @return [Occi::Core::Entities] entities combined list of all resources and links
|
38
38
|
def entities
|
39
|
-
@resources + @links
|
39
|
+
Occi::Core::Entities.new(@resources + @links)
|
40
40
|
end
|
41
41
|
|
42
42
|
# @param [Occi::Core::Model] model
|
43
43
|
# @return [Occi::Core::Model]
|
44
44
|
def model=(model)
|
45
|
-
@model
|
46
|
-
@kinds.model
|
47
|
-
@mixins.model
|
48
|
-
@actions.model
|
45
|
+
@model = model
|
46
|
+
@kinds.model = model
|
47
|
+
@mixins.model = model
|
48
|
+
@actions.model = model
|
49
49
|
@resources.model = model
|
50
|
-
@links.model
|
50
|
+
@links.model = model
|
51
51
|
end
|
52
52
|
|
53
53
|
def check
|
@@ -122,8 +122,19 @@ module Occi
|
|
122
122
|
@kinds.empty? && @mixins.empty? && @actions.empty? && @resources.empty? && @links.empty? && @action.nil?
|
123
123
|
end
|
124
124
|
|
125
|
+
# Returns a collection with all categories related to the specified category
|
126
|
+
#
|
127
|
+
# @param [Occi::Core::Category] category
|
128
|
+
# @return [Occi::Core::Collection]
|
129
|
+
def get_related_to(category)
|
130
|
+
collection = self.class.new
|
131
|
+
collection.kinds = @kinds.get_related_to(category)
|
132
|
+
collection.mixins = @mixins.get_related_to(category)
|
133
|
+
collection
|
134
|
+
end
|
135
|
+
|
125
136
|
# @return [Hashie::Mash] json representation
|
126
|
-
def as_json(options = {
|
137
|
+
def as_json(options = {})
|
127
138
|
collection = Hashie::Mash.new
|
128
139
|
collection.kinds = @kinds.collect { |kind| kind.as_json } if @kinds.any?
|
129
140
|
collection.mixins = @mixins.collect { |mixin| mixin.as_json } if @mixins.any?
|
data/lib/occi/core/categories.rb
CHANGED
@@ -17,6 +17,14 @@ module Occi
|
|
17
17
|
self.to_a.join(separator)
|
18
18
|
end
|
19
19
|
|
20
|
+
# Returns a Set with all categories related to the specified category
|
21
|
+
#
|
22
|
+
# @param [Occi::Core::Category] category
|
23
|
+
# @return [Occi::Core::Categories]
|
24
|
+
def get_related_to(category)
|
25
|
+
self.class.new select { |cat| cat.related_to? category }
|
26
|
+
end
|
27
|
+
|
20
28
|
# @param [Occi::Model] model
|
21
29
|
# @return [Occi::Model]
|
22
30
|
def model=(model)
|
@@ -26,7 +34,7 @@ module Occi
|
|
26
34
|
|
27
35
|
# @param [Hash] options
|
28
36
|
# @return [Hashie::Mash] json representation
|
29
|
-
def as_json(options={
|
37
|
+
def as_json(options={})
|
30
38
|
self.to_a.as_json
|
31
39
|
end
|
32
40
|
|
data/lib/occi/core/category.rb
CHANGED
@@ -16,9 +16,9 @@ module Occi
|
|
16
16
|
term='category',
|
17
17
|
title=nil,
|
18
18
|
attributes=Occi::Core::Attributes.new)
|
19
|
-
@scheme
|
20
|
-
@term
|
21
|
-
@title
|
19
|
+
@scheme = scheme
|
20
|
+
@term = term
|
21
|
+
@title = title
|
22
22
|
@attributes = Occi::Core::AttributeProperties.parse attributes
|
23
23
|
end
|
24
24
|
|
@@ -32,11 +32,13 @@ module Occi
|
|
32
32
|
|
33
33
|
if related.first.to_s == 'http://schemas.ogf.org/occi/core#entity' or related.first.nil?
|
34
34
|
parent = Occi::Core::Entity
|
35
|
-
elsif related.first.kind_of? Occi::Core::
|
35
|
+
elsif related.first.kind_of? Occi::Core::Kind
|
36
|
+
parent = related.first.entity_type
|
37
|
+
elsif related.first.kind_of? Occi::Core::Mixin
|
36
38
|
parent = related.first.class
|
37
39
|
else
|
38
40
|
related_scheme, related_term = related.first.to_s.split '#'
|
39
|
-
parent
|
41
|
+
parent = self.get_class related_scheme, related_term
|
40
42
|
end
|
41
43
|
|
42
44
|
uri = URI.parse(scheme)
|
@@ -62,7 +64,7 @@ module Occi
|
|
62
64
|
end
|
63
65
|
else
|
64
66
|
klass = namespace.const_set term.classify, Class.new(parent)
|
65
|
-
klass.kind = Occi::Core::Kind.new scheme, term, nil, {
|
67
|
+
klass.kind = Occi::Core::Kind.new scheme, term, nil, {}, related unless parent.ancestors.include? Occi::Core::Category
|
66
68
|
end
|
67
69
|
|
68
70
|
klass
|
@@ -79,18 +81,25 @@ module Occi
|
|
79
81
|
end
|
80
82
|
|
81
83
|
# check if category is related to another category
|
84
|
+
# a category is related to another category
|
85
|
+
# if it is included in @related or
|
86
|
+
# if it is the category itself
|
87
|
+
#
|
82
88
|
# @param [String, Category] category Related Category or its type identifier
|
83
89
|
# @return [true,false] true if category is related to category_id else false
|
84
90
|
def related_to?(category)
|
85
|
-
|
86
|
-
|
87
|
-
|
91
|
+
if @related
|
92
|
+
self.related.each do |cat|
|
93
|
+
return true if cat.to_s == category.to_s
|
94
|
+
end
|
95
|
+
return true if self.to_s == category.to_s
|
96
|
+
end
|
88
97
|
false
|
89
98
|
end
|
90
99
|
|
91
100
|
# @param [Hash] options
|
92
101
|
# @return [Hashie::Mash] json representation
|
93
|
-
def as_json(options={
|
102
|
+
def as_json(options={})
|
94
103
|
category = Hashie::Mash.new
|
95
104
|
category.scheme = @scheme if @scheme
|
96
105
|
category.term = @term if @term
|
@@ -118,7 +127,7 @@ module Occi
|
|
118
127
|
|
119
128
|
# @return [Hash] hash containing the HTTP headers of the text/occi rendering
|
120
129
|
def to_header
|
121
|
-
{
|
130
|
+
{:Category => self.to_string}
|
122
131
|
end
|
123
132
|
|
124
133
|
# @return [String] json representation
|
data/lib/occi/core/link.rb
CHANGED
@@ -28,7 +28,6 @@ module Occi
|
|
28
28
|
scheme, term = rel.to_s.split('#')
|
29
29
|
@rel = Occi::Core::Category.get_class(scheme, term).kind if scheme && term
|
30
30
|
end
|
31
|
-
@rel ||= Occi::Core::Resource.kind
|
32
31
|
@source = source if source
|
33
32
|
@target = target
|
34
33
|
end
|
@@ -58,9 +57,9 @@ module Occi
|
|
58
57
|
end
|
59
58
|
|
60
59
|
# @param [Occi::Model] model
|
61
|
-
def check
|
60
|
+
def check
|
62
61
|
raise "rel must be provided" unless @rel
|
63
|
-
super
|
62
|
+
super
|
64
63
|
end
|
65
64
|
|
66
65
|
# @param [Hash] options
|
@@ -68,7 +67,7 @@ module Occi
|
|
68
67
|
def as_json(options={ })
|
69
68
|
link = super
|
70
69
|
link.rel = @rel.to_s if @rel
|
71
|
-
link.source = self.source.to_s if self.source.
|
70
|
+
link.source = self.source.to_s if self.source.to_s
|
72
71
|
link.target = self.target.to_s if self.target
|
73
72
|
link
|
74
73
|
end
|
@@ -86,7 +85,7 @@ module Occi
|
|
86
85
|
string << name + '=' + value + ';'
|
87
86
|
end
|
88
87
|
string << 'occi.core.target=' + self.target.to_s.inspect
|
89
|
-
string << 'occi.core.source=' + self.source.to_s.inspect if self.source.
|
88
|
+
string << 'occi.core.source=' + self.source.to_s.inspect if self.source.to_s
|
90
89
|
|
91
90
|
string
|
92
91
|
end
|
data/lib/occi/model.rb
CHANGED
@@ -76,10 +76,10 @@ module Occi
|
|
76
76
|
|
77
77
|
# Return all categories from model. If filter is present, return only the categories specified by filter
|
78
78
|
#
|
79
|
-
# @param [Occi::Collection] filter
|
79
|
+
# @param [Occi::Collection,Occi::Core::Category,String] filter
|
80
80
|
# @return [Occi::Collection] collection
|
81
81
|
def get(filter = nil)
|
82
|
-
filter ?
|
82
|
+
filter ? self.get_related_to(filter) : self
|
83
83
|
end
|
84
84
|
|
85
85
|
end
|
data/lib/occi/parser.rb
CHANGED
@@ -2,11 +2,11 @@ module Occi
|
|
2
2
|
class Parser
|
3
3
|
|
4
4
|
# Declaring Class constants for OVF XML namespaces (defined in OVF specification ver.1.1)
|
5
|
-
OVF
|
6
|
-
RASD
|
7
|
-
VSSD
|
5
|
+
OVF ="http://schemas.dmtf.org/ovf/envelope/1"
|
6
|
+
RASD ="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData"
|
7
|
+
VSSD ="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData"
|
8
8
|
OVFENV="http://schemas.dmtf.org/ovf/environment/1"
|
9
|
-
CIM
|
9
|
+
CIM ="http://schemas.dmtf.org/wbem/wscim/1/common"
|
10
10
|
|
11
11
|
# Parses an OCCI message and extracts OCCI relevant information
|
12
12
|
# @param [String] media_type the media type of the OCCI message
|
@@ -15,12 +15,12 @@ module Occi
|
|
15
15
|
# @param [Occi::Core::Resource,Occi::Core::Link] entity_type entity type to use for parsing of text plain entities
|
16
16
|
# @param [Hash] header optional header of the OCCI message
|
17
17
|
# @return [Occi::Collection] list consisting of an array of locations and the OCCI object collection
|
18
|
-
def self.parse(media_type, body, category=false, entity_type=Occi::Core::Resource, header={
|
18
|
+
def self.parse(media_type, body, category=false, entity_type=Occi::Core::Resource, header={})
|
19
19
|
Occi::Log.debug '### Parsing request data to OCCI Collection ###'
|
20
20
|
collection = Occi::Collection.new
|
21
21
|
|
22
22
|
# remove trailing HTTP_ prefix if present
|
23
|
-
header = Hash[header.map {|k, v| [k.gsub('HTTP_','').upcase, v] }]
|
23
|
+
header = Hash[header.map { |k, v| [k.gsub('HTTP_', '').upcase, v] }]
|
24
24
|
|
25
25
|
category ? collection = self.header_categories(header) : collection = self.header_entity(header, entity_type)
|
26
26
|
|
@@ -47,6 +47,7 @@ module Occi
|
|
47
47
|
|
48
48
|
def self.locations(media_type, body, header)
|
49
49
|
locations = self.header_locations(header)
|
50
|
+
locations << header['Location'] if !header['Location'].nil? && header['Location'].any?
|
50
51
|
case media_type
|
51
52
|
when 'text/uri-list'
|
52
53
|
body.each_line { |line| locations << URI.parse(line.chomp) }
|
@@ -70,7 +71,7 @@ module Occi
|
|
70
71
|
# @param [Hash] header
|
71
72
|
# @return [Occi::Collection]
|
72
73
|
def self.header_categories(header)
|
73
|
-
collection
|
74
|
+
collection = Occi::Collection.new
|
74
75
|
category_strings = header['CATEGORY'].to_s.split(',')
|
75
76
|
category_strings.each do |cat|
|
76
77
|
category = OCCIANTLR::Parser.new('Category: ' + cat).category
|
@@ -85,12 +86,12 @@ module Occi
|
|
85
86
|
# @param [Class] entity_type
|
86
87
|
# @return [Occi::Collection]
|
87
88
|
def self.header_entity(header, entity_type)
|
88
|
-
collection
|
89
|
-
entity
|
89
|
+
collection = Occi::Collection.new
|
90
|
+
entity = Hashie::Mash.new
|
90
91
|
category_strings = header['CATEGORY'].to_s.split(',')
|
91
92
|
return collection if category_strings.empty?
|
92
93
|
attribute_strings = header['X_OCCI_ATTRIBUTE'].to_s.split(',')
|
93
|
-
categories
|
94
|
+
categories = Hashie::Mash.new({:kinds => [], :mixins => [], :actions => []})
|
94
95
|
category_strings.each do |category|
|
95
96
|
cat = OCCIANTLR::Parser.new('Category: ' + category).category
|
96
97
|
categories.kinds.concat cat.kinds
|
@@ -105,9 +106,9 @@ module Occi
|
|
105
106
|
if entity_type == Occi::Core::Link
|
106
107
|
entity.target = link.attributes!.occi!.core!.target
|
107
108
|
entity.source = link.attributes!.occi!.core!.source
|
108
|
-
cats
|
109
|
-
kind
|
110
|
-
mixins
|
109
|
+
cats = entity.categories.split(' ')
|
110
|
+
kind = cats.reverse!.pop
|
111
|
+
mixins = cats.categories
|
111
112
|
collection.links << Occi::Core::Link.new(kind, mixins, entity.attributes)
|
112
113
|
elsif entity_type == Occi::Core::Resource
|
113
114
|
link_strings = header['LINK'].to_s.split(',')
|
@@ -119,8 +120,8 @@ module Occi
|
|
119
120
|
link.attributes!.occi!.core!.target = link.target
|
120
121
|
|
121
122
|
link.categories = (link.categories.presence || %w'http://schemas.ogf.org/occi/core#link')
|
122
|
-
kind
|
123
|
-
mixins
|
123
|
+
kind = link.categories.reverse!.pop
|
124
|
+
mixins = link.categories
|
124
125
|
|
125
126
|
collection.links << Occi::Core::Link.new(kind, mixins, link.attributes, link.actions, link.rel, link.target, link.source)
|
126
127
|
end
|
@@ -155,9 +156,9 @@ module Occi
|
|
155
156
|
# @return [Occi::Collection]
|
156
157
|
def self.text_entity(text, entity_type)
|
157
158
|
collection = Occi::Collection.new
|
158
|
-
entity
|
159
|
-
links
|
160
|
-
categories = Hashie::Mash.new({
|
159
|
+
entity = Hashie::Mash.new
|
160
|
+
links = []
|
161
|
+
categories = Hashie::Mash.new({:kinds => [], :mixins => [], :actions => []})
|
161
162
|
text.each_line do |line|
|
162
163
|
if line.include? 'Category'
|
163
164
|
cat = (OCCIANTLR::Parser.new(line.chomp).category)
|
@@ -173,9 +174,9 @@ module Occi
|
|
173
174
|
if entity_type == Occi::Core::Link
|
174
175
|
entity.target = links.first.attributes!.occi!.core!.target
|
175
176
|
entity.source = links.first.attributes!.occi!.core!.source
|
176
|
-
cats
|
177
|
-
kind
|
178
|
-
mixins
|
177
|
+
cats = entity.categories.split(' ')
|
178
|
+
kind = cats.reverse!.pop
|
179
|
+
mixins = cats
|
179
180
|
collection.links << Occi::Core::Link.new(kind, mixins, entity.attributes)
|
180
181
|
elsif entity_type == Occi::Core::Resource
|
181
182
|
links.each do |link|
|
@@ -185,9 +186,9 @@ module Occi
|
|
185
186
|
link.attributes!.occi!.core!.target = link.target
|
186
187
|
|
187
188
|
link.categories = (link.categories.presence || %w'http://schemas.ogf.org/occi/core#link')
|
188
|
-
cats
|
189
|
-
kind
|
190
|
-
mixins
|
189
|
+
cats = link.categories
|
190
|
+
kind = link.categories.reverse!.pop
|
191
|
+
mixins = link.categories
|
191
192
|
|
192
193
|
link = Occi::Core::Link.new(kind, mixins, link.attributes, link.actions, link.rel, link.target, link.source)
|
193
194
|
collection.links << link
|
@@ -202,15 +203,16 @@ module Occi
|
|
202
203
|
# @return [Occi::Collection]
|
203
204
|
def self.json(json)
|
204
205
|
collection = Occi::Collection.new
|
205
|
-
hash
|
206
|
+
hash = Hashie::Mash.new(JSON.parse(json))
|
206
207
|
collection.kinds.merge hash.kinds.collect { |kind| Occi::Core::Kind.new(kind.scheme, kind.term, kind.title, kind.attributes, kind.related, kind.actions) } if hash.kinds
|
207
208
|
collection.mixins.merge hash.mixins.collect { |mixin| Occi::Core::Mixin.new(mixin.scheme, mixin.term, mixin.title, mixin.attributes, mixin.related, mixin.actions) } if hash.mixins
|
208
209
|
collection.actions.merge hash.actions.collect { |action| Occi::Core::Action.new(action.scheme, action.term, action.title, action.attributes) } if hash.actions
|
209
210
|
collection.resources.merge hash.resources.collect { |resource| Occi::Core::Resource.new(resource.kind, resource.mixins, resource.attributes, resource.actions, resource.links) } if hash.resources
|
210
|
-
collection.links.merge hash.links.collect { |link| Occi::Core::Link.new(link.kind, link.mixins, link.attributes) } if hash.links
|
211
|
+
collection.links.merge hash.links.collect { |link| Occi::Core::Link.new(link.kind, link.mixins, link.attributes, [], nil, link.target) } if hash.links
|
211
212
|
|
212
|
-
if collection.resources.size == 1
|
213
|
+
if collection.resources.size == 1 && collection.links.size > 0
|
213
214
|
if collection.resources.first.links.empty?
|
215
|
+
collection.links.each { |link| link.source = collection.resources.first }
|
214
216
|
collection.resources.first.links = collection.links
|
215
217
|
end
|
216
218
|
end
|
@@ -230,7 +232,7 @@ module Occi
|
|
230
232
|
# @return [Occi::Collection]
|
231
233
|
def self.xml(xml)
|
232
234
|
collection = Occi::Collection.new
|
233
|
-
hash
|
235
|
+
hash = Hashie::Mash.new(Hash.from_xml(Nokogiri::XML(xml)))
|
234
236
|
collection.kinds.merge hash.kinds.collect { |kind| Occi::Core::Kind.new(kind.scheme, kind.term, kind.title, kind.attributes, kind.related, kind.actions) } if hash.kinds
|
235
237
|
collection.mixins.merge hash.mixins.collect { |mixin| Occi::Core::Mixin.new(mixin.scheme, mixin.term, mixin.title, mixin.attributes, mixin.related, mixin.actions) } if hash.mixins
|
236
238
|
collection.actions.merge hash.actions.collect { |action| Occi::Core::Action.new(action.scheme, action.term, action.title, action.attributes) } if hash.actions
|
@@ -258,7 +260,7 @@ module Occi
|
|
258
260
|
units = alloc_units.split('*')
|
259
261
|
#check units[1] is nil??
|
260
262
|
units[1].strip!
|
261
|
-
alloc_vars
|
263
|
+
alloc_vars = units[1].split('^')
|
262
264
|
alloc_units_bytes = (alloc_vars[0].to_i**alloc_vars[1].to_i)
|
263
265
|
alloc_units_bytes
|
264
266
|
end
|
@@ -268,9 +270,9 @@ module Occi
|
|
268
270
|
# @param [String] ova
|
269
271
|
# @return [Occi::Collection]
|
270
272
|
def self.ova(ova)
|
271
|
-
tar
|
272
|
-
ovf
|
273
|
-
files = {
|
273
|
+
tar = Gem::Package::TarReader.new(StringIO.new(ova))
|
274
|
+
ovf = mf = cert = nil
|
275
|
+
files = {}
|
274
276
|
tar.each do |entry|
|
275
277
|
tempfile = Tempfile.new(entry.full_name)
|
276
278
|
tempfile.write(entry.read)
|
@@ -295,10 +297,10 @@ module Occi
|
|
295
297
|
|
296
298
|
# @param [String] ovf
|
297
299
|
# @param [Hash] files key value pairs of file names and paths to the file
|
298
|
-
def self.ovf(ovf, files={
|
300
|
+
def self.ovf(ovf, files={})
|
299
301
|
collection = Occi::Collection.new
|
300
|
-
doc
|
301
|
-
references = {
|
302
|
+
doc = Nokogiri::XML(ovf)
|
303
|
+
references = {}
|
302
304
|
|
303
305
|
doc.xpath('envelope:Envelope/envelope:References/envelope:File', 'envelope' => "#{Parser::OVF}").each do |file|
|
304
306
|
href = URI.parse(file.attributes['href'].to_s)
|
@@ -316,10 +318,10 @@ module Occi
|
|
316
318
|
doc.xpath('envelope:Envelope/envelope:DiskSection/envelope:Disk', 'envelope' => "#{Parser::OVF}").each do |disk|
|
317
319
|
storage = Occi::Core::Resource.new('http://schemas.ogf.org/occi/infrastructure#storage')
|
318
320
|
if disk.attributes['fileRef']
|
319
|
-
storagelink
|
320
|
-
storagelink.attributes.occi!.core!.title
|
321
|
+
storagelink = Occi::Core::Link.new("http://schemas.ogf.org/occi/infrastructure#storagelink")
|
322
|
+
storagelink.attributes.occi!.core!.title = disk.attributes['fileRef'].to_s
|
321
323
|
storagelink.attributes.occi!.core!.target = references[disk.attributes['fileRef'].to_s]
|
322
|
-
storage.attributes.occi!.core!.title
|
324
|
+
storage.attributes.occi!.core!.title = disk.attributes['diskId'].to_s
|
323
325
|
storage.links << storagelink
|
324
326
|
else
|
325
327
|
#OCCI accepts storage size in GB
|
@@ -333,7 +335,7 @@ module Occi
|
|
333
335
|
capacity =capacity.to_i
|
334
336
|
else
|
335
337
|
alloc_unit_bytes = self.alloc_units_bytes(alloc_units)
|
336
|
-
capacity
|
338
|
+
capacity = self.calculate_capacity_bytes(disk.attributes['capacity'].to_s, alloc_unit_bytes)
|
337
339
|
end
|
338
340
|
capacity_gb = self.calculate_capacity_gb(capacity)
|
339
341
|
Occi::Log.debug('capacity in gb ' + capacity_gb.to_s)
|
@@ -344,7 +346,7 @@ module Occi
|
|
344
346
|
end
|
345
347
|
|
346
348
|
doc.xpath('envelope:Envelope/envelope:NetworkSection/envelope:Network', 'envelope' => "#{Parser::OVF}").each do |nw|
|
347
|
-
network
|
349
|
+
network = Occi::Core::Resource.new('http://schemas.ogf.org/occi/infrastructure#network')
|
348
350
|
network.attributes.occi!.core!.title = nw.attributes['name'].to_s
|
349
351
|
collection.resources << network
|
350
352
|
end
|
@@ -365,8 +367,8 @@ module Occi
|
|
365
367
|
alloc_units = resource_alloc.xpath("item:AllocationUnits/text()", 'item' => "#{Parser::RASD}").to_s
|
366
368
|
Occi::Log.debug('allocated units in ovf file: ' + alloc_units)
|
367
369
|
alloc_unit_bytes = self.alloc_units_bytes(alloc_units)
|
368
|
-
capacity
|
369
|
-
capacity_gb
|
370
|
+
capacity = self.calculate_capacity_bytes(resource_alloc.xpath("item:VirtualQuantity/text()", 'item' => "#{Parser::RASD}").to_s, alloc_unit_bytes)
|
371
|
+
capacity_gb = self.calculate_capacity_gb(capacity)
|
370
372
|
Occi::Log.debug('virtual quantity of memory configured in gb: ' + capacity_gb.to_s)
|
371
373
|
compute.attributes.occi!.compute!.memory = capacity_gb
|
372
374
|
# compute.attributes.occi!.compute!.memory = resource_alloc.xpath("item:VirtualQuantity/text()", 'item' => "#{Parser::RASD}").to_s.to_i
|
@@ -374,24 +376,24 @@ module Occi
|
|
374
376
|
when "3" then
|
375
377
|
compute.attributes.occi!.compute!.cores = resource_alloc.xpath("item:VirtualQuantity/text()", 'item' => "#{Parser::RASD}").to_s.to_i
|
376
378
|
when "10" then
|
377
|
-
networkinterface
|
379
|
+
networkinterface = Occi::Core::Link.new('http://schemas.ogf.org/occi/infrastructure#networkinterface')
|
378
380
|
networkinterface.attributes.occi!.core!.title = resource_alloc.xpath("item:ElementName/text()", 'item' => "#{Parser::RASD}").to_s
|
379
|
-
id
|
380
|
-
network
|
381
|
+
id = resource_alloc.xpath("item:Connection/text()", 'item' => "#{Parser::RASD}").to_s
|
382
|
+
network = collection.resources.select { |resource| resource.attributes.occi!.core!.title == id }.first
|
381
383
|
raise "Network with id #{id} not found" unless network
|
382
384
|
networkinterface.attributes.occi!.core!.target = network
|
383
385
|
when "17" then
|
384
|
-
storagelink
|
386
|
+
storagelink = Occi::Core::Link.new("http://schemas.ogf.org/occi/infrastructure#storagelink")
|
385
387
|
storagelink.attributes.occi!.core!.title = resource_alloc.xpath("item:ElementName/text()", 'item' => "#{Parser::RASD}").to_s
|
386
388
|
# extract the mountpoint
|
387
|
-
host_resource
|
389
|
+
host_resource = resource_alloc.xpath("item:HostResource/text()", 'item' => "#{Parser::RASD}").to_s
|
388
390
|
if host_resource.start_with? 'ovf:/disk/'
|
389
|
-
id
|
391
|
+
id = host_resource.gsub('ovf:/disk/', '')
|
390
392
|
storage = collection.resources.select { |resource| resource.attributes.occi!.core!.title == id }.first
|
391
393
|
raise "Disk with id #{id} not found" unless storage
|
392
394
|
storagelink.attributes.occi!.core!.target = storage
|
393
395
|
elsif host_resource.start_with? 'ovf:/file/'
|
394
|
-
id
|
396
|
+
id = host_resource.gsub('ovf:/file/', '')
|
395
397
|
storagelink.attributes.occi!.core!.target = references[id]
|
396
398
|
end
|
397
399
|
compute.links << storagelink
|