Skip to content

Commit

Permalink
F #2427: Added new class VirtualMachineNicXML
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmont committed Oct 5, 2018
1 parent 782a9b8 commit 125b95e
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 23 deletions.
85 changes: 74 additions & 11 deletions src/scheduler/include/VirtualMachineXML.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,59 @@ class ImageDatastorePoolXML;

using namespace std;

class VirtualMachineNicXML : public ObjectXML
{
public:

/**
* Returns a vector of matched datastores
*/
const vector<Resource *> get_match_networks()
{
return match_networks.get_resources();
}

/**
* Adds a matching network
* @param oid of the network
*/
void add_match_network(int oid)
{
match_networks.add_resource(oid);
}

/**
* Sort the matched networks for the VM
*/
void sort_match_networks()
{
match_networks.sort_resources();
}

/**
* Removes the matched networks
*/
void clear_match_networks()
{
match_networks.clear();
}

const string& get_nic_rank()
{
return nic_rank;
};

void add_nic_rank(string rank)
{
nic_rank = rank;
}

protected:
ResourceMatch match_networks;

string nic_rank;
};

class VirtualMachineXML : public ObjectXML
{
public:
Expand Down Expand Up @@ -106,6 +159,11 @@ class VirtualMachineXML : public ObjectXML
return ds_rank;
};

const string& get_nic_rank(int nic_id)
{
return nics[nic_id]->get_nic_rank();
};

const string& get_requirements()
{
return requirements;
Expand Down Expand Up @@ -215,7 +273,7 @@ class VirtualMachineXML : public ObjectXML
*/
void add_match_network(int oid, int nic_id)
{
match_networks[nic_id].add_resource(oid);
nics[nic_id]->add_match_network(oid);
}

/**
Expand All @@ -235,11 +293,19 @@ class VirtualMachineXML : public ObjectXML
}

/**
* Returns a vector of matched datastores
* Returns a vector of matched networks
*/
const vector<Resource *> get_match_networks(int nic_id)
{
return match_networks[nic_id].get_resources();
return nics[nic_id]->get_match_networks();
}

/**
* Returns a VirtualMachineNicXML
*/
VirtualMachineNicXML * get_nic(int nic_id)
{
return nics[nic_id];
}

/**
Expand All @@ -261,12 +327,9 @@ class VirtualMachineXML : public ObjectXML
/**
* Sort the matched networks for the VM
*/
void sort_match_networks()
void sort_match_networks(int nic_id)
{
for (map<int, ResourceMatch>::iterator it = match_networks.begin(); it != match_networks.end(); it++ )
{
it->second.sort_resources();
}
nics[nic_id]->sort_match_networks();
}

/**
Expand All @@ -290,9 +353,9 @@ class VirtualMachineXML : public ObjectXML
*/
void clear_match_networks()
{
for (map<int, ResourceMatch>::iterator it = match_networks.begin(); it != match_networks.end(); it++ )
for (map<int, VirtualMachineNicXML *>::iterator it = nics.begin(); it != nics.end(); it++ )
{
it->second.clear();
it->second->clear_match_networks();
}
}

Expand Down Expand Up @@ -432,7 +495,7 @@ class VirtualMachineXML : public ObjectXML

ResourceMatch match_datastores;

map<int, ResourceMatch> match_networks;
map<int, VirtualMachineNicXML *> nics;

bool only_public_cloud;

Expand Down
15 changes: 9 additions & 6 deletions src/scheduler/include/VirtualNetworkXML.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,17 @@ class VirtualNetworkXML : public ObjectXML

/**
* Adds a new lease to the VNET
* @param num_leases leases needed by the VM
* @return 0 on success
*/
void add_leases(int ar, int num_leases)
void add_lease()
{
free_leases -= num_leases;
free_leases --;
};

void rollback_leases(int num_leases)
{
free_leases += num_leases;
}

int get_oid() const
{
return oid;
Expand Down Expand Up @@ -109,9 +112,9 @@ class VirtualNetworkXML : public ObjectXML

int free_leases;

static const char *ds_paths[]; /**< paths for search function */
static const char *net_paths[]; /**< paths for search function */

static int ds_num_paths; /**< number of paths*/
static int net_num_paths; /**< number of paths*/

void init_attributes();
};
Expand Down
17 changes: 15 additions & 2 deletions src/scheduler/src/pool/VirtualMachineXML.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,23 @@ void VirtualMachineXML::init_attributes()

vector<string> nics_ids;
vector<string> nics_requirement;
vector<string> nics_rank;

xpaths(nics_ids,"/VM/TEMPLATE/NIC[NETWORK_MODE=\"auto\"]/NIC_ID");
xpaths(nics_requirement,"/VM/TEMPLATE/NIC[NETWORK_MODE=\"auto\"]/REQUIREMENTS");
xpaths(nics_requirement,"/VM/TEMPLATE/NIC[NETWORK_MODE=\"auto\"]/SCHED_REQUIREMENTS");
xpaths(nics_rank,"/VM/TEMPLATE/NIC[NETWORK_MODE=\"auto\"]/SCHED_RANK");

int nic_id;
string requirements;
string rank;

for (size_t i = 0; i < nics_ids.size(); i++)
{
nic_id = atoi(nics_ids[i].c_str());

nics_ids_auto.insert(nic_id);

nics[nic_id] = new VirtualMachineNicXML();
}

for (size_t i = 0; i < nics_ids.size() && i < nics_requirement.size(); i++)
Expand All @@ -125,6 +130,14 @@ void VirtualMachineXML::init_attributes()
nic_requirements[nic_id] = requirements;
}

for (size_t i = 0; i < nics_ids.size() && i < nics_rank.size(); i++)
{
nic_id = atoi(nics_ids[i].c_str());
rank = nics_rank[i];

nics[nic_id]->add_nic_rank(rank);
}

// ---------------- HISTORY HID, DSID, RESCHED & TEMPLATE ------------------

xpath(hid, "/VM/HISTORY_RECORDS/HISTORY/HID", -1);
Expand Down Expand Up @@ -235,7 +248,7 @@ ostream& operator<<(ostream& os, VirtualMachineXML& vm)
os << "\tPRI\tID - NETWORKS"<< endl
<< "\t------------------------" << endl;

const vector<Resource *> net_resources = vm.match_networks[*it].get_resources();
const vector<Resource *> net_resources = vm.nics[*it]->get_match_networks();

for (i = net_resources.rbegin(); i != net_resources.rend() ; i++)
{
Expand Down
8 changes: 4 additions & 4 deletions src/scheduler/src/pool/VirtualNetworkXML.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

int VirtualNetworkXML::ds_num_paths = 2;
int VirtualNetworkXML::net_num_paths = 2;

const char * VirtualNetworkXML::ds_paths[] = {
const char * VirtualNetworkXML::net_paths[] = {
"/VNET/TEMPLATE/",
"/VNET/"
};
Expand Down Expand Up @@ -85,8 +85,8 @@ void VirtualNetworkXML::init_attributes()

free_leases -= used_leases;

ObjectXML::paths = ds_paths;
ObjectXML::num_paths = ds_num_paths;
ObjectXML::paths = net_paths;
ObjectXML::num_paths = net_num_paths;
}

/* -------------------------------------------------------------------------- */
Expand Down

0 comments on commit 125b95e

Please sign in to comment.