occi-core 4.0.0.alpha.3 → 4.0.0.alpha.4
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 +22 -9
- data/lib/occi/core/category.rb +21 -108
- data/lib/occi/core/dependencies.rb +7 -0
- data/lib/occi/core/kind.rb +96 -17
- data/lib/occi/core/kinds.rb +1 -1
- data/lib/occi/core/link.rb +2 -2
- data/lib/occi/core/mixin.rb +28 -12
- data/lib/occi/core/mixins.rb +1 -8
- data/lib/occi/core/resource.rb +1 -1
- data/lib/occi/core.rb +1 -1
- data/lib/occi/infrastructure/compute.rb +1 -1
- data/lib/occi/infrastructure/network/ipnetwork.rb +3 -2
- data/lib/occi/infrastructure/network.rb +1 -1
- data/lib/occi/infrastructure/networkinterface/ipnetworkinterface.rb +3 -2
- data/lib/occi/infrastructure/networkinterface.rb +1 -1
- data/lib/occi/infrastructure/storage.rb +1 -1
- data/lib/occi/infrastructure/storagelink.rb +1 -1
- data/lib/occi/parser/json.rb +2 -2
- data/lib/occi/version.rb +1 -1
- data/spec/occi/core/category_spec.rb +25 -23
- data/spec/occi/core/kind_spec.rb +44 -0
- data/spec/occi/model_spec.rb +2 -1
- data/spec/occi/parser/text_spec.rb +2 -2
- metadata +4 -3
- data/lib/occi/core/related.rb +0 -7
data/README.md
CHANGED
@@ -14,8 +14,7 @@ Ruby
|
|
14
14
|
|
15
15
|
The following setup is recommended
|
16
16
|
|
17
|
-
*
|
18
|
-
* Ruby 1.9.3
|
17
|
+
* Ruby 1.9.3+
|
19
18
|
* RubyGems installed
|
20
19
|
|
21
20
|
The following libraries / packages may be required to use rOCCI
|
@@ -51,10 +50,15 @@ To build and install the bleeding edge version from master
|
|
51
50
|
git clone git://github.com/gwdg/rOCCI-core.git
|
52
51
|
cd rOCCI-core
|
53
52
|
rvm install ruby-1.9.3
|
54
|
-
|
53
|
+
gem install bundler
|
55
54
|
bundle install
|
56
55
|
rake test
|
57
56
|
|
57
|
+
Documentation
|
58
|
+
-------------
|
59
|
+
|
60
|
+
[Code documentation can be found on RubyDoc.info](rubydoc.info/github/gwdg/rOCCI-core).
|
61
|
+
|
58
62
|
Usage
|
59
63
|
-----
|
60
64
|
#### Logging
|
@@ -114,12 +118,12 @@ Currently only the following entries of OVF files are parsed
|
|
114
118
|
* Disk in the DiskSection
|
115
119
|
* Network in the NetworkSection
|
116
120
|
* In the VirutalSystemSection:
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
121
|
+
* Info
|
122
|
+
* in the VirtualHardwareSection the items regarding
|
123
|
+
* Processor
|
124
|
+
* Memory
|
125
|
+
* Ethernet Adapter
|
126
|
+
* Parallel port
|
123
127
|
|
124
128
|
### Using the OCCI model
|
125
129
|
|
@@ -128,6 +132,15 @@ The occi-core gem includes all OCCI Core classes necessary to handly arbitrary O
|
|
128
132
|
Changelog
|
129
133
|
---------
|
130
134
|
|
135
|
+
### Version 4.0
|
136
|
+
* introduced compatibility mode (for OCCI-OS, on by default)
|
137
|
+
* introduced new attribute handling for resources
|
138
|
+
* completely rewrote OCCI parser
|
139
|
+
* improved action and mixin handling
|
140
|
+
* aligned with latest draft of OCCI Core and OCCI JSON specification
|
141
|
+
* split the code into rOCCI-core, rOCCI-api and rOCCI-cli
|
142
|
+
* internal changes, refactoring and some bugfixes
|
143
|
+
|
131
144
|
### Version 3.1
|
132
145
|
* added basic OS Keystone support
|
133
146
|
* added support for PKCS12 credentials for X.509 authN
|
data/lib/occi/core/category.rb
CHANGED
@@ -6,18 +6,15 @@ module Occi
|
|
6
6
|
|
7
7
|
attr_accessor :scheme, :term, :title, :attributes, :model
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
# @param [String ] scheme
|
14
|
-
# @param [String] term
|
15
|
-
# @param [String] title
|
16
|
-
# @param [Hash] attributes
|
9
|
+
# @param scheme [String] The categorisation scheme.
|
10
|
+
# @param term [String] Unique identifier of the Category instance within the categorisation scheme.
|
11
|
+
# @param title [String] The display name of an instance.
|
12
|
+
# @param attributes [Occi::Core::Attributes,Hash] Set of Attribute instances.
|
17
13
|
def initialize(scheme='http://schemas.ogf.org/occi/core#',
|
18
14
|
term='category',
|
19
15
|
title=nil,
|
20
16
|
attributes=Occi::Core::Attributes.new)
|
17
|
+
scheme += '#' unless scheme.end_with? '#'
|
21
18
|
@scheme = scheme
|
22
19
|
@term = term
|
23
20
|
@title = title
|
@@ -29,138 +26,54 @@ module Occi
|
|
29
26
|
end
|
30
27
|
end
|
31
28
|
|
32
|
-
|
33
|
-
# @param [String] scheme
|
34
|
-
# @param [String] term
|
35
|
-
# @param [Array] related
|
36
|
-
# @return [Class] ruby class with scheme as namespace, term as name and related kind as super class
|
37
|
-
def self.get_class(scheme, term, related=['http://schemas.ogf.org/occi/core#entity'])
|
38
|
-
related = related.to_a.flatten
|
39
|
-
scheme += '#' unless scheme.end_with? '#'
|
40
|
-
|
41
|
-
if related.first.to_s == 'http://schemas.ogf.org/occi/core#entity' or related.first.nil?
|
42
|
-
parent = Occi::Core::Entity
|
43
|
-
elsif related.first.kind_of? Occi::Core::Kind
|
44
|
-
parent = related.first.entity_type
|
45
|
-
elsif related.first.kind_of? Occi::Core::Mixin
|
46
|
-
parent = related.first.class
|
47
|
-
else
|
48
|
-
related_scheme, related_term = related.first.to_s.split '#'
|
49
|
-
parent = self.get_class related_scheme, related_term
|
50
|
-
end
|
51
|
-
|
52
|
-
uri = URI.parse(scheme)
|
53
|
-
|
54
|
-
namespace = if uri.host == 'schemas.ogf.org'
|
55
|
-
uri.path.reverse.chomp('/').reverse.split('/')
|
56
|
-
else
|
57
|
-
uri.host.split('.').reverse + uri.path.reverse.chomp('/').reverse.split('/')
|
58
|
-
end
|
59
|
-
|
60
|
-
namespace = namespace.inject(Object) do |mod, name|
|
61
|
-
if mod.constants.collect { |sym| sym.to_s }.include? name.capitalize
|
62
|
-
mod.const_get name.capitalize
|
63
|
-
else
|
64
|
-
mod.const_set name.capitalize, Module.new
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
class_name = self.sanitize_term_before_classify(term).classify
|
69
|
-
if namespace.const_defined? class_name
|
70
|
-
klass = namespace.const_get class_name
|
71
|
-
return klass.mixin if klass.respond_to? :mixin
|
72
|
-
unless klass.ancestors.include? Occi::Core::Entity or klass.ancestors.include? Occi::Core::Category
|
73
|
-
raise "OCCI Kind with type identifier #{scheme + term} could not be created as the corresponding class #{klass.to_s} already exists and is not derived from Occi::Core::Entity"
|
74
|
-
end
|
75
|
-
else
|
76
|
-
klass = namespace.const_set class_name, Class.new(parent)
|
77
|
-
klass.kind = Occi::Core::Kind.new scheme, term, nil, {}, related unless parent.ancestors.include? Occi::Core::Category
|
78
|
-
end
|
79
|
-
|
80
|
-
klass
|
81
|
-
end
|
82
|
-
|
83
|
-
# @param [Occi::Model] model
|
84
|
-
def model=(model)
|
85
|
-
@related.model=model if @related
|
86
|
-
end
|
87
|
-
|
88
|
-
# @return [String] Type identifier of the category
|
29
|
+
# @return [String] Type identifier of the Category.
|
89
30
|
def type_identifier
|
90
|
-
|
31
|
+
self.scheme + self.term
|
91
32
|
end
|
92
33
|
|
93
|
-
#
|
94
|
-
#
|
95
|
-
# if it is included in @related or
|
96
|
-
# if it is the category itself
|
97
|
-
#
|
98
|
-
# @param [String, Category] category Related Category or its type identifier
|
99
|
-
# @return [true,false] true if category is related to category_id else false
|
100
|
-
def related_to?(category)
|
101
|
-
if @related
|
102
|
-
self.related.each do |cat|
|
103
|
-
return true if cat.to_s == category.to_s
|
104
|
-
end
|
105
|
-
return true if self.to_s == category.to_s
|
106
|
-
end
|
107
|
-
false
|
108
|
-
end
|
109
|
-
|
110
|
-
# @param [Hash] options
|
111
|
-
# @return [Hashie::Mash] json representation
|
34
|
+
# @param options [Hash]
|
35
|
+
# @return [Hashie::Mash] JSON representation of Category.
|
112
36
|
def as_json(options={})
|
113
37
|
category = Hashie::Mash.new
|
114
|
-
category.scheme =
|
115
|
-
category.term =
|
116
|
-
category.title =
|
117
|
-
category.attributes =
|
38
|
+
category.scheme = self.scheme
|
39
|
+
category.term = self.term
|
40
|
+
category.title = self.title if self.title
|
41
|
+
category.attributes = self.attributes if self.attributes.any?
|
118
42
|
category
|
119
43
|
end
|
120
44
|
|
121
|
-
# @return [String]
|
45
|
+
# @return [String] Short text representation of the Category.
|
122
46
|
def to_string_short
|
123
|
-
|
47
|
+
self.term + ';scheme=' + self.scheme.inspect + ';class=' + self.class.name.demodulize.downcase.inspect
|
124
48
|
end
|
125
49
|
|
126
|
-
# @return [String]
|
50
|
+
# @return [String] Full text representation of the Category.
|
127
51
|
def to_string
|
128
52
|
string = self.to_string_short
|
129
|
-
string << ';title=' +
|
53
|
+
string << ';title=' + self.title.inspect if self.title
|
130
54
|
string
|
131
55
|
end
|
132
56
|
|
133
|
-
# @return [String]
|
57
|
+
# @return [String] Text representation of the Category.
|
134
58
|
def to_text
|
135
59
|
'Category: ' + self.to_string
|
136
60
|
end
|
137
61
|
|
138
|
-
# @return [Hash]
|
62
|
+
# @return [Hash] Hash containing the HTTP headers of the text/occi rendering.
|
139
63
|
def to_header
|
140
64
|
{:Category => self.to_string}
|
141
65
|
end
|
142
66
|
|
143
|
-
# @return [NilClass]
|
67
|
+
# @return [NilClass] Returns nil as Category itself does not have a location.
|
144
68
|
def location
|
145
69
|
nil # not implemented
|
146
70
|
end
|
147
71
|
|
72
|
+
# @return [String] Type Identififier of the Category.
|
148
73
|
def to_s
|
149
74
|
self.type_identifier
|
150
75
|
end
|
151
76
|
|
152
|
-
private
|
153
|
-
|
154
|
-
# Relaxed parser rules require additional checks on terms.
|
155
|
-
# TODO: a better solution?
|
156
|
-
# TODO: check for more characters
|
157
|
-
def self.sanitize_term_before_classify(term)
|
158
|
-
sanitized = term.downcase.gsub(/[\s\(\)\.\{\}\-;,\\\/\?\!\|\*\<\>]/, '_').gsub(/_+/, '_').chomp('_').reverse.chomp('_').reverse
|
159
|
-
sanitized = "uuid_#{sanitized}" if sanitized.match(/^[0-9]/)
|
160
|
-
|
161
|
-
sanitized
|
162
|
-
end
|
163
|
-
|
164
77
|
end
|
165
78
|
end
|
166
79
|
end
|
data/lib/occi/core/kind.rb
CHANGED
@@ -2,43 +2,110 @@ module Occi
|
|
2
2
|
module Core
|
3
3
|
class Kind < Occi::Core::Category
|
4
4
|
|
5
|
-
attr_accessor :entities, :
|
6
|
-
|
7
|
-
# @param [String ] scheme
|
8
|
-
# @param [String]
|
9
|
-
# @param [String]
|
10
|
-
# @param [
|
11
|
-
# @param [Array]
|
12
|
-
# @param [
|
5
|
+
attr_accessor :entities, :parent, :actions, :location
|
6
|
+
|
7
|
+
# @param scheme [String ] The categorisation scheme.
|
8
|
+
# @param term [String] Unique identifier of the Kind instance within the categorisation scheme.
|
9
|
+
# @param title [String] The display name of an instance.
|
10
|
+
# @param parent [Occi::Core::Kind,String] Another Kind instance which this Kind relates to.
|
11
|
+
# @param actions [Occi::Core::Actions,Array] Set of Action instances defined by the Kind instance.
|
12
|
+
# @param location [String] Location of the Kind instance.
|
13
13
|
def initialize(scheme='http://schemas.ogf.org/occi/core#',
|
14
14
|
term='kind',
|
15
15
|
title=nil,
|
16
16
|
attributes=Occi::Core::Attributes.new,
|
17
|
-
|
17
|
+
parent=nil,
|
18
18
|
actions=Occi::Core::Actions.new,
|
19
19
|
location=nil)
|
20
20
|
super(scheme, term, title, attributes)
|
21
|
-
@
|
21
|
+
@parent = [parent].flatten.first
|
22
22
|
@actions = Occi::Core::Actions.new(actions)
|
23
23
|
@entities = Occi::Core::Entities.new
|
24
24
|
location.blank? ? @location = '/' + term + '/' : @location = location
|
25
25
|
end
|
26
26
|
|
27
|
+
# @param scheme [String] The categorisation scheme.
|
28
|
+
# @param term [String] Unique identifier of the Category instance within the categorisation scheme.
|
29
|
+
# @param parent [Array] Another Kind instance which this Kind relates to.
|
30
|
+
# @return [Class] Ruby class with scheme as namespace, term as name and parent kind as super class.
|
31
|
+
def self.get_class(scheme, term, parent=Occi::Core::Entity.kind)
|
32
|
+
parent ||= Occi::Core::Entity.kind
|
33
|
+
if parent.kind_of? Array
|
34
|
+
parent = parent.first
|
35
|
+
end
|
36
|
+
if parent.to_s == 'http://schemas.ogf.org/occi/core#entity'
|
37
|
+
parent = Occi::Core::Entity.kind
|
38
|
+
elsif parent.kind_of? Occi::Core::Kind
|
39
|
+
parent = parent
|
40
|
+
else
|
41
|
+
parent = self.get_class(*parent.to_s.split('#')).kind
|
42
|
+
end
|
43
|
+
|
44
|
+
unless scheme.end_with? '#'
|
45
|
+
scheme += '#'
|
46
|
+
end
|
47
|
+
|
48
|
+
uri = URI.parse(scheme)
|
49
|
+
|
50
|
+
if uri.host == 'schemas.ogf.org'
|
51
|
+
namespace = uri.path.reverse.chomp('/').reverse.split('/')
|
52
|
+
else
|
53
|
+
namespace = uri.host.split('.').reverse + uri.path.reverse.chomp('/').reverse.split('/')
|
54
|
+
end
|
55
|
+
namespace.inject(Object) do |mod, name|
|
56
|
+
if mod.constants.collect { |sym| sym.to_s }.include? name.capitalize
|
57
|
+
namespace = mod.const_get name.capitalize
|
58
|
+
else
|
59
|
+
namespace = mod.const_set name.capitalize, Module.new
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class_name = self.sanitize_term_before_classify(term).classify
|
64
|
+
if namespace.const_defined? class_name
|
65
|
+
klass = namespace.const_get class_name
|
66
|
+
unless klass.ancestors.include? Occi::Core::Entity
|
67
|
+
raise "OCCI Kind with type identifier #{scheme + term} could not be created as the corresponding class #{klass.to_s} already exists and is not derived from Occi::Core::Entity"
|
68
|
+
end
|
69
|
+
else
|
70
|
+
klass = namespace.const_set class_name, Class.new(parent.entity_type)
|
71
|
+
klass.kind = Occi::Core::Kind.new scheme=scheme,
|
72
|
+
term=term,
|
73
|
+
title=nil,
|
74
|
+
attributes={},
|
75
|
+
parent=parent
|
76
|
+
end
|
77
|
+
|
78
|
+
klass
|
79
|
+
end
|
80
|
+
|
81
|
+
# Check if this Kind instance is related to another Kind instance.
|
82
|
+
#
|
83
|
+
# @param kind [Occi::Core::Kind, String] Kind or Type Identifier of a Kind where relation should be checked.
|
84
|
+
# @return [true,false]
|
85
|
+
def related_to?(kind)
|
86
|
+
self.parent.to_s == kind.to_s or self.to_s == kind.to_s
|
87
|
+
end
|
88
|
+
|
27
89
|
def entity_type
|
28
|
-
self.class.get_class
|
90
|
+
self.class.get_class self.scheme, self.term, self.parent
|
29
91
|
end
|
30
92
|
|
31
93
|
def location
|
32
94
|
@location.clone
|
33
95
|
end
|
34
96
|
|
97
|
+
def related
|
98
|
+
[self.parent]
|
99
|
+
end
|
100
|
+
|
35
101
|
# @param [Hash] options
|
36
102
|
# @return [Hashie::Mash] json representation
|
37
103
|
def as_json(options={})
|
38
104
|
kind = Hashie::Mash.new
|
39
|
-
kind.
|
40
|
-
kind.
|
41
|
-
kind.
|
105
|
+
kind.parent = self.parent.to_s if self.parent
|
106
|
+
kind.related = self.related.join(' ').split(' ') if self.related.any?
|
107
|
+
kind.actions = self.actions.join(' ').split(' ') if self.actions.any?
|
108
|
+
kind.location = self.location if self.location
|
42
109
|
kind.merge! super
|
43
110
|
kind
|
44
111
|
end
|
@@ -46,13 +113,25 @@ module Occi
|
|
46
113
|
# @return [String] string representation of the kind
|
47
114
|
def to_string
|
48
115
|
string = super
|
49
|
-
string << ';rel=' +
|
116
|
+
string << ';rel=' + self.related.first.to_s.inspect if self.related.any?
|
50
117
|
string << ';location=' + self.location.inspect
|
51
|
-
string << ';attributes=' +
|
52
|
-
string << ';actions=' +
|
118
|
+
string << ';attributes=' + self.attributes.names.keys.join(' ').inspect if self.attributes.any?
|
119
|
+
string << ';actions=' + self.actions.join(' ').inspect if self.actions.any?
|
53
120
|
string
|
54
121
|
end
|
55
122
|
|
123
|
+
private
|
124
|
+
|
125
|
+
# Relaxed parser rules require additional checks on terms.
|
126
|
+
# TODO: a better solution?
|
127
|
+
# TODO: check for more characters
|
128
|
+
def self.sanitize_term_before_classify(term)
|
129
|
+
sanitized = term.downcase.gsub(/[\s\(\)\.\{\}\-;,\\\/\?\!\|\*\<\>]/, '_').gsub(/_+/, '_').chomp('_').reverse.chomp('_').reverse
|
130
|
+
sanitized = "uuid_#{sanitized}" if sanitized.match(/^[0-9]/)
|
131
|
+
|
132
|
+
sanitized
|
133
|
+
end
|
134
|
+
|
56
135
|
end
|
57
136
|
end
|
58
137
|
end
|
data/lib/occi/core/kinds.rb
CHANGED
@@ -11,7 +11,7 @@ module Occi
|
|
11
11
|
scheme, term = category.split '#'
|
12
12
|
scheme += '#'
|
13
13
|
|
14
|
-
klass = Occi::Core::
|
14
|
+
klass = Occi::Core::Kind.get_class scheme, term, [Occi::Core::Kind.new]
|
15
15
|
category = klass.kind
|
16
16
|
end
|
17
17
|
category
|
data/lib/occi/core/link.rb
CHANGED
@@ -11,7 +11,7 @@ module Occi
|
|
11
11
|
term='link',
|
12
12
|
title='link',
|
13
13
|
attributes=self.attributes,
|
14
|
-
|
14
|
+
parent=Occi::Core::Entity.kind
|
15
15
|
|
16
16
|
# @param [String] kind
|
17
17
|
# @param [String] mixins
|
@@ -23,7 +23,7 @@ module Occi
|
|
23
23
|
def initialize(kind=self.kind, mixins=[], attributes={}, actions=[], rel=Occi::Core::Link.type_identifier, target=nil, source=nil, location=nil)
|
24
24
|
super(kind, mixins, attributes, actions, location)
|
25
25
|
scheme, term = rel.to_s.split('#')
|
26
|
-
@rel = Occi::Core::
|
26
|
+
@rel = Occi::Core::Kind.get_class(scheme, term).kind if scheme && term
|
27
27
|
@source = source if source
|
28
28
|
@target = target
|
29
29
|
end
|
data/lib/occi/core/mixin.rb
CHANGED
@@ -2,7 +2,7 @@ module Occi
|
|
2
2
|
module Core
|
3
3
|
class Mixin < Occi::Core::Category
|
4
4
|
|
5
|
-
attr_accessor :entities, :
|
5
|
+
attr_accessor :entities, :depends, :actions, :location, :applies
|
6
6
|
|
7
7
|
# @param [String ] scheme
|
8
8
|
# @param [String] term
|
@@ -14,28 +14,44 @@ module Occi
|
|
14
14
|
term='mixin',
|
15
15
|
title=nil,
|
16
16
|
attributes=Occi::Core::Attributes.new,
|
17
|
-
|
17
|
+
depends=Occi::Core::Dependencies.new,
|
18
18
|
actions=Occi::Core::Actions.new,
|
19
|
-
location=''
|
19
|
+
location='',
|
20
|
+
applies=Occi::Core::Kinds.new)
|
20
21
|
|
21
22
|
super(scheme, term, title, attributes)
|
22
|
-
@
|
23
|
-
@actions
|
23
|
+
@depends = Occi::Core::Dependencies.new depends
|
24
|
+
@actions = Occi::Core::Actions.new actions
|
24
25
|
@entities = Occi::Core::Entities.new
|
25
26
|
location.blank? ? @location = '/mixins/' + term + '/' : @location = location
|
27
|
+
@applies = Occi::Core::Kinds.new applies
|
28
|
+
end
|
29
|
+
|
30
|
+
# Check if this Mixin instance is related to another Mixin instance.
|
31
|
+
#
|
32
|
+
# @param kind [Occi::Core::Mixin, String] Mixin or Type Identifier of a Mixin where relation should be checked.
|
33
|
+
# @return [true,false]
|
34
|
+
def related_to?(mixin)
|
35
|
+
self.depends.any? { |dependency| dependency.to_s == mixin.to_s } or self.to_s == mixin.to_s
|
26
36
|
end
|
27
37
|
|
28
38
|
def location
|
29
39
|
@location.clone
|
30
40
|
end
|
31
41
|
|
42
|
+
def related
|
43
|
+
self.depends + self.applies
|
44
|
+
end
|
45
|
+
|
32
46
|
# @param [Hash] options
|
33
47
|
# @return [Hashie::Mash] json representation
|
34
|
-
def as_json(options={
|
48
|
+
def as_json(options={})
|
35
49
|
mixin = Hashie::Mash.new
|
36
|
-
mixin.
|
37
|
-
mixin.
|
38
|
-
mixin.
|
50
|
+
mixin.dependencies = self.depends.join(' ').split(' ') if self.depends.any?
|
51
|
+
mixin.applies = self.applies.join(' ').split(' ') if self.applies.any?
|
52
|
+
mixin.related = self.related.join(' ').split(' ') if self.related.any?
|
53
|
+
mixin.actions = self.actions if self.actions.any?
|
54
|
+
mixin.location = self.location if self.location
|
39
55
|
mixin.merge! super
|
40
56
|
mixin
|
41
57
|
end
|
@@ -43,10 +59,10 @@ module Occi
|
|
43
59
|
# @return [String] text representation
|
44
60
|
def to_string
|
45
61
|
string = super
|
46
|
-
string << ';rel=' +
|
62
|
+
string << ';rel=' + self.related.join(' ').inspect if self.related.any?
|
47
63
|
string << ';location=' + self.location.inspect
|
48
|
-
string << ';attributes=' +
|
49
|
-
string << ';actions=' +
|
64
|
+
string << ';attributes=' + self.attributes.names.keys.join(' ').inspect if self.attributes.any?
|
65
|
+
string << ';actions=' + self.actions.join(' ').inspect if self.actions.any?
|
50
66
|
string
|
51
67
|
end
|
52
68
|
|
data/lib/occi/core/mixins.rb
CHANGED
@@ -26,15 +26,8 @@ module Occi
|
|
26
26
|
# TODO: fix mixin conversion
|
27
27
|
def convert(mixin)
|
28
28
|
mixin = super mixin
|
29
|
-
|
30
29
|
if mixin.kind_of? String
|
31
|
-
|
32
|
-
scheme += '#'
|
33
|
-
|
34
|
-
mixin = Occi::Core::Category.get_class scheme, term, [Occi::Core::Mixin.new]
|
35
|
-
if mixin.respond_to? :new
|
36
|
-
mixin = mixin.new(scheme, term)
|
37
|
-
end
|
30
|
+
mixin = Occi::Core::Mixin.new *mixin.split('#')
|
38
31
|
end
|
39
32
|
mixin
|
40
33
|
end
|
data/lib/occi/core/resource.rb
CHANGED
data/lib/occi/core.rb
CHANGED
@@ -2,11 +2,11 @@ require 'occi/core/properties'
|
|
2
2
|
require 'occi/core/attributes'
|
3
3
|
require 'occi/core/category'
|
4
4
|
require 'occi/core/categories'
|
5
|
-
require 'occi/core/related'
|
6
5
|
require 'occi/core/kind'
|
7
6
|
require 'occi/core/kinds'
|
8
7
|
require 'occi/core/mixin'
|
9
8
|
require 'occi/core/mixins'
|
9
|
+
require 'occi/core/dependencies'
|
10
10
|
require 'occi/core/action'
|
11
11
|
require 'occi/core/action_instance'
|
12
12
|
require 'occi/core/actions'
|
@@ -17,9 +17,10 @@ module Occi
|
|
17
17
|
term='ipnetwork',
|
18
18
|
title='IP network mixin',
|
19
19
|
attributes=self.attributes,
|
20
|
-
|
20
|
+
dependencies=Occi::Core::Dependencies.new,
|
21
21
|
actions=Occi::Core::Actions.new,
|
22
|
-
location='/mixins/ipnetwork/'
|
22
|
+
location='/mixins/ipnetwork/',
|
23
|
+
applies=Occi::Core::Kinds.new << Occi::Infrastructure::Network.kind
|
23
24
|
|
24
25
|
end
|
25
26
|
end
|
@@ -17,9 +17,10 @@ module Occi
|
|
17
17
|
term='ipnetworkinterface',
|
18
18
|
title='IP network interface mixin',
|
19
19
|
attributes=self.attributes,
|
20
|
-
|
20
|
+
dependencies=Occi::Core::Dependencies.new,
|
21
21
|
actions=Occi::Core::Actions.new,
|
22
|
-
location='/mixins/ipnetworkinterface/'
|
22
|
+
location='/mixins/ipnetworkinterface/',
|
23
|
+
applies=Occi::Core::Kinds.new << Occi::Infrastructure::Network.kind
|
23
24
|
|
24
25
|
end
|
25
26
|
end
|
@@ -23,7 +23,7 @@ module Occi
|
|
23
23
|
term='networkinterface',
|
24
24
|
title = 'networkinterface link',
|
25
25
|
attributes = self.attributes,
|
26
|
-
|
26
|
+
parent = Occi::Core::Link.kind,
|
27
27
|
actions = self.actions,
|
28
28
|
location = '/networkinterface/'
|
29
29
|
|
data/lib/occi/parser/json.rb
CHANGED
@@ -6,8 +6,8 @@ module Occi
|
|
6
6
|
def self.collection(string)
|
7
7
|
collection = Occi::Collection.new
|
8
8
|
hash = Hashie::Mash.new(JSON.parse(string))
|
9
|
-
collection.kinds.merge hash.kinds.collect { |kind| Occi::Core::Kind.new(kind.scheme, kind.term, kind.title, kind.attributes, kind.related, kind.actions) } if hash.kinds
|
10
|
-
collection.mixins.merge hash.mixins.collect { |mixin| Occi::Core::Mixin.new(mixin.scheme, mixin.term, mixin.title, mixin.attributes, mixin.related, mixin.actions) } if hash.mixins
|
9
|
+
collection.kinds.merge hash.kinds.collect { |kind| Occi::Core::Kind.new(kind.scheme, kind.term, kind.title, kind.attributes, kind.parent ||= kind.related, kind.actions) } if hash.kinds
|
10
|
+
collection.mixins.merge hash.mixins.collect { |mixin| Occi::Core::Mixin.new(mixin.scheme, mixin.term, mixin.title, mixin.attributes, mixin.depends ||= mixin.related, mixin.actions, mixin.applies) } if hash.mixins
|
11
11
|
collection.actions.merge hash.actions.collect { |action| Occi::Core::Action.new(action.scheme, action.term, action.title, action.attributes) } if hash.actions
|
12
12
|
collection.resources.merge hash.resources.collect { |resource| Occi::Core::Resource.new(resource.kind, resource.mixins, resource.attributes, resource.actions, resource.links) } if hash.resources
|
13
13
|
collection.links.merge hash.links.collect { |link| Occi::Core::Link.new(link.kind, link.mixins, link.attributes, [], nil, link.target) } if hash.links
|
data/lib/occi/version.rb
CHANGED
@@ -2,33 +2,35 @@ module Occi
|
|
2
2
|
module Core
|
3
3
|
describe Category do
|
4
4
|
|
5
|
-
|
6
|
-
scheme = 'http://schemas.ogf.org/occi/core'
|
7
|
-
term = 'resource'
|
8
|
-
klass = Occi::Core::Category.get_class scheme, term
|
9
|
-
klass.should be Occi::Core::Resource
|
10
|
-
klass.superclass.should be Occi::Core::Entity
|
11
|
-
end
|
5
|
+
describe '.new' do
|
12
6
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
7
|
+
it 'instantiates a new Category' do
|
8
|
+
category = Category.new
|
9
|
+
category.scheme.should == 'http://schemas.ogf.org/occi/core#'
|
10
|
+
category.term.should == 'category'
|
11
|
+
category.title.should be_nil
|
12
|
+
category.attributes.should be_kind_of Occi::Core::Attributes
|
13
|
+
category.attributes.should be_empty
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'instantiates a new Category and ensures that the scheme ends with a #' do
|
17
|
+
category = Category.new *'http://schemas.ogf.org/occi/core#category'.split('#')
|
18
|
+
category.scheme.should == 'http://schemas.ogf.org/occi/core#'
|
19
|
+
category.term.should == 'category'
|
20
|
+
category.title.should be_nil
|
21
|
+
category.attributes.should be_kind_of Occi::Core::Attributes
|
22
|
+
category.attributes.should be_empty
|
23
|
+
end
|
21
24
|
|
22
|
-
it "does not get OCCI class by term and scheme if it relates to existing class not derived from OCCI Entity" do
|
23
|
-
scheme = 'http://hashie/'
|
24
|
-
term = 'mash'
|
25
|
-
related = ['http://schemas.ogf.org/occi/core#resource']
|
26
|
-
expect { Occi::Core::Category.get_class scheme, term, related }.to raise_error
|
27
25
|
end
|
28
26
|
|
29
|
-
|
30
|
-
|
31
|
-
category
|
27
|
+
describe '#type_identifier' do
|
28
|
+
|
29
|
+
it 'returns the type identifier of the category' do
|
30
|
+
category = Category.new
|
31
|
+
category.type_identifier.should == 'http://schemas.ogf.org/occi/core#category'
|
32
|
+
end
|
33
|
+
|
32
34
|
end
|
33
35
|
|
34
36
|
# rendering
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Occi
|
2
|
+
module Core
|
3
|
+
describe Kind do
|
4
|
+
|
5
|
+
describe '#get_class' do
|
6
|
+
|
7
|
+
it 'gets OCCI Resource class by term and scheme' do
|
8
|
+
scheme = 'http://schemas.ogf.org/occi/core'
|
9
|
+
term = 'resource'
|
10
|
+
klass = Occi::Core::Kind.get_class scheme, term
|
11
|
+
klass.should be Occi::Core::Resource
|
12
|
+
klass.superclass.should be Occi::Core::Entity
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'gets non predefined OCCI class by term, scheme and related class' do
|
16
|
+
scheme = 'http://example.com/occi'
|
17
|
+
term = 'test'
|
18
|
+
related = ['http://schemas.ogf.org/occi/core#resource']
|
19
|
+
klass = Occi::Core::Kind.get_class scheme, term, related
|
20
|
+
klass.should be Com::Example::Occi::Test
|
21
|
+
klass.superclass.should be Occi::Core::Resource
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'does not get OCCI class by term and scheme if it relates to existing class not derived from OCCI Entity' do
|
25
|
+
scheme = 'http://hashie/'
|
26
|
+
term = 'mash'
|
27
|
+
related = ['http://schemas.ogf.org/occi/core#resource']
|
28
|
+
expect { Occi::Core::Kind.get_class scheme, term, related }.to raise_error
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#related_to?' do
|
34
|
+
|
35
|
+
it 'checks if the kind is related to another kind' do
|
36
|
+
kind = Occi::Core::Resource.kind
|
37
|
+
kind.related_to?(Occi::Core::Entity.kind).should be true
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/spec/occi/model_spec.rb
CHANGED
@@ -39,8 +39,9 @@ module Occi
|
|
39
39
|
network = Occi::Infrastructure::Network.kind
|
40
40
|
collection = model.get(network)
|
41
41
|
collection.kind_of? Occi::Collection
|
42
|
+
collection.kinds.should have(1).kind
|
42
43
|
collection.kinds.first.should == network
|
43
|
-
collection.mixins.
|
44
|
+
collection.mixins.should be_empty
|
44
45
|
collection.actions.should be_empty
|
45
46
|
collection.resources.should be_empty
|
46
47
|
collection.links.should be_empty
|
@@ -21,8 +21,8 @@ module Occi
|
|
21
21
|
category.attributes['a-1'].class.should eq Occi::Core::Attributes
|
22
22
|
category.attributes['a-1']['a'].class.should eq Occi::Core::Attributes
|
23
23
|
category.attributes['a-1']['a']['b'].class.should eq Occi::Core::Properties
|
24
|
-
category.actions.to_a.
|
25
|
-
category.actions.to_a.
|
24
|
+
category.actions.to_a.any? {|action| action.to_s == 'http://a.a/a1#a1'}.should be_true
|
25
|
+
category.actions.to_a.any? {|action| action.to_s == 'http://a.b1/b1#b2'}.should be_true
|
26
26
|
end
|
27
27
|
|
28
28
|
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: 4.0.0.alpha.
|
4
|
+
version: 4.0.0.alpha.4
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-07-
|
14
|
+
date: 2013-07-26 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: json
|
@@ -236,6 +236,7 @@ files:
|
|
236
236
|
- lib/occi/core/attributes.rb
|
237
237
|
- lib/occi/core/categories.rb
|
238
238
|
- lib/occi/core/category.rb
|
239
|
+
- lib/occi/core/dependencies.rb
|
239
240
|
- lib/occi/core/entities.rb
|
240
241
|
- lib/occi/core/entity.rb
|
241
242
|
- lib/occi/core/kind.rb
|
@@ -245,7 +246,6 @@ files:
|
|
245
246
|
- lib/occi/core/mixin.rb
|
246
247
|
- lib/occi/core/mixins.rb
|
247
248
|
- lib/occi/core/properties.rb
|
248
|
-
- lib/occi/core/related.rb
|
249
249
|
- lib/occi/core/resource.rb
|
250
250
|
- lib/occi/core/resources.rb
|
251
251
|
- lib/occi/helpers/inspect.rb
|
@@ -276,6 +276,7 @@ files:
|
|
276
276
|
- spec/occi/core/categories_spec.rb
|
277
277
|
- spec/occi/core/category_spec.rb
|
278
278
|
- spec/occi/core/entity_spec.rb
|
279
|
+
- spec/occi/core/kind_spec.rb
|
279
280
|
- spec/occi/core/resource_spec.rb
|
280
281
|
- spec/occi/infrastructure/compute_spec.rb
|
281
282
|
- spec/occi/log_spec.rb
|