class OpenNebula::Datastore
Constants
- DATASTORE_METHODS
Constants and Class Methods
- DATASTORE_STATES
- DATASTORE_TYPES
- SHORT_DATASTORE_STATES
- SHORT_DATASTORE_TYPES
Public Class Methods
Creates a Datastore description with just its
identifier this method should be used to create plain Datastore objects. id
the id of the
user
Example:
datastore = Datastore.new(Datastore.build_xml(3),rpc_client)
# File lib/opennebula/datastore.rb, line 59 def Datastore.build_xml(pe_id=nil) if pe_id datastore_xml = "<DATASTORE><ID>#{pe_id}</ID></DATASTORE>" else datastore_xml = "<DATASTORE></DATASTORE>" end XMLElement.build_xml(datastore_xml,'DATASTORE') end
Class constructor
# File lib/opennebula/datastore.rb, line 70 def initialize(xml, client) super(xml,client) end
Public Instance Methods
Allocates a new Datastore in OpenNebula
@param description [String] The template of the Datastore. @param cluster_id [Integer] Id of the cluster
@return [Integer, OpenNebula::Error] the new ID in case of
success, error otherwise
# File lib/opennebula/datastore.rb, line 92 def allocate(description, cluster_id=ClusterPool::NONE_CLUSTER_ID) super(DATASTORE_METHODS[:allocate], description, cluster_id) end
Changes the datastore permissions. Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change
@return [nil, OpenNebula::Error] nil in case of success, Error
otherwise
# File lib/opennebula/datastore.rb, line 138 def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, other_m, other_a) super(DATASTORE_METHODS[:chmod], owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, other_m, other_a) end
Changes the datastore permissions.
@param octet [String] Permissions octed , e.g. 640 @return [nil, OpenNebula::Error] nil in case of success, Error
otherwise
# File lib/opennebula/datastore.rb, line 129 def chmod_octet(octet) super(DATASTORE_METHODS[:chmod], octet) end
Changes the owner/group
@param uid [Integer] the new owner id. Set to -1 to leave the current one @param gid [Integer] the new group id. Set to -1 to leave the current one
@return [nil, OpenNebula::Error] nil in case of success, Error
otherwise
# File lib/opennebula/datastore.rb, line 120 def chown(uid, gid) super(DATASTORE_METHODS[:chown], uid, gid) end
Returns whether or not the image with id 'id' is part of this datastore
# File lib/opennebula/datastore.rb, line 199 def contains(id) #This doesn't work in ruby 1.8.5 #return self["DATASTORE/ID[.=#{uid}]"] != nil id_array = retrieve_elements('IMAGES/ID') return id_array != nil && id_array.include?(uid.to_s) end
Deletes the Datastore
# File lib/opennebula/datastore.rb, line 97 def delete() super(DATASTORE_METHODS[:delete]) end
Disables a Datastore
# File lib/opennebula/datastore.rb, line 160 def disable return call(DATASTORE_METHODS[:enable], @pe_id, false) end
Enables a Datastore
# File lib/opennebula/datastore.rb, line 155 def enable return call(DATASTORE_METHODS[:enable], @pe_id, true) end
Returns an array with the numeric image ids
# File lib/opennebula/datastore.rb, line 208 def img_ids array = Array.new self.each("IMAGES/ID") do |id| array << id.text.to_i end return array end
Retrieves the information of the given Datastore.
# File lib/opennebula/datastore.rb, line 79 def info() super(DATASTORE_METHODS[:info], 'DATASTORE') end
Renames this datastore
@param name [String] New name for the datastore
@return [nil, OpenNebula::Error] nil in case of success, Error
otherwise
# File lib/opennebula/datastore.rb, line 150 def rename(name) return call(DATASTORE_METHODS[:rename], @pe_id, name) end
Returns the state of the datastore (string value)
# File lib/opennebula/datastore.rb, line 194 def short_state_str SHORT_DATASTORE_STATES[state_str] end
Returns the datastore type (string value)
# File lib/opennebula/datastore.rb, line 179 def short_type_str SHORT_DATASTORE_TYPES[type_str] end
Returns the state of the datastore (numeric value)
# File lib/opennebula/datastore.rb, line 184 def state self['STATE'].to_i end
Returns the state of the datastore (string value)
# File lib/opennebula/datastore.rb, line 189 def state_str DATASTORE_STATES[state] end
Returns the datastore type
# File lib/opennebula/datastore.rb, line 169 def type self['TYPE'].to_i end
Returns the datastore type (string value)
# File lib/opennebula/datastore.rb, line 174 def type_str DATASTORE_TYPES[type] end
Replaces the template contents
@param new_template [String] New template contents @param append [true, false] True to append new attributes instead of
replace the whole template
@return [nil, OpenNebula::Error] nil in case of success, Error
otherwise
# File lib/opennebula/datastore.rb, line 109 def update(new_template, append=false) super(DATASTORE_METHODS[:update], new_template, append ? 1 : 0) end