class OpenNebula::Datastore

Constants

DATASTORE_METHODS

Constants and Class Methods

DATASTORE_STATES
DATASTORE_TYPES
SHORT_DATASTORE_STATES
SHORT_DATASTORE_TYPES

Public Class Methods

build_xml(pe_id=nil) click to toggle source

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
new(xml, client) click to toggle source

Class constructor

Calls superclass method
# File lib/opennebula/datastore.rb, line 70
def initialize(xml, client)
    super(xml,client)
end

Public Instance Methods

allocate(description, cluster_id=ClusterPool::NONE_CLUSTER_ID) click to toggle source

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
Calls superclass method
# File lib/opennebula/datastore.rb, line 92
def allocate(description, cluster_id=ClusterPool::NONE_CLUSTER_ID)
    super(DATASTORE_METHODS[:allocate], description, cluster_id)
end
chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, other_m, other_a) click to toggle source

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
Calls superclass method
# 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
chmod_octet(octet) click to toggle source

Changes the datastore permissions.

@param octet [String] Permissions octed , e.g. 640 @return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
Calls superclass method
# File lib/opennebula/datastore.rb, line 129
def chmod_octet(octet)
    super(DATASTORE_METHODS[:chmod], octet)
end
chown(uid, gid) click to toggle source

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
Calls superclass method
# File lib/opennebula/datastore.rb, line 120
def chown(uid, gid)
    super(DATASTORE_METHODS[:chown], uid, gid)
end
contains(id) click to toggle source

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
delete() click to toggle source

Deletes the Datastore

Calls superclass method
# File lib/opennebula/datastore.rb, line 97
def delete()
    super(DATASTORE_METHODS[:delete])
end
disable() click to toggle source

Disables a Datastore

# File lib/opennebula/datastore.rb, line 160
def disable
    return call(DATASTORE_METHODS[:enable], @pe_id, false)
end
enable() click to toggle source

Enables a Datastore

# File lib/opennebula/datastore.rb, line 155
def enable
    return call(DATASTORE_METHODS[:enable], @pe_id, true)
end
img_ids() click to toggle source

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
info() click to toggle source

Retrieves the information of the given Datastore.

Calls superclass method
# File lib/opennebula/datastore.rb, line 79
def info()
    super(DATASTORE_METHODS[:info], 'DATASTORE')
end
Also aliased as: info!
info!()
Alias for: info
rename(name) click to toggle source

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
short_state_str() click to toggle source

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
short_type_str() click to toggle source

Returns the datastore type (string value)

# File lib/opennebula/datastore.rb, line 179
def short_type_str
    SHORT_DATASTORE_TYPES[type_str]
end
state() click to toggle source

Returns the state of the datastore (numeric value)

# File lib/opennebula/datastore.rb, line 184
def state
    self['STATE'].to_i
end
state_str() click to toggle source

Returns the state of the datastore (string value)

# File lib/opennebula/datastore.rb, line 189
def state_str
    DATASTORE_STATES[state]
end
type() click to toggle source

Returns the datastore type

# File lib/opennebula/datastore.rb, line 169
def type
    self['TYPE'].to_i
end
type_str() click to toggle source

Returns the datastore type (string value)

# File lib/opennebula/datastore.rb, line 174
def type_str
    DATASTORE_TYPES[type]
end
update(new_template, append=false) click to toggle source

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
Calls superclass method
# File lib/opennebula/datastore.rb, line 109
def update(new_template, append=false)
    super(DATASTORE_METHODS[:update], new_template, append ? 1 : 0)
end