mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-03 01:17:41 +03:00
feature #2980: VNC port tracking. Includes a VNC bitmap for each cluster to
track the ports in use in the cluster and avoid port collision. VNC ports are assigned when the VM is deployed and released when the VM is stopped, undeployed or done. Includes the following: - 9da66150dc0e3dc2731518d8a215f9598696a999 - 4c35a9fcccf70cbe87d2947403ea815967e7b605 - ccfccb6d2fc40aa1c07eb994f37b8da4fb479082 - b1b64e61a39f4452c7ba00e581de42888e0e84a5 - d474ee4db9ed520bcae743d510be35b25ea988ed - dacb61b1402da2ec309b6e79bdd285d0d11de84f
This commit is contained in:
parent
f12b01f7e5
commit
784a4fc960
356
include/BitMap.h
Normal file
356
include/BitMap.h
Normal file
@ -0,0 +1,356 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2015, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef BITMAP_H_
|
||||
#define BITMAP_H_
|
||||
|
||||
#include <bitset>
|
||||
|
||||
#include "Attribute.h"
|
||||
#include "Callbackable.h"
|
||||
|
||||
class SqlDB;
|
||||
|
||||
/**
|
||||
* This class represents a generic BitMap
|
||||
*
|
||||
*/
|
||||
template <unsigned int N>
|
||||
class BitMap : public Callbackable
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Creates a new bitmap, it stores a pointer to the DB parameters
|
||||
* that MUST exists during the object lifetime.
|
||||
*/
|
||||
BitMap(const VectorAttribute& bs_conf, int _id, const char * _db_table)
|
||||
: id(_id), start_bit(0), bs(0), db_table(_db_table)
|
||||
{
|
||||
std::string reserved;
|
||||
|
||||
bs_conf.vector_value("START", start_bit);
|
||||
bs_conf.vector_value("RESERVED", reserved);
|
||||
|
||||
if (!reserved.empty())
|
||||
{
|
||||
one_util::split_unique(reserved, ',', reserved_bit);
|
||||
}
|
||||
};
|
||||
|
||||
virtual ~BitMap()
|
||||
{
|
||||
delete bs;
|
||||
};
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Database interface */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/**
|
||||
* Returns a string stream with the SQL bootstrap command for the
|
||||
* bitmap table
|
||||
*/
|
||||
static std::ostringstream& bootstrap(const char * t, std::ostringstream& o)
|
||||
{
|
||||
o << "CREATE TABLE IF NOT EXISTS " << t
|
||||
<< " (id INTEGER, map LONGTEXT, PRIMARY KEY(id))";
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a new bitmap into the bitmap table. The bitmap marks the
|
||||
* associated reserved bits as initialized by the bitmap conf. This
|
||||
* function is called once to bootstrap the bitmap contents.
|
||||
* @param id of the set, this will update the id of the bitmap
|
||||
* @return 0 on success
|
||||
*/
|
||||
int insert(int _id, SqlDB * db)
|
||||
{
|
||||
id = _id;
|
||||
|
||||
init("");
|
||||
|
||||
return insert_replace(db, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a bitmap and marks (again) the reserved bits. This function
|
||||
* is called once to load the bitmap from the DB. The reserved bits are
|
||||
* updated.
|
||||
* @param id of the set, this will update the id of the bitmap
|
||||
* @return 0 on success
|
||||
*/
|
||||
int select(int _id, SqlDB * db)
|
||||
{
|
||||
std::string * uzbs;
|
||||
|
||||
id = _id;
|
||||
|
||||
if ( select(db, &uzbs) != 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
init(*uzbs);
|
||||
|
||||
delete uzbs;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int update(SqlDB * db)
|
||||
{
|
||||
return insert_replace(db, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a bitmap from the DB.
|
||||
* @return 0 on success
|
||||
*/
|
||||
int drop(SqlDB * db)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "DELETE FROM " << db_table << " WHERE id = " << id ;
|
||||
|
||||
return db->exec(oss);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* BitMap interface */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/*+
|
||||
* Gets the first 0 bit in the map and set it.
|
||||
* @param hint try this bit first, 0 does not use any hint
|
||||
* @param bit the bit number reserved
|
||||
* @return -1 in case of error
|
||||
*/
|
||||
int get(unsigned int hint, unsigned int& bit)
|
||||
{
|
||||
if ( hint != 0 )
|
||||
{
|
||||
if ( bs->test(hint) == false )
|
||||
{
|
||||
bs->set(hint);
|
||||
|
||||
bit = hint;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (bit = start_bit; ; ++bit)
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( bs->test(bit) == false )
|
||||
{
|
||||
bs->set(bit);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
catch (const std::out_of_range& oor)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears a bit in the map and updates DB.
|
||||
* @param bit to reset
|
||||
*/
|
||||
void reset(int bit)
|
||||
{
|
||||
try
|
||||
{
|
||||
bs->reset(bit);
|
||||
}
|
||||
catch(const std::out_of_range& oor){};
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a bit in the map and updates DB.
|
||||
* @param bit to set
|
||||
* @return 0 on success, -1 if bit was set
|
||||
*/
|
||||
int set(int bit)
|
||||
{
|
||||
int rc = -1;
|
||||
|
||||
try
|
||||
{
|
||||
if (bs->test(bit) == false)
|
||||
{
|
||||
bs->set(bit);
|
||||
|
||||
rc = 0;
|
||||
}
|
||||
}
|
||||
catch(const std::out_of_range& oor){};
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the start_bit of the bitmap
|
||||
*/
|
||||
unsigned int get_start_bit()
|
||||
{
|
||||
return start_bit;
|
||||
}
|
||||
|
||||
private:
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Bitmap configuration attributes */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int id;
|
||||
|
||||
unsigned int start_bit;
|
||||
|
||||
std::set<int> reserved_bit;
|
||||
|
||||
std::bitset<N> * bs;
|
||||
|
||||
/**
|
||||
* Initialized a bitmap by creating a new object and setting the reserved
|
||||
* bits.
|
||||
* @param bm_s the bitmap in string form
|
||||
*/
|
||||
void init(const std::string& bm_s)
|
||||
{
|
||||
std::set<int>::iterator it;
|
||||
|
||||
bs = new std::bitset<N>(bm_s);
|
||||
|
||||
for (it = reserved_bit.begin(); it != reserved_bit.end(); ++it)
|
||||
{
|
||||
try
|
||||
{
|
||||
bs->set(*it);
|
||||
}
|
||||
catch (const std::out_of_range& oor) {};
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Database implementation */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
const char * db_table;
|
||||
|
||||
/**
|
||||
* Select callback from DB engine
|
||||
*/
|
||||
int select_cb(void * _bs, int num, char **values, char **names)
|
||||
{
|
||||
if ( num == 0 || values == 0 || values[0] == 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
*static_cast<std::string*>(_bs) = (const char *) values[0];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a the contents of a bitmap from DB
|
||||
* @param **uzbs, pointer to a string pointer to store the bitmap, must
|
||||
* be freed by caller.
|
||||
* @return 0 on success
|
||||
*/
|
||||
int select(SqlDB * db, std::string ** uzbs)
|
||||
{
|
||||
int rc;
|
||||
|
||||
std::ostringstream oss;
|
||||
|
||||
std::string zbs;
|
||||
|
||||
*uzbs = 0;
|
||||
|
||||
set_callback(static_cast<Callbackable::Callback>(&BitMap::select_cb),
|
||||
static_cast<void *>(&zbs));
|
||||
|
||||
oss << "SELECT map FROM " << db_table << " WHERE id = " << id ;
|
||||
|
||||
rc = db->exec(oss, this);
|
||||
|
||||
unset_callback();
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
return rc;
|
||||
}
|
||||
else if (zbs.empty())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
*uzbs = one_util::zlib_decompress(zbs, true);
|
||||
|
||||
if ( *uzbs == 0 )
|
||||
{
|
||||
rc = -1;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Insert a Bitmap in the DB, the bitmap is stored in a compressed (zlib)
|
||||
* string form.
|
||||
* @param replace true to replace false to insert
|
||||
* @return 0 on success
|
||||
*/
|
||||
int insert_replace(SqlDB * db, bool replace)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
|
||||
if (replace)
|
||||
{
|
||||
oss << "REPLACE ";
|
||||
}
|
||||
else
|
||||
{
|
||||
oss << "INSERT ";
|
||||
}
|
||||
|
||||
std::string * zipped = one_util::zlib_compress(bs->to_string(), true);
|
||||
|
||||
if (zipped == 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
char * ezipped64 = db->escape_str(zipped->c_str());
|
||||
|
||||
oss << "INTO " << db_table << " (id, map) VALUES ("
|
||||
<< id << ",'" << ezipped64 << "')";
|
||||
|
||||
int rc = db->exec(oss);
|
||||
|
||||
delete zipped;
|
||||
|
||||
db->free_str(ezipped64);
|
||||
|
||||
return rc;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /*BITMAP_H_*/
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "ObjectCollection.h"
|
||||
#include "DatastorePool.h"
|
||||
#include "ClusterTemplate.h"
|
||||
#include "BitMap.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -173,6 +174,36 @@ public:
|
||||
get_template_attribute("RESERVED_MEM", mem);
|
||||
}
|
||||
|
||||
// *************************************************************************
|
||||
// VNC Port management function
|
||||
// *************************************************************************
|
||||
|
||||
/**
|
||||
* Returns a free VNC port, it will try first to allocate base_port + vmid.
|
||||
* If this port is not free the first lower port from the VNC_PORT/START
|
||||
* port is returned.
|
||||
* @param vmid of the VM
|
||||
* @param port reserved
|
||||
* @return 0 on success
|
||||
*/
|
||||
int get_vnc_port(int vmid, unsigned int& port)
|
||||
{
|
||||
unsigned int base_port = vnc_bitmap.get_start_bit();
|
||||
unsigned int hint_port = base_port + (vmid % (65535 - base_port));
|
||||
|
||||
return vnc_bitmap.get(hint_port,port);
|
||||
}
|
||||
|
||||
void release_vnc_port(int port)
|
||||
{
|
||||
vnc_bitmap.reset(port);
|
||||
}
|
||||
|
||||
int set_vnc_port(int port)
|
||||
{
|
||||
return vnc_bitmap.set(port);
|
||||
}
|
||||
|
||||
// *************************************************************************
|
||||
// DataBase implementation (Public)
|
||||
// *************************************************************************
|
||||
@ -203,9 +234,8 @@ private:
|
||||
// *************************************************************************
|
||||
// Constructor
|
||||
// *************************************************************************
|
||||
Cluster(int id,
|
||||
const string& name,
|
||||
ClusterTemplate* cl_template);
|
||||
Cluster(int id, const string& name, ClusterTemplate* cl_template,
|
||||
const VectorAttribute& vnc_conf);
|
||||
|
||||
virtual ~Cluster(){};
|
||||
|
||||
@ -216,6 +246,8 @@ private:
|
||||
ObjectCollection datastores;
|
||||
ObjectCollection vnets;
|
||||
|
||||
BitMap<65536> vnc_bitmap;
|
||||
|
||||
// *************************************************************************
|
||||
// DataBase implementation (Private)
|
||||
// *************************************************************************
|
||||
@ -231,6 +263,7 @@ private:
|
||||
static const char * network_db_names;
|
||||
static const char * network_db_bootstrap;
|
||||
|
||||
static const char * bitmap_table;
|
||||
/**
|
||||
* Execute an INSERT or REPLACE Sql query.
|
||||
* @param db The SQL DB
|
||||
@ -268,7 +301,16 @@ private:
|
||||
*/
|
||||
int insert(SqlDB *db, string& error_str)
|
||||
{
|
||||
return insert_replace(db, false, error_str);
|
||||
int rc;
|
||||
|
||||
rc = insert_replace(db, false, error_str);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
return rc;
|
||||
}
|
||||
|
||||
return vnc_bitmap.insert(oid, db);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -279,7 +321,46 @@ private:
|
||||
int update(SqlDB *db)
|
||||
{
|
||||
string error_str;
|
||||
return insert_replace(db, true, error_str);
|
||||
|
||||
int rc = insert_replace(db, true, error_str);
|
||||
|
||||
rc += vnc_bitmap.update(db);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the PoolObjectSQL (identified by its OID) from the database.
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
int select(SqlDB *db)
|
||||
{
|
||||
int rc = PoolObjectSQL::select(db);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
return rc;
|
||||
}
|
||||
|
||||
return vnc_bitmap.select(oid, db);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the PoolObjectSQL (identified by its OID) from the database.
|
||||
* @param db pointer to the db
|
||||
* @return 0 on success
|
||||
*/
|
||||
int select(SqlDB *db, const string& _name, int _uid)
|
||||
{
|
||||
int rc = PoolObjectSQL::select(db, _name, _uid);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
return rc;
|
||||
}
|
||||
|
||||
return vnc_bitmap.select(oid, db);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,7 +26,7 @@ using namespace std;
|
||||
class ClusterPool : public PoolSQL
|
||||
{
|
||||
public:
|
||||
ClusterPool(SqlDB * db);
|
||||
ClusterPool(SqlDB * db, const VectorAttribute * vnc_conf);
|
||||
|
||||
~ClusterPool(){};
|
||||
|
||||
@ -54,6 +54,77 @@ public:
|
||||
*/
|
||||
static const int DEFAULT_CLUSTER_ID;
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Cluster Resources */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/**
|
||||
* Get a free VNC port in the cluster. It will try first base_port + id
|
||||
* @param oid of the cluster
|
||||
* @param vm_id of the ID requesting the port
|
||||
* @param port to free
|
||||
*/
|
||||
int get_vnc_port(int oid, int vm_id, unsigned int& port)
|
||||
{
|
||||
int rc = -1;
|
||||
|
||||
Cluster * cluster = get(oid, true);
|
||||
|
||||
if ( cluster != 0 )
|
||||
{
|
||||
rc = cluster->get_vnc_port(vm_id, port);
|
||||
|
||||
update(cluster);
|
||||
|
||||
cluster->unlock();
|
||||
}
|
||||
|
||||
return rc;
|
||||
};
|
||||
|
||||
/**
|
||||
* Release a previously allocated VNC port in the cluster
|
||||
* @param oid of the cluster
|
||||
* @param port to free
|
||||
*/
|
||||
void release_vnc_port(int oid, unsigned int port)
|
||||
{
|
||||
Cluster * cluster = get(oid, true);
|
||||
|
||||
if ( cluster != 0 )
|
||||
{
|
||||
cluster->release_vnc_port(port);
|
||||
|
||||
update(cluster);
|
||||
|
||||
cluster->unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark a VNC port as in-use in the cluster.
|
||||
* @param oid of the cluster
|
||||
* @param port to set
|
||||
*
|
||||
* @return 0 on success, -1 if the port was in-use.
|
||||
*/
|
||||
int set_vnc_port(int oid, unsigned int port)
|
||||
{
|
||||
int rc = -1;
|
||||
|
||||
Cluster * cluster = get(oid, true);
|
||||
|
||||
if ( cluster != 0 )
|
||||
{
|
||||
rc = cluster->set_vnc_port(port);
|
||||
|
||||
update(cluster);
|
||||
|
||||
cluster->unlock();
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Methods for DB management */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@ -67,9 +138,7 @@ public:
|
||||
*
|
||||
* @return the oid assigned to the object, -1 in case of failure
|
||||
*/
|
||||
int allocate(string name,
|
||||
int * oid,
|
||||
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
|
||||
@ -128,7 +197,13 @@ public:
|
||||
*/
|
||||
static int bootstrap(SqlDB * _db)
|
||||
{
|
||||
return Cluster::bootstrap(_db);
|
||||
ostringstream oss_bitmap;
|
||||
int rc;
|
||||
|
||||
rc = Cluster::bootstrap(_db);
|
||||
rc += _db->exec(BitMap<0>::bootstrap(Cluster::bitmap_table, oss_bitmap));
|
||||
|
||||
return rc;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -156,13 +231,18 @@ public:
|
||||
static void cluster_acl_filter(ostringstream& filter,
|
||||
PoolObjectSQL::ObjectType auth_object, const vector<int>& cids);
|
||||
private:
|
||||
/**
|
||||
* VNC configuration for clusters
|
||||
*/
|
||||
const VectorAttribute vnc_conf;
|
||||
|
||||
/**
|
||||
* Factory method to produce objects
|
||||
* @return a pointer to the new object
|
||||
*/
|
||||
PoolObjectSQL * create()
|
||||
{
|
||||
return new Cluster(-1,"",0);
|
||||
return new Cluster(-1,"",0, &vnc_conf);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "HostPool.h"
|
||||
#include "ImagePool.h"
|
||||
#include "SecurityGroupPool.h"
|
||||
#include "ClusterPool.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -42,7 +43,8 @@ class LifeCycleManager : public ActionListener
|
||||
public:
|
||||
|
||||
LifeCycleManager():
|
||||
vmpool(0), hpool(0), ipool(0), sgpool(0), tm(0), vmm(0), dm(0), imagem(0)
|
||||
vmpool(0), hpool(0), ipool(0), sgpool(0), clpool(0), tm(0), vmm(0),
|
||||
dm(0), imagem(0)
|
||||
{
|
||||
am.addListener(this);
|
||||
};
|
||||
@ -178,6 +180,11 @@ private:
|
||||
*/
|
||||
SecurityGroupPool * sgpool;
|
||||
|
||||
/**
|
||||
* Pointer to the Cluster Pool
|
||||
*/
|
||||
ClusterPool * clpool;
|
||||
|
||||
/**
|
||||
* Pointer to TransferManager
|
||||
*/
|
||||
|
@ -238,6 +238,24 @@ namespace one_util
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compress the input string unsing zlib
|
||||
* @param in input string
|
||||
* @param bool64 true to base64 encode output
|
||||
* @return pointer to the compressed sting (must be freed) or 0 in case
|
||||
* of error
|
||||
*/
|
||||
std::string * zlib_compress(const std::string& in, bool base64);
|
||||
|
||||
/**
|
||||
* Decompress the input string unsing zlib
|
||||
* @param in input string
|
||||
* @param base64 true if the input is base64 encoded
|
||||
* @return pointer to the decompressed sting (must be freed) or 0 in case
|
||||
* of error
|
||||
*/
|
||||
std::string * zlib_decompress(const std::string& in, bool base64);
|
||||
};
|
||||
|
||||
#endif /* _NEBULA_UTIL_H_ */
|
||||
|
@ -1439,22 +1439,6 @@ public:
|
||||
*/
|
||||
static void disk_extended_info(int uid,
|
||||
VirtualMachineTemplate *tmpl);
|
||||
/**
|
||||
* Adds extra info to the volatile disks of the given template, ds inherited
|
||||
* attributes and TYPE
|
||||
* @param tmpl the virtual machine template
|
||||
* @return true if there at least one volatile disk was found
|
||||
*/
|
||||
bool volatile_disk_extended_info(Template *tmpl);
|
||||
|
||||
/**
|
||||
* Adds extra info to the volatile disks of the given VM
|
||||
*/
|
||||
bool volatile_disk_extended_info()
|
||||
{
|
||||
return volatile_disk_extended_info(obj_template);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Hotplug related functions
|
||||
// -------------------------------------------------------------------------
|
||||
@ -1465,14 +1449,6 @@ public:
|
||||
*/
|
||||
void get_disk_info(int& max_disk_id, set<string>& used_targets);
|
||||
|
||||
/**
|
||||
* Get the IMAGE_ID of the image that's being saved as hot
|
||||
* @param disk_id of the DISK
|
||||
* @param image_id id of the image being saved
|
||||
* @return IMAGE_ID on success, -1 otherwise
|
||||
*/
|
||||
//int get_disk_hot_info(int& image_id, int& disk_id, string& source);
|
||||
|
||||
/**
|
||||
* Generate a DISK attribute to be attached to the VM.
|
||||
* @param tmpl Template containing a single DISK vector attribute.
|
||||
|
@ -24,7 +24,6 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
/**
|
||||
* The Virtual Machine Pool class. ...
|
||||
*/
|
||||
@ -393,19 +392,19 @@ private:
|
||||
/**
|
||||
* Size, in seconds, of the historical monitoring information
|
||||
*/
|
||||
static time_t _monitor_expiration;
|
||||
time_t _monitor_expiration;
|
||||
|
||||
/**
|
||||
* True or false whether to submit new VM on HOLD or not
|
||||
*/
|
||||
static bool _submit_on_hold;
|
||||
bool _submit_on_hold;
|
||||
|
||||
/**
|
||||
* Default values for cpu and memory cost
|
||||
*/
|
||||
static float _default_cpu_cost;
|
||||
static float _default_mem_cost;
|
||||
static float _default_disk_cost;
|
||||
float _default_cpu_cost;
|
||||
float _default_mem_cost;
|
||||
float _default_disk_cost;
|
||||
|
||||
/**
|
||||
* Callback used to get an int in the DB it is used by VM Pool in:
|
||||
|
@ -34,8 +34,9 @@
|
||||
# passwd : (mysql) the password for user
|
||||
# db_name : (mysql) the database name
|
||||
#
|
||||
# VNC_BASE_PORT: VNC ports for VMs can be automatically set to VNC_BASE_PORT +
|
||||
# VMID
|
||||
# VNC_PORTS: VNC port pool fot automatic VNC port assigment
|
||||
# start : first port to assgin
|
||||
# reserved: comma separated list of ports
|
||||
#
|
||||
# LOG: Configuration for the logging system
|
||||
# system: defines the logging system:
|
||||
@ -77,7 +78,10 @@ DB = [ backend = "sqlite" ]
|
||||
# passwd = "oneadmin",
|
||||
# db_name = "opennebula" ]
|
||||
|
||||
VNC_BASE_PORT = 5900
|
||||
VNC_PORTS = [
|
||||
start = 5900
|
||||
# reserved = "6800, 6801, 9869"
|
||||
]
|
||||
|
||||
#VM_SUBMIT_ON_HOLD = "NO"
|
||||
|
||||
@ -88,19 +92,19 @@ VNC_BASE_PORT = 5900
|
||||
# requires a special DB configuration.
|
||||
#
|
||||
# FEDERATION: Federation attributes
|
||||
# MODE: Operation mode of this oned.
|
||||
# mode: Operation mode of this oned.
|
||||
# STANDALONE no federated.This is the default operational mode
|
||||
# MASTER this oned is the master zone of the federation
|
||||
# SLAVE this oned is a slave zone
|
||||
# ZONE_ID: The zone ID as returned by onezone command
|
||||
# MASTER_ONED: The xml-rpc endpoint of the master oned, e.g.
|
||||
# zone_id: The zone ID as returned by onezone command
|
||||
# master_oned: The xml-rpc endpoint of the master oned, e.g.
|
||||
# http://master.one.org:2633/RPC2
|
||||
#*******************************************************************************
|
||||
|
||||
FEDERATION = [
|
||||
MODE = "STANDALONE",
|
||||
ZONE_ID = 0,
|
||||
MASTER_ONED = ""
|
||||
mode = "STANDALONE",
|
||||
zone_id = 0,
|
||||
master_oned = ""
|
||||
]
|
||||
|
||||
#*******************************************************************************
|
||||
|
@ -39,8 +39,9 @@
|
||||
# passwd : (mysql) the password for user
|
||||
# db_name : (mysql) the database name
|
||||
#
|
||||
# VNC_BASE_PORT: VNC ports for VMs can be automatically set to VNC_BASE_PORT +
|
||||
# VMID
|
||||
# VNC_PORTS: VNC port pool fot automatic VNC port assigment
|
||||
# start : first port to assgin
|
||||
# reserved: comma separated list of ports
|
||||
#
|
||||
# LOG: Configuration for the logging system
|
||||
# system: defines the logging system:
|
||||
@ -86,7 +87,10 @@ DB = [ backend = "sqlite" ]
|
||||
# passwd = "oneadmin",
|
||||
# db_name = "opennebula" ]
|
||||
|
||||
VNC_BASE_PORT = 5900
|
||||
VNC_PORTS = [
|
||||
start = 5900
|
||||
# reserved = "6800, 6801, 9869"
|
||||
]
|
||||
|
||||
#VM_SUBMIT_ON_HOLD = "NO"
|
||||
|
||||
@ -107,9 +111,9 @@ VNC_BASE_PORT = 5900
|
||||
#*******************************************************************************
|
||||
|
||||
FEDERATION = [
|
||||
MODE = "STANDALONE",
|
||||
ZONE_ID = 0,
|
||||
MASTER_ONED = ""
|
||||
mode = "STANDALONE",
|
||||
zone_id = 0,
|
||||
master_oned = ""
|
||||
]
|
||||
|
||||
#*******************************************************************************
|
||||
|
@ -46,6 +46,8 @@ const char * Cluster::network_db_bootstrap =
|
||||
"CREATE TABLE IF NOT EXISTS cluster_network_relation ("
|
||||
"cid INTEGER, oid INTEGER, PRIMARY KEY(cid, oid))";
|
||||
|
||||
const char * Cluster::bitmap_table = "vm_bitmap";
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Cluster :: Constructor/Destructor */
|
||||
/* ************************************************************************** */
|
||||
@ -53,11 +55,13 @@ const char * Cluster::network_db_bootstrap =
|
||||
Cluster::Cluster(
|
||||
int id,
|
||||
const string& name,
|
||||
ClusterTemplate* cl_template):
|
||||
ClusterTemplate* cl_template,
|
||||
const VectorAttribute& vnc_conf):
|
||||
PoolObjectSQL(id,CLUSTER,name,-1,-1,"","",table),
|
||||
hosts("HOSTS"),
|
||||
datastores("DATASTORES"),
|
||||
vnets("VNETS")
|
||||
vnets("VNETS"),
|
||||
vnc_bitmap(vnc_conf, id, bitmap_table)
|
||||
{
|
||||
if (cl_template != 0)
|
||||
{
|
||||
@ -68,11 +72,8 @@ Cluster::Cluster(
|
||||
obj_template = new ClusterTemplate;
|
||||
}
|
||||
|
||||
string default_cpu; //TODO - Get these two from oned.conf
|
||||
string default_mem;
|
||||
|
||||
add_template_attribute("RESERVED_CPU", default_cpu);
|
||||
add_template_attribute("RESERVED_MEM", default_cpu);
|
||||
add_template_attribute("RESERVED_CPU", "");
|
||||
add_template_attribute("RESERVED_MEM", "");
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -225,7 +226,6 @@ int Cluster::insert_replace(SqlDB *db, bool replace, string& error_str)
|
||||
}
|
||||
|
||||
// Construct the SQL statement to Insert or Replace
|
||||
|
||||
oss <<" INTO "<<table <<" ("<< db_names <<") VALUES ("
|
||||
<< oid << ","
|
||||
<< "'" << sql_name << "',"
|
||||
@ -302,9 +302,9 @@ int Cluster::insert_replace(SqlDB *db, bool replace, string& error_str)
|
||||
{
|
||||
oss.str("");
|
||||
|
||||
oss << "BEGIN; "
|
||||
<< "DELETE FROM " << network_table << " WHERE cid = " << oid << "; "
|
||||
<< "DELETE FROM " << datastore_table<< " WHERE cid = " << oid << "; ";
|
||||
oss <<"BEGIN; "
|
||||
<<"DELETE FROM "<< network_table <<" WHERE cid = "<< oid<< "; "
|
||||
<<"DELETE FROM "<< datastore_table<<" WHERE cid = "<< oid<< "; ";
|
||||
|
||||
set<int>::iterator i;
|
||||
|
||||
|
@ -35,7 +35,8 @@ const int ClusterPool::DEFAULT_CLUSTER_ID = 0;
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
ClusterPool::ClusterPool(SqlDB * db):PoolSQL(db, Cluster::table, true, true)
|
||||
ClusterPool::ClusterPool(SqlDB * db, const VectorAttribute * _vnc_conf):
|
||||
PoolSQL(db, Cluster::table, true, true), vnc_conf(_vnc_conf)
|
||||
{
|
||||
ostringstream oss;
|
||||
string error_str;
|
||||
@ -109,7 +110,7 @@ int ClusterPool::allocate(string name, int * oid, string& error_str)
|
||||
}
|
||||
|
||||
// Build a new Cluster object
|
||||
cluster = new Cluster(-1, name, 0);
|
||||
cluster = new Cluster(-1, name, 0, vnc_conf);
|
||||
|
||||
// Insert the Object in the pool
|
||||
*oid = PoolSQL::allocate(cluster, error_str);
|
||||
|
@ -23,6 +23,8 @@
|
||||
#include <openssl/buffer.h>
|
||||
#include <openssl/aes.h>
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
@ -333,3 +335,148 @@ std::string one_util::gsub(const std::string& st, const std::string& sfind,
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Buffer length for zlib inflate/deflate
|
||||
*/
|
||||
#define ZBUFFER 16384
|
||||
|
||||
std::string * one_util::zlib_compress(const std::string& in, bool base64)
|
||||
{
|
||||
z_stream zs;
|
||||
|
||||
std::ostringstream oss;
|
||||
unsigned char out[ZBUFFER];
|
||||
|
||||
std::string * zstr;
|
||||
|
||||
if ( in.empty() )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
zs.zalloc = Z_NULL;
|
||||
zs.zfree = Z_NULL;
|
||||
zs.opaque = Z_NULL;
|
||||
|
||||
if ( deflateInit(&zs, Z_DEFAULT_COMPRESSION) != Z_OK )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
zs.avail_in = in.size();
|
||||
zs.next_in = (unsigned char *) const_cast<char *>(in.c_str());
|
||||
|
||||
do
|
||||
{
|
||||
zs.avail_out = ZBUFFER;
|
||||
zs.next_out = out;
|
||||
|
||||
if ( deflate(&zs, Z_FINISH) == Z_STREAM_ERROR )
|
||||
{
|
||||
deflateEnd(&zs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
oss.write((const char *)out, ZBUFFER - zs.avail_out);
|
||||
} while (zs.avail_out == 0);
|
||||
|
||||
deflateEnd(&zs);
|
||||
|
||||
if ( base64 )
|
||||
{
|
||||
zstr = one_util::base64_encode(oss.str());
|
||||
}
|
||||
else
|
||||
{
|
||||
zstr = new std::string(oss.str());
|
||||
}
|
||||
|
||||
return zstr;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
std::string * one_util::zlib_decompress(const std::string& in, bool base64)
|
||||
{
|
||||
int rc;
|
||||
|
||||
z_stream zs;
|
||||
|
||||
std::ostringstream oss;
|
||||
unsigned char out[ZBUFFER];
|
||||
|
||||
std::string * in64;
|
||||
|
||||
if ( in.empty() )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
zs.zalloc = Z_NULL;
|
||||
zs.zfree = Z_NULL;
|
||||
zs.opaque = Z_NULL;
|
||||
|
||||
zs.avail_in = 0;
|
||||
zs.next_in = Z_NULL;
|
||||
|
||||
if ( inflateInit(&zs) != Z_OK)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( base64 )
|
||||
{
|
||||
in64 = one_util::base64_decode(in);
|
||||
|
||||
if (in64 == 0)
|
||||
{
|
||||
inflateEnd(&zs);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
zs.avail_in = in64->size();
|
||||
zs.next_in = (unsigned char *) const_cast<char *>(in64->c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
zs.avail_in = in.size();
|
||||
zs.next_in = (unsigned char *) const_cast<char *>(in.c_str());
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
zs.avail_out = ZBUFFER;
|
||||
zs.next_out = out;
|
||||
|
||||
if ( (rc = inflate(&zs, Z_FINISH)) == Z_STREAM_ERROR )
|
||||
{
|
||||
inflateEnd(&zs);
|
||||
|
||||
if ( base64 )
|
||||
{
|
||||
delete in64;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
oss.write((const char *)out, ZBUFFER - zs.avail_out);
|
||||
} while (rc != Z_STREAM_END);
|
||||
|
||||
inflateEnd(&zs);
|
||||
|
||||
if ( base64 )
|
||||
{
|
||||
delete in64;
|
||||
}
|
||||
|
||||
return new std::string(oss.str());
|
||||
}
|
||||
|
||||
|
||||
|
@ -835,6 +835,8 @@ void LifeCycleManager::clean_action(int vid)
|
||||
void LifeCycleManager::clean_up_vm(VirtualMachine * vm, bool dispose, int& image_id)
|
||||
{
|
||||
int cpu, mem, disk;
|
||||
unsigned int port;
|
||||
|
||||
vector<VectorAttribute *> pci;
|
||||
time_t the_time = time(0);
|
||||
|
||||
@ -865,8 +867,16 @@ void LifeCycleManager::clean_up_vm(VirtualMachine * vm, bool dispose, int& imag
|
||||
vm->set_reason(History::USER);
|
||||
|
||||
vm->get_requirements(cpu, mem, disk, pci);
|
||||
|
||||
hpool->del_capacity(vm->get_hid(), vm->get_oid(), cpu, mem, disk, pci);
|
||||
|
||||
const VectorAttribute * graphics = vm->get_template_attribute("GRAPHICS");
|
||||
|
||||
if ( graphics != 0 && (graphics->vector_value("PORT", port) == 0))
|
||||
{
|
||||
clpool->release_vnc_port(vm->get_cid(), port);
|
||||
}
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case VirtualMachine::PROLOG:
|
||||
|
@ -74,6 +74,7 @@ void LifeCycleManager::init_managers()
|
||||
hpool = nd.get_hpool();
|
||||
ipool = nd.get_ipool();
|
||||
sgpool = nd.get_secgrouppool();
|
||||
clpool = nd.get_clpool();
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -811,6 +811,7 @@ void LifeCycleManager::epilog_success_action(int vid)
|
||||
|
||||
time_t the_time = time(0);
|
||||
int cpu,mem,disk;
|
||||
unsigned int port;
|
||||
|
||||
VirtualMachine::LcmState state;
|
||||
DispatchManager::Actions action;
|
||||
@ -883,6 +884,13 @@ void LifeCycleManager::epilog_success_action(int vid)
|
||||
|
||||
hpool->del_capacity(vm->get_hid(), vm->get_oid(), cpu, mem, disk, pci);
|
||||
|
||||
const VectorAttribute * graphics = vm->get_template_attribute("GRAPHICS");
|
||||
|
||||
if ( graphics != 0 && (graphics->vector_value("PORT", port) == 0))
|
||||
{
|
||||
clpool->release_vnc_port(vm->get_cid(), port);
|
||||
}
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
dm->trigger(action,vid);
|
||||
|
@ -436,170 +436,160 @@ void Nebula::start(bool bootstrap_only)
|
||||
throw runtime_error("Could not start the ACL Manager");
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// -------------------------------------------------------------------------
|
||||
// Pools
|
||||
// -----------------------------------------------------------
|
||||
// -------------------------------------------------------------------------
|
||||
try
|
||||
{
|
||||
int size;
|
||||
/* -------------------------- Cluster Pool -------------------------- */
|
||||
const VectorAttribute * vnc_conf;
|
||||
|
||||
string mac_prefix;
|
||||
string default_image_type;
|
||||
string default_device_prefix;
|
||||
string default_cdrom_device_prefix;
|
||||
vnc_conf = nebula_configuration->get("VNC_PORTS");
|
||||
|
||||
clpool = new ClusterPool(db, vnc_conf);
|
||||
|
||||
/* --------------------- VirtualMachine Pool ------------------------ */
|
||||
vector<const VectorAttribute *> vm_hooks;
|
||||
vector<const SingleAttribute *> vm_restricted_attrs;
|
||||
|
||||
time_t expiration_time;
|
||||
time_t vm_expiration;
|
||||
time_t host_expiration;
|
||||
|
||||
bool vm_submit_on_hold;
|
||||
|
||||
float cpu_cost;
|
||||
float mem_cost;
|
||||
float disk_cost;
|
||||
|
||||
vector<const VectorAttribute *> vm_hooks;
|
||||
vector<const VectorAttribute *> host_hooks;
|
||||
vector<const VectorAttribute *> vrouter_hooks;
|
||||
vector<const VectorAttribute *> vnet_hooks;
|
||||
vector<const VectorAttribute *> user_hooks;
|
||||
vector<const VectorAttribute *> group_hooks;
|
||||
vector<const VectorAttribute *> image_hooks;
|
||||
|
||||
vector<const SingleAttribute *> vm_restricted_attrs;
|
||||
vector<const SingleAttribute *> img_restricted_attrs;
|
||||
vector<const SingleAttribute *> vnet_restricted_attrs;
|
||||
|
||||
vector<const SingleAttribute *> inherit_image_attrs;
|
||||
vector<const SingleAttribute *> inherit_datastore_attrs;
|
||||
vector<const SingleAttribute *> inherit_vnet_attrs;
|
||||
|
||||
vector<const VectorAttribute *> default_cost;
|
||||
|
||||
clpool = new ClusterPool(db);
|
||||
docpool = new DocumentPool(db);
|
||||
zonepool= new ZonePool(db, is_federation_slave());
|
||||
vdcpool = new VdcPool(db, is_federation_slave());
|
||||
const VectorAttribute * default_cost;
|
||||
|
||||
nebula_configuration->get("VM_HOOK", vm_hooks);
|
||||
nebula_configuration->get("HOST_HOOK", host_hooks);
|
||||
nebula_configuration->get("VROUTER_HOOK", vrouter_hooks);
|
||||
nebula_configuration->get("VNET_HOOK", vnet_hooks);
|
||||
nebula_configuration->get("USER_HOOK", user_hooks);
|
||||
nebula_configuration->get("GROUP_HOOK", group_hooks);
|
||||
nebula_configuration->get("IMAGE_HOOK", image_hooks);
|
||||
|
||||
nebula_configuration->get("VM_RESTRICTED_ATTR", vm_restricted_attrs);
|
||||
nebula_configuration->get("IMAGE_RESTRICTED_ATTR", img_restricted_attrs);
|
||||
nebula_configuration->get("VNET_RESTRICTED_ATTR", vnet_restricted_attrs);
|
||||
|
||||
nebula_configuration->get("INHERIT_IMAGE_ATTR", inherit_image_attrs);
|
||||
nebula_configuration->get("INHERIT_DATASTORE_ATTR", inherit_datastore_attrs);
|
||||
nebula_configuration->get("INHERIT_VNET_ATTR", inherit_vnet_attrs);
|
||||
|
||||
nebula_configuration->get("VM_MONITORING_EXPIRATION_TIME",vm_expiration);
|
||||
nebula_configuration->get("HOST_MONITORING_EXPIRATION_TIME",host_expiration);
|
||||
|
||||
nebula_configuration->get("VM_SUBMIT_ON_HOLD",vm_submit_on_hold);
|
||||
|
||||
rc = nebula_configuration->get("DEFAULT_COST", default_cost);
|
||||
default_cost = nebula_configuration->get("DEFAULT_COST");
|
||||
|
||||
cpu_cost = 0;
|
||||
mem_cost = 0;
|
||||
disk_cost= 0;
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
const VectorAttribute * vatt = static_cast<const VectorAttribute *>
|
||||
(default_cost[0]);
|
||||
|
||||
rc = vatt->vector_value("CPU_COST", cpu_cost);
|
||||
|
||||
if (rc != 0)
|
||||
if (default_cost->vector_value("CPU_COST", cpu_cost) != 0)
|
||||
{
|
||||
cpu_cost = 0;
|
||||
}
|
||||
|
||||
rc = vatt->vector_value("MEMORY_COST", mem_cost);
|
||||
|
||||
if (rc != 0)
|
||||
if (default_cost->vector_value("MEMORY_COST", mem_cost) != 0)
|
||||
{
|
||||
mem_cost = 0;
|
||||
}
|
||||
|
||||
|
||||
rc = vatt->vector_value("DISK_COST", disk_cost);
|
||||
|
||||
if (rc != 0)
|
||||
if (default_cost->vector_value("DISK_COST", disk_cost) != 0)
|
||||
{
|
||||
disk_cost = 0;
|
||||
}
|
||||
}
|
||||
|
||||
vmpool = new VirtualMachinePool(db,
|
||||
vm_hooks,
|
||||
hook_location,
|
||||
remotes_location,
|
||||
vm_restricted_attrs,
|
||||
vm_expiration,
|
||||
vm_submit_on_hold,
|
||||
cpu_cost,
|
||||
mem_cost,
|
||||
disk_cost);
|
||||
vmpool = new VirtualMachinePool(db, vm_hooks, hook_location,
|
||||
remotes_location, vm_restricted_attrs, vm_expiration,
|
||||
vm_submit_on_hold, cpu_cost, mem_cost, disk_cost);
|
||||
|
||||
hpool = new HostPool(db,
|
||||
host_hooks,
|
||||
hook_location,
|
||||
remotes_location,
|
||||
/* ---------------------------- Host Pool --------------------------- */
|
||||
vector<const VectorAttribute *> host_hooks;
|
||||
|
||||
time_t host_expiration;
|
||||
|
||||
nebula_configuration->get("HOST_HOOK", host_hooks);
|
||||
|
||||
nebula_configuration->get("HOST_MONITORING_EXPIRATION_TIME", host_expiration);
|
||||
|
||||
hpool = new HostPool(db, host_hooks, hook_location, remotes_location,
|
||||
host_expiration);
|
||||
|
||||
vrouterpool = new VirtualRouterPool(db,
|
||||
vrouter_hooks,
|
||||
remotes_location);
|
||||
/* --------------------- VirtualRouter Pool ------------------------- */
|
||||
vector<const VectorAttribute *> vrouter_hooks;
|
||||
|
||||
nebula_configuration->get("VROUTER_HOOK", vrouter_hooks);
|
||||
|
||||
vrouterpool = new VirtualRouterPool(db, vrouter_hooks, remotes_location);
|
||||
|
||||
/* -------------------- VirtualNetwork Pool ------------------------- */
|
||||
int size;
|
||||
string mac_prefix;
|
||||
|
||||
vector<const SingleAttribute *> inherit_vnet_attrs;
|
||||
vector<const SingleAttribute *> vnet_restricted_attrs;
|
||||
vector<const VectorAttribute *> vnet_hooks;
|
||||
|
||||
nebula_configuration->get("MAC_PREFIX", mac_prefix);
|
||||
|
||||
nebula_configuration->get("NETWORK_SIZE", size);
|
||||
|
||||
vnpool = new VirtualNetworkPool(db,
|
||||
mac_prefix,
|
||||
size,
|
||||
vnet_restricted_attrs,
|
||||
vnet_hooks,
|
||||
remotes_location,
|
||||
inherit_vnet_attrs);
|
||||
nebula_configuration->get("VNET_RESTRICTED_ATTR", vnet_restricted_attrs);
|
||||
|
||||
gpool = new GroupPool(db, group_hooks,
|
||||
remotes_location, is_federation_slave());
|
||||
nebula_configuration->get("VNET_HOOK", vnet_hooks);
|
||||
|
||||
nebula_configuration->get("INHERIT_VNET_ATTR", inherit_vnet_attrs);
|
||||
|
||||
vnpool = new VirtualNetworkPool(db, mac_prefix, size, vnet_restricted_attrs,
|
||||
vnet_hooks, remotes_location, inherit_vnet_attrs);
|
||||
|
||||
/* ----------------------- Group/User Pool -------------------------- */
|
||||
vector<const VectorAttribute *> user_hooks;
|
||||
vector<const VectorAttribute *> group_hooks;
|
||||
|
||||
time_t expiration_time;
|
||||
|
||||
nebula_configuration->get("GROUP_HOOK", group_hooks);
|
||||
|
||||
gpool = new GroupPool(db, group_hooks, remotes_location,
|
||||
is_federation_slave());
|
||||
|
||||
nebula_configuration->get("SESSION_EXPIRATION_TIME", expiration_time);
|
||||
|
||||
upool = new UserPool(db, expiration_time, user_hooks,
|
||||
remotes_location, is_federation_slave());
|
||||
nebula_configuration->get("USER_HOOK", user_hooks);
|
||||
|
||||
nebula_configuration->get("DEFAULT_IMAGE_TYPE", default_image_type);
|
||||
nebula_configuration->get("DEFAULT_DEVICE_PREFIX",
|
||||
default_device_prefix);
|
||||
nebula_configuration->get("DEFAULT_CDROM_DEVICE_PREFIX",
|
||||
default_cdrom_device_prefix);
|
||||
ipool = new ImagePool(db,
|
||||
default_image_type,
|
||||
default_device_prefix,
|
||||
default_cdrom_device_prefix,
|
||||
img_restricted_attrs,
|
||||
image_hooks,
|
||||
remotes_location,
|
||||
upool = new UserPool(db, expiration_time, user_hooks, remotes_location,
|
||||
is_federation_slave());
|
||||
|
||||
/* -------------------- Image/Datastore Pool ------------------------ */
|
||||
string image_type;
|
||||
string device_prefix;
|
||||
string cd_dev_prefix;
|
||||
|
||||
vector<const VectorAttribute *> image_hooks;
|
||||
vector<const SingleAttribute *> img_restricted_attrs;
|
||||
vector<const SingleAttribute *> inherit_image_attrs;
|
||||
vector<const SingleAttribute *> inherit_ds_attrs;
|
||||
|
||||
nebula_configuration->get("DEFAULT_IMAGE_TYPE", image_type);
|
||||
nebula_configuration->get("DEFAULT_DEVICE_PREFIX", device_prefix);
|
||||
nebula_configuration->get("DEFAULT_CDROM_DEVICE_PREFIX", cd_dev_prefix);
|
||||
|
||||
nebula_configuration->get("IMAGE_HOOK", image_hooks);
|
||||
|
||||
nebula_configuration->get("IMAGE_RESTRICTED_ATTR", img_restricted_attrs);
|
||||
|
||||
nebula_configuration->get("INHERIT_IMAGE_ATTR", inherit_image_attrs);
|
||||
|
||||
ipool = new ImagePool(db, image_type, device_prefix, cd_dev_prefix,
|
||||
img_restricted_attrs, image_hooks, remotes_location,
|
||||
inherit_image_attrs);
|
||||
|
||||
nebula_configuration->get("INHERIT_DATASTORE_ATTR", inherit_ds_attrs);
|
||||
|
||||
dspool = new DatastorePool(db, inherit_ds_attrs);
|
||||
|
||||
/* ----- Document, Zone, VDC, VMTemplate, SG and Makerket Pools ----- */
|
||||
docpool = new DocumentPool(db);
|
||||
zonepool = new ZonePool(db, is_federation_slave());
|
||||
vdcpool = new VdcPool(db, is_federation_slave());
|
||||
|
||||
tpool = new VMTemplatePool(db);
|
||||
|
||||
dspool = new DatastorePool(db, inherit_datastore_attrs);
|
||||
|
||||
default_user_quota.select();
|
||||
default_group_quota.select();
|
||||
|
||||
secgrouppool = new SecurityGroupPool(db);
|
||||
|
||||
marketpool = new MarketPlacePool(db, is_federation_slave());
|
||||
apppool = new MarketPlaceAppPool(db, is_federation_slave());
|
||||
|
||||
default_user_quota.select();
|
||||
default_group_quota.select();
|
||||
}
|
||||
catch (exception&)
|
||||
{
|
||||
|
@ -310,9 +310,9 @@ void OpenNebulaTemplate::set_conf_default()
|
||||
# LISTEN_ADDRESS
|
||||
# PORT
|
||||
# DB
|
||||
# VNC_BASE_PORT
|
||||
# SCRIPTS_REMOTE_DIR
|
||||
# VM_SUBMIT_ON_HOLD
|
||||
# VNC_PORTS
|
||||
#*******************************************************************************
|
||||
*/
|
||||
set_conf_single("MANAGER_TIMER", "15");
|
||||
@ -325,7 +325,6 @@ void OpenNebulaTemplate::set_conf_default()
|
||||
set_conf_single("VM_MONITORING_EXPIRATION_TIME", "14400");
|
||||
set_conf_single("PORT", "2633");
|
||||
set_conf_single("LISTEN_ADDRESS", "0.0.0.0");
|
||||
set_conf_single("VNC_BASE_PORT", "5900");
|
||||
set_conf_single("SCRIPTS_REMOTE_DIR", "/var/tmp/one");
|
||||
set_conf_single("VM_SUBMIT_ON_HOLD", "NO");
|
||||
|
||||
@ -342,6 +341,15 @@ void OpenNebulaTemplate::set_conf_default()
|
||||
|
||||
vattribute = new VectorAttribute("LOG",vvalue);
|
||||
conf_default.insert(make_pair(vattribute->name(),vattribute));
|
||||
|
||||
// LOG CONFIGURATION
|
||||
vvalue.clear();
|
||||
vvalue.insert(make_pair("RESERVED",""));
|
||||
vvalue.insert(make_pair("START","5900"));
|
||||
|
||||
vattribute = new VectorAttribute("VNC_PORTS",vvalue);
|
||||
conf_default.insert(make_pair(vattribute->name(),vattribute));
|
||||
|
||||
/*
|
||||
#*******************************************************************************
|
||||
# Federation configuration attributes
|
||||
|
@ -446,15 +446,13 @@ int RequestManagerVirtualMachine::add_history(VirtualMachine * vm,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
string vmdir;
|
||||
int rc;
|
||||
|
||||
VirtualMachinePool * vmpool = static_cast<VirtualMachinePool *>(pool);
|
||||
|
||||
vm->add_history(hid, cid, hostname, vmm_mad, vnm_mad, tm_mad, ds_location, ds_id);
|
||||
vm->add_history(hid, cid, hostname, vmm_mad, vnm_mad, tm_mad, ds_location,
|
||||
ds_id);
|
||||
|
||||
rc = vmpool->update_history(vm);
|
||||
|
||||
if ( rc != 0 )
|
||||
if ( vmpool->update_history(vm) != 0 )
|
||||
{
|
||||
att.resp_msg = "Cannot update virtual machine history";
|
||||
failure_response(INTERNAL, att);
|
||||
@ -462,7 +460,13 @@ int RequestManagerVirtualMachine::add_history(VirtualMachine * vm,
|
||||
return -1;
|
||||
}
|
||||
|
||||
vmpool->update(vm);
|
||||
if ( vmpool->update(vm) != 0 )
|
||||
{
|
||||
att.resp_msg = "Cannot update virtual machine";
|
||||
failure_response(INTERNAL, att);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -650,6 +654,127 @@ void VirtualMachineAction::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Adds extra info to the volatile disks of the given template, ds inherited
|
||||
* attributes and TYPE
|
||||
* @param ds_id datastore id
|
||||
* @param vd vector of DISKS
|
||||
* @return true if there at least one volatile disk was found
|
||||
*/
|
||||
static bool set_volatile_disk_info(int ds_id, vector<VectorAttribute *>& vd)
|
||||
{
|
||||
DatastorePool * ds_pool = Nebula::instance().get_dspool();
|
||||
|
||||
bool found = false;
|
||||
|
||||
for(vector<VectorAttribute *>::iterator it = vd.begin(); it!=vd.end(); ++it)
|
||||
{
|
||||
if ( !VirtualMachine::is_volatile(*it) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ds_pool->disk_attribute(ds_id, *it);
|
||||
|
||||
found = true;
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
static bool set_volatile_disk_info(VirtualMachine *vm)
|
||||
{
|
||||
if ( !vm->hasHistory() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
vector<VectorAttribute *> disks;
|
||||
|
||||
int ds_id = vm->get_ds_id();
|
||||
|
||||
vm->get_template_attribute("DISK", disks);
|
||||
|
||||
bool found = set_volatile_disk_info(ds_id, disks);
|
||||
|
||||
if ( found )
|
||||
{
|
||||
Nebula::instance().get_vmpool()->update(vm);
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
|
||||
static bool set_volatile_disk_info(VirtualMachine *vm, Template& tmpl)
|
||||
{
|
||||
if ( !vm->hasHistory() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
vector<VectorAttribute *> disks;
|
||||
|
||||
int ds_id = vm->get_ds_id();
|
||||
|
||||
tmpl.get("DISK", disks);
|
||||
|
||||
bool found = set_volatile_disk_info(ds_id, disks);
|
||||
|
||||
if ( found )
|
||||
{
|
||||
Nebula::instance().get_vmpool()->update(vm);
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int set_vnc_port(VirtualMachine *vm, RequestAttributes& att)
|
||||
{
|
||||
ClusterPool * cpool = Nebula::instance().get_clpool();
|
||||
|
||||
VectorAttribute * graphics = vm->get_template_attribute("GRAPHICS");
|
||||
|
||||
unsigned int port;
|
||||
int rc;
|
||||
|
||||
if (graphics == 0 || !vm->hasHistory())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if (graphics->vector_value("PORT", port) == 0)
|
||||
{
|
||||
rc = cpool->set_vnc_port(vm->get_cid(), port);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
att.resp_msg = "Requested VNC port already assgined to a VM";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = cpool->get_vnc_port(vm->get_cid(), vm->get_oid(), port);
|
||||
|
||||
if ( rc == 0 )
|
||||
{
|
||||
graphics->replace("PORT", port);
|
||||
|
||||
Nebula::instance().get_vmpool()->update(vm);
|
||||
}
|
||||
else
|
||||
{
|
||||
att.resp_msg = "No free VNC ports available in the cluster";
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
@ -743,7 +868,7 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
set<int> ds_cluster_ids;
|
||||
bool ds_migr;
|
||||
|
||||
if (get_ds_information(ds_id, ds_cluster_ids, tm_mad, att, ds_migr) != 0)
|
||||
if (get_ds_information(ds_id,ds_cluster_ids,tm_mad,att,ds_migr) != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -752,10 +877,11 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
oss << object_name(PoolObjectSQL::DATASTORE) << " [" << ds_id << "] and "
|
||||
<< object_name(PoolObjectSQL::HOST) << " [" << hid
|
||||
<< "] are not in the same "
|
||||
<< object_name(PoolObjectSQL::CLUSTER) << " [" << cluster_id << "].";
|
||||
oss << object_name(PoolObjectSQL::DATASTORE) << " [" << ds_id
|
||||
<< "] and " << object_name(PoolObjectSQL::HOST) << " ["
|
||||
<< hid << "] are not in the same "
|
||||
<< object_name(PoolObjectSQL::CLUSTER) << " [" << cluster_id
|
||||
<< "].";
|
||||
|
||||
att.resp_msg = oss.str();
|
||||
|
||||
@ -806,7 +932,6 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
// - VM States are right
|
||||
// - Host capacity if required
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ((vm = get_vm(id, att)) == 0)
|
||||
{
|
||||
return;
|
||||
@ -817,7 +942,9 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
vm->get_state() != VirtualMachine::STOPPED &&
|
||||
vm->get_state() != VirtualMachine::UNDEPLOYED)
|
||||
{
|
||||
att.resp_msg = "Deploy action is not available for state " + vm->state_str();
|
||||
att.resp_msg = "Deploy action is not available for state " +
|
||||
vm->state_str();
|
||||
|
||||
failure_response(ACTION, att);
|
||||
|
||||
vm->unlock();
|
||||
@ -833,9 +960,8 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Add a new history record and update volatile DISK info
|
||||
// Add a new history record
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if (add_history(vm,
|
||||
hid,
|
||||
cluster_id,
|
||||
@ -851,7 +977,19 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
return;
|
||||
}
|
||||
|
||||
vm->volatile_disk_extended_info();
|
||||
// ------------------------------------------------------------------------
|
||||
// Add deployment dependent attributes to VM
|
||||
// - volatile disk (selected system DS driver)
|
||||
// - vnc port (free in the selected cluster)
|
||||
// ------------------------------------------------------------------------
|
||||
set_volatile_disk_info(vm);
|
||||
|
||||
if (set_vnc_port(vm, att) != 0)
|
||||
{
|
||||
failure_response(ACTION, att);
|
||||
vm->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// deploy the VM
|
||||
@ -1178,7 +1316,7 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList
|
||||
return;
|
||||
}
|
||||
|
||||
vm->volatile_disk_extended_info();
|
||||
set_volatile_disk_info(vm);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Migrate the VM
|
||||
@ -1570,9 +1708,10 @@ void VirtualMachineAttach::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
|
||||
vm->get_permissions(vm_perms);
|
||||
|
||||
volatile_disk = vm->volatile_disk_extended_info(&tmpl);
|
||||
volatile_disk = set_volatile_disk_info(vm, tmpl);
|
||||
|
||||
if (vm->is_vrouter() && !VirtualRouter::is_action_supported(History::DISK_ATTACH_ACTION))
|
||||
if (vm->is_vrouter() &&
|
||||
!VirtualRouter::is_action_supported(History::DISK_ATTACH_ACTION))
|
||||
{
|
||||
att.resp_msg = "Action is not supported for virtual router VMs";
|
||||
failure_response(ACTION, att);
|
||||
|
@ -1133,59 +1133,31 @@ int VirtualMachine::parse_pci(string& error_str)
|
||||
|
||||
int VirtualMachine::parse_graphics(string& error_str)
|
||||
{
|
||||
vector<Attribute *> array_graphics;
|
||||
VectorAttribute * graphics;
|
||||
VectorAttribute * user_graphics = user_obj_template->get("GRAPHICS");
|
||||
|
||||
vector<Attribute *>::iterator it;
|
||||
|
||||
int num = user_obj_template->remove("GRAPHICS", array_graphics);
|
||||
|
||||
for (it=array_graphics.begin(); it != array_graphics.end(); it++)
|
||||
{
|
||||
obj_template->set(*it);
|
||||
}
|
||||
|
||||
if ( num == 0 )
|
||||
if ( user_graphics == 0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
graphics = dynamic_cast<VectorAttribute * >(array_graphics[0]);
|
||||
VectorAttribute * graphics = new VectorAttribute(user_graphics);
|
||||
|
||||
if ( graphics == 0 )
|
||||
user_obj_template->erase("GRAPHICS");
|
||||
|
||||
obj_template->set(graphics);
|
||||
|
||||
if ( !graphics->vector_value("PORT").empty() )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
unsigned int port;
|
||||
|
||||
string port = graphics->vector_value("PORT");
|
||||
int port_i;
|
||||
int rc = graphics->vector_value("PORT", port);
|
||||
|
||||
int rc = graphics->vector_value("PORT", port_i);
|
||||
|
||||
if ( port.empty() )
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
|
||||
ostringstream oss;
|
||||
istringstream iss;
|
||||
|
||||
int base_port;
|
||||
string base_port_s;
|
||||
|
||||
int limit = 65535;
|
||||
|
||||
nd.get_configuration_attribute("VNC_BASE_PORT",base_port_s);
|
||||
iss.str(base_port_s);
|
||||
iss >> base_port;
|
||||
|
||||
oss << ( base_port + ( oid % (limit - base_port) ));
|
||||
graphics->replace("PORT", oss.str());
|
||||
}
|
||||
else if ( rc == -1 || port_i < 0 )
|
||||
if (rc == -1 || port > 65535 )
|
||||
{
|
||||
error_str = "Wrong PORT number in GRAPHICS attribute";
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
string random_passwd = graphics->vector_value("RANDOM_PASSWD");
|
||||
|
||||
@ -3588,36 +3560,6 @@ void VirtualMachine::disk_extended_info(int uid,
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
bool VirtualMachine::volatile_disk_extended_info(Template *tmpl)
|
||||
{
|
||||
int num;
|
||||
vector<VectorAttribute * > disks;
|
||||
DatastorePool * ds_pool = Nebula::instance().get_dspool();
|
||||
|
||||
bool found = false;
|
||||
|
||||
num = tmpl->get("DISK", disks);
|
||||
|
||||
for(int i=0; i<num; i++)
|
||||
{
|
||||
if ( !is_volatile(disks[i]) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
found = true;
|
||||
|
||||
if (hasHistory())
|
||||
{
|
||||
ds_pool->disk_attribute(get_ds_id(), disks[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -25,13 +25,6 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
time_t VirtualMachinePool::_monitor_expiration;
|
||||
bool VirtualMachinePool::_submit_on_hold;
|
||||
float VirtualMachinePool::_default_cpu_cost;
|
||||
float VirtualMachinePool::_default_mem_cost;
|
||||
float VirtualMachinePool::_default_disk_cost;
|
||||
|
||||
|
||||
const char * VirtualMachinePool::import_table = "vm_import";
|
||||
|
||||
const char * VirtualMachinePool::import_db_names = "deploy_id, vmid";
|
||||
@ -40,7 +33,6 @@ const char * VirtualMachinePool::import_db_bootstrap =
|
||||
"CREATE TABLE IF NOT EXISTS vm_import "
|
||||
"(deploy_id VARCHAR(128), vmid INTEGER, PRIMARY KEY(deploy_id))";
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
@ -55,7 +47,10 @@ VirtualMachinePool::VirtualMachinePool(
|
||||
float default_cpu_cost,
|
||||
float default_mem_cost,
|
||||
float default_disk_cost)
|
||||
: PoolSQL(db, VirtualMachine::table, true, false)
|
||||
: PoolSQL(db, VirtualMachine::table, true, false),
|
||||
_monitor_expiration(expire_time), _submit_on_hold(on_hold),
|
||||
_default_cpu_cost(default_cpu_cost), _default_mem_cost(default_mem_cost),
|
||||
_default_disk_cost(default_disk_cost)
|
||||
{
|
||||
|
||||
string name;
|
||||
@ -64,12 +59,6 @@ VirtualMachinePool::VirtualMachinePool(
|
||||
string arg;
|
||||
bool remote;
|
||||
|
||||
_monitor_expiration = expire_time;
|
||||
_submit_on_hold = on_hold;
|
||||
_default_cpu_cost = default_cpu_cost;
|
||||
_default_mem_cost = default_mem_cost;
|
||||
_default_disk_cost= default_disk_cost;
|
||||
|
||||
if ( _monitor_expiration == 0 )
|
||||
{
|
||||
clean_all_monitoring();
|
||||
|
Loading…
Reference in New Issue
Block a user