occi-core 5.0.0.beta.14 → 5.0.0.beta.15

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: 83d306e26641639a0b848992726e04c14f787cdc
4
- data.tar.gz: 20c6d620598f5826f1be8fdd5b983a7139aa2e40
3
+ metadata.gz: 56685f3371c8b94f29e3f4d87d12fda0a916250b
4
+ data.tar.gz: 8c41a4eeeda72c459f6041995728ca4690d1901a
5
5
  SHA512:
6
- metadata.gz: f7e66f446ce76219515c3ba7b96a90356986ea55d00125c86b718a516dd392d27addce2539f19ca02feda0c3867d06e57933316815adf3d2988777d15aaae189
7
- data.tar.gz: 1f1eb32f15a178c930d59b7b288a1bdd02f4623753e837d80e450318b8c7053807cf3d683972a0db7f169d09043ca67001c38d486a704b450086ac4000ee738d
6
+ metadata.gz: 2b90567b813f12511e7b6b3199a8b05c78ba42f9c9603c0f0bcdf668ac2156ebe1d6ec746577181d034f8e4dde88f8188253368fd4a9af646c8e4135f10dbade
7
+ data.tar.gz: 94f29c71c5866fc05497a1fc2bfd903414be0694f90d4ee362c6a28357748a3a34d63113cf13ceaf0fce44e6a6cf77bac4c93967362172a0125578292bccee0d
data/.rubocop.yml CHANGED
@@ -1,12 +1,5 @@
1
- # This configuration was generated by
2
- # `rubocop --auto-gen-config`
3
- # on 2016-05-23 13:39:50 +0200 using RuboCop version 0.40.0.
4
- # The point is for the user to remove these configuration records
5
- # one by one as the offenses are removed from the code base.
6
- # Note that changes in the inspected code, or installation of new
7
- # versions of RuboCop, may require this file to be generated again.
8
-
9
1
  require: rubocop-rspec
2
+ inherit_from: .rubocop_todo.yml
10
3
 
11
4
  Metrics/ModuleLength:
12
5
  Exclude:
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,4 @@
1
+ Style/RescueModifier:
2
+ Exclude:
3
+ - 'lib/occi/core/parsers/json/entity.rb'
4
+ - 'lib/occi/core/parsers/text/entity.rb'
@@ -8,5 +8,5 @@ X-OCCI-Attribute: occi.compute.state="active"
8
8
  Link: </compute/89878?action=stop>;rel="http://schemas.ogf.org/occi/infrastructure/compute/action#stop"
9
9
  Link: </compute/89878?action=restart>;rel="http://schemas.ogf.org/occi/infrastructure/compute/action#restart"
10
10
  Link: </compute/89878?action=suspend>;rel="http://schemas.ogf.org/occi/infrastructure/compute/action#suspend"
11
- Link: </storage/5401>;rel="http://schemas.ogf.org/occi/infrastructure#storage";self="/link/storagelink/compute_89878_disk_0";category="http://schemas.ogf.org/occi/infrastructure#storagelink";occi.core.id="compute_89878_disk_0";occi.core.title="38d42ca1-f4e9-5b5c-98de-37eb2d26301a";occi.core.target="/storage/5401";occi.core.source="/compute/89878";occi.storagelink.deviceid="/dev/vda";occi.storagelink.state="active"
12
- Link: </network/24>;rel="http://schemas.ogf.org/occi/infrastructure#network";self="/link/networkinterface/compute_89878_nic_0";category="http://schemas.ogf.org/occi/infrastructure#networkinterface http://schemas.ogf.org/occi/infrastructure/networkinterface#ipnetworkinterface";occi.core.id="compute_89878_nic_0";occi.core.title="public";occi.core.target="/network/24";occi.core.source="/compute/89878";occi.networkinterface.interface="eth0";occi.networkinterface.mac="02:00:93:e4:f2:a3";occi.networkinterface.state="active";occi.networkinterface.address="172.16.0.1"
11
+ Link: </storage/5401>;rel="http://schemas.ogf.org/occi/infrastructure#storage";self="/storagelink/compute_89878_disk_0";category="http://schemas.ogf.org/occi/infrastructure#storagelink";occi.core.id="compute_89878_disk_0";occi.core.title="38d42ca1-f4e9-5b5c-98de-37eb2d26301a";occi.core.target="/storage/5401";occi.core.source="/compute/89878";occi.storagelink.deviceid="/dev/vda";occi.storagelink.state="active"
12
+ Link: </network/24>;rel="http://schemas.ogf.org/occi/infrastructure#network";self="/networkinterface/compute_89878_nic_0";category="http://schemas.ogf.org/occi/infrastructure#networkinterface http://schemas.ogf.org/occi/infrastructure/networkinterface#ipnetworkinterface";occi.core.id="compute_89878_nic_0";occi.core.title="public";occi.core.target="/network/24";occi.core.source="/compute/89878";occi.networkinterface.interface="eth0";occi.networkinterface.mac="02:00:93:e4:f2:a3";occi.networkinterface.state="active";occi.networkinterface.address="172.16.0.1"
@@ -420,7 +420,7 @@
420
420
  "type": "string"
421
421
  }
422
422
  },
423
- "location": "/link/networkinterface/",
423
+ "location": "/networkinterface/",
424
424
  "parent": "http://schemas.ogf.org/occi/core#link",
425
425
  "scheme": "http://schemas.ogf.org/occi/infrastructure#",
426
426
  "term": "networkinterface",
@@ -531,7 +531,7 @@
531
531
  "type": "string"
532
532
  }
533
533
  },
534
- "location": "/link/storagelink/",
534
+ "location": "/storagelink/",
535
535
  "parent": "http://schemas.ogf.org/occi/core#link",
536
536
  "scheme": "http://schemas.ogf.org/occi/infrastructure#",
537
537
  "term": "storagelink",
@@ -693,7 +693,7 @@
693
693
  "type": "string"
694
694
  }
695
695
  },
696
- "location": "/link/securitygrouplink/",
696
+ "location": "/securitygrouplink/",
697
697
  "parent": "http://schemas.ogf.org/occi/core#link",
698
698
  "scheme": "http://schemas.ogf.org/occi/infrastructure#",
699
699
  "term": "securitygrouplink",
@@ -4,8 +4,8 @@ Category: link;scheme="http://schemas.ogf.org/occi/core#";class="kind";title="li
4
4
  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 required} 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"
5
5
  Category: storage;scheme="http://schemas.ogf.org/occi/infrastructure#";class="kind";title="storage resource";rel="http://schemas.ogf.org/occi/core#resource";location="/storage/";attributes="occi.core.id{immutable required} occi.core.title occi.core.summary occi.storage.size occi.storage.state";actions="http://schemas.ogf.org/occi/infrastructure/storage/action#online http://schemas.ogf.org/occi/infrastructure/storage/action#offline http://schemas.ogf.org/occi/infrastructure/storage/action#backup http://schemas.ogf.org/occi/infrastructure/storage/action#snapshot http://schemas.ogf.org/occi/infrastructure/storage/action#resize"
6
6
  Category: network;scheme="http://schemas.ogf.org/occi/infrastructure#";class="kind";title="network resource";rel="http://schemas.ogf.org/occi/core#resource";location="/network/";attributes="occi.core.id{immutable required} occi.core.title occi.core.summary occi.network.vlan occi.network.label occi.network.state{immutable}";actions="http://schemas.ogf.org/occi/infrastructure/network/action#up http://schemas.ogf.org/occi/infrastructure/network/action#down"
7
- Category: networkinterface;scheme="http://schemas.ogf.org/occi/infrastructure#";class="kind";title="networkinterface link";rel="http://schemas.ogf.org/occi/core#link";location="/link/networkinterface/";attributes="occi.core.id{immutable required} occi.core.title occi.core.target occi.core.source{required} occi.networkinterface.interface{immutable} occi.networkinterface.mac occi.networkinterface.state{immutable}";actions="http://schemas.ogf.org/occi/infrastructure/networkinterface/action#up http://schemas.ogf.org/occi/infrastructure/networkinterface/action#down"
8
- Category: storagelink;scheme="http://schemas.ogf.org/occi/infrastructure#";class="kind";title="storage link";rel="http://schemas.ogf.org/occi/core#link";location="/link/storagelink/";attributes="occi.core.id{immutable required} occi.core.title occi.core.target occi.core.source{required} occi.storagelink.deviceid occi.storagelink.mountpoint occi.storagelink.state{immutable}";actions="http://schemas.ogf.org/occi/infrastructure/storagelink/action#online http://schemas.ogf.org/occi/infrastructure/storagelink/action#offline"
7
+ Category: networkinterface;scheme="http://schemas.ogf.org/occi/infrastructure#";class="kind";title="networkinterface link";rel="http://schemas.ogf.org/occi/core#link";location="/networkinterface/";attributes="occi.core.id{immutable required} occi.core.title occi.core.target occi.core.source{required} occi.networkinterface.interface{immutable} occi.networkinterface.mac occi.networkinterface.state{immutable}";actions="http://schemas.ogf.org/occi/infrastructure/networkinterface/action#up http://schemas.ogf.org/occi/infrastructure/networkinterface/action#down"
8
+ Category: storagelink;scheme="http://schemas.ogf.org/occi/infrastructure#";class="kind";title="storage link";rel="http://schemas.ogf.org/occi/core#link";location="/storagelink/";attributes="occi.core.id{immutable required} occi.core.title occi.core.target occi.core.source{required} occi.storagelink.deviceid occi.storagelink.mountpoint occi.storagelink.state{immutable}";actions="http://schemas.ogf.org/occi/infrastructure/storagelink/action#online http://schemas.ogf.org/occi/infrastructure/storagelink/action#offline"
9
9
  Category: resource_tpl;scheme="http://schemas.ogf.org/occi/infrastructure#";class="mixin";title="resource template";location="/mixin/resource_tpl/"
10
10
  Category: os_tpl;scheme="http://schemas.ogf.org/occi/infrastructure#";class="mixin";title="operating system template";location="/mixin/os_tpl/"
11
11
  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"
@@ -22,13 +22,13 @@ module Occi
22
22
  include Helpers::InstanceAttributesAccessor
23
23
  include Helpers::ArgumentValidator
24
24
  include Helpers::InstanceAttributeResetter
25
+ include Helpers::MixinSelector
25
26
 
26
27
  attr_accessor :kind, :actions, :attributes, :mixins
27
28
  attr_writer :location
28
29
 
29
30
  ERRORS = [
30
- Occi::Core::Errors::AttributeValidationError,
31
- Occi::Core::Errors::AttributeDefinitionError,
31
+ Occi::Core::Errors::AttributeValidationError, Occi::Core::Errors::AttributeDefinitionError,
32
32
  Occi::Core::Errors::InstanceValidationError
33
33
  ].freeze
34
34
 
@@ -0,0 +1,11 @@
1
+ module Occi
2
+ module Core
3
+ module Errors
4
+ # Custom error class indicating look-up failures on
5
+ # instances.
6
+ #
7
+ # @author Boris Parak <parak@cesnet.cz>
8
+ class InstanceLookupError < StandardError; end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,40 @@
1
+ module Occi
2
+ module Core
3
+ module Helpers
4
+ # Introduces mixin-based helpers to every receiver
5
+ # class. Provides methods to access mixin sub-sets
6
+ # defined by dependencies.
7
+ #
8
+ # @author Boris Parak <parak@cesnet.cz>
9
+ module MixinSelector
10
+ # Selects a set of mixins defined by a common dependence. This dependence
11
+ # must be provided as `filter` and be an instance of `Occi::Core::Mixin` or
12
+ # its subclass.
13
+ #
14
+ # @param filter [Occi::Core::Mixin] mixin to filter by
15
+ # @return [Set] found mixins
16
+ def select_mixins(filter)
17
+ Set.new(mixins.select { |m| m.depends?(filter) })
18
+ end
19
+
20
+ # Selects at most one mixin defined by the given dependence. This dependence
21
+ # must be provided as `filter` and be an instance of `Occi::Core::Mixin` or
22
+ # its subclass.
23
+ #
24
+ # @param filter [Occi::Core::Mixin] mixin to filter by
25
+ # @return [Occi::Core::Mixin] found mixin
26
+ # @return [NilClass] if such mixin is not found
27
+ def select_mixin(filter)
28
+ mixins.detect { |m| m.depends?(filter) }
29
+ end
30
+
31
+ # Selects exactly one mixin or raises an error.
32
+ # @see `select_mixin`
33
+ def select_mixin!(filter)
34
+ select_mixin(filter) \
35
+ || raise(Occi::Core::Errors::InstanceLookupError, "Mixin dependent on #{filter} not found")
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -25,8 +25,8 @@ module Occi
25
25
  TYPECASTER_HASH = {
26
26
  IPAddr => ->(val) { IPAddr.new val },
27
27
  URI => ->(val) { URI.parse val },
28
- Float => ->(val) { val.to_f },
29
- Integer => ->(val) { val.to_i }
28
+ Float => ->(val) { Float(val) rescue raise(Occi::Core::Errors::ParsingError, "Wrong value #{val}") },
29
+ Integer => ->(val) { Integer(val) rescue raise(Occi::Core::Errors::ParsingError, "Wrong value #{val}") }
30
30
  }.freeze
31
31
 
32
32
  attr_reader :model
@@ -24,7 +24,7 @@ module Occi
24
24
  # Typecasting lambdas
25
25
  DEFAULT_LAMBDA = ->(val) { raise "#{self} -> Cannot typecast #{val.inspect} to an unknown type" }
26
26
 
27
- FLOAT_LAMBDA = ->(val) { val.to_f }
27
+ FLOAT_LAMBDA = ->(val) { Float(val) rescue raise(Occi::Core::Errors::ParsingError, "Wrong value #{val}") }
28
28
  JSON_LAMBDA = ->(val) { JSON.parse(val.gsub('\"', '"')) }
29
29
 
30
30
  TYPECASTER_HASH = {
@@ -33,7 +33,7 @@ module Occi
33
33
  String => ->(val) { val },
34
34
  Float => FLOAT_LAMBDA,
35
35
  Numeric => FLOAT_LAMBDA,
36
- Integer => ->(val) { val.to_i },
36
+ Integer => ->(val) { Integer(val) rescue raise(Occi::Core::Errors::ParsingError, "Wrong value #{val}") },
37
37
  Boolean => ->(val) { val.casecmp('true') || val.casecmp('yes') },
38
38
  Array => JSON_LAMBDA,
39
39
  Hash => JSON_LAMBDA
@@ -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 = 'beta.14'.freeze # use `nil` for production releases
6
+ STAGE_VERSION = 'beta.15'.freeze # use `nil` for production releases
7
7
 
8
8
  unless defined?(::Occi::Core::VERSION)
9
9
  VERSION = [
@@ -3,7 +3,7 @@ term: networkinterface
3
3
  schema: http://schemas.ogf.org/occi/infrastructure#
4
4
  title: OCCI Infrastructure NetworkInterface
5
5
  parent: http://schemas.ogf.org/occi/core#link
6
- location: /link/networkinterface/
6
+ location: /networkinterface/
7
7
  attributes:
8
8
  - occi.networkinterface.interface
9
9
  - occi.networkinterface.mac
@@ -3,7 +3,7 @@ term: storagelink
3
3
  schema: http://schemas.ogf.org/occi/infrastructure#
4
4
  title: OCCI Infrastructure StorageLink
5
5
  parent: http://schemas.ogf.org/occi/core#link
6
- location: /link/storagelink/
6
+ location: /storagelink/
7
7
  attributes:
8
8
  - occi.storagelink.deviceid
9
9
  - occi.storagelink.mountpoint
@@ -3,7 +3,7 @@ term: securitygrouplink
3
3
  schema: http://schemas.ogf.org/occi/infrastructure#
4
4
  title: OCCI Infrastructure Security Group link
5
5
  parent: http://schemas.ogf.org/occi/core#link
6
- location: /link/securitygrouplink/
6
+ location: /securitygrouplink/
7
7
  attributes:
8
8
  - occi.securitygrouplink.state
9
9
  - occi.securitygrouplink.state.message
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.beta.14
4
+ version: 5.0.0.beta.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boris Parak
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-08-02 00:00:00.000000000 Z
13
+ date: 2017-08-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
@@ -306,6 +306,7 @@ files:
306
306
  - ".gitignore"
307
307
  - ".rspec"
308
308
  - ".rubocop.yml"
309
+ - ".rubocop_todo.yml"
309
310
  - ".travis.yml"
310
311
  - AUTHORS
311
312
  - CHANGELOG.md
@@ -352,6 +353,7 @@ files:
352
353
  - lib/occi/core/errors/attribute_validation_error.rb
353
354
  - lib/occi/core/errors/category_validation_error.rb
354
355
  - lib/occi/core/errors/collection_lookup_error.rb
356
+ - lib/occi/core/errors/instance_lookup_error.rb
355
357
  - lib/occi/core/errors/instance_validation_error.rb
356
358
  - lib/occi/core/errors/location_validation_error.rb
357
359
  - lib/occi/core/errors/mandatory_argument_error.rb
@@ -371,6 +373,7 @@ files:
371
373
  - lib/occi/core/helpers/instance_attribute_resetter.rb
372
374
  - lib/occi/core/helpers/instance_attributes_accessor.rb
373
375
  - lib/occi/core/helpers/locatable.rb
376
+ - lib/occi/core/helpers/mixin_selector.rb
374
377
  - lib/occi/core/helpers/parser_dereferencer.rb
375
378
  - lib/occi/core/helpers/raw_json_parser.rb
376
379
  - lib/occi/core/helpers/renderable.rb