occi-core 4.2.5 → 4.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 55c4ffb877bc923ee40bd01f091ba0b124289828
4
+ data.tar.gz: 4d4586c406eb9002cd5ffb3d73487b43bc86bdcf
5
+ SHA512:
6
+ metadata.gz: 64d75f1187fb40eaa6fb2b83264c6a1ef9ec18b8d171af3689da6db9e50e0d42be91503c314ddf27d96e008edc1bb3774d9a303709029bacfbaaf80064543b14
7
+ data.tar.gz: c06ed353a0c359ea1465b91ef0db4b3994bd1a7f168895f4a3ded5543ffb6f9435e6301c32d5c9d402d47bb10e919e92e3b4aeccd2055f959bea3db09e6cef59
@@ -64,8 +64,20 @@ module Occi
64
64
  @action.model = model if @action
65
65
  end
66
66
 
67
- def check
68
- @resources.check && @links.check && (@action ? @action.check : true)
67
+ # @param incl_categories [Boolean] check every category against the model
68
+ # @return [Boolean] result
69
+ def check(incl_categories = false)
70
+ @resources.check
71
+ @links.check
72
+ @action.check if @action
73
+
74
+ if incl_categories
75
+ @kinds.check
76
+ @mixins.check
77
+ @actions.check
78
+ end
79
+
80
+ true
69
81
  end
70
82
 
71
83
  # @param [Occi::Collection] other_collection
@@ -118,11 +130,12 @@ module Occi
118
130
 
119
131
  # Returns the category corresponding to a given id
120
132
  #
121
- # @param [String] id
133
+ # @param id [String] identifier
134
+ # @param cats_only [Boolean] look only for categories
122
135
  # @return [Occi::Core::Category]
123
- def get_by_id(id)
136
+ def get_by_id(id, cats_only = false)
124
137
  object = self.categories.select { |category| category.type_identifier == id }
125
- object = self.entities.select { |entity| entity.id == id } if object.empty?
138
+ object = self.entities.select { |entity| entity.id == id } if !cats_only && object.empty?
126
139
  object.first
127
140
  end
128
141
 
@@ -72,15 +72,24 @@ module Occi
72
72
  header
73
73
  end
74
74
 
75
- # @return [Bool] Indicating whether this action instance is "empty", i.e. required attributes are blank
75
+ # @return [Boolean] Indicating whether this action instance is "empty", i.e. required attributes are blank
76
76
  def empty?
77
77
  action.nil? || action.empty?
78
78
  end
79
79
 
80
- # @return [Bool] Result of the validation process
81
- def check
82
- # TODO: impl check for ActionInstance attributes
83
- true
80
+ # @param [Boolean] set default values for all empty attributes
81
+ # @return [Boolean] Result of the validation process
82
+ def check(set_defaults = false)
83
+ raise ArgumentError, 'No model has been assigned to this action instance' unless @model
84
+
85
+ action = @model.get_by_id(@action.type_identifier, true)
86
+ raise Occi::Errors::CategoryNotDefinedError,
87
+ "Action not found for action instance #{self.class.name}[#{self.to_s.inspect}]!" unless action
88
+
89
+ definitions = Occi::Core::Attributes.new
90
+ definitions.merge! action.attributes
91
+
92
+ @attributes.check!(definitions, set_defaults)
84
93
  end
85
94
 
86
95
  end
@@ -137,7 +137,7 @@ module Occi
137
137
 
138
138
  # @return [String]
139
139
  def to_string_short
140
- any? ? ";attributes=#{names.keys.join(' ').inspect}" : ""
140
+ any? ? ";attributes=#{names.keys.collect { |key| name_w_props(key) }.join(' ').inspect}" : ""
141
141
  end
142
142
 
143
143
  # @return [String]
@@ -354,6 +354,25 @@ module Occi
354
354
  end
355
355
  end
356
356
  end
357
+
358
+ def name_w_props(attribute_name)
359
+ return attribute_name if attribute_name.blank?
360
+
361
+ parts = attribute_name.split('.')
362
+ parts[parts.length - 1] = "_#{parts.last}"
363
+ property_name = parts.join('.')
364
+
365
+ return attribute_name unless self[property_name]
366
+
367
+ if !self[property_name].mutable
368
+ "#{attribute_name}{immutable}"
369
+ elsif self[property_name].required
370
+ "#{attribute_name}{required}"
371
+ else
372
+ attribute_name
373
+ end
374
+ end
375
+
357
376
  end
358
377
  end
359
378
  end
@@ -13,7 +13,10 @@ module Occi
13
13
  end
14
14
 
15
15
  def <<(category)
16
- super convert category
16
+ category = convert(category)
17
+ category.model = @model if @model && !category.kind_of?(String)
18
+
19
+ super(category)
17
20
  end
18
21
 
19
22
  def join(separator)
@@ -32,7 +35,8 @@ module Occi
32
35
  # @return [Occi::Model]
33
36
  def model=(model)
34
37
  @model = model
35
- collect! { |category| model.get_by_id category.to_s or category }
38
+ each { |category| category.model = model }
39
+ collect! { |category| model.get_by_id(category.to_s) || category }
36
40
  end
37
41
 
38
42
  # @param [Hash] options
@@ -41,10 +45,18 @@ module Occi
41
45
  self.to_a.as_json
42
46
  end
43
47
 
48
+ def check
49
+ each { |category| category.check }
50
+ end
51
+
44
52
  private
45
53
 
46
54
  def convert(category)
47
- (@model.get_by_id category if @model if category.kind_of? String) or category
55
+ if category.kind_of?(String) && @model
56
+ @model.get_by_id(category) || category
57
+ else
58
+ category
59
+ end
48
60
  end
49
61
 
50
62
  end
@@ -79,13 +79,29 @@ module Occi
79
79
  self.type_identifier
80
80
  end
81
81
 
82
- # @return [Bool] Indicating whether this category is "empty", i.e. required attributes are blank
82
+ # @return [Boolean] Indicating whether this category is "empty", i.e. required attributes are blank
83
83
  def empty?
84
84
  term.blank? || scheme.blank?
85
85
  end
86
86
 
87
+ # Checks this category against the model
88
+ # @param check_attributes [Boolean] attribute definitions must match
89
+ # @param check_title [Boolean] titles must match
90
+ # @return [Boolean]
91
+ def check(check_attributes = false, check_title = false)
92
+ raise ArgumentError, 'No model has been assigned to this category' unless @model
93
+
94
+ cat = @model.get_by_id(type_identifier, true)
95
+ raise Occi::Errors::CategoryNotDefinedError,
96
+ "Category #{self.class.name}[#{type_identifier.inspect}] not found in the model!" unless cat
97
+
98
+ # TODO: impl. check_attributes and check_title for strict matching
99
+
100
+ true
101
+ end
102
+
87
103
  # @param term [String] Term to check.
88
- # @return [Bool] Indicating whether term consists exclusively of valid characters.
104
+ # @return [Boolean] Indicating whether term consists exclusively of valid characters.
89
105
  def self.valid_term?(term)
90
106
  term =~ /^[a-z][a-z0-9_-]*$/
91
107
  end
@@ -18,7 +18,7 @@ module Occi
18
18
 
19
19
  def model=(model)
20
20
  @model = model
21
- each { |entity| entity.model=model }
21
+ each { |entity| entity.model = model }
22
22
  end
23
23
 
24
24
  def check
@@ -159,10 +159,9 @@ module Occi
159
159
  # check attributes against their definitions and set defaults
160
160
  # @param [true,false] set default values for all empty attributes
161
161
  def check(set_defaults = false)
162
-
163
162
  raise ArgumentError, 'No model has been assigned to this entity' unless @model
164
163
 
165
- kind = @model.get_by_id(@kind.to_s)
164
+ kind = @model.get_by_id(@kind.to_s, true)
166
165
  raise Occi::Errors::KindNotDefinedError,
167
166
  "Kind not found for entity #{self.class.name}[#{self.to_s.inspect}]!" unless kind
168
167
 
@@ -0,0 +1,5 @@
1
+ module Occi
2
+ module Errors
3
+ class CategoryNotDefinedError < ArgumentError; end
4
+ end
5
+ end
@@ -13,7 +13,7 @@ module Occi
13
13
  self.actions = Occi::Core::Actions.new << up << down
14
14
 
15
15
  self.attributes = Occi::Core::Attributes.new(Occi::Core::Link.attributes)
16
- self.attributes['occi.networkinterface.interface'] ={:mutable => true}
16
+ self.attributes['occi.networkinterface.interface'] = {:mutable => false}
17
17
  self.attributes['occi.networkinterface.mac'] = {:mutable => true,
18
18
  :pattern => '^([0-9a-fA-F]{2}[:-]){5}([0-9a-fA-F]{2})$'}
19
19
  self.attributes['occi.networkinterface.state'] = {:pattern => 'active|inactive|error',
@@ -115,8 +115,8 @@ module Occi
115
115
  properties = Occi::Core::Properties.new
116
116
 
117
117
  if property_string
118
- properties.required = true if property_string.include? 'required'
119
- properties.mutable = false if property_string.include? 'immutable'
118
+ properties.required = property_string.include?('{required}')
119
+ properties.mutable = !property_string.include?('{immutable}')
120
120
  end
121
121
 
122
122
  name = attribute[/#{REGEXP_ATTRIBUTE_DEF}/, 1]
data/lib/occi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Occi
2
- VERSION = "4.2.5" unless defined?(::Occi::VERSION)
2
+ VERSION = "4.2.6" unless defined?(::Occi::VERSION)
3
3
  end
@@ -811,7 +811,7 @@ module Occi
811
811
  collection.resources << Occi::Core::Resource.new
812
812
  collection.links << Occi::Core::Link.new
813
813
 
814
- expected = "Category: compute;scheme=\"http://schemas.ogf.org/occi/infrastructure#\";class=\"kind\";title=\"compute resource\";rel=\"http://schemas.ogf.org/occi/core#resource\";location=\"/compute/\";attributes=\"occi.core.id occi.core.title occi.core.summary occi.compute.architecture occi.compute.cores occi.compute.hostname occi.compute.memory occi.compute.speed occi.compute.state\";actions=\"http://schemas.ogf.org/occi/infrastructure/compute/action#start http://schemas.ogf.org/occi/infrastructure/compute/action#stop http://schemas.ogf.org/occi/infrastructure/compute/action#restart http://schemas.ogf.org/occi/infrastructure/compute/action#suspend\"\nCategory: my_mixin;scheme=\"http://example.com/occi/tags#\";class=\"mixin\";location=\"/mixin/my_mixin/\"\nCategory: start;scheme=\"http://schemas.ogf.org/occi/infrastructure/compute/action#\";class=\"action\"\nCategory: resource;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"kind\"\nX-OCCI-Attribute: occi.core.id=\"#{collection.resources.first.id}\"Link: <>;rel=\"http://schemas.ogf.org/occi/core#link\";self=\"/link/#{collection.links.first.id}\";category=\"http://schemas.ogf.org/occi/core#link\";occi.core.id=\"#{collection.links.first.id}\"Category: action_instance;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"action\""
814
+ expected = "Category: compute;scheme=\"http://schemas.ogf.org/occi/infrastructure#\";class=\"kind\";title=\"compute resource\";rel=\"http://schemas.ogf.org/occi/core#resource\";location=\"/compute/\";attributes=\"occi.core.id{immutable} occi.core.title occi.core.summary occi.compute.architecture occi.compute.cores occi.compute.hostname occi.compute.memory occi.compute.speed occi.compute.state{immutable}\";actions=\"http://schemas.ogf.org/occi/infrastructure/compute/action#start http://schemas.ogf.org/occi/infrastructure/compute/action#stop http://schemas.ogf.org/occi/infrastructure/compute/action#restart http://schemas.ogf.org/occi/infrastructure/compute/action#suspend\"\nCategory: my_mixin;scheme=\"http://example.com/occi/tags#\";class=\"mixin\";location=\"/mixin/my_mixin/\"\nCategory: start;scheme=\"http://schemas.ogf.org/occi/infrastructure/compute/action#\";class=\"action\"\nCategory: resource;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"kind\"\nX-OCCI-Attribute: occi.core.id=\"#{collection.resources.first.id}\"Link: <>;rel=\"http://schemas.ogf.org/occi/core#link\";self=\"/link/#{collection.links.first.id}\";category=\"http://schemas.ogf.org/occi/core#link\";occi.core.id=\"#{collection.links.first.id}\"Category: action_instance;scheme=\"http://schemas.ogf.org/occi/core#\";class=\"action\""
815
815
  expect(collection.to_text).to eql(expected)
816
816
  end
817
817
 
@@ -822,7 +822,7 @@ module Occi
822
822
 
823
823
  it 'renders text correctly, kinds only' do
824
824
  collection.kinds << "http://schemas.ogf.org/occi/infrastructure#compute"
825
- expected = "Category: compute;scheme=\"http://schemas.ogf.org/occi/infrastructure#\";class=\"kind\";title=\"compute resource\";rel=\"http://schemas.ogf.org/occi/core#resource\";location=\"/compute/\";attributes=\"occi.core.id occi.core.title occi.core.summary occi.compute.architecture occi.compute.cores occi.compute.hostname occi.compute.memory occi.compute.speed occi.compute.state\";actions=\"http://schemas.ogf.org/occi/infrastructure/compute/action#start http://schemas.ogf.org/occi/infrastructure/compute/action#stop http://schemas.ogf.org/occi/infrastructure/compute/action#restart http://schemas.ogf.org/occi/infrastructure/compute/action#suspend\"\n"
825
+ expected = "Category: compute;scheme=\"http://schemas.ogf.org/occi/infrastructure#\";class=\"kind\";title=\"compute resource\";rel=\"http://schemas.ogf.org/occi/core#resource\";location=\"/compute/\";attributes=\"occi.core.id{immutable} occi.core.title occi.core.summary occi.compute.architecture occi.compute.cores occi.compute.hostname occi.compute.memory occi.compute.speed occi.compute.state{immutable}\";actions=\"http://schemas.ogf.org/occi/infrastructure/compute/action#start http://schemas.ogf.org/occi/infrastructure/compute/action#stop http://schemas.ogf.org/occi/infrastructure/compute/action#restart http://schemas.ogf.org/occi/infrastructure/compute/action#suspend\"\n"
826
826
  expect(collection.to_text).to eql(expected)
827
827
  end
828
828
 
@@ -230,8 +230,16 @@ module Occi
230
230
  end
231
231
 
232
232
  context '#to_string_short' do
233
+ let(:attrs_with_req_immut) {
234
+ attrs = Occi::Core::Attributes.new
235
+ attrs['immut_attr'] = { :mutable => false, :required => false }
236
+ attrs['req_attr'] = { :mutable => true, :required => true }
237
+ attrs['immut_req_attr'] = { :mutable => false, :required => true }
238
+ attrs
239
+ }
240
+
233
241
  it 'renders attributes correctly' do
234
- expected = ";attributes=\"numbertype stringtype booleantype booleantypefalse booleantypepattern nest.nested properties category entity\""
242
+ expected = ";attributes=\"numbertype stringtype booleantype booleantypefalse booleantypepattern nest.nested properties{immutable} category entity\""
235
243
  expect(attrs.to_string_short).to eql expected
236
244
  end
237
245
 
@@ -239,6 +247,11 @@ module Occi
239
247
  expected = ""
240
248
  expect(empty.to_string_short).to eql expected
241
249
  end
250
+
251
+ it 'renders attributes with properties correctly' do
252
+ expected = ";attributes=\"immut_attr{immutable} req_attr{required} immut_req_attr{immutable}\""
253
+ expect(attrs_with_req_immut.to_string_short).to eql expected
254
+ end
242
255
  end
243
256
 
244
257
  context '#to_text' do
@@ -14,11 +14,12 @@ module Occi
14
14
 
15
15
  it "replaces a category string when a model is added with the instance from the model" do
16
16
  categories = Occi::Core::Categories.new
17
- categories << Occi::Core::Resource.type_identifier
18
17
  model = Occi::Model.new
18
+ categories.model = model
19
+ categories << Occi::Core::Resource.type_identifier
20
+
19
21
  resource = model.get_by_id Occi::Core::Resource.type_identifier
20
22
  resource.location = '/new_location/'
21
- categories.model = model
22
23
  categories.first.location.should == '/new_location/'
23
24
  end
24
25
 
@@ -29,6 +29,15 @@ module Occi
29
29
  expect(category).to eql expected
30
30
  end
31
31
 
32
+ it 'parses a string describing an OCCI Category incl. attributes with properties' do
33
+ category_string = 'Category: restart;scheme="http://schemas.ogf.org/occi/infrastructure/compute/action#";class="action";title="Restart Compute instance";attributes="method{required} test{immutable}"'
34
+ category = Occi::Parser::Text.category category_string
35
+
36
+ expect(category.attributes['method'].required).to be_true
37
+ expect(category.attributes['method'].mutable).to be_true
38
+ expect(category.attributes['test'].required).to be_false
39
+ expect(category.attributes['test'].mutable).to be_false
40
+ end
32
41
 
33
42
  it 'parses attributes correctly' do
34
43
  resource_string = File.open("spec/occi/parser/text_samples/occi_resource_w_attributes.text", "rb").read
@@ -110,6 +119,7 @@ module Occi
110
119
  Occi::Parser::Text.const_set('REGEXP_CATEGORY', regexp_category)
111
120
  end
112
121
  end
122
+
113
123
  context '.resource' do
114
124
  it 'parses network resource from rOCCI server' do
115
125
  resource_string = File.open("spec/occi/parser/text_samples/occi_network_rocci_server.text", "rb").read
@@ -239,6 +249,7 @@ module Occi
239
249
 
240
250
  context 'compatibility' do
241
251
  after(:each) { Occi::Settings.reload! }
252
+
242
253
  context 'terms' do
243
254
  it 'parses uppercase term, compatibility on' do
244
255
  Occi::Settings['compatibility']=true
@@ -269,6 +280,7 @@ module Occi
269
280
  end
270
281
 
271
282
  end
283
+
272
284
  context 'schemes' do
273
285
  it 'parses a Category, compatibility on' do
274
286
  Occi::Settings['compatibility']=true
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: occi-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.5
5
- prerelease:
4
+ version: 4.2.6
6
5
  platform: ruby
7
6
  authors:
8
7
  - Florian Feldhaus
@@ -11,60 +10,53 @@ authors:
11
10
  autorequire:
12
11
  bindir: bin
13
12
  cert_chain: []
14
- date: 2014-01-09 00:00:00.000000000 Z
13
+ date: 2014-02-03 00:00:00.000000000 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: json
18
17
  requirement: !ruby/object:Gem::Requirement
19
- none: false
20
18
  requirements:
21
- - - ! '>='
19
+ - - '>='
22
20
  - !ruby/object:Gem::Version
23
21
  version: '0'
24
22
  type: :runtime
25
23
  prerelease: false
26
24
  version_requirements: !ruby/object:Gem::Requirement
27
- none: false
28
25
  requirements:
29
- - - ! '>='
26
+ - - '>='
30
27
  - !ruby/object:Gem::Version
31
28
  version: '0'
32
29
  - !ruby/object:Gem::Dependency
33
30
  name: hashie
34
31
  requirement: !ruby/object:Gem::Requirement
35
- none: false
36
32
  requirements:
37
- - - ! '>='
33
+ - - '>='
38
34
  - !ruby/object:Gem::Version
39
35
  version: '0'
40
36
  type: :runtime
41
37
  prerelease: false
42
38
  version_requirements: !ruby/object:Gem::Requirement
43
- none: false
44
39
  requirements:
45
- - - ! '>='
40
+ - - '>='
46
41
  - !ruby/object:Gem::Version
47
42
  version: '0'
48
43
  - !ruby/object:Gem::Dependency
49
44
  name: uuidtools
50
45
  requirement: !ruby/object:Gem::Requirement
51
- none: false
52
46
  requirements:
53
- - - ! '>='
47
+ - - '>='
54
48
  - !ruby/object:Gem::Version
55
49
  version: 2.1.3
56
50
  type: :runtime
57
51
  prerelease: false
58
52
  version_requirements: !ruby/object:Gem::Requirement
59
- none: false
60
53
  requirements:
61
- - - ! '>='
54
+ - - '>='
62
55
  - !ruby/object:Gem::Version
63
56
  version: 2.1.3
64
57
  - !ruby/object:Gem::Dependency
65
58
  name: nokogiri
66
59
  requirement: !ruby/object:Gem::Requirement
67
- none: false
68
60
  requirements:
69
61
  - - ~>
70
62
  - !ruby/object:Gem::Version
@@ -72,7 +64,6 @@ dependencies:
72
64
  type: :runtime
73
65
  prerelease: false
74
66
  version_requirements: !ruby/object:Gem::Requirement
75
- none: false
76
67
  requirements:
77
68
  - - ~>
78
69
  - !ruby/object:Gem::Version
@@ -80,7 +71,6 @@ dependencies:
80
71
  - !ruby/object:Gem::Dependency
81
72
  name: activesupport
82
73
  requirement: !ruby/object:Gem::Requirement
83
- none: false
84
74
  requirements:
85
75
  - - ~>
86
76
  - !ruby/object:Gem::Version
@@ -88,7 +78,6 @@ dependencies:
88
78
  type: :runtime
89
79
  prerelease: false
90
80
  version_requirements: !ruby/object:Gem::Requirement
91
- none: false
92
81
  requirements:
93
82
  - - ~>
94
83
  - !ruby/object:Gem::Version
@@ -96,17 +85,15 @@ dependencies:
96
85
  - !ruby/object:Gem::Dependency
97
86
  name: settingslogic
98
87
  requirement: !ruby/object:Gem::Requirement
99
- none: false
100
88
  requirements:
101
- - - ! '>='
89
+ - - '>='
102
90
  - !ruby/object:Gem::Version
103
91
  version: '0'
104
92
  type: :runtime
105
93
  prerelease: false
106
94
  version_requirements: !ruby/object:Gem::Requirement
107
- none: false
108
95
  requirements:
109
- - - ! '>='
96
+ - - '>='
110
97
  - !ruby/object:Gem::Version
111
98
  version: '0'
112
99
  description: OCCI is a collection of classes to simplify the implementation of the
@@ -157,6 +144,7 @@ files:
157
144
  - lib/occi/errors/attribute_not_defined_error.rb
158
145
  - lib/occi/errors/attribute_property_type_error.rb
159
146
  - lib/occi/errors/attribute_type_error.rb
147
+ - lib/occi/errors/category_not_defined_error.rb
160
148
  - lib/occi/errors/kind_not_defined_error.rb
161
149
  - lib/occi/errors/parser_input_error.rb
162
150
  - lib/occi/errors/parser_type_error.rb
@@ -258,29 +246,25 @@ files:
258
246
  homepage: https://github.com/gwdg/rOCCI-core
259
247
  licenses:
260
248
  - Apache License, Version 2.0
249
+ metadata: {}
261
250
  post_install_message:
262
251
  rdoc_options: []
263
252
  require_paths:
264
253
  - lib
265
254
  required_ruby_version: !ruby/object:Gem::Requirement
266
- none: false
267
255
  requirements:
268
- - - ! '>='
256
+ - - '>='
269
257
  - !ruby/object:Gem::Version
270
258
  version: 1.9.3
271
259
  required_rubygems_version: !ruby/object:Gem::Requirement
272
- none: false
273
260
  requirements:
274
- - - ! '>='
261
+ - - '>='
275
262
  - !ruby/object:Gem::Version
276
263
  version: '0'
277
- segments:
278
- - 0
279
- hash: -1899763597318893191
280
264
  requirements: []
281
265
  rubyforge_project:
282
- rubygems_version: 1.8.25
266
+ rubygems_version: 2.1.11
283
267
  signing_key:
284
- specification_version: 3
268
+ specification_version: 4
285
269
  summary: OCCI toolkit
286
270
  test_files: []