Class: OpenNebula::Group
- Inherits:
-
PoolElement
- Object
- XMLElement
- PoolElement
- OpenNebula::Group
- Defined in:
- lib/opennebula/group.rb
Constant Summary collapse
- 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
-
.build_xml(pe_id = nil) ⇒ Object
Creates a Group description with just its identifier this method should be used to create plain Group objects.
Instance Method Summary collapse
-
#allocate(groupname) ⇒ Object
Allocates a new Group in OpenNebula.
-
#contains(uid) ⇒ Object
Returns whether or not the user with id ‘uid’ is part of this group.
-
#create_acls(filename = GROUP_DEFAULT) ⇒ Object
Creates ACLs for the group.
-
#delete ⇒ Object
Deletes the Group.
-
#info ⇒ Object
(also: #info!)
Retrieves the information of the given Group.
-
#initialize(xml, client) ⇒ Group
constructor
Class constructor.
-
#set_quota(quota) ⇒ nil, OpenNebula::Error
Sets the group quota limits.
-
#user_ids ⇒ Object
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, #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) ⇒ Group
Class constructor
61 62 63 |
# File 'lib/opennebula/group.rb', line 61 def initialize(xml, client) super(xml,client) end |
Class Method Details
.build_xml(pe_id = nil) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/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
#allocate(groupname) ⇒ Object
Allocates a new Group in OpenNebula
groupname
A string containing the name of the Group.
116 117 118 |
# File 'lib/opennebula/group.rb', line 116 def allocate(groupname) super(GROUP_METHODS[:allocate], groupname) end |
#contains(uid) ⇒ Object
Returns whether or not the user with id ‘uid’ is part of this group
144 145 146 147 148 149 150 |
# File 'lib/opennebula/group.rb', line 144 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 |
#create_acls(filename = GROUP_DEFAULT) ⇒ Object
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 'lib/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 |
#delete ⇒ Object
Deletes the Group
121 122 123 |
# File 'lib/opennebula/group.rb', line 121 def delete() super(GROUP_METHODS[:delete]) end |
#info ⇒ Object Also known as: info!
Retrieves the information of the given Group.
107 108 109 |
# File 'lib/opennebula/group.rb', line 107 def info() super(GROUP_METHODS[:info], 'GROUP') end |
#set_quota(quota) ⇒ nil, OpenNebula::Error
Sets the group quota limits
130 131 132 133 134 135 136 137 |
# File 'lib/opennebula/group.rb', line 130 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 |
#user_ids ⇒ Object
Returns an array with the numeric user ids
153 154 155 156 157 158 159 160 161 |
# File 'lib/opennebula/group.rb', line 153 def user_ids array = Array.new self.each("USERS/ID") do |id| array << id.text.to_i end return array end |