Class: OpenNebula::Template

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

Constant Summary collapse

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

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

Constructor Details

#initialize(xml, client) ⇒ Template

Class constructor



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

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)


45
46
47
48
49
50
51
52
53
# File 'lib/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

#allocate(description) ⇒ nil, OpenNebula::Error

Allocates a new Template in OpenNebula

Parameters:

  • description (String)

    The contents of the Template.

Returns:



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

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) ⇒ nil, OpenNebula::Error

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 'lib/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

#chmod_octet(octet) ⇒ nil, OpenNebula::Error

Changes the Template permissions.

Parameters:

  • octet (String)

    Permissions octed , e.g. 640

Returns:



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

def chmod_octet(octet)
    super(TEMPLATE_METHODS[:chmod], octet)
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



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

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

#deleteObject

Deletes the Template



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

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

#gidObject

Returns the group identifier

return

Integer the element’s group ID



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

def gid
    self['GID'].to_i
end

#infoObject

Retrieves the information of the given Template.



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

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



90
91
92
93
94
95
96
97
# File 'lib/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

#owner_idObject



156
157
158
# File 'lib/OpenNebula/Template.rb', line 156

def owner_id
    self['UID'].to_i
end

#public?Boolean

Returns:

  • (Boolean)


160
161
162
163
164
165
166
# File 'lib/OpenNebula/Template.rb', line 160

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

#publishObject

Publishes the Template, to be used by other users



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

def publish
    set_publish(true)
end

#unpublishObject

Unplubishes the Image



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

def unpublish
    set_publish(false)
end

#update(new_template) ⇒ Object

Replaces the template contents

new_template New template contents



102
103
104
105
106
# File 'lib/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