occi 2.4.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +11 -7
- data/etc/model/infrastructure/compute.json +4 -11
- data/etc/model/infrastructure/ipnetwork.json +3 -6
- data/etc/model/infrastructure/ipnetworkinterface.json +3 -6
- data/etc/model/infrastructure/network.json +1 -2
- data/etc/model/infrastructure/networkinterface.json +2 -4
- data/etc/model/infrastructure/storage.json +2 -5
- data/examples/x509auth_example.rb +42 -0
- data/lib/occi/client.rb +270 -167
- data/lib/occi/collection.rb +12 -7
- data/lib/occi/core/action.rb +1 -0
- data/lib/occi/core/attribute_properties.rb +10 -3
- data/lib/occi/core/attributes.rb +10 -2
- data/lib/occi/core/category.rb +7 -0
- data/lib/occi/core/entity.rb +32 -12
- data/lib/occi/core/kind.rb +3 -0
- data/lib/occi/core/link.rb +24 -5
- data/lib/occi/core/mixin.rb +3 -0
- data/lib/occi/core/resource.rb +20 -15
- data/lib/occi/log.rb +7 -5
- data/lib/occi/model.rb +9 -5
- data/lib/occi/parser.rb +28 -2
- data/lib/occi/version.rb +1 -1
- metadata +4 -3
data/lib/occi/collection.rb
CHANGED
@@ -41,7 +41,7 @@ module OCCI
|
|
41
41
|
@kinds.empty? && @mixins.empty? && @actions.empty? && @resources.empty? && @links.empty?
|
42
42
|
end
|
43
43
|
|
44
|
-
# @return [Hashie::Mash]
|
44
|
+
# @return [Hashie::Mash] json representation
|
45
45
|
def as_json(options = { })
|
46
46
|
collection = Hashie::Mash.new
|
47
47
|
collection.kinds = @kinds.collect { |kind| kind.as_json } if @kinds.any?
|
@@ -52,13 +52,18 @@ module OCCI
|
|
52
52
|
collection
|
53
53
|
end
|
54
54
|
|
55
|
+
# @return [String] text representation
|
55
56
|
def to_text
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
raise "Only one entity allowed for rendering to plain text" if
|
60
|
-
|
61
|
-
|
57
|
+
text = ""
|
58
|
+
text << self.categories.collect { |category| category.to_text }.join("\n")
|
59
|
+
text << "\n" if self.categories.any?
|
60
|
+
raise "Only one entity allowed for rendering to plain text" if self.entities.size > 1
|
61
|
+
text << self.entities.collect {|entity| entity.to_text}.join("\n")
|
62
|
+
text
|
63
|
+
end
|
64
|
+
|
65
|
+
def inspect
|
66
|
+
JSON.pretty_generate(JSON.parse(to_json))
|
62
67
|
end
|
63
68
|
|
64
69
|
end
|
data/lib/occi/core/action.rb
CHANGED
@@ -4,6 +4,8 @@ module OCCI
|
|
4
4
|
module Core
|
5
5
|
class AttributeProperties < Hashie::Mash
|
6
6
|
|
7
|
+
# @param [Hashie::Mash] attributes
|
8
|
+
# @param [Hash] default
|
7
9
|
def initialize(attributes = nil, default = nil)
|
8
10
|
if [:Type, :Required, :Mutable, :Pattern, :Default, :Minimum, :Maximum, :Description].any? { |k| attributes.key?(k) }
|
9
11
|
attributes[:Type] ||= "string"
|
@@ -14,12 +16,10 @@ module OCCI
|
|
14
16
|
super(attributes, default)
|
15
17
|
end
|
16
18
|
|
19
|
+
# @return [Array] list of full attribute names
|
17
20
|
def combine
|
18
21
|
array = []
|
19
22
|
self.each_key do |key|
|
20
|
-
#puts "Key :#{key}"
|
21
|
-
#puts self[key].keys
|
22
|
-
#puts self[key].key? 'type'
|
23
23
|
if self[key].key? 'Type'
|
24
24
|
array << key
|
25
25
|
else
|
@@ -30,6 +30,8 @@ module OCCI
|
|
30
30
|
array
|
31
31
|
end
|
32
32
|
|
33
|
+
|
34
|
+
# @return [Hash] key value pairs of attribute names with their defaults set
|
33
35
|
def combine_with_defaults
|
34
36
|
hash = { }
|
35
37
|
self.each_key do |key|
|
@@ -56,6 +58,7 @@ module OCCI
|
|
56
58
|
end
|
57
59
|
end
|
58
60
|
|
61
|
+
# Overrides method of hashie mash to check if one of the attribute properties has been set
|
59
62
|
def method_missing(method_name, *args, &blk)
|
60
63
|
return self.[](method_name, &blk) if key?(method_name)
|
61
64
|
match = method_name.to_s.match(/(.*?)([?=!]?)$/)
|
@@ -91,6 +94,10 @@ module OCCI
|
|
91
94
|
end
|
92
95
|
end
|
93
96
|
|
97
|
+
def inspect
|
98
|
+
JSON.pretty_generate(JSON.parse(to_json))
|
99
|
+
end
|
100
|
+
|
94
101
|
end
|
95
102
|
end
|
96
103
|
end
|
data/lib/occi/core/attributes.rb
CHANGED
@@ -4,7 +4,8 @@ module OCCI
|
|
4
4
|
module Core
|
5
5
|
class Attributes < Hashie::Mash
|
6
6
|
|
7
|
-
|
7
|
+
# @return [Array] key value pair of full attribute names with their corresponding values
|
8
|
+
def combine
|
8
9
|
hash = { }
|
9
10
|
self.each_key do |key|
|
10
11
|
if self[key].kind_of? OCCI::Core::Attributes
|
@@ -16,7 +17,9 @@ module OCCI
|
|
16
17
|
hash
|
17
18
|
end
|
18
19
|
|
19
|
-
|
20
|
+
# @param [Hash] attributes key value pair of full attribute names with their corresponding values
|
21
|
+
# @return [OCCI::Core::Attributes]
|
22
|
+
def self.split(attributes)
|
20
23
|
attribute = Attributes.new
|
21
24
|
attributes.each do |name,value|
|
22
25
|
puts name
|
@@ -31,5 +34,10 @@ module OCCI
|
|
31
34
|
end
|
32
35
|
|
33
36
|
end
|
37
|
+
|
38
|
+
def inspect
|
39
|
+
JSON.pretty_generate(JSON.parse(to_json))
|
40
|
+
end
|
41
|
+
|
34
42
|
end
|
35
43
|
end
|
data/lib/occi/core/category.rb
CHANGED
@@ -34,6 +34,8 @@ module OCCI
|
|
34
34
|
false
|
35
35
|
end
|
36
36
|
|
37
|
+
# @param [Hash] options
|
38
|
+
# @return [Hashie::Mash] json representation
|
37
39
|
def as_json(options={ })
|
38
40
|
category = Hashie::Mash.new
|
39
41
|
category.scheme = @scheme if @scheme
|
@@ -43,12 +45,17 @@ module OCCI
|
|
43
45
|
category
|
44
46
|
end
|
45
47
|
|
48
|
+
# @return [String] text representation
|
46
49
|
def to_text
|
47
50
|
text = @term + ';scheme=' + @scheme.inspect + ';class=' + self.class.name.demodulize.downcase.inspect
|
48
51
|
text << ';title=' + @title.inspect if @title
|
49
52
|
text
|
50
53
|
end
|
51
54
|
|
55
|
+
def inspect
|
56
|
+
JSON.pretty_generate(JSON.parse(to_json))
|
57
|
+
end
|
58
|
+
|
52
59
|
end
|
53
60
|
end
|
54
61
|
end
|
data/lib/occi/core/entity.rb
CHANGED
@@ -39,29 +39,25 @@ module OCCI
|
|
39
39
|
def initialize(kind, mixins=nil, attributes=nil, actions=nil)
|
40
40
|
@checked = false
|
41
41
|
raise "Kind #{kind} not of type String" unless kind.kind_of? String
|
42
|
-
@kind
|
43
|
-
@mixins
|
44
|
-
@attributes
|
45
|
-
@
|
46
|
-
|
42
|
+
@kind = kind
|
43
|
+
@mixins = mixins.to_a
|
44
|
+
@attributes = OCCI::Core::Attributes.new(attributes)
|
45
|
+
@attributes.occi!.core![:id] ||= UUIDTools::UUID.random_create.to_s
|
46
|
+
@actions = actions.to_a
|
47
47
|
end
|
48
48
|
|
49
|
+
# @param [Array] mixins
|
49
50
|
def mixins=(mixins)
|
50
51
|
@checked=false
|
51
52
|
@mixins =mixins
|
52
53
|
end
|
53
54
|
|
55
|
+
# @param [OCCI::Core::Attributes] attributes
|
54
56
|
def attributes=(attributes)
|
55
57
|
@checked =false
|
56
58
|
@attributes=attributes
|
57
59
|
end
|
58
60
|
|
59
|
-
# set id for entity
|
60
|
-
# @param [UUIDTools::UUID] id
|
61
|
-
def id=(id)
|
62
|
-
@attributes.occi!.core!.id = id
|
63
|
-
end
|
64
|
-
|
65
61
|
# @return [UUIDTools::UUID] id of the entity
|
66
62
|
def id
|
67
63
|
@attributes.occi!.core!.id
|
@@ -129,12 +125,13 @@ module OCCI
|
|
129
125
|
attributes
|
130
126
|
end
|
131
127
|
|
128
|
+
# @return [true,false]
|
132
129
|
def checked?
|
133
130
|
@checked && @attributes.checked?
|
134
131
|
end
|
135
132
|
|
136
133
|
# @param [Hash] options
|
137
|
-
# @return [Hashie::Mash]
|
134
|
+
# @return [Hashie::Mash] json representation
|
138
135
|
def as_json(options={ })
|
139
136
|
entity = Hashie::Mash.new
|
140
137
|
entity.kind = @kind if @kind
|
@@ -144,6 +141,29 @@ module OCCI
|
|
144
141
|
entity
|
145
142
|
end
|
146
143
|
|
144
|
+
# @return [String] text representation
|
145
|
+
def to_text
|
146
|
+
scheme, term = self.kind.split('#')
|
147
|
+
text = term + ';scheme=' + scheme.inspect + ';class="kind"' + "\n"
|
148
|
+
@mixins.each do |mixin|
|
149
|
+
scheme, term = mixin.split('#')
|
150
|
+
text << term + ';scheme=' + scheme.inspect + ';class="mixin"' + "\n"
|
151
|
+
end
|
152
|
+
@attributes.combine.each_pair do |name, value|
|
153
|
+
name = name.inspect if name.kind_of? String
|
154
|
+
text << 'X-OCCI-Attribute: ' + name + '=' + value + "\n"
|
155
|
+
end
|
156
|
+
@actions.each do |action|
|
157
|
+
_, term = mixin.split('#')
|
158
|
+
text << 'Link: <' + self.location + '?action=' + term + '>;rel=' + action.inspect + "\n"
|
159
|
+
end
|
160
|
+
text
|
161
|
+
end
|
162
|
+
|
163
|
+
def inspect
|
164
|
+
JSON.pretty_generate(JSON.parse(to_json))
|
165
|
+
end
|
166
|
+
|
147
167
|
end
|
148
168
|
end
|
149
169
|
end
|
data/lib/occi/core/kind.rb
CHANGED
@@ -40,6 +40,8 @@ module OCCI
|
|
40
40
|
'/' + @term + '/'
|
41
41
|
end
|
42
42
|
|
43
|
+
# @param [Hash] options
|
44
|
+
# @return [Hashie::Mash] json representation
|
43
45
|
def as_json(options={ })
|
44
46
|
kind = Hashie::Mash.new
|
45
47
|
kind.related = @related if @related.any?
|
@@ -48,6 +50,7 @@ module OCCI
|
|
48
50
|
kind
|
49
51
|
end
|
50
52
|
|
53
|
+
# @return [String] text representation
|
51
54
|
def to_text
|
52
55
|
text = super
|
53
56
|
text << ';rel=' + @related.join(' ').inspect if @related.any?
|
data/lib/occi/core/link.rb
CHANGED
@@ -6,7 +6,7 @@ module OCCI
|
|
6
6
|
module Core
|
7
7
|
class Link < Entity
|
8
8
|
|
9
|
-
|
9
|
+
attr_accessor :rel
|
10
10
|
|
11
11
|
# @return [OCCI::Core::Kind] kind definition of Link type
|
12
12
|
def self.kind_definition
|
@@ -28,9 +28,17 @@ module OCCI
|
|
28
28
|
kind
|
29
29
|
end
|
30
30
|
|
31
|
+
# @param [String] kind
|
32
|
+
# @param [String] mixins
|
33
|
+
# @param [OCCI::Core::Attributes] attributes
|
34
|
+
def initialize(kind, mixins=nil, attributes=nil, actions=nil, rel=nil)
|
35
|
+
super(kind,mixins,attributes,actions)
|
36
|
+
@rel = rel
|
37
|
+
end
|
38
|
+
|
31
39
|
# @return [String] target attribute of the link
|
32
40
|
def target
|
33
|
-
self.attributes.occi!.core!.
|
41
|
+
self.attributes.occi!.core!.target
|
34
42
|
end
|
35
43
|
|
36
44
|
# set target attribute of link
|
@@ -50,14 +58,14 @@ module OCCI
|
|
50
58
|
self.attributes.occi!.core!.source = source
|
51
59
|
end
|
52
60
|
|
61
|
+
# @param [OCCI::Model] model
|
53
62
|
def check(model)
|
54
|
-
|
55
|
-
@rel = model.type_identifier if target.kind_of? OCCI::Core::Resource
|
63
|
+
raise "rel must be provided" unless @rel
|
56
64
|
super(model)
|
57
65
|
end
|
58
66
|
|
59
67
|
# @param [Hash] options
|
60
|
-
# @return [Hashie::Mash]
|
68
|
+
# @return [Hashie::Mash] json representation
|
61
69
|
def as_json(options={ })
|
62
70
|
link = Hashie::Mash.new
|
63
71
|
link.kind = @kind if @kind
|
@@ -67,6 +75,17 @@ module OCCI
|
|
67
75
|
link
|
68
76
|
end
|
69
77
|
|
78
|
+
# @return [String] text representation of link reference
|
79
|
+
def to_reference_text
|
80
|
+
OCCI::Log.debug "Test"
|
81
|
+
text = '<' + target + '>'
|
82
|
+
text << ';rel=' + @rel.inspect
|
83
|
+
text << ';self=' + self.location
|
84
|
+
text << ';category=' + @kind
|
85
|
+
@attributes.combine.each_pair { |name, value| text << name + '=' + value + ';' }
|
86
|
+
text
|
87
|
+
end
|
88
|
+
|
70
89
|
end
|
71
90
|
end
|
72
91
|
end
|
data/lib/occi/core/mixin.rb
CHANGED
@@ -25,6 +25,8 @@ module OCCI
|
|
25
25
|
'/mixins/' + @term + '/'
|
26
26
|
end
|
27
27
|
|
28
|
+
# @param [Hash] options
|
29
|
+
# @return [Hashie::Mash] json representation
|
28
30
|
def as_json(options={ })
|
29
31
|
mixin = Hashie::Mash.new
|
30
32
|
mixin.related = @related if @related.any?
|
@@ -33,6 +35,7 @@ module OCCI
|
|
33
35
|
mixin
|
34
36
|
end
|
35
37
|
|
38
|
+
# @return [String] text representation
|
36
39
|
def to_text
|
37
40
|
text = super
|
38
41
|
text << ';rel=' + @related.join(' ').inspect if @related.any?
|
data/lib/occi/core/resource.rb
CHANGED
@@ -9,11 +9,6 @@ module OCCI
|
|
9
9
|
|
10
10
|
attr_accessor :links
|
11
11
|
|
12
|
-
def initialize(kind, mixins=nil, attributes=nil, links=nil)
|
13
|
-
@links = links.to_a
|
14
|
-
super(kind, mixins, attributes)
|
15
|
-
end
|
16
|
-
|
17
12
|
# @return [OCCI::Core::Kind] kind definition of Resource type
|
18
13
|
def self.kind_definition
|
19
14
|
kind = OCCI::Core::Kind.new('http://schemas.ogf.org/occi/core#', 'resource')
|
@@ -29,9 +24,17 @@ module OCCI
|
|
29
24
|
kind
|
30
25
|
end
|
31
26
|
|
32
|
-
|
33
|
-
|
34
|
-
|
27
|
+
# @param [String] kind
|
28
|
+
# @param [Array] mixins
|
29
|
+
# @param [OCCI::Core::Attributes,Hash] attributes
|
30
|
+
# @param [Array] links
|
31
|
+
def initialize(kind, mixins=nil, attributes=nil, links=nil)
|
32
|
+
super(kind, mixins, attributes)
|
33
|
+
@links = []
|
34
|
+
links.to_a.each do |link|
|
35
|
+
link = OCCI::Core::Link.new(link.kind,link.mixins,link.attributes,link.actions,link.rel) unless link.kind_of? OCCI::Core::Link
|
36
|
+
@links << link
|
37
|
+
end
|
35
38
|
end
|
36
39
|
|
37
40
|
# set id for resource and update the the source of all links
|
@@ -52,13 +55,8 @@ module OCCI
|
|
52
55
|
self.attributes.occi!.core!.summary = summary
|
53
56
|
end
|
54
57
|
|
55
|
-
#
|
56
|
-
# @return [
|
57
|
-
def links
|
58
|
-
@links.each { |link| link.attributes.occi!.core!.source = self.location }
|
59
|
-
@links
|
60
|
-
end
|
61
|
-
|
58
|
+
# @param [Hash] options
|
59
|
+
# @return [Hashie::Mash] link as Hashie::Mash to be parsed into a JSON object
|
62
60
|
def as_json(options={ })
|
63
61
|
resource = Hashie::Mash.new
|
64
62
|
resource.links = @links if @links.any?
|
@@ -66,6 +64,13 @@ module OCCI
|
|
66
64
|
resource
|
67
65
|
end
|
68
66
|
|
67
|
+
# @return [String] text representation
|
68
|
+
def to_text
|
69
|
+
text = super
|
70
|
+
@links.each { |link| text << 'Link: ' + link.to_reference_text + "\n" }
|
71
|
+
text
|
72
|
+
end
|
73
|
+
|
69
74
|
end
|
70
75
|
end
|
71
76
|
end
|
data/lib/occi/log.rb
CHANGED
@@ -9,13 +9,13 @@ module OCCI
|
|
9
9
|
attr_reader :logger
|
10
10
|
|
11
11
|
# creates a new OCCI logger
|
12
|
-
# @param [IO,String]
|
12
|
+
# @param [IO,String] log_dev The log device. This is a filename (String) or IO object (typically +STDOUT+,
|
13
13
|
# +STDERR+, or an open file).
|
14
|
-
def initialize(
|
15
|
-
if
|
16
|
-
@logger =
|
14
|
+
def initialize(log_dev)
|
15
|
+
if log_dev.kind_of? Logger
|
16
|
+
@logger = log_dev
|
17
17
|
else
|
18
|
-
@logger = Logger.new(
|
18
|
+
@logger = Logger.new(log_dev)
|
19
19
|
end
|
20
20
|
|
21
21
|
# subscribe to log messages and send to logger
|
@@ -24,10 +24,12 @@ module OCCI
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
# @param [Logger::Severity] severity
|
27
28
|
def level=(severity)
|
28
29
|
@logger.level = severity
|
29
30
|
end
|
30
31
|
|
32
|
+
# @return [Logger::Severity]
|
31
33
|
def level
|
32
34
|
@logger.level
|
33
35
|
end
|
data/lib/occi/model.rb
CHANGED
@@ -6,11 +6,12 @@ module OCCI
|
|
6
6
|
attr_accessor :categories
|
7
7
|
attr_accessor :locations
|
8
8
|
|
9
|
+
# @param [OCCI::Core::Collection] collection
|
9
10
|
def initialize(collection=nil)
|
10
11
|
@categories = { }
|
11
12
|
@locations = { }
|
12
13
|
register_core
|
13
|
-
register_collection collection if collection
|
14
|
+
register_collection collection if collection.kind_of? OCCI::Collection
|
14
15
|
end
|
15
16
|
|
16
17
|
# register OCCI Core categories enitity, resource and link
|
@@ -49,11 +50,12 @@ module OCCI
|
|
49
50
|
collection.categories.each { |category| register category }
|
50
51
|
end
|
51
52
|
|
53
|
+
# clear all entities from all categories
|
52
54
|
def reset()
|
53
55
|
@categories.each_value.each { |category| category.entities = [] if category.respond_to? :entities }
|
54
56
|
end
|
55
57
|
|
56
|
-
#
|
58
|
+
# @param [OCCI::Core::Category] category
|
57
59
|
def register(category)
|
58
60
|
OCCI::Log.debug "### Registering category #{category.type_identifier}"
|
59
61
|
@categories[category.type_identifier] = category
|
@@ -62,7 +64,7 @@ module OCCI
|
|
62
64
|
category.model = self
|
63
65
|
end
|
64
66
|
|
65
|
-
#
|
67
|
+
# @param [OCCI::Core::Category] category
|
66
68
|
def unregister(category)
|
67
69
|
OCCI::Log.debug "### Unregistering category #{category.type_identifier}"
|
68
70
|
@categories.delete category.type_identifier
|
@@ -71,14 +73,16 @@ module OCCI
|
|
71
73
|
|
72
74
|
# Returns the category corresponding to a given type identifier
|
73
75
|
#
|
74
|
-
# @param [URI] type identifier of a category
|
76
|
+
# @param [URI] id type identifier of a category
|
77
|
+
# @return [OCCI::Core::Category]
|
75
78
|
def get_by_id(id)
|
76
79
|
@categories.fetch(id) { OCCI::Log.debug("Category with id #{id} not found"); nil }
|
77
80
|
end
|
78
81
|
|
79
82
|
# Returns the category corresponding to a given location
|
80
83
|
#
|
81
|
-
# @param [URI]
|
84
|
+
# @param [URI] location
|
85
|
+
# @return [OCCI::Core::Category]
|
82
86
|
def get_by_location(location)
|
83
87
|
id = @locations.fetch(location) { OCCI::Log.debug("Category with location #{location} not found"); nil }
|
84
88
|
get_by_id id
|