occi 2.5.11 → 2.5.12
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/occi/core/link.rb +21 -14
- data/lib/occi/core/resource.rb +2 -2
- data/lib/occi/parser.rb +58 -17
- data/lib/occi/version.rb +1 -1
- metadata +3 -13
data/lib/occi/core/link.rb
CHANGED
@@ -6,7 +6,7 @@ module OCCI
|
|
6
6
|
module Core
|
7
7
|
class Link < Entity
|
8
8
|
|
9
|
-
attr_accessor :rel
|
9
|
+
attr_accessor :rel, :source, :target
|
10
10
|
|
11
11
|
# @return [OCCI::Core::Kind] kind definition of Link type
|
12
12
|
def self.kind_definition
|
@@ -30,32 +30,40 @@ module OCCI
|
|
30
30
|
|
31
31
|
# @param [String] kind
|
32
32
|
# @param [String] mixins
|
33
|
-
# @param [
|
34
|
-
|
33
|
+
# @param [Occi::Core::Attributes] attributes
|
34
|
+
# @param [Array] actions
|
35
|
+
# @param [String] rel
|
36
|
+
# @param [String,OCCI::Core::Entity] target
|
37
|
+
# @param [String,OCCI::Core::Entity] source
|
38
|
+
def initialize(kind, mixins=[], attributes={ }, actions=[], rel=nil, target=nil, source=nil)
|
35
39
|
super(kind,mixins,attributes,actions)
|
36
|
-
@rel
|
40
|
+
@rel = rel if rel
|
41
|
+
self.source = source if source
|
42
|
+
self.target = target
|
37
43
|
end
|
38
44
|
|
39
45
|
# @return [String] target attribute of the link
|
40
46
|
def target
|
41
|
-
self.attributes.occi
|
47
|
+
@target ||= self.attributes.occi.core.target if @attributes.occi.core if @attributes.occi
|
48
|
+
@target
|
42
49
|
end
|
43
50
|
|
44
51
|
# set target attribute of link
|
45
52
|
# @param [String] target
|
46
|
-
def target=(
|
47
|
-
|
53
|
+
def target=(resource)
|
54
|
+
@target = resource
|
48
55
|
end
|
49
56
|
|
50
57
|
# @return [String] source attribute of the link
|
51
58
|
def source
|
52
|
-
self.attributes.occi
|
59
|
+
@source ||= self.attributes.occi.core.source if @attributes.occi.core if @attributes.occi
|
60
|
+
@source
|
53
61
|
end
|
54
62
|
|
55
63
|
# set source attribute of link
|
56
64
|
# @param [String] source
|
57
|
-
def source=(
|
58
|
-
|
65
|
+
def source=(resource)
|
66
|
+
@source = resource
|
59
67
|
end
|
60
68
|
|
61
69
|
# @param [OCCI::Model] model
|
@@ -67,11 +75,10 @@ module OCCI
|
|
67
75
|
# @param [Hash] options
|
68
76
|
# @return [Hashie::Mash] json representation
|
69
77
|
def as_json(options={ })
|
70
|
-
link =
|
71
|
-
link.kind = @kind if @kind
|
78
|
+
link = super
|
72
79
|
link.rel = @rel if @rel
|
73
|
-
link.
|
74
|
-
link.
|
80
|
+
link.source = self.source.to_s if self.source.kind_of? String if self.source
|
81
|
+
link.target = self.target.to_s if self.target
|
75
82
|
link
|
76
83
|
end
|
77
84
|
|
data/lib/occi/core/resource.rb
CHANGED
@@ -28,8 +28,8 @@ module OCCI
|
|
28
28
|
# @param [Array] mixins
|
29
29
|
# @param [OCCI::Core::Attributes,Hash] attributes
|
30
30
|
# @param [Array] links
|
31
|
-
def initialize(kind, mixins=
|
32
|
-
super(kind, mixins, attributes)
|
31
|
+
def initialize(kind, mixins=[], attributes={ }, actions=[], links=[])
|
32
|
+
super(kind, mixins, attributes, actions)
|
33
33
|
@links = []
|
34
34
|
links.to_a.each do |link|
|
35
35
|
link = OCCI::Core::Link.new(link.kind,link.mixins,link.attributes,link.actions,link.rel) unless link.kind_of? OCCI::Core::Link
|
data/lib/occi/parser.rb
CHANGED
@@ -24,7 +24,7 @@ module OCCI
|
|
24
24
|
|
25
25
|
case media_type
|
26
26
|
when 'text/uri-list'
|
27
|
-
body.each_line { |line| locations << URI.parse(line) }
|
27
|
+
body.each_line { |line| locations << URI.parse(line.chomp) }
|
28
28
|
when 'text/occi'
|
29
29
|
nil
|
30
30
|
when 'text/plain', nil
|
@@ -77,7 +77,13 @@ module OCCI
|
|
77
77
|
return collection if category_strings.empty?
|
78
78
|
attribute_strings = header['HTTP_X_OCCI_ATTRIBUTE'].to_s.split(',')
|
79
79
|
categories = Hashie::Mash.new({ :kinds => [], :mixins => [], :actions => [] })
|
80
|
-
category_strings.each
|
80
|
+
category_strings.each do |category|
|
81
|
+
cat = OCCIANTLR::Parser.new('Category: ' + category).category
|
82
|
+
categories.kinds.concat cat.kinds
|
83
|
+
categories.mixins.concat cat.mixins
|
84
|
+
categories.actions.concat cat.actions
|
85
|
+
end
|
86
|
+
|
81
87
|
return collection if categories.kinds.empty?
|
82
88
|
entity.kind = categories.kinds.first.scheme + categories.kinds.first.term
|
83
89
|
entity.mixins = categories.mixins.collect { |mixin| mixin.scheme + mixin.term } if categories.mixins.any?
|
@@ -85,16 +91,29 @@ module OCCI
|
|
85
91
|
if entity_type == OCCI::Core::Link
|
86
92
|
entity.target = link.attributes!.occi!.core!.target
|
87
93
|
entity.source = link.attributes!.occi!.core!.source
|
88
|
-
|
94
|
+
cats = entity.categories.split(' ')
|
95
|
+
kind = cats.reverse!.pop
|
96
|
+
mixins = cats.categories
|
97
|
+
collection.links << OCCI::Core::Link.new(kind, mixins, entity.attributes)
|
89
98
|
elsif entity_type == OCCI::Core::Resource
|
90
99
|
entity.links = []
|
91
100
|
link_strings = header['HTTP_LINK'].to_s.split(',')
|
92
101
|
link_strings.each do |link_string|
|
93
|
-
link
|
94
|
-
link.
|
95
|
-
|
102
|
+
link = OCCIANTLR::Parser.new('Link: ' + link_string).link
|
103
|
+
if link.rel.include? 'action#'
|
104
|
+
entity.actions = link.rel + entity.actions.to_a
|
105
|
+
else
|
106
|
+
link.attributes!.occi!.core!.target = link.target
|
107
|
+
|
108
|
+
link.category ||= 'http://schemas.ogf.org/occi/core#link'
|
109
|
+
cats = link.category.split(' ')
|
110
|
+
kind = cats.reverse!.pop
|
111
|
+
mixins = cats
|
112
|
+
|
113
|
+
entity.links << OCCI::Core::Link.new(kind, mixins, link.attributes, link.actions, link.rel, link.target, link.source)
|
114
|
+
end
|
96
115
|
end
|
97
|
-
collection.resources << OCCI::Core::Resource.new(entity.kind, entity.mixins, entity.attributes, entity.links)
|
116
|
+
collection.resources << OCCI::Core::Resource.new(entity.kind, entity.mixins, entity.attributes, entity.actions, entity.links)
|
98
117
|
end
|
99
118
|
collection
|
100
119
|
end
|
@@ -102,7 +121,7 @@ module OCCI
|
|
102
121
|
# @param [String] text
|
103
122
|
# @return [Array] list of URIs
|
104
123
|
def self.text_locations(text)
|
105
|
-
text.lines.collect { |line| OCCIANTLR::Parser.new(line).x_occi_location if line.include? 'X-OCCI-Location' }.compact
|
124
|
+
text.lines.collect { |line| OCCIANTLR::Parser.new(line.chomp).x_occi_location if line.include? 'X-OCCI-Location' }.compact
|
106
125
|
end
|
107
126
|
|
108
127
|
# @param [String] text
|
@@ -110,7 +129,7 @@ module OCCI
|
|
110
129
|
def self.text_categories(text)
|
111
130
|
collection = OCCI::Collection.new
|
112
131
|
text.each_line do |line|
|
113
|
-
category = OCCIANTLR::Parser.new(line).category
|
132
|
+
category = OCCIANTLR::Parser.new(line.chomp).category
|
114
133
|
next if category.nil?
|
115
134
|
collection.kinds.concat category.kinds.collect { |kind| OCCI::Core::Kind.new(kind.scheme, kind.term, kind.title, kind.attributes, kind.related, kind.actions) }
|
116
135
|
collection.mixins.concat category.mixins.collect { |mixin| OCCI::Core::Mixin.new(mixin.scheme, mixin.term, mixin.title, mixin.attributes, mixin.related, mixin.actions) }
|
@@ -128,19 +147,41 @@ module OCCI
|
|
128
147
|
links = []
|
129
148
|
categories = Hashie::Mash.new({ :kinds => [], :mixins => [], :actions => [] })
|
130
149
|
text.each_line do |line|
|
131
|
-
|
132
|
-
|
133
|
-
|
150
|
+
if line.include? 'Category'
|
151
|
+
cat = (OCCIANTLR::Parser.new(line.chomp).category)
|
152
|
+
categories.kinds.concat cat.kinds
|
153
|
+
categories.mixins.concat cat.mixins
|
154
|
+
categories.actions.concat cat.actions
|
155
|
+
end
|
156
|
+
entity.attributes!.merge!(OCCIANTLR::Parser.new(line.chomp).x_occi_attribute) if line.include? 'X-OCCI-Attribute'
|
157
|
+
links << OCCIANTLR::Parser.new(line.chomp).link if line.include? 'Link'
|
134
158
|
end
|
135
159
|
entity.kind = categories.kinds.first.scheme + categories.kinds.first.term if categories.kinds.first
|
136
|
-
entity.mixins = categories.mixins.collect { |mixin| mixin.scheme + mixin.term } if
|
160
|
+
entity.mixins = categories.mixins.collect { |mixin| mixin.scheme + mixin.term } if categories.mixins
|
137
161
|
if entity_type == OCCI::Core::Link
|
138
162
|
entity.target = links.first.attributes!.occi!.core!.target
|
139
163
|
entity.source = links.first.attributes!.occi!.core!.source
|
164
|
+
cats = entity.categories.split(' ')
|
165
|
+
kind = cats.reverse!.pop
|
166
|
+
mixins = cats.categories
|
140
167
|
collection.links << OCCI::Core::Link.new(entity.kind, entity.mixins, entity.attributes)
|
141
168
|
elsif entity_type == OCCI::Core::Resource
|
142
|
-
|
143
|
-
|
169
|
+
links.each do |link|
|
170
|
+
if link.rel.include? 'action#'
|
171
|
+
entity.actions = [link.rel] + entity.actions.to_a
|
172
|
+
else
|
173
|
+
link.attributes!.occi!.core!.target = link.target
|
174
|
+
link.category ||= 'http://schemas.ogf.org/occi/core#link'
|
175
|
+
cats = link.category.split(' ')
|
176
|
+
kind = cats.reverse!.pop
|
177
|
+
mixins = cats
|
178
|
+
|
179
|
+
link = OCCI::Core::Link.new(kind, mixins, link.attributes, link.actions, link.rel, link.target, link.source)
|
180
|
+
collection.links << link
|
181
|
+
entity.links = [link.id] + entity.links.to_a
|
182
|
+
end
|
183
|
+
end
|
184
|
+
collection.resources << OCCI::Core::Resource.new(entity.kind, entity.mixins, entity.attributes, entity.actions, entity.links)
|
144
185
|
end unless entity.kind.nil?
|
145
186
|
collection
|
146
187
|
end
|
@@ -152,7 +193,7 @@ module OCCI
|
|
152
193
|
hash = Hashie::Mash.new(JSON.parse(json))
|
153
194
|
collection.kinds.concat hash.kinds.collect { |kind| OCCI::Core::Kind.new(kind.scheme, kind.term, kind.title, kind.attributes, kind.related, kind.actions) } if hash.kinds
|
154
195
|
collection.mixins.concat hash.mixins.collect { |mixin| OCCI::Core::Mixin.new(mixin.scheme, mixin.term, mixin.title, mixin.attributes, mixin.related, mixin.actions) } if hash.mixins
|
155
|
-
collection.resources.concat hash.resources.collect { |resource| OCCI::Core::Resource.new(resource.kind, resource.mixins, resource.attributes, resource.links) } if hash.resources
|
196
|
+
collection.resources.concat hash.resources.collect { |resource| OCCI::Core::Resource.new(resource.kind, resource.mixins, resource.attributes, resource.actions, resource.links) } if hash.resources
|
156
197
|
collection.links.concat hash.links.collect { |link| OCCI::Core::Link.new(link.kind, link.mixins, link.attributes) } if hash.links
|
157
198
|
collection
|
158
199
|
end
|
@@ -164,7 +205,7 @@ module OCCI
|
|
164
205
|
hash = Hashie::Mash.new(Hash.from_xml(Nokogiri::XML(xml)))
|
165
206
|
collection.kinds.concat hash.kinds.collect { |kind| OCCI::Core::Kind.new(kind.scheme, kind.term, kind.title, kind.attributes, kind.related, kind.actions) } if hash.kinds
|
166
207
|
collection.mixins.concat hash.mixins.collect { |mixin| OCCI::Core::Mixin.new(mixin.scheme, mixin.term, mixin.title, mixin.attributes, mixin.related, mixin.actions) } if hash.mixins
|
167
|
-
collection.resources.concat hash.resources.collect { |resource| OCCI::Core::Resource.new(resource.kind, resource.mixins, resource.attributes, resource.links) } if hash.resources
|
208
|
+
collection.resources.concat hash.resources.collect { |resource| OCCI::Core::Resource.new(resource.kind, resource.mixins, resource.attributes, resource.actions, resource.links) } if hash.resources
|
168
209
|
collection.links.concat hash.links.collect { |link| OCCI::Core::Link.new(link.kind, link.mixins, link.attributes) } if hash.links
|
169
210
|
collection
|
170
211
|
end
|
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.5.
|
4
|
+
version: 2.5.12
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-12-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json
|
@@ -248,15 +248,5 @@ rubygems_version: 1.8.24
|
|
248
248
|
signing_key:
|
249
249
|
specification_version: 3
|
250
250
|
summary: OCCI toolkit
|
251
|
-
test_files:
|
252
|
-
- spec/occi/client_spec.rb
|
253
|
-
- spec/occi/collection_spec.rb
|
254
|
-
- spec/occi/log_spec.rb
|
255
|
-
- spec/occi/model_spec.rb
|
256
|
-
- spec/occi/parser_spec.rb
|
257
|
-
- spec/occi/test.json
|
258
|
-
- spec/occi/test.ova
|
259
|
-
- spec/occi/test.ovf
|
260
|
-
- spec/occiantlr/parser_spec.rb
|
261
|
-
- spec/spec_helper.rb
|
251
|
+
test_files: []
|
262
252
|
has_rdoc:
|