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",
    :publish     => "template.publish",
    :delete      => "template.delete",
    :chown       => "template.chown",
    :chmod       => "template.chmod"
}

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

- (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

- (Object) allocate(templatename)

Allocates a new Template in OpenNebula

templatename A string containing the name of the Template.



74
75
76
# File 'OpenNebula/Template.rb', line 74

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



137
138
139
140
141
# File 'OpenNebula/Template.rb', line 137

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:



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

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



119
120
121
# File 'OpenNebula/Template.rb', line 119

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

- (Object) delete

Deletes the Template



79
80
81
# File 'OpenNebula/Template.rb', line 79

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

- (Object) gid

Returns the group identifier

return

Integer the element’s group ID



149
150
151
# File 'OpenNebula/Template.rb', line 149

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



87
88
89
90
91
92
93
94
# File 'OpenNebula/Template.rb', line 87

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



153
154
155
# File 'OpenNebula/Template.rb', line 153

def owner_id
    self['UID'].to_i
end

- (Boolean) public?

Returns:

  • (Boolean)


157
158
159
160
161
162
163
# File 'OpenNebula/Template.rb', line 157

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



106
107
108
# File 'OpenNebula/Template.rb', line 106

def publish
    set_publish(true)
end

- (Object) unpublish

Unplubishes the Image



111
112
113
# File 'OpenNebula/Template.rb', line 111

def unpublish
    set_publish(false)
end

- (Object) update(new_template)

Replaces the template contents

new_template New template contents



99
100
101
102
103
# File 'OpenNebula/Template.rb', line 99

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

    super(TEMPLATE_METHODS[:update], new_template)
end