Class: OpenNebula::Template

Inherits:
PoolElement show all
Defined in:
lib/OpenNebula/Template.rb

Constant Summary collapse

TEMPLATE_METHODS =

Constants and Class Methods


{
    :allocate    => "template.allocate",
    :instantiate => "template.instantiate",
    :info        => "template.info",
    :update      => "template.update",
    :publish     => "template.publish",
    :delete      => "template.delete",
    :chown       => "template.chown"
}

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PoolElement

#id, #name, new_with_id, #to_str

Methods inherited from XMLElement

#[], #attr, #each, #each_xpath, #has_elements?, #initialize_xml, #name, #retrieve_elements, #template_like_str, #template_str, #text, #to_hash, #to_xml

Constructor Details

#initialize(xml, client) ⇒ Template


Class constructor




54
55
56
57
58
# File 'lib/OpenNebula/Template.rb', line 54

def initialize(xml, client)
    super(xml,client)

    @client = client
end

Class Method Details

.build_xml(pe_id = nil) ⇒ Object

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)


41
42
43
44
45
46
47
48
49
# File 'lib/OpenNebula/Template.rb', line 41

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

Instance Method Details

#allocate(templatename) ⇒ Object

Allocates a new Template in OpenNebula

templatename A string containing the name of the Template.



72
73
74
# File 'lib/OpenNebula/Template.rb', line 72

def allocate(templatename)
    super(TEMPLATE_METHODS[:allocate], templatename)
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



117
118
119
# File 'lib/OpenNebula/Template.rb', line 117

def chown(uid, gid)
    super(TEMPLATE_METHODS[:chown], uid, gid)
end

#deleteObject

Deletes the Template



77
78
79
# File 'lib/OpenNebula/Template.rb', line 77

def delete()
    super(TEMPLATE_METHODS[:delete])
end

#gidObject

Returns the group identifier

return

Integer the element’s group ID



127
128
129
# File 'lib/OpenNebula/Template.rb', line 127

def gid
    self['GID'].to_i
end

#infoObject

Retrieves the information of the given Template.



65
66
67
# File 'lib/OpenNebula/Template.rb', line 65

def info()
    super(TEMPLATE_METHODS[:info], 'VMTEMPLATE')
end

#instantiate(name = "") ⇒ Object

Creates a VM instance from a Template

name A string containing the name of the VM instance.

return

The new VM Instance ID, or an Error object



85
86
87
88
89
90
91
92
# File 'lib/OpenNebula/Template.rb', line 85

def instantiate(name="")
    return Error.new('ID not defined') if !@pe_id

    name ||= ""
    rc = @client.call(TEMPLATE_METHODS[:instantiate], @pe_id, name)

    return rc
end

#owner_idObject



131
132
133
# File 'lib/OpenNebula/Template.rb', line 131

def owner_id
    self['UID'].to_i
end

#publishObject

Publishes the Template, to be used by other users



104
105
106
# File 'lib/OpenNebula/Template.rb', line 104

def publish
    set_publish(true)
end

#unpublishObject

Unplubishes the Image



109
110
111
# File 'lib/OpenNebula/Template.rb', line 109

def unpublish
    set_publish(false)
end

#update(new_template) ⇒ Object

Replaces the template contents

new_template New template contents



97
98
99
100
101
# File 'lib/OpenNebula/Template.rb', line 97

def update(new_template)
    return Error.new('ID not defined') if !@pe_id

    super(TEMPLATE_METHODS[:update], new_template)
end