mirror of
https://github.com/OpenNebula/one.git
synced 2025-02-10 13:57:22 +03:00
Merge branch 'master' into feature-595
This commit is contained in:
commit
1d3b59652d
@ -57,7 +57,7 @@ main_env.Append(LIBPATH=[
|
||||
cwd+'/src/log',
|
||||
cwd+'/src/sql',
|
||||
cwd+'/src/host',
|
||||
cwd+'/src/cluster',
|
||||
cwd+'/src/group',
|
||||
cwd+'/src/mad',
|
||||
cwd+'/src/nebula',
|
||||
cwd+'/src/pool',
|
||||
@ -186,7 +186,7 @@ build_scripts=[
|
||||
'src/common/SConstruct',
|
||||
'src/template/SConstruct',
|
||||
'src/host/SConstruct',
|
||||
'src/cluster/SConstruct',
|
||||
'src/group/SConstruct',
|
||||
'src/mad/SConstruct',
|
||||
'src/nebula/SConstruct',
|
||||
'src/pool/SConstruct',
|
||||
@ -233,7 +233,7 @@ if testing=='yes':
|
||||
'src/authm/test/SConstruct',
|
||||
'src/common/test/SConstruct',
|
||||
'src/host/test/SConstruct',
|
||||
'src/cluster/test/SConstruct',
|
||||
'src/group/test/SConstruct',
|
||||
'src/image/test/SConstruct',
|
||||
'src/lcm/test/SConstruct',
|
||||
'src/pool/test/SConstruct',
|
||||
|
@ -281,7 +281,10 @@ public:
|
||||
USE, /** Authorization to use an object */
|
||||
MANAGE, /** Authorization to manage an object */
|
||||
INFO, /** Authorization to view an object */
|
||||
INSTANTIATE /** Authorization to instantiate a VM from a TEMPLATE */
|
||||
INFO_POOL, /** Authorization to view any object in the pool */
|
||||
INFO_POOL_MINE, /** Authorization to view user and/or group objects */
|
||||
INSTANTIATE, /** Authorization to instantiate a VM from a TEMPLATE */
|
||||
CHOWN /** Authorization to change ownership of an object */
|
||||
};
|
||||
|
||||
/**
|
||||
@ -294,8 +297,8 @@ public:
|
||||
NET,
|
||||
IMAGE,
|
||||
USER,
|
||||
CLUSTER,
|
||||
TEMPLATE
|
||||
TEMPLATE,
|
||||
GROUP
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -113,7 +113,7 @@ public:
|
||||
private:
|
||||
|
||||
/**
|
||||
* The default MAC prefix for the OpenNebula cluster
|
||||
* The default MAC prefix for the Leases
|
||||
*/
|
||||
unsigned int mac_prefix;
|
||||
|
||||
|
@ -14,49 +14,24 @@
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef CLUSTER_H_
|
||||
#define CLUSTER_H_
|
||||
#ifndef GROUP_H_
|
||||
#define GROUP_H_
|
||||
|
||||
#include "PoolSQL.h"
|
||||
#include "Host.h"
|
||||
#include "ObjectCollection.h"
|
||||
#include "User.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
* The Cluster class.
|
||||
* The Group class.
|
||||
*/
|
||||
class Cluster : public PoolObjectSQL
|
||||
class Group : public PoolObjectSQL, ObjectCollection
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Adds the host to this cluster
|
||||
* @param host The host to add
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
/*
|
||||
int add_host(Host * host)
|
||||
{
|
||||
return host->set_cluster(name);
|
||||
};
|
||||
*/
|
||||
|
||||
/**
|
||||
* Removes the host from this cluster
|
||||
* @param host The host to add
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
// May be needed in a future
|
||||
// int remove_host(Host * host);
|
||||
|
||||
/**
|
||||
* Function to write a Cluster on an output stream
|
||||
*/
|
||||
friend ostream& operator<<(ostream& os, Cluster& cluster);
|
||||
|
||||
/**
|
||||
* Function to print the Cluster object into a string in XML format
|
||||
* Function to print the Group object into a string in XML format
|
||||
* @param xml the resulting XML string
|
||||
* @return a reference to the generated string
|
||||
*/
|
||||
@ -70,21 +45,43 @@ public:
|
||||
*/
|
||||
int from_xml(const string &xml_str);
|
||||
|
||||
/**
|
||||
* Adds this user's ID to the set.
|
||||
* @param id of the user to be added to the group
|
||||
* @return 0 on success
|
||||
*/
|
||||
int add_user(int id)
|
||||
{
|
||||
return add_collection_id(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes this users's ID from the set.
|
||||
* @param id of the user to be deleted from the group
|
||||
* @return 0 on success
|
||||
*/
|
||||
int del_user(int id)
|
||||
{
|
||||
return del_collection_id(id);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Friends
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
friend class ClusterPool;
|
||||
friend class GroupPool;
|
||||
|
||||
// *************************************************************************
|
||||
// Constructor
|
||||
// *************************************************************************
|
||||
|
||||
Cluster(int id, const string& name);
|
||||
Group(int id, const string& name):
|
||||
PoolObjectSQL(id,name,-1,-1,table),
|
||||
ObjectCollection("USERS"){};
|
||||
|
||||
virtual ~Cluster();
|
||||
virtual ~Group(){};
|
||||
|
||||
// *************************************************************************
|
||||
// DataBase implementation (Private)
|
||||
@ -105,28 +102,43 @@ private:
|
||||
int insert_replace(SqlDB *db, bool replace);
|
||||
|
||||
/**
|
||||
* Bootstraps the database table(s) associated to the Cluster
|
||||
* Bootstraps the database table(s) associated to the Group
|
||||
*/
|
||||
static void bootstrap(SqlDB * db)
|
||||
{
|
||||
ostringstream oss_cluster(Cluster::db_bootstrap);
|
||||
ostringstream oss(Group::db_bootstrap);
|
||||
|
||||
db->exec(oss_cluster);
|
||||
db->exec(oss);
|
||||
};
|
||||
|
||||
/**
|
||||
* Writes the Cluster in the database.
|
||||
* Writes the Group in the database.
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
int insert(SqlDB *db, string& error_str);
|
||||
int insert(SqlDB *db, string& error_str)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = insert_replace(db, false);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
error_str = "Error inserting Group in DB.";
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes/updates the Cluster's data fields in the database.
|
||||
* Writes/updates the Group's data fields in the database.
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
int update(SqlDB *db);
|
||||
int update(SqlDB *db)
|
||||
{
|
||||
return insert_replace(db, true);
|
||||
}
|
||||
};
|
||||
|
||||
#endif /*CLUSTER_H_*/
|
||||
#endif /*GROUP_H_*/
|
@ -14,63 +14,73 @@
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef CLUSTER_POOL_H_
|
||||
#define CLUSTER_POOL_H_
|
||||
#ifndef GROUP_POOL_H_
|
||||
#define GROUP_POOL_H_
|
||||
|
||||
#include "Cluster.h"
|
||||
#include "Host.h"
|
||||
#include "Group.h"
|
||||
#include "SqlDB.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
* A cluster helper class. It is not a normal PoolSQL,
|
||||
* but a series of static methods related to clusters.
|
||||
*/
|
||||
class ClusterPool : public PoolSQL
|
||||
|
||||
class GroupPool : public PoolSQL
|
||||
{
|
||||
public:
|
||||
ClusterPool(SqlDB * db);
|
||||
GroupPool(SqlDB * db);
|
||||
|
||||
~ClusterPool(){};
|
||||
~GroupPool(){};
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Constants r DB management */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Removes the host from the given cluster setting the default one.
|
||||
* @param host The host to assign
|
||||
*
|
||||
* @return 0 on success
|
||||
* Default name for the oneadmin group
|
||||
*/
|
||||
int set_default_cluster(Host * host)
|
||||
{
|
||||
return host->set_cluster(ClusterPool::DEFAULT_CLUSTER_NAME);
|
||||
};
|
||||
static const string ONEADMIN_NAME;
|
||||
|
||||
/**
|
||||
* Cluster name for the default cluster
|
||||
* Identifier for the oneadmin group
|
||||
*/
|
||||
static const string DEFAULT_CLUSTER_NAME;
|
||||
static const int ONEADMIN_ID;
|
||||
|
||||
/**
|
||||
* Default name for the users group
|
||||
*/
|
||||
static const string USERS_NAME;
|
||||
|
||||
/**
|
||||
* Identifier for the user group
|
||||
*/
|
||||
static const int USERS_ID;
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Methods for DB management */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Allocates a new cluster in the pool
|
||||
* @param clid the id assigned to the cluster
|
||||
* @return the id assigned to the cluster or -1 in case of failure
|
||||
* Allocates a new group, writting it in the pool database. No memory is
|
||||
* allocated for the object.
|
||||
* @param name Group name
|
||||
* @param oid the id assigned to the Group
|
||||
* @param error_str Returns the error reason, if any
|
||||
*
|
||||
* @return the oid assigned to the object, -1 in case of failure
|
||||
*/
|
||||
int allocate(int * oid, string name, string& error_str);
|
||||
int allocate(string name,
|
||||
int * oid,
|
||||
string& error_str);
|
||||
|
||||
/**
|
||||
* Function to get a Cluster from the pool, if the object is not in memory
|
||||
* Function to get a group from the pool, if the object is not in memory
|
||||
* it is loaded from the DB
|
||||
* @param oid Cluster unique id
|
||||
* @param lock locks the Cluster mutex
|
||||
* @return a pointer to the Cluster, 0 if the Cluster could not be loaded
|
||||
* @param oid group unique id
|
||||
* @param lock locks the group mutex
|
||||
* @return a pointer to the group, 0 if the group could not be loaded
|
||||
*/
|
||||
Cluster * get(int oid, bool lock)
|
||||
Group * get(int oid, bool lock)
|
||||
{
|
||||
return static_cast<Cluster *>(PoolSQL::get(oid,lock));
|
||||
return static_cast<Group *>(PoolSQL::get(oid,lock));
|
||||
};
|
||||
|
||||
/**
|
||||
@ -81,38 +91,42 @@ public:
|
||||
*
|
||||
* @return a pointer to the object, 0 in case of failure
|
||||
*/
|
||||
Cluster * get(const string& name, bool lock)
|
||||
Group * get(const string& name, bool lock)
|
||||
{
|
||||
return static_cast<Cluster *>(PoolSQL::get(name,-1,lock));
|
||||
return static_cast<Group *>(PoolSQL::get(name,-1,lock));
|
||||
};
|
||||
|
||||
/** Update a particular Cluster
|
||||
* @param user pointer to Cluster
|
||||
/** Update a particular Group
|
||||
* @param user pointer to Group
|
||||
* @return 0 on success
|
||||
*/
|
||||
int update(Cluster * cluster)
|
||||
int update(Group * group)
|
||||
{
|
||||
return cluster->update(db);
|
||||
return group->update(db);
|
||||
};
|
||||
|
||||
/**
|
||||
* Drops the Cluster from the data base. The object mutex SHOULD be
|
||||
* Drops the Group from the data base. The object mutex SHOULD be
|
||||
* locked.
|
||||
* @param cluster a pointer to the object
|
||||
* @return 0 on success.
|
||||
* @param objsql a pointer to a Group object
|
||||
* @param error_msg Error reason, if any
|
||||
* @return 0 on success,
|
||||
* -1 DB error,
|
||||
* -2 object is a system group (ID < 100)
|
||||
* -3 Group's User IDs set is not empty
|
||||
*/
|
||||
int drop(Cluster * cluster);
|
||||
int drop(PoolObjectSQL * objsql, string& error_msg);
|
||||
|
||||
/**
|
||||
* Bootstraps the database table(s) associated to the Cluster pool
|
||||
* Bootstraps the database table(s) associated to the Group pool
|
||||
*/
|
||||
static void bootstrap(SqlDB * _db)
|
||||
{
|
||||
Cluster::bootstrap(_db);
|
||||
Group::bootstrap(_db);
|
||||
};
|
||||
|
||||
/**
|
||||
* Dumps the Cluster pool in XML format. A filter can be also added to the
|
||||
* Dumps the Group pool in XML format. A filter can be also added to the
|
||||
* query
|
||||
* @param oss the output stream to dump the pool contents
|
||||
* @param where filter for the objects, defaults to all
|
||||
@ -121,7 +135,7 @@ public:
|
||||
*/
|
||||
int dump(ostringstream& oss, const string& where)
|
||||
{
|
||||
return PoolSQL::dump(oss, "CLUSTER_POOL", Cluster::table, where);
|
||||
return PoolSQL::dump(oss, "GROUP_POOL", Group::table, where);
|
||||
};
|
||||
|
||||
private:
|
||||
@ -132,8 +146,8 @@ private:
|
||||
*/
|
||||
PoolObjectSQL * create()
|
||||
{
|
||||
return new Cluster(-1,"");
|
||||
return new Group(-1,"");
|
||||
};
|
||||
};
|
||||
|
||||
#endif /*CLUSTER_POOL_H_*/
|
||||
#endif /*GROUP_POOL_H_*/
|
@ -43,11 +43,6 @@ public:
|
||||
DISABLED = 4 /**< The host is disabled won't be monitored. */
|
||||
};
|
||||
|
||||
/**
|
||||
* Function to write a Host on an output stream
|
||||
*/
|
||||
friend ostream& operator<<(ostream& os, Host& h);
|
||||
|
||||
/**
|
||||
* Function to print the Host object into a string in XML format
|
||||
* @param xml the resulting XML string
|
||||
@ -171,16 +166,6 @@ public:
|
||||
return last_monitored;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the cluster for this host
|
||||
* @return time_t last monitored time
|
||||
*/
|
||||
int set_cluster(const string& cluster_name)
|
||||
{
|
||||
cluster = cluster_name;
|
||||
return 0;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Share functions
|
||||
// ------------------------------------------------------------------------
|
||||
@ -292,6 +277,14 @@ public:
|
||||
return host_share.test(cpu,mem,disk);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for host templates
|
||||
*/
|
||||
Template * get_new_template()
|
||||
{
|
||||
return new HostTemplate;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
@ -329,11 +322,6 @@ private:
|
||||
*/
|
||||
time_t last_monitored;
|
||||
|
||||
/**
|
||||
* Name of the cluster this host belongs to.
|
||||
*/
|
||||
string cluster;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Host Attributes
|
||||
// -------------------------------------------------------------------------
|
||||
@ -350,8 +338,7 @@ private:
|
||||
const string& hostname="",
|
||||
const string& im_mad_name="",
|
||||
const string& vmm_mad_name="",
|
||||
const string& tm_mad_name="",
|
||||
const string& cluster="");
|
||||
const string& tm_mad_name="");
|
||||
|
||||
virtual ~Host();
|
||||
|
||||
|
@ -139,6 +139,19 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
int drop(PoolObjectSQL * objsql, string& error_msg)
|
||||
{
|
||||
Host * host = static_cast<Host *>(objsql);
|
||||
|
||||
if ( host->get_share_running_vms() > 0 )
|
||||
{
|
||||
error_msg = "Can not remove a host with running VMs";
|
||||
return -1;
|
||||
}
|
||||
|
||||
return PoolSQL::drop(objsql, error_msg);
|
||||
};
|
||||
|
||||
/**
|
||||
* Dumps the HOST pool in XML format. A filter can be also added to the
|
||||
* query
|
||||
|
@ -52,11 +52,6 @@ public:
|
||||
ERROR = 5 /** < Error state the operation FAILED*/
|
||||
};
|
||||
|
||||
/**
|
||||
* Function to write an Image on an output stream
|
||||
*/
|
||||
friend ostream& operator<<(ostream& os, Image& i);
|
||||
|
||||
// *************************************************************************
|
||||
// Image Public Methods
|
||||
// *************************************************************************
|
||||
@ -76,15 +71,6 @@ public:
|
||||
*/
|
||||
int from_xml(const string &xml_str);
|
||||
|
||||
/**
|
||||
* Returns true if the image is public
|
||||
* @return true if the image is public
|
||||
*/
|
||||
bool isPublic()
|
||||
{
|
||||
return (public_img == 1);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns true if the image is persistent
|
||||
* @return true if the image is persistent
|
||||
@ -195,25 +181,25 @@ public:
|
||||
* @param pub true to publish the image
|
||||
* @return 0 on success
|
||||
*/
|
||||
bool publish(bool pub)
|
||||
int publish(bool pub)
|
||||
{
|
||||
bool success = false;
|
||||
int rc = -1;
|
||||
|
||||
if (pub == true)
|
||||
{
|
||||
if (!isPersistent())
|
||||
{
|
||||
public_img = 1;
|
||||
success = true;
|
||||
public_obj = 1;
|
||||
rc = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
public_img = 0;
|
||||
success = true;
|
||||
public_obj = 0;
|
||||
rc = 0;
|
||||
}
|
||||
|
||||
return success;
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -221,25 +207,25 @@ public:
|
||||
* @param persistent true to make an image persistent
|
||||
* @return 0 on success
|
||||
*/
|
||||
bool persistent(bool persis)
|
||||
int persistent(bool persis)
|
||||
{
|
||||
bool success = false;
|
||||
int rc = -1;
|
||||
|
||||
if (persis == true)
|
||||
{
|
||||
if (!isPublic() && running_vms == 0)
|
||||
{
|
||||
persistent_img = 1;
|
||||
success = true;
|
||||
rc = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
persistent_img = 0;
|
||||
success = true;
|
||||
rc = 0;
|
||||
}
|
||||
|
||||
return success;
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -259,6 +245,14 @@ public:
|
||||
*/
|
||||
int disk_attribute(VectorAttribute * disk, int* index, ImageType* img_type);
|
||||
|
||||
/**
|
||||
* Factory method for image templates
|
||||
*/
|
||||
Template * get_new_template()
|
||||
{
|
||||
return new ImageTemplate;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
@ -271,21 +265,11 @@ private:
|
||||
// Image Description
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Image owner's name
|
||||
*/
|
||||
string user_name;
|
||||
|
||||
/**
|
||||
* Type of the Image
|
||||
*/
|
||||
ImageType type;
|
||||
|
||||
/**
|
||||
* Public scope of the Image
|
||||
*/
|
||||
int public_img;
|
||||
|
||||
/**
|
||||
* Persistency of the Image
|
||||
*/
|
||||
@ -346,8 +330,8 @@ protected:
|
||||
// Constructor
|
||||
// *************************************************************************
|
||||
|
||||
Image(int uid,
|
||||
const string& user_name,
|
||||
Image(int uid,
|
||||
int gid,
|
||||
ImageTemplate* img_template);
|
||||
|
||||
virtual ~Image();
|
||||
|
@ -47,15 +47,17 @@ public:
|
||||
/**
|
||||
* Function to allocate a new Image object
|
||||
* @param uid the user id of the image's owner
|
||||
* @param stemplate template associated with the image
|
||||
* @param gid the id of the group this object is assigned to
|
||||
* @param img_template template associated with the image
|
||||
* @param oid the id assigned to the Image
|
||||
* @param error_str Returns the error reason, if any
|
||||
* @return the oid assigned to the object,
|
||||
* -1 in case of failure
|
||||
* -2 in case of template parse failure
|
||||
*/
|
||||
int allocate (
|
||||
int uid,
|
||||
string user_name,
|
||||
int gid,
|
||||
ImageTemplate * img_template,
|
||||
int * oid,
|
||||
string& error_str);
|
||||
@ -93,15 +95,6 @@ public:
|
||||
return image->update(db);
|
||||
};
|
||||
|
||||
/** Drops an image from the DB, the image mutex MUST BE locked
|
||||
* @param image pointer to Image
|
||||
* @return 0 on success
|
||||
*/
|
||||
int drop(Image * image)
|
||||
{
|
||||
return PoolSQL::drop(image);
|
||||
};
|
||||
|
||||
/**
|
||||
* Bootstraps the database table(s) associated to the Image pool
|
||||
*/
|
||||
@ -179,7 +172,7 @@ private:
|
||||
*/
|
||||
PoolObjectSQL * create()
|
||||
{
|
||||
return new Image(-1,"",0);
|
||||
return new Image(-1,-1,0);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "HostPool.h"
|
||||
#include "UserPool.h"
|
||||
#include "VMTemplatePool.h"
|
||||
#include "GroupPool.h"
|
||||
|
||||
#include "VirtualMachineManager.h"
|
||||
#include "LifeCycleManager.h"
|
||||
@ -79,9 +80,9 @@ public:
|
||||
return ipool;
|
||||
};
|
||||
|
||||
ClusterPool * get_cpool()
|
||||
GroupPool * get_gpool()
|
||||
{
|
||||
return cpool;
|
||||
return gpool;
|
||||
};
|
||||
|
||||
VMTemplatePool * get_tpool()
|
||||
@ -247,8 +248,8 @@ private:
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
Nebula():nebula_configuration(0),db(0),vmpool(0),hpool(0),vnpool(0),
|
||||
upool(0),ipool(0),cpool(0),tpool(0),lcm(0),vmm(0),im(0),tm(0),dm(0),
|
||||
rm(0),hm(0),authm(0),imagem(0)
|
||||
upool(0),ipool(0),gpool(0),tpool(0),lcm(0),vmm(0),im(0),tm(0),
|
||||
dm(0),rm(0),hm(0),authm(0),imagem(0)
|
||||
{
|
||||
const char * nl = getenv("ONE_LOCATION");
|
||||
|
||||
@ -308,9 +309,9 @@ private:
|
||||
delete ipool;
|
||||
}
|
||||
|
||||
if ( cpool != 0)
|
||||
if ( gpool != 0)
|
||||
{
|
||||
delete cpool;
|
||||
delete gpool;
|
||||
}
|
||||
|
||||
if ( tpool != 0)
|
||||
@ -409,7 +410,7 @@ private:
|
||||
VirtualNetworkPool * vnpool;
|
||||
UserPool * upool;
|
||||
ImagePool * ipool;
|
||||
ClusterPool * cpool;
|
||||
GroupPool * gpool;
|
||||
VMTemplatePool * tpool;
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
|
102
include/ObjectCollection.h
Normal file
102
include/ObjectCollection.h
Normal file
@ -0,0 +1,102 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef OBJECT_COLLECTION_H_
|
||||
#define OBJECT_COLLECTION_H_
|
||||
|
||||
#include <set>
|
||||
|
||||
#include "PoolObjectSQL.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
* Class to store a set of PoolObjectSQL IDs.
|
||||
*/
|
||||
class ObjectCollection
|
||||
{
|
||||
protected:
|
||||
|
||||
ObjectCollection(const string& _collection_name)
|
||||
:collection_name(_collection_name){};
|
||||
|
||||
~ObjectCollection(){};
|
||||
|
||||
/**
|
||||
* Adds an ID to the set.
|
||||
* @param id The new id
|
||||
*
|
||||
* @return 0 on success, -1 if the ID was already in the set
|
||||
*/
|
||||
int add_collection_id(int id);
|
||||
|
||||
/**
|
||||
* Deletes an ID from the set.
|
||||
* @param id The id
|
||||
*
|
||||
* @return 0 on success, -1 if the ID was not in the set
|
||||
*/
|
||||
int del_collection_id(int id);
|
||||
|
||||
/**
|
||||
* Returns how many IDs are there in the set.
|
||||
* @return how many IDs are there in the set.
|
||||
*/
|
||||
int get_collection_size()
|
||||
{
|
||||
return collection_set.size();
|
||||
};
|
||||
|
||||
/**
|
||||
* Rebuilds the object from an xml node
|
||||
* @param node The xml node pointer
|
||||
*
|
||||
* @return 0 on success, -1 otherwise
|
||||
*/
|
||||
int from_xml_node(const xmlNodePtr node);
|
||||
|
||||
/**
|
||||
* Function to print the Collection object into a string in
|
||||
* XML format
|
||||
* @param xml the resulting XML string
|
||||
* @return a reference to the generated string
|
||||
*/
|
||||
string& to_xml(string& xml) const;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a copy of the IDs set
|
||||
*/
|
||||
set<int> get_collection_copy()
|
||||
{
|
||||
return set<int> (collection_set);
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* The collection's name
|
||||
*/
|
||||
string collection_name;
|
||||
|
||||
/**
|
||||
* Set containing the relations IDs
|
||||
*/
|
||||
set<int> collection_set;
|
||||
|
||||
};
|
||||
|
||||
#endif /*OBJECT_COLLECTION_H_*/
|
@ -37,9 +37,10 @@ class PoolObjectSQL : public ObjectSQL, public ObjectXML
|
||||
{
|
||||
public:
|
||||
|
||||
PoolObjectSQL(int id, const string& _name, int _uid,const char *_table)
|
||||
:ObjectSQL(),ObjectXML(),oid(id),name(_name),uid(_uid),
|
||||
valid(true),obj_template(0),table(_table)
|
||||
PoolObjectSQL(int id, const string& _name, int _uid,
|
||||
int _gid, const char *_table)
|
||||
:ObjectSQL(),ObjectXML(),oid(id),name(_name),uid(_uid),gid(_gid),
|
||||
valid(true),public_obj(0),obj_template(0),table(_table)
|
||||
{
|
||||
pthread_mutex_init(&mutex,0);
|
||||
};
|
||||
@ -63,11 +64,43 @@ public:
|
||||
return name;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns true if the image is public
|
||||
* @return true if the image is public
|
||||
*/
|
||||
bool isPublic()
|
||||
{
|
||||
return (public_obj == 1);
|
||||
};
|
||||
|
||||
int get_uid()
|
||||
{
|
||||
return uid;
|
||||
};
|
||||
|
||||
int get_gid()
|
||||
{
|
||||
return gid;
|
||||
};
|
||||
|
||||
/**
|
||||
* Changes the object's owner id
|
||||
* @param _uid New User ID
|
||||
*/
|
||||
void set_uid(int _uid)
|
||||
{
|
||||
uid = _uid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the object's group id
|
||||
* @param _gid New Group ID
|
||||
*/
|
||||
void set_gid(int _gid)
|
||||
{
|
||||
gid = _gid;
|
||||
};
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
@ -231,6 +264,23 @@ public:
|
||||
*/
|
||||
void set_template_error_message(const string& message);
|
||||
|
||||
/**
|
||||
* Factory method for templates, it should be implemented
|
||||
* by classes that uses templates
|
||||
* @return a new template
|
||||
*/
|
||||
virtual Template * get_new_template()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace template for this object. Object should be updated
|
||||
* after calling this method
|
||||
* @param tmpl string representation of the template
|
||||
*/
|
||||
int replace_template(const string& tmpl_str, string& error);
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
@ -305,11 +355,21 @@ protected:
|
||||
*/
|
||||
int uid;
|
||||
|
||||
/**
|
||||
* Object's group, set it to -1 if group is not used
|
||||
*/
|
||||
int gid;
|
||||
|
||||
/**
|
||||
* The contents of this object are valid
|
||||
*/
|
||||
bool valid;
|
||||
|
||||
/**
|
||||
* Set if the object is public
|
||||
*/
|
||||
int public_obj;
|
||||
|
||||
/**
|
||||
* Template for this object, will be allocated if needed
|
||||
*/
|
||||
|
@ -121,12 +121,20 @@ public:
|
||||
* Drops the object's data in the data base. The object mutex SHOULD be
|
||||
* locked.
|
||||
* @param objsql a pointer to the object
|
||||
* @return 0 on success.
|
||||
* @param error_msg Error reason, if any
|
||||
* @return 0 on success, -1 DB error
|
||||
*/
|
||||
virtual int drop(
|
||||
PoolObjectSQL * objsql)
|
||||
virtual int drop(PoolObjectSQL * objsql, string& error_msg)
|
||||
{
|
||||
return objsql->drop(db);
|
||||
int rc = objsql->drop(db);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
error_msg = "SQL DB error";
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -164,41 +172,57 @@ protected:
|
||||
int dump(ostringstream& oss, const string& elem_name,
|
||||
const char * table, const string& where);
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Interface to access the lastOID assigned by the pool */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Returns the value of the last identifier assigned by the pool
|
||||
* Gets the value of the last identifier assigned by the pool
|
||||
* @return the lastOID of the pool
|
||||
*/
|
||||
int get_lastOID()
|
||||
{
|
||||
return lastOID;
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the lastOID of the pool and updates the control database
|
||||
* @param _lastOID for the pool
|
||||
*/
|
||||
void set_update_lastOID(int _lastOID)
|
||||
{
|
||||
lastOID = _lastOID;
|
||||
|
||||
update_lastOID();
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
pthread_mutex_t mutex;
|
||||
pthread_mutex_t mutex;
|
||||
|
||||
/**
|
||||
* Max size for the pool, to control the memory footprint of the pool. This
|
||||
* number MUST be greater than the max. number of objects that are
|
||||
* accessed simultaneously.
|
||||
*/
|
||||
static const unsigned int MAX_POOL_SIZE;
|
||||
static const unsigned int MAX_POOL_SIZE;
|
||||
|
||||
/**
|
||||
* Last object ID assigned to an object. It must be initialized by the
|
||||
* target pool.
|
||||
*/
|
||||
int lastOID;
|
||||
int lastOID;
|
||||
|
||||
/**
|
||||
* Tablename for this pool
|
||||
*/
|
||||
string table;
|
||||
string table;
|
||||
|
||||
/**
|
||||
* The pool is implemented with a Map of SQL object pointers, using the
|
||||
* OID as key.
|
||||
*/
|
||||
map<int,PoolObjectSQL *> pool;
|
||||
map<int,PoolObjectSQL *> pool;
|
||||
|
||||
/**
|
||||
* This is a name index for the pool map. The key is the name of the object
|
||||
@ -216,7 +240,7 @@ private:
|
||||
* OID queue to implement a FIFO-like replacement policy for the pool
|
||||
* cache.
|
||||
*/
|
||||
queue<int> oid_queue;
|
||||
queue<int> oid_queue;
|
||||
|
||||
/**
|
||||
* Function to lock the pool
|
||||
|
@ -106,7 +106,7 @@ public:
|
||||
|
||||
private:
|
||||
/**
|
||||
* The default MAC prefix for the OpenNebula cluster
|
||||
* The default MAC prefix for the Leases
|
||||
*/
|
||||
unsigned int mac_prefix;
|
||||
|
||||
|
205
include/Request.h
Normal file
205
include/Request.h
Normal file
@ -0,0 +1,205 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef REQUEST_H_
|
||||
#define REQUEST_H_
|
||||
|
||||
#include <xmlrpc-c/base.hpp>
|
||||
#include <xmlrpc-c/registry.hpp>
|
||||
|
||||
#include "RequestManager.h"
|
||||
#include "AuthManager.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
* The Request Class represents the basic abstraction for the OpenNebula
|
||||
* XML-RPC API. This interface must be implemented by any XML-RPC API call
|
||||
*/
|
||||
class Request: public xmlrpc_c::method
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Wraps the actual execution function by authorizing the user
|
||||
* and calling the request_execute virtual function
|
||||
* @param _paramlist list of XML parameters
|
||||
* @param _retval value to be returned to the client
|
||||
*/
|
||||
virtual void execute(
|
||||
xmlrpc_c::paramList const& _paramList,
|
||||
xmlrpc_c::value * const _retval);
|
||||
|
||||
/**
|
||||
* Error codes for the XML-RPC API
|
||||
*/
|
||||
enum ErrorCode {
|
||||
SUCCESS = 0x0000,
|
||||
AUTHENTICATION = 0x0100,
|
||||
AUTHORIZATION = 0x0200,
|
||||
NO_EXISTS = 0x0400,
|
||||
ACTION = 0x0800,
|
||||
XML_RPC_API = 0x1000,
|
||||
INTERNAL = 0x2000,
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
/* ------------------- Attributes of the Request ---------------------- */
|
||||
|
||||
int uid; /**< id of the user performing the request */
|
||||
|
||||
int gid; /**< id of the user's group */
|
||||
|
||||
PoolSQL * pool; /**< Pool of objects */
|
||||
|
||||
string method_name; /**< The name of the XML-RPC method */
|
||||
|
||||
AuthRequest::Object auth_object; /**< Auth object for the request */
|
||||
|
||||
AuthRequest::Operation auth_op; /**< Auth operation for the request */
|
||||
|
||||
|
||||
/* -------------------- Constructors ---------------------------------- */
|
||||
|
||||
Request(const string& mn,
|
||||
const string& signature,
|
||||
const string& help): uid(-1),gid(-1),pool(0),method_name(mn),retval(0)
|
||||
{
|
||||
_signature = signature;
|
||||
_help = help;
|
||||
};
|
||||
|
||||
virtual ~Request(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Performs a basic autorization for this request using the uid/gid
|
||||
* from the request. The function gets the object from the pool to get
|
||||
* the public attribute and its owner. The authorization is based on
|
||||
* object and type of operation for the request.
|
||||
* @param oid of the object.
|
||||
*
|
||||
* @return true if the user is authorized.
|
||||
*/
|
||||
bool basic_authorization(int oid);
|
||||
|
||||
/**
|
||||
* Actual Execution method for the request. Must be implemented by the
|
||||
* XML-RPC requests
|
||||
* @param _paramlist of the XML-RPC call (complete list)
|
||||
*/
|
||||
virtual void request_execute(xmlrpc_c::paramList const& _paramList) = 0;
|
||||
|
||||
/**
|
||||
* Builds an XML-RPC response updating retval. After calling this function
|
||||
* the xml-rpc excute method should return
|
||||
* @param val to be returned to the client
|
||||
*/
|
||||
void success_response(int val);
|
||||
|
||||
/**
|
||||
* Builds an XML-RPC response updating retval. After calling this function
|
||||
* the xml-rpc excute method should return
|
||||
* @param val string to be returned to the client
|
||||
*/
|
||||
void success_response(const string& val);
|
||||
|
||||
/**
|
||||
* Builds an XML-RPC response updating retval. After calling this function
|
||||
* the xml-rpc excute method should return
|
||||
* @param ec error code for this call
|
||||
* @param val string representation of the error
|
||||
*/
|
||||
void failure_response(ErrorCode ec, const string& val);
|
||||
|
||||
/**
|
||||
* Gets a string representation for the Auth object in the
|
||||
* request.
|
||||
* @param ob object for the auth operation
|
||||
* @return string equivalent of the object
|
||||
*/
|
||||
static string object_name(AuthRequest::Object ob);
|
||||
|
||||
/**
|
||||
* Logs authorization errors
|
||||
* @param message with the authorization error details
|
||||
* @return string for logging
|
||||
*/
|
||||
string authorization_error (const string &message);
|
||||
/**
|
||||
* Logs authenticate errors
|
||||
* @return string for logging
|
||||
*/
|
||||
string authenticate_error ();
|
||||
|
||||
/**
|
||||
* Logs get object errors
|
||||
* @param object over which the get failed
|
||||
* @param id of the object over which the get failed
|
||||
* @return string for logging
|
||||
*/
|
||||
string get_error (const string &object, int id);
|
||||
|
||||
/**
|
||||
* Logs action errors
|
||||
* @param err_desc brief description of the error
|
||||
* @param err_detail additional error details from Managers & Pools
|
||||
* @return string for logging
|
||||
*/
|
||||
string request_error (const string &err_desc, const string &err_detail);
|
||||
|
||||
/**
|
||||
* Logs allocate errors
|
||||
* @param message with the allocate error details
|
||||
* @return string for logging
|
||||
*/
|
||||
string allocate_error (const string& error);
|
||||
|
||||
/**
|
||||
* Logs allocate errors for a given resource
|
||||
* @param obj the resource
|
||||
* @param message with the allocate error details
|
||||
* @return string for logging
|
||||
*/
|
||||
string allocate_error (AuthRequest::Object obj, const string& error);
|
||||
|
||||
/**
|
||||
* Logs allocate errors
|
||||
* @param message with the allocate error details (parsing)
|
||||
* @return string for logging
|
||||
*/
|
||||
string allocate_error (char *error);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Session token from the OpenNebula XML-RPC API
|
||||
*/
|
||||
string session;
|
||||
|
||||
/**
|
||||
* Return value of the request from libxmlrpc-c
|
||||
*/
|
||||
xmlrpc_c::value * retval;
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif //REQUEST_H_
|
||||
|
File diff suppressed because it is too large
Load Diff
275
include/RequestManagerAllocate.h
Normal file
275
include/RequestManagerAllocate.h
Normal file
@ -0,0 +1,275 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef REQUEST_MANAGER_ALLOCATE_H_
|
||||
#define REQUEST_MANAGER_ALLOCATE_H_
|
||||
|
||||
#include "Request.h"
|
||||
#include "Nebula.h"
|
||||
|
||||
#include "VirtualNetworkTemplate.h"
|
||||
#include "ImageTemplate.h"
|
||||
#include "VirtualMachineTemplate.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class RequestManagerAllocate: public Request
|
||||
{
|
||||
protected:
|
||||
RequestManagerAllocate(const string& method_name,
|
||||
const string& help,
|
||||
const string& xml_args,
|
||||
bool dt)
|
||||
:Request(method_name,xml_args,help), do_template(dt)
|
||||
{
|
||||
auth_op = AuthRequest::CREATE;
|
||||
};
|
||||
|
||||
~RequestManagerAllocate(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList);
|
||||
|
||||
virtual bool allocate_authorization(Template * obj_template);
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
virtual Template * get_object_template() { return 0; };
|
||||
|
||||
virtual int pool_allocate(xmlrpc_c::paramList const& _paramList,
|
||||
Template * tmpl,
|
||||
int& id,
|
||||
string& error_str) = 0;
|
||||
private:
|
||||
|
||||
bool do_template;
|
||||
};
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class VirtualMachineAllocate: public RequestManagerAllocate
|
||||
{
|
||||
public:
|
||||
VirtualMachineAllocate():
|
||||
RequestManagerAllocate("VirtualMachineAllocate",
|
||||
"Allocates a new virtual machine",
|
||||
"A:ss",
|
||||
true)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_vmpool();
|
||||
auth_object = AuthRequest::VM;
|
||||
};
|
||||
|
||||
~VirtualMachineAllocate(){};
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
Template * get_object_template()
|
||||
{
|
||||
return new VirtualMachineTemplate;
|
||||
};
|
||||
|
||||
int pool_allocate(xmlrpc_c::paramList const& _paramList,
|
||||
Template * tmpl,
|
||||
int& id,
|
||||
string& error_str);
|
||||
|
||||
bool allocate_authorization(Template * obj_template);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class VirtualNetworkAllocate: public RequestManagerAllocate
|
||||
{
|
||||
public:
|
||||
VirtualNetworkAllocate():
|
||||
RequestManagerAllocate("VirtualNetworkInfo",
|
||||
"Allocates a new virtual network",
|
||||
"A:ss",
|
||||
true)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_vnpool();
|
||||
auth_object = AuthRequest::NET;
|
||||
};
|
||||
|
||||
~VirtualNetworkAllocate(){};
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
Template * get_object_template()
|
||||
{
|
||||
return new VirtualNetworkTemplate;
|
||||
};
|
||||
|
||||
int pool_allocate(xmlrpc_c::paramList const& _paramList,
|
||||
Template * tmpl,
|
||||
int& id,
|
||||
string& error_str);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class ImageAllocate: public RequestManagerAllocate
|
||||
{
|
||||
public:
|
||||
ImageAllocate():
|
||||
RequestManagerAllocate("ImageAllocate",
|
||||
"Allocates a new image",
|
||||
"A:ss",
|
||||
true)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_ipool();
|
||||
auth_object = AuthRequest::IMAGE;
|
||||
};
|
||||
|
||||
~ImageAllocate(){};
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
Template * get_object_template()
|
||||
{
|
||||
return new ImageTemplate;
|
||||
};
|
||||
|
||||
int pool_allocate(xmlrpc_c::paramList const& _paramList,
|
||||
Template * tmpl,
|
||||
int& id,
|
||||
string& error_str);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class TemplateAllocate : public RequestManagerAllocate
|
||||
{
|
||||
public:
|
||||
TemplateAllocate():
|
||||
RequestManagerAllocate("TemplateAllocate",
|
||||
"Allocates a new virtual machine template",
|
||||
"A:ss",
|
||||
true)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_tpool();
|
||||
auth_object = AuthRequest::TEMPLATE;
|
||||
};
|
||||
|
||||
~TemplateAllocate(){};
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
Template * get_object_template()
|
||||
{
|
||||
return new VirtualMachineTemplate;
|
||||
};
|
||||
|
||||
int pool_allocate(xmlrpc_c::paramList const& _paramList,
|
||||
Template * tmpl,
|
||||
int& id,
|
||||
string& error_str);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class HostAllocate : public RequestManagerAllocate
|
||||
{
|
||||
public:
|
||||
HostAllocate():
|
||||
RequestManagerAllocate("HostInfo",
|
||||
"Allocates a new host",
|
||||
"A:sssss",
|
||||
false)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_hpool();
|
||||
auth_object = AuthRequest::HOST;
|
||||
};
|
||||
|
||||
~HostAllocate(){};
|
||||
|
||||
int pool_allocate(xmlrpc_c::paramList const& _paramList,
|
||||
Template * tmpl,
|
||||
int& id,
|
||||
string& error_str);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class UserAllocate: public RequestManagerAllocate
|
||||
{
|
||||
public:
|
||||
UserAllocate():
|
||||
RequestManagerAllocate("UserInfo",
|
||||
"Returns user information",
|
||||
"A:sss",
|
||||
false)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_upool();
|
||||
auth_object = AuthRequest::USER;
|
||||
};
|
||||
|
||||
~UserAllocate(){};
|
||||
|
||||
int pool_allocate(xmlrpc_c::paramList const& _paramList,
|
||||
Template * tmpl,
|
||||
int& id,
|
||||
string& error_str);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class GroupAllocate: public RequestManagerAllocate
|
||||
{
|
||||
public:
|
||||
GroupAllocate():
|
||||
RequestManagerAllocate("GroupAllocate",
|
||||
"Allocates a new group",
|
||||
"A:ss",
|
||||
false)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_gpool();
|
||||
auth_object = AuthRequest::GROUP;
|
||||
};
|
||||
|
||||
~GroupAllocate(){};
|
||||
|
||||
int pool_allocate(xmlrpc_c::paramList const& _paramList,
|
||||
Template * tmpl,
|
||||
int& id,
|
||||
string& error_str);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif
|
149
include/RequestManagerChown.h
Normal file
149
include/RequestManagerChown.h
Normal file
@ -0,0 +1,149 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef REQUEST_MANAGER_CHOWN_H_
|
||||
#define REQUEST_MANAGER_CHOWN_H_
|
||||
|
||||
#include "Request.h"
|
||||
#include "Nebula.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class RequestManagerChown : public Request
|
||||
{
|
||||
protected:
|
||||
RequestManagerChown(const string& method_name,
|
||||
const string& help,
|
||||
const string& params = "A:siii")
|
||||
:Request(method_name,params,help)
|
||||
{
|
||||
auth_op = AuthRequest::CHOWN;
|
||||
};
|
||||
|
||||
~RequestManagerChown(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
virtual void request_execute(xmlrpc_c::paramList const& _paramList);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class VirtualMachineChown : public RequestManagerChown
|
||||
{
|
||||
public:
|
||||
VirtualMachineChown():
|
||||
RequestManagerChown("VirtualMachineChown",
|
||||
"Changes ownership of a virtual machine")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_vmpool();
|
||||
auth_object = AuthRequest::VM;
|
||||
};
|
||||
|
||||
~VirtualMachineChown(){};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class TemplateChown : public RequestManagerChown
|
||||
{
|
||||
public:
|
||||
TemplateChown():
|
||||
RequestManagerChown("TemplateChown",
|
||||
"Changes ownership of a virtual machine template")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_tpool();
|
||||
auth_object = AuthRequest::TEMPLATE;
|
||||
};
|
||||
|
||||
~TemplateChown(){};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
class VirtualNetworkChown: public RequestManagerChown
|
||||
{
|
||||
public:
|
||||
VirtualNetworkChown():
|
||||
RequestManagerChown("VirtualNetworkChown",
|
||||
"Changes ownership of a virtual network")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_vnpool();
|
||||
auth_object = AuthRequest::NET;
|
||||
};
|
||||
|
||||
~VirtualNetworkChown(){};
|
||||
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class ImageChown: public RequestManagerChown
|
||||
{
|
||||
public:
|
||||
ImageChown():
|
||||
RequestManagerChown("ImageChown",
|
||||
"Changes ownership of an image")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_ipool();
|
||||
auth_object = AuthRequest::IMAGE;
|
||||
};
|
||||
|
||||
~ImageChown(){};
|
||||
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class UserChown : public RequestManagerChown
|
||||
{
|
||||
public:
|
||||
UserChown():
|
||||
RequestManagerChown("UserChown",
|
||||
"Changes ownership of a user",
|
||||
"A:sii")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_upool();
|
||||
auth_object = AuthRequest::USER;
|
||||
};
|
||||
|
||||
~UserChown(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
virtual void request_execute(xmlrpc_c::paramList const& _paramList);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif
|
178
include/RequestManagerDelete.h
Normal file
178
include/RequestManagerDelete.h
Normal file
@ -0,0 +1,178 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef REQUEST_MANAGER_DELETE_H_
|
||||
#define REQUEST_MANAGER_DELETE_H_
|
||||
|
||||
#include "Request.h"
|
||||
#include "Nebula.h"
|
||||
#include "AuthManager.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class RequestManagerDelete: public Request
|
||||
{
|
||||
protected:
|
||||
RequestManagerDelete(const string& method_name,
|
||||
const string& help)
|
||||
:Request(method_name,"A:si",help)
|
||||
{
|
||||
auth_op = AuthRequest::DELETE;
|
||||
}
|
||||
|
||||
~RequestManagerDelete(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList);
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
virtual int drop(int oid, PoolObjectSQL * object, string& error_msg)
|
||||
{
|
||||
int rc = pool->drop(object, error_msg);
|
||||
|
||||
object->unlock();
|
||||
|
||||
return rc;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class TemplateDelete : public RequestManagerDelete
|
||||
{
|
||||
public:
|
||||
TemplateDelete():
|
||||
RequestManagerDelete("TemplateDelete",
|
||||
"Deletes a virtual machine template")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_tpool();
|
||||
auth_object = AuthRequest::TEMPLATE;
|
||||
};
|
||||
|
||||
~TemplateDelete(){};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class VirtualNetworkDelete: public RequestManagerDelete
|
||||
{
|
||||
public:
|
||||
VirtualNetworkDelete():
|
||||
RequestManagerDelete("VirtualNetworkDelete",
|
||||
"Deletes a virtual network")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_vnpool();
|
||||
auth_object = AuthRequest::NET;
|
||||
};
|
||||
|
||||
~VirtualNetworkDelete(){};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class ImageDelete: public RequestManagerDelete
|
||||
{
|
||||
public:
|
||||
ImageDelete():
|
||||
RequestManagerDelete("ImageDelete", "Deletes an image")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_ipool();
|
||||
auth_object = AuthRequest::IMAGE;
|
||||
};
|
||||
|
||||
~ImageDelete(){};
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
int drop(int oid, PoolObjectSQL * object, string& error_msg);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class HostDelete : public RequestManagerDelete
|
||||
{
|
||||
public:
|
||||
HostDelete():
|
||||
RequestManagerDelete("HostDelete", "Deletes a host")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_hpool();
|
||||
auth_object = AuthRequest::HOST;
|
||||
};
|
||||
|
||||
~HostDelete(){};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
class GroupDelete: public RequestManagerDelete
|
||||
{
|
||||
public:
|
||||
GroupDelete():
|
||||
RequestManagerDelete("GroupDelete", "Deletes a group")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_gpool();
|
||||
auth_object = AuthRequest::GROUP;
|
||||
};
|
||||
|
||||
~GroupDelete(){};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class UserDelete: public RequestManagerDelete
|
||||
{
|
||||
public:
|
||||
UserDelete():
|
||||
RequestManagerDelete("UserDelete", "Deletes a user")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_upool();
|
||||
auth_object = AuthRequest::USER;
|
||||
};
|
||||
|
||||
~UserDelete(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
int drop(int oid, PoolObjectSQL * object, string& error_msg);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif
|
73
include/RequestManagerHost.h
Normal file
73
include/RequestManagerHost.h
Normal file
@ -0,0 +1,73 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef REQUEST_MANAGER_HOST_H
|
||||
#define REQUEST_MANAGER_HOST_H
|
||||
|
||||
#include "Request.h"
|
||||
#include "Nebula.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class RequestManagerHost: public Request
|
||||
{
|
||||
protected:
|
||||
RequestManagerHost( const string& method_name,
|
||||
const string& help,
|
||||
const string& params)
|
||||
:Request(method_name,params,help)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_hpool();
|
||||
|
||||
auth_object = AuthRequest::HOST;
|
||||
};
|
||||
|
||||
~RequestManagerHost(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
virtual void request_execute(xmlrpc_c::paramList const& _paramList) = 0;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class HostEnable : public RequestManagerHost
|
||||
{
|
||||
public:
|
||||
HostEnable():
|
||||
RequestManagerHost("HostEnable",
|
||||
"Enables or disables a host",
|
||||
"A:sib")
|
||||
{
|
||||
auth_op = AuthRequest::MANAGE;
|
||||
};
|
||||
|
||||
~HostEnable(){};
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif
|
83
include/RequestManagerImage.h
Normal file
83
include/RequestManagerImage.h
Normal file
@ -0,0 +1,83 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef REQUEST_MANAGER_IMAGE_H
|
||||
#define REQUEST_MANAGER_IMAGE_H
|
||||
|
||||
#include "Request.h"
|
||||
#include "Nebula.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class RequestManagerImage: public Request
|
||||
{
|
||||
protected:
|
||||
RequestManagerImage(const string& method_name,
|
||||
const string& help)
|
||||
:Request(method_name,"A:sib",help)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_ipool();
|
||||
|
||||
auth_object = AuthRequest::IMAGE;
|
||||
auth_op = AuthRequest::MANAGE;
|
||||
};
|
||||
|
||||
~RequestManagerImage(){};
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
virtual void request_execute(xmlrpc_c::paramList const& _paramList) = 0;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class ImageEnable : public RequestManagerImage
|
||||
{
|
||||
public:
|
||||
ImageEnable():
|
||||
RequestManagerImage("ImageEnable", "Enables or disables an image"){};
|
||||
|
||||
~ImageEnable(){};
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class ImagePersistent : public RequestManagerImage
|
||||
{
|
||||
public:
|
||||
ImagePersistent():
|
||||
RequestManagerImage("ImagePersistent",
|
||||
"Makes an image persistent or non-persistent"){};
|
||||
|
||||
~ImagePersistent(){};
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif
|
194
include/RequestManagerInfo.h
Normal file
194
include/RequestManagerInfo.h
Normal file
@ -0,0 +1,194 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef REQUEST_MANAGER_INFO_H_
|
||||
#define REQUEST_MANAGER_INFO_H_
|
||||
|
||||
#include "Request.h"
|
||||
#include "Nebula.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class RequestManagerInfo: public Request
|
||||
{
|
||||
protected:
|
||||
RequestManagerInfo(const string& method_name,
|
||||
const string& help)
|
||||
:Request(method_name,"A:si",help)
|
||||
{
|
||||
auth_op = AuthRequest::INFO;
|
||||
};
|
||||
|
||||
~RequestManagerInfo(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList);
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
virtual void to_xml(PoolObjectSQL * object, string& str)
|
||||
{
|
||||
object->to_xml(str);
|
||||
};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class VirtualMachineInfo : public RequestManagerInfo
|
||||
{
|
||||
public:
|
||||
VirtualMachineInfo():
|
||||
RequestManagerInfo("VirtualMachineInfo",
|
||||
"Returns virtual machine instance information")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_vmpool();
|
||||
auth_object = AuthRequest::VM;
|
||||
};
|
||||
|
||||
~VirtualMachineInfo(){};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class TemplateInfo : public RequestManagerInfo
|
||||
{
|
||||
public:
|
||||
TemplateInfo():
|
||||
RequestManagerInfo("TemplateInfo",
|
||||
"Returns virtual machine template information")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_tpool();
|
||||
auth_object = AuthRequest::TEMPLATE;
|
||||
};
|
||||
|
||||
~TemplateInfo(){};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
class VirtualNetworkInfo: public RequestManagerInfo
|
||||
{
|
||||
public:
|
||||
VirtualNetworkInfo():
|
||||
RequestManagerInfo("VirtualNetworkInfo",
|
||||
"Returns virtual network information")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_vnpool();
|
||||
auth_object = AuthRequest::NET;
|
||||
};
|
||||
|
||||
~VirtualNetworkInfo(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void to_xml(PoolObjectSQL * object, string& str)
|
||||
{
|
||||
VirtualNetwork * vn = static_cast<VirtualNetwork*>(object);
|
||||
vn->to_xml_extended(str);
|
||||
};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class ImageInfo: public RequestManagerInfo
|
||||
{
|
||||
public:
|
||||
ImageInfo():
|
||||
RequestManagerInfo("ImageInfo",
|
||||
"Returns image information")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_ipool();
|
||||
auth_object = AuthRequest::IMAGE;
|
||||
};
|
||||
|
||||
~ImageInfo(){};
|
||||
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class HostInfo : public RequestManagerInfo
|
||||
{
|
||||
public:
|
||||
HostInfo():
|
||||
RequestManagerInfo("HostInfo",
|
||||
"Returns host information")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_hpool();
|
||||
auth_object = AuthRequest::HOST;
|
||||
};
|
||||
|
||||
~HostInfo(){};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
class GroupInfo: public RequestManagerInfo
|
||||
{
|
||||
public:
|
||||
GroupInfo():
|
||||
RequestManagerInfo("GroupInfo",
|
||||
"Returns group information")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_gpool();
|
||||
auth_object = AuthRequest::GROUP;
|
||||
};
|
||||
|
||||
~GroupInfo(){};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class UserInfo: public RequestManagerInfo
|
||||
{
|
||||
public:
|
||||
UserInfo():
|
||||
RequestManagerInfo("UserInfo",
|
||||
"Returns user information")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_upool();
|
||||
auth_object = AuthRequest::USER;
|
||||
};
|
||||
|
||||
~UserInfo(){};
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif
|
106
include/RequestManagerPoolInfo.h
Normal file
106
include/RequestManagerPoolInfo.h
Normal file
@ -0,0 +1,106 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef REQUEST_MANAGER_POOL_INFO_H_
|
||||
#define REQUEST_MANAGER_POOL_INFO_H_
|
||||
|
||||
#include "Request.h"
|
||||
#include "Nebula.h"
|
||||
#include "AuthManager.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class RequestManagerPoolInfo: public Request
|
||||
{
|
||||
protected:
|
||||
RequestManagerPoolInfo(const string& method_name,
|
||||
const string& help)
|
||||
:Request(method_name,"A:s",help)
|
||||
{
|
||||
auth_op = AuthRequest::INFO_POOL;
|
||||
};
|
||||
|
||||
~RequestManagerPoolInfo(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class HostPoolInfo : public RequestManagerPoolInfo
|
||||
{
|
||||
public:
|
||||
HostPoolInfo():
|
||||
RequestManagerPoolInfo("HostPoolInfo",
|
||||
"Returns the host pool")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_hpool();
|
||||
auth_object = AuthRequest::HOST;
|
||||
};
|
||||
|
||||
~HostPoolInfo(){};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class GroupPoolInfo: public RequestManagerPoolInfo
|
||||
{
|
||||
public:
|
||||
GroupPoolInfo():
|
||||
RequestManagerPoolInfo("GroupPoolInfo",
|
||||
"Returns the group pool")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_gpool();
|
||||
auth_object = AuthRequest::GROUP;
|
||||
};
|
||||
|
||||
~GroupPoolInfo(){};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class UserPoolInfo: public RequestManagerPoolInfo
|
||||
{
|
||||
public:
|
||||
UserPoolInfo():
|
||||
RequestManagerPoolInfo("UserPoolInfo",
|
||||
"Returns the user pool")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_upool();
|
||||
auth_object = AuthRequest::USER;
|
||||
};
|
||||
|
||||
~UserPoolInfo(){};
|
||||
};
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif
|
131
include/RequestManagerPoolInfoFilter.h
Normal file
131
include/RequestManagerPoolInfoFilter.h
Normal file
@ -0,0 +1,131 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef REQUEST_MANAGER_POOL_INFO_FILTER_H_
|
||||
#define REQUEST_MANAGER_POOL_INFO_FILTER_H_
|
||||
|
||||
#include "Request.h"
|
||||
#include "Nebula.h"
|
||||
#include "AuthManager.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class RequestManagerPoolInfoFilter: public Request
|
||||
{
|
||||
protected:
|
||||
RequestManagerPoolInfoFilter(const string& method_name,
|
||||
const string& help)
|
||||
:Request(method_name,"A:si",help)
|
||||
{
|
||||
auth_op = AuthRequest::INFO_POOL;
|
||||
};
|
||||
|
||||
~RequestManagerPoolInfoFilter(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
static const int ALL; /**< Secify all objects in the pool (-2) */
|
||||
static const int MINE; /**< Secify user's objects in the pool (-3)*/
|
||||
static const int MINE_GROUP; /**< Secify users + group objects (-1) */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class VirtualMachinePoolInfo : public RequestManagerPoolInfoFilter
|
||||
{
|
||||
public:
|
||||
VirtualMachinePoolInfo():
|
||||
RequestManagerPoolInfoFilter("VirtualMachinePoolInfo",
|
||||
"Returns the virtual machine instances pool")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_vmpool();
|
||||
auth_object = AuthRequest::VM;
|
||||
};
|
||||
|
||||
~VirtualMachinePoolInfo(){};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class TemplatePoolInfo : public RequestManagerPoolInfoFilter
|
||||
{
|
||||
public:
|
||||
TemplatePoolInfo():
|
||||
RequestManagerPoolInfoFilter("TemplatePoolInfo",
|
||||
"Returns the virtual machine template pool")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_tpool();
|
||||
auth_object = AuthRequest::TEMPLATE;
|
||||
};
|
||||
|
||||
~TemplatePoolInfo(){};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
class VirtualNetworkPoolInfo: public RequestManagerPoolInfoFilter
|
||||
{
|
||||
public:
|
||||
VirtualNetworkPoolInfo():
|
||||
RequestManagerPoolInfoFilter("VirtualNetworkPoolInfo",
|
||||
"Returns the virtual network pool")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_vnpool();
|
||||
auth_object = AuthRequest::NET;
|
||||
};
|
||||
|
||||
~VirtualNetworkPoolInfo(){};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class ImagePoolInfo: public RequestManagerPoolInfoFilter
|
||||
{
|
||||
public:
|
||||
ImagePoolInfo():
|
||||
RequestManagerPoolInfoFilter("ImagePoolInfo",
|
||||
"Returns the image pool")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_ipool();
|
||||
auth_object = AuthRequest::IMAGE;
|
||||
};
|
||||
|
||||
~ImagePoolInfo(){};
|
||||
};
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif
|
136
include/RequestManagerPublish.h
Normal file
136
include/RequestManagerPublish.h
Normal file
@ -0,0 +1,136 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef REQUEST_MANAGER_PUBLISH_H_
|
||||
#define REQUEST_MANAGER_PUBLISH_H_
|
||||
|
||||
#include "Request.h"
|
||||
#include "Nebula.h"
|
||||
#include "AuthManager.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class RequestManagerPublish: public Request
|
||||
{
|
||||
protected:
|
||||
RequestManagerPublish(const string& method_name,
|
||||
const string& help)
|
||||
:Request(method_name,"A:sib",help)
|
||||
{
|
||||
auth_op = AuthRequest::MANAGE;
|
||||
}
|
||||
|
||||
~RequestManagerPublish(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList);
|
||||
|
||||
virtual int publish(PoolObjectSQL *object, bool pflag) = 0;
|
||||
};
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class TemplatePublish : public RequestManagerPublish
|
||||
{
|
||||
public:
|
||||
TemplatePublish():
|
||||
RequestManagerPublish("TemplatePublish",
|
||||
"Publish a virtual machine template")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_tpool();
|
||||
auth_object = AuthRequest::TEMPLATE;
|
||||
};
|
||||
|
||||
~TemplatePublish(){};
|
||||
|
||||
int publish(PoolObjectSQL *object, bool pflag)
|
||||
{
|
||||
VMTemplate * robject;
|
||||
|
||||
robject = static_cast<VMTemplate *>(object);
|
||||
|
||||
return robject->publish(pflag);
|
||||
}
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class VirtualNetworkPublish: public RequestManagerPublish
|
||||
{
|
||||
public:
|
||||
VirtualNetworkPublish():
|
||||
RequestManagerPublish("VirtualNetworkPublish",
|
||||
"Publish a virtual network")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_vnpool();
|
||||
auth_object = AuthRequest::NET;
|
||||
};
|
||||
|
||||
~VirtualNetworkPublish(){};
|
||||
|
||||
int publish(PoolObjectSQL *object, bool pflag)
|
||||
{
|
||||
VirtualNetwork * robject;
|
||||
|
||||
robject = static_cast<VirtualNetwork *>(object);
|
||||
|
||||
robject->publish(pflag);
|
||||
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class ImagePublish: public RequestManagerPublish
|
||||
{
|
||||
public:
|
||||
ImagePublish():
|
||||
RequestManagerPublish("ImagePublish", "Publish an image")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_ipool();
|
||||
auth_object = AuthRequest::IMAGE;
|
||||
};
|
||||
|
||||
~ImagePublish(){};
|
||||
|
||||
int publish(PoolObjectSQL *object, bool pflag)
|
||||
{
|
||||
Image * robject;
|
||||
|
||||
robject = static_cast<Image *>(object);
|
||||
|
||||
return robject->publish(pflag);
|
||||
}
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif
|
104
include/RequestManagerUpdateTemplate.h
Normal file
104
include/RequestManagerUpdateTemplate.h
Normal file
@ -0,0 +1,104 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef REQUEST_MANAGER_UPDATE_TEMPLATE_H
|
||||
#define REQUEST_MANAGER_UPDATE_TEMPLATE_H
|
||||
|
||||
#include "Request.h"
|
||||
#include "Nebula.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class RequestManagerUpdateTemplate: public Request
|
||||
{
|
||||
protected:
|
||||
RequestManagerUpdateTemplate(const string& method_name,
|
||||
const string& help)
|
||||
:Request(method_name,"A:sis",help)
|
||||
{
|
||||
auth_op = AuthRequest::MANAGE;
|
||||
};
|
||||
|
||||
~RequestManagerUpdateTemplate(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class TemplateUpdateTemplate: public RequestManagerUpdateTemplate
|
||||
{
|
||||
public:
|
||||
TemplateUpdateTemplate():
|
||||
RequestManagerUpdateTemplate("TemplateUpdateTemplate",
|
||||
"Updates a virtual machine template")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_tpool();
|
||||
auth_object = AuthRequest::TEMPLATE;
|
||||
};
|
||||
|
||||
~TemplateUpdateTemplate(){};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class ImageUpdateTemplate: public RequestManagerUpdateTemplate
|
||||
{
|
||||
public:
|
||||
ImageUpdateTemplate():
|
||||
RequestManagerUpdateTemplate("ImageUpdateTemplate",
|
||||
"Updates an image template")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_ipool();
|
||||
auth_object = AuthRequest::IMAGE;
|
||||
};
|
||||
|
||||
~ImageUpdateTemplate(){};
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class HostUpdateTemplate : public RequestManagerUpdateTemplate
|
||||
{
|
||||
public:
|
||||
HostUpdateTemplate():
|
||||
RequestManagerUpdateTemplate("HostUpdateTemplate",
|
||||
"Updates a host template")
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_hpool();
|
||||
auth_object = AuthRequest::HOST;
|
||||
};
|
||||
|
||||
~HostUpdateTemplate(){};
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif
|
113
include/RequestManagerUser.h
Normal file
113
include/RequestManagerUser.h
Normal file
@ -0,0 +1,113 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef REQUEST_MANAGER_USER_H
|
||||
#define REQUEST_MANAGER_USER_H
|
||||
|
||||
#include "Request.h"
|
||||
#include "Nebula.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class RequestManagerUser: public Request
|
||||
{
|
||||
protected:
|
||||
RequestManagerUser(const string& method_name,
|
||||
const string& help,
|
||||
const string& params)
|
||||
:Request(method_name,params,help)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_upool();
|
||||
|
||||
auth_object = AuthRequest::USER;
|
||||
auth_op = AuthRequest::MANAGE;
|
||||
};
|
||||
|
||||
~RequestManagerUser(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList);
|
||||
|
||||
virtual int user_action(User * user,
|
||||
xmlrpc_c::paramList const& _paramList,
|
||||
string& error_str ) = 0;
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class UserChangePassword : public RequestManagerUser
|
||||
{
|
||||
public:
|
||||
UserChangePassword():
|
||||
RequestManagerUser("UserChangePassword",
|
||||
"Changes user's password",
|
||||
"A:sis"){};
|
||||
~UserChangePassword(){};
|
||||
|
||||
int user_action(User * user,
|
||||
xmlrpc_c::paramList const& _paramList,
|
||||
string& err);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class UserAddGroup : public RequestManagerUser
|
||||
{
|
||||
public:
|
||||
UserAddGroup():
|
||||
RequestManagerUser("UserAddGroup",
|
||||
"Adds a new group to the user",
|
||||
"A:sii"){};
|
||||
~UserAddGroup(){};
|
||||
|
||||
int user_action(User * user,
|
||||
xmlrpc_c::paramList const& _paramList,
|
||||
string& err);
|
||||
};
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class UserDelGroup : public RequestManagerUser
|
||||
{
|
||||
public:
|
||||
UserDelGroup():
|
||||
RequestManagerUser("UserDelGroup",
|
||||
"Deletes a new group to the user",
|
||||
"A:sii"){};
|
||||
~UserDelGroup(){};
|
||||
|
||||
int user_action(User * user,
|
||||
xmlrpc_c::paramList const& _paramList,
|
||||
string& err);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif
|
73
include/RequestManagerVMTemplate.h
Normal file
73
include/RequestManagerVMTemplate.h
Normal file
@ -0,0 +1,73 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef REQUEST_MANAGER_VM_TEMPLATE_H
|
||||
#define REQUEST_MANAGER_VM_TEMPLATE_H
|
||||
|
||||
#include "Request.h"
|
||||
#include "Nebula.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class RequestManagerVMTemplate: public Request
|
||||
{
|
||||
protected:
|
||||
RequestManagerVMTemplate(const string& method_name,
|
||||
const string& help,
|
||||
const string& params)
|
||||
:Request(method_name,params,help)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_tpool();
|
||||
|
||||
auth_object = AuthRequest::TEMPLATE;
|
||||
};
|
||||
|
||||
~RequestManagerVMTemplate(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
virtual void request_execute(xmlrpc_c::paramList const& _paramList) = 0;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class VMTemplateInstantiate : public RequestManagerVMTemplate
|
||||
{
|
||||
public:
|
||||
VMTemplateInstantiate():
|
||||
RequestManagerVMTemplate("TemplateInstantiate",
|
||||
"Instantiates a new virtual machine using a template",
|
||||
"A:sis")
|
||||
{
|
||||
auth_op = AuthRequest::INSTANTIATE;
|
||||
};
|
||||
|
||||
~VMTemplateInstantiate(){};
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif
|
130
include/RequestManagerVirtualMachine.h
Normal file
130
include/RequestManagerVirtualMachine.h
Normal file
@ -0,0 +1,130 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef REQUEST_MANAGER_VIRTUAL_MACHINE_H_
|
||||
#define REQUEST_MANAGER_VIRTUAL_MACHINE_H
|
||||
|
||||
#include "Request.h"
|
||||
#include "Nebula.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class RequestManagerVirtualMachine: public Request
|
||||
{
|
||||
protected:
|
||||
RequestManagerVirtualMachine(const string& method_name,
|
||||
const string& help,
|
||||
const string& params)
|
||||
:Request(method_name,params,help)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_vmpool();
|
||||
|
||||
auth_object = AuthRequest::VM;
|
||||
auth_op = AuthRequest::MANAGE;
|
||||
};
|
||||
|
||||
~RequestManagerVirtualMachine(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
virtual void request_execute(xmlrpc_c::paramList const& _paramList) = 0;
|
||||
|
||||
bool vm_authorization(int id, int hid, ImageTemplate *tmpl);
|
||||
|
||||
int get_host_information(int hid, string& name, string& vmm, string& tm);
|
||||
|
||||
int add_history(VirtualMachine * vm,
|
||||
int hid,
|
||||
const string& hostname,
|
||||
const string& vmm_mad,
|
||||
const string& tm_mad);
|
||||
|
||||
VirtualMachine * get_vm(int id);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class VirtualMachineAction : public RequestManagerVirtualMachine
|
||||
{
|
||||
public:
|
||||
VirtualMachineAction():
|
||||
RequestManagerVirtualMachine("VirtualMachineAction",
|
||||
"Performs an action on a virtual machine",
|
||||
"A:ssi"){};
|
||||
~VirtualMachineAction(){};
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class VirtualMachineDeploy : public RequestManagerVirtualMachine
|
||||
{
|
||||
public:
|
||||
VirtualMachineDeploy():
|
||||
RequestManagerVirtualMachine("VirtualMachineDeploy",
|
||||
"Deploys a virtual machine",
|
||||
"A:sii"){};
|
||||
|
||||
~VirtualMachineDeploy(){};
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class VirtualMachineMigrate : public RequestManagerVirtualMachine
|
||||
{
|
||||
public:
|
||||
VirtualMachineMigrate():
|
||||
RequestManagerVirtualMachine("VirtualMachineDeploy",
|
||||
"Migrates a virtual machine",
|
||||
"A:siib"){};
|
||||
|
||||
~VirtualMachineMigrate(){};
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class VirtualMachineSaveDisk : public RequestManagerVirtualMachine
|
||||
{
|
||||
public:
|
||||
VirtualMachineSaveDisk():
|
||||
RequestManagerVirtualMachine("VirtualMachineSaveDisk",
|
||||
"Saves a disk from virtual machine as a new image",
|
||||
"A:siis"){};
|
||||
|
||||
~VirtualMachineSaveDisk(){};
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif
|
100
include/RequestManagerVirtualNetwork.h
Normal file
100
include/RequestManagerVirtualNetwork.h
Normal file
@ -0,0 +1,100 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef REQUEST_MANAGER_VIRTUAL_NETWORK_H
|
||||
#define REQUEST_MANAGER_VIRTUAL_NETWORK_H
|
||||
|
||||
#include "Request.h"
|
||||
#include "Nebula.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class RequestManagerVirtualNetwork: public Request
|
||||
{
|
||||
protected:
|
||||
RequestManagerVirtualNetwork(const string& method_name,
|
||||
const string& help)
|
||||
:Request(method_name,"A:sis",help)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_vnpool();
|
||||
|
||||
auth_object = AuthRequest::NET;
|
||||
auth_op = AuthRequest::MANAGE;
|
||||
};
|
||||
|
||||
~RequestManagerVirtualNetwork(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList);
|
||||
|
||||
virtual int leases_action(VirtualNetwork * vn,
|
||||
VirtualNetworkTemplate * tmpl,
|
||||
string& error_str) = 0;
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
string leases_error (char * error);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class VirtualNetworkAddLeases : public RequestManagerVirtualNetwork
|
||||
{
|
||||
public:
|
||||
VirtualNetworkAddLeases():
|
||||
RequestManagerVirtualNetwork("VirtualNetworkAddLeases",
|
||||
"Adds leases to a virtual network"){};
|
||||
~VirtualNetworkAddLeases(){};
|
||||
|
||||
int leases_action(VirtualNetwork * vn,
|
||||
VirtualNetworkTemplate * tmpl,
|
||||
string& error_str)
|
||||
{
|
||||
return vn->add_leases(tmpl, error_str);
|
||||
}
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class VirtualNetworkRemoveLeases : public RequestManagerVirtualNetwork
|
||||
{
|
||||
public:
|
||||
VirtualNetworkRemoveLeases():
|
||||
RequestManagerVirtualNetwork("VirtualNetworkRemoveLeases",
|
||||
"Removes leases from a virtual network"){};
|
||||
~VirtualNetworkRemoveLeases(){};
|
||||
|
||||
int leases_action(VirtualNetwork * vn,
|
||||
VirtualNetworkTemplate * tmpl,
|
||||
string& error_str)
|
||||
{
|
||||
return vn->remove_leases(tmpl, error_str);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif
|
@ -128,24 +128,23 @@ public:
|
||||
* attributes MUST be freed by the calling funtion
|
||||
* @param name of the attribute
|
||||
* @param values a vector containing a pointer to the attributes
|
||||
* @returns the number of attributes removed
|
||||
* @return the number of attributes removed
|
||||
*/
|
||||
virtual int remove(
|
||||
const string& name,
|
||||
vector<Attribute *>& values);
|
||||
|
||||
|
||||
/**
|
||||
* Removes an attribute from the template, and frees the attributes.
|
||||
* @param name of the attribute
|
||||
* @returns the number of attributes removed
|
||||
* @return the number of attributes removed
|
||||
*/
|
||||
virtual int erase(const string& name);
|
||||
|
||||
/**
|
||||
* Gets all the attributes with the given name.
|
||||
* @param name the attribute name.
|
||||
* @returns the number of elements in the vector
|
||||
* @return the number of elements in the vector
|
||||
*/
|
||||
virtual int get(
|
||||
const string& name,
|
||||
@ -154,7 +153,7 @@ public:
|
||||
/**
|
||||
* Gets all the attributes with the given name, non-const version
|
||||
* @param name the attribute name.
|
||||
* @returns the number of elements in the vector
|
||||
* @return the number of elements in the vector
|
||||
*/
|
||||
virtual int get(
|
||||
const string& name,
|
||||
@ -176,7 +175,7 @@ public:
|
||||
* @param value the attribute value, an int, 0 if the attribute is not
|
||||
* defined or not Single
|
||||
*
|
||||
* @returns True if the Single attribute was found
|
||||
* @return True if the Single attribute was found
|
||||
*/
|
||||
virtual bool get(
|
||||
string& name,
|
||||
|
@ -18,6 +18,7 @@
|
||||
#define USER_H_
|
||||
|
||||
#include "PoolSQL.h"
|
||||
#include "ObjectCollection.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -27,15 +28,10 @@ using namespace std;
|
||||
/**
|
||||
* The User class.
|
||||
*/
|
||||
class User : public PoolObjectSQL
|
||||
class User : public PoolObjectSQL, public ObjectCollection
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Function to write a User on an output stream
|
||||
*/
|
||||
friend ostream& operator<<(ostream& os, User& u);
|
||||
|
||||
/**
|
||||
* Function to print the User object into a string in XML format
|
||||
* @param xml the resulting XML string
|
||||
@ -94,6 +90,47 @@ public:
|
||||
**/
|
||||
static int split_secret(const string secret, string& user, string& pass);
|
||||
|
||||
/**
|
||||
* Returns a copy of the groups for the user
|
||||
*/
|
||||
set<int> get_groups()
|
||||
{
|
||||
return get_collection_copy();
|
||||
};
|
||||
|
||||
// *************************************************************************
|
||||
// Group IDs set Management
|
||||
// *************************************************************************
|
||||
|
||||
/**
|
||||
* Adds a group ID to the groups set.
|
||||
*
|
||||
* @param id The new id
|
||||
* @return 0 on success, -1 if the ID was already in the set
|
||||
*/
|
||||
int add_group(int group_id)
|
||||
{
|
||||
return add_collection_id(group_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a group ID from the groups set.
|
||||
*
|
||||
* @param id The id
|
||||
* @return 0 on success,
|
||||
* -1 if the ID was not in the set,
|
||||
* -2 if the group to delete is the main group
|
||||
*/
|
||||
int del_group(int group_id)
|
||||
{
|
||||
if( group_id == gid )
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
|
||||
return del_collection_id(group_id);
|
||||
}
|
||||
|
||||
private:
|
||||
// -------------------------------------------------------------------------
|
||||
// Friends
|
||||
@ -145,18 +182,20 @@ private:
|
||||
*/
|
||||
int from_xml(const string &xml_str);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// *************************************************************************
|
||||
// Constructor
|
||||
// *************************************************************************
|
||||
|
||||
User(int id,
|
||||
string _username,
|
||||
string _password,
|
||||
bool _enabled);
|
||||
User(int id, int _gid, const string& _username, const string& _password, bool _enabled):
|
||||
PoolObjectSQL(id,_username,-1,_gid,table),
|
||||
ObjectCollection("GROUPS"),
|
||||
password(_password), enabled(_enabled)
|
||||
{ };
|
||||
|
||||
virtual ~User();
|
||||
virtual ~User(){};
|
||||
|
||||
// *************************************************************************
|
||||
// DataBase implementation
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include "PoolSQL.h"
|
||||
#include "User.h"
|
||||
#include "GroupPool.h"
|
||||
|
||||
#include <time.h>
|
||||
#include <sstream>
|
||||
@ -49,7 +50,8 @@ public:
|
||||
*/
|
||||
int allocate (
|
||||
int * oid,
|
||||
string hostname,
|
||||
int gid,
|
||||
string username,
|
||||
string password,
|
||||
bool enabled,
|
||||
string& error_str);
|
||||
@ -87,14 +89,6 @@ public:
|
||||
return user->update(db);
|
||||
};
|
||||
|
||||
/** Drops a user from the DB, the user mutex MUST BE locked
|
||||
* @param user pointer to User
|
||||
*/
|
||||
int drop(User * user)
|
||||
{
|
||||
return PoolSQL::drop(user);
|
||||
};
|
||||
|
||||
/**
|
||||
* Bootstraps the database table(s) associated to the User pool
|
||||
*/
|
||||
@ -106,9 +100,11 @@ public:
|
||||
/**
|
||||
* Returns whether there is a user with given username/password or not
|
||||
* @param session, colon separated username and password string
|
||||
* @return -1 if authn failed, uid of the user in other case
|
||||
* @param uid of the user if authN succeeded -1 otherwise
|
||||
* @param gid of the user if authN succeeded -1 otherwise
|
||||
* @return false if authn failed, true otherwise
|
||||
*/
|
||||
int authenticate(string& session);
|
||||
bool authenticate(const string& session, int& uid, int& gid);
|
||||
|
||||
/**
|
||||
* Returns whether there is a user with given username/password or not
|
||||
@ -137,7 +133,7 @@ private:
|
||||
*/
|
||||
PoolObjectSQL * create()
|
||||
{
|
||||
return new User(-1,"","",true);
|
||||
return new User(-1,-1,"","",true);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -30,11 +30,6 @@ class VMTemplate : public PoolObjectSQL
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Function to write a VMTemplate on an output stream
|
||||
*/
|
||||
friend ostream& operator<<(ostream& os, VMTemplate& u);
|
||||
|
||||
/**
|
||||
* Function to print the VMTemplate object into a string in XML format
|
||||
* @param xml the resulting XML string
|
||||
@ -42,38 +37,37 @@ public:
|
||||
*/
|
||||
string& to_xml(string& xml) const;
|
||||
|
||||
/**
|
||||
* Returns true if the object is public
|
||||
* @return true if the Virtual Network is public
|
||||
*/
|
||||
bool isPublic()
|
||||
{
|
||||
return (public_template == 1);
|
||||
};
|
||||
|
||||
/**
|
||||
* Publish or unpublish an object
|
||||
* @param pub true to publish the object
|
||||
* @return 0 on success
|
||||
*/
|
||||
bool publish(bool pub)
|
||||
int publish(bool pub)
|
||||
{
|
||||
if (pub == true)
|
||||
{
|
||||
public_template = 1;
|
||||
public_obj = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
public_template = 0;
|
||||
public_obj = 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
return 0;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Template Contents
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Factory method for virtual machine templates
|
||||
*/
|
||||
Template * get_new_template()
|
||||
{
|
||||
return new VirtualMachineTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a copy of the VirtualMachineTemplate
|
||||
* @return A copy of the VirtualMachineTemplate
|
||||
@ -82,15 +76,6 @@ public:
|
||||
{
|
||||
return new VirtualMachineTemplate(
|
||||
*(static_cast<VirtualMachineTemplate *>(obj_template)));
|
||||
|
||||
// TODO: Check if there is a more efficient way to do this copy.
|
||||
/*string xml_str;
|
||||
VirtualMachineTemplate * new_template = new VirtualMachineTemplate();
|
||||
|
||||
obj_template->to_xml(xml_str);
|
||||
new_template->from_xml(xml_str);
|
||||
|
||||
return new_template;*/
|
||||
};
|
||||
|
||||
private:
|
||||
@ -104,16 +89,6 @@ private:
|
||||
// VMTemplate Attributes
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Owner's name
|
||||
*/
|
||||
string user_name;
|
||||
|
||||
/**
|
||||
* Public scope of the VMTemplate
|
||||
*/
|
||||
int public_template;
|
||||
|
||||
/**
|
||||
* Registration time
|
||||
*/
|
||||
@ -154,8 +129,8 @@ protected:
|
||||
// *************************************************************************
|
||||
// Constructor
|
||||
// *************************************************************************
|
||||
VMTemplate(int id, int uid, string _user_name,
|
||||
VirtualMachineTemplate * _template_contents);
|
||||
VMTemplate(int id, int uid, int gid,
|
||||
VirtualMachineTemplate * _template_contents);
|
||||
|
||||
~VMTemplate();
|
||||
|
||||
|
@ -35,7 +35,7 @@ public:
|
||||
* Allocates a new object, writting it in the pool database. No memory is
|
||||
* allocated for the object.
|
||||
* @param uid user id (the owner of the Template)
|
||||
* @param user_name Owner's user name
|
||||
* @param gid the id of the group this object is assigned to
|
||||
* @param template_contents a VM Template object
|
||||
* @param oid the id assigned to the Template
|
||||
* @param error_str Returns the error reason, if any
|
||||
@ -43,7 +43,7 @@ public:
|
||||
* @return the oid assigned to the object, -1 in case of failure
|
||||
*/
|
||||
int allocate(int uid,
|
||||
string user_name,
|
||||
int gid,
|
||||
VirtualMachineTemplate * template_contents,
|
||||
int * oid,
|
||||
string& error_str);
|
||||
@ -87,17 +87,6 @@ public:
|
||||
return vm_template->update(db);
|
||||
};
|
||||
|
||||
/**
|
||||
* Drops the object's data in the data base. The object mutex SHOULD be
|
||||
* locked.
|
||||
* @param objsql a pointer to the object
|
||||
* @return 0 on success.
|
||||
*/
|
||||
int drop(VMTemplate * vm_template)
|
||||
{
|
||||
return PoolSQL::drop(vm_template);
|
||||
};
|
||||
|
||||
/**
|
||||
* Dumps the pool in XML format. A filter can be also added to the
|
||||
* query
|
||||
@ -139,7 +128,7 @@ private:
|
||||
*/
|
||||
PoolObjectSQL * create()
|
||||
{
|
||||
return new VMTemplate(-1,-1,"", 0);
|
||||
return new VMTemplate(-1,-1,-1,0);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -28,6 +28,8 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
class AuthRequest;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
@ -114,11 +116,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Function to write a Virtual Machine in an output stream
|
||||
*/
|
||||
friend ostream& operator<<(ostream& os, const VirtualMachine& vm);
|
||||
|
||||
/**
|
||||
* Function to print the VirtualMachine object into a string in
|
||||
* XML format
|
||||
@ -540,6 +537,14 @@ public:
|
||||
* @return 0 on success.
|
||||
*/
|
||||
int parse_template_attribute(const string& attribute, string& parsed);
|
||||
|
||||
/**
|
||||
* Factory method for virtual machine templates
|
||||
*/
|
||||
Template * get_new_template()
|
||||
{
|
||||
return new VirtualMachineTemplate;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// States
|
||||
@ -657,6 +662,19 @@ public:
|
||||
*/
|
||||
int save_disk(int disk_id, int img_id, string& error_str);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Authorization related functions
|
||||
// ------------------------------------------------------------------------
|
||||
/**
|
||||
* Sets an authorization request for a VirtualMachine template based on
|
||||
* the images and networks used
|
||||
* @param uid for template owner
|
||||
* @param ar the AuthRequest object
|
||||
* @param tmpl the virtual machine template
|
||||
*/
|
||||
static void set_auth_request(int uid,
|
||||
AuthRequest& ar,
|
||||
VirtualMachineTemplate *tmpl);
|
||||
private:
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
@ -668,14 +686,6 @@ private:
|
||||
// Virtual Machine Attributes
|
||||
// *************************************************************************
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Identification variables
|
||||
// -------------------------------------------------------------------------
|
||||
/**
|
||||
* Owner's name
|
||||
*/
|
||||
string user_name;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// VM Scheduling & Managing Information
|
||||
// -------------------------------------------------------------------------
|
||||
@ -855,8 +865,8 @@ protected:
|
||||
// Constructor
|
||||
//**************************************************************************
|
||||
|
||||
VirtualMachine(int id, int uid, string _user_name,
|
||||
VirtualMachineTemplate * _vm_template);
|
||||
VirtualMachine(int id, int uid,
|
||||
int gid, VirtualMachineTemplate * _vm_template);
|
||||
|
||||
virtual ~VirtualMachine();
|
||||
|
||||
|
@ -41,7 +41,7 @@ public:
|
||||
/**
|
||||
* Function to allocate a new VM object
|
||||
* @param uid user id (the owner of the VM)
|
||||
* @param user_name Owner's user name
|
||||
* @param gid the id of the group this object is assigned to
|
||||
* @param vm_template a VM Template object describing the VM
|
||||
* @param oid the id assigned to the VM (output)
|
||||
* @param error_str Returns the error reason, if any
|
||||
@ -51,7 +51,7 @@ public:
|
||||
*/
|
||||
int allocate (
|
||||
int uid,
|
||||
string user_name,
|
||||
int gid,
|
||||
VirtualMachineTemplate * vm_template,
|
||||
int * oid,
|
||||
string& error_str,
|
||||
@ -146,7 +146,6 @@ public:
|
||||
* pool
|
||||
* @param oss the output stream to dump the pool contents
|
||||
* @param where filter for the objects, defaults to all
|
||||
* @param extended condition to include history and username data
|
||||
* @param state include only VMs in this state. -1 means any state,
|
||||
* except DONE
|
||||
*
|
||||
@ -161,7 +160,7 @@ private:
|
||||
*/
|
||||
PoolObjectSQL * create()
|
||||
{
|
||||
return new VirtualMachine(-1,-1,"", 0);
|
||||
return new VirtualMachine(-1,-1,-1,0);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include "PoolSQL.h"
|
||||
#include "Leases.h"
|
||||
#include "VirtualNetworkTemplate.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
@ -32,7 +33,6 @@ using namespace std;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
class VirtualNetworkTemplate;
|
||||
|
||||
/**
|
||||
* The Virtual Network class. It represents a Virtual Network at manages its
|
||||
@ -58,15 +58,6 @@ public:
|
||||
// Virtual Network Public Methods
|
||||
// *************************************************************************
|
||||
|
||||
/**
|
||||
* Returns true if the Virtual Network is public
|
||||
* @return true if the Virtual Network is public
|
||||
*/
|
||||
bool isPublic()
|
||||
{
|
||||
return (public_vnet == 1);
|
||||
};
|
||||
|
||||
/**
|
||||
* Publish or unpublish a virtual network
|
||||
* @param pub true to publish the image
|
||||
@ -76,14 +67,22 @@ public:
|
||||
{
|
||||
if (pub == true)
|
||||
{
|
||||
public_vnet = 1;
|
||||
public_obj = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
public_vnet = 0;
|
||||
public_obj = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for virtual network templates
|
||||
*/
|
||||
Template * get_new_template()
|
||||
{
|
||||
return new VirtualNetworkTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds Leases to the virtual network (Only implemented for FIXED networks)
|
||||
* @param leases_template template in the form LEASES = [IP=XX, MAC=XX].
|
||||
@ -152,11 +151,6 @@ public:
|
||||
return leases->size;
|
||||
};
|
||||
|
||||
/**
|
||||
* Function to write a Virtual Network in an output stream
|
||||
*/
|
||||
friend ostream& operator<<(ostream& os, VirtualNetwork& vn);
|
||||
|
||||
/**
|
||||
* Function to print the VirtualNetwork object into a string in
|
||||
* XML format
|
||||
@ -165,6 +159,14 @@ public:
|
||||
*/
|
||||
string& to_xml(string& xml) const;
|
||||
|
||||
/**
|
||||
* Function to print the VirtualNetwork object into a string in
|
||||
* XML format. The extended XML includes the LEASES
|
||||
* @param xml the resulting XML string
|
||||
* @return a reference to the generated string
|
||||
*/
|
||||
string& to_xml_extended(string& xml) const;
|
||||
|
||||
/**
|
||||
* Modifies the given nic attribute adding the following attributes:
|
||||
* * IP: leased from network
|
||||
@ -187,14 +189,6 @@ private:
|
||||
// Virtual Network Private Attributes
|
||||
// *************************************************************************
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Identification variables
|
||||
// -------------------------------------------------------------------------
|
||||
/**
|
||||
* Owner's name
|
||||
*/
|
||||
string user_name;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Binded physical attributes
|
||||
// -------------------------------------------------------------------------
|
||||
@ -212,11 +206,6 @@ private:
|
||||
*/
|
||||
NetworkType type;
|
||||
|
||||
/**
|
||||
* Public scope of this Virtual Network
|
||||
*/
|
||||
int public_vnet;
|
||||
|
||||
/**
|
||||
* Pointer to leases class, can be fixed or ranged.
|
||||
* Holds information on given (and, optionally, possible) leases
|
||||
@ -268,8 +257,8 @@ private:
|
||||
// Constructor
|
||||
//**************************************************************************
|
||||
|
||||
VirtualNetwork(int uid,
|
||||
string _user_name,
|
||||
VirtualNetwork(int uid,
|
||||
int gid,
|
||||
VirtualNetworkTemplate * _vn_template = 0);
|
||||
|
||||
~VirtualNetwork();
|
||||
|
@ -42,16 +42,18 @@ public:
|
||||
/**
|
||||
* Function to allocate a new VNET object
|
||||
* @param uid user identifier
|
||||
* @param gid the id of the group this object is assigned to
|
||||
* @param vn_template a VirtualNetworkTemplate describing the VNET
|
||||
* @param oid the id assigned to the VM (output)
|
||||
* @param error_str Returns the error reason, if any
|
||||
* @return oid on success, -1 error
|
||||
*/
|
||||
int allocate (
|
||||
int uid,
|
||||
string user_name,
|
||||
VirtualNetworkTemplate * vn_template,
|
||||
int * oid,
|
||||
string& error_str);
|
||||
int uid,
|
||||
int gid,
|
||||
VirtualNetworkTemplate * vn_template,
|
||||
int * oid,
|
||||
string& error_str);
|
||||
|
||||
/**
|
||||
* Function to get a VN from the pool, if the object is not in memory
|
||||
@ -154,7 +156,7 @@ private:
|
||||
*/
|
||||
PoolObjectSQL * create()
|
||||
{
|
||||
return new VirtualNetwork(0,"",0);
|
||||
return new VirtualNetwork(-1,-1, 0);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include "VirtualNetworkPool.h"
|
||||
#include "HostPool.h"
|
||||
#include "UserPool.h"
|
||||
#include "ClusterPool.h"
|
||||
#include "VMTemplatePool.h"
|
||||
|
||||
#include "VirtualMachineManager.h"
|
||||
@ -44,12 +43,13 @@ protected:
|
||||
|
||||
NebulaTest():mysql(false), need_host_pool(false), need_vm_pool(false),
|
||||
need_vnet_pool(false), need_image_pool(false),
|
||||
need_user_pool(false), need_cluster_pool(false),
|
||||
need_template_pool(false),need_vmm(false),
|
||||
need_user_pool(false), need_template_pool(false),
|
||||
need_group_pool(false),
|
||||
need_vmm(false),
|
||||
need_im(false), need_tm(false),
|
||||
need_lcm(false), need_dm(false),
|
||||
need_rm(false), need_hm(false),
|
||||
need_authm(false)
|
||||
need_authm(false), need_imagem(false)
|
||||
{};
|
||||
|
||||
virtual ~NebulaTest(){};
|
||||
@ -64,8 +64,8 @@ public:
|
||||
bool need_vnet_pool;
|
||||
bool need_image_pool;
|
||||
bool need_user_pool;
|
||||
bool need_cluster_pool;
|
||||
bool need_template_pool;
|
||||
bool need_group_pool;
|
||||
|
||||
bool need_vmm;
|
||||
bool need_im;
|
||||
@ -100,10 +100,10 @@ public:
|
||||
string default_image_type,
|
||||
string default_device_prefix);
|
||||
|
||||
virtual ClusterPool* create_cpool(SqlDB* db);
|
||||
|
||||
virtual VMTemplatePool* create_tpool(SqlDB* db);
|
||||
|
||||
virtual GroupPool* create_gpool(SqlDB* db);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Managers
|
||||
// ------------------------------------------------------------------------
|
||||
@ -126,15 +126,7 @@ public:
|
||||
virtual DispatchManager* create_dm(VirtualMachinePool* vmpool,
|
||||
HostPool* hpool);
|
||||
|
||||
virtual RequestManager* create_rm(
|
||||
VirtualMachinePool * vmpool,
|
||||
HostPool * hpool,
|
||||
VirtualNetworkPool * vnpool,
|
||||
UserPool * upool,
|
||||
ImagePool * ipool,
|
||||
ClusterPool * cpool,
|
||||
VMTemplatePool * tpool,
|
||||
string log_file);
|
||||
virtual RequestManager* create_rm(string log_file);
|
||||
|
||||
virtual HookManager* create_hm(VirtualMachinePool * vmpool);
|
||||
|
||||
|
@ -68,6 +68,37 @@ protected:
|
||||
PoolTest():pool(0){};
|
||||
virtual ~PoolTest(){};
|
||||
|
||||
/**
|
||||
* Replaces all <REGTIME> elements, padding them with 0
|
||||
*/
|
||||
string fix_regtimes(string& xml)
|
||||
{
|
||||
return fix_time(xml, "REGTIME");
|
||||
}
|
||||
|
||||
string fix_stimes(string& xml)
|
||||
{
|
||||
return fix_time(xml, "STIME");
|
||||
}
|
||||
|
||||
string fix_time(string& xml, string elem_name)
|
||||
{
|
||||
string start = "<" + elem_name + ">";
|
||||
string replacement = "0000000000";
|
||||
size_t pos = 0;
|
||||
|
||||
while( (pos = xml.find(start, pos)) != string::npos )
|
||||
{
|
||||
if ( xml[pos+start.size()] != '0' )
|
||||
{
|
||||
xml.replace( pos+start.size(), replacement.size(), replacement);
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
|
||||
return xml;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
void setUp()
|
||||
@ -180,6 +211,7 @@ public:
|
||||
void drop_and_get()
|
||||
{
|
||||
int oid_0, oid_1;
|
||||
string error_str;
|
||||
|
||||
// Allocate two objects
|
||||
oid_0 = allocate(0);
|
||||
@ -201,7 +233,7 @@ public:
|
||||
obj->lock();
|
||||
|
||||
// Delete it
|
||||
pool->drop(obj);
|
||||
pool->drop(obj, error_str);
|
||||
|
||||
if(obj != 0)
|
||||
{
|
||||
|
11
install.sh
11
install.sh
@ -346,8 +346,8 @@ BIN_FILES="src/nebula/oned \
|
||||
src/cli/onevnet \
|
||||
src/cli/oneuser \
|
||||
src/cli/oneimage \
|
||||
src/cli/onecluster \
|
||||
src/cli/onetemplate \
|
||||
src/cli/onegroup \
|
||||
src/cli/onedb \
|
||||
share/scripts/one \
|
||||
src/authm_mad/oneauth"
|
||||
@ -391,10 +391,10 @@ RUBY_OPENNEBULA_LIB_FILES="src/oca/ruby/OpenNebula/Host.rb \
|
||||
src/oca/ruby/OpenNebula/VirtualNetworkPool.rb \
|
||||
src/oca/ruby/OpenNebula/Image.rb \
|
||||
src/oca/ruby/OpenNebula/ImagePool.rb \
|
||||
src/oca/ruby/OpenNebula/Cluster.rb \
|
||||
src/oca/ruby/OpenNebula/ClusterPool.rb \
|
||||
src/oca/ruby/OpenNebula/Template.rb \
|
||||
src/oca/ruby/OpenNebula/TemplatePool.rb \
|
||||
src/oca/ruby/OpenNebula/Group.rb \
|
||||
src/oca/ruby/OpenNebula/GroupPool.rb \
|
||||
src/oca/ruby/OpenNebula/XMLUtils.rb"
|
||||
|
||||
|
||||
@ -719,8 +719,8 @@ CLI_BIN_FILES="src/cli/onevm \
|
||||
src/cli/onevnet \
|
||||
src/cli/oneuser \
|
||||
src/cli/oneimage \
|
||||
src/cli/onecluster \
|
||||
src/cli/onetemplate"
|
||||
src/cli/onetemplate \
|
||||
src/cli/onegroup"
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Sunstone files
|
||||
@ -829,7 +829,6 @@ SUNSTONE_RUBY_LIB_FILES="src/mad/ruby/CommandManager.rb \
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
MAN_FILES="share/man/oneauth.1.gz \
|
||||
share/man/onecluster.1.gz \
|
||||
share/man/onehost.1.gz \
|
||||
share/man/oneimage.1.gz \
|
||||
share/man/oneuser.1.gz \
|
||||
|
@ -34,7 +34,6 @@ env.Man('occi-compute')
|
||||
env.Man('occi-network')
|
||||
env.Man('occi-storage')
|
||||
env.Man('oneauth')
|
||||
env.Man('onecluster')
|
||||
env.Man('onedb')
|
||||
env.Man('onehost')
|
||||
env.Man('oneimage')
|
||||
|
@ -1,76 +0,0 @@
|
||||
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.37.1.
|
||||
.TH OPENNEBULAPRO "1" "May 2011" "OpenNebulaPro 2.2.0" "User Commands"
|
||||
.SH NAME
|
||||
OpenNebulaPro \- OpenNebula Cluster command
|
||||
.SH SYNOPSIS
|
||||
.B onecluster
|
||||
[\fI<options>\fR] \fI<command> \fR[\fI<parameters>\fR]
|
||||
.SH DESCRIPTION
|
||||
|
||||
This command enables the OpenNebula administrator to manage clusters. The
|
||||
administrator can create, delete, as well as add and remove hosts from them.
|
||||
Any user can list available clusters.
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
\fB\-l\fR, \fB\-\-list\fR x,y,z
|
||||
Selects columns to display with list
|
||||
command
|
||||
.TP
|
||||
\fB\-\-list\-columns\fR
|
||||
Information about the columns available
|
||||
to display, order or filter
|
||||
.TP
|
||||
\fB\-o\fR, \fB\-\-order\fR x,y,z
|
||||
Order by these columns, column starting
|
||||
with \- means decreasing order
|
||||
.TP
|
||||
\fB\-f\fR, \fB\-\-filter\fR x,y,z
|
||||
Filter data. An array is specified
|
||||
with column=value pairs.
|
||||
.TP
|
||||
\fB\-x\fR, \fB\-\-xml\fR
|
||||
Returns xml instead of human readable text
|
||||
.TP
|
||||
\fB\-v\fR, \fB\-\-verbose\fR
|
||||
Tells more information if the command
|
||||
is successful
|
||||
.TP
|
||||
\fB\-h\fR, \fB\-\-help\fR
|
||||
Shows this help message
|
||||
.TP
|
||||
\fB\-\-version\fR
|
||||
Shows version and copyright information
|
||||
.SH COMMANDS
|
||||
.TP
|
||||
\fBcreate\fR (Creates a new cluster)
|
||||
.IP
|
||||
onecluster create clustername
|
||||
.TP
|
||||
\fBdelete\fR (Removes a cluster)
|
||||
.IP
|
||||
onecluster delete <id>
|
||||
.TP
|
||||
\fBlist\fR (Lists all the clusters in the pool)
|
||||
.IP
|
||||
onecluster list
|
||||
.TP
|
||||
\fBaddhost\fR (Add a host to the cluster)
|
||||
.IP
|
||||
onecluster addhost <host_id> <cluster_id>
|
||||
.TP
|
||||
\fBremovehost\fR (Remove a host from the cluster)
|
||||
.IP
|
||||
onecluster removehost <host_id> <cluster_id>
|
||||
.SH COPYRIGHT
|
||||
Copyright 2010\-2011, C12G Labs S.L.
|
||||
.PP
|
||||
Licensed under the C12G Commercial Open\-source License (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License as part
|
||||
of the software distribution.
|
||||
.PP
|
||||
Unless 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.
|
@ -10,7 +10,6 @@ TESTS="$TWD_DIR/vnm/test \
|
||||
$TWD_DIR/scheduler/src/pool/test \
|
||||
$TWD_DIR/common/test \
|
||||
$TWD_DIR/host/test \
|
||||
$TWD_DIR/cluster/test \
|
||||
$TWD_DIR/template/test \
|
||||
$TWD_DIR/image/test \
|
||||
$TWD_DIR/authm/test \
|
||||
@ -18,7 +17,8 @@ TESTS="$TWD_DIR/vnm/test \
|
||||
$TWD_DIR/um/test \
|
||||
$TWD_DIR/lcm/test \
|
||||
$TWD_DIR/pool/test \
|
||||
$TWD_DIR/vm_template/test"
|
||||
$TWD_DIR/vm_template/test \
|
||||
$TWD_DIR/group/test"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# COMMAND LINE PARSING
|
||||
|
@ -46,8 +46,8 @@ void AuthRequest::add_auth(Object ob,
|
||||
case NET: oss << "NET:" ; break;
|
||||
case IMAGE: oss << "IMAGE:" ; break;
|
||||
case USER: oss << "USER:" ; break;
|
||||
case CLUSTER: oss << "CLUSTER:" ; break;
|
||||
case TEMPLATE: oss << "TEMPLATE:" ; break;
|
||||
case GROUP: oss << "GROUP:" ; break;
|
||||
}
|
||||
|
||||
if (op == CREATE || op == INSTANTIATE) //encode the ob_id, it is a template
|
||||
@ -91,9 +91,21 @@ void AuthRequest::add_auth(Object ob,
|
||||
oss << "INFO:" ;
|
||||
break;
|
||||
|
||||
case INFO_POOL:
|
||||
oss << "INFO_POOL:" ;
|
||||
break;
|
||||
|
||||
case INFO_POOL_MINE:
|
||||
oss << "INFO_POOL_MINE:" ;
|
||||
break;
|
||||
|
||||
case INSTANTIATE:
|
||||
oss << "INSTANTIATE:" ;
|
||||
break;
|
||||
|
||||
case CHOWN:
|
||||
oss << "CHOWN:" ;
|
||||
break;
|
||||
}
|
||||
|
||||
oss << owner << ":" << pub;
|
||||
@ -145,8 +157,36 @@ void AuthRequest::add_auth(Object ob,
|
||||
auth = owner == uid;
|
||||
break;
|
||||
|
||||
case INFO: // This is for completeness, as the only INFO existing
|
||||
// is for UserPool, and just oneadmin can see it
|
||||
case INFO:
|
||||
if ( ob != USER ) // User info only for root or owner
|
||||
{
|
||||
auth = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
istringstream iss(ob_id);
|
||||
int ob_id_int;
|
||||
|
||||
iss >> ob_id_int;
|
||||
|
||||
if (ob_id_int == uid)
|
||||
{
|
||||
auth = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case INFO_POOL:
|
||||
if ( ob != USER ) // User pool only for oneadmin
|
||||
{
|
||||
auth = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case INFO_POOL_MINE:
|
||||
auth = true;
|
||||
break;
|
||||
case CHOWN: //true only for oneadmin
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -313,14 +313,14 @@ def get_image_id(name)
|
||||
get_entity_id(name, OpenNebula::ImagePool)
|
||||
end
|
||||
|
||||
def get_cluster_id(name)
|
||||
get_entity_id(name, OpenNebula::ClusterPool)
|
||||
end
|
||||
|
||||
def get_template_id(name)
|
||||
get_entity_id(name, OpenNebula::TemplatePool)
|
||||
end
|
||||
|
||||
def get_group_id(name)
|
||||
get_entity_id(name, OpenNebula::GroupPool)
|
||||
end
|
||||
|
||||
def str_running_time(data)
|
||||
stime=Time.at(data["STIME"].to_i)
|
||||
if data["ETIME"]=="0"
|
||||
|
@ -35,30 +35,38 @@ require 'command_parse'
|
||||
ShowTableUP={
|
||||
:id => {
|
||||
:name => "ID",
|
||||
:desc => "ONE identifier for cluster",
|
||||
:desc => "ONE identifier for group",
|
||||
:size => 4,
|
||||
:proc => lambda {|d,e|
|
||||
d.id
|
||||
:proc => lambda {|d,e|
|
||||
d.id
|
||||
}
|
||||
},
|
||||
:uid => {
|
||||
:name => "OWNER",
|
||||
:desc => "Owner of the group",
|
||||
:size => 5,
|
||||
:proc => lambda {|d,e|
|
||||
d.uid
|
||||
}
|
||||
},
|
||||
:name => {
|
||||
:name => "NAME",
|
||||
:desc => "Name of the cluster",
|
||||
:size => 8,
|
||||
:desc => "Name of the group",
|
||||
:size => 16,
|
||||
:proc => lambda {|d,e|
|
||||
d.name
|
||||
}
|
||||
},
|
||||
|
||||
:default => [:id, :name]
|
||||
|
||||
:default => [:id, :uid, :name]
|
||||
}
|
||||
|
||||
class UPShow
|
||||
def initialize
|
||||
@clusterpool=OpenNebula::ClusterPool.new(get_one_client)
|
||||
@grouppool=OpenNebula::GroupPool.new(get_one_client)
|
||||
@table=ShowTable.new(ShowTableUP)
|
||||
end
|
||||
|
||||
|
||||
def header_up_small
|
||||
scr_bold
|
||||
scr_underline
|
||||
@ -66,9 +74,9 @@ class UPShow
|
||||
scr_restore
|
||||
puts ""
|
||||
end
|
||||
|
||||
|
||||
def list_short(options=nil)
|
||||
res=@clusterpool.info
|
||||
res=@grouppool.info
|
||||
if options
|
||||
@table.columns=options[:columns] if options[:columns]
|
||||
end
|
||||
@ -78,41 +86,33 @@ class UPShow
|
||||
else
|
||||
result=res
|
||||
header_up_small
|
||||
|
||||
puts @table.data_str(@clusterpool, options)
|
||||
|
||||
puts @table.data_str(@grouppool, options)
|
||||
result
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class OneUPParse < CommandParse
|
||||
|
||||
|
||||
COMMANDS_HELP=<<-EOT
|
||||
|
||||
Description:
|
||||
|
||||
This command enables the OpenNebula administrator to manage clusters. The
|
||||
administrator can create, delete, as well as add and remove hosts from them.
|
||||
Any user can list available clusters.
|
||||
This command enables the OpenNebula administrator to manage groups.
|
||||
|
||||
|
||||
Commands:
|
||||
|
||||
* create (Creates a new cluster)
|
||||
onecluster create clustername
|
||||
|
||||
* delete (Removes a cluster)
|
||||
onecluster delete <id>
|
||||
|
||||
* list (Lists all the clusters in the pool)
|
||||
onecluster list
|
||||
* create (Creates a new group)
|
||||
onegroup create groupname
|
||||
|
||||
* delete (Removes a group)
|
||||
onegroup delete <id>
|
||||
|
||||
* list (Lists all the groups in the pool)
|
||||
onegroup list
|
||||
|
||||
* addhost (Add a host to the cluster)
|
||||
onecluster addhost <host_id> <cluster_id>
|
||||
|
||||
* removehost (Remove a host from the cluster)
|
||||
onecluster removehost <host_id> <cluster_id>
|
||||
|
||||
EOT
|
||||
|
||||
def text_commands
|
||||
@ -120,7 +120,7 @@ EOT
|
||||
end
|
||||
|
||||
def text_command_name
|
||||
"onecluster"
|
||||
"onegroup"
|
||||
end
|
||||
|
||||
def list_options
|
||||
@ -141,76 +141,40 @@ command=ARGV.shift
|
||||
case command
|
||||
when "create"
|
||||
check_parameters("create", 1)
|
||||
cluster=OpenNebula::Cluster.new(OpenNebula::Cluster.build_xml, get_one_client)
|
||||
result=cluster.allocate(ARGV[0])
|
||||
|
||||
group=OpenNebula::Group.new(OpenNebula::Group.build_xml, get_one_client)
|
||||
result=group.allocate(ARGV[0])
|
||||
|
||||
if is_successful?(result)
|
||||
puts "ID: " + cluster.id.to_s if ops[:verbose]
|
||||
puts "ID: " + group.id.to_s if ops[:verbose]
|
||||
exit 0
|
||||
end
|
||||
|
||||
|
||||
when "delete"
|
||||
check_parameters("delete", 1)
|
||||
args=expand_args(ARGV)
|
||||
|
||||
args.each do |param|
|
||||
cluster_id=get_cluster_id(param)
|
||||
cluster=OpenNebula::Cluster.new(
|
||||
OpenNebula::Cluster.build_xml(cluster_id), get_one_client)
|
||||
result=cluster.delete
|
||||
group_id=get_group_id(param)
|
||||
group=OpenNebula::Group.new(
|
||||
OpenNebula::Group.build_xml(group_id), get_one_client)
|
||||
result=group.delete
|
||||
if !OpenNebula.is_error?(result)
|
||||
puts "Cluster deleted" if ops[:verbose]
|
||||
puts "Group deleted" if ops[:verbose]
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
when "addhost"
|
||||
check_parameters("addhost", 2)
|
||||
cluster_id=get_cluster_id(ARGV[-1])
|
||||
cluster=OpenNebula::Cluster.new(
|
||||
OpenNebula::Cluster.build_xml(cluster_id), get_one_client)
|
||||
args=expand_args(ARGV[0..-2])
|
||||
|
||||
args.each do |param|
|
||||
host_id=get_host_id(param)
|
||||
|
||||
result=cluster.add_host(host_id)
|
||||
if is_successful?(result)
|
||||
puts "Added HOST to the Cluster" if ops[:verbose]
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
when "removehost"
|
||||
check_parameters("removehost", 2)
|
||||
cluster_id=get_cluster_id(ARGV[-1])
|
||||
cluster=OpenNebula::Cluster.new(
|
||||
OpenNebula::Cluster.build_xml(cluster_id), get_one_client)
|
||||
args=expand_args(ARGV[0..-2])
|
||||
|
||||
args.each do |param|
|
||||
host_id=get_host_id(param)
|
||||
|
||||
result=cluster.remove_host(host_id)
|
||||
if is_successful?(result)
|
||||
puts "Host removed from the Cluster" if ops[:verbose]
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
when "list"
|
||||
if !ops[:xml]
|
||||
uplist=UPShow.new
|
||||
ops[:columns]=ops[:list] if ops[:list]
|
||||
result=uplist.list_short(ops)
|
||||
else
|
||||
clusterpool=OpenNebula::ClusterPool.new(get_one_client)
|
||||
clusterpool.info
|
||||
puts clusterpool.to_xml(true)
|
||||
grouppool=OpenNebula::GroupPool.new(get_one_client)
|
||||
grouppool.info
|
||||
puts grouppool.to_xml(true)
|
||||
end
|
||||
|
||||
|
||||
else
|
||||
oneup_opts.print_help
|
||||
exit -1
|
@ -46,12 +46,19 @@ ShowTableHost={
|
||||
:left => true,
|
||||
:proc => lambda {|d,e| d.name }
|
||||
},
|
||||
# TODO
|
||||
:cid => {
|
||||
:name => "CID",
|
||||
:desc => "Cluster ID",
|
||||
:size => 4,
|
||||
:proc => lambda {|d,e| d.cluster_id }
|
||||
},
|
||||
:cluster => {
|
||||
:name => "CLUSTER",
|
||||
:desc => "Clustername",
|
||||
:size => 8,
|
||||
:left => true,
|
||||
:proc => lambda {|d,e| d.cluster }
|
||||
:proc => lambda { "TODO" }
|
||||
},
|
||||
:rvm => {
|
||||
:name => "RVM",
|
||||
@ -107,7 +114,7 @@ ShowTableHost={
|
||||
},
|
||||
|
||||
|
||||
:default => [:id, :name, :cluster, :rvm, :tcpu, :fcpu, :acpu, :tmem, :fmem, :stat]
|
||||
:default => [:id, :name, :rvm, :tcpu, :fcpu, :acpu, :tmem, :fmem, :stat]
|
||||
}
|
||||
|
||||
class HostShow
|
||||
@ -285,7 +292,10 @@ when "show"
|
||||
|
||||
puts str % ["ID", host.id.to_s]
|
||||
puts str % ["NAME", host.name]
|
||||
puts str % ["CLUSTER", host['CLUSTER']]
|
||||
|
||||
# TODO
|
||||
puts str % ["CLUSTER", "TODO"]
|
||||
# puts str % ["CLUSTER", host['CLUSTER']]
|
||||
puts str % ["STATE", host.state_str]
|
||||
puts str % ["IM_MAD", host['IM_MAD']]
|
||||
puts str % ["VM_MAD", host['VM_MAD']]
|
||||
|
101
src/cli/oneimage
101
src/cli/oneimage
@ -44,7 +44,23 @@ ShowTableImage={
|
||||
:desc => "Name of the owner",
|
||||
:size => 8,
|
||||
:proc => lambda {|d,e|
|
||||
d["USERNAME"]
|
||||
"TODO"
|
||||
}
|
||||
},
|
||||
:uid=> {
|
||||
:name => "UID",
|
||||
:desc => "Id of the owner",
|
||||
:size => 4,
|
||||
:proc => lambda {|d,e|
|
||||
d["UID"]
|
||||
}
|
||||
},
|
||||
:gid=> {
|
||||
:name => "GID",
|
||||
:desc => "Id of the group",
|
||||
:size => 4,
|
||||
:proc => lambda {|d,e|
|
||||
d.gid
|
||||
}
|
||||
},
|
||||
:name => {
|
||||
@ -215,11 +231,8 @@ Commands:
|
||||
* addattr (Add a new image attribute)
|
||||
oneimage addattr <image_id> <attribute_name> <attribute_value>
|
||||
|
||||
* update (Modifies an image attribute)
|
||||
oneimage update <image_id> <attribute_name> <attribute_value>
|
||||
|
||||
* rmattr (Deletes an Image attribute)
|
||||
oneimage rmattr <image_id> <attribute_name>
|
||||
* update (Lets the user edit and replace the image template)
|
||||
oneimage update <image_id>
|
||||
|
||||
* enable (Enabled an Image)
|
||||
oneimage enable <image_id>
|
||||
@ -238,14 +251,21 @@ Commands:
|
||||
|
||||
* nonpersistent (Makes an Image non persistent)
|
||||
oneimage nonpersistent <image_id>
|
||||
|
||||
|
||||
* chown (Changes the Image owner and group)
|
||||
oneimage chown <image_id> <owner_id> [<group_id>]
|
||||
|
||||
* chgrp (Changes the Image group)
|
||||
oneimage chgrp <image_id> <group_id>
|
||||
|
||||
* list (Shows Images in the pool)
|
||||
oneimage list <filter_flag>
|
||||
|
||||
where filter_flag can be
|
||||
a, all --> all the known Images
|
||||
m, mine --> the Images belonging to the user in ONE_AUTH
|
||||
and all the Public Images
|
||||
g, group --> 'mine' plus the Images belonging to the groups
|
||||
the user is member of
|
||||
uid --> Images of the user identified by this uid
|
||||
user --> Images of the user identified by the username
|
||||
|
||||
@ -282,6 +302,8 @@ def get_user_flags
|
||||
when "a", "all"
|
||||
ops[:filter_user]="-2"
|
||||
when "m", "mine"
|
||||
ops[:filter_user]="-3"
|
||||
when "g", "group"
|
||||
ops[:filter_user]="-1"
|
||||
else
|
||||
if !ARGV[0].match(/^[0123456789]+$/)
|
||||
@ -333,29 +355,28 @@ when "register", "create", "add"
|
||||
puts "ID: " + image.id.to_s if ops[:verbose]
|
||||
end
|
||||
|
||||
|
||||
when "update", "addattr"
|
||||
check_parameters("update", 3)
|
||||
when "update"
|
||||
check_parameters("update", 1)
|
||||
image_id=get_image_id(ARGV[0])
|
||||
|
||||
image=OpenNebula::Image.new_with_id(image_id, get_one_client)
|
||||
|
||||
result=image.update(ARGV[1],ARGV[2])
|
||||
rc = image.info
|
||||
if is_successful?(result)
|
||||
puts "Modified image" if ops[:verbose]
|
||||
file = File.open('/tmp/template', "w")
|
||||
file << image.template_str
|
||||
file.close
|
||||
|
||||
system "vim /tmp/template"
|
||||
str = File.read('/tmp/test')
|
||||
|
||||
result = image.update( str )
|
||||
|
||||
if is_successful?(result)
|
||||
puts "Modified image" if ops[:verbose]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
when "rmattr"
|
||||
check_parameters("rmattr", 2)
|
||||
image_id=get_image_id(ARGV[0])
|
||||
|
||||
image=OpenNebula::Image.new_with_id(image_id, get_one_client)
|
||||
|
||||
result=image.remove_attr(ARGV[1])
|
||||
if is_successful?(result)
|
||||
puts "Removed image atrribute" if ops[:verbose]
|
||||
end
|
||||
|
||||
when "enable"
|
||||
check_parameters("enable", 1)
|
||||
image_id=get_image_id(ARGV[0])
|
||||
@ -421,7 +442,35 @@ when "nonpersistent"
|
||||
if is_successful?(result)
|
||||
puts "Image made nonpersistent" if ops[:verbose]
|
||||
end
|
||||
|
||||
|
||||
when "chown"
|
||||
check_parameters("chown", 2)
|
||||
|
||||
image_id = get_image_id(ARGV[0])
|
||||
new_uid = ARGV[1].to_i
|
||||
new_gid = ( ARGV.length > 2 ) ? ARGV[2].to_i : -1
|
||||
|
||||
image = OpenNebula::Image.new_with_id(image_id, get_one_client)
|
||||
|
||||
result = image.chown( new_uid, new_gid )
|
||||
if is_successful?(result)
|
||||
puts "Image user/group changed" if ops[:verbose]
|
||||
end
|
||||
|
||||
when "chgrp"
|
||||
check_parameters("chgrp", 2)
|
||||
|
||||
image_id = get_image_id(ARGV[0])
|
||||
new_uid = -1
|
||||
new_gid = ARGV[1].to_i
|
||||
|
||||
image = OpenNebula::Image.new_with_id(image_id, get_one_client)
|
||||
|
||||
result = image.chown( new_uid, new_gid )
|
||||
if is_successful?(result)
|
||||
puts "Image group changed" if ops[:verbose]
|
||||
end
|
||||
|
||||
when "list"
|
||||
ops.merge!(get_user_flags)
|
||||
if !ops[:xml]
|
||||
|
@ -44,7 +44,23 @@ ShowTableTemplate={
|
||||
:desc => "Name of the owner",
|
||||
:size => 8,
|
||||
:proc => lambda {|d,e|
|
||||
d["USERNAME"]
|
||||
"TODO"
|
||||
}
|
||||
},
|
||||
:uid=> {
|
||||
:name => "UID",
|
||||
:desc => "Id of the owner",
|
||||
:size => 4,
|
||||
:proc => lambda {|d,e|
|
||||
d["UID"]
|
||||
}
|
||||
},
|
||||
:gid=> {
|
||||
:name => "GID",
|
||||
:desc => "Id of the group",
|
||||
:size => 4,
|
||||
:proc => lambda {|d,e|
|
||||
d.gid
|
||||
}
|
||||
},
|
||||
:name => {
|
||||
@ -164,14 +180,11 @@ Commands:
|
||||
|
||||
file is a file name where the Template description is located
|
||||
|
||||
* addattr (Add a new Template attribute)
|
||||
onetemplate addattr <template_id> <attribute_name> <attribute_value>
|
||||
* instantiate (Creates a VM instance from a Template)
|
||||
onetemplate instantiate <template_id>
|
||||
|
||||
* update (Modifies a Template attribute)
|
||||
onetemplate update <template_id> <attribute_name> <attribute_value>
|
||||
|
||||
* rmattr (Deletes a Template attribute)
|
||||
onetemplate rmattr <template_id> <attribute_name>
|
||||
* update (Lets the user edit and replace the Template contents)
|
||||
onetemplate update <template_id>
|
||||
|
||||
* publish (Publish a Template)
|
||||
onetemplate publish <template_id>
|
||||
@ -179,13 +192,20 @@ Commands:
|
||||
* unpublish (Unpublish an Template)
|
||||
onetemplate unpublish <template_id>
|
||||
|
||||
* chown (Changes the Template owner and group)
|
||||
onetemplate chown <template_id> <owner_id> [<group_id>]
|
||||
|
||||
* chgrp (Changes the Template group)
|
||||
onetemplate chgrp <template_id> <group_id>
|
||||
|
||||
* list (Shows Templates in the pool)
|
||||
onetemplate list <filter_flag>
|
||||
|
||||
where filter_flag can be
|
||||
a, all --> all the known Templates
|
||||
m, mine --> the Templates belonging to the user in ONE_AUTH
|
||||
and all the Public Templates
|
||||
g, group --> 'mine' plus the Templates belonging to the groups
|
||||
the user is member of
|
||||
uid --> Templates of the user identified by this uid
|
||||
user --> Templates of the user identified by the username
|
||||
|
||||
@ -222,6 +242,8 @@ def get_user_flags
|
||||
when "a", "all"
|
||||
ops[:filter_user]="-2"
|
||||
when "m", "mine"
|
||||
ops[:filter_user]="-3"
|
||||
when "g", "group"
|
||||
ops[:filter_user]="-1"
|
||||
else
|
||||
if !ARGV[0].match(/^[0123456789]+$/)
|
||||
@ -274,27 +296,19 @@ when "create", "register", "add"
|
||||
exit 0
|
||||
end
|
||||
|
||||
when "update", "addattr"
|
||||
check_parameters("update", 3)
|
||||
when "instantiate"
|
||||
check_parameters("instantiate", 1)
|
||||
template_id = get_template_id(ARGV[0])
|
||||
|
||||
template = OpenNebula::Template.new_with_id(template_id, get_one_client)
|
||||
|
||||
result = template.update(ARGV[1],ARGV[2])
|
||||
result = template.instantiate
|
||||
if is_successful?(result)
|
||||
puts "Modified template" if ops[:verbose]
|
||||
puts "Template instantiated." if ops[:verbose]
|
||||
end
|
||||
|
||||
when "rmattr"
|
||||
check_parameters("rmattr", 2)
|
||||
template_id = get_template_id(ARGV[0])
|
||||
|
||||
template = OpenNebula::Template.new_with_id(template_id, get_one_client)
|
||||
|
||||
result = template.remove_attr(ARGV[1])
|
||||
if is_successful?(result)
|
||||
puts "Removed template attribute" if ops[:verbose]
|
||||
end
|
||||
when "update"
|
||||
puts "TODO"
|
||||
|
||||
when "publish"
|
||||
check_parameters("publish", 1)
|
||||
@ -318,6 +332,34 @@ when "unpublish"
|
||||
puts "Template unpublished" if ops[:verbose]
|
||||
end
|
||||
|
||||
when "chown"
|
||||
check_parameters("chown", 2)
|
||||
|
||||
obj_id = get_template_id(ARGV[0])
|
||||
new_uid = ARGV[1].to_i
|
||||
new_gid = ( ARGV.length > 2 ) ? ARGV[2].to_i : -1
|
||||
|
||||
obj = OpenNebula::Template.new_with_id(obj_id, get_one_client)
|
||||
|
||||
result = obj.chown( new_uid, new_gid )
|
||||
if is_successful?(result)
|
||||
puts "Template user/group changed" if ops[:verbose]
|
||||
end
|
||||
|
||||
when "chgrp"
|
||||
check_parameters("chgrp", 2)
|
||||
|
||||
obj_id = get_template_id(ARGV[0])
|
||||
new_uid = -1
|
||||
new_gid = ARGV[1].to_i
|
||||
|
||||
obj = OpenNebula::Template.new_with_id(obj_id, get_one_client)
|
||||
|
||||
result = obj.chown( new_uid, new_gid )
|
||||
if is_successful?(result)
|
||||
puts "Template group changed" if ops[:verbose]
|
||||
end
|
||||
|
||||
when "list"
|
||||
ops.merge!(get_user_flags)
|
||||
if !ops[:xml]
|
||||
|
@ -39,6 +39,14 @@ ShowTableUP={
|
||||
:size => 4,
|
||||
:proc => lambda {|d,e| d.id }
|
||||
},
|
||||
:gid=> {
|
||||
:name => "GID",
|
||||
:desc => "Id of the group",
|
||||
:size => 4,
|
||||
:proc => lambda {|d,e|
|
||||
d.gid
|
||||
}
|
||||
},
|
||||
:user => {
|
||||
:name => "USER",
|
||||
:desc => "name of the user",
|
||||
@ -54,7 +62,7 @@ ShowTableUP={
|
||||
:proc => lambda {|d,e| d['PASSWORD'] }
|
||||
},
|
||||
|
||||
:default => [:id, :user, :password]
|
||||
:default => [:id, :gid, :user, :password]
|
||||
}
|
||||
|
||||
class UPShow
|
||||
@ -116,6 +124,14 @@ Commands:
|
||||
* passwd (Changes the given user's password)
|
||||
oneuser passwd <id> password
|
||||
|
||||
* chgrp (Changes the User group)
|
||||
oneuser chgrp <id> <group_id>
|
||||
|
||||
* addgroup (Adds a secondary group)
|
||||
oneuser addgroup <id> <group_id>
|
||||
|
||||
* delgroup (Deletes a secondary group. Fails if the group is the main one)
|
||||
oneuser delgroup <id> <group_id>
|
||||
|
||||
Information Columns:
|
||||
|
||||
@ -257,6 +273,46 @@ when "passwd"
|
||||
puts
|
||||
end
|
||||
|
||||
when "chgrp"
|
||||
check_parameters("chgrp", 2)
|
||||
|
||||
obj_id = get_user_id(ARGV[0])
|
||||
new_gid = ARGV[1].to_i
|
||||
|
||||
obj = OpenNebula::User.new_with_id(obj_id, get_one_client)
|
||||
|
||||
result = obj.chgrp( new_gid )
|
||||
if is_successful?(result)
|
||||
puts "User group changed" if ops[:verbose]
|
||||
end
|
||||
|
||||
when "addgroup"
|
||||
check_parameters("addgroup", 2)
|
||||
|
||||
obj_id = get_user_id(ARGV[0])
|
||||
new_gid = ARGV[1].to_i
|
||||
|
||||
obj = OpenNebula::User.new_with_id(obj_id, get_one_client)
|
||||
|
||||
result = obj.addgroup( new_gid )
|
||||
if is_successful?(result)
|
||||
puts "User group added" if ops[:verbose]
|
||||
end
|
||||
|
||||
when "delgroup"
|
||||
check_parameters("delgroup", 2)
|
||||
|
||||
obj_id = get_user_id(ARGV[0])
|
||||
new_gid = ARGV[1].to_i
|
||||
|
||||
obj = OpenNebula::User.new_with_id(obj_id, get_one_client)
|
||||
|
||||
result = obj.delgroup( new_gid )
|
||||
if is_successful?(result)
|
||||
puts "User group deleted" if ops[:verbose]
|
||||
end
|
||||
|
||||
|
||||
when "list"
|
||||
if !ops[:xml]
|
||||
uplist=UPShow.new
|
||||
|
105
src/cli/onevm
105
src/cli/onevm
@ -39,6 +39,22 @@ ShowTableVM={
|
||||
:size => 5,
|
||||
:proc => lambda {|d,e| d.id }
|
||||
},
|
||||
:uid=> {
|
||||
:name => "UID",
|
||||
:desc => "Id of the owner",
|
||||
:size => 4,
|
||||
:proc => lambda {|d,e|
|
||||
d["UID"]
|
||||
}
|
||||
},
|
||||
:gid=> {
|
||||
:name => "GID",
|
||||
:desc => "Id of the group",
|
||||
:size => 4,
|
||||
:proc => lambda {|d,e|
|
||||
d.gid
|
||||
}
|
||||
},
|
||||
:name => {
|
||||
:name => "NAME",
|
||||
:desc => "Name of the domain",
|
||||
@ -52,7 +68,7 @@ ShowTableVM={
|
||||
:desc => "Name of the owner",
|
||||
:size => 8,
|
||||
:proc => lambda {|d,e|
|
||||
d["USERNAME"]
|
||||
"TODO"
|
||||
}
|
||||
},
|
||||
:stat => {
|
||||
@ -318,15 +334,9 @@ machine with the functionality present in onevm.
|
||||
Commands:
|
||||
|
||||
* create (Submits a new virtual machine, adding it to the ONE VM pool)
|
||||
onevm create [OPTION] {<template-file-path>, <template-id>, <template-name>}
|
||||
onevm create [OPTION] <template-file-path>
|
||||
|
||||
<template-file-path> is a file name where the VM description is located.
|
||||
<template-id> is the numeric ID of a registered template (using onetemplate)
|
||||
<template-name> is the name of a registered template (using onetemplate)
|
||||
|
||||
OPTION: -n STRING, --name=STRING
|
||||
Replaces the NAME attribute if the VM is being created from a registered
|
||||
Template
|
||||
|
||||
* deploy (Starts an existing VM in an specific host)
|
||||
onevm deploy <vm_id> <host_id>
|
||||
@ -400,13 +410,22 @@ Commands:
|
||||
|
||||
States: ANY, except SUSPENDED or DONE
|
||||
|
||||
* chown (Changes the VM owner and group)
|
||||
onevm chown <vm_id> <owner_id> [<group_id>]
|
||||
|
||||
* chgrp (Changes the VM group)
|
||||
onevm chgrp <vm_id> <group_id>
|
||||
|
||||
* list (Shows VMs in the pool)
|
||||
onevm list <filter_flag>
|
||||
where filter_flag can be
|
||||
a, all --> all the known VMs
|
||||
m, mine --> the VMs belonging to the user in ONE_AUTH
|
||||
uid --> VMs of the user identified by this uid
|
||||
user --> VMs of the user identified by the username
|
||||
|
||||
where filter_flag can be
|
||||
a, all --> all the known VMs
|
||||
m, mine --> the VMs belonging to the user in ONE_AUTH
|
||||
g, group --> 'mine' plus the VMs belonging to the groups
|
||||
the user is member of
|
||||
uid --> VMs of the user identified by this uid
|
||||
user --> VMs of the user identified by the username
|
||||
|
||||
* show (Gets information about a specific VM)
|
||||
onevm show <vm_id>
|
||||
@ -483,6 +502,8 @@ def get_user_flags
|
||||
when "a", "all"
|
||||
ops[:filter_user]="-2"
|
||||
when "m", "mine"
|
||||
ops[:filter_user]="-3"
|
||||
when "g", "group"
|
||||
ops[:filter_user]="-1"
|
||||
else
|
||||
if !ARGV[0].match(/^[0123456789]+$/)
|
||||
@ -512,32 +533,12 @@ when "submit", "create"
|
||||
check_parameters("create", 1)
|
||||
vm=OpenNebula::VirtualMachine.new(
|
||||
OpenNebula::VirtualMachine.build_xml, get_one_client)
|
||||
|
||||
template = ""
|
||||
success = false
|
||||
|
||||
if( File.file?(ARGV[0]) )
|
||||
# argument is a file path
|
||||
begin
|
||||
template = File.read(ARGV[0])
|
||||
success = true
|
||||
rescue
|
||||
result = OpenNebula::Error.new("Can not read template: #{ARGV[0]}")
|
||||
end
|
||||
else
|
||||
# argument could be a template ID or a template name
|
||||
template_id = get_template_id(ARGV[0])
|
||||
|
||||
template = "TEMPLATE_ID = #{template_id}"
|
||||
template << "\nNAME = #{ops[:vm_name]}" if ops[:vm_name]
|
||||
|
||||
success = true
|
||||
begin
|
||||
template=File.read(ARGV[0])
|
||||
result=vm.allocate(template)
|
||||
rescue
|
||||
result=OpenNebula::Error.new("Can not read template: #{ARGV[0]}")
|
||||
end
|
||||
|
||||
if( success )
|
||||
result = vm.allocate(template)
|
||||
end
|
||||
|
||||
if is_successful?(result)
|
||||
puts "ID: " + vm.id.to_s if ops[:verbose]
|
||||
exit 0
|
||||
@ -749,6 +750,34 @@ when "resubmit"
|
||||
end
|
||||
end
|
||||
|
||||
when "chown"
|
||||
check_parameters("chown", 2)
|
||||
|
||||
obj_id = get_vm_id(ARGV[0])
|
||||
new_uid = ARGV[1].to_i
|
||||
new_gid = ( ARGV.length > 2 ) ? ARGV[2].to_i : -1
|
||||
|
||||
obj = OpenNebula::VirtualMachine.new_with_id(obj_id, get_one_client)
|
||||
|
||||
result = obj.chown( new_uid, new_gid )
|
||||
if is_successful?(result)
|
||||
puts "VM user/group changed" if ops[:verbose]
|
||||
end
|
||||
|
||||
when "chgrp"
|
||||
check_parameters("chgrp", 2)
|
||||
|
||||
obj_id = get_vm_id(ARGV[0])
|
||||
new_uid = -1
|
||||
new_gid = ARGV[1].to_i
|
||||
|
||||
obj = OpenNebula::VirtualMachine.new_with_id(obj_id, get_one_client)
|
||||
|
||||
result = obj.chown( new_uid, new_gid )
|
||||
if is_successful?(result)
|
||||
puts "VM group changed" if ops[:verbose]
|
||||
end
|
||||
|
||||
when "list"
|
||||
ops.merge!(get_user_flags)
|
||||
if !ops[:xml]
|
||||
|
@ -51,7 +51,23 @@ ShowTableVN={
|
||||
:desc => "Username of the virtual network owner",
|
||||
:size => 8,
|
||||
:left => true,
|
||||
:proc => lambda {|d,e| d["USERNAME"] }
|
||||
:proc => lambda {|d,e| "TODO" }
|
||||
},
|
||||
:uid=> {
|
||||
:name => "UID",
|
||||
:desc => "Id of the owner",
|
||||
:size => 4,
|
||||
:proc => lambda {|d,e|
|
||||
d["UID"]
|
||||
}
|
||||
},
|
||||
:gid=> {
|
||||
:name => "GID",
|
||||
:desc => "Id of the group",
|
||||
:size => 4,
|
||||
:proc => lambda {|d,e|
|
||||
d.gid
|
||||
}
|
||||
},
|
||||
:type => {
|
||||
:name => "TYPE",
|
||||
@ -170,15 +186,22 @@ Commands:
|
||||
* rmleases (Removes a lease fom the virtual network)
|
||||
onevnet rmleases <network_id> <IP>
|
||||
|
||||
* chown (Changes the virtual network owner and group)
|
||||
onevnet chown <network_id> <owner_id> [<group_id>]
|
||||
|
||||
* chgrp (Changes the virtual network group)
|
||||
onevnet chgrp <network_id> <group_id>
|
||||
|
||||
* list (Lists virtual networks in the pool)
|
||||
onevnet list <filter_flag>
|
||||
where filter_flag can be
|
||||
a, all : all the known VNs
|
||||
m, mine : the VNs belonging to the user in ONE_AUTH
|
||||
and all the Public VNs
|
||||
uid : VNs of the user identified by this uid
|
||||
user : VNs of the user identified by the username
|
||||
|
||||
|
||||
where filter_flag can be
|
||||
a, all --> all the known VNets
|
||||
m, mine --> the VNets belonging to the user in ONE_AUTH
|
||||
g, group --> 'mine' plus the VNets belonging to the groups
|
||||
the user is member of
|
||||
uid --> VNets of the user identified by this uid
|
||||
user --> VNets of the user identified by the username
|
||||
|
||||
Information columns:
|
||||
|
||||
@ -325,12 +348,42 @@ when "rmleases"
|
||||
puts "Leases removed" if ops[:verbose]
|
||||
end
|
||||
|
||||
when "chown"
|
||||
check_parameters("chown", 2)
|
||||
|
||||
obj_id = get_vn_id(ARGV[0])
|
||||
new_uid = ARGV[1].to_i
|
||||
new_gid = ( ARGV.length > 2 ) ? ARGV[2].to_i : -1
|
||||
|
||||
obj = OpenNebula::VirtualNetwork.new_with_id(obj_id, get_one_client)
|
||||
|
||||
result = obj.chown( new_uid, new_gid )
|
||||
if is_successful?(result)
|
||||
puts "Virtual Network user/group changed" if ops[:verbose]
|
||||
end
|
||||
|
||||
when "chgrp"
|
||||
check_parameters("chgrp", 2)
|
||||
|
||||
obj_id = get_vn_id(ARGV[0])
|
||||
new_uid = -1
|
||||
new_gid = ARGV[1].to_i
|
||||
|
||||
obj = OpenNebula::VirtualNetwork.new_with_id(obj_id, get_one_client)
|
||||
|
||||
result = obj.chown( new_uid, new_gid )
|
||||
if is_successful?(result)
|
||||
puts "Virtual Network group changed" if ops[:verbose]
|
||||
end
|
||||
|
||||
when "list"
|
||||
if ARGV[0]
|
||||
case ARGV[0]
|
||||
when "a", "all"
|
||||
filter_flag="-2"
|
||||
when "m", "mine"
|
||||
filter_flag="-3"
|
||||
when "g", "group"
|
||||
filter_flag="-1"
|
||||
else
|
||||
if !ARGV[0].match(/^[0123456789]+$/)
|
||||
|
@ -318,7 +318,7 @@ private
|
||||
end
|
||||
|
||||
def render_launch_time(vm)
|
||||
return "<launchTime>#{Time.at(vm[:stime].to_i).xmlschema}</launchTime>"
|
||||
return "<launchTime>#{Time.at(vm["STIME"].to_i).xmlschema}</launchTime>"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1,150 +0,0 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* 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 "ClusterPool.h"
|
||||
#include "Nebula.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
const string ClusterPool::DEFAULT_CLUSTER_NAME = "default";
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
ClusterPool::ClusterPool(SqlDB * db):PoolSQL(db, Cluster::table)
|
||||
{
|
||||
// lastOID is set in PoolSQL::init_cb
|
||||
if (get_lastOID() == -1)
|
||||
{
|
||||
int rc;
|
||||
Cluster * cluster;
|
||||
string error_str;
|
||||
|
||||
// Build a new Cluster object
|
||||
cluster = new Cluster(0, ClusterPool::DEFAULT_CLUSTER_NAME);
|
||||
|
||||
// Insert the Object in the pool
|
||||
rc = PoolSQL::allocate(cluster, error_str);
|
||||
|
||||
if(rc != 0)
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
oss << "Error trying to create default cluster: " << error_str;
|
||||
NebulaLog::log("CLUSTER",Log::ERROR,oss);
|
||||
|
||||
throw runtime_error(oss.str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int ClusterPool::allocate(int * oid, string name, string& error_str)
|
||||
{
|
||||
Cluster * cluster;
|
||||
ostringstream oss;
|
||||
|
||||
if ( name.empty() )
|
||||
{
|
||||
goto error_name;
|
||||
}
|
||||
|
||||
// Check for duplicates
|
||||
cluster = get(name, false);
|
||||
|
||||
if( cluster != 0 )
|
||||
{
|
||||
goto error_duplicated;
|
||||
}
|
||||
|
||||
// Build a new Cluster object
|
||||
cluster = new Cluster(-1, name);
|
||||
|
||||
// Insert the Object in the pool
|
||||
*oid = PoolSQL::allocate(cluster, error_str);
|
||||
|
||||
return *oid;
|
||||
|
||||
|
||||
error_name:
|
||||
oss << "NAME cannot be empty.";
|
||||
goto error_common;
|
||||
|
||||
error_duplicated:
|
||||
oss << "NAME is already taken by CLUSTER " << cluster->get_oid() << ".";
|
||||
|
||||
error_common:
|
||||
*oid = -1;
|
||||
error_str = oss.str();
|
||||
|
||||
return *oid;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int ClusterPool::drop(Cluster * cluster)
|
||||
{
|
||||
int rc;
|
||||
|
||||
Host* host;
|
||||
vector<int> hids;
|
||||
vector<int>::iterator hid_it;
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
HostPool * hpool = nd.get_hpool();
|
||||
|
||||
string cluster_name = cluster->get_name();
|
||||
string where = "cluster = '" + cluster_name + "'";
|
||||
|
||||
// Return error if cluster is 'default'
|
||||
if( cluster->get_oid() == 0 )
|
||||
{
|
||||
NebulaLog::log("CLUSTER",Log::WARNING,
|
||||
"Default cluster cannot be deleted.");
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = cluster->drop(db);
|
||||
|
||||
// Move the hosts assigned to the deleted cluster to the default one
|
||||
if( rc == 0 )
|
||||
{
|
||||
hpool->search(hids, where);
|
||||
|
||||
for ( hid_it=hids.begin() ; hid_it < hids.end(); hid_it++ )
|
||||
{
|
||||
host = hpool->get(*hid_it, true);
|
||||
|
||||
if ( host == 0 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
set_default_cluster(host);
|
||||
|
||||
hpool->update(host);
|
||||
|
||||
host->unlock();
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
@ -1,415 +0,0 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* 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 <string>
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "ClusterPool.h"
|
||||
#include "PoolTest.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
const string names[] = {"cluster_a", "Second cluster"};
|
||||
|
||||
const string xmls[] =
|
||||
{
|
||||
"<CLUSTER><ID>1</ID><NAME>cluster_a</NAME></CLUSTER>",
|
||||
"<CLUSTER><ID>2</ID><NAME>Second cluster</NAME></CLUSTER>"
|
||||
};
|
||||
|
||||
const string cluster_default =
|
||||
"<CLUSTER><ID>0</ID><NAME>default</NAME></CLUSTER>";
|
||||
|
||||
const string cluster_xml_dump =
|
||||
"<CLUSTER_POOL><CLUSTER><ID>0</ID><NAME>default</NAME></CLUSTER><CLUSTER><ID>1</ID><NAME>cluster_a</NAME></CLUSTER><CLUSTER><ID>3</ID><NAME>cluster_c</NAME></CLUSTER><CLUSTER><ID>4</ID><NAME>cluster_d</NAME></CLUSTER></CLUSTER_POOL>";
|
||||
|
||||
const string host_0_cluster =
|
||||
"<HOST><ID>0</ID><NAME>Host one</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>cluster_a</CLUSTER><HOST_SHARE><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST>";
|
||||
|
||||
const string host_0_default =
|
||||
"<HOST><ID>0</ID><NAME>Host one</NAME><STATE>0</STATE>"
|
||||
"<IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD>"
|
||||
"<LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE>"
|
||||
"<DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE>"
|
||||
"<MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CPU>"
|
||||
"<FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU>"
|
||||
"<USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU>"
|
||||
"<RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST>";
|
||||
|
||||
/* ************************************************************************* */
|
||||
/* ************************************************************************* */
|
||||
|
||||
|
||||
#include "NebulaTest.h"
|
||||
|
||||
class NebulaTestCluster: public NebulaTest
|
||||
{
|
||||
public:
|
||||
NebulaTestCluster():NebulaTest()
|
||||
{
|
||||
NebulaTest::the_tester = this;
|
||||
|
||||
need_host_pool = true;
|
||||
need_cluster_pool= true;
|
||||
}
|
||||
};
|
||||
|
||||
class ClusterPoolTest : public PoolTest
|
||||
{
|
||||
CPPUNIT_TEST_SUITE (ClusterPoolTest);
|
||||
|
||||
// Not all tests from PoolTest can be used. Because
|
||||
// of the initial default cluster added to the DB, the
|
||||
// oid_assignment would fail.
|
||||
CPPUNIT_TEST (get_from_cache);
|
||||
CPPUNIT_TEST (get_from_db);
|
||||
CPPUNIT_TEST (wrong_get);
|
||||
CPPUNIT_TEST (drop_and_get);
|
||||
|
||||
CPPUNIT_TEST (name_pool);
|
||||
|
||||
CPPUNIT_TEST (duplicates);
|
||||
CPPUNIT_TEST (set_cluster);
|
||||
CPPUNIT_TEST (remove_cluster);
|
||||
CPPUNIT_TEST (delete_cluster);
|
||||
CPPUNIT_TEST (dump);
|
||||
|
||||
CPPUNIT_TEST_SUITE_END ();
|
||||
|
||||
protected:
|
||||
|
||||
NebulaTestCluster * tester;
|
||||
HostPool * hpool;
|
||||
ClusterPool * cpool;
|
||||
|
||||
|
||||
|
||||
void bootstrap(SqlDB* db)
|
||||
{
|
||||
// setUp overwritten
|
||||
};
|
||||
|
||||
PoolSQL* create_pool(SqlDB* db)
|
||||
{
|
||||
// setUp overwritten
|
||||
return cpool;
|
||||
};
|
||||
|
||||
int allocate(int index)
|
||||
{
|
||||
int oid;
|
||||
string err;
|
||||
|
||||
return cpool->allocate(&oid, names[index], err);
|
||||
};
|
||||
|
||||
void check(int index, PoolObjectSQL* obj)
|
||||
{
|
||||
Cluster * cluster = static_cast<Cluster *>(obj);
|
||||
|
||||
CPPUNIT_ASSERT( obj != 0 );
|
||||
|
||||
string xml_str = "";
|
||||
string name = cluster->get_name();
|
||||
|
||||
CPPUNIT_ASSERT( name == names[index] );
|
||||
|
||||
// Get the xml
|
||||
cluster->to_xml(xml_str);
|
||||
|
||||
// A little help for debugging
|
||||
/*
|
||||
if( xml_str != xmls[index] )
|
||||
{
|
||||
cout << endl << xml_str << endl << "========"
|
||||
<< endl << xmls[index];
|
||||
}
|
||||
//*/
|
||||
CPPUNIT_ASSERT( xml_str == xmls[index]);
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Allocates a Host.
|
||||
*/
|
||||
void init_hp()
|
||||
{
|
||||
int oid;
|
||||
string err;
|
||||
|
||||
// Allocate a host
|
||||
oid = hpool->allocate(&oid, "Host one","im_mad","vmm_mad", "tm_mad", err);
|
||||
CPPUNIT_ASSERT(oid == 0);
|
||||
|
||||
hpool->clean();
|
||||
};
|
||||
|
||||
public:
|
||||
ClusterPoolTest()
|
||||
{
|
||||
xmlInitParser();
|
||||
};
|
||||
|
||||
~ClusterPoolTest()
|
||||
{
|
||||
xmlCleanupParser();
|
||||
};
|
||||
|
||||
void setUp()
|
||||
{
|
||||
create_db();
|
||||
|
||||
tester = new NebulaTestCluster();
|
||||
|
||||
Nebula& neb = Nebula::instance();
|
||||
neb.start();
|
||||
|
||||
hpool = neb.get_hpool();
|
||||
cpool = neb.get_cpool();
|
||||
|
||||
pool = cpool;
|
||||
};
|
||||
|
||||
void tearDown()
|
||||
{
|
||||
delete_db();
|
||||
|
||||
delete tester;
|
||||
};
|
||||
|
||||
/* ********************************************************************* */
|
||||
/* ********************************************************************* */
|
||||
|
||||
// Test intended to check the PoolSQL name index functionallity
|
||||
void name_pool()
|
||||
{
|
||||
Cluster * cluster;
|
||||
int oid;
|
||||
string err;
|
||||
|
||||
|
||||
// Allocate some clusters
|
||||
cpool->allocate(&oid, "name_1", err);
|
||||
CPPUNIT_ASSERT( oid == 1 );
|
||||
|
||||
cpool->allocate(&oid, "name_2", err);
|
||||
CPPUNIT_ASSERT( oid == 2 );
|
||||
|
||||
cpool->allocate(&oid, "name_3", err);
|
||||
CPPUNIT_ASSERT( oid == 3 );
|
||||
|
||||
// Clean the cache
|
||||
cpool->clean();
|
||||
|
||||
cpool->allocate(&oid, "name_4", err);
|
||||
CPPUNIT_ASSERT( oid == 4 );
|
||||
|
||||
cpool->allocate(&oid, "name_5", err);
|
||||
CPPUNIT_ASSERT( oid == 5 );
|
||||
|
||||
// Cluster names 0-3 should be unknown, and 4-5 cached
|
||||
// Ask for a cached object
|
||||
cluster = cpool->get("name_5", false);
|
||||
CPPUNIT_ASSERT( cluster != 0 );
|
||||
CPPUNIT_ASSERT( cluster->get_oid() == 5 );
|
||||
CPPUNIT_ASSERT( cluster->get_name() == "name_5" );
|
||||
|
||||
// Ask for non-cached object
|
||||
cluster = cpool->get("name_2", false);
|
||||
CPPUNIT_ASSERT( cluster != 0 );
|
||||
CPPUNIT_ASSERT( cluster->get_oid() == 2 );
|
||||
CPPUNIT_ASSERT( cluster->get_name() == "name_2" );
|
||||
|
||||
// Ask for non-existing object
|
||||
cluster = cpool->get("name_X", false);
|
||||
CPPUNIT_ASSERT( cluster == 0 );
|
||||
};
|
||||
|
||||
/* ********************************************************************* */
|
||||
|
||||
void duplicates()
|
||||
{
|
||||
int rc, oid;
|
||||
string err;
|
||||
|
||||
// Allocate a cluster.
|
||||
rc = cpool->allocate(&oid, names[1], err);
|
||||
CPPUNIT_ASSERT( oid == 1 );
|
||||
CPPUNIT_ASSERT( oid == rc );
|
||||
|
||||
// Try to allocate twice the same cluster, should fail
|
||||
rc = cpool->allocate(&oid, names[1], err);
|
||||
CPPUNIT_ASSERT( rc == -1 );
|
||||
CPPUNIT_ASSERT( oid == rc );
|
||||
}
|
||||
|
||||
/* ********************************************************************* */
|
||||
|
||||
void set_cluster()
|
||||
{
|
||||
Host* host;
|
||||
int rc;
|
||||
string xml_str, err;
|
||||
|
||||
init_hp();
|
||||
|
||||
host = hpool->get(0, false);
|
||||
CPPUNIT_ASSERT(host != 0);
|
||||
|
||||
rc = host->set_cluster("cluster_a");
|
||||
CPPUNIT_ASSERT( rc == 0 );
|
||||
|
||||
hpool->update(host);
|
||||
|
||||
host->to_xml(xml_str);
|
||||
CPPUNIT_ASSERT( xml_str == host_0_cluster);
|
||||
}
|
||||
|
||||
/* ********************************************************************* */
|
||||
|
||||
void remove_cluster()
|
||||
{
|
||||
Host* host;
|
||||
|
||||
int rc;
|
||||
string xml_str;
|
||||
|
||||
init_hp();
|
||||
|
||||
host = hpool->get(0, false);
|
||||
CPPUNIT_ASSERT(host != 0);
|
||||
|
||||
// Set cluster
|
||||
rc = host->set_cluster("cluster_a");
|
||||
CPPUNIT_ASSERT( rc == 0 );
|
||||
|
||||
hpool->update(host);
|
||||
|
||||
host->to_xml(xml_str);
|
||||
CPPUNIT_ASSERT( xml_str == host_0_cluster);
|
||||
|
||||
// Remove from the cluster
|
||||
rc = cpool->set_default_cluster(host);
|
||||
CPPUNIT_ASSERT( rc == 0 );
|
||||
|
||||
hpool->update(host);
|
||||
|
||||
// The host should have been moved to the default cluster
|
||||
|
||||
host = hpool->get(0, false);
|
||||
CPPUNIT_ASSERT(host != 0);
|
||||
|
||||
host->to_xml(xml_str);
|
||||
CPPUNIT_ASSERT( xml_str == host_0_default);
|
||||
}
|
||||
|
||||
/* ********************************************************************* */
|
||||
|
||||
void delete_cluster()
|
||||
{
|
||||
Host * host;
|
||||
Cluster * cluster;
|
||||
|
||||
int rc, oid;
|
||||
string xml_str;
|
||||
|
||||
init_hp();
|
||||
host = hpool->get(0, false);
|
||||
CPPUNIT_ASSERT(host != 0);
|
||||
|
||||
// Allocate a cluster
|
||||
oid = allocate(0);
|
||||
CPPUNIT_ASSERT(oid == 1);
|
||||
|
||||
cluster = cpool->get(1, false);
|
||||
|
||||
// Set cluster
|
||||
rc = host->set_cluster(cluster->get_name());
|
||||
CPPUNIT_ASSERT( rc == 0 );
|
||||
|
||||
hpool->update(host);
|
||||
|
||||
host->to_xml(xml_str);
|
||||
CPPUNIT_ASSERT( xml_str == host_0_cluster);
|
||||
|
||||
// Delete the cluster
|
||||
rc = cpool->drop(cluster);
|
||||
CPPUNIT_ASSERT( rc == 0 );
|
||||
|
||||
// The host should have been moved to the default cluster
|
||||
host = hpool->get(0, false);
|
||||
host->to_xml(xml_str);
|
||||
/*
|
||||
if( xml_str != host_0_default )
|
||||
{
|
||||
cout << endl << xml_str << endl << "========"
|
||||
<< endl << host_0_default;
|
||||
}
|
||||
//*/
|
||||
CPPUNIT_ASSERT( xml_str == host_0_default);
|
||||
}
|
||||
|
||||
/* ********************************************************************* */
|
||||
|
||||
void dump()
|
||||
{
|
||||
Cluster * cluster;
|
||||
int oid, rc;
|
||||
ostringstream oss;
|
||||
string err;
|
||||
|
||||
// Allocate some clusters
|
||||
rc = cpool->allocate(&oid, "cluster_a", err);
|
||||
CPPUNIT_ASSERT( rc == 1 );
|
||||
|
||||
rc = cpool->allocate(&oid, "cluster_b", err);
|
||||
CPPUNIT_ASSERT( rc == 2 );
|
||||
|
||||
rc = cpool->allocate(&oid, "cluster_c", err);
|
||||
CPPUNIT_ASSERT( rc == 3 );
|
||||
|
||||
rc = cpool->allocate(&oid, "cluster_d", err);
|
||||
CPPUNIT_ASSERT( rc == 4 );
|
||||
|
||||
// Drop one of them
|
||||
cluster = cpool->get(2, false);
|
||||
CPPUNIT_ASSERT( cluster != 0 );
|
||||
|
||||
rc = cpool->drop(cluster);
|
||||
CPPUNIT_ASSERT( rc == 0 );
|
||||
|
||||
// dump the pool
|
||||
rc = cpool->dump(oss,"");
|
||||
/*
|
||||
if( oss.str() != cluster_xml_dump )
|
||||
{
|
||||
cout << endl << oss.str() << endl << "========"
|
||||
<< endl << cluster_xml_dump;
|
||||
}
|
||||
//*/
|
||||
CPPUNIT_ASSERT( oss.str() == cluster_xml_dump );
|
||||
}
|
||||
};
|
||||
|
||||
/* ************************************************************************* */
|
||||
/* ************************************************************************* */
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
return PoolTest::main(argc, argv, ClusterPoolTest::suite());
|
||||
}
|
@ -20,62 +20,21 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "Cluster.h"
|
||||
#include "Group.h"
|
||||
|
||||
const char * Group::table = "group_pool";
|
||||
|
||||
const char * Cluster::table = "cluster_pool";
|
||||
|
||||
const char * Cluster::db_names = "oid, name, body";
|
||||
|
||||
const char * Cluster::db_bootstrap = "CREATE TABLE IF NOT EXISTS cluster_pool ("
|
||||
"oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, UNIQUE(name))";
|
||||
const char * Group::db_names = "oid, name, body";
|
||||
|
||||
const char * Group::db_bootstrap = "CREATE TABLE IF NOT EXISTS group_pool ("
|
||||
"oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, "
|
||||
"UNIQUE(name))";
|
||||
|
||||
/* ************************************************************************ */
|
||||
/* Cluster :: Constructor/Destructor */
|
||||
/* Group :: Database Access Functions */
|
||||
/* ************************************************************************ */
|
||||
|
||||
Cluster::Cluster(int id, const string& name):PoolObjectSQL(id,name,-1,table){};
|
||||
|
||||
Cluster::~Cluster(){};
|
||||
|
||||
/* ************************************************************************ */
|
||||
/* Cluster :: Database Access Functions */
|
||||
/* ************************************************************************ */
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
int Cluster::insert(SqlDB *db, string& error_str)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = insert_replace(db, false);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
error_str = "Error inserting Cluster in DB.";
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
int Cluster::update(SqlDB *db)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = insert_replace(db, true);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
int Cluster::insert_replace(SqlDB *db, bool replace)
|
||||
int Group::insert_replace(SqlDB *db, bool replace)
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
@ -85,7 +44,7 @@ int Cluster::insert_replace(SqlDB *db, bool replace)
|
||||
char * sql_name;
|
||||
char * sql_xml;
|
||||
|
||||
// Update the Cluster
|
||||
// Update the Group
|
||||
|
||||
sql_name = db->escape_str(name.c_str());
|
||||
|
||||
@ -101,7 +60,7 @@ int Cluster::insert_replace(SqlDB *db, bool replace)
|
||||
goto error_body;
|
||||
}
|
||||
|
||||
if(replace)
|
||||
if ( replace )
|
||||
{
|
||||
oss << "REPLACE";
|
||||
}
|
||||
@ -130,31 +89,22 @@ error_name:
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ************************************************************************ */
|
||||
/* Cluster :: Misc */
|
||||
/* ************************************************************************ */
|
||||
|
||||
ostream& operator<<(ostream& os, Cluster& cluster)
|
||||
{
|
||||
string cluster_str;
|
||||
|
||||
os << cluster.to_xml(cluster_str);
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
string& Cluster::to_xml(string& xml) const
|
||||
string& Group::to_xml(string& xml) const
|
||||
{
|
||||
ostringstream oss;
|
||||
string collection_xml;
|
||||
|
||||
ObjectCollection::to_xml(collection_xml);
|
||||
|
||||
oss <<
|
||||
"<CLUSTER>" <<
|
||||
"<GROUP>" <<
|
||||
"<ID>" << oid << "</ID>" <<
|
||||
"<NAME>" << name << "</NAME>" <<
|
||||
"</CLUSTER>";
|
||||
collection_xml <<
|
||||
"</GROUP>";
|
||||
|
||||
xml = oss.str();
|
||||
|
||||
@ -164,16 +114,28 @@ string& Cluster::to_xml(string& xml) const
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
int Cluster::from_xml(const string& xml)
|
||||
int Group::from_xml(const string& xml)
|
||||
{
|
||||
int rc = 0;
|
||||
vector<xmlNodePtr> content;
|
||||
|
||||
// Initialize the internal XML object
|
||||
update_from_str(xml);
|
||||
|
||||
// Get class base attributes
|
||||
rc += xpath(oid, "/CLUSTER/ID", -1);
|
||||
rc += xpath(name,"/CLUSTER/NAME", "not_found");
|
||||
rc += xpath(oid, "/GROUP/ID", -1);
|
||||
rc += xpath(name,"/GROUP/NAME", "not_found");
|
||||
|
||||
// Get associated classes
|
||||
ObjectXML::get_nodes("/GROUP/USERS", content);
|
||||
|
||||
if( content.size() < 1 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Set of IDs
|
||||
rc += ObjectCollection::from_xml_node(content[0]);
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
@ -182,3 +144,7 @@ int Cluster::from_xml(const string& xml)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
160
src/group/GroupPool.cc
Normal file
160
src/group/GroupPool.cc
Normal file
@ -0,0 +1,160 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* 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 "GroupPool.h"
|
||||
#include "Nebula.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* There are two default groups boostrapped by the core: */
|
||||
/* - oneadmin can not be removed */
|
||||
/* - users to place regular users by default */
|
||||
/* The first 100 group IDs are reserved for system groups. Regular ones start */
|
||||
/* from ID 100 */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const string GroupPool::ONEADMIN_NAME = "oneadmin";
|
||||
const int GroupPool::ONEADMIN_ID = 0;
|
||||
|
||||
const string GroupPool::USERS_NAME = "users";
|
||||
const int GroupPool::USERS_ID = 1;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
GroupPool::GroupPool(SqlDB * db):PoolSQL(db, Group::table)
|
||||
{
|
||||
ostringstream oss;
|
||||
string error_str;
|
||||
|
||||
if (get_lastOID() == -1) //lastOID is set in PoolSQL::init_cb
|
||||
{
|
||||
int rc;
|
||||
Group * group;
|
||||
|
||||
// Build the default oneadmins & users group
|
||||
group = new Group(ONEADMIN_ID, ONEADMIN_NAME);
|
||||
|
||||
rc = PoolSQL::allocate(group, error_str);
|
||||
|
||||
if( rc < 0 )
|
||||
{
|
||||
goto error_groups;
|
||||
}
|
||||
|
||||
group = new Group(USERS_ID, USERS_NAME);
|
||||
|
||||
rc = PoolSQL::allocate(group, error_str);
|
||||
|
||||
if(rc < 0)
|
||||
{
|
||||
goto error_groups;
|
||||
}
|
||||
|
||||
set_update_lastOID(99);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
error_groups:
|
||||
oss << "Error trying to create default group: " << error_str;
|
||||
NebulaLog::log("GROUP",Log::ERROR,oss);
|
||||
|
||||
throw runtime_error(oss.str());
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int GroupPool::allocate(string name, int * oid, string& error_str)
|
||||
{
|
||||
Group * group;
|
||||
ostringstream oss;
|
||||
|
||||
if ( name.empty() )
|
||||
{
|
||||
goto error_name;
|
||||
}
|
||||
|
||||
// Check for duplicates
|
||||
group = get(name, false);
|
||||
|
||||
if( group != 0 )
|
||||
{
|
||||
goto error_duplicated;
|
||||
}
|
||||
|
||||
// Build a new Group object
|
||||
group = new Group(-1, name);
|
||||
|
||||
// Insert the Object in the pool
|
||||
*oid = PoolSQL::allocate(group, error_str);
|
||||
|
||||
return *oid;
|
||||
|
||||
error_name:
|
||||
oss << "NAME cannot be empty.";
|
||||
goto error_common;
|
||||
|
||||
error_duplicated:
|
||||
oss << "NAME is already taken by GROUP " << group->get_oid() << ".";
|
||||
|
||||
error_common:
|
||||
*oid = -1;
|
||||
error_str = oss.str();
|
||||
|
||||
return *oid;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int GroupPool::drop(PoolObjectSQL * objsql, string& error_msg)
|
||||
{
|
||||
Group * group = static_cast<Group*>(objsql);
|
||||
|
||||
int rc;
|
||||
|
||||
// Return error if the group is a default one.
|
||||
if( group->get_oid() < 100 )
|
||||
{
|
||||
error_msg = "System Groups (ID < 100) cannot be deleted.";
|
||||
NebulaLog::log("GROUP", Log::ERROR, error_msg);
|
||||
return -2;
|
||||
}
|
||||
|
||||
if( group->get_collection_size() > 0 )
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Group " << group->get_oid() << " is not empty.";
|
||||
error_msg = oss.str();
|
||||
NebulaLog::log("GROUP", Log::ERROR, error_msg);
|
||||
|
||||
return -3;
|
||||
}
|
||||
|
||||
rc = group->drop(db);
|
||||
|
||||
if( rc != 0 )
|
||||
{
|
||||
error_msg = "SQL DB error";
|
||||
rc = -1;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
# SConstruct for src/cluster
|
||||
# SConstruct for src/group
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) #
|
||||
@ -18,12 +18,12 @@
|
||||
|
||||
Import('env')
|
||||
|
||||
lib_name='nebula_cluster'
|
||||
lib_name='nebula_group'
|
||||
|
||||
# Sources to generate the library
|
||||
source_files=[
|
||||
'ClusterPool.cc',
|
||||
'Cluster.cc'
|
||||
'GroupPool.cc',
|
||||
'Group.cc'
|
||||
]
|
||||
|
||||
# Build library
|
233
src/group/test/GroupPoolTest.cc
Normal file
233
src/group/test/GroupPoolTest.cc
Normal file
@ -0,0 +1,233 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* 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 <string>
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "GroupPool.h"
|
||||
#include "PoolTest.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
const int uids[] = {0,1,2};
|
||||
const string names[] = {"First name", "Second name"};
|
||||
|
||||
const string xmls[] =
|
||||
{
|
||||
"<GROUP><ID>100</ID><NAME>First name</NAME><USERS></USERS></GROUP>",
|
||||
"<GROUP><ID>101</ID><NAME>Second name</NAME><USERS></USERS></GROUP>"
|
||||
};
|
||||
|
||||
const string group_xml_dump =
|
||||
"<GROUP_POOL><GROUP><ID>0</ID><NAME>oneadmin</NAME><USERS></USERS></GROUP><GROUP><ID>1</ID><NAME>users</NAME><USERS></USERS></GROUP><GROUP><ID>100</ID><NAME>group_a</NAME><USERS></USERS></GROUP><GROUP><ID>102</ID><NAME>group_c</NAME><USERS></USERS></GROUP><GROUP><ID>103</ID><NAME>group_d</NAME><USERS></USERS></GROUP></GROUP_POOL>";
|
||||
|
||||
/* ************************************************************************* */
|
||||
/* ************************************************************************* */
|
||||
|
||||
|
||||
#include "NebulaTest.h"
|
||||
|
||||
class NebulaTestGroup: public NebulaTest
|
||||
{
|
||||
public:
|
||||
NebulaTestGroup():NebulaTest()
|
||||
{
|
||||
NebulaTest::the_tester = this;
|
||||
|
||||
need_group_pool= true;
|
||||
}
|
||||
};
|
||||
|
||||
class GroupPoolTest : public PoolTest
|
||||
{
|
||||
CPPUNIT_TEST_SUITE (GroupPoolTest);
|
||||
|
||||
// Not all tests from PoolTest can be used. Because
|
||||
// of the initial default groups added to the DB, the
|
||||
// oid_assignment would fail.
|
||||
CPPUNIT_TEST (get_from_cache);
|
||||
CPPUNIT_TEST (get_from_db);
|
||||
CPPUNIT_TEST (wrong_get);
|
||||
CPPUNIT_TEST (drop_and_get);
|
||||
|
||||
CPPUNIT_TEST (duplicates);
|
||||
CPPUNIT_TEST (dump);
|
||||
|
||||
CPPUNIT_TEST_SUITE_END ();
|
||||
|
||||
protected:
|
||||
|
||||
NebulaTestGroup * tester;
|
||||
GroupPool * gpool;
|
||||
|
||||
|
||||
|
||||
void bootstrap(SqlDB* db)
|
||||
{
|
||||
// setUp overwritten
|
||||
};
|
||||
|
||||
PoolSQL* create_pool(SqlDB* db)
|
||||
{
|
||||
// setUp overwritten
|
||||
return gpool;
|
||||
};
|
||||
|
||||
int allocate(int index)
|
||||
{
|
||||
int oid;
|
||||
string err;
|
||||
|
||||
return gpool->allocate(names[index], &oid, err);
|
||||
};
|
||||
|
||||
void check(int index, PoolObjectSQL* obj)
|
||||
{
|
||||
Group * group = static_cast<Group *>(obj);
|
||||
|
||||
CPPUNIT_ASSERT( obj != 0 );
|
||||
|
||||
string xml_str = "";
|
||||
string name = group->get_name();
|
||||
|
||||
CPPUNIT_ASSERT( name == names[index] );
|
||||
|
||||
// Get the xml
|
||||
group->to_xml(xml_str);
|
||||
|
||||
// A little help for debugging
|
||||
/*
|
||||
if( xml_str != xmls[index] )
|
||||
{
|
||||
cout << endl << xml_str << endl << "========"
|
||||
<< endl << xmls[index];
|
||||
}
|
||||
//*/
|
||||
CPPUNIT_ASSERT( xml_str == xmls[index]);
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
|
||||
public:
|
||||
GroupPoolTest()
|
||||
{
|
||||
xmlInitParser();
|
||||
};
|
||||
|
||||
~GroupPoolTest()
|
||||
{
|
||||
xmlCleanupParser();
|
||||
};
|
||||
|
||||
void setUp()
|
||||
{
|
||||
create_db();
|
||||
|
||||
tester = new NebulaTestGroup();
|
||||
|
||||
Nebula& neb = Nebula::instance();
|
||||
neb.start();
|
||||
|
||||
gpool = neb.get_gpool();
|
||||
|
||||
pool = gpool;
|
||||
};
|
||||
|
||||
void tearDown()
|
||||
{
|
||||
delete_db();
|
||||
|
||||
delete tester;
|
||||
};
|
||||
|
||||
/* ********************************************************************* */
|
||||
/* ********************************************************************* */
|
||||
|
||||
void duplicates()
|
||||
{
|
||||
int rc, oid;
|
||||
string err;
|
||||
GroupPool * gpool = static_cast<GroupPool*>(pool);
|
||||
|
||||
// Allocate a group
|
||||
rc = gpool->allocate(names[0], &oid, err);
|
||||
CPPUNIT_ASSERT( oid == 100 );
|
||||
CPPUNIT_ASSERT( oid == rc );
|
||||
|
||||
// Try to allocate twice the same group, should fail
|
||||
rc = gpool->allocate(names[0], &oid, err);
|
||||
CPPUNIT_ASSERT( rc == -1 );
|
||||
CPPUNIT_ASSERT( oid == rc );
|
||||
|
||||
// Try again, this time with different uid. Should fail, groups can't
|
||||
// repeat names
|
||||
rc = gpool->allocate(names[0], &oid, err);
|
||||
CPPUNIT_ASSERT( rc == -1 );
|
||||
CPPUNIT_ASSERT( oid == rc );
|
||||
}
|
||||
|
||||
/* ********************************************************************* */
|
||||
|
||||
void dump()
|
||||
{
|
||||
Group * group;
|
||||
int oid, rc;
|
||||
ostringstream oss;
|
||||
string err;
|
||||
|
||||
// Allocate some groups
|
||||
rc = gpool->allocate("group_a", &oid, err);
|
||||
CPPUNIT_ASSERT( rc == 100 );
|
||||
|
||||
rc = gpool->allocate("group_b", &oid, err);
|
||||
CPPUNIT_ASSERT( rc == 101 );
|
||||
|
||||
rc = gpool->allocate("group_c", &oid, err);
|
||||
CPPUNIT_ASSERT( rc == 102 );
|
||||
|
||||
rc = gpool->allocate("group_d", &oid, err);
|
||||
CPPUNIT_ASSERT( rc == 103 );
|
||||
|
||||
// Drop one of them
|
||||
group = gpool->get(101, false);
|
||||
CPPUNIT_ASSERT( group != 0 );
|
||||
|
||||
rc = gpool->drop(group, err);
|
||||
CPPUNIT_ASSERT( rc == 0 );
|
||||
|
||||
// dump the pool
|
||||
rc = gpool->dump(oss,"");
|
||||
/*
|
||||
if( oss.str() != group_xml_dump )
|
||||
{
|
||||
cout << endl << oss.str() << endl << "========"
|
||||
<< endl << group_xml_dump;
|
||||
}
|
||||
//*/
|
||||
CPPUNIT_ASSERT( oss.str() == group_xml_dump );
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
/* ************************************************************************* */
|
||||
/* ************************************************************************* */
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
return PoolTest::main(argc, argv, GroupPoolTest::suite());
|
||||
}
|
@ -17,7 +17,6 @@
|
||||
Import('env')
|
||||
|
||||
env.Prepend(LIBS=[
|
||||
'nebula_cluster',
|
||||
'nebula_host',
|
||||
'nebula_pool',
|
||||
'nebula_template',
|
||||
@ -29,7 +28,6 @@ env.Prepend(LIBS=[
|
||||
### TODO: delete not needed
|
||||
'nebula_core_test',
|
||||
'nebula_host',
|
||||
'nebula_cluster',
|
||||
'nebula_xml',
|
||||
'nebula_vmm',
|
||||
'nebula_im',
|
||||
@ -40,6 +38,7 @@ env.Prepend(LIBS=[
|
||||
'nebula_template',
|
||||
'nebula_vm',
|
||||
'nebula_vmtemplate',
|
||||
'nebula_group',
|
||||
'nebula_vnm',
|
||||
'nebula_image',
|
||||
'nebula_pool',
|
||||
@ -53,4 +52,4 @@ env.Prepend(LIBS=[
|
||||
'crypto'
|
||||
])
|
||||
|
||||
env.Program('test','ClusterPoolTest.cc')
|
||||
env.Program('test','GroupPoolTest.cc')
|
@ -22,25 +22,24 @@
|
||||
|
||||
#include "Host.h"
|
||||
#include "NebulaLog.h"
|
||||
#include "Nebula.h"
|
||||
|
||||
/* ************************************************************************ */
|
||||
/* Host :: Constructor/Destructor */
|
||||
/* ************************************************************************ */
|
||||
|
||||
Host::Host(
|
||||
int id,
|
||||
int id,
|
||||
const string& _hostname,
|
||||
const string& _im_mad_name,
|
||||
const string& _vmm_mad_name,
|
||||
const string& _tm_mad_name,
|
||||
const string& _cluster):
|
||||
PoolObjectSQL(id,_hostname,-1,table),
|
||||
const string& _tm_mad_name):
|
||||
PoolObjectSQL(id,_hostname,-1,-1,table),
|
||||
state(INIT),
|
||||
im_mad_name(_im_mad_name),
|
||||
vmm_mad_name(_vmm_mad_name),
|
||||
tm_mad_name(_tm_mad_name),
|
||||
last_monitored(0),
|
||||
cluster(_cluster)
|
||||
last_monitored(0)
|
||||
{
|
||||
obj_template = new HostTemplate;
|
||||
}
|
||||
@ -59,11 +58,11 @@ Host::~Host()
|
||||
|
||||
const char * Host::table = "host_pool";
|
||||
|
||||
const char * Host::db_names = "oid, name, body, state, last_mon_time, cluster";
|
||||
const char * Host::db_names = "oid, name, body, state, last_mon_time";
|
||||
|
||||
const char * Host::db_bootstrap = "CREATE TABLE IF NOT EXISTS host_pool ("
|
||||
"oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, state INTEGER, "
|
||||
"last_mon_time INTEGER, cluster VARCHAR(128), UNIQUE(name))";
|
||||
"last_mon_time INTEGER, UNIQUE(name))";
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
@ -105,7 +104,6 @@ int Host::insert_replace(SqlDB *db, bool replace)
|
||||
string xml_body;
|
||||
|
||||
char * sql_hostname;
|
||||
char * sql_cluster;
|
||||
char * sql_xml;
|
||||
|
||||
// Update the Host
|
||||
@ -117,13 +115,6 @@ int Host::insert_replace(SqlDB *db, bool replace)
|
||||
goto error_hostname;
|
||||
}
|
||||
|
||||
sql_cluster = db->escape_str(cluster.c_str());
|
||||
|
||||
if ( sql_cluster == 0 )
|
||||
{
|
||||
goto error_cluster;
|
||||
}
|
||||
|
||||
sql_xml = db->escape_str(to_xml(xml_body).c_str());
|
||||
|
||||
if ( sql_xml == 0 )
|
||||
@ -147,20 +138,16 @@ int Host::insert_replace(SqlDB *db, bool replace)
|
||||
<< "'" << sql_hostname << "',"
|
||||
<< "'" << sql_xml << "',"
|
||||
<< state << ","
|
||||
<< last_monitored << ","
|
||||
<< "'" << sql_cluster << "')";
|
||||
<< last_monitored << ")";
|
||||
|
||||
rc = db->exec(oss);
|
||||
|
||||
db->free_str(sql_hostname);
|
||||
db->free_str(sql_cluster);
|
||||
db->free_str(sql_xml);
|
||||
|
||||
return rc;
|
||||
|
||||
error_body:
|
||||
db->free_str(sql_cluster);
|
||||
error_cluster:
|
||||
db->free_str(sql_hostname);
|
||||
error_hostname:
|
||||
return -1;
|
||||
@ -200,18 +187,6 @@ int Host::update_info(string &parse_str)
|
||||
/* Host :: Misc */
|
||||
/* ************************************************************************ */
|
||||
|
||||
ostream& operator<<(ostream& os, Host& host)
|
||||
{
|
||||
string host_str;
|
||||
|
||||
os << host.to_xml(host_str);
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
string& Host::to_xml(string& xml) const
|
||||
{
|
||||
string template_xml;
|
||||
@ -227,7 +202,6 @@ string& Host::to_xml(string& xml) const
|
||||
"<VM_MAD>" << vmm_mad_name << "</VM_MAD>" <<
|
||||
"<TM_MAD>" << tm_mad_name << "</TM_MAD>" <<
|
||||
"<LAST_MON_TIME>" << last_monitored << "</LAST_MON_TIME>" <<
|
||||
"<CLUSTER>" << cluster << "</CLUSTER>" <<
|
||||
host_share.to_xml(share_xml) <<
|
||||
obj_template->to_xml(template_xml) <<
|
||||
"</HOST>";
|
||||
@ -260,7 +234,6 @@ int Host::from_xml(const string& xml)
|
||||
rc += xpath(tm_mad_name, "/HOST/TM_MAD", "not_found");
|
||||
|
||||
rc += xpath(last_monitored, "/HOST/LAST_MON_TIME", 0);
|
||||
rc += xpath(cluster, "/HOST/CLUSTER", "not_found");
|
||||
|
||||
state = static_cast<HostState>( int_state );
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include "HostPool.h"
|
||||
#include "HostHook.h"
|
||||
#include "NebulaLog.h"
|
||||
#include "ClusterPool.h"
|
||||
#include "GroupPool.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -135,7 +135,7 @@ HostPool::HostPool(SqlDB* db,
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int HostPool::allocate (
|
||||
int * oid,
|
||||
int * oid,
|
||||
const string& hostname,
|
||||
const string& im_mad_name,
|
||||
const string& vmm_mad_name,
|
||||
@ -174,12 +174,7 @@ int HostPool::allocate (
|
||||
|
||||
// Build a new Host object
|
||||
|
||||
host = new Host(-1,
|
||||
hostname,
|
||||
im_mad_name,
|
||||
vmm_mad_name,
|
||||
tm_mad_name,
|
||||
ClusterPool::DEFAULT_CLUSTER_NAME);
|
||||
host = new Host(-1, hostname, im_mad_name, vmm_mad_name, tm_mad_name);
|
||||
|
||||
// Insert the Object in the pool
|
||||
|
||||
|
@ -33,7 +33,7 @@ const string xmls[] =
|
||||
{
|
||||
"<HOST><ID>0</ID><NAME>Host one</NAME><STATE>0</STATE>"
|
||||
"<IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD>"
|
||||
"<LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE>"
|
||||
"<LAST_MON_TIME>0</LAST_MON_TIME><HOST_SHARE>"
|
||||
"<DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE>"
|
||||
"<MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CPU>"
|
||||
"<FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU>"
|
||||
@ -42,7 +42,7 @@ const string xmls[] =
|
||||
|
||||
"<HOST><ID>1</ID><NAME>Second host</NAME><STATE>0</STATE>"
|
||||
"<IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD>"
|
||||
"<LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE>"
|
||||
"<LAST_MON_TIME>0</LAST_MON_TIME><HOST_SHARE>"
|
||||
"<DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE>"
|
||||
"<MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CPU>"
|
||||
"<FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU>"
|
||||
@ -54,34 +54,34 @@ const string xmls[] =
|
||||
const string xml_dump =
|
||||
"<HOST_POOL><HOST><ID>0</ID><NAME>a</NAME><STATE>0</STATE><IM_MAD>im_mad</I"
|
||||
"M_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0"
|
||||
"</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE><DISK_USAGE>0</DISK_USAGE><MEM"
|
||||
"</LAST_MON_TIME><HOST_SHARE><DISK_USAGE>0</DISK_USAGE><MEM"
|
||||
"_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM"
|
||||
">0</MAX_MEM><MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_"
|
||||
"MEM><FREE_CPU>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><U"
|
||||
"SED_CPU>0</USED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST><HOST>"
|
||||
"<ID>1</ID><NAME>a name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MA"
|
||||
"D>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_M"
|
||||
"ON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</ME"
|
||||
"ON_TIME><HOST_SHARE><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</ME"
|
||||
"M_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM>"
|
||||
"<MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CP"
|
||||
"U>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</U"
|
||||
"SED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST><HOST><ID>2</ID><N"
|
||||
"AME>a_name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</V"
|
||||
"M_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOS"
|
||||
"M_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><HOS"
|
||||
"T_SHARE><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU"
|
||||
"_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</"
|
||||
"MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CP"
|
||||
"U><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUN"
|
||||
"NING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST><HOST><ID>3</ID><NAME>another "
|
||||
"name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD>"
|
||||
"<TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHAR"
|
||||
"<TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><HOST_SHAR"
|
||||
"E><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE"
|
||||
">0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CP"
|
||||
"U><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU><USE"
|
||||
"D_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUNNING_V"
|
||||
"MS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST><HOST><ID>4</ID><NAME>host</NAME><ST"
|
||||
"ATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad"
|
||||
"</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE>"
|
||||
"</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><HOST_SHARE>"
|
||||
"<DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE>"
|
||||
"<MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CPU><FREE_DISK>0"
|
||||
"</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU><USED_DISK>0</USED"
|
||||
@ -91,27 +91,27 @@ const string xml_dump =
|
||||
const string xml_dump_like_a =
|
||||
"<HOST_POOL><HOST><ID>0</ID><NAME>a</NAME><STATE>0</STATE><IM_MAD>im_mad</I"
|
||||
"M_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0"
|
||||
"</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE><DISK_USAGE>0</DISK_USAGE><MEM"
|
||||
"</LAST_MON_TIME><HOST_SHARE><DISK_USAGE>0</DISK_USAGE><MEM"
|
||||
"_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM"
|
||||
">0</MAX_MEM><MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_"
|
||||
"MEM><FREE_CPU>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><U"
|
||||
"SED_CPU>0</USED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST><HOST>"
|
||||
"<ID>1</ID><NAME>a name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MA"
|
||||
"D>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_M"
|
||||
"ON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</ME"
|
||||
"ON_TIME><HOST_SHARE><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</ME"
|
||||
"M_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM>"
|
||||
"<MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CP"
|
||||
"U>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</U"
|
||||
"SED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST><HOST><ID>2</ID><N"
|
||||
"AME>a_name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</V"
|
||||
"M_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOS"
|
||||
"M_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><HOS"
|
||||
"T_SHARE><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU"
|
||||
"_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</"
|
||||
"MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CP"
|
||||
"U><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUN"
|
||||
"NING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST><HOST><ID>3</ID><NAME>another "
|
||||
"name</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD>"
|
||||
"<TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHAR"
|
||||
"<TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><HOST_SHAR"
|
||||
"E><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE"
|
||||
">0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CP"
|
||||
"U><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU><USE"
|
||||
@ -119,13 +119,7 @@ const string xml_dump_like_a =
|
||||
"MS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST></HOST_POOL>";
|
||||
|
||||
const string host0_updated =
|
||||
"<HOST><ID>0</ID><NAME>Host one</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>default</CLUSTER><HOST_SHARE><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE><ATT_A><![CDATA[VALUE_A]]></ATT_A><ATT_B><![CDATA[VALUE_B]]></ATT_B></TEMPLATE></HOST>";
|
||||
|
||||
const string cluster_default =
|
||||
"<CLUSTER><ID>0</ID><NAME>default</NAME></CLUSTER>";
|
||||
|
||||
const string cluster_xml_dump =
|
||||
"<CLUSTER_POOL><CLUSTER><ID>0</ID><NAME>default</NAME></CLUSTER><CLUSTER><ID>1</ID><NAME>cluster_a</NAME></CLUSTER><CLUSTER><ID>3</ID><NAME>cluster_c</NAME></CLUSTER><CLUSTER><ID>4</ID><NAME>cluster_d</NAME></CLUSTER></CLUSTER_POOL>";
|
||||
"<HOST><ID>0</ID><NAME>Host one</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><HOST_SHARE><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE><ATT_A><![CDATA[VALUE_A]]></ATT_A><ATT_B><![CDATA[VALUE_B]]></ATT_B></TEMPLATE></HOST>";
|
||||
|
||||
const string host_0_cluster =
|
||||
"<HOST><ID>0</ID><NAME>Host one</NAME><STATE>0</STATE><IM_MAD>im_mad</IM_MAD><VM_MAD>vmm_mad</VM_MAD><TM_MAD>tm_mad</TM_MAD><LAST_MON_TIME>0</LAST_MON_TIME><CLUSTER>cluster_a</CLUSTER><HOST_SHARE><DISK_USAGE>0</DISK_USAGE><MEM_USAGE>0</MEM_USAGE><CPU_USAGE>0</CPU_USAGE><MAX_DISK>0</MAX_DISK><MAX_MEM>0</MAX_MEM><MAX_CPU>0</MAX_CPU><FREE_DISK>0</FREE_DISK><FREE_MEM>0</FREE_MEM><FREE_CPU>0</FREE_CPU><USED_DISK>0</USED_DISK><USED_MEM>0</USED_MEM><USED_CPU>0</USED_CPU><RUNNING_VMS>0</RUNNING_VMS></HOST_SHARE><TEMPLATE></TEMPLATE></HOST>";
|
||||
|
@ -29,6 +29,7 @@ public:
|
||||
need_vm_pool = true;
|
||||
need_host_pool = true;
|
||||
need_user_pool = true;
|
||||
need_group_pool = true;
|
||||
need_vnet_pool = true;
|
||||
need_image_pool= true;
|
||||
|
||||
@ -82,29 +83,6 @@ public:
|
||||
|
||||
return new HostPool(db, host_hooks, hook_location);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// Managers
|
||||
// -----------------------------------------------------------
|
||||
|
||||
HookManager* create_hm(VirtualMachinePool * vmpool)
|
||||
{
|
||||
map<string,string> mad_value;
|
||||
VectorAttribute * mad;
|
||||
vector<const Attribute *> hm_mads;
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
// we need the full path (i.e, starting with '/')
|
||||
// for the dummy executable
|
||||
oss << getenv("PWD") << "/../../hm_mad/test/dummy";
|
||||
mad_value.insert(make_pair("EXECUTABLE",oss.str()));
|
||||
|
||||
mad = new VectorAttribute("HM_MAD",mad_value);
|
||||
hm_mads.push_back(mad);
|
||||
|
||||
return new HookManager(hm_mads,vmpool);
|
||||
}
|
||||
};
|
||||
|
||||
#endif /*NEBULA_TEST_H_*/
|
||||
|
@ -21,7 +21,6 @@ Import('env')
|
||||
env.Prepend(LIBS=[
|
||||
'nebula_core_test',
|
||||
'nebula_host',
|
||||
'nebula_cluster',
|
||||
'nebula_xml',
|
||||
'nebula_vmm',
|
||||
'nebula_im',
|
||||
@ -32,6 +31,7 @@ env.Prepend(LIBS=[
|
||||
'nebula_template',
|
||||
'nebula_vm',
|
||||
'nebula_vmtemplate',
|
||||
'nebula_group',
|
||||
'nebula_vnm',
|
||||
'nebula_image',
|
||||
'nebula_pool',
|
||||
|
@ -34,11 +34,10 @@
|
||||
/* Image :: Constructor/Destructor */
|
||||
/* ************************************************************************ */
|
||||
|
||||
Image::Image(int _uid,
|
||||
const string& _user_name,
|
||||
Image::Image(int _uid,
|
||||
int _gid,
|
||||
ImageTemplate * _image_template):
|
||||
PoolObjectSQL(-1,"",_uid,table),
|
||||
user_name(_user_name),
|
||||
PoolObjectSQL(-1,"",_uid,_gid,table),
|
||||
type(OS),
|
||||
regtime(time(0)),
|
||||
source("-"),
|
||||
@ -69,11 +68,11 @@ Image::~Image()
|
||||
|
||||
const char * Image::table = "image_pool";
|
||||
|
||||
const char * Image::db_names = "oid, name, body, uid, public";
|
||||
const char * Image::db_names = "oid, name, body, uid, gid, public";
|
||||
|
||||
const char * Image::db_bootstrap = "CREATE TABLE IF NOT EXISTS image_pool ("
|
||||
"oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, uid INTEGER, "
|
||||
"public INTEGER, UNIQUE(name,uid) )";
|
||||
"gid INTEGER, public INTEGER, UNIQUE(name,uid) )";
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
@ -121,7 +120,7 @@ int Image::insert(SqlDB *db, string& error_str)
|
||||
|
||||
TO_UPPER(public_attr);
|
||||
|
||||
public_img = (public_attr == "YES");
|
||||
public_obj = (public_attr == "YES");
|
||||
|
||||
// ------------ PERSISTENT --------------------
|
||||
|
||||
@ -135,7 +134,7 @@ int Image::insert(SqlDB *db, string& error_str)
|
||||
|
||||
// An image cannot be public and persistent simultaneously
|
||||
|
||||
if ( public_img && persistent_img )
|
||||
if ( public_obj && persistent_img )
|
||||
{
|
||||
goto error_public_and_persistent;
|
||||
}
|
||||
@ -295,7 +294,8 @@ int Image::insert_replace(SqlDB *db, bool replace)
|
||||
<< "'" << sql_name << "',"
|
||||
<< "'" << sql_xml << "',"
|
||||
<< uid << ","
|
||||
<< public_img << ")";
|
||||
<< gid << ","
|
||||
<< public_obj << ")";
|
||||
|
||||
rc = db->exec(oss);
|
||||
|
||||
@ -314,18 +314,6 @@ error_name:
|
||||
/* Image :: Misc */
|
||||
/* ************************************************************************ */
|
||||
|
||||
ostream& operator<<(ostream& os, Image& image)
|
||||
{
|
||||
string image_str;
|
||||
|
||||
os << image.to_xml(image_str);
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
string& Image::to_xml(string& xml) const
|
||||
{
|
||||
string template_xml;
|
||||
@ -335,10 +323,10 @@ string& Image::to_xml(string& xml) const
|
||||
"<IMAGE>" <<
|
||||
"<ID>" << oid << "</ID>" <<
|
||||
"<UID>" << uid << "</UID>" <<
|
||||
"<USERNAME>" << user_name << "</USERNAME>" <<
|
||||
"<GID>" << gid << "</GID>" <<
|
||||
"<NAME>" << name << "</NAME>" <<
|
||||
"<TYPE>" << type << "</TYPE>" <<
|
||||
"<PUBLIC>" << public_img << "</PUBLIC>" <<
|
||||
"<PUBLIC>" << public_obj << "</PUBLIC>" <<
|
||||
"<PERSISTENT>" << persistent_img << "</PERSISTENT>" <<
|
||||
"<REGTIME>" << regtime << "</REGTIME>" <<
|
||||
"<SOURCE>" << source << "</SOURCE>" <<
|
||||
@ -369,11 +357,11 @@ int Image::from_xml(const string& xml)
|
||||
// Get class base attributes
|
||||
rc += xpath(oid, "/IMAGE/ID", -1);
|
||||
rc += xpath(uid, "/IMAGE/UID", -1);
|
||||
rc += xpath(user_name, "/IMAGE/USERNAME", "not_found");
|
||||
rc += xpath(gid, "/IMAGE/GID", -1);
|
||||
rc += xpath(name, "/IMAGE/NAME", "not_found");
|
||||
|
||||
rc += xpath(int_type, "/IMAGE/TYPE", 0);
|
||||
rc += xpath(public_img, "/IMAGE/PUBLIC", 0);
|
||||
rc += xpath(public_obj, "/IMAGE/PUBLIC", 0);
|
||||
rc += xpath(persistent_img, "/IMAGE/PERSISTENT", 0);
|
||||
rc += xpath(regtime, "/IMAGE/REGTIME", 0);
|
||||
|
||||
@ -457,6 +445,7 @@ int Image::disk_attribute( VectorAttribute * disk,
|
||||
{
|
||||
disk->replace("CLONE","NO");
|
||||
disk->replace("SAVE","YES");
|
||||
disk->replace("PERSISTENT","YES");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -229,13 +229,15 @@ void ImageManagerDriver::protocol(
|
||||
else if ( action == "RM" )
|
||||
{
|
||||
int rc;
|
||||
string tmp_error;
|
||||
|
||||
source = image->get_source();
|
||||
|
||||
rc = ipool->drop(image);
|
||||
rc = ipool->drop(image, tmp_error);
|
||||
|
||||
if ( rc < 0 )
|
||||
{
|
||||
image->unlock();
|
||||
NebulaLog::log("ImM",Log::ERROR,"Image could not be removed from DB");
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ ImagePool::ImagePool(SqlDB * db,
|
||||
|
||||
int ImagePool::allocate (
|
||||
int uid,
|
||||
string user_name,
|
||||
int gid,
|
||||
ImageTemplate* img_template,
|
||||
int * oid,
|
||||
string& error_str)
|
||||
@ -66,7 +66,7 @@ int ImagePool::allocate (
|
||||
string name;
|
||||
ostringstream oss;
|
||||
|
||||
img = new Image(uid, user_name, img_template);
|
||||
img = new Image(uid, gid, img_template);
|
||||
|
||||
// Check name
|
||||
img->get_template_attribute("NAME", name);
|
||||
@ -85,9 +85,22 @@ int ImagePool::allocate (
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Insert the Object in the pool
|
||||
// Insert the Object in the pool & Register the image in the repository
|
||||
// ---------------------------------------------------------------------
|
||||
*oid = PoolSQL::allocate(img, error_str);
|
||||
|
||||
if ( *oid != -1 )
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
ImageManager * imagem = nd.get_imagem();
|
||||
|
||||
if ( imagem->register_image(*oid) == -1 )
|
||||
{
|
||||
error_str = "Failed to copy image to repository. "
|
||||
"Image left in ERROR state.";
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return *oid;
|
||||
|
||||
|
@ -24,7 +24,6 @@
|
||||
using namespace std;
|
||||
|
||||
const int uids[] = {0,1,2};
|
||||
const string user_names[] = {"A user","B user","C user"};
|
||||
|
||||
const string names[] = {"Image one", "Second Image", "The third image"};
|
||||
|
||||
@ -50,21 +49,38 @@ const string templates[] =
|
||||
|
||||
const string xmls[] =
|
||||
{
|
||||
"<IMAGE><ID>0</ID><UID>0</UID><USERNAME>A user</USERNAME><NAME>Image one</NAME><TYPE>0</TYPE><PUBLIC>0</PUBLIC><PERSISTENT>1</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>-</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><DESCRIPTION><![CDATA[This is a very long description of an image, and to achieve the longness I will copy this over. This is a very long description of an image, and to achieve the longness I will copy this over. And over. This is a very long description of an image, and to achieve the longness I will copy this over. And over. This is a very long description of an image, and to achieve the longness I will copy this over. And over.This is a very long description of an image, and to achieve the longness I will copy this over.]]></DESCRIPTION><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[Image one]]></NAME><PATH><![CDATA[/tmp/image_test]]></PATH></TEMPLATE></IMAGE>",
|
||||
"<IMAGE><ID>0</ID><UID>0</UID><GID>1</GID><NAME>Image one</NAME><TYPE>0</TYPE><PUBLIC>0</PUBLIC><PERSISTENT>1</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>-</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><DESCRIPTION><![CDATA[This is a very long description of an image, and to achieve the longness I will copy this over. This is a very long description of an image, and to achieve the longness I will copy this over. And over. This is a very long description of an image, and to achieve the longness I will copy this over. And over. This is a very long description of an image, and to achieve the longness I will copy this over. And over.This is a very long description of an image, and to achieve the longness I will copy this over.]]></DESCRIPTION><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[Image one]]></NAME><PATH><![CDATA[/tmp/image_test]]></PATH></TEMPLATE></IMAGE>",
|
||||
|
||||
"<IMAGE><ID>1</ID><UID>1</UID><USERNAME>B user</USERNAME><NAME>Second Image</NAME><TYPE>0</TYPE><PUBLIC>1</PUBLIC><PERSISTENT>0</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>-</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><DESCRIPTION><![CDATA[This is a rather short description.]]></DESCRIPTION><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[Second Image]]></NAME><PATH><![CDATA[/tmp/image_second_test]]></PATH></TEMPLATE></IMAGE>",
|
||||
"<IMAGE><ID>1</ID><UID>1</UID><GID>1</GID><NAME>Second Image</NAME><TYPE>0</TYPE><PUBLIC>1</PUBLIC><PERSISTENT>0</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>-</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><DESCRIPTION><![CDATA[This is a rather short description.]]></DESCRIPTION><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[Second Image]]></NAME><PATH><![CDATA[/tmp/image_second_test]]></PATH></TEMPLATE></IMAGE>",
|
||||
|
||||
"<IMAGE><ID>0</ID><UID>2</UID><USERNAME>C user</USERNAME><NAME>The third image</NAME><TYPE>0</TYPE><PUBLIC>0</PUBLIC><PERSISTENT>0</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>-</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><BUS><![CDATA[SCSI]]></BUS><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[The third image]]></NAME><PATH><![CDATA[/tmp/image_test]]></PATH><PROFILE><![CDATA[STUDENT]]></PROFILE></TEMPLATE></IMAGE>"
|
||||
"<IMAGE><ID>0</ID><UID>2</UID><GID>1</GID><NAME>The third image</NAME><TYPE>0</TYPE><PUBLIC>0</PUBLIC><PERSISTENT>0</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>-</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><BUS><![CDATA[SCSI]]></BUS><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[The third image]]></NAME><PATH><![CDATA[/tmp/image_test]]></PATH><PROFILE><![CDATA[STUDENT]]></PROFILE></TEMPLATE></IMAGE>"
|
||||
};
|
||||
|
||||
|
||||
// This xml dump result has the STIMEs modified to 0000000000
|
||||
const string xml_dump =
|
||||
"<IMAGE_POOL><IMAGE><ID>0</ID><UID>0</UID><USERNAME>A user</USERNAME><NAME>Image one</NAME><TYPE>0</TYPE><PUBLIC>0</PUBLIC><PERSISTENT>1</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>-</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><DESCRIPTION><![CDATA[This is a very long description of an image, and to achieve the longness I will copy this over. This is a very long description of an image, and to achieve the longness I will copy this over. And over. This is a very long description of an image, and to achieve the longness I will copy this over. And over. This is a very long description of an image, and to achieve the longness I will copy this over. And over.This is a very long description of an image, and to achieve the longness I will copy this over.]]></DESCRIPTION><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[Image one]]></NAME><PATH><![CDATA[/tmp/image_test]]></PATH></TEMPLATE></IMAGE><IMAGE><ID>1</ID><UID>1</UID><USERNAME>B user</USERNAME><NAME>Second Image</NAME><TYPE>0</TYPE><PUBLIC>1</PUBLIC><PERSISTENT>0</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>-</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><DESCRIPTION><![CDATA[This is a rather short description.]]></DESCRIPTION><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[Second Image]]></NAME><PATH><![CDATA[/tmp/image_second_test]]></PATH></TEMPLATE></IMAGE><IMAGE><ID>2</ID><UID>2</UID><USERNAME>C user</USERNAME><NAME>The third image</NAME><TYPE>0</TYPE><PUBLIC>0</PUBLIC><PERSISTENT>0</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>-</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><BUS><![CDATA[SCSI]]></BUS><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[The third image]]></NAME><PATH><![CDATA[/tmp/image_test]]></PATH><PROFILE><![CDATA[STUDENT]]></PROFILE></TEMPLATE></IMAGE></IMAGE_POOL>";
|
||||
"<IMAGE_POOL><IMAGE><ID>0</ID><UID>0</UID><GID>1</GID><NAME>Image one</NAME><TYPE>0</TYPE><PUBLIC>0</PUBLIC><PERSISTENT>1</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>-</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><DESCRIPTION><![CDATA[This is a very long description of an image, and to achieve the longness I will copy this over. This is a very long description of an image, and to achieve the longness I will copy this over. And over. This is a very long description of an image, and to achieve the longness I will copy this over. And over. This is a very long description of an image, and to achieve the longness I will copy this over. And over.This is a very long description of an image, and to achieve the longness I will copy this over.]]></DESCRIPTION><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[Image one]]></NAME><PATH><![CDATA[/tmp/image_test]]></PATH></TEMPLATE></IMAGE><IMAGE><ID>1</ID><UID>1</UID><GID>1</GID><NAME>Second Image</NAME><TYPE>0</TYPE><PUBLIC>1</PUBLIC><PERSISTENT>0</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>-</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><DESCRIPTION><![CDATA[This is a rather short description.]]></DESCRIPTION><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[Second Image]]></NAME><PATH><![CDATA[/tmp/image_second_test]]></PATH></TEMPLATE></IMAGE><IMAGE><ID>2</ID><UID>2</UID><GID>1</GID><NAME>The third image</NAME><TYPE>0</TYPE><PUBLIC>0</PUBLIC><PERSISTENT>0</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>-</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><BUS><![CDATA[SCSI]]></BUS><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[The third image]]></NAME><PATH><![CDATA[/tmp/image_test]]></PATH><PROFILE><![CDATA[STUDENT]]></PROFILE></TEMPLATE></IMAGE></IMAGE_POOL>";
|
||||
const string xml_dump_where =
|
||||
"<IMAGE_POOL><IMAGE><ID>0</ID><UID>0</UID><USERNAME>A user</USERNAME><NAME>Image one</NAME><TYPE>0</TYPE><PUBLIC>0</PUBLIC><PERSISTENT>1</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>-</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><DESCRIPTION><![CDATA[This is a very long description of an image, and to achieve the longness I will copy this over. This is a very long description of an image, and to achieve the longness I will copy this over. And over. This is a very long description of an image, and to achieve the longness I will copy this over. And over. This is a very long description of an image, and to achieve the longness I will copy this over. And over.This is a very long description of an image, and to achieve the longness I will copy this over.]]></DESCRIPTION><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[Image one]]></NAME><PATH><![CDATA[/tmp/image_test]]></PATH></TEMPLATE></IMAGE><IMAGE><ID>1</ID><UID>1</UID><USERNAME>B user</USERNAME><NAME>Second Image</NAME><TYPE>0</TYPE><PUBLIC>1</PUBLIC><PERSISTENT>0</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>-</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><DESCRIPTION><![CDATA[This is a rather short description.]]></DESCRIPTION><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[Second Image]]></NAME><PATH><![CDATA[/tmp/image_second_test]]></PATH></TEMPLATE></IMAGE></IMAGE_POOL>";
|
||||
"<IMAGE_POOL><IMAGE><ID>0</ID><UID>0</UID><GID>1</GID><NAME>Image one</NAME><TYPE>0</TYPE><PUBLIC>0</PUBLIC><PERSISTENT>1</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>-</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><DESCRIPTION><![CDATA[This is a very long description of an image, and to achieve the longness I will copy this over. This is a very long description of an image, and to achieve the longness I will copy this over. And over. This is a very long description of an image, and to achieve the longness I will copy this over. And over. This is a very long description of an image, and to achieve the longness I will copy this over. And over.This is a very long description of an image, and to achieve the longness I will copy this over.]]></DESCRIPTION><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[Image one]]></NAME><PATH><![CDATA[/tmp/image_test]]></PATH></TEMPLATE></IMAGE><IMAGE><ID>1</ID><UID>1</UID><GID>1</GID><NAME>Second Image</NAME><TYPE>0</TYPE><PUBLIC>1</PUBLIC><PERSISTENT>0</PERSISTENT><REGTIME>0000000000</REGTIME><SOURCE>-</SOURCE><STATE>4</STATE><RUNNING_VMS>0</RUNNING_VMS><TEMPLATE><DESCRIPTION><![CDATA[This is a rather short description.]]></DESCRIPTION><DEV_PREFIX><![CDATA[hd]]></DEV_PREFIX><NAME><![CDATA[Second Image]]></NAME><PATH><![CDATA[/tmp/image_second_test]]></PATH></TEMPLATE></IMAGE></IMAGE_POOL>";
|
||||
|
||||
|
||||
/* ************************************************************************* */
|
||||
/* ************************************************************************* */
|
||||
|
||||
#include "NebulaTest.h"
|
||||
|
||||
class NebulaTestImage: public NebulaTest
|
||||
{
|
||||
public:
|
||||
NebulaTestImage():NebulaTest()
|
||||
{
|
||||
NebulaTest::the_tester = this;
|
||||
|
||||
need_image_pool = true;
|
||||
need_imagem = true;
|
||||
}
|
||||
};
|
||||
|
||||
const string replacement = "0000000000";
|
||||
|
||||
class ImagePoolFriend : public ImagePool
|
||||
{
|
||||
@ -90,7 +106,7 @@ public:
|
||||
|
||||
if( rc == 0 )
|
||||
{
|
||||
return ImagePool::allocate(uid, user_names[uid], img_template, oid, err);
|
||||
return ImagePool::allocate(uid, 1, img_template, oid, err);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -137,16 +153,18 @@ class ImagePoolTest : public PoolTest
|
||||
|
||||
protected:
|
||||
|
||||
NebulaTestImage * tester;
|
||||
ImagePool * ipool;
|
||||
|
||||
void bootstrap(SqlDB* db)
|
||||
{
|
||||
ImagePool::bootstrap(db);
|
||||
// setUp overwritten
|
||||
};
|
||||
|
||||
PoolSQL* create_pool(SqlDB* db)
|
||||
{
|
||||
ImagePoolFriend * imp =
|
||||
new ImagePoolFriend(db, "OS", "hd");
|
||||
return imp;
|
||||
// setUp overwritten
|
||||
return ipool;
|
||||
};
|
||||
|
||||
int allocate(int index)
|
||||
@ -167,7 +185,7 @@ protected:
|
||||
// Get the xml and replace the REGTIME to 0, so we can compare
|
||||
// it.
|
||||
((Image*)obj)->to_xml(xml_str);
|
||||
xml_str.replace( xml_str.find("<REGTIME>")+9, 10, replacement);
|
||||
fix_regtimes(xml_str);
|
||||
|
||||
/*
|
||||
if( xml_str != xmls[index] )
|
||||
@ -185,7 +203,26 @@ public:
|
||||
|
||||
~ImagePoolTest(){xmlCleanupParser();};
|
||||
|
||||
void setUp()
|
||||
{
|
||||
create_db();
|
||||
|
||||
tester = new NebulaTestImage();
|
||||
|
||||
Nebula& neb = Nebula::instance();
|
||||
neb.start();
|
||||
|
||||
ipool = neb.get_ipool();
|
||||
|
||||
pool = ipool;
|
||||
};
|
||||
|
||||
void tearDown()
|
||||
{
|
||||
delete_db();
|
||||
|
||||
delete tester;
|
||||
};
|
||||
/* ********************************************************************* */
|
||||
|
||||
void names_initialization()
|
||||
@ -742,18 +779,18 @@ public:
|
||||
i++;
|
||||
}
|
||||
|
||||
bool success;
|
||||
int success;
|
||||
|
||||
// img 0 is not public.
|
||||
img = imp->get( 0, false );
|
||||
CPPUNIT_ASSERT( img != 0 );
|
||||
|
||||
success = img->publish(false);
|
||||
CPPUNIT_ASSERT( success == true );
|
||||
CPPUNIT_ASSERT( success == 0 );
|
||||
CPPUNIT_ASSERT( img->isPublic() == false );
|
||||
|
||||
success = img->publish(true);
|
||||
CPPUNIT_ASSERT( success == true );
|
||||
CPPUNIT_ASSERT( success == 0 );
|
||||
CPPUNIT_ASSERT( img->isPublic() == true );
|
||||
}
|
||||
|
||||
@ -763,7 +800,7 @@ public:
|
||||
void persistence()
|
||||
{
|
||||
int oid;
|
||||
bool success;
|
||||
int success;
|
||||
ImagePoolFriend * imp = static_cast<ImagePoolFriend *>(pool);
|
||||
Image * img;
|
||||
|
||||
@ -819,33 +856,33 @@ public:
|
||||
|
||||
// make it persistent
|
||||
success = img->persistent(true);
|
||||
CPPUNIT_ASSERT( success == true );
|
||||
CPPUNIT_ASSERT( success == 0 );
|
||||
CPPUNIT_ASSERT( img->isPersistent() == true );
|
||||
|
||||
// it isn't public, try to unpublish
|
||||
success = img->publish(false);
|
||||
CPPUNIT_ASSERT( success == true );
|
||||
CPPUNIT_ASSERT( success == 0 );
|
||||
CPPUNIT_ASSERT( img->isPublic() == false );
|
||||
|
||||
// try to publish, should fail because it is persistent
|
||||
success = img->publish(true);
|
||||
CPPUNIT_ASSERT( success == false );
|
||||
CPPUNIT_ASSERT( success == -1 );
|
||||
CPPUNIT_ASSERT( img->isPublic() == false );
|
||||
|
||||
|
||||
// make it non-persistent
|
||||
success = img->persistent(false);
|
||||
CPPUNIT_ASSERT( success == true );
|
||||
CPPUNIT_ASSERT( success == 0 );
|
||||
CPPUNIT_ASSERT( img->isPersistent() == false );
|
||||
|
||||
// it isn't public, try to unpublish
|
||||
success = img->publish(false);
|
||||
CPPUNIT_ASSERT( success == true );
|
||||
CPPUNIT_ASSERT( success == 0 );
|
||||
CPPUNIT_ASSERT( img->isPublic() == false );
|
||||
|
||||
// try to publish, now it should be possible
|
||||
success = img->publish(true);
|
||||
CPPUNIT_ASSERT( success == true );
|
||||
CPPUNIT_ASSERT( success == 0 );
|
||||
CPPUNIT_ASSERT( img->isPublic() == true );
|
||||
}
|
||||
|
||||
@ -868,17 +905,14 @@ public:
|
||||
CPPUNIT_ASSERT(rc == 0);
|
||||
|
||||
string result = oss.str();
|
||||
|
||||
result.replace(157, 10, replacement);
|
||||
result.replace(1076, 10, replacement);
|
||||
result.replace(1535, 10, replacement);
|
||||
fix_regtimes(result);
|
||||
|
||||
/*
|
||||
if( result != xml_dump )
|
||||
{
|
||||
cout << endl << result << endl << xml_dump << endl;
|
||||
}
|
||||
*/
|
||||
//*/
|
||||
|
||||
CPPUNIT_ASSERT( result == xml_dump );
|
||||
}
|
||||
@ -904,15 +938,14 @@ public:
|
||||
CPPUNIT_ASSERT(rc == 0);
|
||||
|
||||
string result = oss.str();
|
||||
result.replace(157, 10, replacement);
|
||||
result.replace(1076, 10, replacement);
|
||||
|
||||
fix_regtimes(result);
|
||||
|
||||
/*
|
||||
if( result != xml_dump_where )
|
||||
{
|
||||
cout << endl << result << endl << xml_dump_where << endl;
|
||||
}
|
||||
|
||||
//*/
|
||||
|
||||
CPPUNIT_ASSERT( result == xml_dump_where );
|
||||
}
|
||||
|
@ -17,20 +17,30 @@
|
||||
Import('env')
|
||||
|
||||
env.Prepend(LIBS=[
|
||||
'nebula_image',
|
||||
### TODO: delete not needed
|
||||
'nebula_core_test',
|
||||
'nebula_host',
|
||||
'nebula_xml',
|
||||
'nebula_vmm',
|
||||
'nebula_im',
|
||||
'nebula_rm',
|
||||
'nebula_tm',
|
||||
'nebula_um',
|
||||
'nebula_vm',
|
||||
'nebula_hm',
|
||||
'nebula_vnm',
|
||||
'nebula_authm',
|
||||
'nebula_template',
|
||||
'nebula_pool',
|
||||
'nebula_mad',
|
||||
'nebula_template',
|
||||
'nebula_vm',
|
||||
'nebula_vmtemplate',
|
||||
'nebula_group',
|
||||
'nebula_vnm',
|
||||
'nebula_image',
|
||||
'nebula_pool',
|
||||
'nebula_hm',
|
||||
'nebula_authm',
|
||||
'nebula_common',
|
||||
'nebula_core',
|
||||
'nebula_lcm',
|
||||
'nebula_dm',
|
||||
'nebula_sql',
|
||||
'nebula_log',
|
||||
'nebula_xml',
|
||||
'crypto'
|
||||
])
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
using namespace std;
|
||||
|
||||
const int uids[] = {123, 261, 123};
|
||||
const int gids[] = {150, 164, 175};
|
||||
|
||||
const string names[] = {"VM one", "Second VM", "VM 3"};
|
||||
|
||||
@ -185,7 +186,7 @@ private:
|
||||
|
||||
if( rc == 0 )
|
||||
{
|
||||
return vmpool->allocate(uids[index], "username", vm_template, &oid,
|
||||
return vmpool->allocate(uids[index], gids[index], vm_template, &oid,
|
||||
err, false);
|
||||
}
|
||||
else
|
||||
|
@ -29,6 +29,7 @@ public:
|
||||
need_vm_pool = true;
|
||||
need_host_pool = true;
|
||||
need_user_pool = true;
|
||||
need_group_pool = true;
|
||||
need_vnet_pool = true;
|
||||
need_image_pool= true;
|
||||
|
||||
|
@ -21,7 +21,6 @@ Import('env')
|
||||
env.Prepend(LIBS=[
|
||||
'nebula_core_test',
|
||||
'nebula_host',
|
||||
'nebula_cluster',
|
||||
'nebula_vmm',
|
||||
'nebula_im',
|
||||
'nebula_rm',
|
||||
@ -31,9 +30,9 @@ env.Prepend(LIBS=[
|
||||
'nebula_template',
|
||||
'nebula_vm',
|
||||
'nebula_vmtemplate',
|
||||
'nebula_group',
|
||||
'nebula_vnm',
|
||||
'nebula_image',
|
||||
'nebula_pool',
|
||||
'nebula_xml',
|
||||
'nebula_hm',
|
||||
'nebula_authm',
|
||||
@ -42,6 +41,7 @@ env.Prepend(LIBS=[
|
||||
'nebula_log',
|
||||
'nebula_lcm',
|
||||
'nebula_dm',
|
||||
'nebula_pool',
|
||||
'crypto'
|
||||
])
|
||||
|
||||
|
26
src/mad/test/dummy
Executable file
26
src/mad/test/dummy
Executable file
@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) #
|
||||
# #
|
||||
# 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. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
#echo "MAD started" >> mad.log
|
||||
|
||||
while read COMMAND ARG1 ARG2 ARG3
|
||||
do
|
||||
# echo "$COMMAND $ARG1 $ARG2 $ARG3" >> mad.log
|
||||
|
||||
echo "$COMMAND SUCCESS"
|
||||
done
|
@ -243,9 +243,9 @@ void Nebula::start()
|
||||
VirtualMachinePool::bootstrap(db);
|
||||
HostPool::bootstrap(db);
|
||||
VirtualNetworkPool::bootstrap(db);
|
||||
GroupPool::bootstrap(db);
|
||||
UserPool::bootstrap(db);
|
||||
ImagePool::bootstrap(db);
|
||||
ClusterPool::bootstrap(db);
|
||||
VMTemplatePool::bootstrap(db);
|
||||
}
|
||||
}
|
||||
@ -275,6 +275,8 @@ void Nebula::start()
|
||||
|
||||
vnpool = new VirtualNetworkPool(db,mac_prefix,size);
|
||||
|
||||
gpool = new GroupPool(db);
|
||||
|
||||
upool = new UserPool(db);
|
||||
|
||||
nebula_configuration->get("DEFAULT_IMAGE_TYPE", default_image_type);
|
||||
@ -285,8 +287,6 @@ void Nebula::start()
|
||||
default_image_type,
|
||||
default_device_prefix);
|
||||
|
||||
cpool = new ClusterPool(db);
|
||||
|
||||
tpool = new VMTemplatePool(db);
|
||||
}
|
||||
catch (exception&)
|
||||
@ -447,16 +447,7 @@ void Nebula::start()
|
||||
|
||||
nebula_configuration->get("PORT", rm_port);
|
||||
|
||||
rm = new RequestManager(
|
||||
vmpool,
|
||||
hpool,
|
||||
vnpool,
|
||||
upool,
|
||||
ipool,
|
||||
cpool,
|
||||
tpool,
|
||||
rm_port,
|
||||
log_location + "one_xmlrpc.log");
|
||||
rm = new RequestManager(rm_port, log_location + "one_xmlrpc.log");
|
||||
}
|
||||
catch (bad_alloc&)
|
||||
{
|
||||
@ -616,6 +607,7 @@ void Nebula::bootstrap()
|
||||
|
||||
oss << "CREATE TABLE pool_control (tablename VARCHAR(32) PRIMARY KEY, "
|
||||
"last_oid BIGINT UNSIGNED)";
|
||||
|
||||
db->exec(oss);
|
||||
|
||||
oss.str("");
|
||||
|
@ -41,12 +41,12 @@ env.Prepend(LIBS=[
|
||||
'nebula_dm',
|
||||
'nebula_tm',
|
||||
'nebula_um',
|
||||
'nebula_group',
|
||||
'nebula_authm',
|
||||
'nebula_mad',
|
||||
'nebula_template',
|
||||
'nebula_image',
|
||||
'nebula_pool',
|
||||
'nebula_cluster',
|
||||
'nebula_host',
|
||||
'nebula_vnm',
|
||||
'nebula_vm',
|
||||
|
@ -134,6 +134,50 @@ public abstract class PoolElement {
|
||||
return state != null ? Integer.parseInt( state ) : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the owner User's ID, or -1 if the element doesn't have one.
|
||||
*
|
||||
* @return the owner User's ID, or -1 if the element doesn't have one.
|
||||
*/
|
||||
public int uid()
|
||||
{
|
||||
String uid_str = xpath("UID");
|
||||
int uid_int = -1;
|
||||
|
||||
if ( uid_str != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
uid_int = Integer.parseInt( uid_str );
|
||||
}
|
||||
catch (NumberFormatException e) {}
|
||||
}
|
||||
|
||||
return uid_int;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the element group's ID, or -1 if the element doesn't have one.
|
||||
*
|
||||
* @return the element group's ID, or -1 if the element doesn't have one.
|
||||
*/
|
||||
public int gid()
|
||||
{
|
||||
String gid_str = xpath("GID");
|
||||
int gid_int = -1;
|
||||
|
||||
if ( gid_str != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
gid_int = Integer.parseInt( gid_str );
|
||||
}
|
||||
catch (NumberFormatException e) {}
|
||||
}
|
||||
|
||||
return gid_int;
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates an XPath expression and returns the result as a String.
|
||||
* If the internal xml representation is not built, returns null. The
|
||||
@ -141,7 +185,8 @@ public abstract class PoolElement {
|
||||
*
|
||||
* @param expression The XPath expression.
|
||||
* @return The String that is the result of evaluating the
|
||||
* expression and converting the result to a String. Null if
|
||||
* expression and converting the result to a String. An empty String is
|
||||
* returned if the expression is not a valid path; null if
|
||||
* the internal xml representation is not built.
|
||||
*/
|
||||
public String xpath(String expression)
|
||||
|
@ -1,198 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org)
|
||||
*
|
||||
* 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.
|
||||
******************************************************************************/
|
||||
package org.opennebula.client.cluster;
|
||||
|
||||
import org.opennebula.client.Client;
|
||||
import org.opennebula.client.OneResponse;
|
||||
import org.opennebula.client.PoolElement;
|
||||
import org.opennebula.client.host.Host;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
/**
|
||||
* This class represents an OpenNebula cluster.
|
||||
* It also offers static XML-RPC call wrappers.
|
||||
*/
|
||||
public class Cluster extends PoolElement
|
||||
{
|
||||
|
||||
private static final String METHOD_PREFIX = "cluster.";
|
||||
private static final String ALLOCATE = METHOD_PREFIX + "allocate";
|
||||
private static final String INFO = METHOD_PREFIX + "info";
|
||||
private static final String DELETE = METHOD_PREFIX + "delete";
|
||||
private static final String ADD = METHOD_PREFIX + "add";
|
||||
private static final String REMOVE = METHOD_PREFIX + "remove";
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new Image representation.
|
||||
* @param id The image id.
|
||||
* @param client XML-RPC Client.
|
||||
*/
|
||||
public Cluster(int id, Client client)
|
||||
{
|
||||
super(id, client);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see PoolElement
|
||||
*/
|
||||
protected Cluster(Node xmlElement, Client client)
|
||||
{
|
||||
super(xmlElement, client);
|
||||
}
|
||||
|
||||
|
||||
// =================================
|
||||
// Static XML-RPC methods
|
||||
// =================================
|
||||
|
||||
|
||||
/**
|
||||
* Allocates a new Cluster in OpenNebula.
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param name Name for the cluster we want to add.
|
||||
* @return If successful the message contains the associated
|
||||
* id generated for this Cluster.
|
||||
*/
|
||||
public static OneResponse allocate(Client client, String name)
|
||||
{
|
||||
return client.call(ALLOCATE, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the information of the given Cluster.
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param id The cluster id for the cluster to retrieve the information from
|
||||
* @return If successful the message contains the string
|
||||
* with the information returned by OpenNebula.
|
||||
*/
|
||||
public static OneResponse info(Client client, int id)
|
||||
{
|
||||
return client.call(INFO, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a cluster from OpenNebula.
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param id The cluster id of the target cluster we want to delete.
|
||||
* @return A encapsulated response.
|
||||
*/
|
||||
public static OneResponse delete(Client client, int id)
|
||||
{
|
||||
return client.call(DELETE, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a host to a cluster.
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param id The cluster id of the cluster where the host will be assigned.
|
||||
* @param hid The host id (hid) of the host.
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public static OneResponse add(Client client, int id, int hid)
|
||||
{
|
||||
return client.call(ADD, hid, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a host from its cluster.
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param hid The host id (hid) of the host.
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public static OneResponse remove(Client client, int hid)
|
||||
{
|
||||
return client.call(REMOVE, hid);
|
||||
}
|
||||
|
||||
|
||||
// =================================
|
||||
// Instanced object XML-RPC methods
|
||||
// =================================
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the information of the Cluster.
|
||||
*
|
||||
* @return If successful the message contains the string
|
||||
* with the information returned by OpenNebula.
|
||||
*/
|
||||
public OneResponse info()
|
||||
{
|
||||
OneResponse response = info(client, id);
|
||||
super.processInfo(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the cluster from OpenNebula.
|
||||
*
|
||||
* @return A encapsulated response.
|
||||
*/
|
||||
public OneResponse delete()
|
||||
{
|
||||
return delete(client, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a host to the cluster.
|
||||
*
|
||||
* @param hid The host id (hid) of the host.
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public OneResponse add(int hid)
|
||||
{
|
||||
return add(client, id, hid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a host to the cluster.
|
||||
*
|
||||
* @param host The Host to add.
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public OneResponse add(Host host)
|
||||
{
|
||||
return add(client, id, host.id());
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a host from its cluster.
|
||||
*
|
||||
* @param hid The host id (hid) of the host.
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public OneResponse remove(int hid)
|
||||
{
|
||||
return remove(client, hid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a host from its cluster.
|
||||
*
|
||||
* @param host The Host to remove.
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public OneResponse remove(Host host)
|
||||
{
|
||||
return remove(client, host.id());
|
||||
}
|
||||
}
|
140
src/oca/java/src/org/opennebula/client/group/Group.java
Normal file
140
src/oca/java/src/org/opennebula/client/group/Group.java
Normal file
@ -0,0 +1,140 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org)
|
||||
*
|
||||
* 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.
|
||||
******************************************************************************/
|
||||
package org.opennebula.client.group;
|
||||
|
||||
|
||||
import org.opennebula.client.Client;
|
||||
import org.opennebula.client.OneResponse;
|
||||
import org.opennebula.client.PoolElement;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
/**
|
||||
* This class represents an OpenNebula group.
|
||||
* It also offers static XML-RPC call wrappers.
|
||||
*/
|
||||
public class Group extends PoolElement{
|
||||
|
||||
private static final String METHOD_PREFIX = "group.";
|
||||
private static final String ALLOCATE = METHOD_PREFIX + "allocate";
|
||||
private static final String INFO = METHOD_PREFIX + "info";
|
||||
private static final String DELETE = METHOD_PREFIX + "delete";
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new Group representation.
|
||||
*
|
||||
* @param id The group id (hid) of the machine.
|
||||
* @param client XML-RPC Client.
|
||||
*/
|
||||
public Group(int id, Client client)
|
||||
{
|
||||
super(id, client);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see PoolElement
|
||||
*/
|
||||
protected Group(Node xmlElement, Client client)
|
||||
{
|
||||
super(xmlElement, client);
|
||||
}
|
||||
|
||||
|
||||
// =================================
|
||||
// Static XML-RPC methods
|
||||
// =================================
|
||||
|
||||
/**
|
||||
* Allocates a new group in OpenNebula
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param name Name for the new group.
|
||||
* @return If successful the message contains the associated
|
||||
* id generated for this group.
|
||||
*/
|
||||
public static OneResponse allocate(Client client, String name)
|
||||
{
|
||||
return client.call(ALLOCATE, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the information of the given group.
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param id The group id.
|
||||
* @return If successful the message contains the string
|
||||
* with the information returned by OpenNebula.
|
||||
*/
|
||||
public static OneResponse info(Client client, int id)
|
||||
{
|
||||
return client.call(INFO, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a group from OpenNebula.
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param id The group id.
|
||||
* @return A encapsulated response.
|
||||
*/
|
||||
public static OneResponse delete(Client client, int id)
|
||||
{
|
||||
return client.call(DELETE, id);
|
||||
}
|
||||
|
||||
// =================================
|
||||
// Instanced object XML-RPC methods
|
||||
// =================================
|
||||
|
||||
/**
|
||||
* Loads the xml representation of the group.
|
||||
* The info is also stored internally.
|
||||
*
|
||||
* @see Group#info(Client, int)
|
||||
*/
|
||||
public OneResponse info()
|
||||
{
|
||||
OneResponse response = info(client, id);
|
||||
super.processInfo(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the group from OpenNebula.
|
||||
*
|
||||
* @see Group#delete(Client, int)
|
||||
*/
|
||||
public OneResponse delete()
|
||||
{
|
||||
return delete(client, id);
|
||||
}
|
||||
|
||||
// =================================
|
||||
// Helpers
|
||||
// =================================
|
||||
|
||||
/**
|
||||
* Returns whether or not the user is part of this group
|
||||
*
|
||||
* @param uid The user ID.
|
||||
* @return Whether or not the user is part of this group.
|
||||
*/
|
||||
public boolean contains(int uid)
|
||||
{
|
||||
String res = xpath("USERS/ID[.="+uid+"]");
|
||||
return res != null && res.equals(""+uid);
|
||||
}
|
||||
}
|
@ -1,23 +1,24 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org)
|
||||
*
|
||||
*
|
||||
* 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.
|
||||
******************************************************************************/
|
||||
package org.opennebula.client.cluster;
|
||||
package org.opennebula.client.group;
|
||||
|
||||
import java.util.AbstractList;
|
||||
import java.util.Iterator;
|
||||
|
||||
|
||||
import org.opennebula.client.Client;
|
||||
import org.opennebula.client.OneResponse;
|
||||
import org.opennebula.client.Pool;
|
||||
@ -25,36 +26,32 @@ import org.opennebula.client.PoolElement;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
/**
|
||||
* This class represents an OpenNebula Cluster pool.
|
||||
* This class represents an OpenNebula group pool.
|
||||
* It also offers static XML-RPC call wrappers.
|
||||
*/
|
||||
public class ClusterPool extends Pool implements Iterable<Cluster>
|
||||
{
|
||||
private static final String ELEMENT_NAME = "CLUSTER";
|
||||
private static final String INFO_METHOD = "clusterpool.info";
|
||||
public class GroupPool extends Pool implements Iterable<Group>{
|
||||
|
||||
private static final String ELEMENT_NAME = "GROUP";
|
||||
private static final String INFO_METHOD = "grouppool.info";
|
||||
|
||||
/**
|
||||
* Creates a new Image pool
|
||||
*
|
||||
* Creates a new group pool
|
||||
* @param client XML-RPC Client.
|
||||
*/
|
||||
public ClusterPool(Client client)
|
||||
public GroupPool(Client client)
|
||||
{
|
||||
super(ELEMENT_NAME, client);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.opennebula.client.Pool#factory(org.w3c.dom.Node)
|
||||
*/
|
||||
@Override
|
||||
public PoolElement factory(Node node)
|
||||
{
|
||||
return new Cluster(node, client);
|
||||
return new Group(node, client);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Cluster pool information.
|
||||
*
|
||||
* Retrieves all the hosts in the pool.
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @return If successful the message contains the string
|
||||
* with the information returned by OpenNebula.
|
||||
@ -65,9 +62,9 @@ public class ClusterPool extends Pool implements Iterable<Cluster>
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the xml representation of the Cluster pool.
|
||||
*
|
||||
* @see ClusterPool#info(Client)
|
||||
* Loads the xml representation of the group pool.
|
||||
*
|
||||
* @see GroupPool#info(Client)
|
||||
*/
|
||||
public OneResponse info()
|
||||
{
|
||||
@ -76,18 +73,18 @@ public class ClusterPool extends Pool implements Iterable<Cluster>
|
||||
return response;
|
||||
}
|
||||
|
||||
public Iterator<Cluster> iterator()
|
||||
public Iterator<Group> iterator()
|
||||
{
|
||||
AbstractList<Cluster> ab = new AbstractList<Cluster>()
|
||||
AbstractList<Group> ab = new AbstractList<Group>()
|
||||
{
|
||||
public int size()
|
||||
{
|
||||
return getLength();
|
||||
}
|
||||
|
||||
public Cluster get(int index)
|
||||
public Group get(int index)
|
||||
{
|
||||
return (Cluster) item(index);
|
||||
return (Group) item(index);
|
||||
}
|
||||
};
|
||||
|
@ -32,6 +32,7 @@ public class Host extends PoolElement{
|
||||
private static final String INFO = METHOD_PREFIX + "info";
|
||||
private static final String DELETE = METHOD_PREFIX + "delete";
|
||||
private static final String ENABLE = METHOD_PREFIX + "enable";
|
||||
private static final String UPDATE = METHOD_PREFIX + "update";
|
||||
|
||||
private static final String[] HOST_STATES =
|
||||
{"INIT", "MONITORING", "MONITORED", "ERROR", "DISABLED"};
|
||||
@ -122,7 +123,19 @@ public class Host extends PoolElement{
|
||||
{
|
||||
return client.call(ENABLE, id, enable);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Replaces the template contents.
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param id The image id of the target host we want to modify.
|
||||
* @param new_template New template contents
|
||||
* @return If successful the message contains the host id.
|
||||
*/
|
||||
public static OneResponse update(Client client, int id, String new_template)
|
||||
{
|
||||
return client.call(UPDATE, id, new_template);
|
||||
}
|
||||
|
||||
// =================================
|
||||
// Instanced object XML-RPC methods
|
||||
@ -181,6 +194,17 @@ public class Host extends PoolElement{
|
||||
return enable(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the template contents.
|
||||
*
|
||||
* @param new_template New template contents
|
||||
* @return If successful the message contains the host id.
|
||||
*/
|
||||
public OneResponse update(String new_template)
|
||||
{
|
||||
return update(client, id, new_template);
|
||||
}
|
||||
|
||||
// =================================
|
||||
// Helpers
|
||||
// =================================
|
||||
@ -227,14 +251,4 @@ public class Host extends PoolElement{
|
||||
{
|
||||
return state() != 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the cluster this host is assigned to.
|
||||
*
|
||||
* @return The name of the cluster this host is assigned to.
|
||||
*/
|
||||
public String getCluster()
|
||||
{
|
||||
return xpath("CLUSTER");
|
||||
}
|
||||
}
|
||||
|
@ -32,9 +32,9 @@ public class Image extends PoolElement
|
||||
private static final String INFO = METHOD_PREFIX + "info";
|
||||
private static final String DELETE = METHOD_PREFIX + "delete";
|
||||
private static final String UPDATE = METHOD_PREFIX + "update";
|
||||
private static final String RMATTR = METHOD_PREFIX + "rmattr";
|
||||
private static final String ENABLE = METHOD_PREFIX + "enable";
|
||||
private static final String PUBLISH = METHOD_PREFIX + "publish";
|
||||
private static final String CHOWN = METHOD_PREFIX + "chown";
|
||||
|
||||
private static final String[] IMAGE_STATES =
|
||||
{"INIT", "READY", "USED", "DISABLED"};
|
||||
@ -110,31 +110,16 @@ public class Image extends PoolElement
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifies an image attribute.
|
||||
* Replaces the template contents.
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param id The image id of the target image we want to modify.
|
||||
* @param att_name The name of the attribute to update.
|
||||
* @param att_val The new value for the attribute.
|
||||
* @param new_template New template contents
|
||||
* @return If successful the message contains the image id.
|
||||
*/
|
||||
public static OneResponse update(Client client, int id,
|
||||
String att_name, String att_val)
|
||||
public static OneResponse update(Client client, int id, String new_template)
|
||||
{
|
||||
return client.call(UPDATE, id, att_name, att_val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an image attribute.
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param id The image id of the target image we want to modify.
|
||||
* @param att_name The name of the attribute to remove.
|
||||
* @return If successful the message contains the image id.
|
||||
*/
|
||||
public static OneResponse rmattr(Client client, int id, String att_name)
|
||||
{
|
||||
return client.call(RMATTR, id, att_name);
|
||||
return client.call(UPDATE, id, new_template);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -163,6 +148,19 @@ public class Image extends PoolElement
|
||||
return client.call(PUBLISH, id, publish);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the owner/group
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param id The image id of the target image we want to modify.
|
||||
* @param uid The new owner user ID. Set it to -1 to leave the current one.
|
||||
* @param gid The new group ID. Set it to -1 to leave the current one.
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public static OneResponse chown(Client client, int id, int uid, int gid)
|
||||
{
|
||||
return client.call(CHOWN, id, uid, gid);
|
||||
}
|
||||
|
||||
// =================================
|
||||
// Instanced object XML-RPC methods
|
||||
@ -192,26 +190,14 @@ public class Image extends PoolElement
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifies an image attribute.
|
||||
* Replaces the template contents.
|
||||
*
|
||||
* @param att_name The name of the attribute to update.
|
||||
* @param att_val The new value for the attribute.
|
||||
* @param new_template New template contents
|
||||
* @return If successful the message contains the image id.
|
||||
*/
|
||||
public OneResponse update(String att_name, String att_val)
|
||||
public OneResponse update(String new_template)
|
||||
{
|
||||
return update(client, id, att_name, att_val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an image attribute.
|
||||
*
|
||||
* @param att_name The name of the attribute to remove.
|
||||
* @return If successful the message contains the image id.
|
||||
*/
|
||||
public OneResponse rmattr(String att_name)
|
||||
{
|
||||
return rmattr(client, id, att_name);
|
||||
return update(client, id, new_template);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -276,6 +262,40 @@ public class Image extends PoolElement
|
||||
return publish(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the owner/group
|
||||
*
|
||||
* @param uid The new owner user ID. Set it to -1 to leave the current one.
|
||||
* @param gid The new group ID. Set it to -1 to leave the current one.
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public OneResponse chown(int uid, int gid)
|
||||
{
|
||||
return chown(client, id, uid, gid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the owner
|
||||
*
|
||||
* @param uid The new owner user ID.
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public OneResponse chown(int uid)
|
||||
{
|
||||
return chown(uid, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the group
|
||||
*
|
||||
* @param gid The new group ID.
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public OneResponse chgrp(int gid)
|
||||
{
|
||||
return chown(-1, gid);
|
||||
}
|
||||
|
||||
// =================================
|
||||
// Helpers
|
||||
// =================================
|
||||
|
@ -32,8 +32,9 @@ public class Template extends PoolElement
|
||||
private static final String INFO = METHOD_PREFIX + "info";
|
||||
private static final String DELETE = METHOD_PREFIX + "delete";
|
||||
private static final String UPDATE = METHOD_PREFIX + "update";
|
||||
private static final String RMATTR = METHOD_PREFIX + "rmattr";
|
||||
private static final String PUBLISH = METHOD_PREFIX + "publish";
|
||||
private static final String CHOWN = METHOD_PREFIX + "chown";
|
||||
private static final String INSTANTIATE = METHOD_PREFIX + "instantiate";
|
||||
|
||||
/**
|
||||
* Creates a new Template representation.
|
||||
@ -97,31 +98,16 @@ public class Template extends PoolElement
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifies a template attribute.
|
||||
* Replaces the template contents.
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param id The template id of the target template we want to modify.
|
||||
* @param att_name The name of the attribute to update.
|
||||
* @param att_val The new value for the attribute.
|
||||
* @param new_template New template contents.
|
||||
* @return If successful the message contains the template id.
|
||||
*/
|
||||
public static OneResponse update(Client client, int id,
|
||||
String att_name, String att_val)
|
||||
public static OneResponse update(Client client, int id, String new_template)
|
||||
{
|
||||
return client.call(UPDATE, id, att_name, att_val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a template attribute.
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param id The template id of the target template we want to modify.
|
||||
* @param att_name The name of the attribute to remove.
|
||||
* @return If successful the message contains the template id.
|
||||
*/
|
||||
public static OneResponse rmattr(Client client, int id, String att_name)
|
||||
{
|
||||
return client.call(RMATTR, id, att_name);
|
||||
return client.call(UPDATE, id, new_template);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -137,6 +123,32 @@ public class Template extends PoolElement
|
||||
return client.call(PUBLISH, id, publish);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the owner/group
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param id The template id of the target template we want to modify.
|
||||
* @param uid The new owner user ID. Set it to -1 to leave the current one.
|
||||
* @param gid The new group ID. Set it to -1 to leave the current one.
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public static OneResponse chown(Client client, int id, int uid, int gid)
|
||||
{
|
||||
return client.call(CHOWN, id, uid, gid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a VM instance from a Template
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param id The template id of the target template.
|
||||
* @param name A string containing the name of the VM instance, can be empty.
|
||||
* @return If successful the message contains the VM Instance ID.
|
||||
*/
|
||||
public static OneResponse instantiate(Client client, int id, String name)
|
||||
{
|
||||
return client.call(INSTANTIATE, id, name);
|
||||
}
|
||||
|
||||
// =================================
|
||||
// Instanced object XML-RPC methods
|
||||
@ -166,26 +178,14 @@ public class Template extends PoolElement
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifies a template attribute.
|
||||
* Replaces the template contents.
|
||||
*
|
||||
* @param att_name The name of the attribute to update.
|
||||
* @param att_val The new value for the attribute.
|
||||
* @param new_template New template contents.
|
||||
* @return If successful the message contains the template id.
|
||||
*/
|
||||
public OneResponse update(String att_name, String att_val)
|
||||
public OneResponse update(String new_template)
|
||||
{
|
||||
return update(client, id, att_name, att_val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a template attribute.
|
||||
*
|
||||
* @param att_name The name of the attribute to remove.
|
||||
* @return If successful the message contains the template id.
|
||||
*/
|
||||
public OneResponse rmattr(String att_name)
|
||||
{
|
||||
return rmattr(client, id, att_name);
|
||||
return update(client, id, new_template);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -219,6 +219,61 @@ public class Template extends PoolElement
|
||||
return publish(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the owner/group
|
||||
*
|
||||
* @param uid The new owner user ID. Set it to -1 to leave the current one.
|
||||
* @param gid The new group ID. Set it to -1 to leave the current one.
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public OneResponse chown(int uid, int gid)
|
||||
{
|
||||
return chown(client, id, uid, gid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the owner
|
||||
*
|
||||
* @param uid The new owner user ID.
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public OneResponse chown(int uid)
|
||||
{
|
||||
return chown(uid, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the group
|
||||
*
|
||||
* @param gid The new group ID.
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public OneResponse chgrp(int gid)
|
||||
{
|
||||
return chown(-1, gid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a VM instance from a Template
|
||||
*
|
||||
* @param name A string containing the name of the VM instance, can be empty.
|
||||
* @return If successful the message contains the VM Instance ID.
|
||||
*/
|
||||
public OneResponse instantiate(String name)
|
||||
{
|
||||
return instantiate(client, id, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a VM instance from a Template
|
||||
*
|
||||
* @return If successful the message contains the VM Instance ID.
|
||||
*/
|
||||
public OneResponse instantiate()
|
||||
{
|
||||
return instantiate(client, id, "");
|
||||
}
|
||||
|
||||
// =================================
|
||||
// Helpers
|
||||
// =================================
|
||||
|
@ -32,6 +32,9 @@ public class User extends PoolElement{
|
||||
private static final String INFO = METHOD_PREFIX + "info";
|
||||
private static final String DELETE = METHOD_PREFIX + "delete";
|
||||
private static final String PASSWD = METHOD_PREFIX + "passwd";
|
||||
private static final String CHGRP = METHOD_PREFIX + "chgrp";
|
||||
private static final String ADDGROUP = METHOD_PREFIX + "addgroup";
|
||||
private static final String DELGROUP = METHOD_PREFIX + "delgroup";
|
||||
|
||||
/**
|
||||
* Creates a new User representation.
|
||||
@ -111,6 +114,45 @@ public class User extends PoolElement{
|
||||
return client.call(PASSWD, id, password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the main group of the given user
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param id The user id (uid) of the target user we want to modify.
|
||||
* @param gid The new group ID.
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public static OneResponse chgrp(Client client, int id, int gid)
|
||||
{
|
||||
return client.call(CHGRP, id, gid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds this user to a secondary group
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param id The user id (uid) of the target user we want to modify.
|
||||
* @param gid The new group ID.
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public static OneResponse addgroup(Client client, int id, int gid)
|
||||
{
|
||||
return client.call(ADDGROUP, id, gid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes this user from a secondary group
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param id The user id (uid) of the target user we want to modify.
|
||||
* @param gid The new group ID.
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public static OneResponse delgroup(Client client, int id, int gid)
|
||||
{
|
||||
return client.call(DELGROUP, id, gid);
|
||||
}
|
||||
|
||||
// =================================
|
||||
// Instanced object XML-RPC methods
|
||||
// =================================
|
||||
@ -150,6 +192,39 @@ public class User extends PoolElement{
|
||||
return passwd(client, id, password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the main group of the given user
|
||||
*
|
||||
* @param gid The new group ID.
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public OneResponse chgrp(int gid)
|
||||
{
|
||||
return chgrp(client, id, gid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds this user to a secondary group
|
||||
*
|
||||
* @param gid The new group ID.
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public OneResponse addgroup(int gid)
|
||||
{
|
||||
return addgroup(client, id, gid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes this user from a secondary group
|
||||
*
|
||||
* @param gid The new group ID.
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public OneResponse delgroup(int gid)
|
||||
{
|
||||
return delgroup(client, id, gid);
|
||||
}
|
||||
|
||||
// =================================
|
||||
// Helpers
|
||||
// =================================
|
||||
@ -164,4 +239,16 @@ public class User extends PoolElement{
|
||||
String enabled = xpath("ENABLED");
|
||||
return enabled != null && enabled.equals("1");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the user is part of the group
|
||||
*
|
||||
* @param gid The group ID.
|
||||
* @return whether or not the user is part of the group
|
||||
*/
|
||||
public boolean isPartOf(int gid)
|
||||
{
|
||||
String res = xpath("GROUPS/ID[.="+gid+"]");
|
||||
return res != null && res.equals(""+gid);
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ public class VirtualMachine extends PoolElement{
|
||||
private static final String ACTION = METHOD_PREFIX + "action";
|
||||
private static final String MIGRATE = METHOD_PREFIX + "migrate";
|
||||
private static final String SAVEDISK = METHOD_PREFIX + "savedisk";
|
||||
private static final String CHOWN = METHOD_PREFIX + "chown";
|
||||
|
||||
private static final String[] VM_STATES =
|
||||
{
|
||||
@ -198,6 +199,19 @@ public class VirtualMachine extends PoolElement{
|
||||
return client.call(INFO, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the owner/group
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param id The virtual machine id (vid) of the target instance.
|
||||
* @param uid The new owner user ID. Set it to -1 to leave the current one.
|
||||
* @param gid The new group ID. Set it to -1 to leave the current one.
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public static OneResponse chown(Client client, int id, int uid, int gid)
|
||||
{
|
||||
return client.call(CHOWN, id, uid, gid);
|
||||
}
|
||||
|
||||
// =================================
|
||||
// Instanced object XML-RPC methods
|
||||
@ -281,6 +295,40 @@ public class VirtualMachine extends PoolElement{
|
||||
return client.call(SAVEDISK, id ,diskId, imageName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the owner/group
|
||||
*
|
||||
* @param uid The new owner user ID. Set it to -1 to leave the current one.
|
||||
* @param gid The new group ID. Set it to -1 to leave the current one.
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public OneResponse chown(int uid, int gid)
|
||||
{
|
||||
return chown(client, id, uid, gid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the owner
|
||||
*
|
||||
* @param uid The new owner user ID.
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public OneResponse chown(int uid)
|
||||
{
|
||||
return chown(uid, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the group
|
||||
*
|
||||
* @param gid The new group ID.
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public OneResponse chgrp(int gid)
|
||||
{
|
||||
return chown(-1, gid);
|
||||
}
|
||||
|
||||
// =================================
|
||||
// Helpers
|
||||
// =================================
|
||||
|
@ -34,6 +34,7 @@ public class VirtualNetwork extends PoolElement{
|
||||
private static final String PUBLISH = METHOD_PREFIX + "publish";
|
||||
private static final String ADDLEASES = METHOD_PREFIX + "addleases";
|
||||
private static final String RMLEASES = METHOD_PREFIX + "rmleases";
|
||||
private static final String CHOWN = METHOD_PREFIX + "chown";
|
||||
|
||||
|
||||
/**
|
||||
@ -138,6 +139,20 @@ public class VirtualNetwork extends PoolElement{
|
||||
return client.call(RMLEASES, id, template);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the owner/group
|
||||
*
|
||||
* @param client XML-RPC Client.
|
||||
* @param id The virtual network id (nid) of the target network.
|
||||
* @param uid The new owner user ID. Set it to -1 to leave the current one.
|
||||
* @param gid The new group ID. Set it to -1 to leave the current one.
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public static OneResponse chown(Client client, int id, int uid, int gid)
|
||||
{
|
||||
return client.call(CHOWN, id, uid, gid);
|
||||
}
|
||||
|
||||
// =================================
|
||||
// Instanced object XML-RPC methods
|
||||
// =================================
|
||||
@ -242,6 +257,40 @@ public class VirtualNetwork extends PoolElement{
|
||||
return rmLeases(client, id, lease_template);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the owner/group
|
||||
*
|
||||
* @param uid The new owner user ID. Set it to -1 to leave the current one.
|
||||
* @param gid The new group ID. Set it to -1 to leave the current one.
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public OneResponse chown(int uid, int gid)
|
||||
{
|
||||
return chown(client, id, uid, gid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the owner
|
||||
*
|
||||
* @param uid The new owner user ID.
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public OneResponse chown(int uid)
|
||||
{
|
||||
return chown(uid, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the group
|
||||
*
|
||||
* @param gid The new group ID.
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public OneResponse chgrp(int gid)
|
||||
{
|
||||
return chown(-1, gid);
|
||||
}
|
||||
|
||||
// =================================
|
||||
// Helpers
|
||||
// =================================
|
||||
|
@ -1,166 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org)
|
||||
*
|
||||
* 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.
|
||||
******************************************************************************/
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.opennebula.client.Client;
|
||||
import org.opennebula.client.OneResponse;
|
||||
import org.opennebula.client.cluster.Cluster;
|
||||
import org.opennebula.client.cluster.ClusterPool;
|
||||
import org.opennebula.client.host.Host;
|
||||
|
||||
|
||||
public class ClusterTest
|
||||
{
|
||||
|
||||
private static Cluster cluster;
|
||||
private static ClusterPool clusterPool;
|
||||
|
||||
private static Host host;
|
||||
|
||||
private static Client client;
|
||||
|
||||
private static OneResponse res;
|
||||
private static String name = "new_test_cluster";
|
||||
private static int hid = -1;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception
|
||||
{
|
||||
client = new Client();
|
||||
clusterPool = new ClusterPool(client);
|
||||
|
||||
res = Host.allocate(client, "new_test_host",
|
||||
"im_dummy", "vmm_dummy", "tm_dummy");
|
||||
try{
|
||||
hid = Integer.parseInt( res.getMessage() );
|
||||
}catch(NumberFormatException e)
|
||||
{
|
||||
System.err.println("Test initilization failed (setUpBeforeClass).");
|
||||
}
|
||||
host = new Host(hid, client);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
res = Cluster.allocate(client, name);
|
||||
|
||||
int clid = Integer.parseInt(res.getMessage());
|
||||
cluster = new Cluster(clid, client);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception
|
||||
{
|
||||
cluster.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allocate()
|
||||
{
|
||||
String allocate_name = "allocation_test";
|
||||
res = Cluster.allocate(client, allocate_name);
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
clusterPool.info();
|
||||
|
||||
boolean found = false;
|
||||
for(Cluster c : clusterPool)
|
||||
{
|
||||
found = found || c.getName().equals(allocate_name);
|
||||
}
|
||||
|
||||
assertTrue( found );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void update()
|
||||
{
|
||||
res = cluster.info();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
// assertTrue( cluster.getId().equals("1") );
|
||||
// assertTrue( cluster.id() == 1 );
|
||||
assertTrue( cluster.getName().equals(name) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addHost()
|
||||
{
|
||||
res = cluster.add(hid);
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
res = host.info();
|
||||
assertTrue( !res.isError() );
|
||||
assertTrue( host.getCluster().equals(name) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeHost()
|
||||
{
|
||||
assertTrue( hid > -1 );
|
||||
|
||||
res = cluster.remove(hid);
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
res = host.info();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
assertTrue( host.getCluster().equals("default") );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void attributes()
|
||||
{
|
||||
res = cluster.info();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
// assertTrue( cluster.xpath("ID").equals("1") );
|
||||
assertTrue( cluster.xpath("NAME").equals(name) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void delete()
|
||||
{
|
||||
res = cluster.delete();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
res = cluster.info();
|
||||
assertTrue( res.isError() );
|
||||
}
|
||||
}
|
224
src/oca/java/test/GroupTest.java
Normal file
224
src/oca/java/test/GroupTest.java
Normal file
@ -0,0 +1,224 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org)
|
||||
*
|
||||
* 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.
|
||||
******************************************************************************/
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.opennebula.client.Client;
|
||||
import org.opennebula.client.OneResponse;
|
||||
import org.opennebula.client.group.*;
|
||||
import org.opennebula.client.user.User;
|
||||
|
||||
public class GroupTest
|
||||
{
|
||||
|
||||
private static Group group;
|
||||
private static GroupPool groupPool;
|
||||
|
||||
private static Client client;
|
||||
|
||||
private static OneResponse res;
|
||||
|
||||
private static String group_name = "test_group";
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception
|
||||
{
|
||||
client = new Client();
|
||||
groupPool = new GroupPool(client);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
res = Group.allocate(client, group_name);
|
||||
|
||||
int group_id = res.isError() ? -1 : Integer.parseInt(res.getMessage());
|
||||
group = new Group(group_id, client);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@After
|
||||
public void tearDown() throws Exception
|
||||
{
|
||||
group.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allocate()
|
||||
{
|
||||
group.delete();
|
||||
|
||||
res = Group.allocate(client, group_name);
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
int group_id = res.isError() ? -1 : Integer.parseInt(res.getMessage());
|
||||
group = new Group(group_id, client);
|
||||
|
||||
|
||||
groupPool.info();
|
||||
|
||||
boolean found = false;
|
||||
for(Group img : groupPool)
|
||||
{
|
||||
found = found || img.getName().equals(group_name);
|
||||
}
|
||||
|
||||
assertTrue( found );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void info()
|
||||
{
|
||||
res = group.info();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
assertTrue( group.id() >= 100 );
|
||||
assertTrue( group.getName().equals(group_name) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void delete()
|
||||
{
|
||||
res = group.delete();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
res = group.info();
|
||||
assertTrue( res.isError() );
|
||||
|
||||
res = groupPool.info();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
boolean found = false;
|
||||
for(Group g : groupPool)
|
||||
{
|
||||
found = found || g.getName().equals(group_name);
|
||||
}
|
||||
|
||||
assertTrue( !found );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void userGroupRelations()
|
||||
{
|
||||
Hashtable<String, User> users = new Hashtable<String, User>();
|
||||
Hashtable<String, Group> groups = new Hashtable<String, Group>();
|
||||
|
||||
// Create all users and groups. Add user_* to corresponding group_*
|
||||
String[] names = {"a", "b", "c", "d"};
|
||||
for(String name : names)
|
||||
{
|
||||
res = User.allocate(client, "user_"+name, "password");
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
users.put( name,
|
||||
new User(Integer.parseInt(res.getMessage()), client )
|
||||
);
|
||||
|
||||
res = Group.allocate(client, "group_"+name);
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
groups.put( name,
|
||||
new Group(Integer.parseInt(res.getMessage()), client )
|
||||
);
|
||||
|
||||
users.get(name).addgroup( groups.get(name).id() );
|
||||
}
|
||||
|
||||
// Add all users to group_b
|
||||
for( User u : users.values() )
|
||||
{
|
||||
u.addgroup( groups.get("b").id() );
|
||||
}
|
||||
|
||||
// Change user_c & _d main group
|
||||
users.get("c").chgrp( groups.get("d").id() );
|
||||
users.get("d").chgrp( groups.get("c").id() );
|
||||
|
||||
|
||||
// Check cross-references so far
|
||||
for( User u : users.values() )
|
||||
{
|
||||
assertTrue( !u.info().isError() );
|
||||
}
|
||||
|
||||
for( Group g : groups.values() )
|
||||
{
|
||||
assertTrue( !g.info().isError() );
|
||||
}
|
||||
|
||||
assertTrue( users.get("a").isPartOf( groups.get("a").id() ) );
|
||||
assertTrue( users.get("a").isPartOf( groups.get("b").id() ) );
|
||||
assertFalse( users.get("a").isPartOf( groups.get("c").id() ) );
|
||||
assertFalse( users.get("a").isPartOf( groups.get("d").id() ) );
|
||||
|
||||
assertFalse( users.get("b").isPartOf( groups.get("a").id() ) );
|
||||
assertTrue( users.get("b").isPartOf( groups.get("b").id() ) );
|
||||
assertFalse( users.get("b").isPartOf( groups.get("c").id() ) );
|
||||
assertFalse( users.get("b").isPartOf( groups.get("d").id() ) );
|
||||
|
||||
assertFalse( users.get("c").isPartOf( groups.get("a").id() ) );
|
||||
assertTrue( users.get("c").isPartOf( groups.get("b").id() ) );
|
||||
assertTrue( users.get("c").isPartOf( groups.get("c").id() ) );
|
||||
assertTrue( users.get("c").isPartOf( groups.get("d").id() ) );
|
||||
|
||||
assertFalse( users.get("d").isPartOf( groups.get("a").id() ) );
|
||||
assertTrue( users.get("d").isPartOf( groups.get("b").id() ) );
|
||||
assertTrue( users.get("d").isPartOf( groups.get("c").id() ) );
|
||||
assertTrue( users.get("d").isPartOf( groups.get("d").id() ) );
|
||||
|
||||
assertTrue( groups.get("a").contains( users.get("a").id() ) );
|
||||
assertFalse( groups.get("a").contains( users.get("b").id() ) );
|
||||
assertFalse( groups.get("a").contains( users.get("c").id() ) );
|
||||
assertFalse( groups.get("a").contains( users.get("d").id() ) );
|
||||
|
||||
assertTrue( groups.get("b").contains( users.get("a").id() ) );
|
||||
assertTrue( groups.get("b").contains( users.get("b").id() ) );
|
||||
assertTrue( groups.get("b").contains( users.get("c").id() ) );
|
||||
assertTrue( groups.get("b").contains( users.get("d").id() ) );
|
||||
|
||||
assertFalse( groups.get("c").contains( users.get("a").id() ) );
|
||||
assertFalse( groups.get("c").contains( users.get("b").id() ) );
|
||||
assertTrue( groups.get("c").contains( users.get("c").id() ) );
|
||||
assertTrue( groups.get("c").contains( users.get("d").id() ) );
|
||||
assertFalse( groups.get("d").contains( users.get("a").id() ) );
|
||||
assertFalse( groups.get("d").contains( users.get("b").id() ) );
|
||||
assertTrue( groups.get("d").contains( users.get("c").id() ) );
|
||||
assertTrue( groups.get("d").contains( users.get("d").id() ) );
|
||||
}
|
||||
|
||||
}
|
@ -99,7 +99,7 @@ public class HostTest
|
||||
}
|
||||
|
||||
@Test
|
||||
public void update()
|
||||
public void info()
|
||||
{
|
||||
res = host.info();
|
||||
assertTrue( !res.isError() );
|
||||
@ -152,6 +152,30 @@ public class HostTest
|
||||
|
||||
assertTrue( !found );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void update()
|
||||
{
|
||||
res = host.info();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
assertTrue( host.xpath("TEMPLATE/ATT1").equals( "" ) );
|
||||
assertTrue( host.xpath("TEMPLATE/ATT2").equals( "" ) );
|
||||
|
||||
String new_template = "ATT2 = NEW_VAL\n" +
|
||||
"ATT3 = VAL3";
|
||||
|
||||
res = host.update(new_template);
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
|
||||
res = host.info();
|
||||
assertTrue( !res.isError() );
|
||||
assertTrue( host.xpath("TEMPLATE/ATT1").equals( "" ) );
|
||||
assertTrue( host.xpath("TEMPLATE/ATT2").equals( "NEW_VAL" ) );
|
||||
assertTrue( host.xpath("TEMPLATE/ATT3").equals( "VAL3" ) );
|
||||
}
|
||||
|
||||
/*
|
||||
@Test
|
||||
public void attributes()
|
||||
|
@ -43,7 +43,8 @@ public class ImageTest
|
||||
|
||||
return "NAME = \"test_img_" + cont + "\"\n" +
|
||||
"PATH = /etc/hosts\n" +
|
||||
"ATT1 = \"val1\"";
|
||||
"ATT1 = \"VAL1\"\n" +
|
||||
"ATT2 = \"VAL2\"";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -122,34 +123,26 @@ public class ImageTest
|
||||
@Test
|
||||
public void update()
|
||||
{
|
||||
// Update an existing att.
|
||||
res = image.update("ATT1", "new_val_1");
|
||||
res = image.info();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
assertTrue( image.xpath("TEMPLATE/ATT1").equals( "VAL1" ) );
|
||||
assertTrue( image.xpath("TEMPLATE/ATT2").equals( "VAL2" ) );
|
||||
|
||||
String new_template = "ATT2 = NEW_VAL\n" +
|
||||
"ATT3 = VAL3";
|
||||
|
||||
res = image.update(new_template);
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
|
||||
res = image.info();
|
||||
assertTrue( !res.isError() );
|
||||
assertTrue( image.xpath("TEMPLATE/ATT1").equals("new_val_1") );
|
||||
|
||||
// Create a new att.
|
||||
res = image.update("ATT2", "new_val_2");
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
res = image.info();
|
||||
assertTrue( !res.isError() );
|
||||
assertTrue( image.xpath("TEMPLATE/ATT2").equals("new_val_2") );
|
||||
assertTrue( image.xpath("TEMPLATE/ATT1").equals( "" ) );
|
||||
assertTrue( image.xpath("TEMPLATE/ATT2").equals( "NEW_VAL" ) );
|
||||
assertTrue( image.xpath("TEMPLATE/ATT3").equals( "VAL3" ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rmattr()
|
||||
{
|
||||
res = image.rmattr("ATT1");
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
res = image.info();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
assertTrue( image.xpath("ATT1").equals("") );
|
||||
}
|
||||
|
||||
// TODO
|
||||
// @Test
|
||||
@ -203,13 +196,13 @@ public class ImageTest
|
||||
assertTrue( image.xpath("NAME").equals("test_img_"+cont) );
|
||||
}
|
||||
|
||||
// @Test
|
||||
@Test
|
||||
public void delete()
|
||||
{
|
||||
res = image.delete();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
res = image.info();
|
||||
assertTrue( res.isError() );
|
||||
// res = image.info();
|
||||
// assertTrue( res.isError() );
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,9 @@ import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.opennebula.client.Client;
|
||||
import org.opennebula.client.OneResponse;
|
||||
import org.opennebula.client.group.Group;
|
||||
import org.opennebula.client.template.*;
|
||||
import org.opennebula.client.user.User;
|
||||
import org.opennebula.client.vm.VirtualMachine;
|
||||
|
||||
|
||||
@ -41,7 +43,8 @@ public class TemplateTest
|
||||
|
||||
private static String template_str =
|
||||
"NAME = \"" + name + "\"\n" +
|
||||
"ATT1 = \"val1\"";
|
||||
"ATT1 = \"VAL1\"\n" +
|
||||
"ATT2 = \"VAL2\"";
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
@ -119,33 +122,24 @@ public class TemplateTest
|
||||
@Test
|
||||
public void update()
|
||||
{
|
||||
// Update an existing att.
|
||||
res = template.update("ATT1", "new_val_1");
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
res = template.info();
|
||||
assertTrue( !res.isError() );
|
||||
assertTrue( template.xpath("TEMPLATE/ATT1").equals("new_val_1") );
|
||||
|
||||
// Create a new att.
|
||||
res = template.update("ATT2", "new_val_2");
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
res = template.info();
|
||||
assertTrue( !res.isError() );
|
||||
assertTrue( template.xpath("TEMPLATE/ATT2").equals("new_val_2") );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rmattr()
|
||||
{
|
||||
res = template.rmattr("ATT1");
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
res = template.info();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
assertTrue( template.xpath("ATT1").equals("") );
|
||||
assertTrue( template.xpath("TEMPLATE/ATT1").equals( "VAL1" ) );
|
||||
assertTrue( template.xpath("TEMPLATE/ATT2").equals( "VAL2" ) );
|
||||
|
||||
String new_template = "ATT2 = NEW_VAL\n" +
|
||||
"ATT3 = VAL3";
|
||||
|
||||
res = template.update(new_template);
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
|
||||
res = template.info();
|
||||
assertTrue( !res.isError() );
|
||||
assertTrue( template.xpath("TEMPLATE/ATT1").equals( "" ) );
|
||||
assertTrue( template.xpath("TEMPLATE/ATT2").equals( "NEW_VAL" ) );
|
||||
assertTrue( template.xpath("TEMPLATE/ATT3").equals( "VAL3" ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -191,11 +185,64 @@ public class TemplateTest
|
||||
@Test
|
||||
public void allocateFromTemplate()
|
||||
{
|
||||
template.info();
|
||||
res = template.info();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
res = VirtualMachine.allocateFromTemplate(client, template);
|
||||
assertTrue( !res.isError() );
|
||||
assertTrue( res.getMessage().equals("0") );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void chown()
|
||||
{
|
||||
// Create a new User and Group
|
||||
res = User.allocate(client, "template_test_user", "password");
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
int uid = Integer.parseInt(res.getMessage());
|
||||
|
||||
res = Group.allocate(client, "template_test_group");
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
int gid = Integer.parseInt(res.getMessage());
|
||||
|
||||
res = template.info();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
assertTrue( template.uid() == 0 );
|
||||
assertTrue( template.gid() == 0 );
|
||||
|
||||
res = template.chown(uid, gid);
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
res = template.info();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
assertTrue( template.uid() == uid );
|
||||
assertTrue( template.gid() == gid );
|
||||
|
||||
res = template.chgrp(0);
|
||||
|
||||
res = template.info();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
assertTrue( template.uid() == uid );
|
||||
assertTrue( template.gid() == 0 );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void instantiate()
|
||||
{
|
||||
res = template.instantiate("new_vm_name");
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
int vm_id = Integer.parseInt(res.getMessage());
|
||||
VirtualMachine vm = new VirtualMachine(vm_id, client);
|
||||
|
||||
res = vm.info();
|
||||
assertTrue( !res.isError() );
|
||||
|
||||
assertTrue( vm.getName().equals( "new_vm_name" ) );
|
||||
}
|
||||
}
|
||||
|
@ -17,11 +17,11 @@ cp oned.conf $ONEDCONF_LOCATION
|
||||
export ONE_XMLRPC=http://localhost:2666/RPC2
|
||||
|
||||
|
||||
./test.sh ClusterTest
|
||||
./test.sh HostTest
|
||||
./test.sh ImageTest
|
||||
./test.sh SessionTest
|
||||
./test.sh UserTest
|
||||
./test.sh VirtualMachineTest
|
||||
./test.sh VirtualNetworkTest
|
||||
./test.sh TemplateTest
|
||||
./test.sh TemplateTest
|
||||
./test.sh GroupTest
|
@ -35,10 +35,10 @@ require 'OpenNebula/User'
|
||||
require 'OpenNebula/UserPool'
|
||||
require 'OpenNebula/Host'
|
||||
require 'OpenNebula/HostPool'
|
||||
require 'OpenNebula/Cluster'
|
||||
require 'OpenNebula/ClusterPool'
|
||||
require 'OpenNebula/Template'
|
||||
require 'OpenNebula/TemplatePool'
|
||||
require 'OpenNebula/Group'
|
||||
require 'OpenNebula/GroupPool'
|
||||
|
||||
module OpenNebula
|
||||
|
||||
|
@ -17,33 +17,31 @@
|
||||
require 'OpenNebula/Pool'
|
||||
|
||||
module OpenNebula
|
||||
class Cluster < PoolElement
|
||||
class Group < PoolElement
|
||||
# ---------------------------------------------------------------------
|
||||
# Constants and Class Methods
|
||||
# ---------------------------------------------------------------------
|
||||
CLUSTER_METHODS = {
|
||||
:info => "cluster.info",
|
||||
:allocate => "cluster.allocate",
|
||||
:delete => "cluster.delete",
|
||||
:addhost => "cluster.add",
|
||||
:removehost => "cluster.remove",
|
||||
GROUP_METHODS = {
|
||||
:info => "group.info",
|
||||
:allocate => "group.allocate",
|
||||
:delete => "group.delete"
|
||||
}
|
||||
|
||||
# Creates a Cluster description with just its identifier
|
||||
# this method should be used to create plain Cluster objects.
|
||||
# Creates a Group description with just its identifier
|
||||
# this method should be used to create plain Group objects.
|
||||
# +id+ the id of the user
|
||||
#
|
||||
# Example:
|
||||
# cluster = Cluster.new(User.build_xml(3),rpc_client)
|
||||
# group = Group.new(Group.build_xml(3),rpc_client)
|
||||
#
|
||||
def Cluster.build_xml(pe_id=nil)
|
||||
def Group.build_xml(pe_id=nil)
|
||||
if pe_id
|
||||
user_xml = "<CLUSTER><ID>#{pe_id}</ID></CLUSTER>"
|
||||
group_xml = "<GROUP><ID>#{pe_id}</ID></GROUP>"
|
||||
else
|
||||
user_xml = "<CLUSTER></CLUSTER>"
|
||||
group_xml = "<GROUP></GROUP>"
|
||||
end
|
||||
|
||||
XMLElement.build_xml(user_xml,'CLUSTER')
|
||||
XMLElement.build_xml(group_xml,'GROUP')
|
||||
end
|
||||
|
||||
# ---------------------------------------------------------------------
|
||||
@ -56,48 +54,44 @@ module OpenNebula
|
||||
end
|
||||
|
||||
# ---------------------------------------------------------------------
|
||||
# XML-RPC Methods for the User Object
|
||||
# XML-RPC Methods for the Group Object
|
||||
# ---------------------------------------------------------------------
|
||||
|
||||
# Retrieves the information of the given Cluster.
|
||||
|
||||
# Retrieves the information of the given Group.
|
||||
def info()
|
||||
super(CLUSTER_METHODS[:info], 'CLUSTER')
|
||||
super(GROUP_METHODS[:info], 'GROUP')
|
||||
end
|
||||
|
||||
# Allocates a new Cluster in OpenNebula
|
||||
# Allocates a new Group in OpenNebula
|
||||
#
|
||||
# +clustername+ A string containing the name of the Cluster.
|
||||
def allocate(clustername)
|
||||
super(CLUSTER_METHODS[:allocate], clustername)
|
||||
# +groupname+ A string containing the name of the Group.
|
||||
def allocate(groupname)
|
||||
super(GROUP_METHODS[:allocate], groupname)
|
||||
end
|
||||
|
||||
# Deletes the Cluster
|
||||
# Deletes the Group
|
||||
def delete()
|
||||
super(CLUSTER_METHODS[:delete])
|
||||
super(GROUP_METHODS[:delete])
|
||||
end
|
||||
|
||||
# Add a host to the cluster
|
||||
#
|
||||
# +host_id+ ID of the Host to be added to the Cluster
|
||||
def add_host(host_id)
|
||||
return Error.new('ID not defined') if !@pe_id
|
||||
# ---------------------------------------------------------------------
|
||||
# Helpers to get information
|
||||
# ---------------------------------------------------------------------
|
||||
|
||||
rc = @client.call(CLUSTER_METHODS[:addhost], host_id.to_i, @pe_id)
|
||||
rc = nil if !OpenNebula.is_error?(rc)
|
||||
|
||||
return rc
|
||||
# Returns whether or not the user with id 'uid' is part of this group
|
||||
def contains(uid)
|
||||
return self["USERS/ID[.=#{uid}]"] != nil
|
||||
end
|
||||
|
||||
# Remove a host from the cluster
|
||||
#
|
||||
# +host_id+ ID of the Host to be removed from the Cluster
|
||||
def remove_host(host_id)
|
||||
return Error.new('ID not defined') if !@pe_id
|
||||
# Returns an array with the numeric user ids
|
||||
def user_ids
|
||||
array = Array.new
|
||||
|
||||
rc = @client.call(CLUSTER_METHODS[:removehost], host_id.to_i)
|
||||
rc = nil if !OpenNebula.is_error?(rc)
|
||||
self.each("USERS/ID") do |id|
|
||||
array << id.text.to_i
|
||||
end
|
||||
|
||||
return rc
|
||||
return array
|
||||
end
|
||||
end
|
||||
end
|
@ -17,36 +17,36 @@
|
||||
require 'OpenNebula/Pool'
|
||||
|
||||
module OpenNebula
|
||||
class ClusterPool < Pool
|
||||
class GroupPool < Pool
|
||||
# ---------------------------------------------------------------------
|
||||
# Constants and Class attribute accessors
|
||||
# ---------------------------------------------------------------------
|
||||
|
||||
CLUSTER_POOL_METHODS = {
|
||||
:info => "clusterpool.info"
|
||||
GROUP_POOL_METHODS = {
|
||||
:info => "grouppool.info"
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------
|
||||
# Class constructor & Pool Methods
|
||||
# ---------------------------------------------------------------------
|
||||
|
||||
|
||||
# +client+ a Client object that represents a XML-RPC connection
|
||||
def initialize(client)
|
||||
super('CLUSTER_POOL','CLUSTER',client)
|
||||
super('GROUP_POOL','GROUP',client)
|
||||
end
|
||||
|
||||
# Factory method to create User objects
|
||||
def factory(element_xml)
|
||||
OpenNebula::Cluster.new(element_xml,@client)
|
||||
OpenNebula::Group.new(element_xml,@client)
|
||||
end
|
||||
|
||||
# ---------------------------------------------------------------------
|
||||
# XML-RPC Methods for the User Object
|
||||
# ---------------------------------------------------------------------
|
||||
|
||||
# Retrieves all the Clusters in the pool.
|
||||
|
||||
# Retrieves all the Groups in the pool.
|
||||
def info()
|
||||
super(CLUSTER_POOL_METHODS[:info])
|
||||
super(GROUP_POOL_METHODS[:info])
|
||||
end
|
||||
end
|
||||
end
|
@ -25,7 +25,8 @@ module OpenNebula
|
||||
:info => "host.info",
|
||||
:allocate => "host.allocate",
|
||||
:delete => "host.delete",
|
||||
:enable => "host.enable"
|
||||
:enable => "host.enable",
|
||||
:update => "host.update"
|
||||
}
|
||||
|
||||
HOST_STATES=%w{INIT MONITORING MONITORED ERROR DISABLED}
|
||||
@ -102,6 +103,13 @@ module OpenNebula
|
||||
set_enabled(false)
|
||||
end
|
||||
|
||||
# Replaces the template contents
|
||||
#
|
||||
# +new_template+ New template contents
|
||||
def update(new_template)
|
||||
super(HOST_METHODS[:update], new_template)
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
# Helpers to get Host information
|
||||
#######################################################################
|
||||
@ -121,12 +129,6 @@ module OpenNebula
|
||||
SHORT_HOST_STATES[state_str]
|
||||
end
|
||||
|
||||
# Returns the cluster of the Host
|
||||
def cluster
|
||||
self['CLUSTER']
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def set_enabled(enabled)
|
||||
return Error.new('ID not defined') if !@pe_id
|
||||
|
@ -26,11 +26,11 @@ module OpenNebula
|
||||
:info => "image.info",
|
||||
:allocate => "image.allocate",
|
||||
:update => "image.update",
|
||||
:rmattr => "image.rmattr",
|
||||
:enable => "image.enable",
|
||||
:publish => "image.publish",
|
||||
:persistent => "image.persistent",
|
||||
:delete => "image.delete"
|
||||
:delete => "image.delete",
|
||||
:chown => "image.chown"
|
||||
}
|
||||
|
||||
IMAGE_STATES=%w{INIT READY USED DISABLED LOCKED ERROR}
|
||||
@ -92,20 +92,11 @@ module OpenNebula
|
||||
super(IMAGE_METHODS[:allocate],description)
|
||||
end
|
||||
|
||||
# Modifies an image attribute
|
||||
# Replaces the template contents
|
||||
#
|
||||
# +name+ Name of the attribute to be changed
|
||||
#
|
||||
# +value+ New value for the attribute
|
||||
def update(name, value)
|
||||
super(IMAGE_METHODS[:update], name, value)
|
||||
end
|
||||
|
||||
# Deletes an Image attribute
|
||||
#
|
||||
# +name+ Name of the attribute to be deleted
|
||||
def remove_attr(name)
|
||||
do_rm_attr(name)
|
||||
# +new_template+ New template contents
|
||||
def update(new_template)
|
||||
super(IMAGE_METHODS[:update], new_template)
|
||||
end
|
||||
|
||||
# Enables an Image
|
||||
@ -142,7 +133,14 @@ module OpenNebula
|
||||
def delete()
|
||||
super(IMAGE_METHODS[:delete])
|
||||
end
|
||||
|
||||
|
||||
# Changes the owner/group
|
||||
# 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
|
||||
# [return] nil in case of success or an Error object
|
||||
def chown(uid, gid)
|
||||
super(IMAGE_METHODS[:chown], uid, gid)
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
# Helpers to get Image information
|
||||
@ -178,6 +176,12 @@ module OpenNebula
|
||||
SHORT_IMAGE_TYPES[type_str]
|
||||
end
|
||||
|
||||
# Returns the group identifier
|
||||
# [return] _Integer_ the element's group ID
|
||||
def gid
|
||||
self['GID'].to_i
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_enabled(enabled)
|
||||
@ -206,15 +210,5 @@ module OpenNebula
|
||||
|
||||
return rc
|
||||
end
|
||||
|
||||
def do_rm_attr(name)
|
||||
return Error.new('ID not defined') if !@pe_id
|
||||
|
||||
rc = @client.call(IMAGE_METHODS[:rmattr], @pe_id, name)
|
||||
rc = nil if !OpenNebula.is_error?(rc)
|
||||
|
||||
return rc
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -148,13 +148,12 @@ module OpenNebula
|
||||
# Calls to the corresponding update method to modify
|
||||
# the object's template
|
||||
# xml_method:: _String_ the name of the XML-RPC method
|
||||
# name:: _String_ the name of the property to be modified
|
||||
# value:: _String_ the new value of the property to be modified
|
||||
# new_template:: _String_ the new template contents
|
||||
# [return] nil in case of success or an Error object
|
||||
def update(xml_method, name, value)
|
||||
def update(xml_method, new_template)
|
||||
return Error.new('ID not defined') if !@pe_id
|
||||
|
||||
rc = @client.call(xml_method,@pe_id, name, value)
|
||||
rc = @client.call(xml_method,@pe_id, new_template)
|
||||
rc = nil if !OpenNebula.is_error?(rc)
|
||||
|
||||
return rc
|
||||
@ -173,6 +172,21 @@ module OpenNebula
|
||||
return rc
|
||||
end
|
||||
|
||||
# Calls to the corresponding chown method to modify
|
||||
# the object's owner and group
|
||||
# xml_method:: _String_ the name of the XML-RPC method
|
||||
# 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
|
||||
# [return] nil in case of success or an Error object
|
||||
def chown(xml_method, uid, gid)
|
||||
return Error.new('ID not defined') if !@pe_id
|
||||
|
||||
rc = @client.call(xml_method,@pe_id, uid, gid)
|
||||
rc = nil if !OpenNebula.is_error?(rc)
|
||||
|
||||
return rc
|
||||
end
|
||||
|
||||
public
|
||||
|
||||
# Creates new element specifying its id
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user