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
74 75 76 |
# File 'lib/opennebula/marketplaceapp.rb', line 74 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)
63 64 65 66 67 68 69 70 71 |
# File 'lib/opennebula/marketplaceapp.rb', line 63 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
96 97 98 |
# File 'lib/opennebula/marketplaceapp.rb', line 96 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
142 143 144 145 146 |
# File 'lib/opennebula/marketplaceapp.rb', line 142 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.
133 134 135 |
# File 'lib/opennebula/marketplaceapp.rb', line 133 def chmod_octet(octet) super(MARKETPLACEAPP_METHODS[:chmod], octet) end |
#chown(uid, gid) ⇒ nil, OpenNebula::Error
Changes the owner/group
124 125 126 |
# File 'lib/opennebula/marketplaceapp.rb', line 124 def chown(uid, gid) super(MARKETPLACEAPP_METHODS[:chown], uid, gid) end |
#delete ⇒ Object
Deletes the marketplace app
101 102 103 |
# File 'lib/opennebula/marketplaceapp.rb', line 101 def delete() super(MARKETPLACEAPP_METHODS[:delete]) end |
#disable ⇒ Object
Enables this app
231 232 233 |
# File 'lib/opennebula/marketplaceapp.rb', line 231 def disable return call(MARKETPLACEAPP_METHODS[:enable], @pe_id, false) end |
#enable ⇒ Object
Enables this app
226 227 228 |
# File 'lib/opennebula/marketplaceapp.rb', line 226 def enable return 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 ] }
171 172 173 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 |
# File 'lib/opennebula/marketplaceapp.rb', line 171 def export(={}) return Error.new("Missing datastore id") if [:dsid].nil? return Error.new("Missing name to export app") if [:name].nil? rc = info return rc if OpenNebula.is_error?(rc) return Error.new("App is not in READY state") if state_str!="READY" case type_str when "IMAGE" if !self['APPTEMPLATE64'].nil? tmpl=Base64::decode64(self['APPTEMPLATE64']) else tmpl="" end name = [:name] || "marketapp-#{self.id}" tmpl << "\n" tmpl << "NAME=\"" << name << "\"\n" tmpl << "FROM_APP=\"" << self['ID'] << "\"\n" image = Image.new(Image.build_xml, @client) rc = image.allocate(tmpl, [:dsid]) return { :image => [rc] } if OpenNebula.is_error?(rc) image_id = image.id vmtpl_id = -1 if !self['TEMPLATE/VMTEMPLATE64'].nil? tmpl=Base64::decode64(self['TEMPLATE/VMTEMPLATE64']) tmpl_name = [:vmtemplate_name] || name tmpl << "\nNAME=\"#{tmpl_name}\"\n" tmpl << "DISK=[ IMAGE_ID = #{image.id} ]\n" vmtpl = Template.new(Template.build_xml, @client) rc = vmtpl.allocate(tmpl) if OpenNebula.is_error?(rc) return { :image => [image_id], :vmtemplate => [rc] } end vmtpl_id = vmtpl.id end return { :image => [image_id], :vmtemplate => [vmtpl_id] } else return Error.new("App type #{app.type_str} not supported") end end |
#info ⇒ Object Also known as: info!
Retrieves the information of the given marketplace app
83 84 85 |
# File 'lib/opennebula/marketplaceapp.rb', line 83 def info() super(MARKETPLACEAPP_METHODS[:info], 'MARKETPLACEAPP') end |
#lock(level) ⇒ Object
Locked a MarketplaceApp
270 271 272 |
# File 'lib/opennebula/marketplaceapp.rb', line 270 def lock(level) return call(MARKETPLACEAPP_METHODS[:lock], @pe_id, level) end |
#rename(name) ⇒ nil, OpenNebula::Error
Renames this marketplace app
154 155 156 |
# File 'lib/opennebula/marketplaceapp.rb', line 154 def rename(name) return call(MARKETPLACEAPP_METHODS[:rename], @pe_id, name) end |
#short_state_str ⇒ Object
Returns the state of the marketplace app (string value)
265 266 267 |
# File 'lib/opennebula/marketplaceapp.rb', line 265 def short_state_str SHORT_MARKETPLACEAPP_STATES[state_str] end |
#short_type_str ⇒ Object
Returns the marketplace app type (string value)
250 251 252 |
# File 'lib/opennebula/marketplaceapp.rb', line 250 def short_type_str SHORT_MARKETPLACEAPP_TYPES[type_str] end |
#state ⇒ Object
Returns the state of the marketplace app (numeric value)
255 256 257 |
# File 'lib/opennebula/marketplaceapp.rb', line 255 def state self['STATE'].to_i end |
#state_str ⇒ Object
Returns the state of the marketplace app (string value)
260 261 262 |
# File 'lib/opennebula/marketplaceapp.rb', line 260 def state_str MARKETPLACEAPP_STATES[state] end |
#type ⇒ Object
Returns the marketplace app type
240 241 242 |
# File 'lib/opennebula/marketplaceapp.rb', line 240 def type self['TYPE'].to_i end |
#type_str ⇒ Object
Returns the marketplace app type (string value)
245 246 247 |
# File 'lib/opennebula/marketplaceapp.rb', line 245 def type_str MARKETPLACEAPP_TYPES[type] end |
#unlock ⇒ Object
Unlocked a MarketplaceApp
275 276 277 |
# File 'lib/opennebula/marketplaceapp.rb', line 275 def unlock() return call(MARKETPLACEAPP_METHODS[:unlock], @pe_id) end |
#update(new_template, append = false) ⇒ nil, OpenNebula::Error
Replaces the template contents
113 114 115 |
# File 'lib/opennebula/marketplaceapp.rb', line 113 def update(new_template, append=false) super(MARKETPLACEAPP_METHODS[:update], new_template, append ? 1 : 0) end |