2008-11-13 16:21:17 +00:00
/* -------------------------------------------------------------------------- */
2010-02-22 18:00:30 +01:00
/* Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) */
2008-11-13 16:21:17 +00:00
/* */
/* 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 VIRTUAL_NETWORK_POOL_H_
# define VIRTUAL_NETWORK_POOL_H_
# include "PoolSQL.h"
# include "VirtualNetwork.h"
# include <time.h>
2010-07-14 18:11:29 +02:00
class AuthRequest ;
2008-11-13 16:21:17 +00:00
using namespace std ;
/**
* The Virtual Network Pool class . . . .
*/
class VirtualNetworkPool : public PoolSQL
{
public :
2010-04-10 22:15:47 +02:00
VirtualNetworkPool ( SqlDB * db ,
const string & str_mac_prefix ,
int default_size ) ;
2008-11-13 16:21:17 +00:00
~ VirtualNetworkPool ( ) { } ;
/**
2010-07-14 19:37:43 +02:00
* Function to allocate a new VNET object
2008-11-13 16:21:17 +00:00
* @ param uid user identifier
2010-07-14 19:37:43 +02:00
* @ param vn_template a VirtualNetworkTemplate describing the VNET
2008-11-13 16:21:17 +00:00
* @ param oid the id assigned to the VM ( output )
2010-07-14 19:37:43 +02:00
* @ return oid on success , - 1 error
2008-11-13 16:21:17 +00:00
*/
int allocate (
int uid ,
2010-07-14 19:37:43 +02:00
VirtualNetworkTemplate * vn_template ,
2010-08-05 19:28:28 +02:00
int * oid ,
string & error_str ) ;
2008-11-13 16:21:17 +00:00
/**
* Function to get a VN from the pool , if the object is not in memory
* it is loaded from the DB
* @ param oid VN unique id
* @ param lock locks the VN mutex
* @ return a pointer to the VN , 0 if the VN could not be loaded
*/
VirtualNetwork * get (
int oid ,
bool lock )
{
return static_cast < VirtualNetwork * > ( PoolSQL : : get ( oid , lock ) ) ;
} ;
2010-04-05 23:34:09 +02:00
2008-11-13 16:21:17 +00:00
/**
* Function to get a VN from the pool using the network name
* If the object is not in memory it is loaded from the DB
* @ param name VN unique name
* @ param lock locks the VN mutex
* @ return a pointer to the VN , 0 if the VN could not be loaded
*/
VirtualNetwork * get (
const string & name ,
2010-04-10 22:15:47 +02:00
bool lock ) ;
2008-11-13 16:21:17 +00:00
//--------------------------------------------------------------------------
// Virtual Network DB access functions
//--------------------------------------------------------------------------
2010-04-05 23:34:09 +02:00
2010-06-25 12:08:05 +02:00
/**
* Generates a NIC attribute for VM templates using the VirtualNetwork
* metadata
* @ param nic the nic attribute to be generated
* @ param vid of the VM requesting the lease
* @ return 0 on success , - 1 error , - 2 not using the pool
*/
2010-07-14 16:21:41 +02:00
int nic_attribute ( VectorAttribute * nic , int vid ) ;
2010-06-25 12:08:05 +02:00
2010-07-14 18:11:29 +02:00
/**
* Generates an Authorization token for a NIC attribute
* @ param nic the nic to be authorized
* @ param ar the AuthRequest
*/
void authorize_nic ( VectorAttribute * nic , AuthRequest * ar ) ;
2008-11-13 16:21:17 +00:00
/**
* Bootstraps the database table ( s ) associated to the VirtualNetwork pool
*/
2010-04-10 22:15:47 +02:00
static void bootstrap ( SqlDB * _db )
2008-11-13 16:21:17 +00:00
{
2009-07-09 14:34:34 +00:00
VirtualNetwork : : bootstrap ( _db ) ;
2008-11-13 16:21:17 +00:00
} ;
2010-04-05 23:34:09 +02:00
2008-11-13 16:21:17 +00:00
/**
2010-04-10 22:15:47 +02:00
* Dumps the Virtual Network pool in XML format . A filter can be also added
* to the query
2009-07-09 14:34:34 +00:00
* @ param oss the output stream to dump the pool contents
* @ param where filter for the objects , defaults to all
*
* @ return 0 on success
2008-11-13 16:21:17 +00:00
*/
2010-04-10 22:15:47 +02:00
int dump ( ostringstream & oss , const string & where ) ;
2009-07-09 14:34:34 +00:00
2010-07-01 19:04:52 +02:00
/**
* Get the mac prefix
* @ return the mac prefix
*/
static const unsigned int & mac_prefix ( )
{
return _mac_prefix ;
} ;
/**
* Get the default network size
* @ return the size
*/
static const unsigned int & default_size ( )
{
return _default_size ;
} ;
2009-07-09 14:34:34 +00:00
private :
2008-11-13 16:21:17 +00:00
/**
* Holds the system - wide MAC prefix
*/
2010-07-01 19:04:52 +02:00
static unsigned int _mac_prefix ;
2010-04-05 23:34:09 +02:00
2008-11-13 16:21:17 +00:00
/**
* Default size for Virtual Networks
*/
2010-07-01 19:04:52 +02:00
static unsigned int _default_size ;
2010-04-05 23:34:09 +02:00
2009-07-09 14:34:34 +00:00
/**
* Factory method to produce VN objects
* @ return a pointer to the new VN
*/
PoolObjectSQL * create ( )
{
2010-07-01 19:04:52 +02:00
return new VirtualNetwork ( ) ;
2009-07-09 14:34:34 +00:00
} ;
2010-04-05 23:34:09 +02:00
2010-04-10 22:15:47 +02:00
/**
* Callback function to get output the virtual network pool in XML format
* ( VirtualNetworkPool : : dump )
* @ param num the number of columns read from the DB
* @ param names the column names
* @ param vaues the column values
* @ return 0 on success
*/
int dump_cb ( void * _oss , int num , char * * values , char * * names ) ;
/**
* Callback function to get the ID of a given virtual network
* ( VirtualNetworkPool : : get )
* @ param num the number of columns read from the DB
* @ param names the column names
* @ param vaues the column values
* @ return 0 on success
*/
int get_cb ( void * _oss , int num , char * * values , char * * names ) ;
2008-11-13 16:21:17 +00:00
} ;
2010-04-05 23:34:09 +02:00
2010-06-07 17:51:46 +02:00
# endif /*VIRTUAL_NETWORK_POOL_H_*/