mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-22 13:33:52 +03:00
feature #4217: OpenNebula core methods for MarketPlace class. OCA
binding and onemarket tool
This commit is contained in:
parent
5a0b3d357c
commit
ed92441582
@ -79,11 +79,11 @@ public:
|
||||
int from_xml(const string &xml_str);
|
||||
|
||||
/**
|
||||
* Adds this image's ID to the set.
|
||||
* Adds this marketplace app's ID to the set.
|
||||
* @param id of the app to be added to the MarketPlace
|
||||
* @return 0 on success
|
||||
*/
|
||||
int add_mpapp(int id)
|
||||
int add_marketapp(int id)
|
||||
{
|
||||
return add_collection_id(id);
|
||||
};
|
||||
@ -93,7 +93,7 @@ public:
|
||||
* @param id of the image to be deleted from the MarketPlace
|
||||
* @return 0 on success
|
||||
*/
|
||||
int del_mpapp(int id)
|
||||
int del_marketapp(int id)
|
||||
{
|
||||
return del_collection_id(id);
|
||||
};
|
||||
@ -101,7 +101,7 @@ public:
|
||||
/**
|
||||
* Returns a copy of the Image IDs set
|
||||
*/
|
||||
set<int> get_mpapp_ids()
|
||||
set<int> get_marketapp_ids()
|
||||
{
|
||||
return get_collection_copy();
|
||||
}
|
||||
@ -110,9 +110,9 @@ public:
|
||||
* Retrieves marketplace mad name
|
||||
* @return string mp mad name
|
||||
*/
|
||||
const string& get_mp_mad() const
|
||||
const string& get_market_mad() const
|
||||
{
|
||||
return mp_mad;
|
||||
return market_mad;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -148,7 +148,7 @@ private:
|
||||
/**
|
||||
* Name of the marketplace driver used to import apps
|
||||
*/
|
||||
string mp_mad;
|
||||
string market_mad;
|
||||
|
||||
/**
|
||||
* The marketplace type
|
||||
@ -174,12 +174,12 @@ private:
|
||||
// Constructor
|
||||
// *************************************************************************
|
||||
MarketPlace(
|
||||
int uid,
|
||||
int gid,
|
||||
const string& uname,
|
||||
const string& gname,
|
||||
int umask,
|
||||
MarketPlaceTemplate* ds_template);
|
||||
int uid,
|
||||
int gid,
|
||||
const string& uname,
|
||||
const string& gname,
|
||||
int umask,
|
||||
MarketPlaceTemplate* mp_template);
|
||||
|
||||
virtual ~MarketPlace();
|
||||
|
||||
@ -241,3 +241,4 @@ private:
|
||||
};
|
||||
|
||||
#endif /*MARKETPLACE_H*/
|
||||
|
||||
|
@ -17,7 +17,8 @@
|
||||
#ifndef MARKETPLACE_POOL_H_
|
||||
#define MARKETPLACE_POOL_H_
|
||||
|
||||
#include "Marketplace.h"
|
||||
#include "MarketPlace.h"
|
||||
#include "NebulaLog.h"
|
||||
#include "SqlDB.h"
|
||||
|
||||
class SqlDB;
|
||||
@ -34,9 +35,9 @@ public:
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Allocates a new Datastore, writing it in the pool database. No memory is
|
||||
* Allocates a new MarketPlace, writing it in the pool database. No memory is
|
||||
* allocated for the object.
|
||||
* @param uid the user id of the Datastore owner
|
||||
* @param uid the user id of the MarketPlace owner
|
||||
* @param gid the id of the group this object is assigned to
|
||||
* @param uname name of the user
|
||||
* @param gname name of the group
|
||||
@ -60,7 +61,7 @@ public:
|
||||
/**
|
||||
* Function to get a MarketPlace from the pool, the object is loaded if not
|
||||
* in memory
|
||||
* @param oid Datastore unique id
|
||||
* @param oid MarketPlace unique id
|
||||
* @param lock locks the MarketPlace mutex
|
||||
* @return a pointer to the MarketPlace, 0 if not loaded
|
||||
*/
|
||||
@ -77,9 +78,9 @@ public:
|
||||
*
|
||||
* @return a pointer to the object, 0 in case of failure
|
||||
*/
|
||||
Datastore * get(const std::string& name, bool lock)
|
||||
MarketPlace * get(const std::string& name, bool lock)
|
||||
{
|
||||
return static_cast<Datastore *>(PoolSQL::get(name,-1,lock));
|
||||
return static_cast<MarketPlace *>(PoolSQL::get(name,-1,lock));
|
||||
};
|
||||
|
||||
/**
|
||||
@ -94,22 +95,21 @@ public:
|
||||
return name;
|
||||
};
|
||||
|
||||
/** Update a particular Datastore
|
||||
* @param user pointer to Datastore
|
||||
/** Update a particular MarketPlace
|
||||
* @param user pointer to MarketPlace
|
||||
* @return 0 on success
|
||||
*/
|
||||
int update(Datastore * datastore)
|
||||
int update(MarketPlace * mp)
|
||||
{
|
||||
return datastore->update(db);
|
||||
return mp->update(db);
|
||||
};
|
||||
|
||||
/**
|
||||
* Drops the MarketPlac data in the data base. The object mutex SHOULD be
|
||||
* locked.
|
||||
* @param objsql a pointer to the Datastore object
|
||||
* @param objsql a pointer to the MarketPlace object
|
||||
* @param error_msg Error reason, if any
|
||||
* @return 0 on success, -1 DB error
|
||||
* -3 Datastore's Image IDs set is not empty
|
||||
* @return 0 on success, -1 DB error -3 MarketPlace's App ID set not empty
|
||||
*/
|
||||
int drop(PoolObjectSQL * objsql, std::string& error_msg)
|
||||
{
|
||||
@ -119,7 +119,7 @@ public:
|
||||
{
|
||||
std::ostringstream oss;
|
||||
|
||||
oss << "MarketPlace " << datastore->get_oid() << " is not empty.";
|
||||
oss << "MarketPlace " << mp->get_oid() << " is not empty.";
|
||||
error_msg = oss.str();
|
||||
|
||||
NebulaLog::log("MARKETPLACE", Log::ERROR, error_msg);
|
||||
@ -131,7 +131,7 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstraps the database table(s) associated to the Datastore pool
|
||||
* Bootstraps the database table(s) associated to the MarketPlace pool
|
||||
* @return 0 on success
|
||||
*/
|
||||
static int bootstrap(SqlDB * _db)
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "SecurityGroupPool.h"
|
||||
#include "VdcPool.h"
|
||||
#include "VirtualRouterPool.h"
|
||||
#include "MarketPlacePool.h"
|
||||
|
||||
#include "VirtualMachineManager.h"
|
||||
#include "LifeCycleManager.h"
|
||||
@ -142,6 +143,10 @@ public:
|
||||
return vrouterpool;
|
||||
};
|
||||
|
||||
MarketPlacePool * get_mppool()
|
||||
{
|
||||
return mppool;
|
||||
};
|
||||
// --------------------------------------------------------------
|
||||
// Manager Accessors
|
||||
// --------------------------------------------------------------
|
||||
@ -664,7 +669,7 @@ private:
|
||||
system_db(0), db(0),
|
||||
vmpool(0), hpool(0), vnpool(0), upool(0), ipool(0), gpool(0), tpool(0),
|
||||
dspool(0), clpool(0), docpool(0), zonepool(0),
|
||||
secgrouppool(0), vdcpool(0), vrouterpool(0),
|
||||
secgrouppool(0), vdcpool(0), vrouterpool(0), mppool(0),
|
||||
lcm(0), vmm(0), im(0), tm(0), dm(0), rm(0), hm(0), authm(0),
|
||||
aclm(0), imagem(0)
|
||||
{
|
||||
@ -715,6 +720,7 @@ private:
|
||||
delete secgrouppool;
|
||||
delete vdcpool;
|
||||
delete vrouterpool;
|
||||
delete mppool;
|
||||
delete vmm;
|
||||
delete lcm;
|
||||
delete im;
|
||||
@ -795,6 +801,7 @@ private:
|
||||
SecurityGroupPool * secgrouppool;
|
||||
VdcPool * vdcpool;
|
||||
VirtualRouterPool * vrouterpool;
|
||||
MarketPlacePool * mppool;
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Nebula Managers
|
||||
|
@ -618,7 +618,39 @@ public:
|
||||
RequestAttributes& att);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class MarketPlaceAllocate : public RequestManagerAllocate
|
||||
{
|
||||
public:
|
||||
MarketPlaceAllocate():
|
||||
RequestManagerAllocate("MarketPlaceAllocate",
|
||||
"Allocates a new marketplace",
|
||||
"A:ss",
|
||||
true)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_mppool();
|
||||
auth_object = PoolObjectSQL::MARKETPLACE;
|
||||
};
|
||||
|
||||
~MarketPlaceAllocate(){};
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
Template * get_object_template()
|
||||
{
|
||||
return new MarketPlaceTemplate;
|
||||
};
|
||||
|
||||
int pool_allocate(xmlrpc_c::paramList const& _paramList,
|
||||
Template * tmpl,
|
||||
int& id,
|
||||
string& error_str,
|
||||
RequestAttributes& att);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
|
@ -189,7 +189,25 @@ public:
|
||||
~VirtualRouterChmod(){};
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class MarketPlaceChmod: public RequestManagerChmod
|
||||
{
|
||||
public:
|
||||
MarketPlaceChmod():
|
||||
RequestManagerChmod("MarketPlaceChmod",
|
||||
"Changes permission bits of a marketplace")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_mppool();
|
||||
auth_object = PoolObjectSQL::MARKETPLACE;
|
||||
};
|
||||
|
||||
~MarketPlaceChmod(){};
|
||||
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
|
@ -292,7 +292,29 @@ public:
|
||||
};
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class MarketPlaceChown: public RequestManagerChown
|
||||
{
|
||||
public:
|
||||
MarketPlaceChown():
|
||||
RequestManagerChown("MarketPlaceChown",
|
||||
"Changes ownership of a marketplace")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_mppool();
|
||||
auth_object = PoolObjectSQL::MARKETPLACE;
|
||||
};
|
||||
|
||||
~MarketPlaceChown(){};
|
||||
|
||||
PoolObjectSQL * get(const string& name, int uid, bool lock)
|
||||
{
|
||||
return 0;
|
||||
};
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
|
@ -372,7 +372,24 @@ public:
|
||||
~VirtualRouterDelete(){};
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class MarketPlaceDelete : public RequestManagerDelete
|
||||
{
|
||||
public:
|
||||
MarketPlaceDelete():
|
||||
RequestManagerDelete("MarketPlaceDelete",
|
||||
"Deletes a marketplace")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_mppool();
|
||||
auth_object = PoolObjectSQL::MARKETPLACE;
|
||||
};
|
||||
|
||||
~MarketPlaceDelete(){};
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
|
@ -336,7 +336,24 @@ public:
|
||||
~VirtualRouterInfo(){};
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class MarketPlaceInfo : public RequestManagerInfo
|
||||
{
|
||||
public:
|
||||
MarketPlaceInfo():
|
||||
RequestManagerInfo("MarketPlaceInfo",
|
||||
"Returns MarketPlace information")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_mppool();
|
||||
auth_object = PoolObjectSQL::MARKETPLACE;
|
||||
};
|
||||
|
||||
~MarketPlaceInfo(){};
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
|
@ -488,10 +488,7 @@ public:
|
||||
|
||||
~VdcPoolInfo(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void request_execute(
|
||||
xmlrpc_c::paramList const& paramList, RequestAttributes& att);
|
||||
void request_execute(xmlrpc_c::paramList const& pl, RequestAttributes& att);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -515,6 +512,23 @@ public:
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
class MarketPlacePoolInfo : public RequestManagerPoolInfoFilter
|
||||
{
|
||||
public:
|
||||
MarketPlacePoolInfo():
|
||||
RequestManagerPoolInfoFilter("MarketPlacePoolInfo",
|
||||
"Returns the market place pool",
|
||||
"A:s")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_mppool();
|
||||
auth_object = PoolObjectSQL::MARKETPLACE;
|
||||
};
|
||||
|
||||
~MarketPlacePoolInfo(){};
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& pl, RequestAttributes& att);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -356,7 +356,30 @@ public:
|
||||
};
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class MarketPlaceRename: public RequestManagerRename
|
||||
{
|
||||
public:
|
||||
MarketPlaceRename():
|
||||
RequestManagerRename("MarketPlaceRename", "Renames a marketplace")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_mppool();
|
||||
auth_object = PoolObjectSQL::MARKETPLACE;
|
||||
};
|
||||
|
||||
~MarketPlaceRename(){};
|
||||
|
||||
PoolObjectSQL * get(const string& name, int uid, bool lock)
|
||||
{
|
||||
return static_cast<MarketPlacePool*>(pool)->get(name, lock);
|
||||
};
|
||||
|
||||
//TODO implement batch rename for MarketPlaceApps
|
||||
//void batch_rename(int oid);
|
||||
};
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
|
@ -304,7 +304,23 @@ public:
|
||||
~VirtualRouterUpdateTemplate(){};
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class MarketPlaceUpdateTemplate : public RequestManagerUpdateTemplate
|
||||
{
|
||||
public:
|
||||
MarketPlaceUpdateTemplate():
|
||||
RequestManagerUpdateTemplate("MarketPlaceUpdateTemplate",
|
||||
"Updates a virtual router template")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_mppool();
|
||||
auth_object = PoolObjectSQL::MARKETPLACE;
|
||||
};
|
||||
|
||||
~MarketPlaceUpdateTemplate(){};
|
||||
};
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
|
23
install.sh
23
install.sh
@ -585,6 +585,7 @@ BIN_FILES="src/nebula/oned \
|
||||
src/cli/onesecgroup \
|
||||
src/cli/onevdc \
|
||||
src/cli/onevrouter \
|
||||
src/cli/onemarket \
|
||||
src/cli/onevcenter \
|
||||
src/onedb/onedb \
|
||||
src/mad/utils/tty_expect \
|
||||
@ -1379,7 +1380,9 @@ RUBY_OPENNEBULA_LIB_FILES="src/oca/ruby/opennebula/acl_pool.rb \
|
||||
src/oca/ruby/opennebula/zone_pool.rb \
|
||||
src/oca/ruby/opennebula/zone.rb \
|
||||
src/oca/ruby/opennebula/virtual_router_pool.rb \
|
||||
src/oca/ruby/opennebula/virtual_router.rb"
|
||||
src/oca/ruby/opennebula/virtual_router.rb \
|
||||
src/oca/ruby/opennebula/marketplace_pool.rb \
|
||||
src/oca/ruby/opennebula/marketplace.rb"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Common Cloud Files
|
||||
@ -1498,13 +1501,13 @@ ECO_ETC_TEMPLATE_FILES="src/cloud/ec2/etc/templates/m1.small.erb"
|
||||
# Marketplace Client
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
MARKET_LIB_FILES="src/cloud/marketplace/lib/marketplace_client.rb"
|
||||
#MARKET_LIB_FILES="src/cloud/marketplace/lib/marketplace_client.rb"
|
||||
|
||||
MARKET_LIB_CLIENT_FILES="src/cloud/marketplace/lib/marketplace_client.rb"
|
||||
#MARKET_LIB_CLIENT_FILES="src/cloud/marketplace/lib/marketplace_client.rb"
|
||||
|
||||
MARKET_BIN_FILES="src/cloud/marketplace/bin/onemarket"
|
||||
#MARKET_BIN_FILES="src/cloud/marketplace/bin/onemarket"
|
||||
|
||||
MARKET_BIN_CLIENT_FILES="src/cloud/marketplace/bin/onemarket"
|
||||
#MARKET_BIN_CLIENT_FILES="src/cloud/marketplace/bin/onemarket"
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
@ -1530,7 +1533,8 @@ ONE_CLI_LIB_FILES="src/cli/one_helper/onegroup_helper.rb \
|
||||
src/cli/one_helper/onevdc_helper.rb \
|
||||
src/cli/one_helper/oneacct_helper.rb \
|
||||
src/cli/one_helper/onesecgroup_helper.rb \
|
||||
src/cli/one_helper/onevrouter_helper.rb"
|
||||
src/cli/one_helper/onevrouter_helper.rb \
|
||||
src/cli/one_helper/onemarket_helper.rb"
|
||||
|
||||
CLI_BIN_FILES="src/cli/onevm \
|
||||
src/cli/onehost \
|
||||
@ -1549,7 +1553,8 @@ CLI_BIN_FILES="src/cli/onevm \
|
||||
src/cli/onesecgroup \
|
||||
src/cli/oneshowback \
|
||||
src/cli/onevdc \
|
||||
src/cli/onevrouter"
|
||||
src/cli/onevrouter \
|
||||
src/cli/onemarket"
|
||||
|
||||
CLI_CONF_FILES="src/cli/etc/onegroup.yaml \
|
||||
src/cli/etc/onehost.yaml \
|
||||
@ -1566,7 +1571,8 @@ CLI_CONF_FILES="src/cli/etc/onegroup.yaml \
|
||||
src/cli/etc/onesecgroup.yaml \
|
||||
src/cli/etc/oneshowback.yaml \
|
||||
src/cli/etc/onevdc.yaml \
|
||||
src/cli/etc/onevrouter.yaml"
|
||||
src/cli/etc/onevrouter.yaml \
|
||||
src/cli/etc/onemarket.yaml"
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Sunstone files
|
||||
@ -1839,6 +1845,7 @@ MAN_FILES="share/man/oneacct.1.gz \
|
||||
share/man/onesecgroup.1.gz \
|
||||
share/man/onevdc.1.gz \
|
||||
share/man/onevrouter.1.gz \
|
||||
share/man/onemarket.1.gz \
|
||||
share/man/econe-allocate-address.1.gz \
|
||||
share/man/econe-associate-address.1.gz \
|
||||
share/man/econe-attach-volume.1.gz \
|
||||
|
@ -65,6 +65,7 @@ env.Man('onevcenter')
|
||||
env.Man('onesecgroup')
|
||||
env.Man('onevdc')
|
||||
env.Man('onevrouter')
|
||||
#env.Man('onemarket')
|
||||
|
||||
env.Man('oneflow')
|
||||
env.Man('oneflow-template')
|
||||
|
41
src/cli/etc/onemarket.yaml
Normal file
41
src/cli/etc/onemarket.yaml
Normal file
@ -0,0 +1,41 @@
|
||||
---
|
||||
:ID:
|
||||
:desc: ONE identifier for the Marketplace
|
||||
:size: 4
|
||||
|
||||
:NAME:
|
||||
:desc: Name of the Marketplace
|
||||
:size: 13
|
||||
:left: true
|
||||
|
||||
:SIZE:
|
||||
:desc: Marketplace total size (M)
|
||||
:size: 10
|
||||
|
||||
:AVAIL:
|
||||
:desc: MarketPlace free size (%)
|
||||
:size: 5
|
||||
:left: true
|
||||
|
||||
:MARKETAPPS:
|
||||
:desc: Number of Marketplace Apps
|
||||
:size: 6
|
||||
|
||||
:TYPE:
|
||||
:desc: Marketplace type
|
||||
:size: 4
|
||||
:left: true
|
||||
|
||||
:MAD:
|
||||
:desc: Marketplace driver
|
||||
:size: 7
|
||||
:left: true
|
||||
|
||||
:default:
|
||||
- :ID
|
||||
- :NAME
|
||||
- :SIZE
|
||||
- :AVAIL
|
||||
- :MARKETAPPS
|
||||
- :TYPE
|
||||
- :MAD
|
144
src/cli/one_helper/onemarket_helper.rb
Normal file
144
src/cli/one_helper/onemarket_helper.rb
Normal file
@ -0,0 +1,144 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'one_helper'
|
||||
|
||||
class OneMarketPlaceHelper < OpenNebulaHelper::OneHelper
|
||||
DATASTORE = {
|
||||
:name => "marketplace",
|
||||
:short => "-m id|name",
|
||||
:large => "--marketplace id|name" ,
|
||||
:description => "Selects the marketplace",
|
||||
:format => String,
|
||||
:proc => lambda { |o, options|
|
||||
OpenNebulaHelper.rname_to_id(o, "MARKETPLACE")
|
||||
}
|
||||
}
|
||||
|
||||
def self.rname
|
||||
"MARKETPLACE"
|
||||
end
|
||||
|
||||
def self.conf_file
|
||||
"onemarket.yaml"
|
||||
end
|
||||
|
||||
def format_pool(options)
|
||||
config_file = self.class.table_conf
|
||||
|
||||
table = CLIHelper::ShowTable.new(config_file, self) do
|
||||
column :ID, "ONE identifier for the Marketplace", :size=>4 do |d|
|
||||
d["ID"]
|
||||
end
|
||||
|
||||
column :NAME, "Name of the Marketplace", :left, :size=>13 do |d|
|
||||
d["NAME"]
|
||||
end
|
||||
|
||||
column :SIZE, "Marketplace total size", :size =>10 do |d|
|
||||
OpenNebulaHelper.unit_to_str(d['TOTAL_MB'].to_i, {}, 'M')
|
||||
end
|
||||
|
||||
column :AVAIL, "Marketplace free size", :left, :size =>5 do |d|
|
||||
if d['TOTAL_MB'].to_i == 0
|
||||
"-"
|
||||
else
|
||||
"#{((d['FREE_MB'].to_f/d['TOTAL_MB'].to_f) * 100).round()}%"
|
||||
end
|
||||
end
|
||||
|
||||
column :MARKETAPPS, "Number of marketplace apps", :size=>6 do |d|
|
||||
if d["MARKETPLACEAPPS"]["ID"].nil?
|
||||
"0"
|
||||
else
|
||||
d["MARKETPLACEAPPS"]["ID"].size
|
||||
end
|
||||
end
|
||||
|
||||
column :TYPE, "Marketplace type", :left, :size=>4 do |d|
|
||||
type = MarketPlace::MARKETPLACE_TYPES[d["TYPE"].to_i]
|
||||
MarketPlace::SHORT_MARKETPLACE_TYPES[type]
|
||||
end
|
||||
|
||||
column :MAD, "Marketplace driver", :left, :size=>7 do |d|
|
||||
d["MARKET_MAD"]
|
||||
end
|
||||
|
||||
default :ID, :NAME, :SIZE, :AVAIL, :MARKETAPPS, :TYPE, :MAD
|
||||
end
|
||||
|
||||
table
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def factory(id=nil)
|
||||
if id
|
||||
OpenNebula::MarketPlace.new_with_id(id, @client)
|
||||
else
|
||||
xml=OpenNebula::MarketPlace.build_xml
|
||||
OpenNebula::MarketPlace.new(xml, @client)
|
||||
end
|
||||
end
|
||||
|
||||
def factory_pool(user_flag=-2)
|
||||
OpenNebula::MarketPlacePool.new(@client)
|
||||
end
|
||||
|
||||
def format_resource(datastore, options = {})
|
||||
str="%-15s: %-20s"
|
||||
str_h1="%-80s"
|
||||
|
||||
CLIHelper.print_header(str_h1 % "MARKETPLACE #{datastore['ID']} INFORMATION")
|
||||
puts str % ["ID", datastore.id.to_s]
|
||||
puts str % ["NAME", datastore.name]
|
||||
puts str % ["USER", datastore['UNAME']]
|
||||
puts str % ["GROUP", datastore['GNAME']]
|
||||
puts str % ["TYPE", datastore.type_str]
|
||||
|
||||
puts str % ["MARKET_MAD", datastore['MARKET_MAD']]
|
||||
puts
|
||||
|
||||
CLIHelper.print_header(str_h1 % "MARKETPLACE CAPACITY", false)
|
||||
|
||||
puts str % ["TOTAL:", OpenNebulaHelper.unit_to_str(datastore['TOTAL_MB'].to_i,{},'M')]
|
||||
puts str % ["FREE:", OpenNebulaHelper.unit_to_str(datastore['FREE_MB'].to_i, {},'M')]
|
||||
puts str % ["USED: ", OpenNebulaHelper.unit_to_str(datastore['USED_MB'].to_i, {},'M')]
|
||||
puts
|
||||
|
||||
CLIHelper.print_header(str_h1 % "PERMISSIONS",false)
|
||||
|
||||
["OWNER", "GROUP", "OTHER"].each { |e|
|
||||
mask = "---"
|
||||
mask[0] = "u" if datastore["PERMISSIONS/#{e}_U"] == "1"
|
||||
mask[1] = "m" if datastore["PERMISSIONS/#{e}_M"] == "1"
|
||||
mask[2] = "a" if datastore["PERMISSIONS/#{e}_A"] == "1"
|
||||
|
||||
puts str % [e, mask]
|
||||
}
|
||||
puts
|
||||
|
||||
CLIHelper.print_header(str_h1 % "MARKETPLACE TEMPLATE", false)
|
||||
puts datastore.template_str
|
||||
|
||||
puts
|
||||
|
||||
CLIHelper.print_header("%-15s" % "MARKETAPPS")
|
||||
datastore.marketapp_ids.each do |id|
|
||||
puts "%-15s" % [id]
|
||||
end
|
||||
end
|
||||
end
|
178
src/cli/onemarket
Executable file
178
src/cli/onemarket
Executable file
@ -0,0 +1,178 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
ONE_LOCATION=ENV["ONE_LOCATION"]
|
||||
|
||||
if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
$: << RUBY_LIB_LOCATION+"/cli"
|
||||
|
||||
require 'command_parser'
|
||||
require 'one_helper/onemarket_helper'
|
||||
|
||||
cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
usage "`onemarket` <command> [<args>] [<options>]"
|
||||
version OpenNebulaHelper::ONE_VERSION
|
||||
|
||||
helper = OneMarketPlaceHelper.new
|
||||
|
||||
before_proc do
|
||||
helper.set_client(options)
|
||||
end
|
||||
|
||||
########################################################################
|
||||
# Global Options
|
||||
########################################################################
|
||||
set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS
|
||||
|
||||
list_options = CLIHelper::OPTIONS
|
||||
list_options << OpenNebulaHelper::XML
|
||||
list_options << OpenNebulaHelper::NUMERIC
|
||||
list_options << OpenNebulaHelper::DESCRIBE
|
||||
|
||||
########################################################################
|
||||
# Formatters for arguments
|
||||
########################################################################
|
||||
set :format, :marketplaceid, OneMarketPlaceHelper.to_id_desc do |arg|
|
||||
helper.to_id(arg)
|
||||
end
|
||||
|
||||
set :format, :marketplaceid_list, OneMarketPlaceHelper.list_to_id_desc do |arg|
|
||||
helper.list_to_id(arg)
|
||||
end
|
||||
|
||||
set :format, :groupid, OpenNebulaHelper.rname_to_id_desc("GROUP") do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, "GROUP")
|
||||
end
|
||||
|
||||
set :format, :userid, OpenNebulaHelper.rname_to_id_desc("USER") do |arg|
|
||||
OpenNebulaHelper.rname_to_id(arg, "USER")
|
||||
end
|
||||
|
||||
########################################################################
|
||||
# Commands
|
||||
########################################################################
|
||||
|
||||
create_desc = <<-EOT.unindent
|
||||
Creates a new Marketplace from the given template file
|
||||
EOT
|
||||
|
||||
command :create, create_desc, :file do
|
||||
|
||||
helper.create_resource(options) do |marketplace|
|
||||
begin
|
||||
template = File.read(args[0])
|
||||
marketplace.allocate(template)
|
||||
rescue =>e
|
||||
STDERR.puts e.message
|
||||
exit -1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
delete_desc = <<-EOT.unindent
|
||||
Deletes the given Marketplace
|
||||
EOT
|
||||
|
||||
command :delete, delete_desc, [:range, :marketplaceid_list] do
|
||||
helper.perform_actions(args[0],options,"deleted") do |obj|
|
||||
obj.delete
|
||||
end
|
||||
end
|
||||
|
||||
chgrp_desc = <<-EOT.unindent
|
||||
Changes the Marketplace group
|
||||
EOT
|
||||
|
||||
command :chgrp, chgrp_desc,[:range, :marketplaceid_list], :groupid do
|
||||
helper.perform_actions(args[0],options,"Group changed") do |obj|
|
||||
obj.chown(-1, args[1].to_i)
|
||||
end
|
||||
end
|
||||
|
||||
chown_desc = <<-EOT.unindent
|
||||
Changes the Marketplace owner and group
|
||||
EOT
|
||||
|
||||
command :chown, chown_desc, [:range, :marketplaceid_list], :userid,
|
||||
[:groupid,nil] do
|
||||
gid = args[2].nil? ? -1 : args[2].to_i
|
||||
helper.perform_actions(args[0],options,"Owner/Group changed") do |obj|
|
||||
obj.chown(args[1].to_i, gid)
|
||||
end
|
||||
end
|
||||
|
||||
chmod_desc = <<-EOT.unindent
|
||||
Changes the Marketplace permissions
|
||||
EOT
|
||||
|
||||
command :chmod, chmod_desc, [:range, :marketplaceid_list], :octet do
|
||||
helper.perform_actions(args[0],options, "Permissions changed") do |obj|
|
||||
obj.chmod_octet(args[1])
|
||||
end
|
||||
end
|
||||
|
||||
list_desc = <<-EOT.unindent
|
||||
Lists Marketplaces
|
||||
EOT
|
||||
|
||||
command :list, list_desc, :options=>list_options do
|
||||
helper.list_pool(options)
|
||||
end
|
||||
|
||||
show_desc = <<-EOT.unindent
|
||||
Shows Marketplace information
|
||||
EOT
|
||||
|
||||
command :show, show_desc, :marketplaceid, :options=>OpenNebulaHelper::XML do
|
||||
helper.show_resource(args[0],options)
|
||||
end
|
||||
|
||||
update_desc = <<-EOT.unindent
|
||||
Update the template contents. If a path is not provided the editor will
|
||||
be launched to modify the current content.
|
||||
EOT
|
||||
|
||||
command :update, update_desc, :marketplaceid, [:file, nil],
|
||||
:options=>OpenNebulaHelper::APPEND do
|
||||
helper.perform_action(args[0],options,"modified") do |obj|
|
||||
if options[:append]
|
||||
str = OpenNebulaHelper.append_template(args[0], obj, args[1])
|
||||
else
|
||||
str = OpenNebulaHelper.update_template(args[0], obj, args[1])
|
||||
end
|
||||
|
||||
obj.update(str, options[:append])
|
||||
end
|
||||
end
|
||||
|
||||
rename_desc = <<-EOT.unindent
|
||||
Renames the Marketplace
|
||||
EOT
|
||||
|
||||
command :rename, rename_desc, :marketplaceid, :name do
|
||||
helper.perform_action(args[0],options,"renamed") do |o|
|
||||
o.rename(args[1])
|
||||
end
|
||||
end
|
||||
end
|
@ -43,10 +43,10 @@ MarketPlace::MarketPlace(
|
||||
const std::string& uname,
|
||||
const std::string& gname,
|
||||
int umask,
|
||||
MarketPlaceTemplate* mp_template):
|
||||
MarketPlaceTemplate * mp_template):
|
||||
PoolObjectSQL(-1, MARKETPLACE, "", uid, gid, uname, gname, table),
|
||||
ObjectCollection("MARKETPLACEAPPS"),
|
||||
mp_mad(""),
|
||||
market_mad(""),
|
||||
type(IMAGE_MP),
|
||||
total_mb(0),
|
||||
free_mb(0),
|
||||
@ -86,9 +86,9 @@ int MarketPlace::insert(SqlDB *db, string& error_str)
|
||||
//MarketPlacePool::allocate checks NAME
|
||||
erase_template_attribute("NAME", name);
|
||||
|
||||
get_template_attribute("MP_MAD", mp_mad);
|
||||
erase_template_attribute("MARKET_MAD", market_mad);
|
||||
|
||||
if ( mp_mad.empty() == true )
|
||||
if ( market_mad.empty() == true )
|
||||
{
|
||||
goto error_mad;
|
||||
}
|
||||
@ -102,17 +102,15 @@ int MarketPlace::insert(SqlDB *db, string& error_str)
|
||||
goto error_type;
|
||||
}
|
||||
|
||||
add_template_attribute("TYPE", type_to_str(type));
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
return insert_replace(db, false, error_str);
|
||||
|
||||
error_mad:
|
||||
error_str = "No MarketPlace driver (MP_MAD) in template.";
|
||||
error_str = "No marketplace driver (MARKET_MAD) in template.";
|
||||
goto error_common;
|
||||
error_type:
|
||||
error_str = "Unknown MarketPlace type: " + s_mp_type;
|
||||
error_str = "Unknown marketplace type: " + s_mp_type;
|
||||
goto error_common;
|
||||
|
||||
error_common:
|
||||
@ -183,7 +181,7 @@ error_xml:
|
||||
db->free_str(sql_name);
|
||||
db->free_str(sql_xml);
|
||||
|
||||
error_str = "Error transforming the MarketPlace to XML.";
|
||||
error_str = "Error transforming the marketplace to XML.";
|
||||
|
||||
goto error_common;
|
||||
|
||||
@ -195,7 +193,7 @@ error_name:
|
||||
goto error_generic;
|
||||
|
||||
error_generic:
|
||||
error_str = "Error inserting MarketPlace in DB.";
|
||||
error_str = "Error inserting marketplace in DB.";
|
||||
error_common:
|
||||
return -1;
|
||||
}
|
||||
@ -222,7 +220,8 @@ std::string& MarketPlace::to_xml(std::string& xml) const
|
||||
"<UNAME>" << uname << "</UNAME>" <<
|
||||
"<GNAME>" << gname << "</GNAME>" <<
|
||||
"<NAME>" << name << "</NAME>" <<
|
||||
"<MP_MAD>"<< one_util::escape_xml(mp_mad) << "</MP_MAD>" <<
|
||||
"<TYPE>" << type << "</TYPE>" <<
|
||||
"<MARKET_MAD>"<<one_util::escape_xml(market_mad)<<"</MARKET_MAD>"<<
|
||||
"<TOTAL_MB>" << total_mb << "</TOTAL_MB>" <<
|
||||
"<FREE_MB>" << free_mb << "</FREE_MB>" <<
|
||||
"<USED_MB>" << used_mb << "</USED_MB>" <<
|
||||
@ -249,14 +248,15 @@ int MarketPlace::from_xml(const std::string &xml_str)
|
||||
update_from_str(xml_str);
|
||||
|
||||
// ----- MARKETPLACE base attributes -----
|
||||
rc += xpath(oid, "/MARKETPLACE/ID", -1);
|
||||
rc += xpath(uid, "/MARKETPLACE/UID", -1);
|
||||
rc += xpath(gid, "/MARKETPLACE/GID", -1);
|
||||
rc += xpath(uname, "/MARKETPLACE/UNAME", "not_found");
|
||||
rc += xpath(gname, "/MARKETPLACE/GNAME", "not_found");
|
||||
rc += xpath(name, "/MARKETPLACE/NAME", "not_found");
|
||||
rc += xpath(mp_mad, "/MARKETPLACE/MP_MAD", "not_found");
|
||||
rc += xpath(itype, "/MARKETPLACE/TYPE", -1);
|
||||
rc += xpath(oid, "/MARKETPLACE/ID", -1);
|
||||
rc += xpath(uid, "/MARKETPLACE/UID", -1);
|
||||
rc += xpath(gid, "/MARKETPLACE/GID", -1);
|
||||
rc += xpath(uname, "/MARKETPLACE/UNAME", "not_found");
|
||||
rc += xpath(gname, "/MARKETPLACE/GNAME", "not_found");
|
||||
rc += xpath(name, "/MARKETPLACE/NAME", "not_found");
|
||||
rc += xpath(itype, "/MARKETPLACE/TYPE", -1);
|
||||
|
||||
rc += xpath(market_mad, "/MARKETPLACE/MARKET_MAD", "not_found");
|
||||
|
||||
rc += xpath(total_mb, "/MARKETPLACE/TOTAL_MB", 0);
|
||||
rc += xpath(free_mb, "/MARKETPLACE/FREE_MB", 0);
|
||||
@ -307,12 +307,12 @@ int MarketPlace::from_xml(const std::string &xml_str)
|
||||
int MarketPlace::post_update_template(string& error)
|
||||
{
|
||||
std::string new_s_type;
|
||||
std::string new_mp_mad;
|
||||
std::string new_market_mad;
|
||||
|
||||
MarketPlaceType new_type;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Sanitize TYPE and MP_MAD attributes
|
||||
// Sanitize TYPE and MARKET_MAD attributes
|
||||
// -------------------------------------------------------------------------
|
||||
erase_template_attribute("TYPE", new_s_type);
|
||||
|
||||
@ -320,7 +320,7 @@ int MarketPlace::post_update_template(string& error)
|
||||
|
||||
if ( new_type == UNKNOWN )
|
||||
{
|
||||
error = "Unknown MarketPlace type: " + new_s_type;
|
||||
error = "Unknown marketplace type: " + new_s_type;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -328,14 +328,14 @@ int MarketPlace::post_update_template(string& error)
|
||||
|
||||
add_template_attribute("TYPE", type_to_str(type));
|
||||
|
||||
erase_template_attribute("MP_MAD", new_mp_mad);
|
||||
erase_template_attribute("MARKET_MAD", new_market_mad);
|
||||
|
||||
if (!new_mp_mad.empty())
|
||||
if (!new_market_mad.empty())
|
||||
{
|
||||
mp_mad = new_mp_mad;
|
||||
market_mad = new_market_mad;
|
||||
}
|
||||
|
||||
add_template_attribute("MP_MAD", mp_mad);
|
||||
add_template_attribute("MARKET_MAD", market_mad);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
73
src/market/MarketPlacePool.cc
Normal file
73
src/market/MarketPlacePool.cc
Normal file
@ -0,0 +1,73 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2015, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "MarketPlacePool.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int MarketPlacePool::allocate(
|
||||
int uid,
|
||||
int gid,
|
||||
const std::string& uname,
|
||||
const std::string& gname,
|
||||
int umask,
|
||||
MarketPlaceTemplate * mp_template,
|
||||
int * oid,
|
||||
std::string& error_str)
|
||||
{
|
||||
MarketPlace * mp;
|
||||
MarketPlace * mp_aux = 0;
|
||||
|
||||
std::string name;
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
mp = new MarketPlace(uid, gid, uname, gname, umask, mp_template);
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Check name & duplicates
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
mp->get_template_attribute("NAME", name);
|
||||
|
||||
if ( !PoolObjectSQL::name_is_valid(name, error_str) )
|
||||
{
|
||||
goto error_name;
|
||||
}
|
||||
|
||||
mp_aux = get(name, false);
|
||||
|
||||
if( mp_aux != 0 )
|
||||
{
|
||||
goto error_duplicated;
|
||||
}
|
||||
|
||||
*oid = PoolSQL::allocate(mp, error_str);
|
||||
|
||||
return *oid;
|
||||
|
||||
error_duplicated:
|
||||
oss << "NAME is already taken by MARKETPLACE " << mp_aux->get_oid() << ".";
|
||||
error_str = oss.str();
|
||||
|
||||
error_name:
|
||||
delete mp;
|
||||
*oid = -1;
|
||||
|
||||
return *oid;
|
||||
}
|
||||
|
@ -22,7 +22,8 @@ lib_name='nebula_marketplace'
|
||||
|
||||
# Sources to generate the library
|
||||
source_files=[
|
||||
'MarketPlace.cc'
|
||||
'MarketPlace.cc',
|
||||
'MarketPlacePool.cc'
|
||||
]
|
||||
|
||||
# Build library
|
||||
|
@ -347,6 +347,7 @@ void Nebula::start(bool bootstrap_only)
|
||||
rc += GroupQuotas::bootstrap(db);
|
||||
rc += SecurityGroupPool::bootstrap(db);
|
||||
rc += VirtualRouterPool::bootstrap(db);
|
||||
rc += MarketPlacePool::bootstrap(db);
|
||||
|
||||
// Create the system tables only if bootstrap went well
|
||||
if (rc == 0)
|
||||
@ -493,6 +494,7 @@ void Nebula::start(bool bootstrap_only)
|
||||
zonepool= new ZonePool(db, is_federation_slave());
|
||||
vdcpool = new VdcPool(db, is_federation_slave());
|
||||
vrouterpool = new VirtualRouterPool(db);
|
||||
mppool = new MarketPlacePool(db);
|
||||
|
||||
nebula_configuration->get("VM_HOOK", vm_hooks);
|
||||
nebula_configuration->get("HOST_HOOK", host_hooks);
|
||||
|
@ -65,6 +65,7 @@ env.Prepend(LIBS=[
|
||||
'nebula_secgroup',
|
||||
'nebula_vdc',
|
||||
'nebula_vrouter',
|
||||
'nebula_marketplace',
|
||||
'crypto',
|
||||
'xml2'
|
||||
])
|
||||
|
@ -58,6 +58,8 @@ require 'opennebula/vdc_pool'
|
||||
require 'opennebula/system'
|
||||
require 'opennebula/virtual_router'
|
||||
require 'opennebula/virtual_router_pool'
|
||||
require 'opennebula/marketplace'
|
||||
require 'opennebula/marketplace_pool'
|
||||
|
||||
module OpenNebula
|
||||
|
||||
|
@ -36,9 +36,9 @@ module OpenNebula
|
||||
super('DATASTORE_POOL','DATASTORE',client)
|
||||
end
|
||||
|
||||
# Factory method to create User objects
|
||||
# Factory method to create datastore objects
|
||||
def factory(element_xml)
|
||||
OpenNebula::Group.new(element_xml,@client)
|
||||
OpenNebula::Datastore.new(element_xml,@client)
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
|
190
src/oca/ruby/opennebula/marketplace.rb
Normal file
190
src/oca/ruby/opennebula/marketplace.rb
Normal file
@ -0,0 +1,190 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'opennebula/pool_element'
|
||||
|
||||
module OpenNebula
|
||||
class MarketPlace < PoolElement
|
||||
#######################################################################
|
||||
# Constants and Class Methods
|
||||
#######################################################################
|
||||
|
||||
MARKETPLACE_METHODS = {
|
||||
:info => "market.info",
|
||||
:allocate => "market.allocate",
|
||||
:delete => "market.delete",
|
||||
:update => "market.update",
|
||||
:chown => "market.chown",
|
||||
:chmod => "market.chmod",
|
||||
:rename => "market.rename"
|
||||
}
|
||||
|
||||
MARKETPLACE_TYPES=%w{UNKNOWN IMAGE_MP VMTEMPLATE_MP FLOW_MP}
|
||||
|
||||
SHORT_MARKETPLACE_TYPES = {
|
||||
"UNKNOWN" => "unk",
|
||||
"IMAGE_MP" => "img",
|
||||
"VMTEMPLATE_MP"=> "tpl",
|
||||
"FLOW_MP" => "flo"
|
||||
}
|
||||
|
||||
# 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)
|
||||
#
|
||||
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
|
||||
|
||||
# Class constructor
|
||||
def initialize(xml, client)
|
||||
super(xml,client)
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
# XML-RPC Methods for the MarketPlace Object
|
||||
#######################################################################
|
||||
|
||||
# Retrieves the information of the given MarketPlace.
|
||||
def info()
|
||||
super(MARKETPLACE_METHODS[:info], 'MARKETPLACE')
|
||||
end
|
||||
|
||||
alias_method :info!, :info
|
||||
|
||||
# Allocates a new MarketPlace in OpenNebula
|
||||
#
|
||||
# @param description [String] The template of the MarketPlace.
|
||||
#
|
||||
# @return [Integer, OpenNebula::Error] the new ID in case of
|
||||
# success, error otherwise
|
||||
def allocate(description)
|
||||
super(MARKETPLACE_METHODS[:allocate], description)
|
||||
end
|
||||
|
||||
# Deletes the MarketPlace
|
||||
def delete()
|
||||
super(MARKETPLACE_METHODS[:delete])
|
||||
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
|
||||
def update(new_template, append=false)
|
||||
super(MARKETPLACE_METHODS[:update], new_template, append ? 1 : 0)
|
||||
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
|
||||
def chown(uid, gid)
|
||||
super(MARKETPLACE_METHODS[:chown], uid, gid)
|
||||
end
|
||||
|
||||
# Changes the marketplace permissions.
|
||||
#
|
||||
# @param octet [String] Permissions octed , e.g. 640
|
||||
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
||||
# otherwise
|
||||
def chmod_octet(octet)
|
||||
super(MARKETPLACE_METHODS[:chmod], octet)
|
||||
end
|
||||
|
||||
# Changes the marketplace 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
|
||||
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
|
||||
|
||||
# Renames this marketplace
|
||||
#
|
||||
# @param name [String] New name for the marketplace
|
||||
#
|
||||
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
||||
# otherwise
|
||||
def rename(name)
|
||||
return call(MARKETPLACE_METHODS[:rename], @pe_id, name)
|
||||
end
|
||||
|
||||
# ---------------------------------------------------------------------
|
||||
# Helpers to get information
|
||||
# ---------------------------------------------------------------------
|
||||
|
||||
# Returns the marketplace type
|
||||
def type
|
||||
self['TYPE'].to_i
|
||||
end
|
||||
|
||||
# Returns the marketplace type (string value)
|
||||
def type_str
|
||||
MARKETPLACE_TYPES[type]
|
||||
end
|
||||
|
||||
# Returns the marketplace type (string value)
|
||||
def short_type_str
|
||||
SHORT_MARKETPLACE_TYPES[type_str]
|
||||
end
|
||||
|
||||
# Returns the state of the marketplace (numeric value)
|
||||
def state
|
||||
self['STATE'].to_i
|
||||
end
|
||||
|
||||
# Returns whether or not the marketplace app with id 'id' is part of
|
||||
# this marketplace
|
||||
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
|
||||
|
||||
# Returns an array with the numeric image ids
|
||||
def marketapp_ids
|
||||
array = Array.new
|
||||
|
||||
self.each("MARKETPLACEAPPS/ID") do |id|
|
||||
array << id.text.to_i
|
||||
end
|
||||
|
||||
return array
|
||||
end
|
||||
end
|
||||
end
|
55
src/oca/ruby/opennebula/marketplace_pool.rb
Normal file
55
src/oca/ruby/opennebula/marketplace_pool.rb
Normal file
@ -0,0 +1,55 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
|
||||
require 'opennebula/pool'
|
||||
|
||||
module OpenNebula
|
||||
class MarketPlacePool < Pool
|
||||
#######################################################################
|
||||
# Constants and Class attribute accessors
|
||||
#######################################################################
|
||||
|
||||
MARKETPLACE_POOL_METHODS = {
|
||||
:info => "marketpool.info"
|
||||
}
|
||||
|
||||
#######################################################################
|
||||
# Class constructor & Pool Methods
|
||||
#######################################################################
|
||||
|
||||
# +client+ a Client object that represents a XML-RPC connection
|
||||
def initialize(client)
|
||||
super('MARKETPLACE_POOL','MARKETPLACE', client)
|
||||
end
|
||||
|
||||
# Factory method to create MarketPlace objects
|
||||
def factory(element_xml)
|
||||
OpenNebula::MarketPlace.new(element_xml, @client)
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
# XML-RPC Methods for the User Object
|
||||
#######################################################################
|
||||
|
||||
# Retrieves all the marketplace apps
|
||||
def info()
|
||||
super(MARKETPLACE_POOL_METHODS[:info])
|
||||
end
|
||||
|
||||
alias_method :info!, :info
|
||||
end
|
||||
end
|
@ -624,8 +624,8 @@ string Request::object_name(PoolObjectSQL::ObjectType ob)
|
||||
return "VDC";
|
||||
case PoolObjectSQL::VROUTER:
|
||||
return "virtual router";
|
||||
default:
|
||||
return "-";
|
||||
case PoolObjectSQL::MARKETPLACE:
|
||||
return "marketplace";
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -903,6 +903,51 @@ void RequestManager::register_xml_methods()
|
||||
|
||||
RequestManagerRegistry.addMethod("one.vrouterpool.info",vrouter_pool_info);
|
||||
|
||||
/* MarketPlace related methods */
|
||||
|
||||
xmlrpc_c::method * market_allocate_pt;
|
||||
xmlrpc_c::method * market_update_pt;
|
||||
xmlrpc_c::method * market_delete_pt;
|
||||
xmlrpc_c::method * market_chmod_pt;
|
||||
xmlrpc_c::method * market_chown_pt;
|
||||
|
||||
if (nebula.is_federation_slave())
|
||||
{
|
||||
market_allocate_pt = new RequestManagerProxy("one.market.allocate");
|
||||
market_update_pt = new RequestManagerProxy("one.market.update");
|
||||
market_delete_pt = new RequestManagerProxy("one.market.delete");
|
||||
market_chmod_pt = new RequestManagerProxy("one.market.chmod");
|
||||
market_chown_pt = new RequestManagerProxy("one.market.chown");
|
||||
}
|
||||
else
|
||||
{
|
||||
market_allocate_pt = new MarketPlaceAllocate();
|
||||
market_update_pt = new MarketPlaceUpdateTemplate();
|
||||
market_delete_pt = new MarketPlaceDelete();
|
||||
market_chmod_pt = new MarketPlaceChmod();
|
||||
market_chown_pt = new MarketPlaceChown();
|
||||
}
|
||||
|
||||
xmlrpc_c::methodPtr market_allocate(market_allocate_pt);
|
||||
xmlrpc_c::methodPtr market_update(market_update_pt);
|
||||
xmlrpc_c::methodPtr market_delete(market_delete_pt);
|
||||
xmlrpc_c::methodPtr market_chmod(market_chmod_pt);
|
||||
xmlrpc_c::methodPtr market_chown(market_chown_pt);
|
||||
|
||||
xmlrpc_c::methodPtr market_info(new MarketPlaceInfo());
|
||||
xmlrpc_c::methodPtr market_rename(new MarketPlaceRename());
|
||||
xmlrpc_c::methodPtr marketpool_info(new MarketPlacePoolInfo());
|
||||
|
||||
RequestManagerRegistry.addMethod("one.market.allocate", market_allocate);
|
||||
RequestManagerRegistry.addMethod("one.market.update", market_update);
|
||||
RequestManagerRegistry.addMethod("one.market.delete", market_delete);
|
||||
RequestManagerRegistry.addMethod("one.market.chmod", market_chmod);
|
||||
RequestManagerRegistry.addMethod("one.market.chown", market_chown);
|
||||
|
||||
RequestManagerRegistry.addMethod("one.market.info", market_info);
|
||||
RequestManagerRegistry.addMethod("one.market.rename", market_rename);
|
||||
|
||||
RequestManagerRegistry.addMethod("one.marketpool.info", marketpool_info);
|
||||
|
||||
/* System related methods */
|
||||
RequestManagerRegistry.addMethod("one.system.version", system_version);
|
||||
|
@ -792,3 +792,21 @@ int VirtualRouterAllocate::pool_allocate(
|
||||
return vrpool->allocate(att.uid, att.gid, att.uname, att.gname, att.umask,
|
||||
tmpl, &id, error_str);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int MarketPlaceAllocate::pool_allocate(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
Template * tmpl,
|
||||
int& id,
|
||||
string& error_str,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
MarketPlacePool * mppool = static_cast<MarketPlacePool *>(pool);
|
||||
MarketPlaceTemplate * ttmpl = static_cast<MarketPlaceTemplate *>(tmpl);
|
||||
|
||||
return mppool->allocate(att.uid, att.gid, att.uname, att.gname, att.umask,
|
||||
ttmpl, &id, error_str);
|
||||
}
|
||||
|
||||
|
@ -551,3 +551,14 @@ void VdcPoolInfo::request_execute(
|
||||
{
|
||||
dump(att, ALL, -1, -1, "", "");
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
void MarketPlacePoolInfo::request_execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
dump(att, ALL, -1, -1, "", "");
|
||||
}
|
||||
|
||||
|
72
src/sunstone/models/OpenNebulaJSON/MarketPlaceJSON.rb
Normal file
72
src/sunstone/models/OpenNebulaJSON/MarketPlaceJSON.rb
Normal file
@ -0,0 +1,72 @@
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'OpenNebulaJSON/JSONUtils'
|
||||
|
||||
module OpenNebulaJSON
|
||||
class MarketPlaceJSON < OpenNebula::MarketPlace
|
||||
include JSONUtils
|
||||
|
||||
def create(template_json)
|
||||
mp_hash = parse_json(template_json, 'marketplace')
|
||||
if OpenNebula.is_error?(mp_hash)
|
||||
return mp_hash
|
||||
end
|
||||
|
||||
if ds_hash['marketplace_raw']
|
||||
template = ds_hash['marketplace_raw']
|
||||
else
|
||||
template = template_to_str(ds_hash)
|
||||
end
|
||||
|
||||
self.allocate(template)
|
||||
end
|
||||
|
||||
def perform_action(template_json)
|
||||
action_hash = parse_json(template_json, 'action')
|
||||
if OpenNebula.is_error?(action_hash)
|
||||
return action_hash
|
||||
end
|
||||
|
||||
rc = case action_hash['perform']
|
||||
when "update" then self.update(action_hash['params'])
|
||||
when "chown" then self.chown(action_hash['params'])
|
||||
when "chmod" then self.chmod_octet(action_hash['params'])
|
||||
when "rename" then self.rename(action_hash['params'])
|
||||
else
|
||||
error_msg = "#{action_hash['perform']} action not " <<
|
||||
" available for this resource"
|
||||
OpenNebula::Error.new(error_msg)
|
||||
end
|
||||
end
|
||||
|
||||
def update(params=Hash.new)
|
||||
super(params['template_raw'])
|
||||
end
|
||||
|
||||
def chown(params=Hash.new)
|
||||
super(params['owner_id'].to_i,params['group_id'].to_i)
|
||||
end
|
||||
|
||||
def chmod_octet(params=Hash.new)
|
||||
super(params['octet'])
|
||||
end
|
||||
|
||||
def rename(params=Hash.new)
|
||||
super(params['name'])
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user