class OpenNebula::Image
Constants
- DISK_TYPES
- IMAGE_METHODS
-
Constants and Class Methods
- IMAGE_STATES
- IMAGE_TYPES
- SHORT_IMAGE_STATES
- SHORT_IMAGE_TYPES
Public Class Methods
Source
# 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
Creates an Image
description with just its identifier this method should be used to create plain Image
objects. id
the id of the image
Example:
image = Image.new(Image.build_xml(3),rpc_client)
Source
# File lib/opennebula/image.rb, line 97 def initialize(xml, client) LockableExt.make_lockable(self, IMAGE_METHODS) super(xml,client) end
Class constructor
Public Instance Methods
Source
# 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
Allocates a new Image
in OpenNebula
@param description [String] A string containing the template of the Image
. @param ds_id [Integer] the target datastore ID @param no_check_capacity [Boolean] true to skip capacity check. Only for admins.
@return [nil, OpenNebula::Error
] nil in case of success, Error
otherwise
Source
# 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
Changes the Image
permissions. Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change
@return [nil, OpenNebula::Error
] nil in case of success, Error
otherwise
Source
# File lib/opennebula/image.rb, line 186 def chmod_octet(octet) super(IMAGE_METHODS[:chmod], octet) end
Changes the Image
permissions.
@param octet [String] Permissions octed , e.g. 640 @return [nil, OpenNebula::Error
] nil in case of success, Error
otherwise
Source
# File lib/opennebula/image.rb, line 177 def chown(uid, gid) super(IMAGE_METHODS[:chown], uid, gid) end
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
Source
# 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
Changes the Image
type @param type [String] new Image
type @return [nil, OpenNebula::Error
] nil in case of success, Error
otherwise
Source
# 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
Clones this Image
into a new one
@param [String] name for the new Image
.
@return [Integer, OpenNebula::Error
] The new Image
ID in case
of success, Error otherwise
Source
# File lib/opennebula/image.rb, line 169 def delete(force=false) call(IMAGE_METHODS[:delete], @pe_id, force) end
Deletes the Image
Source
# File lib/opennebula/image.rb, line 144 def disable set_enabled(false) end
Disables an Image
Source
# File lib/opennebula/image.rb, line 139 def enable set_enabled(true) end
Enables an Image
Source
# File lib/opennebula/image.rb, line 309 def gid self['GID'].to_i end
Returns the group identifier
- return
-
Integer the element’s group ID
Source
# File lib/opennebula/image.rb, line 108 def info(decrypt = false) super(IMAGE_METHODS[:info], 'IMAGE', decrypt) end
Retrieves the information of the given Image
.
Source
# File lib/opennebula/image.rb, line 164 def nonpersistent set_persistent(false) end
Makes the Image
non persistent
Source
# File lib/opennebula/image.rb, line 159 def persistent set_persistent(true) end
Makes the Image
persistent
Source
# 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
Source
# File lib/opennebula/image.rb, line 149 def publish set_publish(true) end
Publishes the Image
, to be used by other users
Source
# File lib/opennebula/image.rb, line 234 def rename(name) call(IMAGE_METHODS[:rename], @pe_id, name) end
Renames this Image
@param name [String] New name for the Image
.
@return [nil, OpenNebula::Error
] nil in case of success, Error
otherwise
Source
# 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
Restore the VM backup stored by the image
@param dst_id [Integer] Datastore
destination ID @param restore_opts [String] Template
with additional restore options
Source
# File lib/opennebula/image.rb, line 288 def short_state_str SHORT_IMAGE_STATES[state_str] end
Returns the state of the Image
(string value)
Source
# File lib/opennebula/image.rb, line 303 def short_type_str SHORT_IMAGE_TYPES[type_str] end
Returns the state of the Image
(string value)
Source
# File lib/opennebula/image.rb, line 243 def snapshot_delete(snap_id) call(IMAGE_METHODS[:snapshotdelete], @pe_id, snap_id) end
Deletes Image
from snapshot
@param snap_id [Integer] ID of the snapshot to delete
@return [nil, OpenNebula::Error
] nil in case of success or Error
Source
# File lib/opennebula/image.rb, line 261 def snapshot_flatten(snap_id) call(IMAGE_METHODS[:snapshotflatten], @pe_id, snap_id) end
Flattens an image snapshot
@param snap_id [Integer] ID of the snapshot to flatten
@return [nil, OpenNebula::Error
] nil in case of success or Error
Source
# File lib/opennebula/image.rb, line 252 def snapshot_revert(snap_id) call(IMAGE_METHODS[:snapshotrevert], @pe_id, snap_id) end
Reverts Image
state to a previous snapshot
@param snap_id [Integer] ID of the snapshot to revert to
@return [nil, OpenNebula::Error
] nil in case of success or Error
Source
# File lib/opennebula/image.rb, line 278 def state self['STATE'].to_i end
Returns the state of the Image
(numeric value)
Source
# File lib/opennebula/image.rb, line 283 def state_str IMAGE_STATES[state] end
Returns the state of the Image
(string value)
Source
# File lib/opennebula/image.rb, line 293 def type self['TYPE'].to_i end
Returns the type of the Image
(numeric value)
Source
# File lib/opennebula/image.rb, line 298 def type_str IMAGE_TYPES[type] end
Returns the type of the Image
(string value)
Source
# File lib/opennebula/image.rb, line 154 def unpublish set_publish(false) end
Unplubishes the Image
Source
# File lib/opennebula/image.rb, line 134 def update(new_template=nil, append=false) super(IMAGE_METHODS[:update], new_template, append ? 1 : 0) end
Replaces the template contents
@param new_template [String] New template contents @param append [true, false] True to append new attributes instead of
replace the whole template
@return [nil, OpenNebula::Error
] nil in case of success, Error
otherwise
Source
# 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
Private Instance Methods
Source
# File lib/opennebula/image.rb, line 335 def set_enabled(enabled) return Error.new('ID not defined') if !@pe_id rc = @client.call(IMAGE_METHODS[:enable], @pe_id, enabled) rc = nil if !OpenNebula.is_error?(rc) return rc end
Source
# File lib/opennebula/image.rb, line 350 def set_persistent(persistence) return Error.new('ID not defined') if !@pe_id rc = @client.call(IMAGE_METHODS[:persistent], @pe_id, persistence) rc = nil if !OpenNebula.is_error?(rc) return rc end
Source
# File lib/opennebula/image.rb, line 344 def set_publish(published) group_u = published ? 1 : 0 chmod(-1, -1, -1, group_u, -1, -1, -1, -1, -1) end