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

F #6103: More CppCheck issues solved (#2477)

This commit is contained in:
Pavel Czerný 2023-02-02 12:48:43 +01:00 committed by GitHub
parent b941e62d02
commit 3fd059c543
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
41 changed files with 275 additions and 244 deletions

View File

@ -106,11 +106,11 @@ public:
* -2 if the rule is malformed,
* -3 if the DB insert failed
*/
virtual int add_rule(long long user,
long long resource,
long long rights,
long long zone,
std::string& error_str);
int add_rule(long long user,
long long resource,
long long rights,
long long zone,
std::string& error_str);
/**
* Deletes a rule from the ACL rule set
*
@ -118,7 +118,7 @@ public:
* @param error_str Returns the error reason, if any
* @return 0 on success
*/
virtual int del_rule(int oid, std::string& error_str);
int del_rule(int oid, std::string& error_str);
/**
* Deletes a new rule from the ACL rule set
@ -131,11 +131,11 @@ public:
* @param error_str Returns the error reason, if any
* @return 0 on success
*/
virtual int del_rule(long long user,
long long resource,
long long rights,
long long zone,
std::string& error_str);
int del_rule(long long user,
long long resource,
long long rights,
long long zone,
std::string& error_str);
/**
* Deletes rules that apply to this user id
@ -212,7 +212,7 @@ public:
* @param oss The output stream to dump the rule set contents
* @return 0 on success
*/
virtual int dump(std::ostringstream& oss);
int dump(std::ostringstream& oss);
protected:
/**

View File

@ -753,7 +753,7 @@ private:
/**
* The type of addresses defined in the range
*/
AddressType type;
AddressType type = NONE;
/**
* ID for this range, unique within the Virtual Network
@ -763,12 +763,12 @@ private:
/**
* Number of addresses in the range
*/
unsigned long int size;
unsigned long int size = 0;
/**
* First IP4 in the range
*/
unsigned int ip;
unsigned int ip = 0;
/**
* First MAC in the range
@ -809,7 +809,7 @@ private:
* The Address Range attributes as a Template VectorAttribute. This is
* used to generate XML or a template representation of the AR.
*/
VectorAttribute * attr;
VectorAttribute * attr = nullptr;
/* ---------------------------------------------------------------------- */
/* Restricted Attributes */

View File

@ -36,10 +36,11 @@ public:
AuthManager(
time_t timer,
const std::string& mads_location):
DriverManager(mads_location),
Listener("Authorization Manager"),
timer_thread(timer, [this](){timer_action();})
const std::string& mads_location)
: DriverManager(mads_location)
, Listener("Authorization Manager")
, timer_thread(timer, [this](){timer_action();})
, authz_enabled(false)
{
}

View File

@ -420,13 +420,13 @@ private:
* related to the DS defined in DS_MAD_CONF specified in the Datastore
* template
*/
int set_ds_mad(std::string &ds_mad, std::string &error_str);
int set_ds_mad(const std::string &ds_mad, std::string &error_str);
/**
* Verify the proper definition of the TM_MAD by checking the attributes
* related to the TM defined in TM_MAD_CONF
*/
int set_tm_mad(std::string &tm_mad, std::string &error_str);
int set_tm_mad(const std::string &tm_mad, std::string &error_str);
/**
* Child classes can process the new template set with replace_template or

View File

@ -49,7 +49,6 @@ public:
: cmd(c)
, arg(a)
, concurrency(ct)
, pid(-1)
{}
~Driver()
@ -129,12 +128,12 @@ private:
/**
* Communication pipe file descriptor (daemon <- driver)
*/
int from_drv;
int from_drv = -1;
/**
* Communication pipe file descriptor (daemon -> driver)
*/
int to_drv;
int to_drv = -1;
/**
* Driver configuration: path and arguments
@ -143,12 +142,12 @@ private:
std::string arg;
int concurrency;
int concurrency = 0;
/**
* Process ID of the driver
*/
pid_t pid;
pid_t pid = -1;
/**
* Class to read lines from the stream

View File

@ -50,14 +50,19 @@
class HostShareNode : public Template
{
public:
HostShareNode() : Template(false, '=', "NODE"){};
HostShareNode()
: Template(false, '=', "NODE")
, node_id(std::numeric_limits<unsigned int>::max())
{}
HostShareNode(unsigned int i) : Template(false, '=', "NODE"), node_id(i)
HostShareNode(unsigned int i)
: Template(false, '=', "NODE")
, node_id(i)
{
replace("NODE_ID", i);
};
}
virtual ~HostShareNode(){};
virtual ~HostShareNode() = default;
/**
* Builds the node from its XML representation. This function is used when

View File

@ -53,7 +53,7 @@ public:
virtual ~HostSharePCI()
{
clear();
HostSharePCI::clear();
};
/**

View File

@ -127,6 +127,8 @@ public:
if ( new_ar == 0 )
{
error = "AR not found in IPAM driver response";
return -1;
}
vattr->replace(new_ar->value());
@ -148,6 +150,8 @@ public:
if ( addr == 0 )
{
error = "ADDRESS not found in IPAM driver response";
return -1;
}
ip = addr->vector_value("IP");

View File

@ -597,30 +597,36 @@ public:
//Constructors and = are private to only access the class through instance
// -----------------------------------------------------------------------
Nebula():nebula_configuration(0),
default_user_quota( "DEFAULT_USER_QUOTAS",
"/DEFAULT_USER_QUOTAS/DATASTORE_QUOTA",
"/DEFAULT_USER_QUOTAS/NETWORK_QUOTA",
"/DEFAULT_USER_QUOTAS/IMAGE_QUOTA",
"/DEFAULT_USER_QUOTAS/VM_QUOTA"),
default_group_quota("DEFAULT_GROUP_QUOTAS",
"/DEFAULT_GROUP_QUOTAS/DATASTORE_QUOTA",
"/DEFAULT_GROUP_QUOTAS/NETWORK_QUOTA",
"/DEFAULT_GROUP_QUOTAS/IMAGE_QUOTA",
"/DEFAULT_GROUP_QUOTAS/VM_QUOTA"),
system_db(0), db_backend_type("sqlite"), logdb(0), fed_logdb(0),
vmpool(0), hpool(0), vnpool(0), upool(0), ipool(0), gpool(0), tpool(0),
dspool(0), clpool(0), docpool(0), zonepool(0), secgrouppool(0),
vdcpool(0), vrouterpool(0), marketpool(0), apppool(0), vmgrouppool(0),
vntpool(0), hkpool(0), lcm(0), vmm(0), im(0), tm(0), dm(0), rm(0), hm(0),
hl(0), authm(0), aclm(0), imagem(0), marketm(0), ipamm(0), raftm(0), frm(0)
Nebula()
: nebula_configuration(0)
, federation_enabled(false)
, federation_master(false)
, cache(false)
, zone_id(0)
, server_id(-1)
, default_user_quota( "DEFAULT_USER_QUOTAS",
"/DEFAULT_USER_QUOTAS/DATASTORE_QUOTA",
"/DEFAULT_USER_QUOTAS/NETWORK_QUOTA",
"/DEFAULT_USER_QUOTAS/IMAGE_QUOTA",
"/DEFAULT_USER_QUOTAS/VM_QUOTA")
, default_group_quota("DEFAULT_GROUP_QUOTAS",
"/DEFAULT_GROUP_QUOTAS/DATASTORE_QUOTA",
"/DEFAULT_GROUP_QUOTAS/NETWORK_QUOTA",
"/DEFAULT_GROUP_QUOTAS/IMAGE_QUOTA",
"/DEFAULT_GROUP_QUOTAS/VM_QUOTA")
, system_db(0), db_backend_type("sqlite"), logdb(0), fed_logdb(0)
, vmpool(0), hpool(0), vnpool(0), upool(0), ipool(0), gpool(0), tpool(0)
, dspool(0), clpool(0), docpool(0), zonepool(0), secgrouppool(0)
, vdcpool(0), vrouterpool(0), marketpool(0), apppool(0), vmgrouppool(0)
, vntpool(0), hkpool(0), lcm(0), vmm(0), im(0), tm(0), dm(0), rm(0), hm(0)
, hl(0), authm(0), aclm(0), imagem(0), marketm(0), ipamm(0), raftm(0), frm(0)
{
};
~Nebula();
private:
Nebula& operator=(Nebula const&){return *this;};
Nebula& operator=(Nebula const&) = delete;
// ---------------------------------------------------------------
// Environment variables

View File

@ -37,7 +37,12 @@ public:
// ---------------------- Constructors ------------------------------------
ObjectXML():xml(0), ctx(0) {}
ObjectXML()
: paths(nullptr)
, num_paths(0)
, xml(nullptr)
, ctx(nullptr)
{}
/**
* Constructs an object using a XML document

View File

@ -30,23 +30,25 @@ class PoolObjectAuth
public:
/* ------------------- Constructor and Methods -------------------------- */
PoolObjectAuth():
oid(-1),
uid(-1),
gid(-1),
owner_u(1),
owner_m(1),
owner_a(0),
group_u(0),
group_m(0),
group_a(0),
other_u(0),
other_m(0),
other_a(0),
disable_all_acl(false),
disable_cluster_acl(false),
disable_group_acl(false),
locked(0) {};
PoolObjectAuth()
: obj_type(PoolObjectSQL::NONE)
, oid(-1)
, uid(-1)
, gid(-1)
, owner_u(1)
, owner_m(1)
, owner_a(0)
, group_u(0)
, group_m(0)
, group_a(0)
, other_u(0)
, other_m(0)
, other_a(0)
, disable_all_acl(false)
, disable_cluster_acl(false)
, disable_group_acl(false)
, locked(0)
{}
void get_acl_rules(AclRule& owner_rule,
AclRule& group_rule,

View File

@ -63,10 +63,16 @@ public:
bool success; /**< True if the call was successfull false otherwise */
RequestAttributes(AuthRequest::Operation api_auth_op)
: resp_obj(PoolObjectSQL::NONE)
: uid(-1)
, gid(-1)
, req_id(-1)
, umask(0)
, retval(nullptr)
, resp_obj(PoolObjectSQL::NONE)
, resp_id(-1)
, replication_idx(UINT64_MAX)
, auth_op(api_auth_op)
, success(false)
{}
RequestAttributes(const RequestAttributes& ra) = default;
@ -89,6 +95,7 @@ public:
, resp_msg()
, replication_idx(UINT64_MAX)
, auth_op(ra.auth_op)
, success(ra.success)
{}
bool is_admin() const
@ -257,7 +264,7 @@ protected:
// Configuration for authentication level of the API call
PoolObjectSQL::ObjectType auth_object = PoolObjectSQL::ObjectType::NONE;
AuthRequest::Operation auth_op;
AuthRequest::Operation auth_op = AuthRequest::NONE;
VMActions::Action vm_action;

View File

@ -113,7 +113,7 @@ private:
std::condition_variable _cond;
int _concurrency;
int _concurrency = 0;
std::map<typename MSG::msg_enum, callback_t > actions;

View File

@ -81,7 +81,9 @@ public:
* attributes
* @param tmpl template with SERVER
*/
ZoneServers(Template * tmpl):ExtendedAttributeSet(false), next_id(-1)
ZoneServers(Template * tmpl)
: ExtendedAttributeSet(false)
, next_id(-1)
{
std::vector<VectorAttribute *> vas;
@ -109,9 +111,12 @@ public:
/**
* Creates an empty zone server set
*/
ZoneServers():ExtendedAttributeSet(false){};
ZoneServers()
: ExtendedAttributeSet(false)
, next_id(-1)
{}
virtual ~ZoneServers(){};
virtual ~ZoneServers() = default;
/* ---------------------------------------------------------------------- */
/* Iterators */

View File

@ -1,9 +1,60 @@
<suppressions>
<!--
<!-- Global suppression, issues which we don't want to solve -->
<suppress>
<id>variableScope</id>
<fileName>*</fileName>
</suppress>
<suppress>
<id>noExplicitConstructor</id>
<fileName>*</fileName>
</suppress>
<suppress>
<id>missingInclude</id>
<fileName>*</fileName>
</suppress>
<suppress>
<id>danglingLifetime</id>
<fileName>*</fileName>
</suppress>
<suppress>
<id>shadowFunction</id>
<fileName>*</fileName>
</suppress>
<!-- Suppresions specific per file, false positives -->
<suppress>
<id>containerOutOfBounds</id>
<fileName>src/hm/HookLog.cc</fileName>
<symbolName>query_output</symbolName>
</suppress>
<suppress>
<id>ctuuninitvar</id>
<fileName>src/sql/LogDB.cc</fileName>
</suppress>
<suppress>
<id>knownConditionTrueFalse</id>
<fileName>src/raft/ReplicaThread.cc</fileName>
</suppress>
<suppress>
<id>knownConditionTrueFalse</id>
<fileName>src/vmm/LibVirtDriverKVM.cc</fileName>
</suppress>
<suppress>
<id>knownConditionTrueFalse</id>
<fileName>src/sql/LogDB.cc</fileName>
</suppress>
<suppress>
<id>knownConditionTrueFalse</id>
<fileName>src/monitor/src/data_model/VMRPCPool.cc</fileName>
</suppress>
<suppress>
<id>nullPointer</id>
<fileName>src/scheduler/include/Scheduler.h</fileName>
</suppress>
<suppress>
<id>uninitMemberVar</id>
<fileName>include/Callbackable.h</fileName>
</suppress>
<!-- Temporary suppressions, we may want to solve them in the future -->
<suppress>
<id>unusedVariable</id>
<fileName>*</fileName>
@ -12,10 +63,6 @@
<id>noConstructor</id>
<fileName>*</fileName>
</suppress>
<suppress>
<id>noExplicitConstructor</id>
<fileName>*</fileName>
</suppress>
<suppress>
<id>constVariable</id>
<fileName>*</fileName>
@ -32,23 +79,13 @@
<id>unreadVariable</id>
<fileName>*</fileName>
</suppress>
-->
<suppress>
<id>missingInclude</id>
<id>constParameter</id>
<fileName>*</fileName>
</suppress>
<suppress>
<id>danglingLifetime</id>
<id>useStlAlgorithm</id>
<fileName>*</fileName>
</suppress>
<suppress>
<id>containerOutOfBounds</id>
<fileName>src/hm/HookLog.cc</fileName>
<symbolName>query_output</symbolName>
</suppress>
<suppress>
<id>ctuuninitvar</id>
<fileName>src/sql/LogDB.cc</fileName>
</suppress>
</suppressions>

View File

@ -14,10 +14,10 @@
# To disable specific error messages use cppcheck-suppressions.xml file
SOURCES="src"
INCLUDES="-I include"
INCLUDES="-I include -I src/monitor/include -I src/scheduler/include"
DEFINES="-DSQLITE_DB -DMYSQL_DB -DPOSTGRESQL_DB -DSYSTEMD"
ENABLE="--enable=performance,information"
IGNORE="-i .xmlrpc_test/ -i src/sunstone/ -i src/svncterm_server/ -i src/fireedge"
ENABLE="--enable=performance,information,warning,portability,style"
IGNORE="-i .xmlrpc_test/ -i src/sunstone/ -i src/svncterm_server/ -i src/fireedge -i src/parsers"
SUPRESS="--suppress-xml=share/smoke_tests/config/cppcheck-suppressions.xml"
OTHERS="--std=c++14 --error-exitcode=2 -q"

View File

@ -312,7 +312,7 @@ static int check_tm_target_type(string& tm_tt)
/* -------------------------------------------------------------------------- */
int Datastore::set_ds_mad(std::string &mad, std::string &error_str)
int Datastore::set_ds_mad(const std::string &mad, std::string &error_str)
{
const VectorAttribute* vatt;
std::vector <std::string> vrequired_attrs;
@ -371,7 +371,7 @@ error_common:
/* -------------------------------------------------------------------------- */
int Datastore::set_tm_mad(string &tm_mad, string &error_str)
int Datastore::set_tm_mad(const string &tm_mad, string &error_str)
{
const VectorAttribute* vatt;
@ -437,35 +437,35 @@ int Datastore::set_tm_mad(string &tm_mad, string &error_str)
for (const auto &mode : modes)
{
string tm_mad = one_util::trim(mode);
one_util::toupper(tm_mad);
string tm = one_util::trim(mode);
one_util::toupper(tm);
st = vatt->vector_value("LN_TARGET_" + tm_mad);
st = vatt->vector_value("LN_TARGET_" + tm);
if (check_tm_target_type(st) == -1)
{
goto error;
}
replace_template_attribute("LN_TARGET_" + tm_mad, st);
replace_template_attribute("LN_TARGET_" + tm, st);
st = vatt->vector_value("CLONE_TARGET_" + tm_mad);
st = vatt->vector_value("CLONE_TARGET_" + tm);
if (check_tm_target_type(st) == -1)
{
goto error;
}
replace_template_attribute("CLONE_TARGET_" + tm_mad, st);
replace_template_attribute("CLONE_TARGET_" + tm, st);
st = vatt->vector_value("DISK_TYPE_" + tm_mad);
st = vatt->vector_value("DISK_TYPE_" + tm);
if (st.empty())
{
goto error;
}
replace_template_attribute("DISK_TYPE_" + tm_mad, st);
replace_template_attribute("DISK_TYPE_" + tm, st);
}
}

View File

@ -50,7 +50,7 @@ ExecuteHook::ExecuteHook(const std::string& _name, const std::string& _cmd,
c_args[i] = nullptr;
}
for (int i=1; iss >> args[i] && i < EXECUTE_HOOK_MAX_ARG - 1; ++i)
for (int i=1; i < EXECUTE_HOOK_MAX_ARG && iss >> args[i]; ++i)
{
c_args[i] = args[i].c_str();
}

View File

@ -578,7 +578,7 @@ int Host::post_update_template(string& error)
im_mad_name = new_im_mad;
}
if (!new_im_mad.empty())
if (!new_vm_mad.empty())
{
vmm_mad_name = new_vm_mad;
}

View File

@ -246,7 +246,7 @@ void HostShare::update_capacity(Template& ht, string& rcpu, string& rmem)
if ( ht.get("VMS_THREAD", vthread) )
{
if ( vthread <= 0 )
if ( vthread == 0 )
{
vthread = 1;

View File

@ -104,7 +104,7 @@ int VirtualMachineBase::init_attributes()
}
else
{
vm_template = 0;
vm_template = nullptr;
}
nodes.clear();
@ -116,21 +116,21 @@ int VirtualMachineBase::init_attributes()
user_template->from_xml_node(nodes[0]);
free_nodes(nodes);
public_cloud = (user_template->get("PUBLIC_CLOUD", attrs) > 0);
if (public_cloud == false)
{
attrs.clear();
public_cloud = (user_template->get("EC2", attrs) > 0);
}
}
else
{
user_template = 0;
user_template = nullptr;
}
public_cloud = (user_template->get("PUBLIC_CLOUD", attrs) > 0);
if (public_cloud == false)
{
attrs.clear();
public_cloud = (user_template->get("EC2", attrs) > 0);
}
if (vm_template != 0)
if (vm_template != nullptr)
{
init_storage_usage();
}
@ -200,10 +200,7 @@ void VirtualMachineBase::init_storage_usage()
continue;
}
if (ds_usage.count(ds_id) == 0)
{
ds_usage[ds_id] = 0;
}
ds_usage.emplace(ds_id, 0); // no-op if element already exists
if (disk->vector_value("CLONE", clone) != 0)
{

View File

@ -45,7 +45,10 @@ HostMonitorManager::HostMonitorManager(
const std::string& driver_path,
int timer_period,
int monitor_interval_host)
: hpool(hp)
: driver_manager(make_unique<driver_manager_t>(driver_path))
, udp_driver(make_unique<UDPMonitorDriver>(addr, port))
, tcp_driver(make_unique<TCPMonitorDriver>(addr, port))
, hpool(hp)
, vmpool(vmp)
, threads(_threads)
, timer_period(timer_period)
@ -53,10 +56,7 @@ HostMonitorManager::HostMonitorManager(
, is_leader(false)
{
oned_driver = make_unique<OneMonitorDriver>(this);
udp_driver = make_unique<UDPMonitorDriver>(addr, port);
tcp_driver = make_unique<TCPMonitorDriver>(addr, port);
driver_manager = make_unique<driver_manager_t>(driver_path);
};
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -284,18 +284,15 @@ void Nebula::start(bool bootstrap_only)
// -----------------------------------------------------------
const VectorAttribute * vatt = nebula_configuration->get("FEDERATION");
federation_enabled = false;
federation_master = false;
cache = false;
zone_id = 0;
server_id = -1;
master_oned = vatt->vector_value("MASTER_ONED");
string mode = vatt->vector_value("MODE");
one_util::toupper(mode);
string mode = "STANDALONE";
if (vatt != 0)
{
master_oned = vatt->vector_value("MASTER_ONED");
mode = vatt->vector_value("MODE");
one_util::toupper(mode);
if (mode == "STANDALONE")
{
federation_enabled = false;

View File

@ -175,7 +175,6 @@ void RequestManagerAllocate::request_execute(xmlrpc_c::paramList const& params,
int rc, id;
int cluster_id = ClusterPool::NONE_CLUSTER_ID;
string cluster_name = ClusterPool::NONE_CLUSTER_NAME;
PoolObjectAuth cluster_perms;
@ -195,7 +194,7 @@ void RequestManagerAllocate::request_execute(xmlrpc_c::paramList const& params,
}
}
cluster_id = get_cluster_id(params);
int cluster_id = get_cluster_id(params);
if ( cluster_id != ClusterPool::NONE_CLUSTER_ID )
{

View File

@ -848,11 +848,12 @@ int MarketPlaceDelete::drop(std::unique_ptr<PoolObjectSQL> object, bool r, Reque
{
unique_ptr<MarketPlace> mp(static_cast<MarketPlace *>(object.release()));
bool can_del = mp->is_public() || apps.empty();
apps = mp->get_marketapp_ids();
mp_id = mp->get_oid();
bool can_del = mp->is_public() || apps.empty();
if (!can_del)
{
std::ostringstream oss;

View File

@ -57,7 +57,7 @@ void GroupSetQuota::
return;
}
group->quota.set(&quota_tmpl, att.resp_msg);
rc = group->quota.set(&quota_tmpl, att.resp_msg);
static_cast<GroupPool *>(pool)->update_quotas(group.get());

View File

@ -39,30 +39,18 @@ public:
private:
/* ---------------------------------------------------------------------- */
/* Re-implement DB public functions not used in scheduler */
/* Disable public methods not used in scheduler */
/* ---------------------------------------------------------------------- */
int start()
{
return -1;
}
int start() = delete;
int add_rule(long long user,
long long resource,
long long rights,
std::string& error_str)
{
return -1;
};
std::string& error_str) = delete;
int del_rule(int oid, std::string& error_str)
{
return -1;
};
int del_rule(int oid, std::string& error_str) = delete;
int dump(std::ostringstream& oss)
{
return -1;
};
int dump(std::ostringstream& oss) = delete;
Client * client;

View File

@ -84,10 +84,7 @@ public:
*/
bool test_ds_capacity(int dsid, long long vm_disk_mb)
{
if (ds_free_disk.count(dsid) == 0)
{
ds_free_disk[dsid] = free_disk;
}
ds_free_disk.emplace(dsid, free_disk);
return (vm_disk_mb < ds_free_disk[dsid]);
}
@ -100,10 +97,7 @@ public:
*/
void add_ds_capacity(int dsid, long long vm_disk_mb)
{
if (ds_free_disk.count(dsid) == 0)
{
ds_free_disk[dsid] = free_disk;
}
ds_free_disk.emplace(dsid, free_disk);
ds_free_disk[dsid] -= vm_disk_mb;
}
@ -117,19 +111,19 @@ private:
friend class HostXML;
// Host computing capacity and usage
long long mem_usage;
long long cpu_usage;
long long mem_usage = 0;
long long cpu_usage = 0;
long long max_mem;
long long max_cpu;
long long max_mem = 0;
long long max_cpu = 0;
long long running_vms;
long long running_vms = 0;
// PCI devices
HostSharePCI pci;
// System datastore
long long free_disk;
long long free_disk = 0;
std::map<int, long long> ds_free_disk;
//Numa Nodes

View File

@ -90,7 +90,7 @@ public:
get_suitable_nodes(nodes);
for (unsigned int i=0 ;
i < nodes.size() && ( pool_limit <= 0 || i < pool_limit ) ;
i < nodes.size() && ( pool_limit == 0 || i < pool_limit ) ;
i++)
{
add_object(nodes[i]);

View File

@ -78,6 +78,7 @@ protected:
machines_limit(0),
dispatch_limit(0),
host_dispatch_limit(0),
zone_id(0),
mem_ds_scale(0),
diff_vnets(false)
{

View File

@ -115,7 +115,7 @@ private:
float weight;
float max;
float max = 0;
} sw;
};

View File

@ -187,7 +187,7 @@ protected:
oss << "/VM_POOL/VM/TEMPLATE/SCHED_ACTION[(TIME < " << time(0)
<< " and (not(DONE > 0) or boolean(REPEAT))) or ( TIME[starts-with(text(),\"+\")] and not(DONE>0) ) ]/../..";
return get_nodes(oss.str().c_str(), content);
return get_nodes(oss.str(), content);
}
};
@ -220,7 +220,7 @@ protected:
oss << "/VM_POOL/VM[TEMPLATE/VMGROUP/ROLE]";
return get_nodes(oss.str().c_str(), content);
return get_nodes(oss.str(), content);
}
};
#endif /* VM_POOL_XML_H_ */

View File

@ -226,20 +226,20 @@ void VirtualMachineXML::init_attributes()
user_template->from_xml_node(nodes[0]);
free_nodes(nodes);
public_cloud = (user_template->get("PUBLIC_CLOUD", attrs) > 0);
if (public_cloud == false)
{
attrs.clear();
public_cloud = (user_template->get("EC2", attrs) > 0);
}
}
else
{
user_template = 0;
}
public_cloud = (user_template->get("PUBLIC_CLOUD", attrs) > 0);
if (public_cloud == false)
{
attrs.clear();
public_cloud = (user_template->get("EC2", attrs) > 0);
}
only_public_cloud = false;
if (vm_template != 0)
@ -311,10 +311,7 @@ void VirtualMachineXML::init_storage_usage()
continue;
}
if (ds_usage.count(ds_id) == 0)
{
ds_usage[ds_id] = 0;
}
ds_usage.emplace(ds_id, 0);
if (disk->vector_value("CLONE", clone) != 0)
{
@ -453,7 +450,7 @@ bool VirtualMachineXML::test_image_datastore_capacity(
{
ostringstream oss;
oss << "Image Datastore " << ds->get_oid()
oss << "Image Datastore " << ds_it->first
<< " does not have enough capacity";
error_msg = oss.str();

View File

@ -1325,7 +1325,7 @@ void Scheduler::dispatch()
// Dispatch each VM till we reach the dispatch limit
//--------------------------------------------------------------------------
for (k = vm_rs.rbegin(); k != vm_rs.rend() &&
( dispatch_limit <= 0 || dispatched_vms < dispatch_limit ); ++k)
( dispatch_limit == 0 || dispatched_vms < dispatch_limit ); ++k)
{
dispatched = false;

View File

@ -531,7 +531,7 @@ Attribute * Template::vector_xml_att(const xmlNode * node)
attr = new VectorAttribute(
reinterpret_cast<const char *>(node->name));
for(child = child; child != 0; child = child->next)
for( ; child != 0; child = child->next)
{
grandchild = child->children;

View File

@ -399,9 +399,9 @@ int UserPool::allocate(
user = new User(-1, gid, uname, gname, upass, auth_driver, enabled);
// Add the primary and secondary groups to the collection
for (auto gid : gids)
for (auto group_id : gids)
{
user->add_group(gid);
user->add_group(group_id);
}
// Set a password for the OneGate tokens
@ -416,9 +416,9 @@ int UserPool::allocate(
}
// Add the user to the main and secondary groups
for (auto gid : gids)
for (auto group_id : gids)
{
auto group = gpool->get(gid);
auto group = gpool->get(group_id);
if (!group) //Secondary group no longer exists
{
@ -440,9 +440,9 @@ int UserPool::allocate(
if ( driver_managed_group_admin )
{
// Set the user group admin
for (auto gid : agids)
for (auto group_id : agids)
{
auto group = gpool->get(gid);
auto group = gpool->get(group_id);
if (!group) //Secondary group no longer exists
{
@ -483,9 +483,9 @@ error_group:
// Remove from all the groups, just in case the user id was added to a any
// of them before a non-existing group was found
for (auto gid : gids)
for (auto group_id : gids)
{
if ( auto group = gpool->get(gid) )
if ( auto group = gpool->get(group_id) )
{
group->del_user(*oid);

View File

@ -534,9 +534,9 @@ int ResourceSet::add(const set<int>& groups, int zone_id, int id,
}
}
for (auto id : del_ids)
for (auto del_id : del_ids)
{
this->del(groups, zone_id, id, error_aux);
this->del(groups, zone_id, del_id, error_aux);
}
}

View File

@ -2086,7 +2086,7 @@ string VirtualMachine::get_import_state() const
bool VirtualMachine::is_imported_action_supported(VMActions::Action action) const
{
string vmm_mad;
if (hasHistory())
{
vmm_mad = get_vmm_mad();
@ -2596,12 +2596,6 @@ int VirtualMachine::replace_template(
auto new_tmpl =
make_unique<VirtualMachineTemplate>(false,'=',"USER_TEMPLATE");
if ( new_tmpl == 0 )
{
error = "Cannot allocate a new template";
return -1;
}
if ( new_tmpl->parse_str_or_xml(tmpl_str, error) != 0 )
{
return -1;
@ -2655,12 +2649,6 @@ int VirtualMachine::append_template(
make_unique<VirtualMachineTemplate>(false,'=',"USER_TEMPLATE");
string rname;
if ( new_tmpl == 0 )
{
error = "Cannot allocate a new template";
return -1;
}
if ( new_tmpl->parse_str_or_xml(tmpl_str, error) != 0 )
{
return -1;
@ -2669,31 +2657,18 @@ int VirtualMachine::append_template(
/* ---------------------------------------------------------------------- */
/* Append new_tmpl to the current user_template */
/* ---------------------------------------------------------------------- */
// Create a copy of actual user template
auto old_user_tmpl = make_unique<VirtualMachineTemplate>(*user_obj_template);
if (user_obj_template != 0)
if (keep_restricted &&
new_tmpl->check_restricted(rname, user_obj_template.get()))
{
if (keep_restricted &&
new_tmpl->check_restricted(rname, user_obj_template.get()))
{
error ="User Template includes a restricted attribute " + rname;
error ="User Template includes a restricted attribute " + rname;
return -1;
}
user_obj_template->merge(new_tmpl.get());
return -1;
}
else
{
if (keep_restricted && new_tmpl->check_restricted(rname))
{
error ="User Template includes a restricted attribute " + rname;
return -1;
}
user_obj_template = move(new_tmpl);
}
user_obj_template->merge(new_tmpl.get());
if (post_update_template(error) == -1)
{
@ -3242,15 +3217,25 @@ int VirtualMachine::get_auto_network_leases(VirtualMachineTemplate * tmpl,
VirtualMachineNic * nic = get_nic(nic_id);
if (!nic)
{
std::ostringstream oss;
oss << "NIC_ID " << nic_id << " not found";
estr = oss.str();
return -1;
}
net_mode = nic->vector_value("NETWORK_MODE");
string network_id = nic->vector_value("NETWORK_ID");
if (nic == 0 || !one_util::icasecmp(net_mode, "AUTO") || !network_id.empty())
if (!one_util::icasecmp(net_mode, "AUTO") || !network_id.empty())
{
std::ostringstream oss;
oss << "NIC_ID "<< nic_id << " not found or not AUTO";
oss << "NIC_ID " << nic_id << " not AUTO";
estr = oss.str();
return -1;

View File

@ -946,7 +946,7 @@ int VirtualMachine::parse_topology(Template * tmpl, std::string &error)
(*it)->vector_value("TOTAL_CPUS", ncpu);
(*it)->vector_value("MEMORY", nmem);
if ( ncpu <= 0 || nmem <= 0)
if ( ncpu == 0 || nmem <= 0)
{
break;
}
@ -965,7 +965,7 @@ int VirtualMachine::parse_topology(Template * tmpl, std::string &error)
tmpl->erase("NUMA_NODE");
if (node_cpu != vcpu || node_mem != memory ||
ncpu <= 0 || nmem <= 0)
ncpu == 0 || nmem <= 0)
{
for (auto it = new_nodes.begin(); it != new_nodes.end(); ++it)
{
@ -973,7 +973,7 @@ int VirtualMachine::parse_topology(Template * tmpl, std::string &error)
}
}
if (ncpu <= 0)
if (ncpu == 0)
{
error = "A NUMA_NODE must have TOTAL_CPUS greater than 0";
return -1;

View File

@ -706,7 +706,7 @@ int VirtualMachinePool::calculate_showback(
std::string acct_str;
rc = dump_acct(acct_str, start_time, end_time, start_index, chunk_size);
dump_acct(acct_str, start_time, end_time, start_index, chunk_size);
start_index += chunk_size;
ObjectXML xml(acct_str);
@ -716,7 +716,7 @@ int VirtualMachinePool::calculate_showback(
//--------------------------------------------------------------------------
nodes.clear();
rc = xml.get_nodes("/HISTORY_RECORDS/HISTORY", nodes);
xml.get_nodes("/HISTORY_RECORDS/HISTORY", nodes);
for ( auto node : nodes )
{
@ -774,10 +774,7 @@ int VirtualMachinePool::calculate_showback(
if( (et > t || et == 0) &&
(st != 0 && st <= t_next) ) {
time_t stime = t;
if(st != 0){
stime = max(t, st);
}
time_t stime = max(t, st);
time_t etime = t_next;
if(et != 0){

View File

@ -31,7 +31,11 @@ using namespace std;
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
ObjectXML::ObjectXML(const std::string &xml_doc):paths(0),num_paths(0),xml(0),ctx(0)
ObjectXML::ObjectXML(const std::string &xml_doc)
: paths(nullptr)
, num_paths(0)
, xml(nullptr)
, ctx(nullptr)
{
try
{