class OpenNebula::MarketPlaceApp

Constants

MARKETPLACEAPP_METHODS

Constants and Class Methods

MARKETPLACEAPP_STATES
MARKETPLACEAPP_TYPES
SHORT_MARKETPLACEAPP_STATES
SHORT_MARKETPLACEAPP_TYPES

Public Class Methods

build_xml(pe_id = nil) click to toggle source

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)
# 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
new(xml, client) click to toggle source

Class constructor

Calls superclass method
# File lib/opennebula/marketplaceapp.rb, line 77
def initialize(xml, client)
    super(xml, client)
end

Public Instance Methods

allocate(description, mp_id) click to toggle source

Allocates a new MarketPlace in OpenNebula

@param description [String] The template of the marketplace app @param mp_id [Integer] The id of the marketplace to create the app

@return [Integer, OpenNebula::Error] the new ID in case of

success, error otherwise
Calls superclass method
# 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) click to toggle source

Changes the marketplace app permissions. Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
Calls superclass method
# 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) click to toggle source

Changes the marketplace app permissions.

@param octet [String] Permissions octed , e.g. 640 @return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
Calls superclass method
# File lib/opennebula/marketplaceapp.rb, line 136
def chmod_octet(octet)
    super(MARKETPLACEAPP_METHODS[:chmod], octet)
end
chown(uid, gid) click to toggle source

Changes the owner/group

@param uid [Integer] the new owner id. Set to -1 to leave the current one @param gid [Integer] the new group id. Set to -1 to leave the current one

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
Calls superclass method
# File lib/opennebula/marketplaceapp.rb, line 127
def chown(uid, gid)
    super(MARKETPLACEAPP_METHODS[:chown], uid, gid)
end
delete() click to toggle source

Deletes the marketplace app

Calls superclass method
# File lib/opennebula/marketplaceapp.rb, line 104
def delete
    super(MARKETPLACEAPP_METHODS[:delete])
end
disable() click to toggle source

Enables this app

# File lib/opennebula/marketplaceapp.rb, line 246
def disable
    call(MARKETPLACEAPP_METHODS[:enable], @pe_id, false)
end
enable() click to toggle source

Enables this app

# File lib/opennebula/marketplaceapp.rb, line 241
def enable
    call(MARKETPLACEAPP_METHODS[:enable], @pe_id, true)
end
export(options = {}) click to toggle source

Exports this app to a suitable OpenNebula object @param appid [Integer] id of the marketplace app @param options [Hash] 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

@return [Hash, OpenNebula::Error] with the ID and type of the created 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 ] }
# 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 != '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
info() click to toggle source

Retrieves the information of the given marketplace app

Calls superclass method
# File lib/opennebula/marketplaceapp.rb, line 86
def info
    super(MARKETPLACEAPP_METHODS[:info], 'MARKETPLACEAPP')
end
Also aliased as: info!
info!()
Alias for: info
lock(level) click to toggle source

Locked a MarketplaceApp

# File lib/opennebula/marketplaceapp.rb, line 285
def lock(level)
    call(MARKETPLACEAPP_METHODS[:lock], @pe_id, level)
end
rename(name) click to toggle source

Renames this marketplace app

@param name [String] New name for the marketplace app

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/marketplaceapp.rb, line 157
def rename(name)
    call(MARKETPLACEAPP_METHODS[:rename], @pe_id, name)
end
short_state_str() click to toggle source

Returns the state of the marketplace app (string value)

# File lib/opennebula/marketplaceapp.rb, line 280
def short_state_str
    SHORT_MARKETPLACEAPP_STATES[state_str]
end
short_type_str() click to toggle source

Returns the marketplace app type (string value)

# File lib/opennebula/marketplaceapp.rb, line 265
def short_type_str
    SHORT_MARKETPLACEAPP_TYPES[type_str]
end
state() click to toggle source

Returns the state of the marketplace app (numeric value)

# File lib/opennebula/marketplaceapp.rb, line 270
def state
    self['STATE'].to_i
end
state_str() click to toggle source

Returns the state of the marketplace app (string value)

# File lib/opennebula/marketplaceapp.rb, line 275
def state_str
    MARKETPLACEAPP_STATES[state]
end
type() click to toggle source

Returns the marketplace app type

# File lib/opennebula/marketplaceapp.rb, line 255
def type
    self['TYPE'].to_i
end
type_str() click to toggle source

Returns the marketplace app type (string value)

# File lib/opennebula/marketplaceapp.rb, line 260
def type_str
    MARKETPLACEAPP_TYPES[type]
end
unlock() click to toggle source

Unlocked a MarketplaceApp

# File lib/opennebula/marketplaceapp.rb, line 290
def unlock()
    call(MARKETPLACEAPP_METHODS[:unlock], @pe_id)
end
update(new_template, append = false) click to toggle source

Replaces the template contents

@param new_template [String] New template contents @param append [true, false] True to append new attributes instead of

replace the whole template

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
Calls superclass method
# File lib/opennebula/marketplaceapp.rb, line 116
def update(new_template, append = false)
    super(MARKETPLACEAPP_METHODS[:update], new_template, append ? 1 : 0)
end

Private Instance Methods

create_vmtemplate(options, image_id = nil) click to toggle source

Creates a VM template based on the VMTEMPLATE64 attribute @return [Integer, OpenNebula::Error] template id or error TODO this method needs to be extended to support [image_ids]

# File lib/opennebula/marketplaceapp.rb, line 299
def create_vmtemplate(options, image_id = nil)
    return -1 if self['TEMPLATE/VMTEMPLATE64'].nil?

    tmpl = Base64.decode64(self['TEMPLATE/VMTEMPLATE64'])

    tmpl << "\nNAME=\"#{options[:vmtemplate_name]}\"\n"
    tmpl << "DISK=[ IMAGE_ID = #{image_id} ]\n" if image_id

    vmtpl = Template.new(Template.build_xml, @client)
    rc    = vmtpl.allocate(tmpl)

    return rc if OpenNebula.is_error?(rc)

    vmtpl.id
end