Class: OpenNebula::MarketPlaceApp

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

Constant Summary collapse

MARKETPLACEAPP_METHODS =

Constants and Class Methods

{
    :info       => 'marketapp.info',
    :allocate   => 'marketapp.allocate',
    :delete     => 'marketapp.delete',
    :update     => 'marketapp.update',
    :chown      => 'marketapp.chown',
    :chmod      => 'marketapp.chmod',
    :rename     => 'marketapp.rename',
    :enable     => 'marketapp.enable',
    :lock       => 'marketapp.lock',
    :unlock     => 'marketapp.unlock'
}
MARKETPLACEAPP_STATES =
%w{INIT READY LOCKED ERROR DISABLED}
SHORT_MARKETPLACEAPP_STATES =
{
    'INIT'      => 'ini',
    'READY'     => 'rdy',
    'LOCKED'    => 'lck',
    'ERROR'     => 'err',
    'DISABLED'  => 'dis'
}
MARKETPLACEAPP_TYPES =
%w{UNKNOWN IMAGE VMTEMPLATE SERVICE_TEMPLATE}
SHORT_MARKETPLACEAPP_TYPES =
{
    'UNKNOWN'          => 'unk',
    'IMAGE'            => 'img',
    'VMTEMPLATE'       => 'tpl',
    'SERVICE_TEMPLATE' => 'srv'
}

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PoolElement

#id, #name, 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) ⇒ MarketPlaceApp

Class constructor



77
78
79
# File 'lib/opennebula/marketplaceapp.rb', line 77

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

Class Method Details

.build_xml(pe_id = nil) ⇒ Object

Creates a MarketPlace description with just its identifier this method should be used to create plain MarketPlace objects. id the id of the user

Example:

app = MarketPlaceApp.new(MarketPlace.build_xml(3),rpc_client)


66
67
68
69
70
71
72
73
74
# File 'lib/opennebula/marketplaceapp.rb', line 66

def MarketPlaceApp.build_xml(pe_id = nil)
    if pe_id
        app_xml = "<MARKETPLACEAPP><ID>#{pe_id}</ID></MARKETPLACEAPP>"
    else
        app_xml = '<MARKETPLACEAPP></MARKETPLACEAPP>'
    end

    XMLElement.build_xml(app_xml, 'MARKETPLACEAPP')
end

Instance Method Details

#allocate(description, mp_id) ⇒ Integer, OpenNebula::Error

Allocates a new MarketPlace in OpenNebula

Parameters:

  • description (String)

    The template of the marketplace app

  • mp_id (Integer)

    The id of the marketplace to create the app

Returns:



99
100
101
# File 'lib/opennebula/marketplaceapp.rb', line 99

def allocate(description, mp_id)
    super(MARKETPLACEAPP_METHODS[:allocate], description, mp_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 marketplace app permissions. Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change

Returns:



145
146
147
148
149
# File 'lib/opennebula/marketplaceapp.rb', line 145

def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
        other_m, other_a)
    super(MARKETPLACEAPP_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 marketplace app permissions.

Parameters:

  • octet (String)

    Permissions octed , e.g. 640

Returns:



136
137
138
# File 'lib/opennebula/marketplaceapp.rb', line 136

def chmod_octet(octet)
    super(MARKETPLACEAPP_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:



127
128
129
# File 'lib/opennebula/marketplaceapp.rb', line 127

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

#deleteObject

Deletes the marketplace app



104
105
106
# File 'lib/opennebula/marketplaceapp.rb', line 104

def delete
    super(MARKETPLACEAPP_METHODS[:delete])
end

#disableObject

Enables this app



252
253
254
# File 'lib/opennebula/marketplaceapp.rb', line 252

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

#enableObject

Enables this app



247
248
249
# File 'lib/opennebula/marketplaceapp.rb', line 247

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

#export(options = {}) ⇒ Hash, OpenNebula::Error

Exports this app to a suitable OpenNebula object objects. Instead of an ID, the array may contain OpenNebula::Error with specific object creation errors

{ :vm => [ vm ids/OpenNebula::Error ],
  :vmtemplate => [ vmtemplates ids/OpenNebula::Error ],
  :image => [ vm ids/OpenNebula::Error ] }

Parameters:

  • appid (Integer)

    id of the marketplace app

  • options (Hash) (defaults to: {})

    to control the export behavior dsid [Integer] datastore to save images name [String] of the new object vmtemplate_name [String] name for the VM Template, if the App has one

Returns:



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/opennebula/marketplaceapp.rb', line 174

def export(options = {})
    rc = info
    return rc if OpenNebula.is_error?(rc)
    return Error.new('App is not READY') if state_str != 'READY'

    if options[:dsid].nil? && type_str != 'VMTEMPLATE'
        return Error.new('Missing datastore id')
    end

    return Error.new('Missing name to export app') if options[:name].nil?

    if !self['APPTEMPLATE64'].nil?
        tmpl = Base64.decode64(self['APPTEMPLATE64'])
    else
        tmpl = ''
    end

    name = options[:name] || "marketapp-#{id}"
    options[:vmtemplate_name] = name unless options[:vmtemplate_name]

    tmpl << "\n"
    tmpl << "NAME=\"" << name << "\"\n"
    tmpl << "FROM_APP=\"" << self['ID'] << "\"\n"

    case type_str
    when 'IMAGE'
        image = Image.new(Image.build_xml, @client)
        rc    = image.allocate(tmpl, options[:dsid])

        ds = OpenNebula::Datastore.new_with_id(options[:dsid], @client)

        rc_image = image.info
        rc_ds    = ds.info

        image_error = OpenNebula.is_error?(rc_image)
        ds_error    = OpenNebula.is_error?(rc_ds)

        xpath  = 'TEMPLATE/DRIVER'
        format = self['FORMAT']
        type   = ds[xpath]

        if !image_error && !ds_error
            if type == 'vcenter' && format == 'qcow2'
                image.replace('DEV_PREFIX' => 'sd')
                image.delete_element('TEMPLATE/FORMAT')
                image.delete_element('TEMPLATE/DRIVER')

                image.update(image.template_like_str("TEMPLATE"))
            elsif type == 'vcenter' && format != 'iso' && format != 'vmdk'
                image.replace('FORMAT' => 'vmdk')
            elsif type && type != 'vcenter' && format == 'vmdk'
                image.replace('FORMAT' => type)
            end
        end

        return { :image => [rc] } if OpenNebula.is_error?(rc)

        vmtpl_id = create_vmtemplate(options, image.id)

        return { :image => [image.id], :vmtemplate => [vmtpl_id] }

    when 'VMTEMPLATE'
        # TODO import all the images associated to a VMTEMPLATE app
        # current version only support no-image based apps (e.g. hybrid)
        vmtpl_id = create_vmtemplate(options)

        return { :image => [], :vmtemplate => [vmtpl_id] }
    else
        return Error.new("App type #{type_str} not supported")
    end
end

#infoObject Also known as: info!

Retrieves the information of the given marketplace app



86
87
88
# File 'lib/opennebula/marketplaceapp.rb', line 86

def info
    super(MARKETPLACEAPP_METHODS[:info], 'MARKETPLACEAPP')
end

#lock(level) ⇒ Object

Locked a MarketplaceApp



291
292
293
# File 'lib/opennebula/marketplaceapp.rb', line 291

def lock(level)
    call(MARKETPLACEAPP_METHODS[:lock], @pe_id, level)
end

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

Renames this marketplace app

Parameters:

  • name (String)

    New name for the marketplace app

Returns:



157
158
159
# File 'lib/opennebula/marketplaceapp.rb', line 157

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

#short_state_strObject

Returns the state of the marketplace app (string value)



286
287
288
# File 'lib/opennebula/marketplaceapp.rb', line 286

def short_state_str
    SHORT_MARKETPLACEAPP_STATES[state_str]
end

#short_type_strObject

Returns the marketplace app type (string value)



271
272
273
# File 'lib/opennebula/marketplaceapp.rb', line 271

def short_type_str
    SHORT_MARKETPLACEAPP_TYPES[type_str]
end

#stateObject

Returns the state of the marketplace app (numeric value)



276
277
278
# File 'lib/opennebula/marketplaceapp.rb', line 276

def state
    self['STATE'].to_i
end

#state_strObject

Returns the state of the marketplace app (string value)



281
282
283
# File 'lib/opennebula/marketplaceapp.rb', line 281

def state_str
    MARKETPLACEAPP_STATES[state]
end

#typeObject

Returns the marketplace app type



261
262
263
# File 'lib/opennebula/marketplaceapp.rb', line 261

def type
    self['TYPE'].to_i
end

#type_strObject

Returns the marketplace app type (string value)



266
267
268
# File 'lib/opennebula/marketplaceapp.rb', line 266

def type_str
    MARKETPLACEAPP_TYPES[type]
end

#unlockObject

Unlocked a MarketplaceApp



296
297
298
# File 'lib/opennebula/marketplaceapp.rb', line 296

def unlock()
    call(MARKETPLACEAPP_METHODS[:unlock], @pe_id)
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:



116
117
118
# File 'lib/opennebula/marketplaceapp.rb', line 116

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