Class: OpenNebula::Template

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

Constant Summary

TEMPLATE_METHODS =
{
    :allocate    => "template.allocate",
    :instantiate => "template.instantiate",
    :info        => "template.info",
    :update      => "template.update",
    :delete      => "template.delete",
    :chown       => "template.chown",
    :chmod       => "template.chmod",
    :clone       => "template.clone"
}

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from PoolElement

#id, #name, new_with_id, #to_str

Methods inherited from XMLElement

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

Constructor Details

- (Template) initialize(xml, client)

Class constructor



56
57
58
59
60
# File 'OpenNebula/Template.rb', line 56

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

    @client = client
end

Class Method Details

+ (Object) build_xml(pe_id = nil)

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)


45
46
47
48
49
50
51
52
53
# File 'OpenNebula/Template.rb', line 45

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

- (nil, OpenNebula::Error) allocate(description)

Allocates a new Template in OpenNebula

Parameters:

  • description (String)

    The contents of the Template.

Returns:



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

def allocate(description)
    super(TEMPLATE_METHODS[:allocate], description)
end

- (nil, OpenNebula::Error) chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, other_m, other_a)

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

Returns:



140
141
142
143
144
# File 'OpenNebula/Template.rb', line 140

def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
        other_m, other_a)
    super(TEMPLATE_METHODS[:chmod], owner_u, owner_m, owner_a, group_u,
        group_m, group_a, other_u, other_m, other_a)
end

- (nil, OpenNebula::Error) chmod_octet(octet)

Changes the Template permissions.

Parameters:

  • octet (String)

    Permissions octed , e.g. 640

Returns:



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

def chmod_octet(octet)
    super(TEMPLATE_METHODS[:chmod], octet)
end

- (Object) chown(uid, gid)

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



122
123
124
# File 'OpenNebula/Template.rb', line 122

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

- (Integer, OpenNebula::Error) clone(name)

Clones this Template into a new one

Parameters:

  • name (String)

    for the new Template.

Returns:

  • (Integer, OpenNebula::Error)

    The new Template ID in case of success, Error otherwise



152
153
154
155
156
157
158
# File 'OpenNebula/Template.rb', line 152

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

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

    return rc
end

- (Object) delete

Deletes the Template



82
83
84
# File 'OpenNebula/Template.rb', line 82

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

- (Object) gid

Returns the group identifier

return

Integer the element's group ID



166
167
168
# File 'OpenNebula/Template.rb', line 166

def gid
    self['GID'].to_i
end

- (Object) info

Retrieves the information of the given Template.



67
68
69
# File 'OpenNebula/Template.rb', line 67

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

- (Object) instantiate(name = "")

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



90
91
92
93
94
95
96
97
# File 'OpenNebula/Template.rb', line 90

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

- (Object) owner_id



170
171
172
# File 'OpenNebula/Template.rb', line 170

def owner_id
    self['UID'].to_i
end

- (Boolean) public?

Returns:

  • (Boolean)


174
175
176
177
178
179
180
# File 'OpenNebula/Template.rb', line 174

def public?
    if self['PERMISSIONS/GROUP_U'] == "1" || self['PERMISSIONS/OTHER_U'] == "1"
        true
    else
        false
    end
end

- (Object) publish

Publishes the Template, to be used by other users



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

def publish
    set_publish(true)
end

- (Object) unpublish

Unplubishes the Image



114
115
116
# File 'OpenNebula/Template.rb', line 114

def unpublish
    set_publish(false)
end

- (Object) update(new_template)

Replaces the template contents

new_template New template contents



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

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

    super(TEMPLATE_METHODS[:update], new_template)
end