Class: OpenNebula::Datastore

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

Constant Summary collapse

DATASTORE_METHODS =

Constants and Class Methods

{
    :info       => "datastore.info",
    :allocate   => "datastore.allocate",
    :delete     => "datastore.delete",
    :update     => "datastore.update",
    :chown      => "datastore.chown",
    :chmod      => "datastore.chmod",
    :rename     => "datastore.rename",
    :enable     => "datastore.enable"
}
DATASTORE_TYPES =
%w{IMAGE SYSTEM FILE}
SHORT_DATASTORE_TYPES =
{
    "IMAGE" => "img",
    "SYSTEM"=> "sys",
    "FILE"  => "fil"
}
DATASTORE_STATES =
%w{READY DISABLED}
SHORT_DATASTORE_STATES =
{
    "READY"     => "on",
    "DISABLED"  => "off"
}

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, #retrieve_xmlelements, #template_like_str, #template_str, #template_xml, #text, #to_hash, #to_xml, #xml_nil?

Constructor Details

#initialize(xml, client) ⇒ Datastore

Class constructor



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

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

Class Method Details

.build_xml(pe_id = nil) ⇒ Object

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)


59
60
61
62
63
64
65
66
67
# 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

Instance Method Details

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

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, -1 to use default

Returns:



92
93
94
# 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) ⇒ nil, OpenNebula::Error

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

Returns:



138
139
140
141
142
# 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) ⇒ nil, OpenNebula::Error

Changes the datastore permissions.

Parameters:

  • octet (String)

    Permissions octed , e.g. 640

Returns:



129
130
131
# File 'lib/opennebula/datastore.rb', line 129

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

#chown(uid, gid) ⇒ nil, OpenNebula::Error

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:



120
121
122
# File 'lib/opennebula/datastore.rb', line 120

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

#contains(id) ⇒ Object

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



199
200
201
202
203
204
205
# 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

#deleteObject

Deletes the Datastore



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

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

#disableObject

Disables a Datastore



160
161
162
# File 'lib/opennebula/datastore.rb', line 160

def disable
    return call(DATASTORE_METHODS[:enable], @pe_id, false)
end

#enableObject

Enables a Datastore



155
156
157
# File 'lib/opennebula/datastore.rb', line 155

def enable
    return call(DATASTORE_METHODS[:enable], @pe_id, true)
end

#img_idsObject

Returns an array with the numeric image ids



208
209
210
211
212
213
214
215
216
# 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

#infoObject Also known as: info!

Retrieves the information of the given Datastore.



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

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

#rename(name) ⇒ nil, OpenNebula::Error

Renames this datastore

Parameters:

  • name (String)

    New name for the datastore

Returns:



150
151
152
# File 'lib/opennebula/datastore.rb', line 150

def rename(name)
    return call(DATASTORE_METHODS[:rename], @pe_id, name)
end

#short_state_strObject

Returns the state of the datastore (string value)



194
195
196
# File 'lib/opennebula/datastore.rb', line 194

def short_state_str
    SHORT_DATASTORE_STATES[state_str]
end

#short_type_strObject

Returns the datastore type (string value)



179
180
181
# File 'lib/opennebula/datastore.rb', line 179

def short_type_str
    SHORT_DATASTORE_TYPES[type_str]
end

#stateObject

Returns the state of the datastore (numeric value)



184
185
186
# File 'lib/opennebula/datastore.rb', line 184

def state
    self['STATE'].to_i
end

#state_strObject

Returns the state of the datastore (string value)



189
190
191
# File 'lib/opennebula/datastore.rb', line 189

def state_str
    DATASTORE_STATES[state]
end

#typeObject

Returns the datastore type



169
170
171
# File 'lib/opennebula/datastore.rb', line 169

def type
    self['TYPE'].to_i
end

#type_strObject

Returns the datastore type (string value)



174
175
176
# File 'lib/opennebula/datastore.rb', line 174

def type_str
    DATASTORE_TYPES[type]
end

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

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:



109
110
111
# File 'lib/opennebula/datastore.rb', line 109

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