2008-11-13 19:21:17 +03:00
/* -------------------------------------------------------------------------- */
2012-01-12 15:29:18 +04:00
/* Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) */
2008-11-13 19:21:17 +03: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 RANGED_LEASES_H_
# define RANGED_LEASES_H_
# include "Leases.h"
2011-11-28 20:24:46 +04:00
# include "VirtualNetwork.h"
2008-11-13 19:21:17 +03:00
using namespace std ;
class RangedLeases : public Leases
{
public :
// *************************************************************************
// Constructor
// *************************************************************************
2010-04-11 00:15:47 +04:00
RangedLeases ( SqlDB * db ,
2008-11-13 19:21:17 +03:00
int _oid ,
unsigned int _mac_prefix ,
2011-11-25 22:02:17 +04:00
unsigned int _ip_start ,
unsigned int _ip_end ) ;
2008-11-13 19:21:17 +03:00
~ RangedLeases ( ) { } ;
2011-11-28 20:24:46 +04:00
/**
* Reads ( and clears ) the necessary attributes to define a Ranged VNet
* @ param vn Virtual Network
* @ param ip_start First IP of the range
* @ param ip_end Last IP of the range
* @ param error_str Error reason , if any
* @ return 0 on success , - 1 otherwise
*/
static int process_template ( VirtualNetwork * vn ,
unsigned int & ip_start , unsigned int & ip_end , string & error_str ) ;
2008-11-13 19:21:17 +03:00
/**
* Returns an unused lease , which becomes used
* @ param vid identifier of the VM getting this lease
* @ param ip ip of the returned lease
* @ param mac mac of the returned lease
* @ return 0 if success
*/
int get ( int vid , string & ip , string & mac ) ;
2008-11-15 03:40:27 +03:00
/**
* Ask for a specific lease in the network
* @ param vid identifier of the VM getting this lease
* @ param ip ip of lease requested
* @ param mac mac of the lease
* @ return 0 if success
*/
int set ( int vid , const string & ip , string & mac ) ;
2010-04-11 00:15:47 +04:00
2008-11-13 19:21:17 +03:00
/**
* Release an used lease , which becomes unused
* @ param ip of the lease in use
*/
void release ( const string & ip )
{
2010-04-11 00:15:47 +04:00
del ( ip ) ;
2008-11-13 19:21:17 +03:00
}
2010-04-11 00:15:47 +04:00
2011-02-01 20:26:26 +03:00
/**
* Adds New leases .
* Only available for FIXED networks .
* @ param vector_leases vector of VectorAttribute objects . For the
* moment , the vector can only contain one LEASE .
* @ param error_msg If the action fails , this message contains
* the reason .
* @ return 0 on success
*/
2011-02-02 14:40:08 +03:00
int add_leases ( vector < const Attribute * > & vector_leases , string & error_msg )
2011-02-01 20:26:26 +03:00
{
2011-02-02 14:40:08 +03:00
error_msg = " Adding new leases is only supported for FIXED networks. " ;
2011-02-01 20:26:26 +03:00
return - 1 ;
}
/**
* Removes leases ; if they are not used .
* Only available for FIXED networks .
* @ param vector_leases vector of VectorAttribute objects . For the
* moment , the vector can only contain one LEASE .
* @ param error_msg If the action fails , this message contains
* the reason .
* @ return 0 on success
*/
2011-02-02 14:40:08 +03:00
int remove_leases ( vector < const Attribute * > & vector_leases , string & error_msg )
2011-02-01 20:26:26 +03:00
{
2011-02-02 14:40:08 +03:00
error_msg = " Removing leases is only supported for FIXED networks. " ;
2011-02-01 20:26:26 +03:00
return - 1 ;
}
2008-11-13 19:21:17 +03:00
/**
* Loads the leases from the DB .
*/
2010-04-11 00:15:47 +04:00
int select ( SqlDB * db )
2008-11-13 19:21:17 +03:00
{
2010-04-11 00:15:47 +04:00
//Read the leases from the DB
int rc = Leases : : select ( db ) ;
return rc ;
2008-11-13 19:21:17 +03:00
}
2010-04-11 00:15:47 +04:00
2008-11-13 19:21:17 +03:00
private :
2010-04-11 00:15:47 +04:00
2011-11-25 22:02:17 +04:00
unsigned int ip_start ;
unsigned int ip_end ;
2010-04-11 00:15:47 +04:00
unsigned int current ;
2008-11-13 19:21:17 +03:00
/**
* Add a lease , from the Lease interface
* @ param ip ip of the lease
* @ param mac mac of the lease
* @ param vid identifier of the VM getting this lease
* @ return 0 if success
*/
int add ( unsigned int ip , unsigned int mac [ ] , int vid , bool used = true ) ;
2010-04-11 00:15:47 +04:00
2008-11-13 19:21:17 +03:00
/**
* Remove a lease , from the Lease interface
* @ param db pointer to DB
* @ param ip ip of the lease to be deleted
* @ return 0 if success
*/
int del ( const string & ip ) ;
2010-04-11 00:15:47 +04:00
2008-11-13 19:21:17 +03:00
} ;
2010-09-02 22:26:51 +04:00
# endif /*RANGED_LEASES_H_*/