Class: OpenNebula::Datastore

Inherits:
PoolElement show all
Defined in:
opennebula/datastore.rb

Constant Summary

DATASTORE_METHODS =

Constants and Class Methods

{
    :info       => "datastore.info",
    :allocate   => "datastore.allocate",
    :delete     => "datastore.delete",
    :update     => "datastore.update",
    :chown      => "datastore.chown",
    :chmod      => "datastore.chmod"
}
DATASTORE_TYPES =
%w{IMAGE SYSTEM FILE}
SHORT_DATASTORE_TYPES =
{
    "IMAGE" => "img",
    "SYSTEM"=> "sys",
    "FILE"  => "fil"
}

Class Method Summary (collapse)

Instance Method Summary (collapse)

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

- (Datastore) initialize(xml, client)

Class constructor



61
62
63
# File 'opennebula/datastore.rb', line 61

def initialize(xml, client)
    super(xml,client)
end

Class Method Details

+ (Object) build_xml(pe_id = nil)

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)


50
51
52
53
54
55
56
57
58
# File 'opennebula/datastore.rb', line 50

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

Instance Method Details

- (Integer, OpenNebula::Error) allocate(description, cluster_id = ClusterPool::NONE_CLUSTER_ID)

Allocates a new Datastore in OpenNebula

Parameters:

  • description (String)

    The template of the Datastore.

  • cluster_id (Integer) (defaults to: ClusterPool::NONE_CLUSTER_ID)

    Id of the cluster

Returns:



97
98
99
# File 'opennebula/datastore.rb', line 97

def allocate(description, cluster_id=ClusterPool::NONE_CLUSTER_ID)
    super(DATASTORE_METHODS[:allocate], description, cluster_id)
end

- (nil, OpenNebula::Error) chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, other_m, other_a)

Changes the datastore permissions. Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change

Returns:



143
144
145
146
147
# File 'opennebula/datastore.rb', line 143

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

- (nil, OpenNebula::Error) chmod_octet(octet)

Changes the datastore permissions.

Parameters:

  • octet (String)

    Permissions octed , e.g. 640

Returns:



134
135
136
# File 'opennebula/datastore.rb', line 134

def chmod_octet(octet)
    super(DATASTORE_METHODS[:chmod], octet)
end

- (nil, OpenNebula::Error) chown(uid, gid)

Changes the owner/group

Parameters:

  • uid (Integer)

    the new owner id. Set to -1 to leave the current one

  • gid (Integer)

    the new group id. Set to -1 to leave the current one

Returns:



125
126
127
# File 'opennebula/datastore.rb', line 125

def chown(uid, gid)
    super(DATASTORE_METHODS[:chown], uid, gid)
end

- (Object) contains(id)

Returns whether or not the image with id 'id' is part of this datastore



154
155
156
157
158
159
160
# File 'opennebula/datastore.rb', line 154

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

- (Object) delete

Deletes the Datastore



102
103
104
# File 'opennebula/datastore.rb', line 102

def delete()
    super(DATASTORE_METHODS[:delete])
end

- (Object) img_ids

Returns an array with the numeric image ids



163
164
165
166
167
168
169
170
171
# File 'opennebula/datastore.rb', line 163

def img_ids
    array = Array.new

    self.each("IMAGES/ID") do |id|
        array << id.text.to_i
    end

    return array
end

- (Object) info Also known as: info!

Retrieves the information of the given Datastore.



84
85
86
# File 'opennebula/datastore.rb', line 84

def info()
    super(DATASTORE_METHODS[:info], 'DATASTORE')
end

- (Object) short_type_str

Returns the datastore type (string value)



79
80
81
# File 'opennebula/datastore.rb', line 79

def short_type_str
    SHORT_DATASTORE_TYPES[type_str]
end

- (Object) type

XML-RPC Methods for the Datastore Object

Returns the datastore type



69
70
71
# File 'opennebula/datastore.rb', line 69

def type
    self['TYPE'].to_i
end

- (Object) type_str

Returns the datastore type (string value)



74
75
76
# File 'opennebula/datastore.rb', line 74

def type_str
    DATASTORE_TYPES[type]
end

- (nil, OpenNebula::Error) update(new_template, append = false)

Replaces the template contents

Parameters:

  • new_template (String)

    New template contents

  • append (true, false) (defaults to: false)

    True to append new attributes instead of replace the whole template

Returns:



114
115
116
# File 'opennebula/datastore.rb', line 114

def update(new_template, append=false)
    super(DATASTORE_METHODS[:update], new_template, append ? 1 : 0)
end