1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-11 05:17:41 +03:00

Now a VM can ask for a specific lease, based on the IP

git-svn-id: http://svn.opennebula.org/one/trunk@239 3034c82b-c49b-4eb3-8279-a7acafdc01c0
This commit is contained in:
Rubén S. Montero 2008-11-15 00:40:27 +00:00
parent aaf6abc70d
commit 2566d2fe23
8 changed files with 156 additions and 9 deletions

View File

@ -59,6 +59,15 @@ public:
* @return 0 if success
*/
int get(int vid, string& ip, string& mac);
/**
* 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);
/**
* Release an used lease, which becomes unused

View File

@ -69,9 +69,16 @@ public:
* @param mac mac of the returned lease
* @return 0 if success
*/
virtual int get(int vid,
string& ip,
string& mac) = 0;
virtual int get(int vid, string& ip,string& mac) = 0;
/**
* 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
*/
virtual int set(int vid, const string& ip, string& mac) = 0;
/**
* Release an used lease, which becomes unused

View File

@ -46,6 +46,15 @@ public:
*/
int get(int vid, string& ip, string& mac);
/**
* 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);
/**
* Release an used lease, which becomes unused
* @param ip of the lease in use

View File

@ -73,6 +73,20 @@ public:
_bridge = bridge;
return leases->get(vid,_ip,_mac);
};
/**
* Asks for an specific lease of the given virtual network
* @param vid VM identifier
* @param _ip the ip of the requested lease
* @param _mac pointer to string for MAC to be stored into
* @param _bridge name of the physical bridge this VN binds to
* @return 0 if success
*/
int set_lease(int vid, const string& _ip, string& _mac, string& _bridge)
{
_bridge = bridge;
return leases->set(vid,_ip,_mac);
};
/**
* Release previously given lease

View File

@ -490,7 +490,7 @@ void VirtualMachine::get_requirements (int& cpu, int& memory, int& disk)
int VirtualMachine::get_leases()
{
int num_nics;
int num_nics, rc;
vector<Attribute * > nics;
VirtualNetworkPool * vnpool;
VirtualNetwork * vn;
@ -533,14 +533,24 @@ int VirtualMachine::get_leases()
{
continue;
}
if ( vn->get_lease(oid, ip, mac, bridge) != 0 )
ip = nic->vector_value("IP");
if (ip.empty())
{
vn->unlock();
return -1;
rc = vn->get_lease(oid, ip, mac, bridge);
}
else
{
rc = vn->set_lease(oid, ip, mac, bridge);
}
vn->unlock();
vn->unlock();
if ( rc != 0 )
{
return -1;
}
vnid << vn->get_oid();

View File

@ -186,3 +186,50 @@ int FixedLeases::get(int vid, string& ip, string& mac)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int FixedLeases::set(int vid, const string& ip, string& mac)
{
map<unsigned int,Lease *>::iterator it;
ostringstream oss;
unsigned int num_ip;
int rc;
rc = Leases::Lease::ip_to_number(ip,num_ip);
if (rc != 0)
{
return -1;
}
it=leases.find(num_ip);
if (it == leases.end()) //it does not exists in the net
{
return -1;
}
else if (it->second->used) //it is in use
{
return -1;
}
oss << "UPDATE " << table << " SET used='1', vid='" << vid
<< "' WHERE ip='" << it->second->ip <<"'";
rc = db->exec(oss);
if ( rc != 0 )
{
return -1;
}
it->second->used = true;
it->second->vid = vid;
Leases::Lease::mac_to_string(it->second->mac,mac);
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -327,12 +327,18 @@ int Leases::drop(SqliteDB * db)
return db->exec(oss);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int Leases::insert(SqliteDB * db)
{
Nebula::log("VNM", Log::ERROR, "Should not access to Leases.insert()");
return -1;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int Leases::update(SqliteDB * db)
{
Nebula::log("VNM", Log::ERROR, "Should not access to Leases.update()");

View File

@ -82,6 +82,51 @@ int RangedLeases::get(int vid, string& ip, string& mac)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int RangedLeases::set(int vid, const string& ip, string& mac)
{
unsigned int num_ip;
unsigned int num_mac[2];
unsigned int net;
int rc;
rc = Leases::Lease::ip_to_number(ip,num_ip);
if (rc != 0)
{
return -1;
}
net = 0xFFFFFFFF << (int) ceil(log(size)/log(2));
net &= num_ip;
if ( net != network_address )
{
return -1;
}
if (check(num_ip) == true)
{
return -1;
}
num_mac[Lease::PREFIX] = mac_prefix;
num_mac[Lease::SUFFIX] = num_ip;
rc = add(num_ip,num_mac,vid);
if (rc != 0)
{
return -1;
}
Leases::Lease::mac_to_string(num_mac,mac);
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int RangedLeases::add(
unsigned int ip,
unsigned int mac[],