occi-core 4.2.10 → 4.2.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/lib/occi/collection.rb +17 -7
- data/lib/occi/core/entity.rb +5 -1
- data/lib/occi/core/links.rb +6 -3
- data/lib/occi/parser/text.rb +25 -3
- data/lib/occi/version.rb +1 -1
- data/lib/occi-core.rb +1 -0
- data/spec/occi/collection_spec.rb +22 -0
- data/spec/occi/core/entities_spec.rb +1 -1
- data/spec/occi/core/entity_spec.rb +9 -0
- data/spec/occi/core/links_spec.rb +5 -3
- data/spec/occi/parser/text_spec.rb +2 -4
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YWU2NmRkOTcxMWYxMjZmNTExZTZmY2MyZTk5NTA0OTZkYTZjYzNhNw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MWExYTgyNzM0ZjU4NzA4MjhjNjRkNzZiZDBhZjI4N2IwNmY5ZTdkMw==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MzE2MDM1N2NmYmNmMTZhMWY0NDg3YmM3M2NhYTM0NzU3MTJhZGYyNTQxOTk1
|
10
|
+
YmVjNGEyMzkxZjM4OTI4MGFmZDg5ZjA5NTFkNGM1ODFiMjg3MmY4N2FhNTVk
|
11
|
+
ZDZlNWY0NDg2YzZhMDdiNjZkNTIyN2NkODA4MjBkNTYyNGMyZTM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZDhmN2JjNzFmZTFjYTg2NTRiNjU1MjkwZjkyMDFkNGU5YWY5ZjkzYzQxZWEw
|
14
|
+
OWZlNjAzZDRhZGYyMDk3Njk1MzcwYTgzZmQ1OTEzYmNmODJjODM0ODBjZTc0
|
15
|
+
ZmEzOTUyMmJiNTk5ZTliMjQ1ZmI5YzMyNDcxNzA3ZWRmYzVhMjM=
|
data/lib/occi/collection.rb
CHANGED
@@ -134,6 +134,7 @@ module Occi
|
|
134
134
|
# @param cats_only [Boolean] look only for categories
|
135
135
|
# @return [Occi::Core::Category]
|
136
136
|
def get_by_id(id, cats_only = false)
|
137
|
+
raise "Cannot do a look-up with a blank id!" if id.blank?
|
137
138
|
object = self.categories.select { |category| category.type_identifier == id }
|
138
139
|
object = self.entities.select { |entity| entity.id == id } if !cats_only && object.empty?
|
139
140
|
object.first
|
@@ -141,10 +142,11 @@ module Occi
|
|
141
142
|
|
142
143
|
# Returns the category corresponding to a given location
|
143
144
|
#
|
144
|
-
# @param [
|
145
|
+
# @param [String] location
|
145
146
|
# @return [Occi::Core::Category]
|
146
147
|
def get_by_location(location)
|
147
|
-
|
148
|
+
raise "Cannot do a look-up with a blank location!" if location.blank?
|
149
|
+
self.categories.select { |category| category.location == instance2cat(location) }.first
|
148
150
|
end
|
149
151
|
|
150
152
|
# @return [true,false] true if collection is empty, false otherwise
|
@@ -154,9 +156,10 @@ module Occi
|
|
154
156
|
|
155
157
|
# Returns a collection with all categories related to the specified category
|
156
158
|
#
|
157
|
-
# @param [Occi::Core::Category] category
|
159
|
+
# @param [Occi::Core::Category, String] category
|
158
160
|
# @return [Occi::Core::Collection]
|
159
161
|
def get_related_to(category)
|
162
|
+
raise "Cannot do a look-up with a blank category!" if category.blank?
|
160
163
|
collection = self.class.new
|
161
164
|
collection.kinds = @kinds.get_related_to(category)
|
162
165
|
collection.mixins = @mixins.get_related_to(category)
|
@@ -194,14 +197,14 @@ module Occi
|
|
194
197
|
text = ""
|
195
198
|
|
196
199
|
if standalone_links?
|
197
|
-
raise "Only one standalone link allowed for rendering to text/plain" if self.links.size > 1
|
200
|
+
raise "Only one standalone link allowed for rendering to text/plain!" if self.links.size > 1
|
198
201
|
text << self.links.first.to_text
|
199
202
|
elsif standalone_action_instance?
|
200
203
|
text << self.action.to_text
|
201
204
|
else
|
202
205
|
text << self.categories.collect { |category| category.to_text }.join("\n")
|
203
206
|
text << "\n" if self.categories.any?
|
204
|
-
raise "Only one resource allowed for rendering to text/plain" if self.resources.size > 1
|
207
|
+
raise "Only one resource allowed for rendering to text/plain!" if self.resources.size > 1
|
205
208
|
text << self.resources.first.to_text if self.resources.any?
|
206
209
|
text << self.links.collect { |link| link.to_text_link }.join("\n")
|
207
210
|
text << self.action.to_text if self.action
|
@@ -214,13 +217,13 @@ module Occi
|
|
214
217
|
header = Hashie::Mash.new
|
215
218
|
|
216
219
|
if standalone_links?
|
217
|
-
raise "Only one standalone link allowed for rendering to text/occi" if self.links.size > 1
|
220
|
+
raise "Only one standalone link allowed for rendering to text/occi!" if self.links.size > 1
|
218
221
|
header = self.links.first.to_header
|
219
222
|
elsif standalone_action_instance?
|
220
223
|
header = self.action.to_header
|
221
224
|
else
|
222
225
|
header['Category'] = self.categories.collect { |category| category.to_string_short }.join(',') if self.categories.any?
|
223
|
-
raise "Only one resource allowed for rendering to text/occi" if self.resources.size > 1
|
226
|
+
raise "Only one resource allowed for rendering to text/occi!" if self.resources.size > 1
|
224
227
|
header = self.class.header_merge(header, self.resources.first.to_header) if self.resources.any?
|
225
228
|
header['Link'] = self.links.collect { |link| link.to_string }.join(',') if self.links.any?
|
226
229
|
header = self.class.header_merge(header, self.action.to_header) if self.action
|
@@ -250,5 +253,12 @@ module Occi
|
|
250
253
|
!self.action.blank? && self.categories.blank? && self.entities.blank?
|
251
254
|
end
|
252
255
|
|
256
|
+
def instance2cat(location)
|
257
|
+
return location if location.start_with?('/') && location.end_with?('/')
|
258
|
+
cat_relative_uri = "#{File.dirname(URI.parse(location).path)}/"
|
259
|
+
raise "Supplied location is invalid! #{cat_relative_uri.inspect}" unless cat_relative_uri =~ /\/.+\//
|
260
|
+
cat_relative_uri
|
261
|
+
end
|
262
|
+
|
253
263
|
end
|
254
264
|
end
|
data/lib/occi/core/entity.rb
CHANGED
@@ -185,9 +185,13 @@ module Occi
|
|
185
185
|
entity = Hashie::Mash.new
|
186
186
|
entity.kind = @kind.to_s if @kind
|
187
187
|
entity.mixins = @mixins.join(' ').split(' ') if @mixins.any?
|
188
|
-
|
188
|
+
|
189
|
+
action_strings = @actions.collect { |action| action.to_s if action.to_s }.compact
|
190
|
+
entity.actions = action_strings unless action_strings.empty?
|
191
|
+
|
189
192
|
entity.attributes = @attributes.as_json if @attributes.as_json.any?
|
190
193
|
entity.id = id.to_s if id
|
194
|
+
|
191
195
|
entity
|
192
196
|
end
|
193
197
|
|
data/lib/occi/core/links.rb
CHANGED
@@ -15,6 +15,7 @@ module Occi
|
|
15
15
|
link = Occi::Core::Link.new(*args)
|
16
16
|
link.model = @model if @model
|
17
17
|
self << link
|
18
|
+
|
18
19
|
link
|
19
20
|
end
|
20
21
|
|
@@ -22,10 +23,12 @@ module Occi
|
|
22
23
|
|
23
24
|
def convert(link)
|
24
25
|
if link.kind_of? String
|
25
|
-
|
26
|
-
link
|
27
|
-
link.
|
26
|
+
link_location = link
|
27
|
+
link = Occi::Core::Link.new
|
28
|
+
link.id = link_location.split('/').last
|
29
|
+
link.location = link_location
|
28
30
|
end
|
31
|
+
|
29
32
|
link
|
30
33
|
end
|
31
34
|
|
data/lib/occi/parser/text.rb
CHANGED
@@ -44,8 +44,15 @@ module Occi
|
|
44
44
|
resource.attributes.merge! attribute(line)
|
45
45
|
when /^Link:/
|
46
46
|
link = link_string(line, resource)
|
47
|
-
|
48
|
-
|
47
|
+
|
48
|
+
if link.kind_of? Occi::Core::Link
|
49
|
+
resource.links << link
|
50
|
+
links << link
|
51
|
+
elsif link.kind_of? Occi::Core::Action
|
52
|
+
resource.actions << link
|
53
|
+
else
|
54
|
+
raise Occi::Errors::ParserInputError, "Could not recognize resource link! #{link.inspect}"
|
55
|
+
end
|
49
56
|
end
|
50
57
|
}
|
51
58
|
lines.respond_to?(:each) ? lines.each(&block) : lines.each_line(&block)
|
@@ -169,8 +176,22 @@ module Occi
|
|
169
176
|
|
170
177
|
raise Occi::Errors::ParserInputError, "Could not match #{string}" unless match
|
171
178
|
|
179
|
+
if match[:uri].include?('?action=')
|
180
|
+
link_string_action match
|
181
|
+
else
|
182
|
+
link_string_link match, source
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def link_string_action(match)
|
187
|
+
scheme, term = match[:rel].split('#')
|
188
|
+
Occi::Core::Action.new scheme, term
|
189
|
+
end
|
190
|
+
|
191
|
+
def link_string_link(match, source)
|
172
192
|
target = match[:uri]
|
173
193
|
rel = match[:rel]
|
194
|
+
|
174
195
|
if match[:category].blank?
|
175
196
|
kind = Occi::Core::Link.kind
|
176
197
|
else
|
@@ -183,7 +204,7 @@ module Occi
|
|
183
204
|
|
184
205
|
# create an array of the list of attributes
|
185
206
|
attributes = []
|
186
|
-
regexp=Regexp.new '(\\s*'+REGEXP_ATTRIBUTE_REPR.to_s+')'
|
207
|
+
regexp = Regexp.new '(\\s*'+REGEXP_ATTRIBUTE_REPR.to_s+')'
|
187
208
|
attr_line = match[:attributes].sub(/^\s*;\s*/, ' ')
|
188
209
|
attributes = attr_line.scan(regexp).collect {|matches| matches.first}
|
189
210
|
|
@@ -191,6 +212,7 @@ module Occi
|
|
191
212
|
attributes = attributes.inject(Hashie::Mash.new) { |hsh, attribute|
|
192
213
|
hsh.merge!(Occi::Parser::Text.attribute("X-OCCI-Attribute: #{attribute}"))
|
193
214
|
}
|
215
|
+
|
194
216
|
Occi::Core::Link.new kind, mixins, attributes, actions, rel, target, source, location
|
195
217
|
end
|
196
218
|
|
data/lib/occi/version.rb
CHANGED
data/lib/occi-core.rb
CHANGED
@@ -71,14 +71,22 @@ module Occi
|
|
71
71
|
}
|
72
72
|
it 'gets Entity as a related kind' do
|
73
73
|
expect(collection.get_related_to(Occi::Core::Entity.kind)).to eql collection
|
74
|
+
expect(collection.get_related_to(Occi::Core::Entity.kind.type_identifier)).to eql collection
|
74
75
|
end
|
75
76
|
|
76
77
|
it 'gets Resource as a related kind' do
|
77
78
|
expect(collection.get_related_to(Occi::Core::Resource.kind).kinds.first).to eql Occi::Core::Resource.kind
|
79
|
+
expect(collection.get_related_to(Occi::Core::Resource.kind.type_identifier).kinds.first).to eql Occi::Core::Resource.kind
|
78
80
|
end
|
79
81
|
|
80
82
|
it 'gets Link as a related kind' do
|
81
83
|
expect(collection.get_related_to(Occi::Core::Link.kind).kinds.first).to eql Occi::Core::Link.kind
|
84
|
+
expect(collection.get_related_to(Occi::Core::Link.kind.type_identifier).kinds.first).to eql Occi::Core::Link.kind
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'fails loudly when no category is given' do
|
88
|
+
expect { collection.get_related_to("") } .to raise_error RuntimeError
|
89
|
+
expect { collection.get_related_to(nil) } .to raise_error RuntimeError
|
82
90
|
end
|
83
91
|
end
|
84
92
|
|
@@ -716,6 +724,11 @@ module Occi
|
|
716
724
|
expect(collection.get_by_id("ID.notexist")).to eql nil
|
717
725
|
end
|
718
726
|
|
727
|
+
it 'fails loudly when no id is given' do
|
728
|
+
expect { collection.get_by_id("") } .to raise_error RuntimeError
|
729
|
+
expect { collection.get_by_id(nil) } .to raise_error RuntimeError
|
730
|
+
end
|
731
|
+
|
719
732
|
end
|
720
733
|
|
721
734
|
context '#get_by_location' do
|
@@ -723,9 +736,18 @@ module Occi
|
|
723
736
|
expect(collection.get_by_location("/mixin/my_mixin/")).to eql collection.mixins.first
|
724
737
|
end
|
725
738
|
|
739
|
+
it 'finds category by instance location' do
|
740
|
+
expect(collection.get_by_location("/compute/1")).to eql collection.kinds.first
|
741
|
+
end
|
742
|
+
|
726
743
|
it 'fails gracefully' do
|
727
744
|
expect(collection.get_by_location("/notexist/")).to eql nil
|
728
745
|
end
|
746
|
+
|
747
|
+
it 'fails loudly when no location is given' do
|
748
|
+
expect { collection.get_by_location("") } .to raise_error RuntimeError
|
749
|
+
expect { collection.get_by_location(nil) } .to raise_error RuntimeError
|
750
|
+
end
|
729
751
|
end
|
730
752
|
end
|
731
753
|
|
@@ -85,7 +85,7 @@ module Occi
|
|
85
85
|
entities << entity2
|
86
86
|
expected = []
|
87
87
|
hash=Hashie::Mash.new JSON.parse('{"kind":"http://schemas.ogf.org/occi/core#entity","attributes":{"occi":{"core":{"id":"e1testid"}}},"id":"e1testid"}')
|
88
|
-
hash2= Hashie::Mash.new JSON.parse('{"kind":"http://example.org/test/schema#entity2","actions":[
|
88
|
+
hash2= Hashie::Mash.new JSON.parse('{"kind":"http://example.org/test/schema#entity2","actions":["http://schemas.ogf.org/occi/core/entity/action#testaction"],"attributes":{"occi":{"core":{"id":"e2testid"}}},"id":"e2testid"}')
|
89
89
|
expected << hash
|
90
90
|
expected << hash2
|
91
91
|
expect(entities.as_json).to eql expected
|
@@ -174,6 +174,15 @@ Link: </TestLoc/1?action=testaction>;rel="http://schemas.ogf.org/occi/core/entit
|
|
174
174
|
end
|
175
175
|
end
|
176
176
|
|
177
|
+
context '#as_json' do
|
178
|
+
it 'renders element as JSON' do
|
179
|
+
entity.actions << testaction
|
180
|
+
|
181
|
+
expected = Hashie::Mash.new JSON.parse('{"kind":"http://schemas.ogf.org/occi/core#entity","actions":["http://schemas.ogf.org/occi/core/entity/action#testaction"],"attributes":{"occi":{"core":{"id":"baf1"}}},"id":"baf1"}')
|
182
|
+
expect(entity.as_json).to eql expected
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
177
186
|
context '#check' do
|
178
187
|
let(:defs){
|
179
188
|
defs = Occi::Core::Attributes.new
|
@@ -35,9 +35,11 @@ module Occi
|
|
35
35
|
expect(links.count).to eql 2
|
36
36
|
end
|
37
37
|
|
38
|
-
it 'populates
|
39
|
-
links = Occi::Core::Links.new ["
|
40
|
-
|
38
|
+
it 'populates Links with correctly initialized links' do
|
39
|
+
links = Occi::Core::Links.new ["/link/9c3b83bd-2456-45e9-8ce5-91a7d5c7bb85"]
|
40
|
+
|
41
|
+
expect(links.first.id).to eql "9c3b83bd-2456-45e9-8ce5-91a7d5c7bb85"
|
42
|
+
expect(links.first.location).to eql "/link/9c3b83bd-2456-45e9-8ce5-91a7d5c7bb85"
|
41
43
|
end
|
42
44
|
|
43
45
|
it 'produces the right number of members, string/link combination' do
|
@@ -237,12 +237,10 @@ module Occi
|
|
237
237
|
expect(link).to eql expected
|
238
238
|
end
|
239
239
|
|
240
|
-
it 'parses string with
|
240
|
+
it 'parses string with action link' do
|
241
241
|
link_string = 'Link: </compute/04106bce-87eb-4f8f-a665-2f624e54ba46?action=restart>; rel="http://schemas.ogf.org/occi/infrastructure/compute/action#restart"'
|
242
242
|
link = Occi::Parser::Text.link_string(link_string, "source")
|
243
|
-
expected = Marshal.restore("\x04\bo:\
|
244
|
-
expected.id = 'epmtied'
|
245
|
-
link.id = 'epmtied'
|
243
|
+
expected = Marshal.restore("\x04\bo:\x17Occi::Core::Action\t:\f@schemeI\"?http://schemas.ogf.org/occi/infrastructure/compute/action#\x06:\x06ET:\n@termI\"\frestart\x06;\aT:\v@title0:\x10@attributesC:\eOcci::Core::Attributes{\x00")
|
246
244
|
expect(link).to eql expected
|
247
245
|
end
|
248
246
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: occi-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.2.
|
4
|
+
version: 4.2.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Feldhaus
|
@@ -10,48 +10,48 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-
|
13
|
+
date: 2014-03-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
|
-
- - '>='
|
19
|
+
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
|
-
- - '>='
|
26
|
+
- - ! '>='
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: '0'
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: hashie
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
|
-
- - '>='
|
33
|
+
- - ! '>='
|
34
34
|
- !ruby/object:Gem::Version
|
35
35
|
version: '0'
|
36
36
|
type: :runtime
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
|
-
- - '>='
|
40
|
+
- - ! '>='
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '0'
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: uuidtools
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
|
-
- - '>='
|
47
|
+
- - ! '>='
|
48
48
|
- !ruby/object:Gem::Version
|
49
49
|
version: 2.1.3
|
50
50
|
type: :runtime
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
|
-
- - '>='
|
54
|
+
- - ! '>='
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: 2.1.3
|
57
57
|
- !ruby/object:Gem::Dependency
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
name: settingslogic
|
73
73
|
requirement: !ruby/object:Gem::Requirement
|
74
74
|
requirements:
|
75
|
-
- - '>='
|
75
|
+
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
78
|
type: :runtime
|
79
79
|
prerelease: false
|
80
80
|
version_requirements: !ruby/object:Gem::Requirement
|
81
81
|
requirements:
|
82
|
-
- - '>='
|
82
|
+
- - ! '>='
|
83
83
|
- !ruby/object:Gem::Version
|
84
84
|
version: '0'
|
85
85
|
description: OCCI is a collection of classes to simplify the implementation of the
|
@@ -231,12 +231,12 @@ require_paths:
|
|
231
231
|
- lib
|
232
232
|
required_ruby_version: !ruby/object:Gem::Requirement
|
233
233
|
requirements:
|
234
|
-
- - '>='
|
234
|
+
- - ! '>='
|
235
235
|
- !ruby/object:Gem::Version
|
236
236
|
version: 1.9.3
|
237
237
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
238
238
|
requirements:
|
239
|
-
- - '>='
|
239
|
+
- - ! '>='
|
240
240
|
- !ruby/object:Gem::Version
|
241
241
|
version: '0'
|
242
242
|
requirements: []
|