Class: OpenNebula::MarketPlace

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

Constant Summary collapse

MARKETPLACE_METHODS =

Constants and Class Methods

{
    :info       => "market.info",
    :allocate   => "market.allocate",
    :delete     => "market.delete",
    :update     => "market.update",
    :chown      => "market.chown",
    :chmod      => "market.chmod",
    :rename     => "market.rename"
}

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) ⇒ MarketPlace

Class constructor



53
54
55
# File 'lib/opennebula/marketplace.rb', line 53

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:

marketplace = MarketPlace.new(MarketPlace.build_xml(3),rpc_client)


42
43
44
45
46
47
48
49
50
# File 'lib/opennebula/marketplace.rb', line 42

def MarketPlace.build_xml(pe_id=nil)
    if pe_id
        marketplace_xml = "<MARKETPLACE><ID>#{pe_id}</ID></MARKETPLACE>"
    else
        marketplace_xml = "<MARKETPLACE></MARKETPLACE>"
    end

    XMLElement.build_xml(marketplace_xml,'MARKETPLACE')
end

Instance Method Details

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

Allocates a new marketplace in OpenNebula

Parameters:

  • description (String)

    The template of the marketplace.

Returns:



74
75
76
# File 'lib/opennebula/marketplace.rb', line 74

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

Returns:



120
121
122
123
124
# File 'lib/opennebula/marketplace.rb', line 120

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

Parameters:

  • octet (String)

    Permissions octed , e.g. 640

Returns:



111
112
113
# File 'lib/opennebula/marketplace.rb', line 111

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



102
103
104
# File 'lib/opennebula/marketplace.rb', line 102

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

#contains(id) ⇒ Object

Returns whether or not the marketplace app with id ‘id’ is part of this marketplace



142
143
144
145
146
147
148
# File 'lib/opennebula/marketplace.rb', line 142

def contains(id)
    #This doesn't work in ruby 1.8.5
    #return self["MARKETPLACE/MARKETPLACEAPPS/ID[.=#{uid}]"] != nil

    id_array = retrieve_elements('MARKETPLACEAPPS/ID')
    return id_array != nil && id_array.include?(uid.to_s)
end

#deleteObject

Deletes the marketplace



79
80
81
# File 'lib/opennebula/marketplace.rb', line 79

def delete()
    super(MARKETPLACE_METHODS[:delete])
end

#infoObject Also known as: info!

Retrieves the information of the given marketplace.



62
63
64
# File 'lib/opennebula/marketplace.rb', line 62

def info()
    super(MARKETPLACE_METHODS[:info], 'MARKETPLACE')
end

#marketapp_idsObject

Returns an array with the numeric image ids



151
152
153
154
155
156
157
158
159
# File 'lib/opennebula/marketplace.rb', line 151

def marketapp_ids
    array = Array.new

    self.each("MARKETPLACEAPPS/ID") do |id|
        array << id.text.to_i
    end

    return array
end

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

Renames this marketplace

Parameters:

  • name (String)

    New name for the marketplace

Returns:



132
133
134
# File 'lib/opennebula/marketplace.rb', line 132

def rename(name)
    return call(MARKETPLACE_METHODS[:rename], @pe_id, name)
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:



91
92
93
# File 'lib/opennebula/marketplace.rb', line 91

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