Class: OpenNebula::SecurityGroup

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

Constant Summary collapse

SECGROUP_METHODS =
{
    :allocate    => "secgroup.allocate",
    :info        => "secgroup.info",
    :update      => "secgroup.update",
    :delete      => "secgroup.delete",
    :chown       => "secgroup.chown",
    :chmod       => "secgroup.chmod",
    :clone       => "secgroup.clone",
    :rename      => "secgroup.rename",
    :commit      => "secgroup.commit"
}

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

Class constructor



53
54
55
56
57
# File 'lib/opennebula/security_group.rb', line 53

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

    @client = client
end

Class Method Details

.build_xml(pe_id = nil) ⇒ Object

Creates a SecurityGroup description with just its identifier this method should be used to create plain SecurityGroup objects.

Parameters:

  • pe_id (Integer) (defaults to: nil)

    the id of the object



42
43
44
45
46
47
48
49
50
# File 'lib/opennebula/security_group.rb', line 42

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

    XMLElement.build_xml(obj_xml,'SECURITY_GROUP')
end

Instance Method Details

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

Allocates a new SecurityGroup in OpenNebula

Parameters:

  • description (String)

    The contents of the SecurityGroup.

Returns:



76
77
78
# File 'lib/opennebula/security_group.rb', line 76

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

Returns:



121
122
123
124
125
# File 'lib/opennebula/security_group.rb', line 121

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

Parameters:

  • octet (String)

    Permissions octed , e.g. 640

Returns:



112
113
114
# File 'lib/opennebula/security_group.rb', line 112

def chmod_octet(octet)
    super(SECGROUP_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:



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

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

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

Clones this SecurityGroup into a new one

Parameters:

  • name (String)

    for the new SecurityGroup.

Returns:

  • (Integer, OpenNebula::Error)

    The new SecurityGroup ID in case of success, Error otherwise



133
134
135
136
137
138
139
# File 'lib/opennebula/security_group.rb', line 133

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

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

    return rc
end

#commit(recover) ⇒ nil, OpenNebula::Error

Commit SG changes to associated VMs

VMs. This is intended for retrying updates of VMs or reinitialize the updating process if oned stopped or fail.

Parameters:

  • recover (Bool)

    If true will only operate on outdated and error

Returns:



159
160
161
# File 'lib/opennebula/security_group.rb', line 159

def commit(recover)
    return call(SECGROUP_METHODS[:commit], @pe_id, recover)
end

#deleteObject

Deletes the SecurityGroup



81
82
83
# File 'lib/opennebula/security_group.rb', line 81

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

#gidObject

Returns the group identifier

return

Integer the element’s group ID



197
198
199
# File 'lib/opennebula/security_group.rb', line 197

def gid
    self['GID'].to_i
end

#infoObject Also known as: info!

Retrieves the information of the given SecurityGroup.



64
65
66
# File 'lib/opennebula/security_group.rb', line 64

def info()
    super(SECGROUP_METHODS[:info], 'SECURITY_GROUP')
end

#owner_idObject



201
202
203
# File 'lib/opennebula/security_group.rb', line 201

def owner_id
    self['UID'].to_i
end

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

Renames this SecurityGroup

Parameters:

  • name (String)

    New name for the SecurityGroup.

Returns:



147
148
149
# File 'lib/opennebula/security_group.rb', line 147

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

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

Replaces the securitygroup contents

Parameters:

  • new_securitygroup (String)

    New securitygroup contents

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

    True to append new attributes instead of replace the whole securitygroup

Returns:



93
94
95
# File 'lib/opennebula/security_group.rb', line 93

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

#vm_idsObject

Returns three arrays with the numeric vm ids for vms updated, outdated (include updating) and error



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/opennebula/security_group.rb', line 169

def vm_ids
    updated = Array.new

    self.each("UPDATED_VMS/ID") do |id|
        updated << id.text.to_i
    end

    outdated = Array.new

    self.each("OUTDATED_VMS/ID") do |id|
        outdated << id.text.to_i
    end

    self.each("UPDATING_VMS/ID") do |id|
        outdated << id.text.to_i
    end

    error = Array.new

    self.each("ERROR_VMS/ID") do |id|
        error << id.text.to_i
    end

    return [updated, outdated, error]
end