Class: OpenNebula::Image

Inherits:
PoolElement show all
Defined in:
lib/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"
}
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)

Instance Method Summary (collapse)

Methods inherited from PoolElement

#id, #name, new_with_id, #to_str

Methods inherited from XMLElement

#[], #attr, #each, #each_xpath, #has_elements?, #initialize_xml, #name, #retrieve_elements, #template_like_str, #template_str, #text, #to_hash, #to_xml

Constructor Details

- (Image) initialize(xml, client)

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

+ (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)



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

- (Object) allocate(description)

Allocates a new Image in OpenNebula

+description+ A string containing the template of the Image.



95
96
97
# File 'lib/OpenNebula/Image.rb', line 95

def allocate(description)
    super(IMAGE_METHODS[:allocate],description)
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



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

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.



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

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



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

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

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

Changes the Image type



173
174
175
176
177
178
179
180
# File 'lib/OpenNebula/Image.rb', line 173

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

- (Object) delete

Deletes the Image



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

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

- (Object) disable

Disables an Image



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

def disable
    set_enabled(false)
end

- (Object) enable

Enables an Image



107
108
109
# File 'lib/OpenNebula/Image.rb', line 107

def enable
    set_enabled(true)
end

- (Object) gid

Returns the group identifier [return] Integer the element's group ID



218
219
220
# File 'lib/OpenNebula/Image.rb', line 218

def gid
    self['GID'].to_i
end

- (Object) info

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

- (Object) nonpersistent

Makes the Image non persistent



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

def nonpersistent
    set_persistent(false)
end

- (Object) persistent

Makes the Image persistent



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

def persistent
    set_persistent(true)
end

- (Boolean) public?



222
223
224
225
226
227
228
# File 'lib/OpenNebula/Image.rb', line 222

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



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

def publish
    set_publish(true)
end

- (Object) short_state_str

Returns the state of the Image (string value)



197
198
199
# File 'lib/OpenNebula/Image.rb', line 197

def short_state_str
    SHORT_IMAGE_STATES[state_str]
end

- (Object) short_type_str

Returns the state of the Image (string value)



212
213
214
# File 'lib/OpenNebula/Image.rb', line 212

def short_type_str
    SHORT_IMAGE_TYPES[type_str]
end

- (Object) state

Returns the state of the Image (numeric value)



187
188
189
# File 'lib/OpenNebula/Image.rb', line 187

def state
    self['STATE'].to_i
end

- (Object) state_str

Returns the state of the Image (string value)



192
193
194
# File 'lib/OpenNebula/Image.rb', line 192

def state_str
    IMAGE_STATES[state]
end

- (Object) type

Returns the type of the Image (numeric value)



202
203
204
# File 'lib/OpenNebula/Image.rb', line 202

def type
    self['TYPE'].to_i
end

- (Object) type_str

Returns the type of the Image (string value)



207
208
209
# File 'lib/OpenNebula/Image.rb', line 207

def type_str
    IMAGE_TYPES[type]
end

- (Object) unpublish

Unplubishes the Image



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

def unpublish
    set_publish(false)
end

- (Object) update(new_template)

Replaces the template contents

+new_template+ New template contents



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

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