class OpenNebula::Template

Constants

TEMPLATE_METHODS

Constants and Class Methods

Public Class Methods

build_xml(pe_id=nil) click to toggle source

Creates a Template description with just its identifier this method should be used to create plain Template objects. id the id of the user

Example:

template = Template.new(Template.build_xml(3),rpc_client)
# File lib/opennebula/template.rb, line 48
def Template.build_xml(pe_id=nil)
    if pe_id
        obj_xml = "<VMTEMPLATE><ID>#{pe_id}</ID></VMTEMPLATE>"
    else
        obj_xml = "<VMTEMPLATE></VMTEMPLATE>"
    end

    XMLElement.build_xml(obj_xml,'VMTEMPLATE')
end
new(xml, client) click to toggle source

Class constructor

Calls superclass method OpenNebula::PoolElement::new
# File lib/opennebula/template.rb, line 59
def initialize(xml, client)
    super(xml,client)

    @client = client
end

Public Instance Methods

allocate(description) click to toggle source

Allocates a new Template in OpenNebula

@param description [String] The contents of the Template.

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

otherwise
Calls superclass method OpenNebula::PoolElement#allocate
# File lib/opennebula/template.rb, line 96
def allocate(description)
    super(TEMPLATE_METHODS[:allocate], description)
end
chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, other_m, other_a, recursive=false) click to toggle source

Changes the Template permissions. Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change

@param recursive [true,false] optional, chmods the template plus any image defined in DISK.

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

otherwise
# File lib/opennebula/template.rb, line 200
def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
        other_m, other_a, recursive=false)
    return call(TEMPLATE_METHODS[:chmod], @pe_id, owner_u, owner_m, owner_a, group_u,
        group_m, group_a, other_u, other_m, other_a, recursive)
end
chmod_octet(octet, recursive=false) click to toggle source

Changes the Template permissions.

@param octet [String] Permissions octed , e.g. 640 @param recursive [true,false] optional, chmods the template plus any image defined in DISK.

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

otherwise
# File lib/opennebula/template.rb, line 177
def chmod_octet(octet, recursive=false)
    owner_u = octet[0..0].to_i & 4 != 0 ? 1 : 0
    owner_m = octet[0..0].to_i & 2 != 0 ? 1 : 0
    owner_a = octet[0..0].to_i & 1 != 0 ? 1 : 0
    group_u = octet[1..1].to_i & 4 != 0 ? 1 : 0
    group_m = octet[1..1].to_i & 2 != 0 ? 1 : 0
    group_a = octet[1..1].to_i & 1 != 0 ? 1 : 0
    other_u = octet[2..2].to_i & 4 != 0 ? 1 : 0
    other_m = octet[2..2].to_i & 2 != 0 ? 1 : 0
    other_a = octet[2..2].to_i & 1 != 0 ? 1 : 0

    chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
        other_m, other_a, recursive)
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 OpenNebula::PoolElement#chown
# File lib/opennebula/template.rb, line 165
def chown(uid, gid)
    super(TEMPLATE_METHODS[:chown], uid, gid)
end
clone(name, recursive=false) click to toggle source

Clones this Template into a new one

@param [String] name for the new Template. @param recursive [true,false] optional, clones the template plus any image defined in DISK. The new IMAGE_ID is set into each DISK.

@return [Integer, OpenNebula::Error] The new Template ID in case

of success, Error otherwise
# File lib/opennebula/template.rb, line 214
def clone(name, recursive=false)
    return Error.new('ID not defined') if !@pe_id

    rc = @client.call(TEMPLATE_METHODS[:clone], @pe_id, name, recursive)

    return rc
end
delete(recursive=false) click to toggle source

Deletes the Template

@param recursive [true,false] optional, deletes the template plus any image defined in DISK.

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

otherwise
# File lib/opennebula/template.rb, line 107
def delete(recursive=false)
    return call(TEMPLATE_METHODS[:delete], @pe_id, recursive)
end
gid() click to toggle source

Returns the group identifier

return

Integer the element's group ID

# File lib/opennebula/template.rb, line 238
def gid
    self['GID'].to_i
end
info(extended=false, decrypt=false) click to toggle source

Retrieves the information of the given Template. @param extended [true,false] optional flag to process the template and include extended information, such as the SIZE for each DISK

# File lib/opennebula/template.rb, line 72
def info(extended=false, decrypt=false)
    return Error.new('ID not defined') if !@pe_id

    rc = @client.call(TEMPLATE_METHODS[:info], @pe_id, extended, decrypt)

    if !OpenNebula.is_error?(rc)
        initialize_xml(rc, 'VMTEMPLATE')
        rc   = nil

        @pe_id = self['ID'].to_i if self['ID']
        @name  = self['NAME'] if self['NAME']
    end

    return rc
end
Also aliased as: info!
info!(extended=false, decrypt=false)
Alias for: info
instantiate(name="", hold=false, template="", persistent=false) click to toggle source

Creates a VM instance from a Template

@param name [String] Name for the VM instance. If it is an empty

string OpenNebula will set a default name

@param hold [true,false] false to create the VM in pending state,

true to create it on hold

@param template [String] User provided Template to merge with the

one being instantiated

@param persistent [true,false] true to create a private persistent

copy of the template plus any image defined in DISK, and instantiate
that copy

@return [Integer, OpenNebula::Error] The new VM id, Error

otherwise
# File lib/opennebula/template.rb, line 125
def instantiate(name="", hold=false, template="", persistent=false)
    return Error.new('ID not defined') if !@pe_id

    name ||= ""
    hold = false if hold.nil?
    template ||= ""
    persistent = false if persistent.nil?

    rc = @client.call(TEMPLATE_METHODS[:instantiate], @pe_id,
        name, hold, template, persistent)

    return rc
end
lock(level) click to toggle source

Lock a Template

# File lib/opennebula/template.rb, line 247
def lock(level)
    return call(TEMPLATE_METHODS[:lock], @pe_id, level)
end
owner_id() click to toggle source
# File lib/opennebula/template.rb, line 242
def owner_id
    self['UID'].to_i
end
public?() click to toggle source
# File lib/opennebula/template.rb, line 256
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 Template, to be used by other users

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

Renames this Template

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

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

otherwise
# File lib/opennebula/template.rb, line 228
def rename(name)
    return call(TEMPLATE_METHODS[:rename], @pe_id, name)
end
unlock() click to toggle source

Unlock a Template

# File lib/opennebula/template.rb, line 252
def unlock()
    return call(TEMPLATE_METHODS[:unlock], @pe_id)
end
unpublish() click to toggle source

Unplubishes the Image

# File lib/opennebula/template.rb, line 157
def unpublish
    set_publish(false)
end
update(new_template, 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 OpenNebula::PoolElement#update
# File lib/opennebula/template.rb, line 147
def update(new_template, append=false)
    super(TEMPLATE_METHODS[:update], new_template, append ? 1 : 0)
end

Private Instance Methods

set_publish(published) click to toggle source
# File lib/opennebula/template.rb, line 266
def set_publish(published)
    group_u = published ? 1 : 0

    chmod(-1, -1, -1, group_u, -1, -1, -1, -1, -1)
end