occi 1.2.1 → 2.0.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.
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,118 @@
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: Configuration of OCCI Webservice
19
+ # Author(s): Hayati Bice, Florian Feldhaus, Piotr Kasprzak
20
+ ##############################################################################
21
+
22
+ require 'occi/log'
23
+
24
+ module OCCI
25
+ class Configuration
26
+
27
+ ###########################################################################
28
+ # Mandatory config parameters
29
+
30
+ @@mandatory_params = []
31
+ # the backend needs to be specified, currently supported: dummy and opennebula
32
+ @@mandatory_params << "backend"
33
+ # the url of the server needs to be specified
34
+ @@mandatory_params << "server"
35
+ # the port of the server needs to be specified
36
+ @@mandatory_params << "port"
37
+
38
+ ###########################################################################
39
+ # Patterns to parse the Configuration File
40
+
41
+ NAME_REG =/[\w\d_-]+/
42
+ VARIABLE_REG =/\s*(#{NAME_REG})\s*=\s*/
43
+
44
+ SIMPLE_VARIABLE_REG =/#{VARIABLE_REG}([^\[]+?)(#.*)?/
45
+ SINGLE_VARIABLE_REG =/^#{SIMPLE_VARIABLE_REG}$/
46
+ ARRAY_VARIABLE_REG =/^#{VARIABLE_REG}\[(.*?)\]/m
47
+
48
+ ###########################################################################
49
+ def initialize(file)
50
+ @conf=parse_conf(file)
51
+ end
52
+
53
+ def add_configuration_value(key,value)
54
+ add_value(@conf,key,value)
55
+ end
56
+
57
+ def [](key)
58
+ @conf[key.to_s.upcase]
59
+ end
60
+
61
+ private
62
+
63
+ #
64
+ #
65
+ #
66
+ def add_value(conf, key, value)
67
+ if conf[key]
68
+ if !conf[key].kind_of?(Array)
69
+ conf[key]=[conf[key]]
70
+ end
71
+ conf[key]<<value
72
+ else
73
+ conf[key]=value
74
+ end
75
+ end
76
+
77
+ def check_params(conf)
78
+ @@mandatory_params.each do
79
+ |param|
80
+ if conf[param.upcase] == nil
81
+ raise "Mandatory parameter " + param + " not provided in config file. exiting"
82
+ end
83
+ end
84
+ end
85
+
86
+ def parse_conf(file)
87
+ conf_file=File.read(file)
88
+
89
+ conf=Hash.new
90
+
91
+ conf_file.scan(SINGLE_VARIABLE_REG) {|m|
92
+ key=m[0].strip.upcase
93
+ value=m[1].strip
94
+
95
+ # hack to skip multiline VM_TYPE values
96
+ next if %w{NAME TEMPLATE}.include? key.upcase
97
+
98
+ add_value(conf, key, value)
99
+ }
100
+
101
+ conf_file.scan(ARRAY_VARIABLE_REG) {|m|
102
+ master_key=m[0].strip.upcase
103
+
104
+ pieces=m[1].split(',')
105
+
106
+ vars=Hash.new
107
+ pieces.each {|p|
108
+ key, value=p.split('=')
109
+ vars[key.strip.upcase]=value.strip
110
+ }
111
+
112
+ add_value(conf, master_key, vars)
113
+ }
114
+
115
+ conf
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,29 @@
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 Core Action
19
+ # Author(s): Hayati Bice, Florian Feldhaus, Piotr Kasprzak
20
+ ##############################################################################
21
+
22
+ require 'occi/core/category'
23
+
24
+ module OCCI
25
+ module Core
26
+ class Action < OCCI::Core::Category
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,54 @@
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: storing a single Attribute
19
+ # Author(s): Florian Feldhaus, Piotr Kasprzak
20
+ ##############################################################################
21
+
22
+ require 'hashie/mash'
23
+
24
+ module OCCI
25
+ module Core
26
+ class AttributeProperties < Hashie::Mash
27
+
28
+ def initialize(attributes = nil, default = nil)
29
+ if attributes[:type] || attributes.required || attributes.mutable || attributes.pattern || attributes.minimum || attributes.maximum || attributes.description
30
+ attributes[:type] ||= "string"
31
+ attributes.required ||= false
32
+ attributes.mutable ||= false
33
+ attributes.pattern ||= ".*"
34
+ end unless attributes.nil?
35
+ super(attributes, default)
36
+ end
37
+
38
+ def combine
39
+ array = []
40
+ self.each_key do |key|
41
+ puts key
42
+ puts self[key]
43
+ if self[key].include? 'type'
44
+ array << key + "{}"
45
+ else
46
+ self[key].combine.each { |attr| array << key + '.' + attr }
47
+ end
48
+ end
49
+ return array
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,40 @@
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: storing a single Attribute
19
+ # Author(s): Hayati Bice, Florian Feldhaus, Piotr Kasprzak
20
+ ##############################################################################
21
+
22
+ module OCCI
23
+ module Core
24
+ class Attributes < Hashie::Mash
25
+
26
+ def combine
27
+ hash = {}
28
+ self.each_key do |key|
29
+ if self[key].kind_of? Hashie::Mash
30
+ self[key].combine.each_pair { |k, v| hash[key + '.' + k] = v }
31
+ else
32
+ hash[key] = self[key]
33
+ end
34
+ end
35
+ return hash
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,62 @@
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 Core Category
19
+ # Author(s): Hayati Bice, Florian Feldhaus, Piotr Kasprzak
20
+ ##############################################################################
21
+
22
+ require 'json'
23
+ require 'hashie/mash'
24
+
25
+ module OCCI
26
+ module Core
27
+ class Category < Hashie::Mash
28
+
29
+ def initialize(category=nil, default = nil)
30
+ category.attributes = OCCI::Core::AttributeProperties.new(category.attributes) if category
31
+ super(category, default)
32
+ end
33
+
34
+ def convert_value(val, duping=false) #:nodoc:
35
+ case val
36
+ when self.class
37
+ val.dup
38
+ when ::Hash
39
+ val = val.dup if duping
40
+ self.class.subkey_class.new.merge(val) unless val.kind_of?(Hashie::Mash)
41
+ val
42
+ when Array
43
+ val.collect { |e| convert_value(e) }
44
+ else
45
+ val
46
+ end
47
+ end
48
+
49
+ def type_identifier
50
+ regular_reader("scheme") + regular_reader("term")
51
+ end
52
+
53
+ def related_to?(category_id)
54
+ self.related.each do |category|
55
+ return true if category.type_identifier == category_id || category.related_to?(category_id)
56
+ end if self.related
57
+ false
58
+ end
59
+
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,27 @@
1
+ module OCCI
2
+ module Core
3
+ class Collection
4
+ attr_accessor :kinds
5
+ attr_accessor :mixins
6
+ attr_accessor :actions
7
+ attr_accessor :resources
8
+ attr_accessor :links
9
+
10
+ def initialize(kinds=[], mixins=[], actions=[], resources=[], links=[])
11
+ @kinds = kinds
12
+ @mixins = mixins
13
+ @actions = actions
14
+ @resources = resources
15
+ @links = links
16
+ end
17
+
18
+ def categories
19
+ @kinds + @mixins + @actions
20
+ end
21
+
22
+ def entities
23
+ @resources + @links
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,135 @@
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 Core Entity
19
+ # Author(s): Hayati Bice, Florian Feldhaus, Piotr Kasprzak
20
+ ##############################################################################
21
+
22
+ require 'rubygems'
23
+ require 'uuidtools'
24
+ require 'hashie'
25
+ require 'occi/registry'
26
+ require 'occi/core/attributes'
27
+ require 'occi/core/kind'
28
+ require 'occi/core/attribute_properties'
29
+
30
+ module OCCI
31
+ module Core
32
+ class Entity < Hashie::Mash
33
+
34
+ # Define appropriate kind
35
+ def self.register
36
+ data = Hashie::Mash.new
37
+ data[:term] = "entity"
38
+ data[:scheme] = "http://schemas.ogf.org/occi/core#"
39
+ data[:title] = "Entity"
40
+ data.attributes!.occi!.core!.id!.type = "string"
41
+ data.attributes!.occi!.core!.id!.pattern = "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}"
42
+ data.attributes!.occi!.core!.id!.required = false
43
+ data.attributes!.occi!.core!.id!.mutable = false
44
+ data.attributes!.occi!.core!.title!.type = "string"
45
+ data.attributes!.occi!.core!.title!.pattern = ".*"
46
+ data.attributes!.occi!.core!.title!.required = false
47
+ data.attributes!.occi!.core!.title!.mutable = true
48
+
49
+ kind = OCCI::Core::Kind.new(data)
50
+ OCCI::Registry.register(kind)
51
+ end
52
+
53
+ def initialize(entity=nil, default = nil)
54
+ super(entity, default)
55
+ self.check
56
+ end
57
+
58
+ def id
59
+ return self[:id]
60
+ end
61
+
62
+ def id=(id)
63
+ self[:id] = id
64
+ self.attributes!.occi!.core!.id = id
65
+ end
66
+
67
+ def title
68
+ return self[:title]
69
+ end
70
+
71
+ def title=(title)
72
+ self[:title] = title
73
+ self.attributes!.occi!.core!.title = title
74
+ end
75
+
76
+ def location
77
+ '/' + OCCI::Registry.get_by_id(self.kind).term + '/' + self.id if self.kind
78
+ end
79
+
80
+ def type_identifier
81
+ OCCI::Registry.get_by_id(self.kind).type_identifier
82
+ end
83
+
84
+ def check
85
+ definitions = OCCI::Registry.get_by_id(self.kind).attributes if self.kind
86
+ self.mixins.each { |mixin| definitions.merge!(OCCI::Registry.get_by_id(mixin).attributes) if OCCI::Registry.get_by_id(mixin).attributes } if self.mixins
87
+ self.attributes = Entity.check(self.attributes, definitions) if definitions
88
+ end
89
+
90
+ def self.check(attributes, definitions)
91
+ attributes = OCCI::Core::Attributes.new(attributes)
92
+ definitions.each_key do |key|
93
+ properties = definitions[key]
94
+ value = attributes[key] ||= properties[:default]
95
+ if properties.include?(:type)
96
+ raise "required attribute #{key} not found" if value.nil? && properties.required
97
+ next if value.nil? && !properties.required
98
+ case properties.type
99
+ when 'string'
100
+ raise "attribute #{key} with value #{value} from class #{value.class.name} does not match attribute property type #{properties.type}" unless value.kind_of?(String)
101
+ raise "attribute #{key} with length #{value.length} not in range #{properties.minimum}-#{properties.maximum}" unless (properties.minimum..properties.maximum) === value.length if properties.minimum && properties.maximum
102
+ when 'number'
103
+ raise "attribute #{key} value #{value} from class #{value.class.name} does not match attribute property type #{properties.type}" unless value.kind_of?(Numeric)
104
+ raise "attribute #{key} with value #{value} not in range #{properties.minimum}-#{properties.maximum}" unless (properties.minimum..properties.maximum) === value if properties.minimum && properties.maximum
105
+ when 'boolean'
106
+ raise "attribute #{key} value #{value} from class #{value.class.name} does not match attribute property type #{properties.type}" unless !!value == value
107
+ end
108
+ raise "attribute #{key} with value #{value} does not match pattern #{properties.pattern}" if value.to_s.scan(Regexp.new(properties.pattern)).empty? if properties.pattern
109
+ attributes[key] = value
110
+ else
111
+ attributes[key] = check(value, definitions[key])
112
+ end
113
+ end
114
+ attributes.delete_if { |k, v| v.nil? } # remove empty attributes
115
+ return attributes
116
+ end
117
+
118
+ def convert_value(val, duping=false) #:nodoc:
119
+ case val
120
+ when self.class
121
+ val.dup
122
+ when ::Hash
123
+ val = val.dup if duping
124
+ self.class.subkey_class.new.merge(val) unless val.kind_of?(Hashie::Mash)
125
+ val
126
+ when Array
127
+ val.collect { |e| convert_value(e) }
128
+ else
129
+ val
130
+ end
131
+ end
132
+
133
+ end
134
+ end
135
+ end