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,53 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
3
+ # #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
+ # not use this file except in compliance with the License. You may obtain #
6
+ # 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
+ require 'OpenNebula/Pool'
19
+
20
+ module OpenNebula
21
+ class AclPool < Pool
22
+
23
+ #######################################################################
24
+ # Constants and Class Methods
25
+ #######################################################################
26
+
27
+
28
+ ACL_POOL_METHODS = {
29
+ :info => "acl.info",
30
+ :addrule => "acl.addrule",
31
+ :delrule => "acl.delrule"
32
+ }
33
+
34
+ # Class constructor
35
+ def initialize(client)
36
+ super('ACL_POOL','ACL',client)
37
+ end
38
+
39
+ def factory(element_xml)
40
+ OpenNebula::Acl.new(element_xml, @client)
41
+ end
42
+
43
+ #######################################################################
44
+ # XML-RPC Methods
45
+ #######################################################################
46
+
47
+ # Retrieves the ACL Pool
48
+ def info()
49
+ # Retrieves all the Acls in the pool.
50
+ super(ACL_POOL_METHODS[:info])
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,147 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
3
+ # #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
+ # not use this file except in compliance with the License. You may obtain #
6
+ # 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
+ require 'OpenNebula/Pool'
19
+
20
+ module OpenNebula
21
+ class Group < PoolElement
22
+ #######################################################################
23
+ # Constants and Class Methods
24
+ #######################################################################
25
+
26
+
27
+ GROUP_METHODS = {
28
+ :info => "group.info",
29
+ :allocate => "group.allocate",
30
+ :delete => "group.delete"
31
+ }
32
+
33
+ # Flag for requesting connected user's group info
34
+ SELF = -1
35
+
36
+ #Default location for group ACL's
37
+ if ENV['ONE_LOCATION']
38
+ GROUP_DEFAULT = ENV['ONE_LOCATION'] + "/etc/group.default"
39
+ else
40
+ GROUP_DEFAULT = "/etc/one/group.default"
41
+ end
42
+
43
+ # Creates a Group description with just its identifier
44
+ # this method should be used to create plain Group objects.
45
+ # +id+ the id of the user
46
+ #
47
+ # Example:
48
+ # group = Group.new(Group.build_xml(3),rpc_client)
49
+ #
50
+ def Group.build_xml(pe_id=nil)
51
+ if pe_id
52
+ group_xml = "<GROUP><ID>#{pe_id}</ID></GROUP>"
53
+ else
54
+ group_xml = "<GROUP></GROUP>"
55
+ end
56
+
57
+ XMLElement.build_xml(group_xml,'GROUP')
58
+ end
59
+
60
+ # Class constructor
61
+ def initialize(xml, client)
62
+ super(xml,client)
63
+ end
64
+
65
+ #######################################################################
66
+ # Group utils
67
+ #######################################################################
68
+
69
+ # Creates ACLs for the group. The ACL rules are described in a file
70
+ def create_acls(filename = GROUP_DEFAULT)
71
+ if !File.readable?(filename)
72
+ return -1, "Can not read deafult ACL file for group"
73
+ end
74
+
75
+ msg = String.new
76
+
77
+ File.open(filename).each_line{ |l|
78
+ next if l.match(/^#/)
79
+
80
+ rule = "@#{@pe_id} #{l}"
81
+ parse = OpenNebula::Acl.parse_rule(rule)
82
+
83
+ if OpenNebula.is_error?(parse)
84
+ return -1, "Error parsing rule #{rule}: #{parse.message}"
85
+ end
86
+
87
+ xml = OpenNebula::Acl.build_xml
88
+ acl = OpenNebula::Acl.new(xml, @client)
89
+
90
+ rc = acl.allocate(*parse)
91
+
92
+ if OpenNebula.is_error?(rc)
93
+ return -1, "Error creating rule #{rule}: #{rc.message}"
94
+ else
95
+ msg << "ACL_ID: #{acl.id}\n"
96
+ end
97
+ }
98
+
99
+ return 0, msg
100
+ end
101
+
102
+ #######################################################################
103
+ # XML-RPC Methods for the Group Object
104
+ #######################################################################
105
+
106
+ # Retrieves the information of the given Group.
107
+ def info()
108
+ super(GROUP_METHODS[:info], 'GROUP')
109
+ end
110
+
111
+ # Allocates a new Group in OpenNebula
112
+ #
113
+ # +groupname+ A string containing the name of the Group.
114
+ def allocate(groupname)
115
+ super(GROUP_METHODS[:allocate], groupname)
116
+ end
117
+
118
+ # Deletes the Group
119
+ def delete()
120
+ super(GROUP_METHODS[:delete])
121
+ end
122
+
123
+ # ---------------------------------------------------------------------
124
+ # Helpers to get information
125
+ # ---------------------------------------------------------------------
126
+
127
+ # Returns whether or not the user with id 'uid' is part of this group
128
+ def contains(uid)
129
+ #This doesn't work in ruby 1.8.5
130
+ #return self["USERS/ID[.=#{uid}]"] != nil
131
+
132
+ id_array = retrieve_elements('USERS/ID')
133
+ return id_array != nil && id_array.include?(uid.to_s)
134
+ end
135
+
136
+ # Returns an array with the numeric user ids
137
+ def user_ids
138
+ array = Array.new
139
+
140
+ self.each("USERS/ID") do |id|
141
+ array << id.text.to_i
142
+ end
143
+
144
+ return array
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,54 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
3
+ # #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
+ # not use this file except in compliance with the License. You may obtain #
6
+ # 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
+ require 'OpenNebula/Pool'
19
+
20
+ module OpenNebula
21
+ class GroupPool < Pool
22
+ #######################################################################
23
+ # Constants and Class attribute accessors
24
+ #######################################################################
25
+
26
+
27
+ GROUP_POOL_METHODS = {
28
+ :info => "grouppool.info"
29
+ }
30
+
31
+ #######################################################################
32
+ # Class constructor & Pool Methods
33
+ #######################################################################
34
+
35
+ # +client+ a Client object that represents a XML-RPC connection
36
+ def initialize(client)
37
+ super('GROUP_POOL','GROUP',client)
38
+ end
39
+
40
+ # Factory method to create User objects
41
+ def factory(element_xml)
42
+ OpenNebula::Group.new(element_xml,@client)
43
+ end
44
+
45
+ #######################################################################
46
+ # XML-RPC Methods for the User Object
47
+ #######################################################################
48
+
49
+ # Retrieves all the Groups in the pool.
50
+ def info()
51
+ super(GROUP_POOL_METHODS[:info])
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,143 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
3
+ # #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
+ # not use this file except in compliance with the License. You may obtain #
6
+ # 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
+ require 'OpenNebula/Pool'
19
+
20
+ module OpenNebula
21
+ class Host < PoolElement
22
+ #######################################################################
23
+ # Constants and Class Methods
24
+ #######################################################################
25
+
26
+
27
+ HOST_METHODS = {
28
+ :info => "host.info",
29
+ :allocate => "host.allocate",
30
+ :delete => "host.delete",
31
+ :enable => "host.enable",
32
+ :update => "host.update"
33
+ }
34
+
35
+ HOST_STATES=%w{INIT MONITORING MONITORED ERROR DISABLED}
36
+
37
+ SHORT_HOST_STATES={
38
+ "INIT" => "on",
39
+ "MONITORING" => "on",
40
+ "MONITORED" => "on",
41
+ "ERROR" => "err",
42
+ "DISABLED" => "off"
43
+ }
44
+
45
+ # Creates a Host description with just its identifier
46
+ # this method should be used to create plain Host objects.
47
+ # +id+ the id of the host
48
+ #
49
+ # Example:
50
+ # host = Host.new(Host.build_xml(3),rpc_client)
51
+ #
52
+ def Host.build_xml(pe_id=nil)
53
+ if pe_id
54
+ host_xml = "<HOST><ID>#{pe_id}</ID></HOST>"
55
+ else
56
+ host_xml = "<HOST></HOST>"
57
+ end
58
+
59
+ XMLElement.build_xml(host_xml, 'HOST')
60
+ end
61
+
62
+ # Class constructor
63
+ def initialize(xml, client)
64
+ super(xml,client)
65
+
66
+ @client = client
67
+ @pe_id = self['ID'].to_i if self['ID']
68
+ end
69
+
70
+ #######################################################################
71
+ # XML-RPC Methods for the Host
72
+ #######################################################################
73
+
74
+ # Retrieves the information of the given Host.
75
+ def info()
76
+ super(HOST_METHODS[:info], 'HOST')
77
+ end
78
+
79
+ # Allocates a new Host in OpenNebula
80
+ #
81
+ # @param hostname [String] Name of the new Host.
82
+ # @param im [String] Name of the im_driver
83
+ # @param vmm [String] Name of the vmm_driver
84
+ # @param tm [String] Name of the tm_driver
85
+ #
86
+ # @return [Integer, OpenNebula::Error] the new VM ID in case of
87
+ # success, error otherwise
88
+ def allocate(hostname,im,vmm,vnm,tm)
89
+ super(HOST_METHODS[:allocate],hostname,im,vmm,vnm,tm)
90
+ end
91
+
92
+ # Deletes the Host
93
+ def delete()
94
+ super(HOST_METHODS[:delete])
95
+ end
96
+
97
+ # Enables the Host
98
+ def enable()
99
+ set_enabled(true)
100
+ end
101
+
102
+ # Disables the Host
103
+ def disable()
104
+ set_enabled(false)
105
+ end
106
+
107
+ # Replaces the template contents
108
+ #
109
+ # +new_template+ New template contents
110
+ def update(new_template)
111
+ super(HOST_METHODS[:update], new_template)
112
+ end
113
+
114
+ #######################################################################
115
+ # Helpers to get Host information
116
+ #######################################################################
117
+
118
+ # Returns the state of the Host (numeric value)
119
+ def state
120
+ self['STATE'].to_i
121
+ end
122
+
123
+ # Returns the state of the Host (string value)
124
+ def state_str
125
+ HOST_STATES[state]
126
+ end
127
+
128
+ # Returns the state of the Host (string value)
129
+ def short_state_str
130
+ SHORT_HOST_STATES[state_str]
131
+ end
132
+
133
+ private
134
+ def set_enabled(enabled)
135
+ return Error.new('ID not defined') if !@pe_id
136
+
137
+ rc = @client.call(HOST_METHODS[:enable], @pe_id, enabled)
138
+ rc = nil if !OpenNebula.is_error?(rc)
139
+
140
+ return rc
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,55 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) #
3
+ # #
4
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
+ # not use this file except in compliance with the License. You may obtain #
6
+ # 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
+ require 'OpenNebula/Pool'
19
+
20
+ module OpenNebula
21
+ class HostPool < Pool
22
+ #######################################################################
23
+ # Constants and Class attribute accessors
24
+ #######################################################################
25
+
26
+
27
+ HOST_POOL_METHODS = {
28
+ :info => "hostpool.info"
29
+ }
30
+
31
+ #######################################################################
32
+ # Class constructor & Pool Methods
33
+ #######################################################################
34
+
35
+
36
+ # +client+ a Client object that represents a XML-RPC connection
37
+ def initialize(client)
38
+ super('HOST_POOL','HOST',client)
39
+ end
40
+
41
+ # Factory Method for the Host Pool
42
+ def factory(element_xml)
43
+ OpenNebula::Host.new(element_xml,@client)
44
+ end
45
+
46
+ #######################################################################
47
+ # XML-RPC Methods for the Host Pool
48
+ #######################################################################
49
+
50
+ # Retrieves all the Hosts in the pool.
51
+ def info()
52
+ super(HOST_POOL_METHODS[:info])
53
+ end
54
+ end
55
+ end