Class: OpenNebula::Image
- Inherits:
-
PoolElement
- Object
- XMLElement
- PoolElement
- OpenNebula::Image
- Defined in:
- lib/OpenNebula/Image.rb
Constant Summary collapse
- IMAGE_METHODS =
{ :info => "image.info", :allocate => "image.allocate", :update => "image.update", :enable => "image.enable", :persistent => "image.persistent", :delete => "image.delete", :chown => "image.chown", :chmod => "image.chmod", :chtype => "image.chtype" }
- IMAGE_STATES =
%w{INIT READY USED DISABLED LOCKED ERROR}
- SHORT_IMAGE_STATES =
{ "INIT" => "init", "READY" => "rdy", "USED" => "used", "DISABLED" => "disa", "LOCKED" => "lock", "ERROR" => "err" }
- IMAGE_TYPES =
%w{OS CDROM DATABLOCK}
- SHORT_IMAGE_TYPES =
{ "OS" => "OS", "CDROM" => "CD", "DATABLOCK" => "DB" }
Class Method Summary collapse
-
.build_xml(pe_id = nil) ⇒ Object
Creates an Image description with just its identifier this method should be used to create plain Image objects.
Instance Method Summary collapse
-
#allocate(description, ds_id) ⇒ nil, OpenNebula::Error
Allocates a new Image 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 Image permissions.
-
#chmod_octet(octet) ⇒ nil, OpenNebula::Error
Changes the Image permissions.
-
#chown(uid, gid) ⇒ Object
- Changes the owner/group uid
-
Integer the new owner id.
-
#chtype(type) ⇒ nil, OpenNebula::Error
Changes the Image type.
-
#delete ⇒ Object
Deletes the Image.
-
#disable ⇒ Object
Disables an Image.
-
#enable ⇒ Object
Enables an Image.
-
#gid ⇒ Object
Returns the group identifier [return] Integer the element’s group ID.
-
#info ⇒ Object
Retrieves the information of the given Image.
-
#initialize(xml, client) ⇒ Image
constructor
Class constructor.
-
#nonpersistent ⇒ Object
Makes the Image non persistent.
-
#persistent ⇒ Object
Makes the Image persistent.
- #public? ⇒ Boolean
-
#publish ⇒ Object
Publishes the Image, to be used by other users.
-
#short_state_str ⇒ Object
Returns the state of the Image (string value).
-
#short_type_str ⇒ Object
Returns the state of the Image (string value).
-
#state ⇒ Object
Returns the state of the Image (numeric value).
-
#state_str ⇒ Object
Returns the state of the Image (string value).
-
#type ⇒ Object
Returns the type of the Image (numeric value).
-
#type_str ⇒ Object
Returns the type of the Image (string value).
-
#unpublish ⇒ Object
Unplubishes the Image.
-
#update(new_template) ⇒ Object
Replaces the template contents.
Methods inherited from PoolElement
#id, #name, new_with_id, #to_str
Methods inherited from XMLElement
#[], #add_element, #attr, #delete_element, #each, #each_xpath, #has_elements?, #initialize_xml, #name, #retrieve_elements, #template_like_str, #template_str, #template_xml, #text, #to_hash, #to_xml
Constructor Details
#initialize(xml, client) ⇒ Image
Class constructor
77 78 79 80 81 |
# File 'lib/OpenNebula/Image.rb', line 77 def initialize(xml, client) super(xml,client) @client = client end |
Class Method Details
.build_xml(pe_id = nil) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/OpenNebula/Image.rb', line 66 def Image.build_xml(pe_id=nil) if pe_id image_xml = "<IMAGE><ID>#{pe_id}</ID></IMAGE>" else image_xml = "<IMAGE></IMAGE>" end XMLElement.build_xml(image_xml,'IMAGE') end |
Instance Method Details
#allocate(description, ds_id) ⇒ nil, OpenNebula::Error
Allocates a new Image in OpenNebula
99 100 101 |
# File 'lib/OpenNebula/Image.rb', line 99 def allocate(description, ds_id) super(IMAGE_METHODS[:allocate],description, ds_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 Image permissions. Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change
167 168 169 170 171 |
# File 'lib/OpenNebula/Image.rb', line 167 def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, other_m, other_a) super(IMAGE_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 Image permissions.
158 159 160 |
# File 'lib/OpenNebula/Image.rb', line 158 def chmod_octet(octet) super(IMAGE_METHODS[:chmod], octet) end |
#chown(uid, gid) ⇒ Object
Changes the owner/group
- 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
- return
-
nil in case of success or an Error object
149 150 151 |
# File 'lib/OpenNebula/Image.rb', line 149 def chown(uid, gid) super(IMAGE_METHODS[:chown], uid, gid) end |
#chtype(type) ⇒ nil, OpenNebula::Error
Changes the Image type
177 178 179 180 181 182 183 184 |
# File 'lib/OpenNebula/Image.rb', line 177 def chtype(type) return Error.new('ID not defined') if !@pe_id rc = @client.call(IMAGE_METHODS[:chtype], @pe_id, type) rc = nil if !OpenNebula.is_error?(rc) return rc end |
#delete ⇒ Object
Deletes the Image
141 142 143 |
# File 'lib/OpenNebula/Image.rb', line 141 def delete() super(IMAGE_METHODS[:delete]) end |
#disable ⇒ Object
Disables an Image
116 117 118 |
# File 'lib/OpenNebula/Image.rb', line 116 def disable set_enabled(false) end |
#enable ⇒ Object
Enables an Image
111 112 113 |
# File 'lib/OpenNebula/Image.rb', line 111 def enable set_enabled(true) end |
#gid ⇒ Object
Returns the group identifier
- return
-
Integer the element’s group ID
222 223 224 |
# File 'lib/OpenNebula/Image.rb', line 222 def gid self['GID'].to_i end |
#info ⇒ Object
Retrieves the information of the given Image.
88 89 90 |
# File 'lib/OpenNebula/Image.rb', line 88 def info() super(IMAGE_METHODS[:info], 'IMAGE') end |
#nonpersistent ⇒ Object
Makes the Image non persistent
136 137 138 |
# File 'lib/OpenNebula/Image.rb', line 136 def nonpersistent set_persistent(false) end |
#persistent ⇒ Object
Makes the Image persistent
131 132 133 |
# File 'lib/OpenNebula/Image.rb', line 131 def persistent set_persistent(true) end |
#public? ⇒ Boolean
226 227 228 229 230 231 232 |
# File 'lib/OpenNebula/Image.rb', line 226 def public? if self['PERMISSIONS/GROUP_U'] == "1" || self['PERMISSIONS/OTHER_U'] == "1" true else false end end |
#publish ⇒ Object
Publishes the Image, to be used by other users
121 122 123 |
# File 'lib/OpenNebula/Image.rb', line 121 def publish set_publish(true) end |
#short_state_str ⇒ Object
Returns the state of the Image (string value)
201 202 203 |
# File 'lib/OpenNebula/Image.rb', line 201 def short_state_str SHORT_IMAGE_STATES[state_str] end |
#short_type_str ⇒ Object
Returns the state of the Image (string value)
216 217 218 |
# File 'lib/OpenNebula/Image.rb', line 216 def short_type_str SHORT_IMAGE_TYPES[type_str] end |
#state ⇒ Object
Returns the state of the Image (numeric value)
191 192 193 |
# File 'lib/OpenNebula/Image.rb', line 191 def state self['STATE'].to_i end |
#state_str ⇒ Object
Returns the state of the Image (string value)
196 197 198 |
# File 'lib/OpenNebula/Image.rb', line 196 def state_str IMAGE_STATES[state] end |
#type ⇒ Object
Returns the type of the Image (numeric value)
206 207 208 |
# File 'lib/OpenNebula/Image.rb', line 206 def type self['TYPE'].to_i end |
#type_str ⇒ Object
Returns the type of the Image (string value)
211 212 213 |
# File 'lib/OpenNebula/Image.rb', line 211 def type_str IMAGE_TYPES[type] end |
#unpublish ⇒ Object
Unplubishes the Image
126 127 128 |
# File 'lib/OpenNebula/Image.rb', line 126 def unpublish set_publish(false) end |
#update(new_template) ⇒ Object
Replaces the template contents
new_template
New template contents
106 107 108 |
# File 'lib/OpenNebula/Image.rb', line 106 def update(new_template) super(IMAGE_METHODS[:update], new_template) end |