mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-30 22:50:10 +03:00
feature #2858: Add reservations to an exisiting network. VNETs are labeled with the PARENT_NETWORK_ID if any. Just one PARENT VNET is allowed
This commit is contained in:
parent
509529bac6
commit
be238e98ee
@ -204,37 +204,34 @@ public:
|
||||
|
||||
/**
|
||||
* Reserve a given number of addresses from this address range
|
||||
* @param pvid the id of the parent VNET
|
||||
* @param vid the id of the VNET making the reservation
|
||||
* @param size number of addresses to reserve
|
||||
* @param rar a new address range to place the reservation
|
||||
* @return 0 on success
|
||||
*/
|
||||
int reserve_addr(int pvid, int vid, unsigned int rsize, AddressRange *rar);
|
||||
int reserve_addr(int vid, unsigned int rsize, AddressRange *rar);
|
||||
|
||||
/**
|
||||
* Reserve a given number of addresses from this address range
|
||||
* @param pvid the id of the parent VNET
|
||||
* @param vid the id of the VNET making the reservation
|
||||
* @param size number of addresses to reserve
|
||||
* @param rar a new address range to place the reservation
|
||||
* @param ip the firs ip in the Reservation
|
||||
* @return 0 on success
|
||||
*/
|
||||
int reserve_addr_by_ip(int pvid, int vid, unsigned int rsize,
|
||||
const string& ip, AddressRange *rar);
|
||||
int reserve_addr_by_ip(int vid, unsigned int rsize, const string& ip,
|
||||
AddressRange *rar);
|
||||
|
||||
/**
|
||||
* Reserve a given number of addresses from this address range
|
||||
* @param pvid the id of the parent VNET
|
||||
* @param vid the id of the VNET making the reservation
|
||||
* @param size number of addresses to reserve
|
||||
* @param rar a new address range to place the reservation
|
||||
* @param mac the firs mac in the Reservation
|
||||
* @return 0 on success
|
||||
*/
|
||||
int reserve_addr_by_mac(int pvid, int vid, unsigned int rsize,
|
||||
const string& mac, AddressRange *rar);
|
||||
int reserve_addr_by_mac(int vid, unsigned int rsize, const string& mac,
|
||||
AddressRange *rar);
|
||||
|
||||
// *************************************************************************
|
||||
// Helpers
|
||||
@ -389,15 +386,14 @@ private:
|
||||
|
||||
/**
|
||||
* Reserve a set of addresses from an starting one
|
||||
* @param pvid the id of the parent VNET
|
||||
* @param vid the id of the VNET making the reservation
|
||||
* @param rsize number of addresses to reserve
|
||||
* @param sindex the first index to start the reservation
|
||||
* @param rar a new address range to place the reservation
|
||||
* @return 0 on success
|
||||
*/
|
||||
int reserve_addr_by_index(int pvid, int vid, unsigned int rsize,
|
||||
unsigned int sindex, AddressRange *rar);
|
||||
int reserve_addr_by_index(int vid, unsigned int rsize, unsigned int sindex,
|
||||
AddressRange *rar);
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Restricted Attributes functions */
|
||||
|
@ -217,29 +217,26 @@ public:
|
||||
/**
|
||||
* Reserve a given number of addresses from the first address range with
|
||||
* enough free addresses to allocate the reservation
|
||||
* @param pvid the id of the parent VNET
|
||||
* @param vid the id of the VNET making the reservation
|
||||
* @param size number of addresses to reserve
|
||||
* @param rar a new address range to place the reservation
|
||||
* @return 0 on success
|
||||
*/
|
||||
int reserve_addr(int pvid, int vid, unsigned int rsize, AddressRange *rar);
|
||||
int reserve_addr(int vid, unsigned int rsize, AddressRange *rar);
|
||||
|
||||
/**
|
||||
* Reserve a given number of addresses from the given address range
|
||||
* @param pvid the id of the parent VNET
|
||||
* @param vid the id of the VNET making the reservation
|
||||
* @param rsize number of addresses to reserve
|
||||
* @param ar_id the address range to reserve the addresses from
|
||||
* @param rar a new address range to place the reservation
|
||||
* @return 0 on success
|
||||
*/
|
||||
int reserve_addr(int pvid, int vid, unsigned int rsize, unsigned int ar_id,
|
||||
int reserve_addr(int vid, unsigned int rsize, unsigned int ar_id,
|
||||
AddressRange *rar);
|
||||
|
||||
/**
|
||||
* Reserve a number of addresses from an address range from a given ip
|
||||
* @param pvid the id of the parent VNET
|
||||
* @param vid the id of the VNET making the reservation
|
||||
* @param rsize number of addresses to reserve
|
||||
* @param ar_id the address range to reserve the addresses from
|
||||
@ -247,12 +244,11 @@ public:
|
||||
* @param rar a new address range to place the reservation
|
||||
* @return 0 on success
|
||||
*/
|
||||
int reserve_addr_by_ip(int pvid, int vid, unsigned int rsize,
|
||||
unsigned int ar_id, const string& ip, AddressRange *rar);
|
||||
int reserve_addr_by_ip(int vid, unsigned int rsize, unsigned int ar_id,
|
||||
const string& ip, AddressRange *rar);
|
||||
|
||||
/**
|
||||
* Reserve a number of addresses from an address range from a given ip
|
||||
* @param pvid the id of the parent VNET
|
||||
* @param vid the id of the VNET making the reservation
|
||||
* @param rsize number of addresses to reserve
|
||||
* @param ar_id the address range to reserve the addresses from
|
||||
@ -260,14 +256,8 @@ public:
|
||||
* @param rar a new address range to place the reservation
|
||||
* @return 0 on success
|
||||
*/
|
||||
int reserve_addr_by_mac(int pvid, int vid, unsigned int rsize,
|
||||
unsigned int ar_id, const string& mac, AddressRange *rar);
|
||||
|
||||
/**
|
||||
* Get the parent vnets of the Address Ranges in this AR POOL
|
||||
* @param parent_vnets vector with the vnet ids of the parent vnets
|
||||
*/
|
||||
unsigned int get_parents(vector<int>& parent_nets);
|
||||
int reserve_addr_by_mac(int vid, unsigned int rsize, unsigned int ar_id,
|
||||
const string& mac, AddressRange *rar);
|
||||
|
||||
// *************************************************************************
|
||||
// Helpers & Formatting
|
||||
|
@ -279,13 +279,12 @@ public:
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the parent networks used to create this VNET (if any)
|
||||
* @param parents vector of parents networks if any
|
||||
* @return the number of parents
|
||||
* Returns the parent network used to create this VNET (if any)
|
||||
* @return the parent vnet id or -1 this vnet has no parent
|
||||
*/
|
||||
unsigned int get_parents(vector<int>& parents)
|
||||
int get_parent()
|
||||
{
|
||||
return ar_pool.get_parents(parents);
|
||||
return parent_vid;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -375,6 +374,11 @@ private:
|
||||
*/
|
||||
int vlan;
|
||||
|
||||
/**
|
||||
* Parent VNET ID if any
|
||||
*/
|
||||
int parent_vid;
|
||||
|
||||
/**
|
||||
* The Address Range Pool
|
||||
*/
|
||||
@ -430,6 +434,7 @@ private:
|
||||
const string& _uname,
|
||||
const string& _gname,
|
||||
int _umask,
|
||||
int _parent_vid,
|
||||
int _cluster_id,
|
||||
const string& _cluster_name,
|
||||
VirtualNetworkTemplate * _vn_template = 0);
|
||||
|
@ -62,6 +62,7 @@ public:
|
||||
const string& uname,
|
||||
const string& gname,
|
||||
int umask,
|
||||
int parent_vid,
|
||||
VirtualNetworkTemplate * vn_template,
|
||||
int * oid,
|
||||
int cluster_id,
|
||||
@ -188,7 +189,7 @@ private:
|
||||
*/
|
||||
PoolObjectSQL * create()
|
||||
{
|
||||
return new VirtualNetwork(-1,-1,"","",0,-1,"",0);
|
||||
return new VirtualNetwork(-1,-1,"","",0,-1,-1,"",0);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -183,10 +183,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
end
|
||||
|
||||
reserve_desc = <<-EOT.unindent
|
||||
Reserve addresses from the Virtual Network
|
||||
Reserve addresses from the Virtual Network. A new virtual network will
|
||||
be created to hold the reservation. Optionally the reservation can be
|
||||
put on an exisiting VNET, as long as it contains a valid reservation
|
||||
from the same VNET
|
||||
EOT
|
||||
|
||||
command :reserve, reserve_desc, :vnetid,
|
||||
command :reserve, reserve_desc, :vnetid, [:vnetid, nil],
|
||||
:options=>STD_OPTIONS + [OneVNetHelper::AR, OneVNetHelper::R_NAME,
|
||||
OneVNetHelper::R_SIZE, OneVNetHelper::AR_MAC, OneVNetHelper::AR_IP] do
|
||||
helper.perform_action(args[0],options,"reservation made") do |vn|
|
||||
@ -207,7 +210,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
exit -1
|
||||
end
|
||||
|
||||
vn.reserve(rname, rsize, options[:ar_id], addr)
|
||||
vn.reserve(rname, rsize, options[:ar_id], addr, args[1])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -193,12 +193,15 @@ module OpenNebula
|
||||
# any address range will be used
|
||||
# @param addr [String] the first address in the reservation. If set to
|
||||
# nil the first free address will be used
|
||||
def reserve(rname, rsize, ar_id, addr)
|
||||
# @param vnet [String] ID of the VNET to add the reservation to. If not
|
||||
# set a new VNET will be created.
|
||||
def reserve(rname, rsize, ar_id, addr, vnet)
|
||||
return Error.new('ID not defined') if !@pe_id
|
||||
|
||||
rtmpl = "NAME = #{rname}\n"
|
||||
rtmpl << "SIZE = #{rsize}\n"
|
||||
rtmpl << "AR_ID= #{ar_id}\n" if !ar_id.nil?
|
||||
rtmpl = "SIZE = #{rsize}\n"
|
||||
rtmpl << "NAME = #{rname}\n" if !name.nil?
|
||||
rtmpl << "AR_ID = #{ar_id}\n" if !ar_id.nil?
|
||||
rtmpl << "NETWORK_ID = #{vnet}\n" if !vnet.nil?
|
||||
|
||||
if !addr.nil?
|
||||
if addr.include?':'
|
||||
|
@ -280,7 +280,7 @@ int VirtualNetworkAllocate::pool_allocate(
|
||||
VirtualNetworkPool * vpool = static_cast<VirtualNetworkPool *>(pool);
|
||||
VirtualNetworkTemplate * vtmpl=static_cast<VirtualNetworkTemplate *>(tmpl);
|
||||
|
||||
return vpool->allocate(att.uid, att.gid, att.uname, att.gname, att.umask,
|
||||
return vpool->allocate(att.uid, att.gid, att.uname, att.gname, att.umask,-1,
|
||||
vtmpl, &id, cluster_id, cluster_name, error_str);
|
||||
}
|
||||
|
||||
|
@ -323,8 +323,6 @@ int ZoneDelete::drop(int oid, PoolObjectSQL * object, string& error_msg)
|
||||
|
||||
int VirtualNetworkDelete::drop(int oid, PoolObjectSQL * object, string& error_msg)
|
||||
{
|
||||
vector<int> parents;
|
||||
|
||||
VirtualNetwork * vnet = static_cast<VirtualNetwork *>(object);
|
||||
|
||||
if ( vnet->get_used() > 0 )
|
||||
@ -336,22 +334,19 @@ int VirtualNetworkDelete::drop(int oid, PoolObjectSQL * object, string& error_ms
|
||||
return -1;
|
||||
}
|
||||
|
||||
vnet->get_parents(parents);
|
||||
|
||||
int uid = vnet->get_uid();
|
||||
int gid = vnet->get_gid();
|
||||
int pvid = vnet->get_parent();
|
||||
int uid = vnet->get_uid();
|
||||
int gid = vnet->get_gid();
|
||||
|
||||
int rc = RequestManagerDelete::drop(oid, object, error_msg);
|
||||
|
||||
VirtualNetworkPool *vnpool = static_cast<VirtualNetworkPool *>(pool);
|
||||
|
||||
for (vector<int>::iterator it = parents.begin(); it < parents.end(); it++)
|
||||
if (pvid != -1)
|
||||
{
|
||||
vnet = vnpool->get(*it, true);
|
||||
vnet = (static_cast<VirtualNetworkPool *>(pool))->get(pvid, true);
|
||||
|
||||
if (vnet == 0)
|
||||
{
|
||||
continue;
|
||||
return rc;
|
||||
}
|
||||
|
||||
int freed = vnet->free_addr_by_owner(PoolObjectSQL::NET, oid);
|
||||
@ -367,7 +362,7 @@ int VirtualNetworkDelete::drop(int oid, PoolObjectSQL * object, string& error_ms
|
||||
|
||||
for (int i= 0 ; i < freed ; i++)
|
||||
{
|
||||
oss << " NIC = [ NETWORK_ID = " << *it << " ]" << endl;
|
||||
oss << " NIC = [ NETWORK_ID = " << pvid << " ]" << endl;
|
||||
}
|
||||
|
||||
tmpl.parse_str_or_xml(oss.str(), error_msg);
|
||||
|
@ -139,9 +139,11 @@ void VirtualNetworkReserve::request_execute(
|
||||
|
||||
VirtualNetworkTemplate tmpl;
|
||||
VirtualNetwork * vn;
|
||||
VirtualNetwork * rvn;
|
||||
|
||||
string error_str;
|
||||
int rc;
|
||||
int cluster_id;
|
||||
|
||||
if ( basic_authorization(id, att) == false )
|
||||
{
|
||||
@ -170,11 +172,22 @@ void VirtualNetworkReserve::request_execute(
|
||||
return;
|
||||
}
|
||||
|
||||
int rid;
|
||||
bool on_exisiting = tmpl.get("NETWORK_ID", rid);
|
||||
|
||||
if ( on_exisiting && (rid < 0))
|
||||
{
|
||||
failure_response(ACTION, request_error("Error in reservation request",
|
||||
"NETWORK_ID must be equal or greater than 0"), att);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
string name;
|
||||
|
||||
tmpl.get("NAME", name);
|
||||
|
||||
if (name.empty())
|
||||
if (name.empty() && !on_exisiting)
|
||||
{
|
||||
failure_response(ACTION, request_error("Error in reservation request",
|
||||
"NAME for reservation has to be set"), att);
|
||||
@ -224,7 +237,7 @@ void VirtualNetworkReserve::request_execute(
|
||||
return;
|
||||
}
|
||||
|
||||
// --------------- Create a new VNET to place the reservation -------------
|
||||
// --------------- Get the VNET to make the reservation -------------
|
||||
|
||||
vn = static_cast<VirtualNetwork *>(pool->get(id,true));
|
||||
|
||||
@ -236,37 +249,55 @@ void VirtualNetworkReserve::request_execute(
|
||||
return;
|
||||
}
|
||||
|
||||
VirtualNetworkTemplate * vtmpl = vn->clone_template();
|
||||
// -------------- Get/create a network to place the reservation ------------
|
||||
|
||||
vtmpl->replace("NAME", name);
|
||||
if (!on_exisiting) //Create a new VNET
|
||||
{
|
||||
VirtualNetworkTemplate * vtmpl = vn->clone_template();
|
||||
|
||||
int rid;
|
||||
int cluster_id = vn->get_cluster_id();
|
||||
vtmpl->replace("NAME", name);
|
||||
|
||||
rc = (static_cast<VirtualNetworkPool *>(pool))->allocate(att.uid, att.gid,
|
||||
att.uname, att.gname, att.umask, vtmpl, &rid, cluster_id,
|
||||
vn->get_cluster_name(), error_str);
|
||||
cluster_id = vn->get_cluster_id();
|
||||
|
||||
if (rc < 0)
|
||||
rc = (static_cast<VirtualNetworkPool *>(pool))->allocate(att.uid, att.gid,
|
||||
att.uname, att.gname, att.umask, id, vtmpl, &rid, cluster_id,
|
||||
vn->get_cluster_name(), error_str);
|
||||
|
||||
if (rc < 0)
|
||||
{
|
||||
quota_rollback(&qtmpl, Quotas::NETWORK, att);
|
||||
|
||||
failure_response(INTERNAL,
|
||||
request_error("Cannot create a reservation VNET",error_str),att);
|
||||
|
||||
vn->unlock();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
rvn = static_cast<VirtualNetwork *>(pool->get(rid,true));
|
||||
|
||||
if (rvn == 0)
|
||||
{
|
||||
quota_rollback(&qtmpl, Quotas::NETWORK, att);
|
||||
|
||||
failure_response(INTERNAL,
|
||||
request_error("Cannot allocate reservation VNET", error_str), att);
|
||||
failure_response(NO_EXISTS, get_error(object_name(auth_object),rid),att);
|
||||
|
||||
vn->unlock();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
VirtualNetwork * rvn = static_cast<VirtualNetwork *>(pool->get(rid,true));
|
||||
|
||||
if (rvn == 0)
|
||||
if (on_exisiting && rvn->get_parent() != id)
|
||||
{
|
||||
quota_rollback(&qtmpl, Quotas::NETWORK, att);
|
||||
|
||||
failure_response(INTERNAL,
|
||||
request_error("Cannot allocate reservation VNET",""), att);
|
||||
request_error("Cannot put reservations from different networks on "
|
||||
"the same VNET",""), att);
|
||||
|
||||
rvn->unlock();
|
||||
|
||||
vn->unlock();
|
||||
|
||||
@ -301,7 +332,10 @@ void VirtualNetworkReserve::request_execute(
|
||||
|
||||
failure_response(ACTION, request_error(error_str,""), att);
|
||||
|
||||
pool->drop(rvn, error_str);
|
||||
if (!on_exisiting)
|
||||
{
|
||||
pool->drop(rvn, error_str);
|
||||
}
|
||||
|
||||
rvn->unlock();
|
||||
|
||||
@ -320,7 +354,7 @@ void VirtualNetworkReserve::request_execute(
|
||||
|
||||
// -------------- Add the reservation to the cluster ----------------------
|
||||
|
||||
if ( cluster_id != ClusterPool::NONE_CLUSTER_ID )
|
||||
if ((cluster_id != ClusterPool::NONE_CLUSTER_ID) && (!on_exisiting))
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
|
||||
|
@ -1016,22 +1016,15 @@ int AddressRange::hold_by_mac(const string& mac_s)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int AddressRange::reserve_addr(int pvid, int vid, unsigned int rsize,
|
||||
AddressRange *rar)
|
||||
int AddressRange::reserve_addr(int vid, unsigned int rsize, AddressRange *rar)
|
||||
{
|
||||
unsigned int first_index;
|
||||
int pnet;
|
||||
|
||||
if (rsize > (size - used_addr))
|
||||
{
|
||||
return -1; //reservation dosen't fit
|
||||
}
|
||||
|
||||
if ((attr->vector_value("PARENT_NETWORK_ID", pnet) == 0 ) && (pnet > -1))
|
||||
{
|
||||
return -1; //This address range is already a reservation
|
||||
}
|
||||
|
||||
// --------------- Look for a continuos range of addresses -----------------
|
||||
|
||||
bool valid = true;
|
||||
@ -1087,8 +1080,6 @@ int AddressRange::reserve_addr(int pvid, int vid, unsigned int rsize,
|
||||
|
||||
rar->from_vattr(new_ar, errmsg);
|
||||
|
||||
new_ar->replace("PARENT_NETWORK_ID", pvid);
|
||||
|
||||
new_ar->replace("PARENT_NETWORK_AR_ID",id);
|
||||
|
||||
return 0;
|
||||
@ -1097,16 +1088,9 @@ int AddressRange::reserve_addr(int pvid, int vid, unsigned int rsize,
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int AddressRange::reserve_addr_by_index(int pvid, int vid, unsigned int rsize,
|
||||
int AddressRange::reserve_addr_by_index(int vid, unsigned int rsize,
|
||||
unsigned int sindex, AddressRange *rar)
|
||||
{
|
||||
int pnet;
|
||||
|
||||
if ((attr->vector_value("PARENT_NETWORK_ID", pnet) == 0 ) && (pnet > -1))
|
||||
{
|
||||
return -1; //This address range is already a reservation
|
||||
}
|
||||
|
||||
/* ----------------- Allocate the new AR from sindex -------------------- */
|
||||
|
||||
for (unsigned int j=sindex; j< (sindex+rsize) ; j++)
|
||||
@ -1138,8 +1122,6 @@ int AddressRange::reserve_addr_by_index(int pvid, int vid, unsigned int rsize,
|
||||
|
||||
rar->from_vattr(new_ar, errmsg);
|
||||
|
||||
new_ar->replace("PARENT_NETWORK_ID", pvid);
|
||||
|
||||
new_ar->replace("PARENT_NETWORK_AR_ID",id);
|
||||
|
||||
return 0;
|
||||
@ -1148,7 +1130,7 @@ int AddressRange::reserve_addr_by_index(int pvid, int vid, unsigned int rsize,
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int AddressRange::reserve_addr_by_ip(int pvid, int vid, unsigned int rsize,
|
||||
int AddressRange::reserve_addr_by_ip(int vid, unsigned int rsize,
|
||||
const string& ip_s, AddressRange *rar)
|
||||
{
|
||||
if (!(type & 0x00000002))//Not of type IP4 or IP4_6
|
||||
@ -1175,13 +1157,13 @@ int AddressRange::reserve_addr_by_ip(int pvid, int vid, unsigned int rsize,
|
||||
return -1;
|
||||
}
|
||||
|
||||
return reserve_addr_by_index(pvid, vid, rsize, sindex, rar);
|
||||
return reserve_addr_by_index(vid, rsize, sindex, rar);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int AddressRange::reserve_addr_by_mac(int pvid, int vid, unsigned int rsize,
|
||||
int AddressRange::reserve_addr_by_mac(int vid, unsigned int rsize,
|
||||
const string& mac_s, AddressRange *rar)
|
||||
{
|
||||
unsigned int mac_i[2];
|
||||
@ -1203,7 +1185,7 @@ int AddressRange::reserve_addr_by_mac(int pvid, int vid, unsigned int rsize,
|
||||
return -1;
|
||||
}
|
||||
|
||||
return reserve_addr_by_index(pvid, vid, rsize, sindex, rar);
|
||||
return reserve_addr_by_index(vid, rsize, sindex, rar);
|
||||
}
|
||||
|
||||
/* ************************************************************************** */
|
||||
|
@ -499,7 +499,7 @@ int AddressRangePool::hold_by_mac(const string& mac_s)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int AddressRangePool::reserve_addr(int pvid, int vid, unsigned int rsize,
|
||||
int AddressRangePool::reserve_addr(int vid, unsigned int rsize,
|
||||
AddressRange *rar)
|
||||
{
|
||||
map<unsigned int, AddressRange *>::iterator it;
|
||||
@ -507,7 +507,7 @@ int AddressRangePool::reserve_addr(int pvid, int vid, unsigned int rsize,
|
||||
for (it=ar_pool.begin(); it!=ar_pool.end(); it++)
|
||||
{
|
||||
if ((it->second->get_free_addr() >= rsize) &&
|
||||
(it->second->reserve_addr(pvid, vid, rsize, rar) == 0))
|
||||
(it->second->reserve_addr(vid, rsize, rar) == 0))
|
||||
{
|
||||
used_addr += rsize;
|
||||
return 0;
|
||||
@ -520,7 +520,7 @@ int AddressRangePool::reserve_addr(int pvid, int vid, unsigned int rsize,
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int AddressRangePool::reserve_addr(int pvid, int vid, unsigned int rsize,
|
||||
int AddressRangePool::reserve_addr(int vid, unsigned int rsize,
|
||||
unsigned int ar_id, AddressRange *rar)
|
||||
{
|
||||
map<unsigned int, AddressRange *>::iterator it;
|
||||
@ -533,7 +533,7 @@ int AddressRangePool::reserve_addr(int pvid, int vid, unsigned int rsize,
|
||||
}
|
||||
|
||||
if ((it->second->get_free_addr() >= rsize) &&
|
||||
(it->second->reserve_addr(pvid, vid, rsize, rar) == 0))
|
||||
(it->second->reserve_addr(vid, rsize, rar) == 0))
|
||||
{
|
||||
used_addr += rsize;
|
||||
return 0;
|
||||
@ -545,7 +545,7 @@ int AddressRangePool::reserve_addr(int pvid, int vid, unsigned int rsize,
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int AddressRangePool::reserve_addr_by_ip(int pvid, int vid, unsigned int rsize,
|
||||
int AddressRangePool::reserve_addr_by_ip(int vid, unsigned int rsize,
|
||||
unsigned int ar_id, const string& ip, AddressRange *rar)
|
||||
{
|
||||
map<unsigned int, AddressRange *>::iterator it;
|
||||
@ -557,7 +557,7 @@ int AddressRangePool::reserve_addr_by_ip(int pvid, int vid, unsigned int rsize,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (it->second->reserve_addr_by_ip(pvid, vid, rsize, ip, rar) == 0)
|
||||
if (it->second->reserve_addr_by_ip(vid, rsize, ip, rar) == 0)
|
||||
{
|
||||
used_addr += rsize;
|
||||
return 0;
|
||||
@ -569,7 +569,7 @@ int AddressRangePool::reserve_addr_by_ip(int pvid, int vid, unsigned int rsize,
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int AddressRangePool::reserve_addr_by_mac(int pvid, int vid, unsigned int rsize,
|
||||
int AddressRangePool::reserve_addr_by_mac(int vid, unsigned int rsize,
|
||||
unsigned int ar_id, const string& mac, AddressRange *rar)
|
||||
{
|
||||
map<unsigned int, AddressRange *>::iterator it;
|
||||
@ -581,7 +581,7 @@ int AddressRangePool::reserve_addr_by_mac(int pvid, int vid, unsigned int rsize,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (it->second->reserve_addr_by_mac(pvid, vid, rsize, mac, rar) == 0)
|
||||
if (it->second->reserve_addr_by_mac(vid, rsize, mac, rar) == 0)
|
||||
{
|
||||
used_addr += rsize;
|
||||
return 0;
|
||||
@ -592,23 +592,3 @@ int AddressRangePool::reserve_addr_by_mac(int pvid, int vid, unsigned int rsize,
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
unsigned int AddressRangePool::get_parents(vector<int>& parent_nets)
|
||||
{
|
||||
int vid;
|
||||
int num_parents = 0;
|
||||
|
||||
map<unsigned int, AddressRange *>::iterator it;
|
||||
|
||||
for (it=ar_pool.begin(); it!=ar_pool.end(); it++)
|
||||
{
|
||||
if ((it->second->get_attribute("PARENT_NETWORK_ID", vid) == 0) &&
|
||||
(vid >= 0))
|
||||
{
|
||||
parent_nets.push_back(vid);
|
||||
num_parents++;
|
||||
}
|
||||
}
|
||||
|
||||
return num_parents;
|
||||
}
|
||||
|
@ -38,12 +38,14 @@ VirtualNetwork::VirtualNetwork(int _uid,
|
||||
const string& _uname,
|
||||
const string& _gname,
|
||||
int _umask,
|
||||
int _pvid,
|
||||
int _cluster_id,
|
||||
const string& _cluster_name,
|
||||
VirtualNetworkTemplate * _vn_template):
|
||||
PoolObjectSQL(-1,NET,"",_uid,_gid,_uname,_gname,table),
|
||||
Clusterable(_cluster_id, _cluster_name),
|
||||
bridge("")
|
||||
bridge(""),
|
||||
parent_vid(_pvid)
|
||||
{
|
||||
if (_vn_template != 0)
|
||||
{
|
||||
@ -413,6 +415,15 @@ string& VirtualNetwork::to_xml_extended(string& xml, bool extended) const
|
||||
"<BRIDGE>" << bridge << "</BRIDGE>" <<
|
||||
"<VLAN>" << vlan << "</VLAN>";
|
||||
|
||||
if (parent_vid != -1)
|
||||
{
|
||||
os << "<PARENT_NETWORK_ID>" << parent_vid << "</PARENT_NETWORK_ID>";
|
||||
}
|
||||
else
|
||||
{
|
||||
os << "<PARENT_NETWORK_ID/>";
|
||||
}
|
||||
|
||||
if (!phydev.empty())
|
||||
{
|
||||
os << "<PHYDEV>" << phydev << "</PHYDEV>";
|
||||
@ -472,6 +483,7 @@ int VirtualNetwork::from_xml(const string &xml_str)
|
||||
|
||||
xpath(phydev, "/VNET/PHYDEV", "");
|
||||
xpath(vlan_id,"/VNET/VLAN_ID","");
|
||||
xpath(parent_vid,"/VNET/PARENT_NETWORK_ID",-1);
|
||||
|
||||
// Virtual Network template
|
||||
ObjectXML::get_nodes("/VNET/TEMPLATE", content);
|
||||
@ -811,7 +823,7 @@ int VirtualNetwork::reserve_addr(VirtualNetwork *rvnet,
|
||||
{
|
||||
AddressRange *rar = rvnet->allocate_ar();
|
||||
|
||||
if (ar_pool.reserve_addr(oid, rvnet->get_oid(), rsize, rar) != 0)
|
||||
if (ar_pool.reserve_addr(rvnet->get_oid(), rsize, rar) != 0)
|
||||
{
|
||||
error_str = "Not enough free addresses in an address range";
|
||||
|
||||
@ -840,7 +852,7 @@ int VirtualNetwork::reserve_addr(VirtualNetwork *rvnet,
|
||||
{
|
||||
AddressRange *rar = rvnet->allocate_ar();
|
||||
|
||||
if (ar_pool.reserve_addr(oid, rvnet->get_oid(), rsize, ar_id, rar) != 0)
|
||||
if (ar_pool.reserve_addr(rvnet->get_oid(), rsize, ar_id, rar) != 0)
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
@ -874,7 +886,7 @@ int VirtualNetwork::reserve_addr_by_ip(VirtualNetwork *rvnet,
|
||||
{
|
||||
AddressRange *rar = rvnet->allocate_ar();
|
||||
|
||||
if (ar_pool.reserve_addr_by_ip(oid,rvnet->get_oid(),rsize,ar_id,ip,rar)!=0)
|
||||
if (ar_pool.reserve_addr_by_ip(rvnet->get_oid(),rsize,ar_id,ip,rar)!=0)
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
@ -908,7 +920,7 @@ int VirtualNetwork::reserve_addr_by_mac(VirtualNetwork *rvnet,
|
||||
{
|
||||
AddressRange *rar = rvnet->allocate_ar();
|
||||
|
||||
if (ar_pool.reserve_addr_by_mac(oid,rvnet->get_oid(),rsize,ar_id,mac,rar)!=0)
|
||||
if (ar_pool.reserve_addr_by_mac(rvnet->get_oid(),rsize,ar_id,mac,rar)!=0)
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
|
@ -92,6 +92,7 @@ int VirtualNetworkPool::allocate (
|
||||
const string& uname,
|
||||
const string& gname,
|
||||
int umask,
|
||||
int pvid,
|
||||
VirtualNetworkTemplate * vn_template,
|
||||
int * oid,
|
||||
int cluster_id,
|
||||
@ -105,7 +106,7 @@ int VirtualNetworkPool::allocate (
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
vn = new VirtualNetwork(uid, gid, uname, gname, umask,
|
||||
vn = new VirtualNetwork(uid, gid, uname, gname, umask, pvid,
|
||||
cluster_id, cluster_name, vn_template);
|
||||
|
||||
// Check name
|
||||
|
Loading…
x
Reference in New Issue
Block a user