Class: OpenNebula::Image
- Inherits:
-
PoolElement
- Object
- XMLElement
- PoolElement
- OpenNebula::Image
- Defined in:
- lib/opennebula/image.rb
Constant Summary collapse
- IMAGE_METHODS =
Constants and Class Methods
{ :info => "image.info", :allocate => "image.allocate", :update => "image.update", :enable => "image.enable", :persistent => "image.persistent", :delete => "image.delete", :chown => "image.chown", :chmod => "image.chmod", :chtype => "image.chtype", :clone => "image.clone", :rename => "image.rename", :snapshotdelete => "image.snapshotdelete", :snapshotrevert => "image.snapshotrevert", :snapshotflatten => "image.snapshotflatten", :restore => "image.restore", :lock => "image.lock", :unlock => "image.unlock" }
- IMAGE_STATES =
%w{INIT READY USED DISABLED LOCKED ERROR CLONE DELETE USED_PERS LOCKED_USED LOCKED_USED_PERS}
- SHORT_IMAGE_STATES =
{ "INIT" => "init", "READY" => "rdy", "USED" => "used", "DISABLED" => "disa", "LOCKED" => "lock", "ERROR" => "err", "CLONE" => "clon", "DELETE" => "dele", "USED_PERS" => "used", "LOCKED_USED" => "lock", "LOCKED_USED_PERS" => "lock" }
- IMAGE_TYPES =
%w{OS CDROM DATABLOCK KERNEL RAMDISK CONTEXT BACKUP}
- SHORT_IMAGE_TYPES =
{ "OS" => "OS", "CDROM" => "CD", "DATABLOCK" => "DB", "KERNEL" => "KL", "RAMDISK" => "RD", "CONTEXT" => "CX", "BACKUP" => "BK" }
- DISK_TYPES =
%w{FILE CD_ROM BLOCK RBD}
Instance Attribute Summary
Attributes inherited from PoolElement
Class Method Summary collapse
-
.build_xml(pe_id = nil) ⇒ Object
Creates an Image description with just its identifier this method should be used to create plain Image objects.
Instance Method Summary collapse
-
#allocate(description, ds_id, no_check_capacity = false) ⇒ nil, OpenNebula::Error
Allocates a new Image in OpenNebula.
-
#chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, other_m, other_a) ⇒ nil, OpenNebula::Error
Changes the Image permissions.
-
#chmod_octet(octet) ⇒ nil, OpenNebula::Error
Changes the Image permissions.
-
#chown(uid, gid) ⇒ Object
- Changes the owner/group uid
-
Integer the new owner id.
-
#chtype(type) ⇒ nil, OpenNebula::Error
Changes the Image type.
-
#clone(name, target_ds = -1)) ⇒ Integer, OpenNebula::Error
Clones this Image into a new one.
-
#delete(force = false) ⇒ Object
Deletes the Image.
-
#disable ⇒ Object
Disables an Image.
-
#enable ⇒ Object
Enables an Image.
-
#gid ⇒ Object
Returns the group identifier [return] Integer the element’s group ID.
-
#info(decrypt = false) ⇒ Object
(also: #info!)
Retrieves the information of the given Image.
-
#initialize(xml, client) ⇒ Image
constructor
Class constructor.
-
#nonpersistent ⇒ Object
Makes the Image non persistent.
-
#persistent ⇒ Object
Makes the Image persistent.
- #public? ⇒ Boolean
-
#publish ⇒ Object
Publishes the Image, to be used by other users.
-
#rename(name) ⇒ nil, OpenNebula::Error
Renames this Image.
-
#restore(dst_id, restore_opts) ⇒ Object
Restore the VM backup stored by the image.
-
#short_state_str ⇒ Object
Returns the state of the Image (string value).
-
#short_type_str ⇒ Object
Returns the state of the Image (string value).
-
#snapshot_delete(snap_id) ⇒ nil, OpenNebula::Error
Deletes Image from snapshot.
-
#snapshot_flatten(snap_id) ⇒ nil, OpenNebula::Error
Flattens an image snapshot.
-
#snapshot_revert(snap_id) ⇒ nil, OpenNebula::Error
Reverts Image state to a previous snapshot.
-
#state ⇒ Object
Returns the state of the Image (numeric value).
-
#state_str ⇒ Object
Returns the state of the Image (string value).
-
#type ⇒ Object
Returns the type of the Image (numeric value).
-
#type_str ⇒ Object
Returns the type of the Image (string value).
-
#unpublish ⇒ Object
Unplubishes the Image.
-
#update(new_template = nil, append = false) ⇒ nil, OpenNebula::Error
Replaces the template contents.
- #wait_state(state, timeout = 120) ⇒ Object
Methods inherited from PoolElement
#id, new_with_id, #replace, #to_str
Methods inherited from XMLElement
#[], #add_element, #attr, #delete_element, #each, #each_xpath, #element_xml, #has_elements?, #initialize_xml, #name, #retrieve_elements, #retrieve_xmlelements, #set_content, #template_like_str, #template_str, #template_xml, #text, #to_hash, #to_xml, #xml_nil?
Constructor Details
#initialize(xml, client) ⇒ Image
Class constructor
97 98 99 100 101 |
# File 'lib/opennebula/image.rb', line 97 def initialize(xml, client) LockableExt.make_lockable(self, IMAGE_METHODS) super(xml,client) end |
Class Method Details
.build_xml(pe_id = nil) ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'lib/opennebula/image.rb', line 86 def Image.build_xml(pe_id=nil) if pe_id image_xml = "<IMAGE><ID>#{pe_id}</ID></IMAGE>" else image_xml = "<IMAGE></IMAGE>" end XMLElement.build_xml(image_xml,'IMAGE') end |
Instance Method Details
#allocate(description, ds_id, no_check_capacity = false) ⇒ nil, OpenNebula::Error
Allocates a new Image in OpenNebula
122 123 124 |
# File 'lib/opennebula/image.rb', line 122 def allocate(description, ds_id, no_check_capacity=false) super(IMAGE_METHODS[:allocate],description, ds_id, no_check_capacity) end |
#chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, other_m, other_a) ⇒ nil, OpenNebula::Error
Changes the Image permissions. Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change
195 196 197 198 199 |
# File 'lib/opennebula/image.rb', line 195 def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, other_m, other_a) super(IMAGE_METHODS[:chmod], owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, other_m, other_a) end |
#chmod_octet(octet) ⇒ nil, OpenNebula::Error
Changes the Image permissions.
186 187 188 |
# File 'lib/opennebula/image.rb', line 186 def chmod_octet(octet) super(IMAGE_METHODS[:chmod], octet) end |
#chown(uid, gid) ⇒ Object
Changes the owner/group
- uid
-
Integer the new owner id. Set to -1 to leave the current one
- gid
-
Integer the new group id. Set to -1 to leave the current one
- return
-
nil in case of success or an Error object
177 178 179 |
# File 'lib/opennebula/image.rb', line 177 def chown(uid, gid) super(IMAGE_METHODS[:chown], uid, gid) end |
#chtype(type) ⇒ nil, OpenNebula::Error
Changes the Image type
205 206 207 208 209 210 211 212 |
# File 'lib/opennebula/image.rb', line 205 def chtype(type) return Error.new('ID not defined') if !@pe_id rc = @client.call(IMAGE_METHODS[:chtype], @pe_id, type) rc = nil if !OpenNebula.is_error?(rc) return rc end |
#clone(name, target_ds = -1)) ⇒ Integer, OpenNebula::Error
Clones this Image into a new one
220 221 222 223 224 225 226 |
# File 'lib/opennebula/image.rb', line 220 def clone(name, target_ds=-1) return Error.new('ID not defined') if !@pe_id rc = @client.call(IMAGE_METHODS[:clone], @pe_id, name, target_ds) return rc end |
#delete(force = false) ⇒ Object
Deletes the Image
169 170 171 |
# File 'lib/opennebula/image.rb', line 169 def delete(force=false) call(IMAGE_METHODS[:delete], @pe_id, force) end |
#disable ⇒ Object
Disables an Image
144 145 146 |
# File 'lib/opennebula/image.rb', line 144 def disable set_enabled(false) end |
#enable ⇒ Object
Enables an Image
139 140 141 |
# File 'lib/opennebula/image.rb', line 139 def enable set_enabled(true) end |
#gid ⇒ Object
Returns the group identifier
- return
-
Integer the element’s group ID
309 310 311 |
# File 'lib/opennebula/image.rb', line 309 def gid self['GID'].to_i end |
#info(decrypt = false) ⇒ Object Also known as: info!
Retrieves the information of the given Image.
108 109 110 |
# File 'lib/opennebula/image.rb', line 108 def info(decrypt = false) super(IMAGE_METHODS[:info], 'IMAGE', decrypt) end |
#nonpersistent ⇒ Object
Makes the Image non persistent
164 165 166 |
# File 'lib/opennebula/image.rb', line 164 def nonpersistent set_persistent(false) end |
#persistent ⇒ Object
Makes the Image persistent
159 160 161 |
# File 'lib/opennebula/image.rb', line 159 def persistent set_persistent(true) end |
#public? ⇒ Boolean
313 314 315 316 317 318 319 |
# File 'lib/opennebula/image.rb', line 313 def public? if self['PERMISSIONS/GROUP_U'] == "1" || self['PERMISSIONS/OTHER_U'] == "1" true else false end end |
#publish ⇒ Object
Publishes the Image, to be used by other users
149 150 151 |
# File 'lib/opennebula/image.rb', line 149 def publish set_publish(true) end |
#rename(name) ⇒ nil, OpenNebula::Error
Renames this Image
234 235 236 |
# File 'lib/opennebula/image.rb', line 234 def rename(name) call(IMAGE_METHODS[:rename], @pe_id, name) end |
#restore(dst_id, restore_opts) ⇒ Object
Restore the VM backup stored by the image
269 270 271 |
# File 'lib/opennebula/image.rb', line 269 def restore(dst_id, restore_opts) @client.call(IMAGE_METHODS[:restore], @pe_id, dst_id, restore_opts) end |
#short_state_str ⇒ Object
Returns the state of the Image (string value)
288 289 290 |
# File 'lib/opennebula/image.rb', line 288 def short_state_str SHORT_IMAGE_STATES[state_str] end |
#short_type_str ⇒ Object
Returns the state of the Image (string value)
303 304 305 |
# File 'lib/opennebula/image.rb', line 303 def short_type_str SHORT_IMAGE_TYPES[type_str] end |
#snapshot_delete(snap_id) ⇒ nil, OpenNebula::Error
Deletes Image from snapshot
243 244 245 |
# File 'lib/opennebula/image.rb', line 243 def snapshot_delete(snap_id) call(IMAGE_METHODS[:snapshotdelete], @pe_id, snap_id) end |
#snapshot_flatten(snap_id) ⇒ nil, OpenNebula::Error
Flattens an image snapshot
261 262 263 |
# File 'lib/opennebula/image.rb', line 261 def snapshot_flatten(snap_id) call(IMAGE_METHODS[:snapshotflatten], @pe_id, snap_id) end |
#snapshot_revert(snap_id) ⇒ nil, OpenNebula::Error
Reverts Image state to a previous snapshot
252 253 254 |
# File 'lib/opennebula/image.rb', line 252 def snapshot_revert(snap_id) call(IMAGE_METHODS[:snapshotrevert], @pe_id, snap_id) end |
#state ⇒ Object
Returns the state of the Image (numeric value)
278 279 280 |
# File 'lib/opennebula/image.rb', line 278 def state self['STATE'].to_i end |
#state_str ⇒ Object
Returns the state of the Image (string value)
283 284 285 |
# File 'lib/opennebula/image.rb', line 283 def state_str IMAGE_STATES[state] end |
#type ⇒ Object
Returns the type of the Image (numeric value)
293 294 295 |
# File 'lib/opennebula/image.rb', line 293 def type self['TYPE'].to_i end |
#type_str ⇒ Object
Returns the type of the Image (string value)
298 299 300 |
# File 'lib/opennebula/image.rb', line 298 def type_str IMAGE_TYPES[type] end |
#unpublish ⇒ Object
Unplubishes the Image
154 155 156 |
# File 'lib/opennebula/image.rb', line 154 def unpublish set_publish(false) end |
#update(new_template = nil, append = false) ⇒ nil, OpenNebula::Error
Replaces the template contents
134 135 136 |
# File 'lib/opennebula/image.rb', line 134 def update(new_template=nil, append=false) super(IMAGE_METHODS[:update], new_template, append ? 1 : 0) end |
#wait_state(state, timeout = 120) ⇒ Object
321 322 323 324 325 326 327 328 329 330 331 |
# File 'lib/opennebula/image.rb', line 321 def wait_state(state, timeout=120) require 'opennebula/wait_ext' extend OpenNebula::WaitExt rc = wait(state, timeout) return Error.new("Timeout expired for state #{state}.") unless rc true end |