Class: OpenNebula::VirtualRouter

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

Constant Summary collapse

VIRTUAL_ROUTER_METHODS =

Constants and Class Methods

{
    :allocate    => "vrouter.allocate",
    :instantiate => "vrouter.instantiate",
    :info        => "vrouter.info",
    :update      => "vrouter.update",
    :delete      => "vrouter.delete",
    :chown       => "vrouter.chown",
    :chmod       => "vrouter.chmod",
    :rename      => "vrouter.rename",
    :attachnic   => "vrouter.attachnic",
    :detachnic   => "vrouter.detachnic",
    :lock        => "vrouter.lock",
    :unlock      => "vrouter.unlock"
}

Instance Attribute Summary

Attributes inherited from PoolElement

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PoolElement

#id, 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) ⇒ VirtualRouter

Class constructor



59
60
61
62
63
64
65
# File 'lib/opennebula/virtual_router.rb', line 59

def initialize(xml, client)
    LockableExt.make_lockable(self, VIRTUAL_ROUTER_METHODS)

    super(xml,client)

    @client = client
end

Class Method Details

.build_xml(pe_id = nil) ⇒ Object

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

Example:

vrouter = VirtualRouter.new(VirtualRouter.build_xml(3),rpc_client)


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

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

    XMLElement.build_xml(obj_xml,'VROUTER')
end

Instance Method Details

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

Allocates a new VirtualRouter in OpenNebula

Parameters:

  • description (String)

    The contents of the VirtualRouter.

Returns:



84
85
86
# File 'lib/opennebula/virtual_router.rb', line 84

def allocate(description)
    super(VIRTUAL_ROUTER_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 VirtualRouter permissions. Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change

Returns:



148
149
150
151
152
# File 'lib/opennebula/virtual_router.rb', line 148

def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
        other_m, other_a)
    super(VIRTUAL_ROUTER_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 VirtualRouter permissions.

Parameters:

  • octet (String)

    Permissions octed , e.g. 640

Returns:



139
140
141
# File 'lib/opennebula/virtual_router.rb', line 139

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

#chown(uid, gid) ⇒ nil, OpenNebula::Error

Changes the owner/group

Parameters:

  • 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

Returns:



130
131
132
# File 'lib/opennebula/virtual_router.rb', line 130

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

#deleteObject

Deletes the VirtualRouter



109
110
111
# File 'lib/opennebula/virtual_router.rb', line 109

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

#gidInteger

Returns the group identifier

Returns:

  • (Integer)

    the element’s group ID



188
189
190
# File 'lib/opennebula/virtual_router.rb', line 188

def gid
    self['GID'].to_i
end

#infoObject Also known as: info!

Retrieves the information of the given Virtual Router



72
73
74
# File 'lib/opennebula/virtual_router.rb', line 72

def info()
    super(VIRTUAL_ROUTER_METHODS[:info], 'VROUTER')
end

#instantiate(n_vms, template_id, name = "", hold = false, template = "") ⇒ nil, OpenNebula::Error

Creates VM instances from a VM Template. New VMs will be associated to this Virtual Router, and its Virtual Networks

Parameters:

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

    Name for the VM instances. If it is an empty string OpenNebula will set a default name. Wildcard %i can be used.

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

    false to create the VM in pending state, true to create it on hold

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

    User provided Template to merge with the one being instantiated

Returns:



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

def instantiate(n_vms, template_id, name="", hold=false, template="")
    return call(VIRTUAL_ROUTER_METHODS[:instantiate], @pe_id,
                n_vms.to_i, template_id.to_i, name, hold, template)
end

#nic_attach(nic_template) ⇒ nil, OpenNebula::Error

Attaches a NIC to this VirtualRouter, and each one of its VMs

Parameters:

  • nic_template (String)

    Template containing a NIC element

Returns:



169
170
171
# File 'lib/opennebula/virtual_router.rb', line 169

def nic_attach(nic_template)
    return call(VIRTUAL_ROUTER_METHODS[:attachnic], @pe_id, nic_template)
end

#nic_detach(nic_id) ⇒ nil, OpenNebula::Error

Detaches a NIC from this VirtualRouter, and each one of its VMs

Parameters:

  • nic_id (Integer)

    Id of the NIC to be detached

Returns:



178
179
180
# File 'lib/opennebula/virtual_router.rb', line 178

def nic_detach(nic_id)
    return call(VIRTUAL_ROUTER_METHODS[:detachnic], @pe_id, nic_id)
end

#owner_idObject



192
193
194
# File 'lib/opennebula/virtual_router.rb', line 192

def owner_id
    self['UID'].to_i
end

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

Renames this VirtualRouter

Parameters:

  • name (String)

    New name for the VirtualRouter.

Returns:



160
161
162
# File 'lib/opennebula/virtual_router.rb', line 160

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

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

Replaces the template contents

Parameters:

  • new_template (String)

    New template contents

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

    True to append new attributes instead of replace the whole template

Returns:



121
122
123
# File 'lib/opennebula/virtual_router.rb', line 121

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

#vm_idsObject

Returns an array with the numeric VM ids



197
198
199
200
201
202
203
204
205
# File 'lib/opennebula/virtual_router.rb', line 197

def vm_ids
    array = Array.new

    self.each("VMS/ID") do |id|
        array << id.text.to_i
    end

    return array
end