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.
- data/LICENSE +202 -0
- data/NOTICE +47 -0
- data/lib/opennebula.rb +58 -0
- data/lib/opennebula/acl.rb +266 -0
- data/lib/opennebula/acl_pool.rb +55 -0
- data/lib/opennebula/client.rb +119 -0
- data/lib/opennebula/cluster.rb +249 -0
- data/lib/opennebula/cluster_pool.rb +58 -0
- data/lib/opennebula/datastore.rb +171 -0
- data/lib/opennebula/datastore_pool.rb +55 -0
- data/lib/opennebula/document.rb +261 -0
- data/lib/opennebula/document_json.rb +131 -0
- data/lib/opennebula/document_pool.rb +102 -0
- data/lib/opennebula/document_pool_json.rb +58 -0
- data/lib/opennebula/error.rb +52 -0
- data/lib/opennebula/group.rb +163 -0
- data/lib/opennebula/group_pool.rb +56 -0
- data/lib/opennebula/host.rb +201 -0
- data/lib/opennebula/host_pool.rb +93 -0
- data/lib/opennebula/image.rb +297 -0
- data/lib/opennebula/image_pool.rb +79 -0
- data/lib/opennebula/ldap_auth.rb +99 -0
- data/lib/opennebula/ldap_auth_spec.rb +70 -0
- data/lib/opennebula/pool.rb +160 -0
- data/lib/opennebula/pool_element.rb +269 -0
- data/lib/opennebula/server_cipher_auth.rb +148 -0
- data/lib/opennebula/server_x509_auth.rb +104 -0
- data/lib/opennebula/ssh_auth.rb +139 -0
- data/lib/opennebula/system.rb +141 -0
- data/lib/opennebula/template.rb +213 -0
- data/lib/opennebula/template_pool.rb +79 -0
- data/lib/opennebula/user.rb +174 -0
- data/lib/opennebula/user_pool.rb +55 -0
- data/lib/opennebula/virtual_machine.rb +560 -0
- data/lib/opennebula/virtual_machine_pool.rb +323 -0
- data/lib/opennebula/virtual_network.rb +249 -0
- data/lib/opennebula/virtual_network_pool.rb +79 -0
- data/lib/opennebula/x509_auth.rb +288 -0
- data/lib/opennebula/xml_element.rb +427 -0
- data/lib/opennebula/xml_pool.rb +45 -0
- data/lib/opennebula/xml_utils.rb +34 -0
- metadata +118 -0
@@ -0,0 +1,56 @@
|
|
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 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
|
+
|
54
|
+
alias_method :info!, :info
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,201 @@
|
|
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 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
|
+
:monitoring => "host.monitoring"
|
34
|
+
}
|
35
|
+
|
36
|
+
HOST_STATES=%w{INIT MONITORING_MONITORED MONITORED ERROR DISABLED MONITORING_ERROR}
|
37
|
+
|
38
|
+
SHORT_HOST_STATES={
|
39
|
+
"INIT" => "init",
|
40
|
+
"MONITORING_MONITORED" => "update",
|
41
|
+
"MONITORED" => "on",
|
42
|
+
"ERROR" => "err",
|
43
|
+
"DISABLED" => "off",
|
44
|
+
"MONITORING_ERROR" => "retry",
|
45
|
+
}
|
46
|
+
|
47
|
+
# Creates a Host description with just its identifier
|
48
|
+
# this method should be used to create plain Host objects.
|
49
|
+
# +id+ the id of the host
|
50
|
+
#
|
51
|
+
# Example:
|
52
|
+
# host = Host.new(Host.build_xml(3),rpc_client)
|
53
|
+
#
|
54
|
+
def Host.build_xml(pe_id=nil)
|
55
|
+
if pe_id
|
56
|
+
host_xml = "<HOST><ID>#{pe_id}</ID></HOST>"
|
57
|
+
else
|
58
|
+
host_xml = "<HOST></HOST>"
|
59
|
+
end
|
60
|
+
|
61
|
+
XMLElement.build_xml(host_xml, 'HOST')
|
62
|
+
end
|
63
|
+
|
64
|
+
# Class constructor
|
65
|
+
def initialize(xml, client)
|
66
|
+
super(xml,client)
|
67
|
+
|
68
|
+
@client = client
|
69
|
+
@pe_id = self['ID'].to_i if self['ID']
|
70
|
+
end
|
71
|
+
|
72
|
+
#######################################################################
|
73
|
+
# XML-RPC Methods for the Host
|
74
|
+
#######################################################################
|
75
|
+
|
76
|
+
# Retrieves the information of the given Host.
|
77
|
+
def info()
|
78
|
+
super(HOST_METHODS[:info], 'HOST')
|
79
|
+
end
|
80
|
+
|
81
|
+
alias_method :info!, :info
|
82
|
+
|
83
|
+
# Allocates a new Host in OpenNebula
|
84
|
+
#
|
85
|
+
# @param hostname [String] Name of the new Host.
|
86
|
+
# @param im [String] Name of the im_driver (information/monitoring)
|
87
|
+
# @param vmm [String] Name of the vmm_driver (hypervisor)
|
88
|
+
# @param tm [String] Name of the vnm_driver (networking)
|
89
|
+
# @param cluster_id [String] Id of the cluster
|
90
|
+
#
|
91
|
+
# @return [Integer, OpenNebula::Error] the new ID in case of
|
92
|
+
# success, error otherwise
|
93
|
+
def allocate(hostname,im,vmm,vnm,cluster_id=ClusterPool::NONE_CLUSTER_ID)
|
94
|
+
super(HOST_METHODS[:allocate],hostname,im,vmm,vnm,cluster_id)
|
95
|
+
end
|
96
|
+
|
97
|
+
# Deletes the Host
|
98
|
+
def delete()
|
99
|
+
super(HOST_METHODS[:delete])
|
100
|
+
end
|
101
|
+
|
102
|
+
# Enables the Host
|
103
|
+
def enable()
|
104
|
+
set_enabled(true)
|
105
|
+
end
|
106
|
+
|
107
|
+
# Disables the Host
|
108
|
+
def disable()
|
109
|
+
set_enabled(false)
|
110
|
+
end
|
111
|
+
|
112
|
+
def flush()
|
113
|
+
self.disable
|
114
|
+
|
115
|
+
vm_pool = OpenNebula::VirtualMachinePool.new(@client,
|
116
|
+
VirtualMachinePool::INFO_ALL_VM)
|
117
|
+
|
118
|
+
rc = vm_pool.info
|
119
|
+
if OpenNebula.is_error?(rc)
|
120
|
+
puts rc.message
|
121
|
+
exit -1
|
122
|
+
end
|
123
|
+
|
124
|
+
vm_pool.each do |vm|
|
125
|
+
hid = vm['HISTORY_RECORDS/HISTORY[last()]/HID']
|
126
|
+
if hid == self['ID']
|
127
|
+
vm.resched
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
# Replaces the template contents
|
133
|
+
#
|
134
|
+
# +new_template+ New template contents
|
135
|
+
def update(new_template)
|
136
|
+
super(HOST_METHODS[:update], new_template)
|
137
|
+
end
|
138
|
+
|
139
|
+
# Retrieves this Host's monitoring data from OpenNebula
|
140
|
+
#
|
141
|
+
# @param [Array<String>] xpath_expressions Elements to retrieve.
|
142
|
+
#
|
143
|
+
# @return [Hash<String, Array<Array<int>>>, OpenNebula::Error] Hash with
|
144
|
+
# the requested xpath expressions, and an Array of 'timestamp, value'.
|
145
|
+
#
|
146
|
+
# @example
|
147
|
+
# host.monitoring( ['HOST_SHARE/FREE_CPU', 'HOST_SHARE/RUNNING_VMS'] )
|
148
|
+
#
|
149
|
+
# { "HOST_SHARE/RUNNING_VMS" =>
|
150
|
+
# [["1337266000", "1"],
|
151
|
+
# ["1337266044", "1"],
|
152
|
+
# ["1337266088", "3"]],
|
153
|
+
# "HOST_SHARE/FREE_CPU" =>
|
154
|
+
# [["1337266000", "800"],
|
155
|
+
# ["1337266044", "800"],
|
156
|
+
# ["1337266088", "800"]]
|
157
|
+
# }
|
158
|
+
def monitoring(xpath_expressions)
|
159
|
+
return super(HOST_METHODS[:monitoring], 'HOST',
|
160
|
+
'LAST_MON_TIME', xpath_expressions)
|
161
|
+
end
|
162
|
+
|
163
|
+
# Retrieves this Host's monitoring data from OpenNebula, in XML
|
164
|
+
#
|
165
|
+
# @return [String] Monitoring data, in XML
|
166
|
+
def monitoring_xml()
|
167
|
+
return Error.new('ID not defined') if !@pe_id
|
168
|
+
|
169
|
+
return @client.call(HOST_METHODS[:monitoring], @pe_id)
|
170
|
+
end
|
171
|
+
|
172
|
+
#######################################################################
|
173
|
+
# Helpers to get Host information
|
174
|
+
#######################################################################
|
175
|
+
|
176
|
+
# Returns the state of the Host (numeric value)
|
177
|
+
def state
|
178
|
+
self['STATE'].to_i
|
179
|
+
end
|
180
|
+
|
181
|
+
# Returns the state of the Host (string value)
|
182
|
+
def state_str
|
183
|
+
HOST_STATES[state]
|
184
|
+
end
|
185
|
+
|
186
|
+
# Returns the state of the Host (string value)
|
187
|
+
def short_state_str
|
188
|
+
SHORT_HOST_STATES[state_str]
|
189
|
+
end
|
190
|
+
|
191
|
+
private
|
192
|
+
def set_enabled(enabled)
|
193
|
+
return Error.new('ID not defined') if !@pe_id
|
194
|
+
|
195
|
+
rc = @client.call(HOST_METHODS[:enable], @pe_id, enabled)
|
196
|
+
rc = nil if !OpenNebula.is_error?(rc)
|
197
|
+
|
198
|
+
return rc
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
@@ -0,0 +1,93 @@
|
|
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 HostPool < Pool
|
22
|
+
#######################################################################
|
23
|
+
# Constants and Class attribute accessors
|
24
|
+
#######################################################################
|
25
|
+
|
26
|
+
|
27
|
+
HOST_POOL_METHODS = {
|
28
|
+
:info => "hostpool.info",
|
29
|
+
:monitoring => "hostpool.monitoring"
|
30
|
+
}
|
31
|
+
|
32
|
+
#######################################################################
|
33
|
+
# Class constructor & Pool Methods
|
34
|
+
#######################################################################
|
35
|
+
|
36
|
+
|
37
|
+
# +client+ a Client object that represents a XML-RPC connection
|
38
|
+
def initialize(client)
|
39
|
+
super('HOST_POOL','HOST',client)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Factory Method for the Host Pool
|
43
|
+
def factory(element_xml)
|
44
|
+
OpenNebula::Host.new(element_xml,@client)
|
45
|
+
end
|
46
|
+
|
47
|
+
#######################################################################
|
48
|
+
# XML-RPC Methods for the Host Pool
|
49
|
+
#######################################################################
|
50
|
+
|
51
|
+
# Retrieves all the Hosts in the pool.
|
52
|
+
def info()
|
53
|
+
super(HOST_POOL_METHODS[:info])
|
54
|
+
end
|
55
|
+
|
56
|
+
alias_method :info!, :info
|
57
|
+
|
58
|
+
# Retrieves the monitoring data for all the Hosts in the pool
|
59
|
+
#
|
60
|
+
# @param [Array<String>] xpath_expressions Elements to retrieve.
|
61
|
+
#
|
62
|
+
# @return [Hash<String, <Hash<String, Array<Array<int>>>>>,
|
63
|
+
# OpenNebula::Error] The first level hash uses the Host ID as keys,
|
64
|
+
# and as value a Hash with the requested xpath expressions,
|
65
|
+
# and an Array of 'timestamp, value'.
|
66
|
+
#
|
67
|
+
# @example
|
68
|
+
# host_pool.monitoring(
|
69
|
+
# ['HOST_SHARE/FREE_CPU',
|
70
|
+
# 'HOST_SHARE/RUNNING_VMS',
|
71
|
+
# 'TEMPLATE/CUSTOM_PROBE'] )
|
72
|
+
#
|
73
|
+
# {"1"=>
|
74
|
+
# {"TEMPLATE/CUSTOM_PROBE"=>[],
|
75
|
+
# "HOST_SHARE/FREE_CPU"=>[["1337609673", "800"]],
|
76
|
+
# "HOST_SHARE/RUNNING_VMS"=>[["1337609673", "3"]]},
|
77
|
+
# "0"=>
|
78
|
+
# {"TEMPLATE/CUSTOM_PROBE"=>[],
|
79
|
+
# "HOST_SHARE/FREE_CPU"=>[["1337609673", "800"]],
|
80
|
+
# "HOST_SHARE/RUNNING_VMS"=>[["1337609673", "3"]]}}
|
81
|
+
def monitoring(xpath_expressions)
|
82
|
+
return super(HOST_POOL_METHODS[:monitoring],
|
83
|
+
'HOST', 'LAST_MON_TIME', xpath_expressions)
|
84
|
+
end
|
85
|
+
|
86
|
+
# Retrieves the monitoring data for all the Hosts in the pool, in XML
|
87
|
+
#
|
88
|
+
# @return [String] VM monitoring data, in XML
|
89
|
+
def monitoring_xml()
|
90
|
+
return @client.call(HOST_POOL_METHODS[:monitoring])
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,297 @@
|
|
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
|
+
require 'fileutils'
|
20
|
+
|
21
|
+
module OpenNebula
|
22
|
+
class Image < PoolElement
|
23
|
+
#######################################################################
|
24
|
+
# Constants and Class Methods
|
25
|
+
#######################################################################
|
26
|
+
|
27
|
+
|
28
|
+
IMAGE_METHODS = {
|
29
|
+
:info => "image.info",
|
30
|
+
:allocate => "image.allocate",
|
31
|
+
:update => "image.update",
|
32
|
+
:enable => "image.enable",
|
33
|
+
:persistent => "image.persistent",
|
34
|
+
:delete => "image.delete",
|
35
|
+
:chown => "image.chown",
|
36
|
+
:chmod => "image.chmod",
|
37
|
+
:chtype => "image.chtype",
|
38
|
+
:clone => "image.clone",
|
39
|
+
:rename => "image.rename"
|
40
|
+
}
|
41
|
+
|
42
|
+
IMAGE_STATES=%w{INIT READY USED DISABLED LOCKED ERROR CLONE DELETE USED_PERS}
|
43
|
+
|
44
|
+
SHORT_IMAGE_STATES={
|
45
|
+
"INIT" => "init",
|
46
|
+
"READY" => "rdy",
|
47
|
+
"USED" => "used",
|
48
|
+
"DISABLED" => "disa",
|
49
|
+
"LOCKED" => "lock",
|
50
|
+
"ERROR" => "err",
|
51
|
+
"CLONE" => "clon",
|
52
|
+
"DELETE" => "dele",
|
53
|
+
"USED_PERS" => "used"
|
54
|
+
}
|
55
|
+
|
56
|
+
IMAGE_TYPES=%w{OS CDROM DATABLOCK KERNEL RAMDISK CONTEXT}
|
57
|
+
|
58
|
+
SHORT_IMAGE_TYPES={
|
59
|
+
"OS" => "OS",
|
60
|
+
"CDROM" => "CD",
|
61
|
+
"DATABLOCK" => "DB",
|
62
|
+
"KERNEL" => "KL",
|
63
|
+
"RAMDISK" => "RD",
|
64
|
+
"CONTEXT" => "CX"
|
65
|
+
}
|
66
|
+
|
67
|
+
DISK_TYPES=%w{FILE CD_ROM BLOCK RBD}
|
68
|
+
|
69
|
+
# Creates an Image description with just its identifier
|
70
|
+
# this method should be used to create plain Image objects.
|
71
|
+
# +id+ the id of the image
|
72
|
+
#
|
73
|
+
# Example:
|
74
|
+
# image = Image.new(Image.build_xml(3),rpc_client)
|
75
|
+
#
|
76
|
+
def Image.build_xml(pe_id=nil)
|
77
|
+
if pe_id
|
78
|
+
image_xml = "<IMAGE><ID>#{pe_id}</ID></IMAGE>"
|
79
|
+
else
|
80
|
+
image_xml = "<IMAGE></IMAGE>"
|
81
|
+
end
|
82
|
+
|
83
|
+
XMLElement.build_xml(image_xml,'IMAGE')
|
84
|
+
end
|
85
|
+
|
86
|
+
# Class constructor
|
87
|
+
def initialize(xml, client)
|
88
|
+
super(xml,client)
|
89
|
+
|
90
|
+
@client = client
|
91
|
+
end
|
92
|
+
|
93
|
+
#######################################################################
|
94
|
+
# XML-RPC Methods for the Image Object
|
95
|
+
#######################################################################
|
96
|
+
|
97
|
+
# Retrieves the information of the given Image.
|
98
|
+
def info()
|
99
|
+
super(IMAGE_METHODS[:info], 'IMAGE')
|
100
|
+
end
|
101
|
+
|
102
|
+
alias_method :info!, :info
|
103
|
+
|
104
|
+
# Allocates a new Image in OpenNebula
|
105
|
+
#
|
106
|
+
# @param description [String] A string containing the template of the Image.
|
107
|
+
# @param ds_id [Integer] the target datastore ID
|
108
|
+
#
|
109
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
110
|
+
# otherwise
|
111
|
+
def allocate(description, ds_id)
|
112
|
+
super(IMAGE_METHODS[:allocate],description, ds_id)
|
113
|
+
end
|
114
|
+
|
115
|
+
# Replaces the template contents
|
116
|
+
#
|
117
|
+
# +new_template+ New template contents. If no argument is provided
|
118
|
+
# the object will be updated using the @xml variable
|
119
|
+
def update(new_template=nil)
|
120
|
+
super(IMAGE_METHODS[:update], new_template)
|
121
|
+
end
|
122
|
+
|
123
|
+
# Enables an Image
|
124
|
+
def enable
|
125
|
+
set_enabled(true)
|
126
|
+
end
|
127
|
+
|
128
|
+
# Disables an Image
|
129
|
+
def disable
|
130
|
+
set_enabled(false)
|
131
|
+
end
|
132
|
+
|
133
|
+
# Publishes the Image, to be used by other users
|
134
|
+
def publish
|
135
|
+
set_publish(true)
|
136
|
+
end
|
137
|
+
|
138
|
+
# Unplubishes the Image
|
139
|
+
def unpublish
|
140
|
+
set_publish(false)
|
141
|
+
end
|
142
|
+
|
143
|
+
# Makes the Image persistent
|
144
|
+
def persistent
|
145
|
+
set_persistent(true)
|
146
|
+
end
|
147
|
+
|
148
|
+
# Makes the Image non persistent
|
149
|
+
def nonpersistent
|
150
|
+
set_persistent(false)
|
151
|
+
end
|
152
|
+
|
153
|
+
# Deletes the Image
|
154
|
+
def delete()
|
155
|
+
super(IMAGE_METHODS[:delete])
|
156
|
+
end
|
157
|
+
|
158
|
+
# Changes the owner/group
|
159
|
+
# uid:: _Integer_ the new owner id. Set to -1 to leave the current one
|
160
|
+
# gid:: _Integer_ the new group id. Set to -1 to leave the current one
|
161
|
+
# [return] nil in case of success or an Error object
|
162
|
+
def chown(uid, gid)
|
163
|
+
super(IMAGE_METHODS[:chown], uid, gid)
|
164
|
+
end
|
165
|
+
|
166
|
+
# Changes the Image permissions.
|
167
|
+
#
|
168
|
+
# @param octet [String] Permissions octed , e.g. 640
|
169
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
170
|
+
# otherwise
|
171
|
+
def chmod_octet(octet)
|
172
|
+
super(IMAGE_METHODS[:chmod], octet)
|
173
|
+
end
|
174
|
+
|
175
|
+
# Changes the Image permissions.
|
176
|
+
# Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change
|
177
|
+
#
|
178
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
179
|
+
# otherwise
|
180
|
+
def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
|
181
|
+
other_m, other_a)
|
182
|
+
super(IMAGE_METHODS[:chmod], owner_u, owner_m, owner_a, group_u,
|
183
|
+
group_m, group_a, other_u, other_m, other_a)
|
184
|
+
end
|
185
|
+
|
186
|
+
# Changes the Image type
|
187
|
+
# @param type [String] new Image type
|
188
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
189
|
+
# otherwise
|
190
|
+
def chtype(type)
|
191
|
+
return Error.new('ID not defined') if !@pe_id
|
192
|
+
|
193
|
+
rc = @client.call(IMAGE_METHODS[:chtype], @pe_id, type)
|
194
|
+
rc = nil if !OpenNebula.is_error?(rc)
|
195
|
+
|
196
|
+
return rc
|
197
|
+
end
|
198
|
+
|
199
|
+
# Clones this Image into a new one
|
200
|
+
#
|
201
|
+
# @param [String] name for the new Image.
|
202
|
+
#
|
203
|
+
# @return [Integer, OpenNebula::Error] The new Image ID in case
|
204
|
+
# of success, Error otherwise
|
205
|
+
def clone(name)
|
206
|
+
return Error.new('ID not defined') if !@pe_id
|
207
|
+
|
208
|
+
rc = @client.call(IMAGE_METHODS[:clone], @pe_id, name)
|
209
|
+
|
210
|
+
return rc
|
211
|
+
end
|
212
|
+
|
213
|
+
# Renames this Image
|
214
|
+
#
|
215
|
+
# @param name [String] New name for the Image.
|
216
|
+
#
|
217
|
+
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
218
|
+
# otherwise
|
219
|
+
def rename(name)
|
220
|
+
return call(IMAGE_METHODS[:rename], @pe_id, name)
|
221
|
+
end
|
222
|
+
|
223
|
+
#######################################################################
|
224
|
+
# Helpers to get Image information
|
225
|
+
#######################################################################
|
226
|
+
|
227
|
+
# Returns the state of the Image (numeric value)
|
228
|
+
def state
|
229
|
+
self['STATE'].to_i
|
230
|
+
end
|
231
|
+
|
232
|
+
# Returns the state of the Image (string value)
|
233
|
+
def state_str
|
234
|
+
IMAGE_STATES[state]
|
235
|
+
end
|
236
|
+
|
237
|
+
# Returns the state of the Image (string value)
|
238
|
+
def short_state_str
|
239
|
+
SHORT_IMAGE_STATES[state_str]
|
240
|
+
end
|
241
|
+
|
242
|
+
# Returns the type of the Image (numeric value)
|
243
|
+
def type
|
244
|
+
self['TYPE'].to_i
|
245
|
+
end
|
246
|
+
|
247
|
+
# Returns the type of the Image (string value)
|
248
|
+
def type_str
|
249
|
+
IMAGE_TYPES[type]
|
250
|
+
end
|
251
|
+
|
252
|
+
# Returns the state of the Image (string value)
|
253
|
+
def short_type_str
|
254
|
+
SHORT_IMAGE_TYPES[type_str]
|
255
|
+
end
|
256
|
+
|
257
|
+
# Returns the group identifier
|
258
|
+
# [return] _Integer_ the element's group ID
|
259
|
+
def gid
|
260
|
+
self['GID'].to_i
|
261
|
+
end
|
262
|
+
|
263
|
+
def public?
|
264
|
+
if self['PERMISSIONS/GROUP_U'] == "1" || self['PERMISSIONS/OTHER_U'] == "1"
|
265
|
+
true
|
266
|
+
else
|
267
|
+
false
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
private
|
272
|
+
|
273
|
+
def set_enabled(enabled)
|
274
|
+
return Error.new('ID not defined') if !@pe_id
|
275
|
+
|
276
|
+
rc = @client.call(IMAGE_METHODS[:enable], @pe_id, enabled)
|
277
|
+
rc = nil if !OpenNebula.is_error?(rc)
|
278
|
+
|
279
|
+
return rc
|
280
|
+
end
|
281
|
+
|
282
|
+
def set_publish(published)
|
283
|
+
group_u = published ? 1 : 0
|
284
|
+
|
285
|
+
chmod(-1, -1, -1, group_u, -1, -1, -1, -1, -1)
|
286
|
+
end
|
287
|
+
|
288
|
+
def set_persistent(persistence)
|
289
|
+
return Error.new('ID not defined') if !@pe_id
|
290
|
+
|
291
|
+
rc = @client.call(IMAGE_METHODS[:persistent], @pe_id, persistence)
|
292
|
+
rc = nil if !OpenNebula.is_error?(rc)
|
293
|
+
|
294
|
+
return rc
|
295
|
+
end
|
296
|
+
end
|
297
|
+
end
|