occi 2.5.19 → 3.0.0.beta.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.travis.yml +3 -1
- data/AUTHORS +4 -3
- data/Gemfile +9 -0
- data/Gemfile.lock +64 -21
- data/README.md +19 -14
- data/Rakefile +12 -8
- data/Test Results - discovery_interface.html +862 -0
- data/bin/occi +333 -83
- data/examples/dsl_example.rb +6 -6
- data/examples/x509auth_example.rb +6 -6
- data/features/common/step_definitions/common_steps.rb +32 -0
- data/features/occi/core/create/create.feature +17 -0
- data/features/occi/core/create/step_definitions/create_steps.rb +0 -0
- data/features/occi/core/delete/delete.feature +14 -0
- data/features/occi/core/delete/step_definitions/delete_steps.rb +0 -0
- data/features/occi/core/discovery_interface/discovery_interface.feature +35 -0
- data/features/occi/core/discovery_interface/step_definitions/discovery_interface_steps.rb +19 -0
- data/features/occi/core/miscellaneous/miscellaneous.feature +14 -0
- data/features/occi/core/miscellaneous/step_definitions/miscellaneous_steps.rb +0 -0
- data/features/occi/core/read/read.feature +14 -0
- data/features/occi/core/read/step_definitions/read_steps.rb +0 -0
- data/features/occi/core/update/step_definitions/update_steps.rb +0 -0
- data/features/occi/core/update/update.feature +14 -0
- data/features/occi/infrastructure/create/create.feature +14 -0
- data/features/occi/infrastructure/create/step_definitions/create_steps.rb +0 -0
- data/features/support/env.rb +4 -0
- data/lib/occi.rb +29 -3
- data/lib/occi/api/client/client_amqp.rb +756 -0
- data/lib/occi/api/client/client_http.rb +922 -0
- data/lib/occi/api/client/http/httparty_fix.rb +53 -0
- data/lib/occi/api/client/http/net_http_fix.rb +46 -0
- data/lib/occi/api/dsl.rb +77 -73
- data/lib/occi/bin/helpers.rb +91 -0
- data/lib/occi/bin/occi_opts.rb +251 -0
- data/lib/occi/bin/resource_output_factory.rb +90 -0
- data/lib/occi/bin/templates/compute.erb +15 -0
- data/lib/occi/bin/templates/network.erb +11 -0
- data/lib/occi/bin/templates/os_tpl.erb +9 -0
- data/lib/occi/bin/templates/resource_tpl.erb +9 -0
- data/lib/occi/bin/templates/storage.erb +10 -0
- data/lib/occi/collection.rb +122 -25
- data/lib/occi/core.rb +18 -9
- data/lib/occi/core/action.rb +20 -4
- data/lib/occi/core/action_instance.rb +24 -0
- data/lib/occi/core/actions.rb +22 -0
- data/lib/occi/core/attribute_properties.rb +33 -84
- data/lib/occi/core/attributes.rb +32 -14
- data/lib/occi/core/categories.rb +46 -0
- data/lib/occi/core/category.rb +94 -20
- data/lib/occi/core/entities.rb +50 -0
- data/lib/occi/core/entity.rb +130 -89
- data/lib/occi/core/kind.rb +28 -35
- data/lib/occi/core/kinds.rb +22 -0
- data/lib/occi/core/link.rb +43 -40
- data/lib/occi/core/links.rb +34 -0
- data/lib/occi/core/mixin.rb +28 -23
- data/lib/occi/core/mixins.rb +22 -0
- data/lib/occi/core/related.rb +20 -0
- data/lib/occi/core/resource.rb +40 -40
- data/lib/occi/core/resources.rb +14 -0
- data/lib/occi/infrastructure.rb +27 -0
- data/lib/occi/infrastructure/compute.rb +159 -0
- data/lib/occi/infrastructure/network.rb +131 -0
- data/lib/occi/infrastructure/network/ipnetwork.rb +34 -0
- data/lib/occi/infrastructure/networkinterface.rb +124 -0
- data/lib/occi/infrastructure/networkinterface/ipnetworkinterface.rb +34 -0
- data/lib/occi/infrastructure/os_tpl.rb +19 -0
- data/lib/occi/infrastructure/resource_tpl.rb +19 -0
- data/lib/occi/infrastructure/storage.rb +96 -0
- data/lib/occi/infrastructure/storagelink.rb +73 -0
- data/lib/occi/log.rb +6 -2
- data/lib/occi/model.rb +38 -70
- data/lib/occi/parser.rb +108 -88
- data/lib/occi/version.rb +2 -2
- data/lib/occiantlr/OCCIANTLR.g +6 -5
- data/lib/occiantlr/OCCIANTLRLexer.rb +52 -52
- data/lib/occiantlr/OCCIANTLRParser.rb +678 -569
- data/lib/occiantlr/README.md +1 -1
- data/occi.gemspec +2 -1
- data/spec/cassettes/client_http_text_plain.yml +1066 -0
- data/spec/occi/api/client/client_amqp_spec.rb +148 -0
- data/spec/occi/api/client/client_http_0.5_spec.rb +292 -0
- data/spec/occi/api/client/client_http_spec.rb +259 -0
- data/spec/occi/api/dsl_spec.rb +0 -0
- data/spec/occi/collection_spec.rb +23 -10
- data/spec/occi/core/categories_spec.rb +30 -0
- data/spec/occi/core/category_spec.rb +41 -0
- data/spec/occi/core/entity_spec.rb +52 -0
- data/spec/occi/core/resource_spec.rb +21 -0
- data/spec/occi/infrastructure/compute_spec.rb +32 -0
- data/spec/occi/log_spec.rb +10 -10
- data/spec/occi/model_spec.rb +24 -24
- data/spec/occi/parser_spec.rb +89 -39
- data/spec/occi/test.json +22 -58
- data/spec/occiantlr/parser_spec.rb +5 -7
- data/spec/spec_helper.rb +13 -3
- metadata +116 -19
- data/etc/model/infrastructure/compute.json +0 -108
- data/etc/model/infrastructure/ipnetwork.json +0 -40
- data/etc/model/infrastructure/ipnetworkinterface.json +0 -40
- data/etc/model/infrastructure/network.json +0 -55
- data/etc/model/infrastructure/networkinterface.json +0 -38
- data/etc/model/infrastructure/os_template.json +0 -9
- data/etc/model/infrastructure/resource_template.json +0 -9
- data/etc/model/infrastructure/storage.json +0 -72
- data/etc/model/infrastructure/storagelink.json +0 -38
- data/lib/occi/api/client.rb +0 -596
- data/lib/occi/client/occiopts.rb +0 -146
- data/spec/occi/client_spec.rb +0 -12
data/lib/occi/core/entity.rb
CHANGED
@@ -1,72 +1,106 @@
|
|
1
|
-
|
2
|
-
require 'uuidtools'
|
3
|
-
require 'hashie/mash'
|
4
|
-
require 'active_support/json'
|
5
|
-
require 'occi/model'
|
6
|
-
require 'occi/core/attributes'
|
7
|
-
require 'occi/core/kind'
|
8
|
-
require 'occi/core/attribute_properties'
|
9
|
-
|
10
|
-
module OCCI
|
1
|
+
module Occi
|
11
2
|
module Core
|
12
3
|
class Entity
|
13
4
|
|
14
|
-
attr_accessor :mixins, :attributes, :actions
|
15
|
-
attr_reader :kind
|
5
|
+
attr_accessor :mixins, :attributes, :actions, :id, :model, :kind
|
16
6
|
|
17
|
-
|
18
|
-
|
19
|
-
|
7
|
+
class << self
|
8
|
+
attr_accessor :kind
|
9
|
+
attr_reader :mixins, :actions
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.mixins
|
13
|
+
Occi::Core::Mixins.new
|
14
|
+
end
|
15
|
+
|
16
|
+
@kind = Occi::Core::Kind.new('http://schemas.ogf.org/occi/core#', 'entity')
|
17
|
+
|
18
|
+
@kind.title = "entity"
|
19
|
+
|
20
|
+
@kind.attributes.occi!.core!.id = Occi::Core::AttributeProperties.new(
|
21
|
+
{ :pattern => "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}" })
|
22
|
+
|
23
|
+
@kind.attributes.occi!.core!.title = Occi::Core::AttributeProperties.new(
|
24
|
+
{ :mutable => true })
|
20
25
|
|
21
|
-
kind.title = "Entity"
|
22
26
|
|
23
|
-
|
24
|
-
|
25
|
-
kind.
|
26
|
-
|
27
|
+
# @return [String]
|
28
|
+
def self.type_identifier
|
29
|
+
self.kind.type_identifier
|
30
|
+
end
|
31
|
+
|
32
|
+
# @param [Array] args list of arguments
|
33
|
+
# @return [Object] new instance of this class
|
34
|
+
def self.new(*args)
|
35
|
+
if args.size > 0
|
36
|
+
type_identifier = args[0].to_s
|
37
|
+
related = [self.kind]
|
38
|
+
else
|
39
|
+
type_identifier = self.kind.type_identifier
|
40
|
+
related = nil
|
41
|
+
end
|
42
|
+
scheme, term = type_identifier.split '#'
|
27
43
|
|
28
|
-
|
29
|
-
kind.attributes.occi!.core!.title!.Pattern = ".*"
|
30
|
-
kind.attributes.occi!.core!.title!.Required = false
|
31
|
-
kind.attributes.occi!.core!.title!.Mutable = true
|
44
|
+
klass = Occi::Core::Kind.get_class scheme, term, related
|
32
45
|
|
33
|
-
|
46
|
+
object = klass.allocate
|
47
|
+
object.send :initialize, *args
|
48
|
+
object
|
34
49
|
end
|
35
50
|
|
36
51
|
# @param [String] kind
|
37
52
|
# @param [String] mixins
|
38
|
-
# @param [
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
@kind
|
43
|
-
@mixins
|
44
|
-
@attributes
|
45
|
-
@
|
46
|
-
|
53
|
+
# @param [Occi::Core::Attributes] attributes
|
54
|
+
# @param [Occi::Core::Actions] actions
|
55
|
+
# @return [Occi::Core::Entity]
|
56
|
+
def initialize(kind = self.kind, mixins=[], attributes={ }, actions=[])
|
57
|
+
@kind = self.class.kind.clone
|
58
|
+
@mixins = Occi::Core::Mixins.new mixins
|
59
|
+
@attributes = Occi::Core::Attributes.new attributes
|
60
|
+
@actions = Occi::Core::Actions.new actions
|
61
|
+
end
|
62
|
+
|
63
|
+
# @return [Occi::Core::Kind]
|
64
|
+
def kind
|
65
|
+
@kind
|
66
|
+
end
|
67
|
+
|
68
|
+
# @param [Occi::Core::Kind,String] kind
|
69
|
+
# @return [Occi::Core::Kind]
|
70
|
+
def kind=(kind)
|
71
|
+
if kind.kind_of? String
|
72
|
+
scheme, term = kind.split '#'
|
73
|
+
kind = Occi::Core::Category.get_class scheme, term
|
74
|
+
end
|
75
|
+
@kind = kind
|
47
76
|
end
|
48
77
|
|
49
78
|
# @param [Array] mixins
|
50
79
|
def mixins=(mixins)
|
51
|
-
@
|
52
|
-
@mixins =mixins
|
80
|
+
@mixins = Occi::Core::Mixins.new mixins
|
53
81
|
end
|
54
82
|
|
55
|
-
# @param [
|
83
|
+
# @param [Occi::Core::Attributes] attributes
|
56
84
|
def attributes=(attributes)
|
57
|
-
@
|
58
|
-
|
85
|
+
@attributes = Occi::Core::Attributes.new attributes
|
86
|
+
end
|
87
|
+
|
88
|
+
# @param [Occi::Core::Actions] actions
|
89
|
+
def actions=(actions)
|
90
|
+
@actions = Occi::Core::Actions.new actions
|
59
91
|
end
|
60
92
|
|
61
93
|
# set id for entity
|
62
94
|
# @param [UUIDTools::UUID] id
|
63
95
|
def id=(id)
|
64
96
|
@attributes.occi!.core!.id = id
|
97
|
+
@id = id
|
65
98
|
end
|
66
99
|
|
67
100
|
# @return [UUIDTools::UUID] id of the entity
|
68
101
|
def id
|
69
|
-
@attributes.occi
|
102
|
+
@id ||= @attributes.occi.core.id if @attributes.occi.core if @attributes.occi
|
103
|
+
@id
|
70
104
|
end
|
71
105
|
|
72
106
|
# set title attribute for entity
|
@@ -77,20 +111,30 @@ module OCCI
|
|
77
111
|
|
78
112
|
# @return [String] title attribute of entity
|
79
113
|
def title
|
80
|
-
@attributes.occi
|
114
|
+
@attributes.occi.core.title if @attributes.occi.core if @attributes.occi
|
115
|
+
end
|
116
|
+
|
117
|
+
# @param [Occi::Model] model
|
118
|
+
# @return [Occi::Model]
|
119
|
+
def model=(model)
|
120
|
+
@model = model
|
121
|
+
@kind = (model.get_by_id(@kind.type_identifier) || @kind)
|
122
|
+
@kind.entities << self
|
123
|
+
@mixins.model = model
|
124
|
+
@mixins.each { |mixin| mixin.entities << self }
|
125
|
+
@actions.model = model
|
81
126
|
end
|
82
127
|
|
83
128
|
# @return [String] location of the entity
|
84
129
|
def location
|
85
|
-
|
130
|
+
kind.location + id.gsub('urn:uuid:', '') if id
|
86
131
|
end
|
87
132
|
|
88
133
|
# check attributes against their definitions and set defaults
|
89
|
-
# @param [
|
90
|
-
def check
|
91
|
-
raise "No
|
92
|
-
definitions =
|
93
|
-
definitions.merge!(model.get_by_id(@kind).attributes)
|
134
|
+
# @param [Occi::Model] model representation of the Occi model to check the attributes against
|
135
|
+
def check
|
136
|
+
raise "No model associated" unless @model
|
137
|
+
definitions = model.get_by_id(@kind.to_s).attributes
|
94
138
|
@mixins.each do |mixin_id|
|
95
139
|
mixin = model.get_by_id(mixin_id)
|
96
140
|
next if mixin.nil?
|
@@ -100,64 +144,60 @@ module OCCI
|
|
100
144
|
@attributes = Entity.check(@attributes, definitions) if definitions
|
101
145
|
end
|
102
146
|
|
103
|
-
# @param [
|
104
|
-
# @param [
|
105
|
-
# @
|
106
|
-
|
107
|
-
|
147
|
+
# @param [Occi::Core::Attributes] attributes
|
148
|
+
# @param [Occi::Core::Attributes] definitions
|
149
|
+
# @param [true,false] set_defaults
|
150
|
+
# @return [Occi::Core::Attributes] attributes with their defaults set
|
151
|
+
def self.check(attributes, definitions, set_defaults=false)
|
152
|
+
attributes = Occi::Core::Attributes.new(attributes)
|
108
153
|
definitions.each_key do |key|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
154
|
+
if definitions[key].kind_of? Occi::Core::Attributes
|
155
|
+
attributes[key] = check(attributes[key], definitions[key])
|
156
|
+
else
|
157
|
+
properties = definitions[key]
|
158
|
+
value = attributes[key]
|
159
|
+
value ||= properties.default if set_defaults or properties.required
|
160
|
+
raise "required attribute #{key} not found" if value.nil? && properties.required
|
161
|
+
next if value.nil? and not properties.required
|
162
|
+
case properties.type
|
115
163
|
when 'number'
|
116
|
-
raise "attribute #{key} value #{value} from class #{value.class.name} does not match attribute property type #{properties.
|
117
|
-
raise "attribute #{key} with value #{value} not in range #{properties.Minimum}-#{properties.Maximum}" unless (properties.Minimum..properties.Maximum) === value if properties.Minimum && properties.Maximum
|
164
|
+
raise "attribute #{key} value #{value} from class #{value.class.name} does not match attribute property type #{properties.type}" unless value.kind_of?(Numeric)
|
118
165
|
when 'boolean'
|
119
|
-
raise "attribute #{key} value #{value} from class #{value.class.name} does not match attribute property type #{properties.
|
166
|
+
raise "attribute #{key} value #{value} from class #{value.class.name} does not match attribute property type #{properties.type}" unless !!value == value
|
167
|
+
when 'string'
|
168
|
+
raise "attribute #{key} with value #{value} from class #{value.class.name} does not match attribute property type #{properties.type}" unless value.kind_of?(String)
|
120
169
|
else
|
121
|
-
raise "
|
122
|
-
raise "attribute #{key} with length #{value.length} not in range #{properties.Minimum}-#{properties.Maximum}" unless (properties.Minimum..properties.Maximum) === value.length if properties.Minimum && properties.Maximum
|
170
|
+
raise "property type #{properties.type} is not one of the allowed types number, boolean or string"
|
123
171
|
end
|
124
|
-
|
172
|
+
Occi::Log.warn "attribute #{key} with value #{value} does not match pattern #{properties.pattern}" if value.to_s.scan(Regexp.new(properties.pattern)).empty? if properties.pattern
|
125
173
|
attributes[key] = value
|
126
|
-
else
|
127
|
-
attributes[key] = check(value, definitions[key])
|
128
174
|
end
|
129
175
|
end
|
130
|
-
attributes.delete_if { |_, v| v.
|
131
|
-
@checked = true
|
176
|
+
attributes.delete_if { |_, v| v.empty? } # remove empty attributes
|
132
177
|
attributes
|
133
178
|
end
|
134
179
|
|
135
|
-
# @return [true,false]
|
136
|
-
def checked?
|
137
|
-
@checked && @attributes.checked?
|
138
|
-
end
|
139
|
-
|
140
180
|
# @param [Hash] options
|
141
181
|
# @return [Hashie::Mash] json representation
|
142
182
|
def as_json(options={ })
|
143
183
|
entity = Hashie::Mash.new
|
144
|
-
entity.kind = @kind if @kind
|
145
|
-
entity.mixins = @mixins if @mixins.any?
|
184
|
+
entity.kind = @kind.to_s if @kind
|
185
|
+
entity.mixins = @mixins.join(' ').split(' ') if @mixins.any?
|
146
186
|
entity.actions = @actions if @actions.any?
|
147
187
|
entity.attributes = @attributes if @attributes.any?
|
188
|
+
entity.id = id if id
|
148
189
|
entity
|
149
190
|
end
|
150
191
|
|
151
192
|
# @return [String] text representation
|
152
193
|
def to_text
|
153
|
-
|
154
|
-
text = 'Category: ' + term + ';scheme=' + scheme.inspect + ';class="kind"' + "\n"
|
194
|
+
text = 'Category: ' + self.kind.term + ';scheme=' + self.kind.scheme.inspect + ';class="kind"' + "\n"
|
155
195
|
@mixins.each do |mixin|
|
156
|
-
scheme, term = mixin.split('#')
|
196
|
+
scheme, term = mixin.to_s.split('#')
|
197
|
+
scheme << '#'
|
157
198
|
text << 'Category: ' + term + ';scheme=' + scheme.inspect + ';class="mixin"' + "\n"
|
158
199
|
end
|
159
200
|
@attributes.combine.each_pair do |name, value|
|
160
|
-
name = name.inspect
|
161
201
|
value = value.inspect
|
162
202
|
text << 'X-OCCI-Attribute: ' + name + '=' + value + "\n"
|
163
203
|
end
|
@@ -168,17 +208,17 @@ module OCCI
|
|
168
208
|
text
|
169
209
|
end
|
170
210
|
|
211
|
+
# @return [Hash] hash containing the HTTP headers of the text/occi rendering
|
171
212
|
def to_header
|
172
|
-
|
173
|
-
header
|
174
|
-
header['Category'] = term + ';scheme=' + scheme.inspect + ';class="kind"'
|
213
|
+
header = Hashie::Mash.new
|
214
|
+
header['Category'] = self.kind.term + ';scheme=' + self.kind.scheme.inspect + ';class="kind"'
|
175
215
|
@mixins.each do |mixin|
|
176
|
-
scheme, term
|
216
|
+
scheme, term = mixin.to_s.split('#')
|
217
|
+
scheme << '#'
|
177
218
|
header['Category'] += ',' + term + ';scheme=' + scheme.inspect + ';class="mixin"'
|
178
219
|
end
|
179
220
|
attributes = []
|
180
221
|
@attributes.combine.each_pair do |name, value|
|
181
|
-
name = name.inspect
|
182
222
|
attributes << name + '=' + value.inspect
|
183
223
|
end
|
184
224
|
header['X-OCCI-Attribute'] = attributes.join(',') if attributes.any?
|
@@ -187,18 +227,19 @@ module OCCI
|
|
187
227
|
_, term = action.split('#')
|
188
228
|
links << self.location + '?action=' + term + '>;rel=' + action.inspect
|
189
229
|
end
|
190
|
-
header['Link'] = links.join(',') if links.any?
|
191
230
|
header
|
192
231
|
end
|
193
232
|
|
194
|
-
|
195
|
-
self.location
|
196
|
-
end
|
197
|
-
|
233
|
+
# @return [String] json representation
|
198
234
|
def inspect
|
199
235
|
JSON.pretty_generate(JSON.parse(to_json))
|
200
236
|
end
|
201
237
|
|
238
|
+
# @return [String] string representation of entity is its location
|
239
|
+
def to_s
|
240
|
+
self.location
|
241
|
+
end
|
242
|
+
|
202
243
|
end
|
203
244
|
end
|
204
245
|
end
|
data/lib/occi/core/kind.rb
CHANGED
@@ -1,63 +1,56 @@
|
|
1
|
-
|
2
|
-
require 'occi/core/category'
|
3
|
-
require 'occi/core/action'
|
4
|
-
require 'occi/core/attribute_properties'
|
5
|
-
|
6
|
-
module OCCI
|
1
|
+
module Occi
|
7
2
|
module Core
|
8
|
-
class Kind <
|
3
|
+
class Kind < Occi::Core::Category
|
9
4
|
|
10
|
-
attr_accessor :entities, :related, :actions
|
5
|
+
attr_accessor :entities, :related, :actions, :location
|
11
6
|
|
12
7
|
# @param [String ] scheme
|
13
8
|
# @param [String] term
|
14
9
|
# @param [String] title
|
15
|
-
# @param [
|
10
|
+
# @param [Hash] attributes
|
16
11
|
# @param [Array] related
|
17
12
|
# @param [Array] actions
|
18
|
-
def initialize(scheme
|
19
|
-
|
20
|
-
|
21
|
-
|
13
|
+
def initialize(scheme='http://schemas.ogf.org/occi/core#',
|
14
|
+
term='kind',
|
15
|
+
title=nil,
|
16
|
+
attributes=Occi::Core::Attributes.new,
|
17
|
+
related=Occi::Core::Categories.new,
|
18
|
+
actions=Occi::Core::Actions.new,
|
19
|
+
location=nil)
|
22
20
|
super(scheme, term, title, attributes)
|
21
|
+
@related = Occi::Core::Related.new(related)
|
22
|
+
@actions = Occi::Core::Actions.new(actions)
|
23
|
+
@entities = Occi::Core::Entities.new
|
24
|
+
location.blank? ? @location = '/' + term + '/' : @location = location
|
23
25
|
end
|
24
26
|
|
25
|
-
# @return [String] name of the OCCI core class the entity is related to
|
26
27
|
def entity_type
|
27
|
-
|
28
|
-
when "http://schemas.ogf.org/occi/core#resource"
|
29
|
-
return OCCI::Core::Resource
|
30
|
-
when "http://schemas.ogf.org/occi/core#link"
|
31
|
-
return OCCI::Core::Link
|
32
|
-
else
|
33
|
-
raise "no model back reference provided for kind #{self.typ_identifier}" unless @model
|
34
|
-
@model.get_by_id(self.related.first).entity_type unless self.term == 'entity'
|
35
|
-
end
|
28
|
+
self.class.get_class @scheme, @term, @related
|
36
29
|
end
|
37
30
|
|
38
|
-
# @return [String] string containing location URI of kind
|
39
31
|
def location
|
40
|
-
|
32
|
+
@location.clone
|
41
33
|
end
|
42
34
|
|
43
35
|
# @param [Hash] options
|
44
36
|
# @return [Hashie::Mash] json representation
|
45
37
|
def as_json(options={ })
|
46
38
|
kind = Hashie::Mash.new
|
47
|
-
kind.related = @related if @related.any?
|
48
|
-
kind.actions = @actions if @actions.any?
|
39
|
+
kind.related = @related.join(' ').split(' ') if @related.any?
|
40
|
+
kind.actions = @actions.join(' ').split(' ') if @actions.any?
|
41
|
+
kind.location = @location if @location
|
49
42
|
kind.merge! super
|
50
43
|
kind
|
51
44
|
end
|
52
45
|
|
53
|
-
# @return [String]
|
54
|
-
def
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
46
|
+
# @return [String] string representation of the kind
|
47
|
+
def to_string
|
48
|
+
string = super
|
49
|
+
string << ';rel=' + @related.join(' ').inspect if @related.any?
|
50
|
+
string << ';location=' + self.location.inspect
|
51
|
+
string << ';attributes=' + @attributes.combine.keys.join(' ').inspect if @attributes.any?
|
52
|
+
string << ';actions=' + @actions.join(' ').inspect if @actions.any?
|
53
|
+
string
|
61
54
|
end
|
62
55
|
|
63
56
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Occi
|
2
|
+
module Core
|
3
|
+
class Kinds < Occi::Core::Categories
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
def convert(category)
|
8
|
+
category = super category
|
9
|
+
|
10
|
+
if category.kind_of? String
|
11
|
+
scheme, term = category.split '#'
|
12
|
+
scheme += '#'
|
13
|
+
|
14
|
+
klass = Occi::Core::Category.get_class scheme, term, [Occi::Core::Kind.new]
|
15
|
+
category = klass.kind
|
16
|
+
end
|
17
|
+
category
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/occi/core/link.rb
CHANGED
@@ -1,45 +1,36 @@
|
|
1
|
-
|
2
|
-
require 'occi/core/entity'
|
3
|
-
require 'occi/core/kind'
|
4
|
-
|
5
|
-
module OCCI
|
1
|
+
module Occi
|
6
2
|
module Core
|
7
|
-
class Link < Entity
|
3
|
+
class Link < Occi::Core::Entity
|
8
4
|
|
9
5
|
attr_accessor :rel, :source, :target
|
10
6
|
|
11
|
-
|
12
|
-
def self.kind_definition
|
13
|
-
kind = OCCI::Core::Kind.new('http://schemas.ogf.org/occi/core#', 'link')
|
14
|
-
|
15
|
-
kind.related = %w{http://schemas.ogf.org/occi/core#entity}
|
16
|
-
kind.title = "Link"
|
7
|
+
@kind = Occi::Core::Kind.new('http://schemas.ogf.org/occi/core#', 'link')
|
17
8
|
|
18
|
-
|
19
|
-
|
20
|
-
kind.attributes.occi!.core!.target!.Required = false
|
21
|
-
kind.attributes.occi!.core!.target!.Mutable = true
|
9
|
+
@kind.related << Occi::Core::Entity.kind
|
10
|
+
@kind.title = "link"
|
22
11
|
|
23
|
-
|
24
|
-
|
25
|
-
kind.attributes.occi!.core!.source!.Required = false
|
26
|
-
kind.attributes.occi!.core!.source!.Mutable = true
|
12
|
+
@kind.attributes.occi!.core!.target = Occi::Core::AttributeProperties.new(
|
13
|
+
{ :mutable => true })
|
27
14
|
|
28
|
-
|
29
|
-
|
15
|
+
@kind.attributes.occi!.core!.source = Occi::Core::AttributeProperties.new(
|
16
|
+
{ :mutable => true })
|
30
17
|
|
31
18
|
# @param [String] kind
|
32
19
|
# @param [String] mixins
|
33
20
|
# @param [Occi::Core::Attributes] attributes
|
34
21
|
# @param [Array] actions
|
35
22
|
# @param [String] rel
|
36
|
-
# @param [String,
|
37
|
-
# @param [String,
|
38
|
-
def initialize(kind, mixins=[], attributes={ }, actions=[], rel=nil, target=nil, source=nil)
|
39
|
-
super(kind,mixins,attributes,actions)
|
40
|
-
|
41
|
-
|
42
|
-
|
23
|
+
# @param [String,Occi::Core::Entity] target
|
24
|
+
# @param [String,Occi::Core::Entity] source
|
25
|
+
def initialize(kind=self.kind, mixins=[], attributes={ }, actions=[], rel=nil, target=nil, source=nil)
|
26
|
+
super(kind, mixins, attributes, actions)
|
27
|
+
if rel.kind_of? String
|
28
|
+
scheme, term = rel.to_s.split('#')
|
29
|
+
@rel = Occi::Core::Category.get_class(scheme, term).kind if scheme && term
|
30
|
+
end
|
31
|
+
@rel ||= Occi::Core::Resource.kind
|
32
|
+
@source = source if source
|
33
|
+
@target = target
|
43
34
|
end
|
44
35
|
|
45
36
|
# @return [String] target attribute of the link
|
@@ -66,7 +57,7 @@ module OCCI
|
|
66
57
|
@source = resource
|
67
58
|
end
|
68
59
|
|
69
|
-
# @param [
|
60
|
+
# @param [Occi::Model] model
|
70
61
|
def check(model)
|
71
62
|
raise "rel must be provided" unless @rel
|
72
63
|
super(model)
|
@@ -76,21 +67,33 @@ module OCCI
|
|
76
67
|
# @return [Hashie::Mash] json representation
|
77
68
|
def as_json(options={ })
|
78
69
|
link = super
|
79
|
-
link.rel = @rel if @rel
|
80
|
-
link.source = self.source.to_s if self.source.
|
70
|
+
link.rel = @rel.to_s if @rel
|
71
|
+
link.source = self.source.to_s if self.source.kind_of? String if self.source
|
81
72
|
link.target = self.target.to_s if self.target
|
82
73
|
link
|
83
74
|
end
|
84
75
|
|
85
76
|
# @return [String] text representation of link reference
|
86
|
-
def
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
77
|
+
def to_string
|
78
|
+
string = '<' + self.target.to_s + '>'
|
79
|
+
string << ';rel=' + @rel.to_s.inspect
|
80
|
+
string << ';self=' + self.location.inspect if self.location
|
81
|
+
categories = [@kind] + @mixins.join(',').split(',')
|
82
|
+
string << ';category=' + categories.join(' ').inspect
|
83
|
+
string << ';'
|
84
|
+
@attributes.combine.each_pair do |name, value|
|
85
|
+
value = value.inspect
|
86
|
+
string << name + '=' + value + ';'
|
87
|
+
end
|
88
|
+
string << 'occi.core.target=' + self.target.to_s.inspect
|
89
|
+
string << 'occi.core.source=' + self.source.to_s.inspect if self.source.kind_of? String if self.source
|
90
|
+
|
91
|
+
string
|
92
|
+
end
|
93
|
+
|
94
|
+
# @return [String] text representation of link
|
95
|
+
def to_text_link
|
96
|
+
'Link: ' + self.to_string
|
94
97
|
end
|
95
98
|
|
96
99
|
end
|