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
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)
# File lib/opennebula/image.rb, line 76 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
Class constructor
# File lib/opennebula/image.rb, line 87 def initialize(xml, client) super(xml,client) @client = client end
Public Instance Methods
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
@return [nil, OpenNebula::Error] nil in case of success, Error
otherwise
# File lib/opennebula/image.rb, line 111 def allocate(description, ds_id) super(IMAGE_METHODS[:allocate],description, ds_id) 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
# File lib/opennebula/image.rb, line 184 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 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
# File lib/opennebula/image.rb, line 166 def chown(uid, gid) super(IMAGE_METHODS[:chown], uid, gid) end
Changes the Image type @param type [String] new Image type @return [nil, OpenNebula::Error] nil in case of success, Error
otherwise
# File lib/opennebula/image.rb, line 194 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
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
# File lib/opennebula/image.rb, line 209 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
Deletes the Image
# File lib/opennebula/image.rb, line 158 def delete() super(IMAGE_METHODS[:delete]) end
Disables an Image
# File lib/opennebula/image.rb, line 133 def disable set_enabled(false) end
Enables an Image
# File lib/opennebula/image.rb, line 128 def enable set_enabled(true) end
Returns the group identifier
- return
-
Integer the element's group ID
# File lib/opennebula/image.rb, line 263 def gid self['GID'].to_i end
Retrieves the information of the given Image.
# File lib/opennebula/image.rb, line 98 def info() super(IMAGE_METHODS[:info], 'IMAGE') end
Makes the Image non persistent
# File lib/opennebula/image.rb, line 153 def nonpersistent set_persistent(false) end
Makes the Image persistent
# File lib/opennebula/image.rb, line 148 def persistent set_persistent(true) end
# File lib/opennebula/image.rb, line 267 def public? if self['PERMISSIONS/GROUP_U'] == "1" || self['PERMISSIONS/OTHER_U'] == "1" true else false end end
Publishes the Image, to be used by other users
# File lib/opennebula/image.rb, line 138 def publish set_publish(true) end
Returns the state of the Image (string value)
# File lib/opennebula/image.rb, line 242 def short_state_str SHORT_IMAGE_STATES[state_str] end
Returns the state of the Image (string value)
# File lib/opennebula/image.rb, line 257 def short_type_str SHORT_IMAGE_TYPES[type_str] end
Returns the state of the Image (numeric value)
# File lib/opennebula/image.rb, line 232 def state self['STATE'].to_i end
Returns the state of the Image (string value)
# File lib/opennebula/image.rb, line 237 def state_str IMAGE_STATES[state] end
Returns the type of the Image (numeric value)
# File lib/opennebula/image.rb, line 247 def type self['TYPE'].to_i end
Returns the type of the Image (string value)
# File lib/opennebula/image.rb, line 252 def type_str IMAGE_TYPES[type] end
Unplubishes the Image
# File lib/opennebula/image.rb, line 143 def unpublish set_publish(false) 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
# File lib/opennebula/image.rb, line 123 def update(new_template=nil, append=false) super(IMAGE_METHODS[:update], new_template, append ? 1 : 0) end
Private Instance Methods
# File lib/opennebula/image.rb, line 277 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
# File lib/opennebula/image.rb, line 292 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
# File lib/opennebula/image.rb, line 286 def set_publish(published) group_u = published ? 1 : 0 chmod(-1, -1, -1, group_u, -1, -1, -1, -1, -1) end