Class: OpenNebula::MarketPlaceApp
- Inherits:
-
PoolElement
- Object
- XMLElement
- PoolElement
- OpenNebula::MarketPlaceApp
- 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
-
.build_xml(pe_id = nil) ⇒ Object
Creates a MarketPlace description with just its identifier this method should be used to create plain MarketPlace objects.
Instance Method Summary collapse
-
#allocate(description, mp_id) ⇒ Integer, OpenNebula::Error
Allocates a new MarketPlace in OpenNebula.
-
#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.
-
#chmod_octet(octet) ⇒ nil, OpenNebula::Error
Changes the marketplace app permissions.
-
#chown(uid, gid) ⇒ nil, OpenNebula::Error
Changes the owner/group.
-
#delete ⇒ Object
Deletes the marketplace app.
-
#disable ⇒ Object
Enables this app.
-
#enable ⇒ Object
Enables this app.
-
#export(options = {}) ⇒ Hash, OpenNebula::Error
Exports this app to a suitable OpenNebula object objects.
-
#info ⇒ Object
(also: #info!)
Retrieves the information of the given marketplace app.
-
#initialize(xml, client) ⇒ MarketPlaceApp
constructor
Class constructor.
-
#lock(level) ⇒ Object
Locked a MarketplaceApp.
-
#rename(name) ⇒ nil, OpenNebula::Error
Renames this marketplace app.
-
#short_state_str ⇒ Object
Returns the state of the marketplace app (string value).
-
#short_type_str ⇒ Object
Returns the marketplace app type (string value).
-
#state ⇒ Object
Returns the state of the marketplace app (numeric value).
-
#state_str ⇒ Object
Returns the state of the marketplace app (string value).
-
#type ⇒ Object
Returns the marketplace app type.
-
#type_str ⇒ Object
Returns the marketplace app type (string value).
-
#unlock ⇒ Object
Unlocked a MarketplaceApp.
-
#update(new_template, append = false) ⇒ nil, OpenNebula::Error
Replaces the template contents.
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
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
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.
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
127 128 129 |
# File 'lib/opennebula/marketplaceapp.rb', line 127 def chown(uid, gid) super(MARKETPLACEAPP_METHODS[:chown], uid, gid) end |
#delete ⇒ Object
Deletes the marketplace app
104 105 106 |
# File 'lib/opennebula/marketplaceapp.rb', line 104 def delete super(MARKETPLACEAPP_METHODS[:delete]) end |
#disable ⇒ Object
Enables this app
253 254 255 |
# File 'lib/opennebula/marketplaceapp.rb', line 253 def disable call(MARKETPLACEAPP_METHODS[:enable], @pe_id, false) end |
#enable ⇒ Object
Enables this app
248 249 250 |
# File 'lib/opennebula/marketplaceapp.rb', line 248 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 ] }
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 245 |
# File 'lib/opennebula/marketplaceapp.rb', line 174 def export( = {}) rc = info return rc if OpenNebula.is_error?(rc) return Error.new('App is not READY') if state_str != 'READY' if [:dsid].nil? && type_str != 'VMTEMPLATE' return Error.new('Missing datastore id') end return Error.new('Missing name to export app') if [:name].nil? if !self['APPTEMPLATE64'].nil? tmpl = Base64.decode64(self['APPTEMPLATE64']) else tmpl = '' end name = [:name] || "marketapp-#{id}" [:vmtemplate_name] = name unless [:vmtemplate_name] tmpl << "\n" tmpl << 'NAME="' << name << "\"\n" tmpl << 'FROM_APP="' << self['ID'] << "\"\n" tmpl << 'URL_ARGS="' << [:url_args] << "\"\n" if [:url_args] case type_str when 'IMAGE' image = Image.new(Image.build_xml, @client) rc = image.allocate(tmpl, [:dsid]) ds = OpenNebula::Datastore.new_with_id([: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(, 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() return { :image => [], :vmtemplate => [vmtpl_id] } else return Error.new("App type #{type_str} not supported") end end |
#info ⇒ Object 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
292 293 294 |
# File 'lib/opennebula/marketplaceapp.rb', line 292 def lock(level) call(MARKETPLACEAPP_METHODS[:lock], @pe_id, level) end |
#rename(name) ⇒ nil, OpenNebula::Error
Renames this marketplace app
157 158 159 |
# File 'lib/opennebula/marketplaceapp.rb', line 157 def rename(name) call(MARKETPLACEAPP_METHODS[:rename], @pe_id, name) end |
#short_state_str ⇒ Object
Returns the state of the marketplace app (string value)
287 288 289 |
# File 'lib/opennebula/marketplaceapp.rb', line 287 def short_state_str SHORT_MARKETPLACEAPP_STATES[state_str] end |
#short_type_str ⇒ Object
Returns the marketplace app type (string value)
272 273 274 |
# File 'lib/opennebula/marketplaceapp.rb', line 272 def short_type_str SHORT_MARKETPLACEAPP_TYPES[type_str] end |
#state ⇒ Object
Returns the state of the marketplace app (numeric value)
277 278 279 |
# File 'lib/opennebula/marketplaceapp.rb', line 277 def state self['STATE'].to_i end |
#state_str ⇒ Object
Returns the state of the marketplace app (string value)
282 283 284 |
# File 'lib/opennebula/marketplaceapp.rb', line 282 def state_str MARKETPLACEAPP_STATES[state] end |
#type ⇒ Object
Returns the marketplace app type
262 263 264 |
# File 'lib/opennebula/marketplaceapp.rb', line 262 def type self['TYPE'].to_i end |
#type_str ⇒ Object
Returns the marketplace app type (string value)
267 268 269 |
# File 'lib/opennebula/marketplaceapp.rb', line 267 def type_str MARKETPLACEAPP_TYPES[type] end |
#unlock ⇒ Object
Unlocked a MarketplaceApp
297 298 299 |
# File 'lib/opennebula/marketplaceapp.rb', line 297 def unlock() call(MARKETPLACEAPP_METHODS[:unlock], @pe_id) end |
#update(new_template, append = false) ⇒ nil, OpenNebula::Error
Replaces the template contents
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 |