Class: OpenNebula::Group
- Inherits:
-
PoolElement
- Object
- XMLElement
- PoolElement
- OpenNebula::Group
- Defined in:
- OpenNebula/Group.rb
Constant Summary
- GROUP_METHODS =
{ :info => "group.info", :allocate => "group.allocate", :delete => "group.delete" }
- SELF =
Flag for requesting connected user's group info
-1
- GROUP_DEFAULT =
"/etc/one/group.default"
Class Method Summary (collapse)
-
+ (Object) build_xml(pe_id = nil)
Creates a Group description with just its identifier this method should be used to create plain Group objects.
Instance Method Summary (collapse)
-
- (Object) allocate(groupname)
Allocates a new Group in OpenNebula.
-
- (Object) contains(uid)
Returns whether or not the user with id 'uid' is part of this group.
-
- (Object) create_acls(filename = GROUP_DEFAULT)
Creates ACLs for the group.
-
- (Object) delete
Deletes the Group.
-
- (Object) info
Retrieves the information of the given Group.
-
- (Group) initialize(xml, client)
constructor
Class constructor.
-
- (Object) user_ids
Returns an array with the numeric user ids.
Methods inherited from PoolElement
#id, #name, new_with_id, #to_str
Methods inherited from XMLElement
#[], #add_element, #attr, #delete_element, #each, #each_xpath, #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
128 129 130 131 132 133 134 |
# File 'OpenNebula/Group.rb', line 128 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.}" 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.}" 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 |
- (Object) user_ids
Returns an array with the numeric user ids
137 138 139 140 141 142 143 144 145 |
# File 'OpenNebula/Group.rb', line 137 def user_ids array = Array.new self.each("USERS/ID") do |id| array << id.text.to_i end return array end |