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", :update => "group.update", :delete => "group.delete", :quota => "group.quota", :add_provider => "group.addprovider", :del_provider => "group.delprovider" }
- SELF =
Flag for requesting connected user’s group info
-1
- GROUP_DEFAULT_ACLS =
Default resource ACL’s for group users (create)
"VM+IMAGE+TEMPLATE+DOCUMENT"
- ALL_CLUSTERS_IN_ZONE =
10
- GROUP_ADMIN_SUNSTONE_VIEWS =
The default view for group and group admins, must be defined in sunstone_views.yaml
"vdcadmin"
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
-
#add_provider(zone_id, cluster_id) ⇒ nil, OpenNebula::Error
Adds a resource provider to this group.
-
#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(group_hash) ⇒ Object
Creates a group based in a group definition hash group_hash the group name group_hash the admin user definition hash, see def create_admin_user function description for details.
-
#del_provider(zone_id, cluster_id) ⇒ nil, OpenNebula::Error
Deletes a resource provider from this 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.
-
#update(new_template = nil, append = false) ⇒ nil, OpenNebula::Error
Replaces the template contents.
-
#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
65 66 67 |
# File 'lib/opennebula/group.rb', line 65 def initialize(xml, client) super(xml,client) end |
Class Method Details
.build_xml(pe_id = nil) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/opennebula/group.rb', line 54 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
#add_provider(zone_id, cluster_id) ⇒ nil, OpenNebula::Error
Adds a resource provider to this group
188 189 190 |
# File 'lib/opennebula/group.rb', line 188 def add_provider(zone_id, cluster_id) return call(GROUP_METHODS[:add_provider], @pe_id, zone_id.to_i, cluster_id.to_i) end |
#allocate(groupname) ⇒ Object
Allocates a new Group in OpenNebula
groupname
A string containing the name of the Group.
147 148 149 |
# File 'lib/opennebula/group.rb', line 147 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
207 208 209 210 211 212 213 |
# File 'lib/opennebula/group.rb', line 207 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(group_hash) ⇒ Object
Creates a group based in a group definition hash
group_hash[:name] the group name
group_hash[:group_admin] the admin user definition hash, see def
create_admin_user function description for details.
group_hash[:resource_providers]
group_hash[:resource_providers][:zone_id]
group_hash[:resource_providers][:cluster_id]
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/opennebula/group.rb', line 89 def create(group_hash) # Check arguments if !group_hash[:name] return OpenNebula::Error.new("Group name not defined") end if group_hash[:group_admin] if group_hash[:group_admin][:name] && !group_hash[:group_admin][:password] error_msg = "Admin user password not defined" return OpenNebula::Error.new(error_msg) end end # Allocate group rc = self.allocate(group_hash[:name]) return rc if OpenNebula.is_error?(rc) # Handle resource providers group_hash[:resource_providers].each { |rp| next if rp[:zone_id].nil? && rp[:cluster_id].nil? if rp[:cluster_id].class == String && rp[:cluster_id] == "ALL" add_provider(rp[:zone_id],ALL_CLUSTERS_IN_ZONE) else add_provider(rp[:zone_id],rp[:cluster_id]) end } if !group_hash[:resource_providers].nil? # Set group ACLs to create resources rc, msg = create_default_acls(group_hash[:resources]) if OpenNebula.is_error?(rc) self.delete error_msg = "Error creating group ACL's: #{rc.}" return OpenNebula::Error.new(error_msg) end # Create associated group admin if needed rc = create_admin_user(group_hash) if OpenNebula.is_error?(rc) self.delete error_msg = "Error creating admin group: #{rc.}" return OpenNebula::Error.new(error_msg) end # Add default Sunstone views for the group if group_hash[:views] str = "SUNSTONE_VIEWS=\"#{group_hash[:views].join(",")}\"\n" self.update(str, true) end return 0 end |
#del_provider(zone_id, cluster_id) ⇒ nil, OpenNebula::Error
Deletes a resource provider from this group
198 199 200 |
# File 'lib/opennebula/group.rb', line 198 def del_provider(zone_id, cluster_id) return call(GROUP_METHODS[:del_provider], @pe_id, zone_id.to_i, cluster_id.to_i) end |
#delete ⇒ Object
Deletes the Group
164 165 166 |
# File 'lib/opennebula/group.rb', line 164 def delete() super(GROUP_METHODS[:delete]) end |
#info ⇒ Object Also known as: info!
Retrieves the information of the given Group.
75 76 77 |
# File 'lib/opennebula/group.rb', line 75 def info() super(GROUP_METHODS[:info], 'GROUP') end |
#set_quota(quota) ⇒ nil, OpenNebula::Error
Sets the group quota limits
173 174 175 176 177 178 179 180 |
# File 'lib/opennebula/group.rb', line 173 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 |
#update(new_template = nil, append = false) ⇒ nil, OpenNebula::Error
Replaces the template contents
159 160 161 |
# File 'lib/opennebula/group.rb', line 159 def update(new_template=nil, append=false) super(GROUP_METHODS[:update], new_template, append ? 1 : 0) end |
#user_ids ⇒ Object
Returns an array with the numeric user ids
216 217 218 219 220 221 222 223 224 |
# File 'lib/opennebula/group.rb', line 216 def user_ids array = Array.new self.each("USERS/ID") do |id| array << id.text.to_i end return array end |