occi-core 5.0.0.beta.15 → 5.0.0.beta.16
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a0ab29b73d64e17d3196b39205eb9fc2e2c1810
|
4
|
+
data.tar.gz: 46f3633cb5dfb7ece6df2a96c33e6f045f76c170
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe713635ebab1f64c3b3d953e0bc98b87b4e7d2120483c1307251802951ebaa3e608c06b3ee83c2cce9cac85be1353f0ad565e94246d46748b74a1b3d5acb68b
|
7
|
+
data.tar.gz: b3f9e167697889b2238a3514d6e847a4def422d7454e05001cfd0bb310777767166647f7af6fcc0b2319081171d9b440a98728c181be0b4923133fd279eaee92
|
@@ -11,10 +11,9 @@ module Occi
|
|
11
11
|
class Attributes < Base
|
12
12
|
# Typecasting lambdas
|
13
13
|
DEFAULT_LAMBDA = ->(val) { val }
|
14
|
-
STRING_LAMBDA = ->(val) { val.to_s }
|
15
14
|
TYPECASTER_HASH = {
|
16
|
-
IPAddr =>
|
17
|
-
URI =>
|
15
|
+
IPAddr => ->(val) { val.host? ? val.to_s : "#{val}/#{val.cidr_mask}" },
|
16
|
+
URI => ->(val) { val.to_s }
|
18
17
|
}.freeze
|
19
18
|
|
20
19
|
# Renders the given object to `JSON`.
|
@@ -15,7 +15,8 @@ module Occi
|
|
15
15
|
|
16
16
|
# Known primitive attribute value types
|
17
17
|
PRIMITIVE_TYPES = [String, Numeric, Integer, Float, Boolean].freeze
|
18
|
-
|
18
|
+
IP_TYPES = [IPAddr].freeze
|
19
|
+
QUOTABLE_TYPES = [URI].freeze
|
19
20
|
JSONABLE_TYPES = [Array, Hash].freeze
|
20
21
|
|
21
22
|
# Renders `object` into plain text and returns the result
|
@@ -68,18 +69,24 @@ module Occi
|
|
68
69
|
|
69
70
|
# :nodoc:
|
70
71
|
def prepare_instance_attribute_value(name, type, value)
|
71
|
-
|
72
|
-
|
72
|
+
if ancestor_match?(IP_TYPES, type)
|
73
|
+
value.host? ? "\"#{value}\"" : "\"#{value}/#{value.cidr_mask}\""
|
74
|
+
elsif ancestor_match?(QUOTABLE_TYPES, type)
|
73
75
|
"\"#{value}\""
|
74
|
-
elsif (JSONABLE_TYPES
|
76
|
+
elsif ancestor_match?(JSONABLE_TYPES, type)
|
75
77
|
value.to_json.inspect
|
76
|
-
elsif (PRIMITIVE_TYPES
|
78
|
+
elsif ancestor_match?(PRIMITIVE_TYPES, type)
|
77
79
|
value.inspect
|
78
80
|
else
|
79
81
|
raise Occi::Core::Errors::RenderingError, "Value #{value.inspect} " \
|
80
82
|
"for attribute #{name} cannot be rendered to text"
|
81
83
|
end
|
82
84
|
end
|
85
|
+
|
86
|
+
# :nodoc:
|
87
|
+
def ancestor_match?(defined_types, type)
|
88
|
+
(defined_types & type.ancestors).any?
|
89
|
+
end
|
83
90
|
end
|
84
91
|
end
|
85
92
|
end
|
data/lib/occi/core/version.rb
CHANGED
@@ -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.
|
6
|
+
STAGE_VERSION = 'beta.16'.freeze # use `nil` for production releases
|
7
7
|
|
8
8
|
unless defined?(::Occi::Core::VERSION)
|
9
9
|
VERSION = [
|
data/lib/occi/core.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
# :nodoc:
|
2
|
+
class IPAddr
|
3
|
+
AF_INET_FULL_MASK = 32
|
4
|
+
AF_INET6_FULL_MASK = 128
|
5
|
+
|
6
|
+
attr_reader :mask_addr
|
7
|
+
|
8
|
+
# Converts network mask to CIDR format.
|
9
|
+
#
|
10
|
+
# @return [Integer] CIDR representation of address mask
|
11
|
+
def cidr_mask
|
12
|
+
case family
|
13
|
+
when Socket::AF_INET
|
14
|
+
AF_INET_FULL_MASK - Math.log2((1 << AF_INET_FULL_MASK) - mask_addr).to_i
|
15
|
+
when Socket::AF_INET6
|
16
|
+
AF_INET6_FULL_MASK - Math.log2((1 << AF_INET6_FULL_MASK) - mask_addr).to_i
|
17
|
+
else
|
18
|
+
raise AddressFamilyError, 'unsupported address family'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# :nodoc:
|
23
|
+
def host?
|
24
|
+
case family
|
25
|
+
when Socket::AF_INET
|
26
|
+
cidr_mask == AF_INET_FULL_MASK
|
27
|
+
when Socket::AF_INET6
|
28
|
+
cidr_mask == AF_INET6_FULL_MASK
|
29
|
+
else
|
30
|
+
raise AddressFamilyError, 'unsupported address family'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# :nodoc:
|
35
|
+
def network?
|
36
|
+
!host?
|
37
|
+
end
|
38
|
+
end
|
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.
|
4
|
+
version: 5.0.0.beta.16
|
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-
|
13
|
+
date: 2017-08-05 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json
|
@@ -571,6 +571,7 @@ files:
|
|
571
571
|
- lib/occi/infrastructure_ext/warehouse/mixins/public_net.yml
|
572
572
|
- lib/occi/monkey_island/boolean.rb
|
573
573
|
- lib/occi/monkey_island/hash.rb
|
574
|
+
- lib/occi/monkey_island/ipaddr.rb
|
574
575
|
- occi-core.gemspec
|
575
576
|
homepage: https://github.com/EGI-FCTF/rOCCI-core
|
576
577
|
licenses:
|