1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-22 13:33:52 +03:00

Feature #474: First commit for add/remove leases feature

This commit is contained in:
Carlos Martín 2011-02-01 18:26:26 +01:00
parent 281c5cc927
commit c5734c93c0
14 changed files with 819 additions and 31 deletions

View File

@ -74,9 +74,33 @@ public:
*/
void release(const string& ip)
{
del(ip);
unset(ip);
}
/**
* 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
*/
int add_leases(vector<const Attribute*>& vector_leases,
char ** error_msg);
/**
* 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
*/
int remove_leases(vector<const Attribute*>& vector_leases,
char ** error_msg);
/**
* Loads the leases from the DB.
*/
@ -107,17 +131,31 @@ private:
* @param ip ip of the lease
* @param mac mac of the lease
* @param vid identifier of the VM getting this lease
* @param error_msg If the action fails, this message contains the reason.
* @param used Flag to insert the lease as used.
* @param check If set to true, the IP will be checked for duplicates.
* @return 0 if success
*/
int add(const string& ip, const string& mac, int vid, bool used=true);
int add(const string& ip,
const string& mac,
int vid,
char ** error_msg,
bool used=true,
bool check=false);
/**
* Remove a lease, from the Lease interface
* @param db pointer to DB
* Remove an existing lease, if it is not in use.
* @param ip ip of the lease
* @param error_msg If the action fails, this message contains the reason
*/
int remove(const string& ip, char ** error_msg);
/**
* Sets a lease as not used, from the Lease interface
* @param ip ip of the lease to be deleted
* @return 0 if success
*/
int del(const string& ip);
int unset(const string& ip);
};
#endif /*FIXED_LEASES_H_*/

View File

@ -78,6 +78,30 @@ public:
*/
virtual void release(const string& ip) = 0;
/**
* 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
*/
virtual int add_leases(vector<const Attribute*>& vector_leases,
char ** error_msg) = 0;
/**
* 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
*/
virtual int remove_leases(vector<const Attribute*>& vector_leases,
char ** error_msg) = 0;
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------

View File

@ -19,6 +19,8 @@
#include "Leases.h"
#include <string.h>
using namespace std;
class RangedLeases : public Leases
@ -63,6 +65,40 @@ public:
del(ip);
}
/**
* 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
*/
int add_leases(vector<const Attribute*>& vector_leases,
char ** error_msg)
{
*error_msg = strdup(
"Adding new leases is only supported for FIXED networks.");
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
*/
int remove_leases(vector<const Attribute*>& vector_leases,
char ** error_msg)
{
*error_msg = strdup(
"Removing leases is only supported for FIXED networks.");
return -1;
}
/**
* Loads the leases from the DB.
*/

View File

@ -915,6 +915,57 @@ private:
UserPool * upool;
};
/* ---------------------------------------------------------------------- */
class VirtualNetworkAddLeases: public xmlrpc_c::method
{
public:
VirtualNetworkAddLeases(
VirtualNetworkPool * _vnpool,
UserPool * _upool):
vnpool(_vnpool),
upool(_upool)
{
_signature="A:sis";
_help="Adds leases to a virtual network";
};
~VirtualNetworkAddLeases(){};
void execute(
xmlrpc_c::paramList const& paramList,
xmlrpc_c::value * const retvalP);
private:
VirtualNetworkPool * vnpool;
UserPool * upool;
};
/* ---------------------------------------------------------------------- */
class VirtualNetworkRemoveLeases: public xmlrpc_c::method
{
public:
VirtualNetworkRemoveLeases(
VirtualNetworkPool * _vnpool,
UserPool * _upool):
vnpool(_vnpool),
upool(_upool)
{
_signature="A:sis";
_help="Removes leases from a virtual network";
};
~VirtualNetworkRemoveLeases(){};
void execute(
xmlrpc_c::paramList const& paramList,
xmlrpc_c::value * const retvalP);
private:
VirtualNetworkPool * vnpool;
UserPool * upool;
};
/* ---------------------------------------------------------------------- */
/* User Management Interface */
/* ---------------------------------------------------------------------- */

View File

@ -29,7 +29,7 @@
using namespace std;
/**
* Base class for file templates. A template is a file (or a tring for the
* Base class for file templates. A template is a file (or a string for the
* matter of fact) containing a set of attribute definitions of the form:
* NAME = VALUE
* where NAME is a string representing the name of the attribute, and VALUE can

View File

@ -102,6 +102,29 @@ public:
}
}
/**
* Adds Leases to the virtual network.
* Only available for FIXED networks.
* @param leases_template template in the form LEASES = [IP=XX, MAC=XX].
* MAC is optional. For the moment, the template can only contain one
* LEASE definition.
* @param error_msg If the action fails, this message contains
* the reason.
* @return 0 on success
*/
int add_leases(VirtualNetworkTemplate * leases_template, char **error_msg);
/**
* Removes Leases from the virtual network; if they are not used.
* Only available for FIXED networks.
* @param leases_template template in the form LEASES = [IP=XX].
* For the moment, the template can only contain one LEASE definition.
* @param error_msg If the action fails, this message contains
* the reason.
* @return 0 on success
*/
int remove_leases(VirtualNetworkTemplate* leases_template,char **error_msg);
/**
* Gets a new lease for a specific VM
* @param vid VM identifier

View File

@ -163,7 +163,13 @@ Commands:
* delete (Removes a virtual network)
onevnet delete <network_id>
* addleases (Adds a lease to the virtual network)
onevnet addleases <network_id> <IP> [<MAC>]
* rmleases (Removes a lease fom the virtual network)
onevnet rmleases <network_id> <IP>
* list (Lists virtual networks in the pool)
onevnet list <filter_flag>
where filter_flag can be
@ -296,7 +302,29 @@ when "delete"
break
end
end
when "addleases"
check_parameters("addleases", 2)
vn_id = get_vn_id(ARGV[0])
vn = OpenNebula::VirtualNetwork.new_with_id(vn_id, get_one_client)
result = vn.addleases(ARGV[1], ARGV[2])
if is_successful?(result)
puts "Leases added" if ops[:verbose]
end
when "rmleases"
check_parameters("rmleases", 2)
vn_id = get_vn_id(ARGV[0])
vn = OpenNebula::VirtualNetwork.new_with_id(vn_id, get_one_client)
result = vn.rmleases(ARGV[1])
if is_successful?(result)
puts "Leases removed" if ops[:verbose]
end
when "list"
if ARGV[0]
case ARGV[0]

View File

@ -22,10 +22,12 @@ module OpenNebula
# Constants and Class Methods
# ---------------------------------------------------------------------
VN_METHODS = {
:info => "vn.info",
:allocate => "vn.allocate",
:publish => "vn.publish",
:delete => "vn.delete"
:info => "vn.info",
:allocate => "vn.allocate",
:publish => "vn.publish",
:delete => "vn.delete",
:addleases => "vn.addleases",
:rmleases => "vn.rmleases"
}
# Creates a VirtualNetwork description with just its identifier
@ -83,6 +85,32 @@ module OpenNebula
super(VN_METHODS[:delete])
end
# Adds a lease to the VirtualNetwork
def addleases(ip, mac = nil)
return Error.new('ID not defined') if !@pe_id
lease_template = "LEASES = [ IP = #{ip}"
lease_template << ", MAC = #{mac}" if mac
lease_template << " ]"
rc = @client.call(VN_METHODS[:addleases], @pe_id, lease_template)
rc = nil if !OpenNebula.is_error?(rc)
return rc
end
# Removes a lease from the VirtualNetwork
def rmleases(ip)
return Error.new('ID not defined') if !@pe_id
lease_template = "LEASES = [ IP = #{ip} ]"
rc = @client.call(VN_METHODS[:rmleases], @pe_id, lease_template)
rc = nil if !OpenNebula.is_error?(rc)
return rc
end
private
def set_publish(published)
return Error.new('ID not defined') if !@pe_id

View File

@ -282,6 +282,12 @@ void RequestManager::register_xml_methods()
xmlrpc_c::methodPtr vn_delete(new
RequestManager::VirtualNetworkDelete(vnpool, upool));
xmlrpc_c::methodPtr vn_addleases(new
RequestManager::VirtualNetworkAddLeases(vnpool, upool));
xmlrpc_c::methodPtr vn_rmleases(new
RequestManager::VirtualNetworkRemoveLeases(vnpool, upool));
xmlrpc_c::methodPtr user_allocate(new
RequestManager::UserAllocate(upool));
@ -355,11 +361,13 @@ void RequestManager::register_xml_methods()
RequestManagerRegistry.addMethod("one.clusterpool.info", clusterpool_info);
/* Network related methods*/
RequestManagerRegistry.addMethod("one.vn.allocate", vn_allocate);
RequestManagerRegistry.addMethod("one.vn.info", vn_info);
RequestManagerRegistry.addMethod("one.vn.publish", vn_publish);
RequestManagerRegistry.addMethod("one.vn.delete", vn_delete);
RequestManagerRegistry.addMethod("one.vn.addleases", vn_addleases);
RequestManagerRegistry.addMethod("one.vn.rmleases", vn_rmleases);
RequestManagerRegistry.addMethod("one.vnpool.info", vnpool_info);

View File

@ -0,0 +1,189 @@
/* -------------------------------------------------------------------------- */
/* 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 "RequestManager.h"
#include "NebulaLog.h"
#include "Nebula.h"
#include "AuthManager.h"
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void RequestManager::VirtualNetworkAddLeases::execute(
xmlrpc_c::paramList const& paramList,
xmlrpc_c::value * const retval)
{
string session;
int nid;
int uid;
int rc;
string str_template;
char * error_msg = 0;
VirtualNetworkTemplate * leases_template;
VirtualNetwork * vn;
int network_owner;
bool is_public;
ostringstream oss;
const string method_name = "VirtualNetworkAddLeases";
vector<xmlrpc_c::value> arrayData;
xmlrpc_c::value_array * arrayresult;
NebulaLog::log("ReM",Log::DEBUG,"VirtualNetworkAddLeases invoked");
session = xmlrpc_c::value_string (paramList.getString(0));
nid = xmlrpc_c::value_int (paramList.getInt(1));
str_template = xmlrpc_c::value_string (paramList.getString(2));
// First, we need to authenticate the user
uid = VirtualNetworkAddLeases::upool->authenticate(session);
if ( uid == -1 )
{
goto error_authenticate;
}
// Check template syntax
leases_template = new VirtualNetworkTemplate;
rc = leases_template->parse(str_template,&error_msg);
if ( rc != 0 )
{
goto error_parse;
}
// Get virtual network from the VirtualNetworkPool
vn = VirtualNetworkAddLeases::vnpool->get(nid,true);
if ( vn == 0 )
{
goto error_vn_get;
}
network_owner = vn->get_uid();
is_public = vn->isPublic();
vn->unlock();
// Authorize the operation
if ( uid != 0 ) // uid == 0 means oneadmin
{
AuthRequest ar(uid);
ar.add_auth(AuthRequest::NET,
nid,
AuthRequest::MANAGE,
network_owner,
is_public);
if (UserPool::authorize(ar) == -1)
{
goto error_authorize;
}
}
// Get virtual network from the VirtualNetworkPool
vn = VirtualNetworkAddLeases::vnpool->get(nid,true);
if ( vn == 0 )
{
goto error_vn_get;
}
rc = vn->add_leases(leases_template, &error_msg);
if ( rc < 0 )
{
goto error_add;
}
vn->unlock();
arrayData.push_back(xmlrpc_c::value_boolean(true));
arrayData.push_back(xmlrpc_c::value_int(nid));
// Copy arrayresult into retval mem space
arrayresult = new xmlrpc_c::value_array(arrayData);
*retval = *arrayresult;
delete arrayresult; // and get rid of the original
delete leases_template;
return;
error_authenticate:
oss.str(authenticate_error(method_name));
goto error_common;
error_parse:
oss << action_error(method_name, "PARSE", "LEASES TEMPLATE",-2,rc);
if (error_msg != 0)
{
oss << " Reason: " << error_msg;
free(error_msg);
}
goto error_delete;
error_vn_get:
oss.str(get_error(method_name, "NET", nid));
goto error_delete;
error_authorize:
oss.str(authorization_error(method_name, "MANAGE", "NET", uid, nid));
goto error_common;
error_add:
oss << action_error(method_name, "ADD LEASE", "NET", nid, rc);
if (error_msg != 0)
{
oss << " Reason: " << error_msg;
free(error_msg);
}
vn->unlock();
goto error_delete;
error_delete:
delete leases_template;
error_common:
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
NebulaLog::log("ReM",Log::ERROR,oss);
xmlrpc_c::value_array arrayresult_error(arrayData);
*retval = arrayresult_error;
return;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -0,0 +1,189 @@
/* -------------------------------------------------------------------------- */
/* 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 "RequestManager.h"
#include "NebulaLog.h"
#include "Nebula.h"
#include "AuthManager.h"
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void RequestManager::VirtualNetworkRemoveLeases::execute(
xmlrpc_c::paramList const& paramList,
xmlrpc_c::value * const retval)
{
string session;
int nid;
int uid;
int rc;
string str_template;
char * error_msg = 0;
VirtualNetworkTemplate * leases_template;
VirtualNetwork * vn;
int network_owner;
bool is_public;
ostringstream oss;
const string method_name = "VirtualNetworkRemoveLeases";
vector<xmlrpc_c::value> arrayData;
xmlrpc_c::value_array * arrayresult;
NebulaLog::log("ReM",Log::DEBUG,"VirtualNetworkRemoveLeases invoked");
session = xmlrpc_c::value_string (paramList.getString(0));
nid = xmlrpc_c::value_int (paramList.getInt(1));
str_template = xmlrpc_c::value_string (paramList.getString(2));
// First, we need to authenticate the user
uid = VirtualNetworkRemoveLeases::upool->authenticate(session);
if ( uid == -1 )
{
goto error_authenticate;
}
// Check template syntax
leases_template = new VirtualNetworkTemplate;
rc = leases_template->parse(str_template,&error_msg);
if ( rc != 0 )
{
goto error_parse;
}
// Get virtual network from the VirtualNetworkPool
vn = VirtualNetworkRemoveLeases::vnpool->get(nid,true);
if ( vn == 0 )
{
goto error_vn_get;
}
network_owner = vn->get_uid();
is_public = vn->isPublic();
vn->unlock();
// Authorize the operation
if ( uid != 0 ) // uid == 0 means oneadmin
{
AuthRequest ar(uid);
ar.add_auth(AuthRequest::NET,
nid,
AuthRequest::MANAGE,
network_owner,
is_public);
if (UserPool::authorize(ar) == -1)
{
goto error_authorize;
}
}
// Get virtual network from the VirtualNetworkPool
vn = VirtualNetworkRemoveLeases::vnpool->get(nid,true);
if ( vn == 0 )
{
goto error_vn_get;
}
rc = vn->remove_leases(leases_template, &error_msg);
if ( rc < 0 )
{
goto error_add;
}
vn->unlock();
arrayData.push_back(xmlrpc_c::value_boolean(true));
arrayData.push_back(xmlrpc_c::value_int(nid));
// Copy arrayresult into retval mem space
arrayresult = new xmlrpc_c::value_array(arrayData);
*retval = *arrayresult;
delete arrayresult; // and get rid of the original
delete leases_template;
return;
error_authenticate:
oss.str(authenticate_error(method_name));
goto error_common;
error_parse:
oss << action_error(method_name, "PARSE", "LEASES TEMPLATE",-2,rc);
if (error_msg != 0)
{
oss << " Reason: " << error_msg;
free(error_msg);
}
goto error_delete;
error_vn_get:
oss.str(get_error(method_name, "NET", nid));
goto error_delete;
error_authorize:
oss.str(authorization_error(method_name, "MANAGE", "NET", uid, nid));
goto error_common;
error_add:
oss << action_error(method_name, "REMOVE LEASE", "NET", nid, rc);
if (error_msg != 0)
{
oss << " Reason: " << error_msg;
free(error_msg);
}
vn->unlock();
goto error_delete;
error_delete:
delete leases_template;
error_common:
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
NebulaLog::log("ReM",Log::ERROR,oss);
xmlrpc_c::value_array arrayresult_error(arrayData);
*retval = arrayresult_error;
return;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -55,6 +55,8 @@ source_files=[
'RequestManagerVirtualNetworkPoolInfo.cc',
'RequestManagerVirtualNetworkPublish.cc',
'RequestManagerVirtualNetworkDelete.cc',
'RequestManagerVirtualNetworkAddLeases.cc',
'RequestManagerVirtualNetworkRemoveLeases.cc',
'RequestManagerUserAllocate.cc',
'RequestManagerUserDelete.cc',
'RequestManagerUserChangePassword.cc',

View File

@ -18,6 +18,8 @@
#include "FixedLeases.h"
#include "NebulaLog.h"
#include <string.h>
FixedLeases::FixedLeases(
SqlDB * db,
int _oid,
@ -28,28 +30,34 @@ FixedLeases::FixedLeases(
const VectorAttribute * single_attr_lease;
string _mac;
string _ip;
char * error_msg = 0;
size = vector_leases.size();
for (unsigned long i=0; i < size ;i++)
for (unsigned long i=0; i < vector_leases.size() ;i++)
{
single_attr_lease = dynamic_cast<const VectorAttribute *>
(vector_leases[i]);
if( single_attr_lease )
{
_ip = single_attr_lease->vector_value("IP");
_mac = single_attr_lease->vector_value("MAC");
_ip = single_attr_lease->vector_value("IP");
_mac = single_attr_lease->vector_value("MAC");
add(_ip,_mac,-1,false);
if( add(_ip,_mac,-1,&error_msg,false,true) != 0 )
{
NebulaLog::log("VNM", Log::ERROR, error_msg);
free(error_msg);
}
}
}
size = leases.size();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int FixedLeases::add(const string& ip, const string& mac, int vid, bool used)
int FixedLeases::add(const string& ip, const string& mac, int vid,
char** error_msg, bool used, bool check)
{
ostringstream oss;
unsigned int _ip;
@ -62,6 +70,11 @@ int FixedLeases::add(const string& ip, const string& mac, int vid, bool used)
goto error_ip;
}
if ( check && leases.count(_ip) > 0 )
{
goto error_duplicate;
}
if (mac.empty())
{
_mac[Lease::PREFIX] = mac_prefix;
@ -82,39 +95,117 @@ int FixedLeases::add(const string& ip, const string& mac, int vid, bool used)
rc = db->exec(oss);
if ( rc == 0 )
if ( rc != 0 )
{
leases.insert(make_pair(_ip,new Lease(_ip,_mac,vid,used)));
goto error_db;
}
leases.insert(make_pair(_ip,new Lease(_ip,_mac,vid,used)));
return rc;
error_ip:
oss.str("");
oss << "Error inserting lease, malformed IP = " << ip;
goto error_common;
error_mac:
oss.str("");
oss << "Error inserting lease, MAC = " << mac;
oss << "Error inserting lease, malformed MAC = " << mac;
goto error_common;
error_ip:
oss.str("");
oss << "Error inserting lease, IP = " << ip;
error_duplicate:
oss.str("");
oss << "Error inserting lease, IP " << ip << " already exists";
goto error_common;
error_db:
oss.str("");
oss << "Error inserting lease in database. Check oned.log";
goto error_common;
error_common:
NebulaLog::log("VNM", Log::ERROR, oss);
return -1;
*error_msg = strdup( oss.str().c_str() );
return -1;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int FixedLeases::del(const string& ip)
int FixedLeases::remove(const string& ip, char ** error_msg)
{
map<unsigned int,Lease *>::iterator it;
ostringstream oss;
unsigned int _ip;
int rc;
if( Leases::Lease::ip_to_number(ip,_ip) )
{
goto error_ip;
}
it = leases.find(_ip);
if (it == leases.end()) //it does not exist in the net
{
goto error_notfound;
}
else if (it->second->used) //it is in use
{
goto error_used;
}
oss << "DELETE FROM " << table << " WHERE (oid=" << oid
<< " AND ip=" << _ip << ")";
rc = db->exec(oss);
if ( rc != 0 )
{
goto error_db;
}
leases.erase(it);
return rc;
error_ip:
oss.str("");
oss << "Error deleting lease, malformed IP = " << ip;
goto error_common;
error_notfound:
oss.str("");
oss << "Error deleting lease, IP " << ip << " is not part of NET " << oid;
goto error_common;
error_used:
oss.str("");
oss << "Error deleting lease, IP " << ip << " is currently in use";
goto error_common;
error_db:
oss.str("");
oss << "Error inserting lease in database. Check oned.log";
goto error_common;
error_common:
*error_msg = strdup( oss.str().c_str() );
return -1;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int FixedLeases::unset(const string& ip)
{
unsigned int _ip;
ostringstream oss;
map<unsigned int, Lease *>::iterator it_ip;
// Remove lease from leases map
if ( Leases::Lease::ip_to_number(ip,_ip) )
{
return 0; //Wrong format, not leased
@ -233,3 +324,59 @@ int FixedLeases::set(int vid, const string& ip, string& mac)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int FixedLeases::add_leases(vector<const Attribute*>& vector_leases,
char ** error_msg)
{
const VectorAttribute * single_attr_lease;
int rc = -1;
string _mac;
string _ip;
single_attr_lease = dynamic_cast<const VectorAttribute *>(vector_leases[0]);
if( single_attr_lease )
{
_ip = single_attr_lease->vector_value("IP");
_mac = single_attr_lease->vector_value("MAC");
rc = add(_ip, _mac, -1, error_msg, false, true);
if( rc == 0 )
{
size = leases.size();
}
}
return rc;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int FixedLeases::remove_leases(vector<const Attribute*>& vector_leases,
char ** error_msg)
{
const VectorAttribute * single_attr_lease;
int rc = -1;
string _ip;
single_attr_lease = dynamic_cast<const VectorAttribute *>(vector_leases[0]);
if( single_attr_lease )
{
_ip = single_attr_lease->vector_value("IP");
rc = remove(_ip, error_msg);
if( rc == 0 )
{
size = leases.size();
}
}
return rc;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -686,3 +686,28 @@ int VirtualNetwork::nic_attribute(VectorAttribute *nic, int vid)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int VirtualNetwork::add_leases(VirtualNetworkTemplate * leases_template,
char ** error_msg)
{
vector<const Attribute *> vector_leases;
leases_template->get("LEASES", vector_leases);
return leases->add_leases(vector_leases, error_msg);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int VirtualNetwork::remove_leases(VirtualNetworkTemplate * leases_template,
char ** error_msg)
{
vector<const Attribute *> vector_leases;
leases_template->get("LEASES", vector_leases);
return leases->remove_leases(vector_leases, error_msg);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */