occi 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +3 -0
- data/README.md +6 -3
- data/lib/occi/collection.rb +5 -1
- data/lib/occi/core/attribute_properties.rb +0 -2
- data/lib/occi/core/category.rb +2 -2
- data/lib/occi/core/entity.rb +8 -1
- data/lib/occi/core/resource.rb +1 -0
- data/lib/occi/model.rb +14 -10
- data/lib/occi/parser.rb +9 -8
- data/lib/occi/version.rb +1 -1
- metadata +2 -2
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -11,6 +11,8 @@ GEM
|
|
11
11
|
i18n (0.6.0)
|
12
12
|
json (1.6.6)
|
13
13
|
multi_json (1.3.5)
|
14
|
+
nokogiri (1.5.3)
|
15
|
+
rake (0.9.2.2)
|
14
16
|
rspec (2.10.0)
|
15
17
|
rspec-core (~> 2.10.0)
|
16
18
|
rspec-expectations (~> 2.10.0)
|
@@ -40,6 +42,7 @@ DEPENDENCIES
|
|
40
42
|
hashie
|
41
43
|
json
|
42
44
|
nokogiri
|
45
|
+
rake
|
43
46
|
rspec
|
44
47
|
rspec-http
|
45
48
|
simplecov
|
data/README.md
CHANGED
@@ -42,10 +42,13 @@ First require the gem
|
|
42
42
|
The OCCI gem includes its own logging mechanism using a message queue. By default, no one is listening to that queue.
|
43
43
|
A new OCCI Logger can be initialized by specifying the log destination (either a filename or an IO object like
|
44
44
|
STDOUT) and the log level.
|
45
|
+
|
45
46
|
OCCI::Log.new(STDOUT,OCCI::Log::INFO)
|
47
|
+
|
46
48
|
You can create multiple Loggers to receive the log output.
|
47
49
|
|
48
50
|
You can always, even if there is no logger defined, log output using the class methods of OCCI::Log e.g.
|
51
|
+
|
49
52
|
OCCI::Log.info("Test message")
|
50
53
|
|
51
54
|
### Registering categories in the OCCI Model
|
@@ -53,6 +56,7 @@ You can always, even if there is no logger defined, log output using the class m
|
|
53
56
|
Before the parser may be used, the available categories have to be registered in the OCCI Model.
|
54
57
|
|
55
58
|
For categories already specified by the OCCI WG a method exists in the OCCI Model class to register them:
|
59
|
+
|
56
60
|
OCCI::Model.register_core
|
57
61
|
OCCI::Model.register_infrastructure
|
58
62
|
|
@@ -68,11 +72,10 @@ category and a message with an entity which has a kind, it has to be specified i
|
|
68
72
|
.g. for user defined mixins)
|
69
73
|
|
70
74
|
OCCI messages can be parsed for example like
|
75
|
+
|
71
76
|
media_type = text/plain
|
72
77
|
body = %Q|Category: compute; scheme="http://schemas.ogf.org/occi/infrastructure#"; class="kind"|
|
73
|
-
|
74
|
-
category = false
|
75
|
-
OCCI::Parser.parse(media_type,body,header,category)
|
78
|
+
OCCI::Parser.parse(media_type,body)
|
76
79
|
|
77
80
|
### Using the OCCI model
|
78
81
|
|
data/lib/occi/collection.rb
CHANGED
@@ -13,7 +13,11 @@ module OCCI
|
|
13
13
|
# @param [Hash] collection including one or more of the keys kinds, mixins, actions, resources, links
|
14
14
|
def initialize(collection={ })
|
15
15
|
collection = Hashie::Mash.new(collection)
|
16
|
-
@kinds =
|
16
|
+
@kinds = []
|
17
|
+
@mixins = []
|
18
|
+
@actions = []
|
19
|
+
@resources = []
|
20
|
+
@links = []
|
17
21
|
@kinds = collection.kinds.collect { |kind| OCCI::Core::Kind.new(kind) } if collection.kinds.instance_of? Array
|
18
22
|
@mixins = collection.mixins.collect { |mixin| OCCI::Core::Mixin.new(mixin) } if collection.mixins.instance_of? Array
|
19
23
|
@actions = collection.actions.collect { |action| OCCI::Core::Action.new(action) } if collection.actions.instance_of? Array
|
data/lib/occi/core/category.rb
CHANGED
@@ -30,8 +30,8 @@ module OCCI
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def related_to?(category_id)
|
33
|
-
self.related.each do |
|
34
|
-
return true if
|
33
|
+
self.related.each do |rel_id|
|
34
|
+
return true if rel_id == category_id || OCCI::Model.get_by_id(rel_id).related_to?(category_id)
|
35
35
|
end if self.related
|
36
36
|
false
|
37
37
|
end
|
data/lib/occi/core/entity.rb
CHANGED
@@ -41,6 +41,7 @@ module OCCI
|
|
41
41
|
|
42
42
|
def id=(id)
|
43
43
|
self[:id] = id
|
44
|
+
self.attributes ||= OCCI::Core::Attributes.new
|
44
45
|
self.attributes!.occi!.core!.id = id
|
45
46
|
end
|
46
47
|
|
@@ -51,6 +52,7 @@ module OCCI
|
|
51
52
|
|
52
53
|
def title=(title)
|
53
54
|
self[:title] = title
|
55
|
+
self.attributes ||= OCCI::Core::Attributes.new
|
54
56
|
self.attributes!.occi!.core!.title = title
|
55
57
|
end
|
56
58
|
|
@@ -64,7 +66,12 @@ module OCCI
|
|
64
66
|
|
65
67
|
def check
|
66
68
|
definitions = OCCI::Model.get_by_id(self.kind).attributes if self.kind
|
67
|
-
self.mixins.each
|
69
|
+
self.mixins.each do |mixin_id|
|
70
|
+
mixin = OCCI::Model.get_by_id(mixin_id)
|
71
|
+
next if mixin.nil?
|
72
|
+
definitions.merge!(mixin.attributes) if mixin.attributes
|
73
|
+
end if self.mixins
|
74
|
+
|
68
75
|
self.attributes = Entity.check(self.attributes, definitions) if definitions
|
69
76
|
end
|
70
77
|
|
data/lib/occi/core/resource.rb
CHANGED
data/lib/occi/model.rb
CHANGED
@@ -24,14 +24,15 @@ module OCCI
|
|
24
24
|
#
|
25
25
|
# @param [String] path to a folder containing files which include OCCI collections in JSON format. The path is
|
26
26
|
# recursively searched for files with the extension .json .
|
27
|
-
|
27
|
+
# @param [Sting] scheme_base_url base location for provider specific extensions of the OCCI model
|
28
|
+
def self.register_files(path, scheme_base_url='http://localhost')
|
28
29
|
OCCI::Log.info("### Initializing OCCI Model from #{path} ###")
|
29
30
|
Dir.glob(path + '/**/*.json').each do |file|
|
30
31
|
collection = OCCI::Collection.new(JSON.parse(File.read(file)))
|
31
32
|
# add location of service provider to scheme if it has a relative location
|
32
|
-
collection.kinds.collect { |kind| kind.scheme =
|
33
|
-
collection.mixins.collect { |mixin| mixin.scheme =
|
34
|
-
collection.actions.collect { |action| action.scheme =
|
33
|
+
collection.kinds.collect { |kind| kind.scheme = scheme_base_url + kind.scheme if kind.scheme.start_with? '/' } if collection.kinds
|
34
|
+
collection.mixins.collect { |mixin| mixin.scheme = scheme_base_url + mixin.scheme if mixin.scheme.start_with? '/' } if collection.mixins
|
35
|
+
collection.actions.collect { |action| action.scheme = scheme_base_url + action.scheme if action.scheme.start_with? '/' } if collection.actions
|
35
36
|
self.register_collection(collection)
|
36
37
|
end
|
37
38
|
end
|
@@ -82,12 +83,6 @@ module OCCI
|
|
82
83
|
# @return [Hashie::Mash] collection
|
83
84
|
def self.get(filter = [])
|
84
85
|
collection = Hashie::Mash.new({ :kinds => [], :mixins => [], :actions => [] })
|
85
|
-
filter.each do |cat|
|
86
|
-
category = get_by_id(cat.type_identifier)
|
87
|
-
collection.kinds << category if category.kind_of?(OCCI::Core::Kind)
|
88
|
-
collection.mixins << category if category.kind_of?(OCCI::Core::Mixin)
|
89
|
-
collection.actions << category if category.kind_of?(OCCI::Core::Action)
|
90
|
-
end
|
91
86
|
if filter.empty?
|
92
87
|
@@categories.each_value do |category|
|
93
88
|
collection.kinds << category if category.kind_of? OCCI::Core::Kind
|
@@ -95,6 +90,15 @@ module OCCI
|
|
95
90
|
collection.actions << category if category.kind_of? OCCI::Core::Action
|
96
91
|
end
|
97
92
|
end
|
93
|
+
OCCI::Log.debug("### Filtering categories #{filter.collect{|c| c.type_identifier}.inspect}")
|
94
|
+
while filter.any? do
|
95
|
+
cat = filter.pop
|
96
|
+
filter.concat @@categories.each_value.select { |category| category.related_to?(cat.type_identifier) }
|
97
|
+
category = get_by_id(cat.type_identifier)
|
98
|
+
collection.kinds << category if category.kind_of?(OCCI::Core::Kind)
|
99
|
+
collection.mixins << category if category.kind_of?(OCCI::Core::Mixin)
|
100
|
+
collection.actions << category if category.kind_of?(OCCI::Core::Action)
|
101
|
+
end
|
98
102
|
return collection
|
99
103
|
end
|
100
104
|
|
data/lib/occi/parser.rb
CHANGED
@@ -39,15 +39,15 @@ module OCCI
|
|
39
39
|
# @param [String] body the body of the OCCI message
|
40
40
|
# @param [true, false] category for text/plain and text/occi media types information e.g. from the HTTP request location is needed to determine if the OCCI message includes a category or an entity
|
41
41
|
# @param [Hash] header optional header of the OCCI message
|
42
|
-
# @return [Array<Array, OCCI::
|
42
|
+
# @return [Array<Array, OCCI::Collection>] list consisting of an array of locations and the OCCI object collection
|
43
43
|
def self.parse(media_type, body, category=false, header={ })
|
44
44
|
OCCI::Log.debug('### Parsing request data to OCCI data structure ###')
|
45
45
|
collection = OCCI::Collection.new
|
46
|
-
# always check header for locations
|
47
|
-
locations = self.header_locations(header)
|
48
|
-
category ? collection = self.header_categories(header) : collection = self.header_entity(header) if locations.empty?
|
49
46
|
|
50
47
|
case media_type
|
48
|
+
when 'text/occi'
|
49
|
+
locations = self.header_locations(header)
|
50
|
+
category ? collection = self.header_categories(header) : collection = self.header_entity(header) if locations.empty?
|
51
51
|
when 'text/uri-list'
|
52
52
|
body.each_line { |line| locations << URI.parse(line) }
|
53
53
|
when 'text/plain', nil
|
@@ -60,7 +60,7 @@ module OCCI
|
|
60
60
|
#when 'application/ovf+xml'
|
61
61
|
# collection = self.ovf(body)
|
62
62
|
else
|
63
|
-
raise
|
63
|
+
raise "Content Type not supported"
|
64
64
|
end
|
65
65
|
return locations, collection
|
66
66
|
end
|
@@ -73,7 +73,7 @@ module OCCI
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def self.header_categories(header)
|
76
|
-
collection = OCCI::
|
76
|
+
collection = OCCI::Collection.new
|
77
77
|
category_strings = header['HTTP_CATEGORY'].to_s.split(',')
|
78
78
|
category_strings.each do |cat|
|
79
79
|
category = OCCIANTLR::Parser.new('Category: ' + cat).category
|
@@ -116,9 +116,10 @@ module OCCI
|
|
116
116
|
end
|
117
117
|
|
118
118
|
def self.text_categories(text)
|
119
|
-
collection = OCCI::
|
119
|
+
collection = OCCI::Collection.new
|
120
120
|
text.each_line do |line|
|
121
121
|
category = OCCIANTLR::Parser.new(line).category
|
122
|
+
next if category.nil?
|
122
123
|
collection.kinds.concat category.kinds.collect { |kind| OCCI::Core::Kind.new(kind) }
|
123
124
|
collection.mixins.concat category.mixins.collect { |mixin| OCCI::Core::Mixin.new(mixin) }
|
124
125
|
collection.actions.concat category.actions.collect { |action| OCCI::Core::Action.new(action) }
|
@@ -153,7 +154,7 @@ module OCCI
|
|
153
154
|
end
|
154
155
|
|
155
156
|
def self.json(json)
|
156
|
-
collection = OCCI::
|
157
|
+
collection = OCCI::Collection.new
|
157
158
|
hash = Hashie::Mash.new(JSON.parse(json))
|
158
159
|
collection.kinds.concat hash.kinds.collect { |kind| OCCI::Core::Kind.new(kind) } if hash.kinds
|
159
160
|
collection.mixins.concat hash.mixins.collect { |mixin| OCCI::Core::Mixin.new(mixin) } if hash.mixins
|
data/lib/occi/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: occi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-06-
|
13
|
+
date: 2012-06-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json
|