Class: OpenNebula::Group

Inherits:
PoolElement show all
Defined in:
OpenNebula/Group.rb

Constant Summary

GROUP_METHODS =

Constants and Class Methods

{
    :info     => "group.info",
    :allocate => "group.allocate",
    :delete   => "group.delete",
    :quota    => "group.quota"
}
SELF =

Flag for requesting connected user's group info

-1
GROUP_DEFAULT =
"/etc/one/group.default"

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

- (Group) initialize(xml, client)

Class constructor



61
62
63
# File 'OpenNebula/Group.rb', line 61

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

Class Method Details

+ (Object) build_xml(pe_id = nil)

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

Example:

group = Group.new(Group.build_xml(3),rpc_client)


50
51
52
53
54
55
56
57
58
# File 'OpenNebula/Group.rb', line 50

def Group.build_xml(pe_id=nil)
    if pe_id
        group_xml = "<GROUP><ID>#{pe_id}</ID></GROUP>"
    else
        group_xml = "<GROUP></GROUP>"
    end

    XMLElement.build_xml(group_xml,'GROUP')
end

Instance Method Details

- (Object) allocate(groupname)

Allocates a new Group in OpenNebula

groupname A string containing the name of the Group.



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

def allocate(groupname)
    super(GROUP_METHODS[:allocate], groupname)
end

- (Object) contains(uid)

Returns whether or not the user with id 'uid' is part of this group



142
143
144
145
146
147
148
# File 'OpenNebula/Group.rb', line 142

def contains(uid)
    #This doesn't work in ruby 1.8.5
    #return self["USERS/ID[.=#{uid}]"] != nil

    id_array = retrieve_elements('USERS/ID')
    return id_array != nil && id_array.include?(uid.to_s)
end

- (Object) create_acls(filename = GROUP_DEFAULT)

Creates ACLs for the group. The ACL rules are described in a file



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'OpenNebula/Group.rb', line 70

def create_acls(filename = GROUP_DEFAULT)
    if !File.readable?(filename)
        return -1, "Cannot read deafult ACL file for group"
    end

    msg = String.new

    File.open(filename).each_line{ |l|
        next if l.match(/^#/)

        rule  = "@#{@pe_id} #{l}"
        parse = OpenNebula::Acl.parse_rule(rule)

        if OpenNebula.is_error?(parse)
            return -1, "Error parsing rule #{rule}: #{parse.message}"
        end

        xml = OpenNebula::Acl.build_xml
        acl = OpenNebula::Acl.new(xml, @client)

        rc = acl.allocate(*parse)

        if OpenNebula.is_error?(rc)
            return -1, "Error creating rule #{rule}: #{rc.message}"
        else
            msg << "ACL_ID: #{acl.id}\n"
        end
    }

    return 0, msg
end

- (Object) delete

Deletes the Group



119
120
121
# File 'OpenNebula/Group.rb', line 119

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

- (Object) info

Retrieves the information of the given Group.



107
108
109
# File 'OpenNebula/Group.rb', line 107

def info()
    super(GROUP_METHODS[:info], 'GROUP')
end

- (nil, OpenNebula::Error) set_quota(quota)

Sets the group quota limits

Parameters:

  • quota (String)

    a template (XML or txt) with the new quota limits

Returns:



128
129
130
131
132
133
134
135
# File 'OpenNebula/Group.rb', line 128

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

    rc = @client.call(GROUP_METHODS[:quota],@pe_id, quota)
    rc = nil if !OpenNebula.is_error?(rc)

    return rc
end

- (Object) user_ids

Returns an array with the numeric user ids



151
152
153
154
155
156
157
158
159
# File 'OpenNebula/Group.rb', line 151

def user_ids
    array = Array.new

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

    return array
end