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

build_xml(pe_id=nil) click to toggle source

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
new(xml, client) click to toggle source

Class constructor

Calls superclass method
# File lib/opennebula/image.rb, line 87
def initialize(xml, client)
    super(xml,client)

    @client = client
end

Public Instance Methods

allocate(description, ds_id) click to toggle source

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
Calls superclass method
# File lib/opennebula/image.rb, line 111
def allocate(description, ds_id)
    super(IMAGE_METHODS[:allocate],description, ds_id)
end
chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, other_m, other_a) click to toggle source

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
Calls superclass method
# 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
chmod_octet(octet) click to toggle source

Changes the Image permissions.

@param octet [String] Permissions octed , e.g. 640 @return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
Calls superclass method
# File lib/opennebula/image.rb, line 175
def chmod_octet(octet)
    super(IMAGE_METHODS[:chmod], octet)
end
chown(uid, gid) click to toggle source

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

Calls superclass method
# File lib/opennebula/image.rb, line 166
def chown(uid, gid)
    super(IMAGE_METHODS[:chown], uid, gid)
end
chtype(type) click to toggle source

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
clone(name, target_ds=-1) click to toggle source

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
delete() click to toggle source

Deletes the Image

Calls superclass method
# File lib/opennebula/image.rb, line 158
def delete()
    super(IMAGE_METHODS[:delete])
end
disable() click to toggle source

Disables an Image

# File lib/opennebula/image.rb, line 133
def disable
    set_enabled(false)
end
enable() click to toggle source

Enables an Image

# File lib/opennebula/image.rb, line 128
def enable
    set_enabled(true)
end
gid() click to toggle source

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
info() click to toggle source

Retrieves the information of the given Image.

Calls superclass method
# File lib/opennebula/image.rb, line 98
def info()
    super(IMAGE_METHODS[:info], 'IMAGE')
end
Also aliased as: info!
info!()
Alias for: info
nonpersistent() click to toggle source

Makes the Image non persistent

# File lib/opennebula/image.rb, line 153
def nonpersistent
    set_persistent(false)
end
persistent() click to toggle source

Makes the Image persistent

# File lib/opennebula/image.rb, line 148
def persistent
    set_persistent(true)
end
public?() click to toggle source
# 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
publish() click to toggle source

Publishes the Image, to be used by other users

# File lib/opennebula/image.rb, line 138
def publish
    set_publish(true)
end
rename(name) click to toggle source

Renames this Image

@param name [String] New name for the Image.

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/image.rb, line 223
def rename(name)
    return call(IMAGE_METHODS[:rename], @pe_id, name)
end
short_state_str() click to toggle source

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
short_type_str() click to toggle source

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
state() click to toggle source

Returns the state of the Image (numeric value)

# File lib/opennebula/image.rb, line 232
def state
    self['STATE'].to_i
end
state_str() click to toggle source

Returns the state of the Image (string value)

# File lib/opennebula/image.rb, line 237
def state_str
    IMAGE_STATES[state]
end
type() click to toggle source

Returns the type of the Image (numeric value)

# File lib/opennebula/image.rb, line 247
def type
    self['TYPE'].to_i
end
type_str() click to toggle source

Returns the type of the Image (string value)

# File lib/opennebula/image.rb, line 252
def type_str
    IMAGE_TYPES[type]
end
unpublish() click to toggle source

Unplubishes the Image

# File lib/opennebula/image.rb, line 143
def unpublish
    set_publish(false)
end
update(new_template=nil, append=false) click to toggle source

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
Calls superclass method
# 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

set_enabled(enabled) click to toggle source
# 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
set_persistent(persistence) click to toggle source
# 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
set_publish(published) click to toggle source
# 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