Class: OpenNebula::Datastore
- Inherits:
-
PoolElement
- Object
- XMLElement
- PoolElement
- OpenNebula::Datastore
- 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 BACKUP}
- SHORT_DATASTORE_TYPES =
{ "IMAGE" => "img", "SYSTEM"=> "sys", "FILE" => "fil", "BACKUP"=> "bck" }
- DATASTORE_STATES =
%w{READY DISABLED}
- SHORT_DATASTORE_STATES =
{ "READY" => "on", "DISABLED" => "off" }
Instance Attribute Summary
Attributes inherited from PoolElement
Class Method Summary collapse
-
.build_xml(pe_id = nil) ⇒ Object
Creates a Datastore description with just its identifier this method should be used to create plain Datastore objects.
Instance Method Summary collapse
-
#allocate(description, cluster_id = ClusterPool::NONE_CLUSTER_ID) ⇒ Integer, OpenNebula::Error
Allocates a new Datastore in OpenNebula.
-
#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.
-
#chmod_octet(octet) ⇒ nil, OpenNebula::Error
Changes the datastore permissions.
-
#chown(uid, gid) ⇒ nil, OpenNebula::Error
Changes the owner/group.
-
#contains(id) ⇒ Object
Returns whether or not the image with id ‘id’ is part of this datastore.
-
#delete ⇒ Object
Deletes the Datastore.
-
#disable ⇒ Object
Disables a Datastore.
-
#enable ⇒ Object
Enables a Datastore.
-
#img_ids ⇒ Object
Returns an array with the numeric image ids.
-
#info(decrypt = false) ⇒ Object
(also: #info!)
Retrieves the information of the given Datastore.
-
#initialize(xml, client) ⇒ Datastore
constructor
Class constructor.
-
#rename(name) ⇒ nil, OpenNebula::Error
Renames this datastore.
-
#short_state_str ⇒ Object
Returns the state of the datastore (string value).
-
#short_type_str ⇒ Object
Returns the datastore type (string value).
-
#state ⇒ Object
Returns the state of the datastore (numeric value).
-
#state_str ⇒ Object
Returns the state of the datastore (string value).
-
#type ⇒ Object
Returns the datastore type.
-
#type_str ⇒ Object
Returns the datastore type (string value).
-
#update(new_template, append = false) ⇒ nil, OpenNebula::Error
Replaces the template contents.
Methods inherited from PoolElement
#id, new_with_id, #replace, #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, #set_content, #template_like_str, #template_str, #template_xml, #text, #to_hash, #to_xml, #xml_nil?
Constructor Details
#initialize(xml, client) ⇒ Datastore
Class constructor
71 72 73 |
# File 'lib/opennebula/datastore.rb', line 71 def initialize(xml, client) super(xml,client) end |
Class Method Details
.build_xml(pe_id = nil) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/opennebula/datastore.rb', line 60 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
93 94 95 |
# File 'lib/opennebula/datastore.rb', line 93 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
139 140 141 142 143 |
# File 'lib/opennebula/datastore.rb', line 139 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.
130 131 132 |
# File 'lib/opennebula/datastore.rb', line 130 def chmod_octet(octet) super(DATASTORE_METHODS[:chmod], octet) end |
#chown(uid, gid) ⇒ nil, OpenNebula::Error
Changes the owner/group
121 122 123 |
# File 'lib/opennebula/datastore.rb', line 121 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
200 201 202 203 204 205 206 |
# File 'lib/opennebula/datastore.rb', line 200 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 ⇒ Object
Deletes the Datastore
98 99 100 |
# File 'lib/opennebula/datastore.rb', line 98 def delete() super(DATASTORE_METHODS[:delete]) end |
#disable ⇒ Object
Disables a Datastore
161 162 163 |
# File 'lib/opennebula/datastore.rb', line 161 def disable return call(DATASTORE_METHODS[:enable], @pe_id, false) end |
#enable ⇒ Object
Enables a Datastore
156 157 158 |
# File 'lib/opennebula/datastore.rb', line 156 def enable return call(DATASTORE_METHODS[:enable], @pe_id, true) end |
#img_ids ⇒ Object
Returns an array with the numeric image ids
209 210 211 212 213 214 215 216 217 |
# File 'lib/opennebula/datastore.rb', line 209 def img_ids array = Array.new self.each("IMAGES/ID") do |id| array << id.text.to_i end return array end |
#info(decrypt = false) ⇒ Object Also known as: info!
Retrieves the information of the given Datastore.
80 81 82 |
# File 'lib/opennebula/datastore.rb', line 80 def info(decrypt = false) super(DATASTORE_METHODS[:info], 'DATASTORE', decrypt) end |
#rename(name) ⇒ nil, OpenNebula::Error
Renames this datastore
151 152 153 |
# File 'lib/opennebula/datastore.rb', line 151 def rename(name) return call(DATASTORE_METHODS[:rename], @pe_id, name) end |
#short_state_str ⇒ Object
Returns the state of the datastore (string value)
195 196 197 |
# File 'lib/opennebula/datastore.rb', line 195 def short_state_str SHORT_DATASTORE_STATES[state_str] end |
#short_type_str ⇒ Object
Returns the datastore type (string value)
180 181 182 |
# File 'lib/opennebula/datastore.rb', line 180 def short_type_str SHORT_DATASTORE_TYPES[type_str] end |
#state ⇒ Object
Returns the state of the datastore (numeric value)
185 186 187 |
# File 'lib/opennebula/datastore.rb', line 185 def state self['STATE'].to_i end |
#state_str ⇒ Object
Returns the state of the datastore (string value)
190 191 192 |
# File 'lib/opennebula/datastore.rb', line 190 def state_str DATASTORE_STATES[state] end |
#type ⇒ Object
Returns the datastore type
170 171 172 |
# File 'lib/opennebula/datastore.rb', line 170 def type self['TYPE'].to_i end |
#type_str ⇒ Object
Returns the datastore type (string value)
175 176 177 |
# File 'lib/opennebula/datastore.rb', line 175 def type_str DATASTORE_TYPES[type] end |
#update(new_template, append = false) ⇒ nil, OpenNebula::Error
Replaces the template contents
110 111 112 |
# File 'lib/opennebula/datastore.rb', line 110 def update(new_template, append=false) super(DATASTORE_METHODS[:update], new_template, append ? 1 : 0) end |