opennebula 3.9.80.beta

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 (42) hide show
  1. data/LICENSE +202 -0
  2. data/NOTICE +47 -0
  3. data/lib/opennebula.rb +58 -0
  4. data/lib/opennebula/acl.rb +266 -0
  5. data/lib/opennebula/acl_pool.rb +55 -0
  6. data/lib/opennebula/client.rb +119 -0
  7. data/lib/opennebula/cluster.rb +249 -0
  8. data/lib/opennebula/cluster_pool.rb +58 -0
  9. data/lib/opennebula/datastore.rb +171 -0
  10. data/lib/opennebula/datastore_pool.rb +55 -0
  11. data/lib/opennebula/document.rb +261 -0
  12. data/lib/opennebula/document_json.rb +131 -0
  13. data/lib/opennebula/document_pool.rb +102 -0
  14. data/lib/opennebula/document_pool_json.rb +58 -0
  15. data/lib/opennebula/error.rb +52 -0
  16. data/lib/opennebula/group.rb +163 -0
  17. data/lib/opennebula/group_pool.rb +56 -0
  18. data/lib/opennebula/host.rb +201 -0
  19. data/lib/opennebula/host_pool.rb +93 -0
  20. data/lib/opennebula/image.rb +297 -0
  21. data/lib/opennebula/image_pool.rb +79 -0
  22. data/lib/opennebula/ldap_auth.rb +99 -0
  23. data/lib/opennebula/ldap_auth_spec.rb +70 -0
  24. data/lib/opennebula/pool.rb +160 -0
  25. data/lib/opennebula/pool_element.rb +269 -0
  26. data/lib/opennebula/server_cipher_auth.rb +148 -0
  27. data/lib/opennebula/server_x509_auth.rb +104 -0
  28. data/lib/opennebula/ssh_auth.rb +139 -0
  29. data/lib/opennebula/system.rb +141 -0
  30. data/lib/opennebula/template.rb +213 -0
  31. data/lib/opennebula/template_pool.rb +79 -0
  32. data/lib/opennebula/user.rb +174 -0
  33. data/lib/opennebula/user_pool.rb +55 -0
  34. data/lib/opennebula/virtual_machine.rb +560 -0
  35. data/lib/opennebula/virtual_machine_pool.rb +323 -0
  36. data/lib/opennebula/virtual_network.rb +249 -0
  37. data/lib/opennebula/virtual_network_pool.rb +79 -0
  38. data/lib/opennebula/x509_auth.rb +288 -0
  39. data/lib/opennebula/xml_element.rb +427 -0
  40. data/lib/opennebula/xml_pool.rb +45 -0
  41. data/lib/opennebula/xml_utils.rb +34 -0
  42. metadata +118 -0
@@ -0,0 +1,55 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
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
+
53
+ alias_method :info!, :info
54
+ end
55
+ end
@@ -0,0 +1,119 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
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
+ require 'xmlrpc/client'
18
+
19
+ module OpenNebula
20
+ if OpenNebula::NOKOGIRI
21
+ class NokogiriStreamParser < XMLRPC::XMLParser::AbstractStreamParser
22
+ def initialize
23
+ @parser_class = NokogiriParser
24
+ end
25
+
26
+ class NokogiriParser < Nokogiri::XML::SAX::Document
27
+ include XMLRPC::XMLParser::StreamParserMixin
28
+
29
+ alias :cdata_block :character
30
+ alias :characters :character
31
+ alias :end_element :endElement
32
+ alias :start_element :startElement
33
+
34
+ def parse(str)
35
+ parser = Nokogiri::XML::SAX::Parser.new(self)
36
+ parser.parse(str)
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ # The client class, represents the connection with the core and handles the
43
+ # xml-rpc calls.
44
+ class Client
45
+ attr_accessor :one_auth
46
+
47
+ begin
48
+ require 'xmlparser'
49
+ XMLPARSER=true
50
+ rescue LoadError
51
+ XMLPARSER=false
52
+ end
53
+
54
+ # Creates a new client object that will be used to call OpenNebula
55
+ # functions.
56
+ #
57
+ # @param [String, nil] secret user credentials ("user:password") or
58
+ # nil to get the credentials from user auth file
59
+ # @param [String, nil] endpoint OpenNebula server endpoint
60
+ # (http://host:2633/RPC2) or nil to get it form the environment
61
+ # variable ONE_XMLRPC or use the default endpoint
62
+ # @param [Hash] options
63
+ # @option params [Integer] :timeout connection timeout in seconds,
64
+ # defaults to 30
65
+ #
66
+ # @return [OpenNebula::Client]
67
+ def initialize(secret=nil, endpoint=nil, options={})
68
+ if secret
69
+ @one_auth = secret
70
+ elsif ENV["ONE_AUTH"] and !ENV["ONE_AUTH"].empty? and
71
+ File.file?(ENV["ONE_AUTH"])
72
+ @one_auth = File.read(ENV["ONE_AUTH"])
73
+ elsif File.file?(ENV["HOME"]+"/.one/one_auth")
74
+ @one_auth = File.read(ENV["HOME"]+"/.one/one_auth")
75
+ else
76
+ raise "ONE_AUTH file not present"
77
+ end
78
+
79
+ @one_auth.rstrip!
80
+
81
+ if endpoint
82
+ @one_endpoint = endpoint
83
+ elsif ENV["ONE_XMLRPC"]
84
+ @one_endpoint = ENV["ONE_XMLRPC"]
85
+ else
86
+ @one_endpoint = "http://localhost:2633/RPC2"
87
+ end
88
+
89
+ timeout=nil
90
+ timeout=options[:timeout] if options[:timeout]
91
+
92
+ @server = XMLRPC::Client.new2(@one_endpoint, nil, timeout)
93
+
94
+ if OpenNebula::NOKOGIRI
95
+ @server.set_parser(NokogiriStreamParser.new)
96
+ elsif XMLPARSER
97
+ @server.set_parser(XMLRPC::XMLParser::XMLStreamParser.new)
98
+ end
99
+ end
100
+
101
+ def call(action, *args)
102
+ begin
103
+ response = @server.call_async("one."+action, @one_auth, *args)
104
+
105
+ if response[0] == false
106
+ Error.new(response[1], response[2])
107
+ else
108
+ response[1] #response[1..-1]
109
+ end
110
+ rescue Exception => e
111
+ Error.new(e.message)
112
+ end
113
+ end
114
+
115
+ def get_version()
116
+ call("system.version")
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,249 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
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_element'
19
+
20
+ module OpenNebula
21
+ class Cluster < PoolElement
22
+ #######################################################################
23
+ # Constants and Class Methods
24
+ #######################################################################
25
+
26
+ CLUSTER_METHODS = {
27
+ :info => "cluster.info",
28
+ :allocate => "cluster.allocate",
29
+ :delete => "cluster.delete",
30
+ :addhost => "cluster.addhost",
31
+ :delhost => "cluster.delhost",
32
+ :adddatastore => "cluster.adddatastore",
33
+ :deldatastore => "cluster.deldatastore",
34
+ :addvnet => "cluster.addvnet",
35
+ :delvnet => "cluster.delvnet",
36
+ :update => "cluster.update",
37
+ }
38
+
39
+ # Creates a Cluster description with just its identifier
40
+ # this method should be used to create plain Cluster objects.
41
+ # +id+ the id of the host
42
+ #
43
+ # Example:
44
+ # cluster = Cluster.new(Cluster.build_xml(3),rpc_client)
45
+ #
46
+ def Cluster.build_xml(pe_id=nil)
47
+ if pe_id
48
+ cluster_xml = "<CLUSTER><ID>#{pe_id}</ID></CLUSTER>"
49
+ else
50
+ cluster_xml = "<CLUSTER></CLUSTER>"
51
+ end
52
+
53
+ XMLElement.build_xml(cluster_xml,'CLUSTER')
54
+ end
55
+
56
+ # Class constructor
57
+ def initialize(xml, client)
58
+ super(xml,client)
59
+ end
60
+
61
+ #######################################################################
62
+ # XML-RPC Methods for the Cluster Object
63
+ #######################################################################
64
+
65
+ # Retrieves the information of the given Cluster.
66
+ def info()
67
+ super(CLUSTER_METHODS[:info], 'CLUSTER')
68
+ end
69
+
70
+ alias_method :info!, :info
71
+
72
+ # Allocates a new Cluster in OpenNebula
73
+ #
74
+ # +clustername+ A string containing the name of the Cluster.
75
+ def allocate(clustername)
76
+ super(CLUSTER_METHODS[:allocate], clustername)
77
+ end
78
+
79
+ # Deletes the Cluster
80
+ def delete()
81
+ super(CLUSTER_METHODS[:delete])
82
+ end
83
+
84
+ # Adds a Host to this Cluster
85
+ # @param hid [Integer] Host ID
86
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
87
+ # otherwise
88
+ def addhost(hid)
89
+ return Error.new('ID not defined') if !@pe_id
90
+
91
+ rc = @client.call(CLUSTER_METHODS[:addhost], @pe_id, hid)
92
+ rc = nil if !OpenNebula.is_error?(rc)
93
+
94
+ return rc
95
+ end
96
+
97
+ # Deletes a Host from this Cluster
98
+ # @param hid [Integer] Host ID
99
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
100
+ # otherwise
101
+ def delhost(hid)
102
+ return Error.new('ID not defined') if !@pe_id
103
+
104
+ rc = @client.call(CLUSTER_METHODS[:delhost], @pe_id, hid)
105
+ rc = nil if !OpenNebula.is_error?(rc)
106
+
107
+ return rc
108
+ end
109
+
110
+ # Adds a Datastore to this Cluster
111
+ # @param ds_id [Integer] Datastore ID
112
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
113
+ # otherwise
114
+ def adddatastore(ds_id)
115
+ return Error.new('ID not defined') if !@pe_id
116
+
117
+ rc = @client.call(CLUSTER_METHODS[:adddatastore], @pe_id, ds_id)
118
+ rc = nil if !OpenNebula.is_error?(rc)
119
+
120
+ return rc
121
+ end
122
+
123
+ # Deletes a Datastore from this Cluster
124
+ # @param ds_id [Integer] Datastore ID
125
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
126
+ # otherwise
127
+ def deldatastore(ds_id)
128
+ return Error.new('ID not defined') if !@pe_id
129
+
130
+ rc = @client.call(CLUSTER_METHODS[:deldatastore], @pe_id, ds_id)
131
+ rc = nil if !OpenNebula.is_error?(rc)
132
+
133
+ return rc
134
+ end
135
+
136
+ # Adds a VNet to this Cluster
137
+ # @param vnet_id [Integer] VNet ID
138
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
139
+ # otherwise
140
+ def addvnet(vnet_id)
141
+ return Error.new('ID not defined') if !@pe_id
142
+
143
+ rc = @client.call(CLUSTER_METHODS[:addvnet], @pe_id, vnet_id)
144
+ rc = nil if !OpenNebula.is_error?(rc)
145
+
146
+ return rc
147
+ end
148
+
149
+ # Deletes a VNet from this Cluster
150
+ # @param vnet_id [Integer] VNet ID
151
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
152
+ # otherwise
153
+ def delvnet(vnet_id)
154
+ return Error.new('ID not defined') if !@pe_id
155
+
156
+ rc = @client.call(CLUSTER_METHODS[:delvnet], @pe_id, vnet_id)
157
+ rc = nil if !OpenNebula.is_error?(rc)
158
+
159
+ return rc
160
+ end
161
+
162
+ # Replaces the template contents
163
+ #
164
+ # @param new_template [String] New template contents
165
+ #
166
+ # @return [nil, OpenNebula::Error] nil in case of success, Error
167
+ # otherwise
168
+ def update(new_template)
169
+ super(CLUSTER_METHODS[:update], new_template)
170
+ end
171
+
172
+ # ---------------------------------------------------------------------
173
+ # Helpers to get information
174
+ # ---------------------------------------------------------------------
175
+
176
+ # Returns whether or not the host with 'id' is part of this cluster
177
+ # @param id [Integer|Array] host ID
178
+ # @return [Boolean] true if found
179
+ def contains_host?(id)
180
+ contains_resource?('HOSTS/ID', id)
181
+ end
182
+
183
+ # Returns an array with the numeric host ids
184
+ # @return [Array<Integer>]
185
+ def host_ids
186
+ array = Array.new
187
+
188
+ self.each("HOSTS/ID") do |id|
189
+ array << id.text.to_i
190
+ end
191
+
192
+ return array
193
+ end
194
+
195
+ # Returns whether or not the datastore with 'id' is part of this cluster
196
+ # @param id [Integer|Array] datastore ID
197
+ # @return [Boolean] true if found
198
+ def contains_datastore?(id)
199
+ contains_resource?('DATASTORES/ID', id)
200
+ end
201
+
202
+ # Returns an array with the numeric datastore ids
203
+ # @return [Array<Integer>]
204
+ def datastore_ids
205
+ array = Array.new
206
+
207
+ self.each("DATASTORES/ID") do |id|
208
+ array << id.text.to_i
209
+ end
210
+
211
+ return array
212
+ end
213
+
214
+ # Returns whether or not the vnet with 'id' is part of this cluster
215
+ # @param id [Integer|Arrray] vnet ID
216
+ # @return [Boolean] true if found
217
+ def contains_vnet?(id)
218
+ contains_resource?('VNETS/ID', id)
219
+ end
220
+
221
+ # Returns an array with the numeric vnet ids
222
+ # @return [Array<Integer>]
223
+ def vnet_ids
224
+ array = Array.new
225
+
226
+ self.each("VNETS/ID") do |id|
227
+ array << id.text.to_i
228
+ end
229
+
230
+ return array
231
+ end
232
+
233
+ private
234
+
235
+ def contains_resource?(xpath, id)
236
+ id_array = retrieve_elements(xpath)
237
+
238
+ return false if id_array.nil?
239
+
240
+ id = [id] if id.class != Array
241
+
242
+ id.each { |i|
243
+ return false if !id_array.include?(i.to_s)
244
+ }
245
+
246
+ return true
247
+ end
248
+ end
249
+ end
@@ -0,0 +1,58 @@
1
+ # -------------------------------------------------------------------------- #
2
+ # Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
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 ClusterPool < Pool
22
+ #######################################################################
23
+ # Constants and Class attribute accessors
24
+ #######################################################################
25
+
26
+ NONE_CLUSTER_ID = -1
27
+ DEFAULT_CLUSTER_ID = 0
28
+
29
+ CLUSTER_POOL_METHODS = {
30
+ :info => "clusterpool.info"
31
+ }
32
+
33
+ #######################################################################
34
+ # Class constructor & Pool Methods
35
+ #######################################################################
36
+
37
+ # +client+ a Client object that represents a XML-RPC connection
38
+ def initialize(client)
39
+ super('CLUSTER_POOL','CLUSTER',client)
40
+ end
41
+
42
+ # Factory method to create Cluster objects
43
+ def factory(element_xml)
44
+ OpenNebula::Cluster.new(element_xml,@client)
45
+ end
46
+
47
+ #######################################################################
48
+ # XML-RPC Methods for the Cluster Object
49
+ #######################################################################
50
+
51
+ # Retrieves all the Clusters in the pool.
52
+ def info()
53
+ super(CLUSTER_POOL_METHODS[:info])
54
+ end
55
+
56
+ alias_method :info!, :info
57
+ end
58
+ end