occi 1.2.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. data/.gitignore +9 -0
  2. data/.project +32 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +8 -0
  5. data/.yardopts +1 -0
  6. data/AUTHORS +8 -0
  7. data/Gemfile +35 -14
  8. data/Gemfile.lock +89 -32
  9. data/LICENSE +13 -4
  10. data/README.md +70 -21
  11. data/Rakefile +25 -21
  12. data/lib/OpenNebula/Acl.rb +256 -0
  13. data/lib/OpenNebula/AclPool.rb +53 -0
  14. data/lib/OpenNebula/Group.rb +147 -0
  15. data/lib/OpenNebula/GroupPool.rb +54 -0
  16. data/lib/OpenNebula/Host.rb +143 -0
  17. data/lib/OpenNebula/HostPool.rb +55 -0
  18. data/lib/OpenNebula/Image.rb +256 -0
  19. data/lib/OpenNebula/ImagePool.rb +74 -0
  20. data/lib/OpenNebula/OpenNebula.rb +137 -0
  21. data/lib/OpenNebula/Pool.rb +285 -0
  22. data/lib/OpenNebula/Template.rb +173 -0
  23. data/lib/OpenNebula/TemplatePool.rb +74 -0
  24. data/lib/OpenNebula/User.rb +157 -0
  25. data/lib/OpenNebula/UserPool.rb +53 -0
  26. data/lib/OpenNebula/VirtualMachine.rb +319 -0
  27. data/lib/OpenNebula/VirtualMachinePool.rb +120 -0
  28. data/lib/OpenNebula/VirtualNetwork.rb +229 -0
  29. data/lib/OpenNebula/VirtualNetworkPool.rb +74 -0
  30. data/lib/OpenNebula/XMLUtils.rb +337 -0
  31. data/lib/occi/antlr/.gitignore +18 -0
  32. data/lib/occi/antlr/OCCI.g +164 -0
  33. data/lib/occi/antlr/OCCI.tokens +75 -0
  34. data/lib/occi/antlr/OCCILexer.rb +1532 -0
  35. data/lib/occi/antlr/OCCIParser.rb +2472 -0
  36. data/lib/occi/antlr/README.md +2 -0
  37. data/lib/occi/backend/dummy.rb +232 -0
  38. data/lib/occi/backend/ec2/Compute.rb +310 -0
  39. data/lib/occi/backend/ec2/compute.rb +310 -0
  40. data/lib/occi/backend/ec2/ec2.rb +215 -0
  41. data/lib/occi/backend/manager.rb +131 -0
  42. data/lib/occi/backend/opennebula/compute.rb +360 -0
  43. data/lib/occi/backend/opennebula/network.rb +143 -0
  44. data/lib/occi/backend/opennebula/opennebula.rb +188 -0
  45. data/lib/occi/backend/opennebula/storage.rb +175 -0
  46. data/lib/occi/configuration.rb +118 -0
  47. data/lib/occi/core/action.rb +29 -0
  48. data/lib/occi/core/attribute_properties.rb +54 -0
  49. data/lib/occi/core/attributes.rb +40 -0
  50. data/lib/occi/core/category.rb +62 -0
  51. data/lib/occi/core/collection.rb +27 -0
  52. data/lib/occi/core/entity.rb +135 -0
  53. data/lib/occi/core/kind.rb +55 -0
  54. data/lib/occi/core/link.rb +88 -0
  55. data/lib/occi/core/mixin.rb +43 -0
  56. data/lib/occi/core/resource.rb +73 -0
  57. data/lib/occi/exceptions.rb +59 -0
  58. data/lib/occi/extensions/monitoring/cpu.rb +51 -0
  59. data/lib/occi/extensions/monitoring/memory.rb +49 -0
  60. data/lib/occi/extensions/monitoring/metric.rb +54 -0
  61. data/lib/occi/extensions/monitoring/netrx.rb +49 -0
  62. data/lib/occi/extensions/monitoring/nettx.rb +55 -0
  63. data/lib/occi/extensions/one/VNC.rb +58 -0
  64. data/lib/occi/extensions/one/vnc.rb +58 -0
  65. data/lib/occi/log.rb +47 -0
  66. data/lib/occi/parse.rb +164 -0
  67. data/lib/occi/registry.rb +87 -0
  68. data/lib/occi/server.rb +594 -0
  69. data/lib/occi/version.rb +3 -0
  70. data/occi.gemspec +18 -96
  71. data/spec/occi/antlr/parser_spec.rb +82 -0
  72. data/spec/spec_helper.rb +6 -0
  73. metadata +100 -208
  74. data/.autotest +0 -21
  75. data/.rvmrc +0 -1
  76. data/VERSION +0 -1
  77. data/lib/occi.rb +0 -1
  78. data/lib/occi/client.rb +0 -36
  79. data/lib/occi/compute.rb +0 -4
  80. data/lib/occi/network.rb +0 -4
  81. data/lib/occi/resource.rb +0 -59
  82. data/lib/occi/storage.rb +0 -7
  83. data/test/fixtures/cassettes/compute_all.yml +0 -28
  84. data/test/fixtures/cassettes/compute_create.yml +0 -45
  85. data/test/fixtures/cassettes/compute_destroy.yml +0 -22
  86. data/test/fixtures/cassettes/compute_find.yml +0 -28
  87. data/test/fixtures/cassettes/compute_update.yml +0 -35
  88. data/test/fixtures/cassettes/network_all.yml +0 -28
  89. data/test/fixtures/cassettes/network_create.yml +0 -37
  90. data/test/fixtures/cassettes/network_destroy.yml +0 -22
  91. data/test/fixtures/cassettes/network_find.yml +0 -28
  92. data/test/fixtures/cassettes/storage_all.yml +0 -28
  93. data/test/fixtures/cassettes/storage_create.yml +0 -50
  94. data/test/fixtures/cassettes/storage_destroy.yml +0 -22
  95. data/test/fixtures/cassettes/storage_find.yml +0 -28
  96. data/test/lib/occi/compute_test.rb +0 -91
  97. data/test/lib/occi/network_test.rb +0 -57
  98. data/test/lib/occi/storage_test.rb +0 -67
  99. data/test/test_helper.rb +0 -48
@@ -0,0 +1,49 @@
1
+ ##############################################################################
2
+ # Copyright 2012 GWDG
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ ##############################################################################
16
+
17
+ ##############################################################################
18
+ # Description: OCCI monitoring VM Network reception
19
+ # Author(s): Ali Imran Jehangiri, Florian Feldhaus, Piotr Kasprzak
20
+ ##############################################################################
21
+
22
+ require 'singleton'
23
+ require 'occi/core/mixin'
24
+
25
+ module OCCI
26
+ module Monitor
27
+ class Nettx < OCCI::Core::Mixin
28
+
29
+ # Define appropriate mixin
30
+ begin
31
+ # Define actions
32
+ actions = []
33
+
34
+ related = [OCCI::Monitor::Metric::MIXIN]
35
+ entities = []
36
+
37
+ term = "net_rx"
38
+ scheme = "http://example.com/occi/infrastructure/metric/compute#"
39
+ title = "compute.net_rx"
40
+
41
+ attributes = OCCI::Core::Attributes.new()
42
+ MIXIN = OCCI::Core::Mixin.new(term, scheme, title, attributes, actions, related, entities)
43
+ OCCI::CategoryRegistry.register(MIXIN)
44
+ OCCI::Rendering::HTTP::LocationRegistry.register('/metric/compute/net_rx', MIXIN)
45
+
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,55 @@
1
+ ##############################################################################
2
+ # Copyright 2012 GWDG
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ ##############################################################################
16
+
17
+ ##############################################################################
18
+ # Description: OCCI monitoring VM Network transmission
19
+ # Author(s): Ali Imran Jehangiri, Florian Feldhaus, Piotr Kasprzak
20
+ ##############################################################################
21
+
22
+ require 'singleton'
23
+ require 'occi/core/mixin'
24
+
25
+ module OCCI
26
+ module Monitor
27
+ class Nettx < OCCI::Core::Mixin
28
+
29
+ # Define appropriate mixin
30
+ begin
31
+ # Define actions
32
+ actions = []
33
+
34
+ related = [OCCI::Monitor::Metric::MIXIN]
35
+ entities = []
36
+
37
+ term = "net_tx"
38
+ scheme = "http://example.com/occi/infrastructure/metric/compute#"
39
+ title = "compute.net_tx"
40
+
41
+ attributes = OCCI::Core::Attributes.new()
42
+ # attributes << OCCI::Core::Attribute.new(name = 'compute.net_tx.value', mutable = false, mandatory = true, unique = true)
43
+ # attributes << OCCI::Core::Attribute.new(name = 'compute.net_tx.timestamp', mutable = false, mandatory = true, unique = true)
44
+ # attributes << OCCI::Core::Attribute.new(name = 'compute.net_tx.samplerate', mutable = true, mandatory = false, unique = true)
45
+ # attributes << OCCI::Core::Attribute.new(name = 'compute.net_tx.resolution', mutable = true, mandatory = false, unique = true)
46
+ # attributes << OCCI::Core::Attribute.new(name = 'compute.net_tx.unit', mutable = false, mandatory = true, unique = true)
47
+ MIXIN = OCCI::Core::Mixin.new(term, scheme, title, attributes, actions, related, entities)
48
+
49
+ OCCI::CategoryRegistry.register(MIXIN)
50
+ OCCI::Rendering::HTTP::LocationRegistry.register('/metric/compute/net_tx', MIXIN)
51
+
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,58 @@
1
+ ##############################################################################
2
+ # Copyright 2011 Service Computing group, TU Dortmund
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ ##############################################################################
16
+
17
+ ##############################################################################
18
+ # Description: OCCI Mixin to support OpenNebula specific virtual machine parameters
19
+ # Author(s): Hayati Bice, Florian Feldhaus, Piotr Kasprzak
20
+ ##############################################################################
21
+
22
+ require 'occi/core/mixin'
23
+ require 'occi/core/attribute'
24
+ require 'occi/core/attributes'
25
+ require 'singleton'
26
+
27
+ module OCCI
28
+ module Backend
29
+ module ONE
30
+ class VNC < OCCI::Core::Mixin
31
+
32
+ # Define appropriate mixin
33
+ begin
34
+ # Define actions
35
+ actions = []
36
+
37
+ related = []
38
+ entities = []
39
+
40
+ term = "vnc"
41
+ scheme = "http://schemas.opennebula.org/occi/infrastructure#"
42
+ title = "OpenNebula VNC Mixin"
43
+
44
+ attributes = OCCI::Core::Attributes.new()
45
+ attributes << OCCI::Core::Attribute.new(name = 'opennebula.vm.vnc', mutable = true, required = false, type = "string", range = "", default = "")
46
+ attributes << OCCI::Core::Attribute.new(name = 'opennebula.vm.web_vnc', mutable = true, required = false, type = "string", range = "", default = "")
47
+
48
+ MIXIN = OCCI::Core::Mixin.new(term, scheme, title, attributes, actions, related, entities)
49
+ end
50
+
51
+ def initialize(term, scheme, title, attributes, actions, related, entities)
52
+ super(term, scheme, title, attributes, actions, related, entities)
53
+ end
54
+
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,58 @@
1
+ ##############################################################################
2
+ # Copyright 2011 Service Computing group, TU Dortmund
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ ##############################################################################
16
+
17
+ ##############################################################################
18
+ # Description: OCCI Mixin to support OpenNebula specific virtual machine parameters
19
+ # Author(s): Hayati Bice, Florian Feldhaus, Piotr Kasprzak
20
+ ##############################################################################
21
+
22
+ require 'occi/core/mixin'
23
+ require 'occi/core/attribute'
24
+ require 'occi/core/attributes'
25
+ require 'singleton'
26
+
27
+ module OCCI
28
+ module Backend
29
+ module ONE
30
+ class VNC < OCCI::Core::Mixin
31
+
32
+ # Define appropriate mixin
33
+ begin
34
+ # Define actions
35
+ actions = []
36
+
37
+ related = []
38
+ entities = []
39
+
40
+ term = "vnc"
41
+ scheme = "http://schemas.opennebula.org/occi/infrastructure#"
42
+ title = "OpenNebula VNC Mixin"
43
+
44
+ attributes = OCCI::Core::Attributes.new()
45
+ attributes << OCCI::Core::Attribute.new(name = 'opennebula.vm.vnc', mutable = true, required = false, type = "string", range = "", default = "")
46
+ attributes << OCCI::Core::Attribute.new(name = 'opennebula.vm.web_vnc', mutable = true, required = false, type = "string", range = "", default = "")
47
+
48
+ MIXIN = OCCI::Core::Mixin.new(term, scheme, title, attributes, actions, related, entities)
49
+ end
50
+
51
+ def initialize(term, scheme, title, attributes, actions, related, entities)
52
+ super(term, scheme, title, attributes, actions, related, entities)
53
+ end
54
+
55
+ end
56
+ end
57
+ end
58
+ end
data/lib/occi/log.rb ADDED
@@ -0,0 +1,47 @@
1
+ ##############################################################################
2
+ # Copyright 2011 Service Computing group, TU Dortmund
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ ##############################################################################
16
+
17
+ ##############################################################################
18
+ # Description: OCCI logger
19
+ # Author(s): Hayati Bice, Florian Feldhaus, Piotr Kasprzak
20
+ ##############################################################################
21
+
22
+ require 'logger'
23
+
24
+ module OCCI
25
+ class Log
26
+
27
+ def self.debug(message)
28
+ ActiveSupport::Notifications.instrument("log",:level=>Logger::DEBUG,:message=>message)
29
+ end
30
+
31
+ def self.info(message)
32
+ ActiveSupport::Notifications.instrument("log", :level => Logger::INFO, :message => message)
33
+ end
34
+
35
+ def self.warn(message)
36
+ ActiveSupport::Notifications.instrument("log", :level => Logger::WARN, :message => message)
37
+ end
38
+
39
+ def self.error(message)
40
+ ActiveSupport::Notifications.instrument("log", :level => Logger::ERROR, :message => message)
41
+ end
42
+
43
+ def self.fatal(message)
44
+ ActiveSupport::Notifications.instrument("log", :level => Logger::FATAL, :message => message)
45
+ end
46
+ end
47
+ end
data/lib/occi/parse.rb ADDED
@@ -0,0 +1,164 @@
1
+ ##############################################################################
2
+ # Copyright 2011 Service Computing group, TU Dortmund
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ ##############################################################################
16
+
17
+ ##############################################################################
18
+ # @note OCCI RESTful Web Service
19
+ # @author Florian Feldhaus, Piotr Kasprzak
20
+ ##############################################################################
21
+
22
+ require 'json'
23
+ #require 'nokogiri'
24
+ require 'occi/core/collection'
25
+ require 'occi/log'
26
+ require 'occi/antlr/OCCIParser'
27
+
28
+ module OCCI
29
+ class Parse
30
+
31
+ =begin
32
+ if content_type.includes?('multipart')
33
+ # TODO: implement multipart handling
34
+ # handle file upload
35
+ if params['file'] != nil
36
+ OCCI::Log.debug("Location of Image #{params['file'][:tempfile].path}")
37
+ $image_path = OCCI::Server.config[:one_image_tmp_dir] + '/' + params['file'][:filename]
38
+ FileUtils.cp(params['file'][:tempfile].path, $image_path)
39
+ end
40
+
41
+ # handle file upload in multipart requests
42
+ request.POST.values.each do |body|
43
+ if body.kind_of?(String)
44
+ parse_text(body)
45
+ elsif body.kind_of?(Hash)
46
+ if body['type'].include?('application/json')
47
+ # try to parse body as JSON object
48
+ parse_json(body.read)
49
+ elsif body['type'].include?('text/plain') # text/plain
50
+ parse_text(body.read)
51
+ end unless body['type'].nil?
52
+ end
53
+ end
54
+ end
55
+ =end
56
+
57
+ def self.header_locations(header)
58
+ x_occi_location_strings = header['HTTP_X_OCCI_LOCATION'].to_s.split(',')
59
+ x_occi_location_strings.collect { |loc| OCCI::Parser.new('X-OCCI-Location: ' + loc).x_occi_location }
60
+ end
61
+
62
+ def self.header_categories(header)
63
+ collection = OCCI::Core::Collection.new
64
+ category_strings = header['HTTP_CATEGORY'].to_s.split(',')
65
+ category_strings.each do |cat|
66
+ category = OCCI::Parser.new('Category: ' + cat).category
67
+ collection.kinds.concat category.kinds.collect { |kind| OCCI::Core::Kind.new(kind) }
68
+ collection.mixins.concat category.mixins.collect { |mixin| OCCI::Core::Mixin.new(mixin) }
69
+ collection.actions.concat category.actions.collect { |action| OCCI::Core::Action.new(action) }
70
+ end
71
+ collection
72
+ end
73
+
74
+ def self.header_entity(header)
75
+ collection = OCCI::Core::Collection.new
76
+ entity = Hashie::Mash.new
77
+ category_strings = header['HTTP_CATEGORY'].to_s.split(',')
78
+ return collection if category_strings.empty?
79
+ attribute_strings = header['HTTP_X_OCCI_ATTRIBUTE'].to_s.split(',')
80
+ categories = Hashie::Mash.new({:kinds => [], :mixins => [], :actions => []})
81
+ category_strings.each { |cat| categories.merge!(OCCI::Parser.new('Category: ' + cat).category) }
82
+ return collection if categories.kinds.empty?
83
+ entity.kind = categories.kinds.first.scheme + categories.kinds.first.term
84
+ entity.mixins = categories.mixins.collect { |mixin| mixin.scheme + mixin.term } if categories.mixins.any?
85
+ attribute_strings.each { |attr| entity.attributes!.merge!(OCCI::Parser.new('X-OCCI-Attribute: ' + attr).x_occi_attribute) }
86
+ kind = OCCI::Registry.get_by_id(entity.kind)
87
+ # TODO: error handling
88
+ return collection if kind.nil?
89
+ if kind.entity_type == OCCI::Core::Link.name
90
+ entity.target = link.attributes.occi!.core!.target
91
+ entity.source = link.attributes.occi!.core!.source
92
+ collection.links << OCCI::Core::Link.new(entity)
93
+ elsif kind.entity_type == OCCI::Core::Resource.name
94
+ link_strings = header['HTTP_LINK'].to_s.split(',')
95
+ link_strings.each { |link| entity.links << OCCI::Parser.new('Link: ' + link).link }
96
+ collection.resources << OCCI::Core::Resource.new(entity)
97
+ end
98
+ collection
99
+ end
100
+
101
+ def self.text_locations(text)
102
+ text.lines.collect { |line| OCCI::Parser.new(line).x_occi_location if line.include? 'X-OCCI-Location' }.compact
103
+ end
104
+
105
+ def self.text_categories(text)
106
+ collection = OCCI::Core::Collection.new
107
+ text.each_line do |line|
108
+ category = OCCI::Parser.new(line).category
109
+ collection.kinds.concat category.kinds.collect { |kind| OCCI::Core::Kind.new(kind) }
110
+ collection.mixins.concat category.mixins.collect { |mixin| OCCI::Core::Mixin.new(mixin) }
111
+ collection.actions.concat category.actions.collect { |action| OCCI::Core::Action.new(action) }
112
+ end
113
+ collection
114
+ end
115
+
116
+ def self.text_entity(text)
117
+ collection = OCCI::Core::Collection.new
118
+ entity = Hashie::Mash.new
119
+ links = []
120
+ categories = Hashie::Mash.new({:kinds => [], :mixins => [], :actions => []})
121
+ text.each_line do |line|
122
+ categories.merge!(OCCI::Parser.new(line).category) if line.include? 'Category'
123
+ entity.attributes!.merge!(OCCI::Parser.new(line).x_occi_attribute) if line.include? 'X-OCCI-Attribute'
124
+ links << OCCI::Parser.new(line).link if line.include? 'Link'
125
+ end
126
+ entity.kind = categories.kinds.first.scheme + categories.kinds.first.term if categories.kinds.first
127
+ entity.mixins = categories.mixins.collect { |mixin| mixin.scheme + mixin.term } if entity.mixins
128
+ kind = OCCI::Registry.get_by_id(entity.kind)
129
+ # TODO: error handling
130
+ return collection if kind.nil?
131
+ if OCCI::Registry.get_by_id(entity.kind).entity_type == OCCI::Core::Link.name
132
+ entity.target = links.first.attributes.occi!.core!.target
133
+ entity.source = links.first.attributes.occi!.core!.source
134
+ collection.links << OCCI::Core::Link.new(entity)
135
+ elsif OCCI::Registry.get_by_id(entity.kind).entity_type == OCCI::Core::Resource.name
136
+ entity.links = links
137
+ collection.resources << OCCI::Core::Resource.new(entity)
138
+ end unless entity.kind.nil?
139
+ collection
140
+ end
141
+
142
+ def self.json(json)
143
+ collection = OCCI::Core::Collection.new
144
+ hash = Hashie::Mash.new(JSON.parse(json))
145
+ collection.kinds.concat hash.kinds.collect { |kind| OCCI::Core::Kind.new(kind) } if hash.kinds
146
+ collection.mixins.concat hash.mixins.collect { |mixin| OCCI::Core::Mixin.new(mixin) } if hash.mixins
147
+ collection.resources.concat hash.resources.collect { |resource| OCCI::Core::Resource.new(resource) } if hash.resources
148
+ collection.links.concat hash.links.collect { |link| OCCI::Core::Link.new(link) } if hash.links
149
+ collection
150
+ end
151
+
152
+ #def self.xml(xml)
153
+ # collection = OCCI::Core::Collection.new
154
+ # hash = Hashie::Mash.new(Hash.from_xml(Nokogiri::XML(xml)))
155
+ # collection.kinds.concat hash.kinds.collect { |kind| OCCI::Core::Kind.new(kind) } if hash.kinds
156
+ # collection.mixins.concat hash.mixins.collect { |mixin| OCCI::Core::Mixin.new(mixin) } if hash.mixins
157
+ # collection.resources.concat hash.resources.collect { |resource| OCCI::Core::Resource.new(resource) } if hash.resources
158
+ # collection.links.concat hash.links.collect { |link| OCCI::Core::Link.new(link) } if hash.links
159
+ # collection
160
+ #end
161
+
162
+ end
163
+
164
+ end
@@ -0,0 +1,87 @@
1
+ ##############################################################################
2
+ # Copyright 2011 Service Computing group, TU Dortmund
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ ##############################################################################
16
+
17
+ ##############################################################################
18
+ # Description: registry for all Category/Kind/Mixin instances currently
19
+ # known to the OCCI server
20
+ # Author(s): Hayati Bice, Florian Feldhaus, Piotr Kasprzak
21
+ ##############################################################################
22
+
23
+ require 'occi/log'
24
+
25
+ module OCCI
26
+ # ---------------------------------------------------------------------------------------------------------------------
27
+ module Registry
28
+
29
+ @@categories = {}
30
+ @@locations = {}
31
+
32
+ def self.reset()
33
+ @@categories.each_value.each {|category| category.entities = [] if category.entities}
34
+ end
35
+
36
+ # ---------------------------------------------------------------------------------------------------------------------
37
+ def self.register(category)
38
+ OCCI::Log.debug("### Registering category #{category.type_identifier}")
39
+ @@categories[category.type_identifier] = category
40
+ @@locations[category.location] = category.type_identifier unless category.kind_of?(OCCI::Core::Action)
41
+ end
42
+
43
+ # ---------------------------------------------------------------------------------------------------------------------
44
+ def self.unregister(category)
45
+ OCCI::Log.debug("### Unregistering category #{category.type_identifier}")
46
+ @@categories.delete(category.type_identifier)
47
+ @@locations.delete(category.location) unless category.kind_of?(OCCI :Core::Action)
48
+ end
49
+
50
+ # Returns the category corresponding to a given type identifier
51
+ #
52
+ # @param [URI] type identifier of a category
53
+ def self.get_by_id(id)
54
+ @@categories.fetch(id) { OCCI::Log.debug("Category with id #{id} not found"); nil }
55
+ end
56
+
57
+ # Returns the category corresponding to a given location
58
+ #
59
+ # @param [URI] Location of a category
60
+ def self.get_by_location(location)
61
+ id = @@locations.fetch(location) { OCCI::Log.debug("Category with location #{location} not found"); nil }
62
+ self.get_by_id(id)
63
+ end
64
+
65
+ # Return all categories from category registry. If filter is present, return only the categories specified by filter
66
+ #
67
+ # @param [Hashie:Hash] filter
68
+ # @return [Hashie::Mash] collection
69
+ def self.get(filter = [])
70
+ collection = Hashie::Mash.new({:kinds => [], :mixins => [], :actions => []})
71
+ filter.each do |cat|
72
+ category = get_by_id(cat.type_identifier)
73
+ collection.kinds << category if category.kind_of?(OCCI::Core::Kind)
74
+ collection.mixins << category if category.kind_of?(OCCI::Core::Mixin)
75
+ collection.actions << category if category.kind_of?(OCCI::Core::Action)
76
+ end
77
+ if filter.empty?
78
+ @@categories.each_value do |category|
79
+ collection.kinds << category if category.kind_of? OCCI::Core::Kind
80
+ collection.mixins << category if category.kind_of? OCCI::Core::Mixin
81
+ collection.actions << category if category.kind_of? OCCI::Core::Action
82
+ end
83
+ end
84
+ return collection
85
+ end
86
+ end
87
+ end