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",
    :enable     => "market.enable"
}
MARKETPLACE_STATES =
%w{ENABLED DISABLED}
SHORT_MARKETPLACE_STATES =
{
    "ENABLED"              => "on",
    "DISABLED"             => "off"
}

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



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

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)


50
51
52
53
54
55
56
57
58
# File 'lib/opennebula/marketplace.rb', line 50

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:



82
83
84
# File 'lib/opennebula/marketplace.rb', line 82

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:



128
129
130
131
132
# File 'lib/opennebula/marketplace.rb', line 128

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:



119
120
121
# File 'lib/opennebula/marketplace.rb', line 119

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:



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

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



170
171
172
173
174
175
176
# File 'lib/opennebula/marketplace.rb', line 170

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



87
88
89
# File 'lib/opennebula/marketplace.rb', line 87

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

#disableObject

Enables this marketplace



150
151
152
# File 'lib/opennebula/marketplace.rb', line 150

def disable
    call(MARKETPLACE_METHODS[:enable], @pe_id, false)
end

#enableObject

Enables this marketplace



145
146
147
# File 'lib/opennebula/marketplace.rb', line 145

def enable
    call(MARKETPLACE_METHODS[:enable], @pe_id, true)
end

#infoObject Also known as: info!

Retrieves the information of the given marketplace.



70
71
72
# File 'lib/opennebula/marketplace.rb', line 70

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

#marketapp_idsObject

Returns an array with the numeric image ids



179
180
181
182
183
184
185
186
187
# File 'lib/opennebula/marketplace.rb', line 179

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:



140
141
142
# File 'lib/opennebula/marketplace.rb', line 140

def rename(name)
    call(MARKETPLACE_METHODS[:rename], @pe_id, name)
end

#stateObject

Returns the state of the Zone (numeric value)



159
160
161
# File 'lib/opennebula/marketplace.rb', line 159

def state
    self['STATE'].to_i
end

#state_strObject

Returns the state of the Zone (string value)



164
165
166
# File 'lib/opennebula/marketplace.rb', line 164

def state_str
    MARKETPLACE_STATES[state]
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:



99
100
101
# File 'lib/opennebula/marketplace.rb', line 99

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