Class: OpenNebula::Image

Inherits:
PoolElement show all
Defined in:
OpenNebula/Image.rb

Constant Summary

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",
    :clone       => "image.clone"
}
IMAGE_STATES =
%w{INIT READY USED DISABLED LOCKED ERROR CLONE DELETE USED_PERS}
SHORT_IMAGE_STATES =
{
    "INIT"      => "init",
    "READY"     => "rdy",
    "USED"      => "used",
    "DISABLED"  => "disa",
    "LOCKED"    => "lock",
    "ERROR"     => "err",
    "CLONE"     => "clon",
    "DELETE"    => "dele",
    "USED_PERS" => "used"
}
IMAGE_TYPES =
%w{OS CDROM DATABLOCK}
SHORT_IMAGE_TYPES =
{
    "OS"         => "OS",
    "CDROM"      => "CD",
    "DATABLOCK"  => "DB"
}

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

- (Image) initialize(xml, client)

Class constructor



81
82
83
84
85
# File 'OpenNebula/Image.rb', line 81

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

    @client = client
end

Class Method Details

+ (Object) build_xml(pe_id = nil)

Creates an Image description with just its identifier this method should be used to create plain Image objects. id the id of the image

Example:

image = Image.new(Image.build_xml(3),rpc_client)


70
71
72
73
74
75
76
77
78
# File 'OpenNebula/Image.rb', line 70

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

- (nil, OpenNebula::Error) allocate(description, ds_id)

Allocates a new Image in OpenNebula

Parameters:

  • description (String)

    A string containing the template of the Image.

  • ds_id (Integer)

    the target datastore ID

Returns:



103
104
105
# File 'OpenNebula/Image.rb', line 103

def allocate(description, ds_id)
    super(IMAGE_METHODS[:allocate],description, ds_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 Image permissions. Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change

Returns:



172
173
174
175
176
# File 'OpenNebula/Image.rb', line 172

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

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

Changes the Image permissions.

Parameters:

  • octet (String)

    Permissions octed , e.g. 640

Returns:



163
164
165
# File 'OpenNebula/Image.rb', line 163

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

- (Object) chown(uid, gid)

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



154
155
156
# File 'OpenNebula/Image.rb', line 154

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

- (nil, OpenNebula::Error) chtype(type)

Changes the Image type

Parameters:

  • type (String)

    new Image type

Returns:



182
183
184
185
186
187
188
189
# File 'OpenNebula/Image.rb', line 182

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

- (Integer, OpenNebula::Error) clone(name)

Clones this Image into a new one

Parameters:

  • name (String)

    for the new Image.

Returns:

  • (Integer, OpenNebula::Error)

    The new Image ID in case of success, Error otherwise



197
198
199
200
201
202
203
# File 'OpenNebula/Image.rb', line 197

def clone(name)
    return Error.new('ID not defined') if !@pe_id

    rc = @client.call(IMAGE_METHODS[:clone], @pe_id, name)

    return rc
end

- (Object) delete

Deletes the Image



146
147
148
# File 'OpenNebula/Image.rb', line 146

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

- (Object) disable

Disables an Image



121
122
123
# File 'OpenNebula/Image.rb', line 121

def disable
    set_enabled(false)
end

- (Object) enable

Enables an Image



116
117
118
# File 'OpenNebula/Image.rb', line 116

def enable
    set_enabled(true)
end

- (Object) gid

Returns the group identifier

return

Integer the element's group ID



241
242
243
# File 'OpenNebula/Image.rb', line 241

def gid
    self['GID'].to_i
end

- (Object) info

Retrieves the information of the given Image.



92
93
94
# File 'OpenNebula/Image.rb', line 92

def info()
    super(IMAGE_METHODS[:info], 'IMAGE')
end

- (Object) nonpersistent

Makes the Image non persistent



141
142
143
# File 'OpenNebula/Image.rb', line 141

def nonpersistent
    set_persistent(false)
end

- (Object) persistent

Makes the Image persistent



136
137
138
# File 'OpenNebula/Image.rb', line 136

def persistent
    set_persistent(true)
end

- (Boolean) public?

Returns:

  • (Boolean)


245
246
247
248
249
250
251
# File 'OpenNebula/Image.rb', line 245

def public?
    if self['PERMISSIONS/GROUP_U'] == "1" || self['PERMISSIONS/OTHER_U'] == "1"
        true
    else
        false
    end
end

- (Object) publish

Publishes the Image, to be used by other users



126
127
128
# File 'OpenNebula/Image.rb', line 126

def publish
    set_publish(true)
end

- (Object) short_state_str

Returns the state of the Image (string value)



220
221
222
# File 'OpenNebula/Image.rb', line 220

def short_state_str
    SHORT_IMAGE_STATES[state_str]
end

- (Object) short_type_str

Returns the state of the Image (string value)



235
236
237
# File 'OpenNebula/Image.rb', line 235

def short_type_str
    SHORT_IMAGE_TYPES[type_str]
end

- (Object) state

Returns the state of the Image (numeric value)



210
211
212
# File 'OpenNebula/Image.rb', line 210

def state
    self['STATE'].to_i
end

- (Object) state_str

Returns the state of the Image (string value)



215
216
217
# File 'OpenNebula/Image.rb', line 215

def state_str
    IMAGE_STATES[state]
end

- (Object) type

Returns the type of the Image (numeric value)



225
226
227
# File 'OpenNebula/Image.rb', line 225

def type
    self['TYPE'].to_i
end

- (Object) type_str

Returns the type of the Image (string value)



230
231
232
# File 'OpenNebula/Image.rb', line 230

def type_str
    IMAGE_TYPES[type]
end

- (Object) unpublish

Unplubishes the Image



131
132
133
# File 'OpenNebula/Image.rb', line 131

def unpublish
    set_publish(false)
end

- (Object) update(new_template = nil)

Replaces the template contents

new_template New template contents. If no argument is provided

the object will be updated using the @xml variable


111
112
113
# File 'OpenNebula/Image.rb', line 111

def update(new_template=nil)
    super(IMAGE_METHODS[:update], new_template)
end