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" }
- 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
Retrieves the information of the given Group.
-
#initialize(xml, client) ⇒ Group
constructor
——————————————————————— Class constructor ———————————————————————.
-
#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
#[], #attr, #each, #each_xpath, #has_elements?, #initialize_xml, #name, #retrieve_elements, #template_like_str, #template_str, #text, #to_hash, #to_xml
Constructor Details
#initialize(xml, client) ⇒ Group
Class constructor
60 61 62 63 64 |
# File 'lib/OpenNebula/Group.rb', line 60 def initialize(xml, client) super(xml,client) @client = client end |
Class Method Details
.build_xml(pe_id = nil) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/OpenNebula/Group.rb', line 47 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.
115 116 117 |
# File 'lib/OpenNebula/Group.rb', line 115 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
129 130 131 132 133 134 135 |
# File 'lib/OpenNebula/Group.rb', line 129 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
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 101 |
# File 'lib/OpenNebula/Group.rb', line 71 def create_acls(filename = GROUP_DEFAULT) if !File.readable?(filename) return -1, "Can not 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
120 121 122 |
# File 'lib/OpenNebula/Group.rb', line 120 def delete() super(GROUP_METHODS[:delete]) end |
#info ⇒ Object
Retrieves the information of the given Group.
108 109 110 |
# File 'lib/OpenNebula/Group.rb', line 108 def info() super(GROUP_METHODS[:info], 'GROUP') end |
#user_ids ⇒ Object
Returns an array with the numeric user ids
138 139 140 141 142 143 144 145 146 |
# File 'lib/OpenNebula/Group.rb', line 138 def user_ids array = Array.new self.each("USERS/ID") do |id| array << id.text.to_i end return array end |