class OpenNebula::MarketPlaceApp
Constants
- MARKETPLACEAPP_METHODS
Constants and Class Methods
- MARKETPLACEAPP_STATES
- MARKETPLACEAPP_TYPES
- SHORT_MARKETPLACEAPP_STATES
- SHORT_MARKETPLACEAPP_TYPES
Public Class Methods
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
Class constructor
# File lib/opennebula/marketplaceapp.rb, line 77 def initialize(xml, client) super(xml, client) end
Public Instance Methods
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
# File lib/opennebula/marketplaceapp.rb, line 99 def allocate(description, mp_id) super(MARKETPLACEAPP_METHODS[:allocate], description, mp_id) end
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
# 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
Changes the marketplace app permissions.
@param octet [String] Permissions octed , e.g. 640 @return [nil, OpenNebula::Error
] nil in case of success, Error
otherwise
# File lib/opennebula/marketplaceapp.rb, line 136 def chmod_octet(octet) super(MARKETPLACEAPP_METHODS[:chmod], octet) end
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
# File lib/opennebula/marketplaceapp.rb, line 127 def chown(uid, gid) super(MARKETPLACEAPP_METHODS[:chown], uid, gid) end
Deletes the marketplace app
# File lib/opennebula/marketplaceapp.rb, line 104 def delete super(MARKETPLACEAPP_METHODS[:delete]) end
Enables this app
# File lib/opennebula/marketplaceapp.rb, line 253 def disable call(MARKETPLACEAPP_METHODS[:enable], @pe_id, false) end
Enables this app
# File lib/opennebula/marketplaceapp.rb, line 248 def enable call(MARKETPLACEAPP_METHODS[:enable], @pe_id, true) end
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" tmpl << 'URL_ARGS="' << options[:url_args] << "\"\n" if options[:url_args] 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
Retrieves the information of the given marketplace app
# File lib/opennebula/marketplaceapp.rb, line 86 def info super(MARKETPLACEAPP_METHODS[:info], 'MARKETPLACEAPP') end
Locked a MarketplaceApp
# File lib/opennebula/marketplaceapp.rb, line 292 def lock(level) call(MARKETPLACEAPP_METHODS[:lock], @pe_id, level) end
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
Returns the state of the marketplace app (string value)
# File lib/opennebula/marketplaceapp.rb, line 287 def short_state_str SHORT_MARKETPLACEAPP_STATES[state_str] end
Returns the marketplace app type (string value)
# File lib/opennebula/marketplaceapp.rb, line 272 def short_type_str SHORT_MARKETPLACEAPP_TYPES[type_str] end
Returns the state of the marketplace app (numeric value)
# File lib/opennebula/marketplaceapp.rb, line 277 def state self['STATE'].to_i end
Returns the state of the marketplace app (string value)
# File lib/opennebula/marketplaceapp.rb, line 282 def state_str MARKETPLACEAPP_STATES[state] end
Returns the marketplace app type
# File lib/opennebula/marketplaceapp.rb, line 262 def type self['TYPE'].to_i end
Returns the marketplace app type (string value)
# File lib/opennebula/marketplaceapp.rb, line 267 def type_str MARKETPLACEAPP_TYPES[type] end
Unlocked a MarketplaceApp
# File lib/opennebula/marketplaceapp.rb, line 297 def unlock() call(MARKETPLACEAPP_METHODS[:unlock], @pe_id) end
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
# 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
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 306 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