occi-core 5.0.0.alpha.1 → 5.0.0.alpha.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d36511dceaecabc4508ec2db62c83920e63fff0
4
- data.tar.gz: e9f542fefa3da8fabe0e6aaecaa822b7d1d25233
3
+ metadata.gz: 196f824b580d6a90fe2da14cbf85b99deb088d93
4
+ data.tar.gz: 8b06f630a141c702742c019529bf11184e8ce87f
5
5
  SHA512:
6
- metadata.gz: b96ea07c5b9c28b5933e47f0874946abb38df81ceed4461a188c0b96ca3ae3ed56bf43842b1eddbca21c058c6884816683900e35a7e3fbe720da8ce86672eee8
7
- data.tar.gz: a3b0c5dbb6b998df32495b6b2d474f7b7ab8dafe95264953410fe58ac3e1e07c1ea1bac21a5c4dff21142a5704cb180b2196083c78d08bd48173c8f2eca540c8
6
+ metadata.gz: db0db57a71621cf8beb45e2682659831a8aff23356efbdf26d6b1160f4a36d8e69ef9ecb94b55819d7584825dbc74034f6c1a155bf62d374c98722602a8d2f52
7
+ data.tar.gz: 93ef6536c47a7d0b3225f0ffb5280eaacc2b6b5611c4d902bcb5374bbf0cf162abfdbee0fdb58e35d0c914a514786a36ee8719ecd881c953afff81cc0b60e070
data/.rubocop.yml CHANGED
@@ -21,6 +21,7 @@ Metrics/AbcSize:
21
21
  - 'lib/occi/core/parsers/text/*'
22
22
  - 'lib/occi/core/parsers/json/*'
23
23
  - 'lib/occi/core/helpers/parser_dereferencer.rb'
24
+ - 'lib/occi/core/helpers/instance_attribute_resetter.rb'
24
25
 
25
26
  Metrics/LineLength:
26
27
  Max: 120
@@ -1,78 +1,8 @@
1
1
  {
2
2
  "mixins": [
3
- {
4
- "applies": [
5
- "http://schemas.ogf.org/occi/infrastructure#network"
6
- ],
7
- "attributes": {
8
- "occi.network.address": {
9
- "description": "IP address (v4 or v6) assigned to this instance.",
10
- "mutable": true,
11
- "required": false,
12
- "type": "string"
13
- },
14
- "occi.network.allocation": {
15
- "default": "static",
16
- "description": "Network address allocation mechanism.",
17
- "mutable": true,
18
- "pattern": "(?-mix:^(dynamic|static)$)",
19
- "required": false,
20
- "type": "string"
21
- },
22
- "occi.network.gateway": {
23
- "description": "IP address (v4 or v6) of the pre-configured gateway.",
24
- "mutable": true,
25
- "required": false,
26
- "type": "string"
27
- }
28
- },
29
- "location": "/mixin/ipnetwork/",
30
- "scheme": "http://schemas.ogf.org/occi/infrastructure/network#",
31
- "term": "ipnetwork",
32
- "title": "OCCI IP Network mixin"
33
- },
34
- {
35
- "applies": [
36
- "http://schemas.ogf.org/occi/infrastructure#networkinterface"
37
- ],
38
- "attributes": {
39
- "occi.networkinterface.address": {
40
- "description": "IP address (v4 or v6) assigned to this instance.",
41
- "mutable": true,
42
- "required": false,
43
- "type": "string"
44
- },
45
- "occi.networkinterface.allocation": {
46
- "default": "static",
47
- "description": "Network address allocation mechanism.",
48
- "mutable": true,
49
- "pattern": "(?-mix:^(dynamic|static)$)",
50
- "required": false,
51
- "type": "string"
52
- },
53
- "occi.networkinterface.gateway": {
54
- "description": "IP address (v4 or v6) of the pre-configured gateway.",
55
- "mutable": true,
56
- "required": false,
57
- "type": "string"
58
- }
59
- },
60
- "location": "/mixin/ipnetworkinterface/",
61
- "scheme": "http://schemas.ogf.org/occi/infrastructure/networkinterface#",
62
- "term": "ipnetworkinterface",
63
- "title": "OCCI IP NetworkInterface mixin"
64
- },
65
- {
66
- "location": "/mixin/os_tpl/",
67
- "scheme": "http://schemas.ogf.org/occi/infrastructure#",
68
- "term": "os_tpl",
69
- "title": "OS or Appliance template (parent mixin)"
70
- },
71
- {
72
- "location": "/mixin/resource_tpl/",
73
- "scheme": "http://schemas.ogf.org/occi/infrastructure#",
74
- "term": "resource_tpl",
75
- "title": "Resource template providing flavor/sizing information (parent mixin)"
76
- }
3
+ "http://schemas.ogf.org/occi/infrastructure/network#ipnetwork",
4
+ "http://schemas.ogf.org/occi/infrastructure/networkinterface#ipnetworkinterface",
5
+ "http://schemas.ogf.org/occi/infrastructure#os_tpl",
6
+ "http://schemas.ogf.org/occi/infrastructure#resource_tpl"
77
7
  ]
78
8
  }
@@ -1,4 +1,4 @@
1
- Category: resource_tpl;scheme="http://schemas.ogf.org/occi/infrastructure#";class="mixin";title="resource template";location="/mixin/resource_tpl/"
2
- Category: os_tpl;scheme="http://schemas.ogf.org/occi/infrastructure#";class="mixin";title="operating system template";location="/mixin/os_tpl/"
3
- Category: ipnetwork;scheme="http://schemas.ogf.org/occi/infrastructure/network#";class="mixin";title="IP network mixin";location="/mixin/ipnetwork/";attributes="occi.network.address occi.network.gateway occi.network.allocation"
4
- Category: ipnetworkinterface;scheme="http://schemas.ogf.org/occi/infrastructure/networkinterface#";class="mixin";title="IP network interface mixin";location="/mixin/ipnetworkinterface/";attributes="occi.networkinterface.address occi.networkinterface.gateway occi.networkinterface.allocation"
1
+ Category: resource_tpl;scheme="http://schemas.ogf.org/occi/infrastructure#";class="mixin"
2
+ Category: os_tpl;scheme="http://schemas.ogf.org/occi/infrastructure#";class="mixin"
3
+ Category: ipnetwork;scheme="http://schemas.ogf.org/occi/infrastructure/network#";class="mixin"
4
+ Category: ipnetworkinterface;scheme="http://schemas.ogf.org/occi/infrastructure/networkinterface#";class="mixin"
@@ -8,6 +8,7 @@ module Occi
8
8
  module ArgumentValidator
9
9
  # :nodoc:
10
10
  def default_args!(args)
11
+ logger.debug "#{self.class}: Merging given args #{args.inspect} with defaults #{defaults.inspect}"
11
12
  args.merge!(defaults) { |_, oldval, _| oldval }
12
13
  sufficient_args!(args)
13
14
  end
@@ -51,7 +51,11 @@ module Occi
51
51
  # @return [Hash] updated attribute hash
52
52
  def remove_undef_attributes
53
53
  name_cache = attribute_names
54
- attributes.keep_if { |key, value| name_cache.include?(key) && value && value.attribute_definition }
54
+ attributes.keep_if do |key, value|
55
+ defined = name_cache.include?(key) && value && value.attribute_definition
56
+ logger.debug "#{self.class}: Removing undefined attribute #{key.inspect}" unless defined
57
+ defined
58
+ end
55
59
  end
56
60
 
57
61
  # Collects all available attribute names into a list. Without definitions
@@ -118,8 +122,10 @@ module Occi
118
122
  # @param force [TrueClass, FalseClass] forcibly change attribute value to default
119
123
  def reset_attribute(name, definition, force)
120
124
  if attributes[name]
125
+ logger.debug "#{self.class}: Setting attribute definition for existing #{name.inspect}"
121
126
  attributes[name].attribute_definition = definition
122
127
  else
128
+ logger.debug "#{self.class}: Creating attribute definition for new #{name.inspect}"
123
129
  attributes[name] = Attribute.new(nil, definition)
124
130
  end
125
131
 
@@ -44,6 +44,7 @@ module Occi
44
44
  # @param derefd [Array] list of all available category instances
45
45
  # @param parsed_actions [Array] textual representation of needed actions
46
46
  def lookup_action_references!(cat, derefd, parsed_actions)
47
+ logger.debug "#{self}: Dereferencing actions #{parsed_actions.inspect} for #{cat.identifier.inspect}"
47
48
  return if parsed_actions.blank?
48
49
  parsed_actions.each { |action| cat.actions << first_or_die(derefd, action) }
49
50
  end
@@ -53,6 +54,7 @@ module Occi
53
54
  # @param parsed_rel [Array] textual representation of needed parent(s)
54
55
  def lookup_parent_references!(kind, derefd, parsed_rel)
55
56
  return if parsed_rel.blank? || kind.parent.is_a?(Occi::Core::Kind)
57
+ logger.debug "#{self}: Dereferencing parent #{parsed_rel.inspect} for #{kind.identifier.inspect}"
56
58
  if parsed_rel.is_a?(Enumerable)
57
59
  if parsed_rel.count > 1
58
60
  raise Occi::Core::Errors::ParsingError,
@@ -83,6 +85,7 @@ module Occi
83
85
  # @param what [String] identifier of the desired item
84
86
  # @return [Object] desired item from `where`
85
87
  def first_or_die(where, what)
88
+ logger.debug "#{self}: Looking for #{what.inspect} in #{where.class}"
86
89
  found = where.detect { |elm| elm.identifier == what }
87
90
  unless found
88
91
  raise Occi::Core::Errors::ParsingError,
@@ -25,6 +25,7 @@ module Occi
25
25
  raise 'This method cannot be invoked on instances' unless is_a? Class
26
26
  allowed_classes = respond_to?(:allowed_yaml_classes, true) ? allowed_yaml_classes : []
27
27
 
28
+ logger.debug "#{self}: Loading YAML definition from #{path.inspect}"
28
29
  object_args = YAML.safe_load(File.read(path), allowed_classes)
29
30
  object_args.symbolize_keys!
30
31
  object_args.dereference_with!(self, model, attribute_definitions) if needs_dereferencing?
@@ -42,6 +42,7 @@ module Occi
42
42
  # @return [Object] constructed instance
43
43
  # @return [NilClass] if such an instance could not be constructed
44
44
  def build(identifier, args = {})
45
+ logger.debug "#{self.class}: Building instance of #{identifier.inspect} with #{args.inspect}"
45
46
  k_args = args_with_kind(identifier, args)
46
47
  klass(identifier, parent_klass(k_args[:kind])).new k_args
47
48
  end
@@ -77,19 +78,23 @@ module Occi
77
78
 
78
79
  # Looks up the appropriate candidate class for the given identifier. If no class
79
80
  # is found in static tables, the last known ancestor is returned. For Core, this
80
- # method ALWAYS returns the last known ancestor given as `last_ancestor`, for
81
+ # method ALWAYS returns the last known ancestor given as `known_ancestor`, for
81
82
  # compatibility reasons.
82
83
  #
83
84
  # @param identifier [String] identifier of the category
84
- # @param last_ancestor [Class] expected ancestor
85
+ # @param known_ancestor [Class] expected ancestor
85
86
  # @return [Class] pre-defined class or given last ancestor
86
- def klass(identifier, last_ancestor)
87
- found_last_ancestor = self.class.klass_map[identifier]
88
- if found_last_ancestor && !found_last_ancestor.ancestors.include?(last_ancestor)
87
+ def klass(identifier, known_ancestor)
88
+ found_klass = self.class.klass_map[identifier]
89
+ return known_ancestor unless found_klass
90
+
91
+ unless found_klass.ancestors.include?(known_ancestor)
89
92
  raise Occi::Core::Errors::InstanceValidationError,
90
- "#{found_last_ancestor.inspect} is not a sub-type of #{last_ancestor.inspect}"
93
+ "#{found_klass} is not a sub-type of #{known_ancestor}"
91
94
  end
92
- found_last_ancestor || last_ancestor
95
+
96
+ logger.debug "#{self.class}: Found #{found_klass} for #{identifier.inspect}"
97
+ found_klass
93
98
  end
94
99
 
95
100
  # Looks up the given identifier in the model. Returns `Occi::Core::Kind` instance if
@@ -98,7 +103,7 @@ module Occi
98
103
  #
99
104
  # @param identifier [String] identifier of the category
100
105
  # @return [Occi::Core::Kind] full category definition from the model
101
- def kind(identifier)
106
+ def kind_instance(identifier)
102
107
  kind = model.find_by_identifier!(identifier)
103
108
  unless kind.is_a? Occi::Core::Kind
104
109
  raise Occi::Core::Errors::CategoryValidationError, "#{identifier.inspect} " \
@@ -113,13 +118,15 @@ module Occi
113
118
  # @param kind [Occi::Core::Kind] kind instance to evaluate
114
119
  # @return [Class] located known parent class
115
120
  def parent_klass(kind)
116
- if kind.related? kind(Occi::Core::Constants::RESOURCE_KIND)
121
+ if kind.related? kind_instance(Occi::Core::Constants::RESOURCE_KIND)
122
+ logger.debug "#{self.class}: Identified #{kind.identifier} as Resource"
117
123
  Occi::Core::Resource
118
- elsif kind.related? kind(Occi::Core::Constants::LINK_KIND)
124
+ elsif kind.related? kind_instance(Occi::Core::Constants::LINK_KIND)
125
+ logger.debug "#{self.class}: Identified #{kind.identifier} as Link"
119
126
  Occi::Core::Link
120
127
  else
121
128
  raise Occi::Core::Errors::ModelLookupError,
122
- "Could not identify #{kind.identifier.inspect} as a Link or Resource"
129
+ "Could not identify #{kind.identifier} as a Link or Resource"
123
130
  end
124
131
  end
125
132
 
@@ -153,8 +160,8 @@ module Occi
153
160
  # :nodoc:
154
161
  def args_with_kind(identifier, args)
155
162
  k_args = args.clone
156
- k_args[:kind] = kind(identifier)
157
- k_args[:rel] = kind(k_args[:rel]) if k_args[:rel]
163
+ k_args[:kind] = kind_instance(identifier)
164
+ k_args[:rel] = kind_instance(k_args[:rel]) if k_args[:rel]
158
165
  k_args
159
166
  end
160
167
  end
@@ -242,6 +242,7 @@ module Occi
242
242
  # model = Occi::Core::Model.new
243
243
  # model.load_core!
244
244
  def load_core!
245
+ logger.debug "#{self.class}: Loading Core from Warehouse"
245
246
  Occi::Core::Warehouse.bootstrap! self
246
247
  end
247
248
 
@@ -33,13 +33,10 @@ module Occi
33
33
  #
34
34
  # @param body [String] JSON body for parsing
35
35
  # @param model [Occi::Core::Model] model with existing categories
36
- # @param full [Boolean] dereference categories
37
36
  # @return [Occi::Core::Model] model with all known category instances
38
- def json(body, model, full = true)
37
+ def json(body, model)
39
38
  parsed = raw_hash(body)
40
-
41
39
  instantiate_hashes! parsed, model
42
- return model unless full
43
40
 
44
41
  raw_categories = [parsed[:kinds], parsed[:mixins]].flatten.compact
45
42
  dereference_identifiers! model.categories, raw_categories
@@ -0,0 +1,3 @@
1
+ {
2
+ "$ref": "occi-schema.json#/definitions/category_identifiers"
3
+ }
@@ -13,52 +13,49 @@
13
13
  "kind": { "type": "string" }
14
14
  }
15
15
  },
16
- "resource": {
17
- "id": "#resource",
16
+ "attributes": {
17
+ "id": "#attributes",
18
18
  "type": "object",
19
- "required": ["kind", "id", "attributes"],
20
- "additionalProperties": false,
21
- "properties": {
22
- "kind": { "type": "string" },
23
- "mixins": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray" },
24
- "attributes": { "$ref": "#/definitions/attributes" },
25
- "actions": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray" },
26
- "id": { "type": "string" },
27
- "links": {
28
- "type": "array",
29
- "minItems": 1,
30
- "items": {
31
- "$ref": "#/definitions/link"
32
- }
33
- },
34
- "summary": { "type": "string" },
35
- "title": { "type": "string" }
19
+ "additionalProperties": {
20
+ "oneOf": [
21
+ { "type": "number" },
22
+ { "type": "boolean" },
23
+ { "type": "string" },
24
+ { "type": "object" },
25
+ { "type": "array" }
26
+ ]
36
27
  }
37
28
  },
38
- "action_instance": {
39
- "id": "#action_instance",
29
+ "attribute_definition": {
30
+ "id": "#attribute_definition",
40
31
  "type": "object",
41
- "required": ["action"],
42
32
  "additionalProperties": false,
33
+ "required": ["type", "mutable", "required"],
43
34
  "properties": {
44
- "action": { "type": "string" },
45
- "attributes": { "$ref": "#/definitions/attributes" }
35
+ "mutable": { "type": "boolean" },
36
+ "required": { "type": "boolean" },
37
+ "type": { "type": "string" },
38
+ "default": {
39
+ "oneOf": [
40
+ { "type": "number" },
41
+ { "type": "string" },
42
+ { "type": "boolean" },
43
+ { "type": "object" },
44
+ { "type": "array" }
45
+ ]
46
+ },
47
+ "description": { "type": "string" },
48
+ "pattern": { "type": "string" }
46
49
  }
47
50
  },
48
- "link": {
49
- "id": "#link",
51
+ "attribute_definitions": {
52
+ "id": "#attribute_definitions",
50
53
  "type": "object",
51
- "required": ["kind", "id", "target", "source", "attributes"],
52
54
  "additionalProperties": false,
53
- "properties": {
54
- "kind": { "type": "string" },
55
- "mixins": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray" },
56
- "attributes": { "$ref": "#/definitions/attributes" },
57
- "actions": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray" },
58
- "id": { "type": "string" },
59
- "source": { "$ref": "#/definitions/kinded_uri" },
60
- "target": { "$ref": "#/definitions/kinded_uri" },
61
- "title": { "type": "string" }
55
+ "patternProperties": {
56
+ ".+": {
57
+ "$ref": "#/definitions/attribute_definition"
58
+ }
62
59
  }
63
60
  },
64
61
  "kind": {
@@ -104,6 +101,54 @@
104
101
  "attributes": { "$ref": "#/definitions/attribute_definitions" }
105
102
  }
106
103
  },
104
+ "action_instance": {
105
+ "id": "#action_instance",
106
+ "type": "object",
107
+ "required": ["action"],
108
+ "additionalProperties": false,
109
+ "properties": {
110
+ "action": { "type": "string" },
111
+ "attributes": { "$ref": "#/definitions/attributes" }
112
+ }
113
+ },
114
+ "resource": {
115
+ "id": "#resource",
116
+ "type": "object",
117
+ "required": ["kind", "id", "attributes"],
118
+ "additionalProperties": false,
119
+ "properties": {
120
+ "kind": { "type": "string" },
121
+ "mixins": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray" },
122
+ "attributes": { "$ref": "#/definitions/attributes" },
123
+ "actions": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray" },
124
+ "id": { "type": "string" },
125
+ "links": {
126
+ "type": "array",
127
+ "minItems": 1,
128
+ "items": {
129
+ "$ref": "#/definitions/link"
130
+ }
131
+ },
132
+ "summary": { "type": "string" },
133
+ "title": { "type": "string" }
134
+ }
135
+ },
136
+ "link": {
137
+ "id": "#link",
138
+ "type": "object",
139
+ "required": ["kind", "id", "target", "source", "attributes"],
140
+ "additionalProperties": false,
141
+ "properties": {
142
+ "kind": { "type": "string" },
143
+ "mixins": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray" },
144
+ "attributes": { "$ref": "#/definitions/attributes" },
145
+ "actions": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray" },
146
+ "id": { "type": "string" },
147
+ "source": { "$ref": "#/definitions/kinded_uri" },
148
+ "target": { "$ref": "#/definitions/kinded_uri" },
149
+ "title": { "type": "string" }
150
+ }
151
+ },
107
152
  "resource_collection": {
108
153
  "id": "#resource_collection",
109
154
  "type": "object",
@@ -155,94 +200,41 @@
155
200
  }
156
201
  }
157
202
  },
158
- "kind_collection": {
159
- "id": "#kind_collection",
203
+ "mixin_identifiers": {
204
+ "id": "#mixin_identifiers",
160
205
  "type": "object",
161
- "required": ["kinds"],
206
+ "required": ["mixins"],
162
207
  "additionalProperties": false,
163
208
  "properties": {
164
- "kinds": {
165
- "type": "array",
166
- "minItems": 1,
167
- "items": {
168
- "$ref": "#/definitions/kind"
169
- }
170
- }
209
+ "mixins": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray" }
171
210
  }
172
211
  },
173
- "mixin_collection": {
174
- "id": "#mixin_collection",
212
+ "kind_identifiers": {
213
+ "id": "#kind_identifiers",
175
214
  "type": "object",
176
- "required": ["mixins"],
215
+ "required": ["kinds"],
177
216
  "additionalProperties": false,
178
217
  "properties": {
179
- "mixins": {
180
- "type": "array",
181
- "minItems": 1,
182
- "items": {
183
- "$ref": "#/definitions/mixin"
184
- }
185
- }
218
+ "kinds": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray" }
186
219
  }
187
220
  },
188
- "action_collection": {
189
- "id": "#action_collection",
221
+ "action_identifiers": {
222
+ "id": "#action_identifiers",
190
223
  "type": "object",
191
224
  "required": ["actions"],
192
225
  "additionalProperties": false,
193
226
  "properties": {
194
- "actions": {
195
- "type": "array",
196
- "minItems": 1,
197
- "items": {
198
- "$ref": "#/definitions/action"
199
- }
200
- }
227
+ "actions": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray" }
201
228
  }
202
229
  },
203
- "attributes": {
204
- "id": "#attributes",
205
- "type": "object",
206
- "additionalProperties": {
207
- "oneOf": [
208
- { "type": "number" },
209
- { "type": "boolean" },
210
- { "type": "string" },
211
- { "type": "object" },
212
- { "type": "array" }
213
- ]
214
- }
215
- },
216
- "attribute_definition": {
217
- "id": "#attribute_definition",
230
+ "category_identifiers": {
231
+ "id": "#category_identifiers",
218
232
  "type": "object",
219
233
  "additionalProperties": false,
220
- "required": ["type", "mutable", "required"],
221
234
  "properties": {
222
- "mutable": { "type": "boolean" },
223
- "required": { "type": "boolean" },
224
- "type": { "type": "string" },
225
- "default": {
226
- "oneOf": [
227
- { "type": "number" },
228
- { "type": "string" },
229
- { "type": "boolean" },
230
- { "type": "object" },
231
- { "type": "array" }
232
- ]
233
- },
234
- "description": { "type": "string" },
235
- "pattern": { "type": "string" }
236
- }
237
- },
238
- "attribute_definitions": {
239
- "id": "#attribute_definitions",
240
- "type": "object",
241
- "additionalProperties": false,
242
- "patternProperties": {
243
- ".+": {
244
- "$ref": "#/definitions/attribute_definition"
245
- }
235
+ "mixins": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray" },
236
+ "kinds": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray" },
237
+ "actions": { "$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray" }
246
238
  }
247
239
  },
248
240
  "model": {
@@ -27,18 +27,18 @@ module Occi
27
27
  end
28
28
 
29
29
  # :nodoc:
30
- def validate_model!(json)
31
- validate! json, :model
30
+ def validate_locations!(json)
31
+ validate! json, :locations
32
32
  end
33
33
 
34
34
  # :nodoc:
35
- def validate_resource!(json)
36
- validate! json, :resource
35
+ def validate_category_identifiers!(json)
36
+ validate! json, :'category-identifiers'
37
37
  end
38
38
 
39
39
  # :nodoc:
40
- def validate_link!(json)
41
- validate! json, :link
40
+ def validate_model!(json)
41
+ validate! json, :model
42
42
  end
43
43
 
44
44
  # :nodoc:
@@ -47,28 +47,18 @@ module Occi
47
47
  end
48
48
 
49
49
  # :nodoc:
50
- def validate_entity_collection!(json)
51
- validate! json, :'entity-collection'
52
- end
53
-
54
- # :nodoc:
55
- def validate_link_collection!(json)
56
- validate! json, :'link-collection'
57
- end
58
-
59
- # :nodoc:
60
- def validate_resource_collection!(json)
61
- validate! json, :'resource-collection'
50
+ def validate_resource!(json)
51
+ validate! json, :resource
62
52
  end
63
53
 
64
54
  # :nodoc:
65
- def validate_mixin_collection!(json)
66
- validate! json, :'mixin-collection'
55
+ def validate_link!(json)
56
+ validate! json, :link
67
57
  end
68
58
 
69
59
  # :nodoc:
70
- def validate_locations!(json)
71
- validate! json, :locations
60
+ def validate_entity_collection!(json)
61
+ validate! json, :'entity-collection'
72
62
  end
73
63
 
74
64
  # :nodoc:
@@ -67,8 +67,13 @@ module Occi
67
67
  # @return [Set] set of instances
68
68
  def categories(body, _headers = nil, expectation = nil)
69
69
  expectation ||= Occi::Core::Category
70
- Json::Validator.validate_model! body
71
- Json::Category.json(body, Set.new, false).map { |c| lookup c.identifier, expectation }.to_set
70
+ Json::Validator.validate_category_identifiers! body
71
+
72
+ cats = Set.new
73
+ hsh = handle(Occi::Core::Errors::ParsingError) { JSON.parse(body) }
74
+ hsh.values.flatten.each { |cat_id| cats << lookup(cat_id, expectation) }
75
+
76
+ cats
72
77
  end
73
78
 
74
79
  # :nodoc:
@@ -79,8 +84,8 @@ module Occi
79
84
  begin
80
85
  Json::Validator.validate! body, type
81
86
  found = type
82
- rescue
83
- logger.debug "#{self.class}: Body isn't #{type}"
87
+ rescue => ex
88
+ logger.debug "#{self.class}: Body isn't #{type} - #{ex.message}"
84
89
  end
85
90
  end
86
91
  raise Occi::Core::Errors::ParsingError, "#{self.class} -> No entity sub-type instance found" unless found
@@ -3,7 +3,7 @@ module Occi
3
3
  MAJOR_VERSION = 5 # Major update constant
4
4
  MINOR_VERSION = 0 # Minor update constant
5
5
  PATCH_VERSION = 0 # Patch/Fix version constant
6
- STAGE_VERSION = 'alpha.1'.freeze # use `nil` for production releases
6
+ STAGE_VERSION = 'alpha.4'.freeze # use `nil` for production releases
7
7
 
8
8
  unless defined?(::Occi::Core::VERSION)
9
9
  VERSION = [
@@ -29,6 +29,7 @@ module Occi
29
29
  #
30
30
  # @param model [Occi::Core::Model] model to be bootstrapped
31
31
  def bootstrap!(model)
32
+ logger.debug "#{self}: Bootstrapping#{model.empty? ? ' empty' : ''} model"
32
33
  actions! model
33
34
  kinds! model
34
35
  mixins! model
@@ -66,6 +67,7 @@ module Occi
66
67
  def kinds!(model)
67
68
  attribute_definitions = attribute_definitions_for(kinds_path)
68
69
  yamls_in(kinds_path).each do |file|
70
+ logger.debug "#{self}: Loading kind from #{file.inspect}"
69
71
  model << Occi::Core::Kind.from_yaml(file, model, attribute_definitions)
70
72
  end
71
73
  end
@@ -74,6 +76,7 @@ module Occi
74
76
  def mixins!(model)
75
77
  attribute_definitions = attribute_definitions_for(mixins_path)
76
78
  yamls_in(mixins_path).each do |file|
79
+ logger.debug "#{self}: Loading mixin from #{file.inspect}"
77
80
  model << Occi::Core::Mixin.from_yaml(file, model, attribute_definitions)
78
81
  end
79
82
  end
@@ -83,6 +86,7 @@ module Occi
83
86
  # TODO: work with separate attribute definitions
84
87
  attribute_definitions = {}
85
88
  yamls_in(actions_path).each do |file|
89
+ logger.debug "#{self}: Loading action from #{file.inspect}"
86
90
  model << Occi::Core::Action.from_yaml(file, model, attribute_definitions)
87
91
  end
88
92
  end
@@ -94,6 +98,7 @@ module Occi
94
98
  attr_defs_path = File.join(categories_path, ATTRIBS)
95
99
  yamls_in(attr_defs_path).each do |file|
96
100
  name = attribute_name_from(file)
101
+ logger.debug "#{self}: Loading attribute definition for #{name.inspect} from #{file.inspect}"
97
102
  attribute_definitions[name] = Occi::Core::AttributeDefinition.from_yaml(file)
98
103
  end
99
104
 
@@ -10,6 +10,7 @@ module Occi
10
10
  # model = Occi::Infrastructure::Model.new
11
11
  # model.load_infrastructure!
12
12
  def load_infrastructure!
13
+ logger.debug "#{self.class}: Loading Infrastructure from Warehouse"
13
14
  Occi::Infrastructure::Warehouse.bootstrap! self
14
15
  self << Occi::Infrastructure::Mixins::OsTpl.new
15
16
  self << Occi::Infrastructure::Mixins::ResourceTpl.new
@@ -22,6 +23,20 @@ module Occi
22
23
  def instance_builder
23
24
  Occi::Infrastructure::InstanceBuilder.new(model: self)
24
25
  end
26
+
27
+ # Returns all mixins dependent on the base `os_tpl` mixin defined by OGF.
28
+ #
29
+ # @return [Set] set of mixins dependent on `os_tpl`
30
+ def find_os_tpls
31
+ find_dependent Occi::Infrastructure::Mixins::OsTpl.new
32
+ end
33
+
34
+ # Returns all mixins dependent on the base `resource_tpl` mixin defined by OGF.
35
+ #
36
+ # @return [Set] set of mixins dependent on `resource_tpl`
37
+ def find_resource_tpls
38
+ find_dependent Occi::Infrastructure::Mixins::ResourceTpl.new
39
+ end
25
40
  end
26
41
  end
27
42
  end
@@ -10,6 +10,7 @@ module Occi
10
10
  # model = Occi::InfrastructureExt::Model.new
11
11
  # model.load_infrastructure_ext!
12
12
  def load_infrastructure_ext!
13
+ logger.debug "#{self.class}: Loading InfrastructureExt from Warehouse"
13
14
  Occi::InfrastructureExt::Warehouse.bootstrap! self
14
15
  self << Occi::InfrastructureExt::Mixins::AvailabilityZone.new
15
16
  nil
@@ -21,6 +22,13 @@ module Occi
21
22
  def instance_builder
22
23
  Occi::InfrastructureExt::InstanceBuilder.new(model: self)
23
24
  end
25
+
26
+ # Returns all mixins dependent on the base `availability_zone` mixin defined by OGF.
27
+ #
28
+ # @return [Set] set of mixins dependent on `availability_zone`
29
+ def find_availability_zones
30
+ find_dependent Occi::InfrastructureExt::Mixins::AvailabilityZone.new
31
+ end
24
32
  end
25
33
  end
26
34
  end
data/occi-core.gemspec CHANGED
@@ -17,7 +17,6 @@ Gem::Specification.new do |gem|
17
17
  gem.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
18
  gem.require_paths = ['lib']
19
19
 
20
- gem.add_runtime_dependency 'ox', '>= 2.4', '< 3'
21
20
  gem.add_runtime_dependency 'json', '>= 1.8', '< 3'
22
21
  gem.add_runtime_dependency 'activesupport', '>= 4.0', '< 6'
23
22
  gem.add_runtime_dependency 'json-schema', '>= 2.5', '< 3'
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: 5.0.0.alpha.1
4
+ version: 5.0.0.alpha.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boris Parak
@@ -10,28 +10,8 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-05-04 00:00:00.000000000 Z
13
+ date: 2017-05-15 00:00:00.000000000 Z
14
14
  dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: ox
17
- requirement: !ruby/object:Gem::Requirement
18
- requirements:
19
- - - ">="
20
- - !ruby/object:Gem::Version
21
- version: '2.4'
22
- - - "<"
23
- - !ruby/object:Gem::Version
24
- version: '3'
25
- type: :runtime
26
- prerelease: false
27
- version_requirements: !ruby/object:Gem::Requirement
28
- requirements:
29
- - - ">="
30
- - !ruby/object:Gem::Version
31
- version: '2.4'
32
- - - "<"
33
- - !ruby/object:Gem::Version
34
- version: '3'
35
15
  - !ruby/object:Gem::Dependency
36
16
  name: json
37
17
  requirement: !ruby/object:Gem::Requirement
@@ -409,14 +389,12 @@ files:
409
389
  - lib/occi/core/parsers/json/validator.rb
410
390
  - lib/occi/core/parsers/json/validator/.gitkeep
411
391
  - lib/occi/core/parsers/json/validator/action-instance.json
392
+ - lib/occi/core/parsers/json/validator/category-identifiers.json
412
393
  - lib/occi/core/parsers/json/validator/entity-collection.json
413
- - lib/occi/core/parsers/json/validator/link-collection.json
414
394
  - lib/occi/core/parsers/json/validator/link.json
415
395
  - lib/occi/core/parsers/json/validator/locations.json
416
- - lib/occi/core/parsers/json/validator/mixin-collection.json
417
396
  - lib/occi/core/parsers/json/validator/model.json
418
397
  - lib/occi/core/parsers/json/validator/occi-schema.json
419
- - lib/occi/core/parsers/json/validator/resource-collection.json
420
398
  - lib/occi/core/parsers/json/validator/resource.json
421
399
  - lib/occi/core/parsers/json_parser.rb
422
400
  - lib/occi/core/parsers/text/.gitkeep
@@ -588,7 +566,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
588
566
  version: 1.3.1
589
567
  requirements: []
590
568
  rubyforge_project:
591
- rubygems_version: 2.6.10
569
+ rubygems_version: 2.6.8
592
570
  signing_key:
593
571
  specification_version: 4
594
572
  summary: The rOCCI toolkit
@@ -1,3 +0,0 @@
1
- {
2
- "$ref": "occi-schema.json#/definitions/link_collection"
3
- }
@@ -1,3 +0,0 @@
1
- {
2
- "$ref": "occi-schema.json#/definitions/mixin_collection"
3
- }
@@ -1,3 +0,0 @@
1
- {
2
- "$ref": "occi-schema.json#/definitions/resource_collection"
3
- }