1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-28 17:57:22 +03:00

feature #2858: Integrate Address Ranges with VirtualNetwork and VirtualMachine

This commit is contained in:
Ruben S. Montero 2014-05-10 21:06:59 +02:00
parent cab018fc98
commit 72b61e9ec5
6 changed files with 74 additions and 68 deletions

View File

@ -70,8 +70,8 @@ public:
* @param inherit attributes to be added to the NIC
* @return 0 if success
*/
int allocate(PoolObjectSQL::ObjectType ot, int obid, VectorAttribute * nic,
const vector<string> &inherit);
int allocate_addr(PoolObjectSQL::ObjectType ot, int obid,
VectorAttribute * nic, const vector<string> &inherit);
/**
* Allocates an address in a suitable address range from the pool by mac

View File

@ -98,69 +98,57 @@ public:
int free_leases(VirtualNetworkTemplate* leases, string& error_msg);
/**
* Gets a new lease for a specific VM
* Gets a new address lease for a specific VM
* @param vid VM identifier
* @param _ip pointer to string for IP to be stored into
* @param _mac pointer to string for MAC to be stored into
* @param _bridge name of the physical bridge this VN binds to
* @param nic the VM NIC attribute to be filled with the lease info.
* @param inherit attributes from the address range to include in the NIC
* @return 0 if success
*/
int get_lease(int vid, string& _ip, string& _mac, string& _bridge)
int allocate_addr(int vid, VectorAttribute * nic,
const vector<string>& inherit)
{
return 0;
//TODO
/*
unsigned int eui64[2];
_bridge = bridge;
return leases->get(vid, _ip, _mac, eui64);
*/
};
return ar_pool.allocate_addr(PoolObjectSQL::VM, vid, nic, inherit);
}
/**
* Asks for an specific lease of the given virtual network
* Gets a new address lease for a specific VM by MAC
* @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
* @param mac the MAC address requested
* @param nic the VM NIC attribute to be filled with the lease info.
* @param inherit attributes from the address range to include in the NIC
* @return 0 if success
*/
int set_lease(int vid, const string& _ip, string& _mac, string& _bridge)
int allocate_by_mac(int vid, const string& mac, VectorAttribute * nic,
const vector<string>& inherit)
{
//TODO
/*
unsigned int eui64[2];
_bridge = bridge;
return leases->set(vid, _ip, _mac, eui64);
*/
return 0;
};
return ar_pool.allocate_by_mac(mac, PoolObjectSQL::VM, vid, nic, inherit);
}
/**
* Release previously given lease
* @param _ip IP identifying the lease
* Gets a new address lease for a specific VM by IP
* @param vid VM identifier
* @param ip the IP address requested
* @param nic the VM NIC attribute to be filled with the lease info.
* @param inherit attributes from the address range to include in the NIC
* @return 0 if success
*/
void release_lease(const string& ip)
int allocate_by_ip(int vid, const string& ip, VectorAttribute * nic,
const vector<string>& inherit)
{
//TODO
//return leases->release(ip);
};
return ar_pool.allocate_by_ip(ip, PoolObjectSQL::VM, vid, nic, inherit);
}
/**
* Check if a VM is the owner of the ip
* @param ip of the lease to be checked
* Release previously given address lease
* @param arid of the address range where the address was leased from
* @param vid the ID of the VM
* @return true if the ip was already assigned
* @param mac MAC address identifying the lease
* @return 0 if success
*/
bool is_owner (const string& ip, int vid)
void free_addr(unsigned int arid, int vid, const string& mac)
{
return true;
//TODO
//return leases->is_owner(ip, vid);
};
ar_pool.free_addr(arid, PoolObjectSQL::VM, vid, mac);
}
/**
* Gets size of the network (used + free)

View File

@ -2595,21 +2595,23 @@ int VirtualMachine::release_network_leases(VectorAttribute const * nic, int vmid
VirtualNetwork* vn;
int vnid;
string ip;
int ar_id;
string mac;
if ( nic == 0 )
{
return -1;
}
if ( nic->vector_value("NETWORK_ID", vnid) != 0 )
if (nic->vector_value("NETWORK_ID", vnid) != 0 ||
nic->vector_value("AR_ID", ar_id) != 0)
{
return -1;
}
ip = nic->vector_value("IP");
mac = nic->vector_value("MAC");
if ( ip.empty() )
if (mac.empty())
{
return -1;
}
@ -2621,11 +2623,9 @@ int VirtualMachine::release_network_leases(VectorAttribute const * nic, int vmid
return -1;
}
if (vn->is_owner(ip,vmid))
{
vn->release_lease(ip);
vn->free_addr(ar_id, vmid, mac);
vnpool->update(vn);
}
vn->unlock();

View File

@ -263,11 +263,11 @@ void AddressRange::to_xml(ostringstream &oss) const
if (it->second & PoolObjectSQL::VM)
{
lease.replace("VM", it->second && 0x00000000FFFFFFFFLL);
lease.replace("VM", it->second & 0x00000000FFFFFFFFLL);
}
else if (it->second & PoolObjectSQL::NET)
{
lease.replace("VNET", it->second && 0x00000000FFFFFFFFLL);
lease.replace("VNET", it->second & 0x00000000FFFFFFFFLL);
}
lease.to_xml(oss);
@ -586,11 +586,12 @@ int AddressRange::attr_to_allocated(const string& allocated_s)
{
iss >> ws >> addr_index >> ws >> object_pack;
if (!iss.fail())
if (iss.fail())
{
allocated.insert(make_pair(addr_index,object_pack));
return -1;
}
allocated.insert(make_pair(addr_index,object_pack));
}
return 0;
@ -632,8 +633,6 @@ int AddressRange::allocate_addr(
VectorAttribute* nic,
const vector<string>& inherit)
{
int rc = -1;
for ( unsigned int i=0; i<size; i++, next = (next+1)%size )
{
if ( allocated.count(next) == 0 )
@ -653,10 +652,12 @@ int AddressRange::allocate_addr(
set_vnet(nic, inherit);
allocate_addr(ot, obid, next);
return 0;
}
}
return rc;
return -1;
}
/* -------------------------------------------------------------------------- */
@ -702,7 +703,7 @@ int AddressRange::allocate_by_mac(
set_vnet(nic, inherit);
allocate_addr(ot, obid, next);
allocate_addr(ot, obid, index);
return 0;
}
@ -755,7 +756,7 @@ int AddressRange::allocate_by_ip(
set_vnet(nic, inherit);
allocate_addr(ot, obid, next);
allocate_addr(ot, obid, index);
return 0;
}

View File

@ -139,7 +139,7 @@ string& AddressRangePool::to_xml(string& sstream, bool extended) const
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int AddressRangePool::allocate(PoolObjectSQL::ObjectType ot, int obid,
int AddressRangePool::allocate_addr(PoolObjectSQL::ObjectType ot, int obid,
VectorAttribute * nic, const vector<string> &inherit)
{
map<unsigned int, AddressRange *>::iterator it;

View File

@ -560,11 +560,28 @@ int VirtualNetwork::nic_attribute(
}
}
//GET THE IP/MAC... AND OVERWRITE FROM AR.
//string ip = nic->vector_value("IP");
//string mac = nic->vector_value("MAC");
//--------------------------------------------------------------------------
// Get the lease from the Virtual Network
//--------------------------------------------------------------------------
int rc;
return 0;
string ip = nic->vector_value("IP");
string mac = nic->vector_value("MAC");
if (!ip.empty())
{
rc = allocate_by_ip(vid, ip, nic, inherit_attrs);
}
else if (!mac.empty())
{
rc = allocate_by_mac(vid, mac, nic, inherit_attrs);
}
else
{
rc = allocate_addr(vid, nic, inherit_attrs);
}
return rc;
}
/* -------------------------------------------------------------------------- */