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"
}

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, #element_xml, #has_elements?, #initialize_xml, #name, #retrieve_elements, #template_like_str, #template_str, #template_xml, #text, #to_hash, #to_xml

Constructor Details

#initialize(xml, client) ⇒ SecurityGroup

Class constructor



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

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



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

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:



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

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:



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

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:



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

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:



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

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



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

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

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

    return rc
end

#deleteObject

Deletes the SecurityGroup



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

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

#gidObject

Returns the group identifier

return

Integer the element’s group ID



156
157
158
# File 'lib/opennebula/security_group.rb', line 156

def gid
    self['GID'].to_i
end

#infoObject Also known as: info!

Retrieves the information of the given SecurityGroup.



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

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

#owner_idObject



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

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:



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

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:



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

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