Skip to content

Commit

Permalink
F #2427: Code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmont committed Oct 3, 2018
1 parent 319c42a commit 5a839f1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
8 changes: 5 additions & 3 deletions src/rm/RequestManagerVirtualMachine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList,
int rc;
int uid, gid;
set<int> gids;
int has_net_mode, nic_id;
int nic_id;
string net_mode;

VirtualMachinePool * vmpool = static_cast<VirtualMachinePool *>(pool);
Expand Down Expand Up @@ -995,14 +995,16 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList,

for (vector<VectorAttribute*>::iterator it = vnics.begin(); it != vnics.end(); it++)
{
net_mode = "";

(*it)->vector_value("NIC_ID", nic_id);

nic = vm->get_nic(nic_id);

has_net_mode = (*it)->vector_value("NETWORK_MODE", net_mode);
net_mode = (*it)->vector_value("NETWORK_MODE");
one_util::toupper(net_mode);

if ( nic == 0 || ( has_net_mode != 0 ) || ( has_net_mode == 0 && net_mode != "AUTO" ) )
if ( nic == 0 || ( net_mode != "AUTO" ) )
{
att.resp_msg = "NIC_ID not found or not AUTO";
failure_response(NO_EXISTS, att);
Expand Down
10 changes: 4 additions & 6 deletions src/um/QuotaNetwork.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ bool QuotaNetwork::check(PoolObjectSQL::ObjectType otype, Template * tmpl,
{
vector<VectorAttribute*> nic;

string net_id;
int num;
bool uses_lease;
string net_mode;
int has_net_mode, has_net_id;
string net_mode = "", net_id = "";

map<string, float> net_request;

Expand All @@ -46,12 +44,12 @@ bool QuotaNetwork::check(PoolObjectSQL::ObjectType otype, Template * tmpl,

for (int i = 0 ; i < num ; i++)
{
has_net_mode = nic[i]->vector_value("NETWORK_MODE", net_mode);
net_mode = nic[i]->vector_value("NETWORK_MODE");
one_util::toupper(net_mode);

has_net_id = nic[i]->vector_value("NETWORK_ID", net_id);
net_id = nic[i]->vector_value("NETWORK_ID");

if ( has_net_mode == 0 && net_mode == "AUTO" && has_net_id != 0)
if ( net_mode == "AUTO" && net_id == "" )
{
continue;
}
Expand Down
8 changes: 3 additions & 5 deletions src/vm/VirtualMachineContext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ int VirtualMachine::generate_network_context(VectorAttribute* context,
{
bool net_context;
string net_mode = "";
int has_net_mode;
bool parse_vnets = false; //All nets are auto

context->vector_value("NETWORK", net_context);
Expand All @@ -312,13 +311,12 @@ int VirtualMachine::generate_network_context(VectorAttribute* context,

for(int i=0; i<num_vatts; i++)
{
has_net_mode = vatts[i]->vector_value("NETWORK_MODE", net_mode); // !0 = true
net_mode = vatts[i]->vector_value("NETWORK_MODE"); // !0 = true
one_util::toupper(net_mode);

if ( ( ( has_net_mode == 0 && net_mode != "AUTO" ) || has_net_mode != 0) ||
( only_auto && ( has_net_mode == 0 && net_mode == "AUTO" ) ) )
if ( ( net_mode != "AUTO" ) || ( only_auto && ( net_mode == "AUTO" ) ) )
{
if ( only_auto && ( ( has_net_mode == 0 && net_mode != "AUTO" ) || has_net_mode != 0) )
if ( only_auto && net_mode != "AUTO" )
{
continue;
}
Expand Down
11 changes: 4 additions & 7 deletions src/vm/VirtualMachineNic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,12 @@ void VirtualMachineNic::authorize(PoolObjectSQL::ObjectType ot, int uid,

set<int> sgroups;

int has_net_mode;
string net_mode = "";

has_net_mode = this->vector_value("NETWORK_MODE", net_mode);
net_mode = this->vector_value("NETWORK_MODE");
one_util::toupper(net_mode);

if ( has_net_mode && net_mode == "AUTO")
if ( net_mode == "AUTO" )
{
return;
}
Expand Down Expand Up @@ -198,7 +197,6 @@ int VirtualMachineNics::get_network_leases(int vm_id, int uid,
int nic_id, anic_id;
int has_nic_id;
string net_mode = "";
int has_net_mode;

VirtualMachineNic * nic;

Expand All @@ -215,7 +213,7 @@ int VirtualMachineNics::get_network_leases(int vm_id, int uid,
nic_id = anic_id;
}

has_net_mode = vnic->vector_value("NETWORK_MODE", net_mode); // !0 = true
net_mode = vnic->vector_value("NETWORK_MODE"); // !0 = true
one_util::toupper(net_mode);

if ( only_auto )
Expand All @@ -227,8 +225,7 @@ int VirtualMachineNics::get_network_leases(int vm_id, int uid,
nic = new VirtualMachineNic(vnic, nic_id);
}

if ( ( ( ( has_net_mode == 0 && net_mode != "AUTO" ) || has_net_mode != 0) && !only_auto ) ||
( only_auto && ( has_net_mode == 0 && net_mode == "AUTO" ) ) )
if ( ( net_mode != "AUTO" && !only_auto ) || ( only_auto && net_mode == "AUTO" ) )
{

if ( nic_default != 0 )
Expand Down

0 comments on commit 5a839f1

Please sign in to comment.