Class: OpenNebula::VNTemplate

Inherits:
PoolElement show all
Defined in:
lib/opennebula/vntemplate.rb

Constant Summary collapse

TEMPLATE_METHODS =
{
    :allocate    => "vntemplate.allocate",
    :instantiate => "vntemplate.instantiate",
    :info        => "vntemplate.info",
    :update      => "vntemplate.update",
    :delete      => "vntemplate.delete",
    :chown       => "vntemplate.chown",
    :chmod       => "vntemplate.chmod",
    :clone       => "vntemplate.clone",
    :rename      => "vntemplate.rename",
    :lock        => "vntemplate.lock",
    :unlock      => "vntemplate.unlock"
}

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PoolElement

#id, #name, new_with_id, #replace, #to_str

Methods inherited from XMLElement

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

Constructor Details

#initialize(xml, client) ⇒ VNTemplate

Class constructor



59
60
61
62
63
# File 'lib/opennebula/vntemplate.rb', line 59

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

    @client = client
end

Class Method Details

.build_xml(pe_id = nil) ⇒ Object

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

Example:

vntemplate = VNTemplate.new(VNTemplate.build_xml(3),rpc_client)


48
49
50
51
52
53
54
55
56
# File 'lib/opennebula/vntemplate.rb', line 48

def VNTemplate.build_xml(pe_id=nil)
    if pe_id
        obj_xml = "<VNTEMPLATE><ID>#{pe_id}</ID></VNTEMPLATE>"
    else
        obj_xml = "<VNTEMPLATE></VNTEMPLATE>"
    end

    XMLElement.build_xml(obj_xml,'VNTEMPLATE')
end

Instance Method Details

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

Allocates a new VNTemplate in OpenNebula

Parameters:

  • description (String)

    The contents of the VNTemplate.

Returns:



95
96
97
# File 'lib/opennebula/vntemplate.rb', line 95

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

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

any image defined in DISK.

Parameters:

  • recursive (true, false) (defaults to: false)

    optional, chmods the vntemplate plus

Returns:



189
190
191
192
193
# File 'lib/opennebula/vntemplate.rb', line 189

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

Changes the VNTemplate permissions.

any image defined in DISK.

Parameters:

  • octet (String)

    Permissions octed , e.g. 640

  • recursive (true, false) (defaults to: false)

    optional, chmods the vntemplate plus

Returns:



166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/opennebula/vntemplate.rb', line 166

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) ⇒ 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



154
155
156
# File 'lib/opennebula/vntemplate.rb', line 154

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

#clone(name) ⇒ Integer, OpenNebula::Error

Clones this VNTemplate into a new one

any image defined in DISK. The new IMAGE_ID is set into each DISK.

Parameters:

  • name (String)

    for the new VNTemplate.

Returns:

  • (Integer, OpenNebula::Error)

    The new Template ID in case of success, Error otherwise



202
203
204
205
206
207
208
# File 'lib/opennebula/vntemplate.rb', line 202

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

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

    return rc
end

#deletenil, OpenNebula::Error

Deletes the Template

Returns:



103
104
105
# File 'lib/opennebula/vntemplate.rb', line 103

def delete()
    return call(TEMPLATE_METHODS[:delete], @pe_id, false)
end

#gidObject

Returns the group identifier

return

Integer the element’s group ID



226
227
228
# File 'lib/opennebula/vntemplate.rb', line 226

def gid
    self['GID'].to_i
end

#infoObject Also known as: info!

Retrieves the information of the given VNTemplate. include extended information, such as the SIZE for each DISK



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/opennebula/vntemplate.rb', line 71

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

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

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

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

    return rc
end

#instantiate(name = "", template = "") ⇒ Integer, OpenNebula::Error

Creates a VNet instance from a VNTemplate

Parameters:

  • name (String) (defaults to: "")

    Name for the VNet instance. If it is an empty string OpenNebula will set a default name

  • template (String) (defaults to: "")

    User provided VNTemplate to merge with the one being instantiated

Returns:



116
117
118
119
120
121
122
123
124
125
126
# File 'lib/opennebula/vntemplate.rb', line 116

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

    name ||= ""
    template ||= ""

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

    return rc
end

#lock(level) ⇒ Object

Lock a VNTemplate



235
236
237
# File 'lib/opennebula/vntemplate.rb', line 235

def lock(level)
    return call(TEMPLATE_METHODS[:lock], @pe_id, level)
end

#owner_idObject



230
231
232
# File 'lib/opennebula/vntemplate.rb', line 230

def owner_id
    self['UID'].to_i
end

#public?Boolean

Returns:

  • (Boolean)


244
245
246
247
248
249
250
# File 'lib/opennebula/vntemplate.rb', line 244

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



141
142
143
# File 'lib/opennebula/vntemplate.rb', line 141

def publish
    set_publish(true)
end

#rename(name) ⇒ nil, OpenNebula::Error

Renames this VNTemplate

Parameters:

  • name (String)

    New name for the VNTemplate.

Returns:



216
217
218
# File 'lib/opennebula/vntemplate.rb', line 216

def rename(name)
    return call(TEMPLATE_METHODS[:rename], @pe_id, name)
end

#unlockObject

Unlock a VNTemplate



240
241
242
# File 'lib/opennebula/vntemplate.rb', line 240

def unlock()
    return call(TEMPLATE_METHODS[:unlock], @pe_id)
end

#unpublishObject

Unplubishes the Image



146
147
148
# File 'lib/opennebula/vntemplate.rb', line 146

def unpublish
    set_publish(false)
end

#update(new_template, append = false) ⇒ nil, OpenNebula::Error

Replaces the vntemplate contents

Parameters:

  • new_template (String)

    New vntemplate contents

  • append (true, false) (defaults to: false)

    True to append new attributes instead of replace the whole template

Returns:



136
137
138
# File 'lib/opennebula/vntemplate.rb', line 136

def update(new_template, append=false)
    super(TEMPLATE_METHODS[:update], new_template, append ? 1 : 0)
end