mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-03 01:17:41 +03:00
F #4936: Refactor pools to use unique_ptr
co-authored-by: Pavel Czerný <pczerny@opennebula.systems>
This commit is contained in:
parent
ef17f77d26
commit
5ce49ed404
@ -29,6 +29,9 @@
|
||||
class Cluster : public PoolObjectSQL
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~Cluster() = default;
|
||||
|
||||
// *************************************************************************
|
||||
// Object Collections (Public)
|
||||
// *************************************************************************
|
||||
@ -101,6 +104,7 @@ private:
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
friend class ClusterPool;
|
||||
friend class PoolSQL;
|
||||
|
||||
// *************************************************************************
|
||||
// VNC Port management function
|
||||
@ -137,8 +141,6 @@ private:
|
||||
Cluster(int id, const std::string& name, ClusterTemplate* cl_template,
|
||||
const VectorAttribute& vnc_conf);
|
||||
|
||||
virtual ~Cluster() = default;
|
||||
|
||||
// *************************************************************************
|
||||
// Attributes (Private)
|
||||
// *************************************************************************
|
||||
|
@ -68,19 +68,15 @@ public:
|
||||
{
|
||||
int rc = -1;
|
||||
|
||||
Cluster * cluster = get(oid);
|
||||
|
||||
if ( cluster != 0 )
|
||||
if ( auto cluster = get(oid) )
|
||||
{
|
||||
rc = cluster->get_vnc_port(vm_id, port);
|
||||
|
||||
update_vnc_bitmap(cluster);
|
||||
|
||||
cluster->unlock();
|
||||
update_vnc_bitmap(cluster.get());
|
||||
}
|
||||
|
||||
return rc;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Release a previously allocated VNC port in the cluster
|
||||
@ -89,15 +85,11 @@ public:
|
||||
*/
|
||||
void release_vnc_port(int oid, unsigned int port)
|
||||
{
|
||||
Cluster * cluster = get(oid);
|
||||
|
||||
if ( cluster != 0 )
|
||||
if ( auto cluster = get(oid) )
|
||||
{
|
||||
cluster->release_vnc_port(port);
|
||||
|
||||
update_vnc_bitmap(cluster);
|
||||
|
||||
cluster->unlock();
|
||||
update_vnc_bitmap(cluster.get());
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,15 +104,11 @@ public:
|
||||
{
|
||||
int rc = -1;
|
||||
|
||||
Cluster * cluster = get(oid);
|
||||
|
||||
if ( cluster != 0 )
|
||||
if ( auto cluster = get(oid) )
|
||||
{
|
||||
rc = cluster->set_vnc_port(port);
|
||||
|
||||
update_vnc_bitmap(cluster);
|
||||
|
||||
cluster->unlock();
|
||||
update_vnc_bitmap(cluster.get());
|
||||
}
|
||||
|
||||
return rc;
|
||||
@ -142,28 +130,26 @@ public:
|
||||
int allocate(std::string name, int * oid, std::string& error_str);
|
||||
|
||||
/**
|
||||
* Function to get a cluster from the pool, if the object is not in memory
|
||||
* it is loaded from the DB
|
||||
* @param oid cluster unique id
|
||||
* @param lock locks the cluster mutex
|
||||
* @return a pointer to the cluster, 0 if the cluster could not be loaded
|
||||
* Gets an object from the pool (if needed the object is loaded from the
|
||||
* database). The object is locked, other threads can't access the same
|
||||
* object. The lock is released by destructor.
|
||||
* @param oid the Cluster unique identifier
|
||||
* @return a pointer to the Cluster, nullptr in case of failure
|
||||
*/
|
||||
Cluster * get(int oid)
|
||||
std::unique_ptr<Cluster> get(int oid)
|
||||
{
|
||||
return static_cast<Cluster *>(PoolSQL::get(oid));
|
||||
};
|
||||
return PoolSQL::get<Cluster>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get a read onlycluster from the pool, if the object is not
|
||||
* in memory it is loaded from the DB
|
||||
* @param oid cluster unique id
|
||||
*
|
||||
* @return a pointer to the cluster, 0 if the cluster could not be loaded
|
||||
* Gets a read only object from the pool (if needed the object is loaded from the
|
||||
* database). No object lock, other threads may work with the same object.
|
||||
* @param oid the Cluster unique identifier
|
||||
* @return a pointer to the Cluster, nullptr in case of failure
|
||||
*/
|
||||
|
||||
Cluster * get_ro(int oid)
|
||||
std::unique_ptr<Cluster> get_ro(int oid)
|
||||
{
|
||||
return static_cast<Cluster *>(PoolSQL::get_ro(oid));
|
||||
return PoolSQL::get_ro<Cluster>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -88,6 +88,8 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
virtual ~Datastore() = default;
|
||||
|
||||
/**
|
||||
* Function to print the Datastore object into a string in XML format
|
||||
* @param xml the resulting XML string
|
||||
@ -344,8 +346,6 @@ private:
|
||||
DatastoreTemplate* ds_template,
|
||||
const std::set<int> &cluster_ids);
|
||||
|
||||
virtual ~Datastore() = default;
|
||||
|
||||
/**
|
||||
* Sets the DISK_TYPE attribute for the datastore. This function will
|
||||
* check the type against the supported DiskTypes for each datastore type
|
||||
|
@ -96,26 +96,26 @@ public:
|
||||
std::string& error_str);
|
||||
|
||||
/**
|
||||
* Function to get a Datastore from the pool, if the object is not in memory
|
||||
* it is loaded from the DB
|
||||
* @param oid Datastore unique id
|
||||
* @param lock locks the Datastore mutex
|
||||
* @return a pointer to the Datastore, 0 if the Datastore could not be loaded
|
||||
* Gets an object from the pool (if needed the object is loaded from the
|
||||
* database). The object is locked, other threads can't access the same
|
||||
* object. The lock is released by destructor.
|
||||
* @param oid the Datastore unique identifier
|
||||
* @return a pointer to the Datastore, nullptr in case of failure
|
||||
*/
|
||||
Datastore * get(int oid)
|
||||
std::unique_ptr<Datastore> get(int oid)
|
||||
{
|
||||
return static_cast<Datastore *>(PoolSQL::get(oid));
|
||||
};
|
||||
return PoolSQL::get<Datastore>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get a read only Datastore from the pool, if the object is not in memory
|
||||
* it is loaded from the DB
|
||||
* @param oid Datastore unique id
|
||||
* @return a pointer to the Datastore, 0 if the Datastore could not be loaded
|
||||
* Gets a read only object from the pool (if needed the object is loaded from the
|
||||
* database). No object lock, other threads may work with the same object.
|
||||
* @param oid the Datastore unique identifier
|
||||
* @return a pointer to the Datastore, nullptr in case of failure
|
||||
*/
|
||||
Datastore * get_ro(int oid)
|
||||
std::unique_ptr<Datastore> get_ro(int oid)
|
||||
{
|
||||
return static_cast<Datastore *>(PoolSQL::get_ro(oid));
|
||||
return PoolSQL::get_ro<Datastore>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -70,7 +70,8 @@ public:
|
||||
* @param ra information about the API call request
|
||||
* @return 0 on success
|
||||
*/
|
||||
int deploy(VirtualMachine * vm, const RequestAttributes& request);
|
||||
int deploy(std::unique_ptr<VirtualMachine> vm,
|
||||
const RequestAttributes& request);
|
||||
|
||||
/**
|
||||
* Sets an imported VM to RUNNING state, a history record MUST be added,
|
||||
@ -79,7 +80,8 @@ public:
|
||||
* @param ra information about the API call request
|
||||
* @return 0 on success
|
||||
*/
|
||||
int import(VirtualMachine * vm, const RequestAttributes& ra);
|
||||
int import(std::unique_ptr<VirtualMachine> vm,
|
||||
const RequestAttributes& ra);
|
||||
|
||||
/**
|
||||
* Migrates a VM. The following actions must be performed before calling
|
||||
@ -194,7 +196,8 @@ public:
|
||||
* @param ra information about the API call request
|
||||
* @return 0 on success, the VM mutex is unlocked
|
||||
*/
|
||||
int delete_vm(VirtualMachine * vm, const RequestAttributes& ra,
|
||||
int delete_vm(std::unique_ptr<VirtualMachine> vm,
|
||||
const RequestAttributes& ra,
|
||||
std::string& error_str);
|
||||
|
||||
/**
|
||||
@ -208,7 +211,8 @@ public:
|
||||
* @param ra information about the API call request
|
||||
* @return 0 on success
|
||||
*/
|
||||
int delete_recreate(VirtualMachine * vm, const RequestAttributes& ra,
|
||||
int delete_recreate(std::unique_ptr<VirtualMachine> vm,
|
||||
const RequestAttributes& ra,
|
||||
std::string& error_str);
|
||||
|
||||
/**
|
||||
@ -217,7 +221,8 @@ public:
|
||||
* @param ra information about the API call request
|
||||
* @return 0 on success, the VM mutex is unlocked
|
||||
*/
|
||||
int delete_vm_db(VirtualMachine * vm, const RequestAttributes& ra,
|
||||
int delete_vm_db(std::unique_ptr<VirtualMachine> vm,
|
||||
const RequestAttributes& ra,
|
||||
std::string& error_str);
|
||||
|
||||
/**
|
||||
@ -227,7 +232,9 @@ public:
|
||||
* @param ra information about the API call request
|
||||
* @return 0 on success
|
||||
*/
|
||||
int recover(VirtualMachine * vm, bool success, const RequestAttributes& ra,
|
||||
int recover(std::unique_ptr<VirtualMachine> vm,
|
||||
bool success,
|
||||
const RequestAttributes& ra,
|
||||
std::string& error_str);
|
||||
|
||||
/**
|
||||
@ -236,7 +243,7 @@ public:
|
||||
* @param ra information about the API call request
|
||||
* @return 0 on success
|
||||
*/
|
||||
int retry(VirtualMachine * vm, const RequestAttributes& ra,
|
||||
int retry(std::unique_ptr<VirtualMachine> vm, const RequestAttributes& ra,
|
||||
std::string& error_str);
|
||||
|
||||
/**
|
||||
@ -416,8 +423,8 @@ public:
|
||||
*
|
||||
* @return 0 on success, -1 otherwise
|
||||
*/
|
||||
int live_updateconf(int vid, const RequestAttributes& ra,
|
||||
std::string& error_str);
|
||||
int live_updateconf(std::unique_ptr<VirtualMachine> vm,
|
||||
const RequestAttributes& ra, std::string& error_str);
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// DM Actions associated with a VM state transition
|
||||
@ -484,7 +491,7 @@ private:
|
||||
/**
|
||||
* Frees the resources associated to a VM: disks, ip addresses and Quotas
|
||||
*/
|
||||
void free_vm_resources(VirtualMachine * vm, bool check_images);
|
||||
void free_vm_resources(std::unique_ptr<VirtualMachine> vm, bool check_images);
|
||||
};
|
||||
|
||||
#endif /*DISPATCH_MANAGER_H*/
|
||||
|
@ -30,6 +30,8 @@ class Document : public PoolObjectSQL
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~Document() = default;
|
||||
|
||||
/**
|
||||
* Function to print the Document object into a string in XML format
|
||||
* @param xml the resulting XML string
|
||||
@ -127,8 +129,6 @@ protected:
|
||||
int type,
|
||||
Template * _template_contents);
|
||||
|
||||
virtual ~Document() = default;
|
||||
|
||||
// *************************************************************************
|
||||
// DataBase implementation
|
||||
// *************************************************************************
|
||||
|
@ -66,29 +66,26 @@ public:
|
||||
|
||||
/**
|
||||
* Gets an object from the pool (if needed the object is loaded from the
|
||||
* database).
|
||||
* @param oid the object unique identifier
|
||||
* @param lock locks the object if true
|
||||
*
|
||||
* @return a pointer to the object, 0 in case of failure
|
||||
* database). The object is locked, other threads can't access the same
|
||||
* object. The lock is released by destructor.
|
||||
* @param oid the Document unique identifier
|
||||
* @return a pointer to the Document, nullptr in case of failure
|
||||
*/
|
||||
Document * get(int oid)
|
||||
std::unique_ptr<Document> get(int oid)
|
||||
{
|
||||
return static_cast<Document *>(PoolSQL::get(oid));
|
||||
};
|
||||
return PoolSQL::get<Document>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a read only object from the pool (if needed the object is loaded from the
|
||||
* database).
|
||||
* @param oid the object unique identifier
|
||||
* @param lock locks the object if true
|
||||
*
|
||||
* @return a pointer to the object, 0 in case of failure
|
||||
* database). No object lock, other threads may work with the same object.
|
||||
* @param oid the Document unique identifier
|
||||
* @return a pointer to the Document, nullptr in case of failure
|
||||
*/
|
||||
Document * get_ro(int oid)
|
||||
std::unique_ptr<Document> get_ro(int oid)
|
||||
{
|
||||
return static_cast<Document *>(PoolSQL::get_ro(oid));
|
||||
};
|
||||
return PoolSQL::get_ro<Document>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps the pool in XML format. A filter can be also added to the
|
||||
|
@ -31,6 +31,8 @@ class Group : public PoolObjectSQL
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~Group() = default;
|
||||
|
||||
/**
|
||||
* Function to print the Group object into a string in XML format
|
||||
* @param xml the resulting XML string
|
||||
@ -172,6 +174,7 @@ private:
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
friend class GroupPool;
|
||||
friend class PoolSQL;
|
||||
|
||||
// *************************************************************************
|
||||
// Constructor
|
||||
@ -179,8 +182,6 @@ private:
|
||||
|
||||
Group(int id, const std::string& name);
|
||||
|
||||
virtual ~Group() = default;
|
||||
|
||||
// *************************************************************************
|
||||
// Administrators
|
||||
// *************************************************************************
|
||||
|
@ -72,28 +72,27 @@ public:
|
||||
std::string& error_str);
|
||||
|
||||
/**
|
||||
* Function to get a group from the pool, if the object is not in memory
|
||||
* it is loaded from the DB
|
||||
* @param oid group unique id
|
||||
* @param lock locks the group mutex
|
||||
* @return a pointer to the group, 0 if the group could not be loaded
|
||||
* Gets an object from the pool (if needed the object is loaded from the
|
||||
* database). The object is locked, other threads can't access the same
|
||||
* object. The lock is released by destructor.
|
||||
* @param oid the Group unique identifier
|
||||
* @return a pointer to the Group, nullptr in case of failure
|
||||
*/
|
||||
Group * get(int oid)
|
||||
std::unique_ptr<Group> get(int oid)
|
||||
{
|
||||
return static_cast<Group *>(PoolSQL::get(oid));
|
||||
};
|
||||
return PoolSQL::get<Group>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get a read only group from the pool, if the object is not in memory
|
||||
* it is loaded from the DB
|
||||
* @param oid group unique id
|
||||
* @param lock locks the group mutex
|
||||
* @return a pointer to the group, 0 if the group could not be loaded
|
||||
* Gets a read only object from the pool (if needed the object is loaded from the
|
||||
* database). No object lock, other threads may work with the same object.
|
||||
* @param oid the Group unique identifier
|
||||
* @return a pointer to the Group, nullptr in case of failure
|
||||
*/
|
||||
Group * get_ro(int oid)
|
||||
std::unique_ptr<Group> get_ro(int oid)
|
||||
{
|
||||
return static_cast<Group *>(PoolSQL::get_ro(oid));
|
||||
};
|
||||
return PoolSQL::get_ro<Group>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of a group
|
||||
@ -104,7 +103,7 @@ public:
|
||||
{
|
||||
static std::string error_str = "";
|
||||
|
||||
Group * group = get_ro(gid);
|
||||
auto group = get_ro(gid);
|
||||
|
||||
if ( group == 0 )
|
||||
{
|
||||
@ -113,8 +112,6 @@ public:
|
||||
|
||||
const std::string gname = group->get_name();
|
||||
|
||||
group->unlock();
|
||||
|
||||
return gname;
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,8 @@ class Hook : public PoolObjectSQL
|
||||
{
|
||||
public:
|
||||
|
||||
~Hook();
|
||||
|
||||
/**
|
||||
* Defines the hook type, so a whole hook class can be masked
|
||||
*/
|
||||
@ -95,8 +97,6 @@ private:
|
||||
|
||||
Hook(Template * tmpl);
|
||||
|
||||
~Hook();
|
||||
|
||||
/**
|
||||
* Set hook implementation attribute depending of the hook type.
|
||||
*/
|
||||
|
@ -41,25 +41,26 @@ public:
|
||||
int allocate (Template * tmpl, std::string& error_str);
|
||||
|
||||
/**
|
||||
* Function to get a Hook from the pool, if the object is not in memory
|
||||
* it is loaded from the DB
|
||||
* @param oid Hook unique id
|
||||
* @return a pointer to the Hook, 0 if the Hook could not be loaded
|
||||
* Gets an object from the pool (if needed the object is loaded from the
|
||||
* database). The object is locked, other threads can't access the same
|
||||
* object. The lock is released by destructor.
|
||||
* @param oid the Hook unique identifier
|
||||
* @return a pointer to the Hook, nullptr in case of failure
|
||||
*/
|
||||
Hook * get(int oid)
|
||||
std::unique_ptr<Hook> get(int oid)
|
||||
{
|
||||
return static_cast<Hook *>(PoolSQL::get(oid));
|
||||
};
|
||||
return PoolSQL::get<Hook>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get a read only Hook from the pool, if the object is not in memory
|
||||
* it is loaded from the DB
|
||||
* @param oid Hook unique id
|
||||
* @return a pointer to the Hook, 0 if the Host could not be loaded
|
||||
* Gets a read only object from the pool (if needed the object is loaded from the
|
||||
* database). No object lock, other threads may work with the same object.
|
||||
* @param oid the Hook unique identifier
|
||||
* @return a pointer to the Hook, nullptr in case of failure
|
||||
*/
|
||||
Hook * get_ro(int oid)
|
||||
std::unique_ptr<Hook> get_ro(int oid)
|
||||
{
|
||||
return static_cast<Hook *>(PoolSQL::get_ro(oid));
|
||||
return PoolSQL::get_ro<Hook>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -112,6 +112,8 @@ public:
|
||||
return st;
|
||||
}
|
||||
|
||||
virtual ~Host() = default;
|
||||
|
||||
/**
|
||||
* Function to print the Host object into a string in XML format
|
||||
* @param xml the resulting XML string
|
||||
@ -357,8 +359,6 @@ private:
|
||||
Host(int id, const std::string& hostname, const std::string& im_mad,
|
||||
const std::string& vmm_mad, int clusterid, const std::string& cluster);
|
||||
|
||||
virtual ~Host() = default;
|
||||
|
||||
|
||||
// *************************************************************************
|
||||
// Helper functions
|
||||
|
@ -60,53 +60,52 @@ public:
|
||||
virtual int update(PoolObjectSQL * objsql);
|
||||
|
||||
/**
|
||||
* Function to get a Host from the pool, if the object is not in memory
|
||||
* it is loaded from the DB
|
||||
* @param oid Host unique id
|
||||
* @param lock locks the Host mutex
|
||||
* @return a pointer to the Host, 0 if the Host could not be loaded
|
||||
* Gets an object from the pool (if needed the object is loaded from the
|
||||
* database). The object is locked, other threads can't access the same
|
||||
* object. The lock is released by destructor.
|
||||
* @param oid the Host unique identifier
|
||||
* @return a pointer to the Host, nullptr in case of failure
|
||||
*/
|
||||
Host * get(int oid)
|
||||
std::unique_ptr<Host> get(int oid)
|
||||
{
|
||||
return static_cast<Host *>(PoolSQL::get(oid));
|
||||
};
|
||||
return PoolSQL::get<Host>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get a read only Host from the pool, if the object is not in memory
|
||||
* it is loaded from the DB
|
||||
* @param oid Host unique id
|
||||
* @return a pointer to the Host, 0 if the Host could not be loaded
|
||||
* Gets a read only object from the pool (if needed the object is loaded from the
|
||||
* database). No object lock, other threads may work with the same object.
|
||||
* @param oid the Host unique identifier
|
||||
* @return a pointer to the Host, nullptr in case of failure
|
||||
*/
|
||||
Host * get_ro(int oid)
|
||||
std::unique_ptr<Host> get_ro(int oid)
|
||||
{
|
||||
return static_cast<Host *>(PoolSQL::get_ro(oid));
|
||||
};
|
||||
return PoolSQL::get_ro<Host>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get a Host from the pool, if the object is not in memory
|
||||
* it is loaded from the DB
|
||||
* Gets an object from the pool (if needed the object is loaded from the
|
||||
* database). The object is locked, other threads can't access the same
|
||||
* object. The lock is released by destructor.
|
||||
* @param hostname
|
||||
* @param lock locks the Host mutex
|
||||
* @return a pointer to the Host, 0 if the Host could not be loaded
|
||||
* @return a pointer to the Host, nullptr if the Host could not be loaded
|
||||
*/
|
||||
Host * get(std::string name)
|
||||
std::unique_ptr<Host> get(std::string name)
|
||||
{
|
||||
// The owner is set to -1, because it is not used in the key() method
|
||||
return static_cast<Host *>(PoolSQL::get(name,-1));
|
||||
};
|
||||
return PoolSQL::get<Host>(name, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get a Host from the pool, if the object is not in memory
|
||||
* it is loaded from the DB
|
||||
* Gets a read only object from the pool (if needed the object is loaded from the
|
||||
* database). No object lock, other threads may work with the same object.
|
||||
* @param hostname
|
||||
* @param lock locks the Host mutex
|
||||
* @return a pointer to the Host, 0 if the Host could not be loaded
|
||||
*/
|
||||
Host * get_ro(std::string name)
|
||||
std::unique_ptr<Host> get_ro(std::string name)
|
||||
{
|
||||
// The owner is set to -1, because it is not used in the key() method
|
||||
return static_cast<Host *>(PoolSQL::get_ro(name,-1));
|
||||
};
|
||||
return PoolSQL::get_ro<Host>(name, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an index key for the object
|
||||
@ -152,15 +151,12 @@ public:
|
||||
int add_capacity(int oid, HostShareCapacity &sr)
|
||||
{
|
||||
int rc = 0;
|
||||
Host * host = get(oid);
|
||||
|
||||
if ( host != 0 )
|
||||
if ( auto host = get(oid) )
|
||||
{
|
||||
host->add_capacity(sr);
|
||||
|
||||
update(host);
|
||||
|
||||
host->unlock();
|
||||
update(host.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -168,7 +164,7 @@ public:
|
||||
}
|
||||
|
||||
return rc;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* De-Allocates a given capacity to the host
|
||||
@ -181,17 +177,13 @@ public:
|
||||
*/
|
||||
void del_capacity(int oid, HostShareCapacity &sr)
|
||||
{
|
||||
Host * host = get(oid);
|
||||
|
||||
if ( host != 0 )
|
||||
if ( auto host = get(oid) )
|
||||
{
|
||||
host->del_capacity(sr);
|
||||
|
||||
update(host);
|
||||
|
||||
host->unlock();
|
||||
update(host.get());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int drop(PoolObjectSQL * objsql, std::string& error_msg)
|
||||
{
|
||||
|
@ -164,6 +164,8 @@ public:
|
||||
// Image Public Methods
|
||||
// *************************************************************************
|
||||
|
||||
virtual ~Image() = default;
|
||||
|
||||
/**
|
||||
* Function to print the Image object into a string in XML format
|
||||
* @param xml the resulting XML string
|
||||
@ -718,8 +720,6 @@ protected:
|
||||
int umask,
|
||||
ImageTemplate* img_template);
|
||||
|
||||
virtual ~Image() = default;
|
||||
|
||||
// *************************************************************************
|
||||
// DataBase implementation
|
||||
// *************************************************************************
|
||||
|
@ -85,7 +85,8 @@ public:
|
||||
* @param attach true if attaching the image to a VM
|
||||
* @return pointer to the image or 0 if could not be acquired
|
||||
*/
|
||||
Image * acquire_image(int vm_id, int image_id, bool attach, std::string& error);
|
||||
std::unique_ptr<Image> acquire_image(int vm_id, int image_id,
|
||||
bool attach, std::string& error);
|
||||
|
||||
/**
|
||||
* Try to acquire an image from the repository for a VM.
|
||||
@ -95,7 +96,7 @@ public:
|
||||
* @param attach true if attaching the image to a VM
|
||||
* @return pointer to the image or 0 if could not be acquired
|
||||
*/
|
||||
Image * acquire_image(int vm_id, const std::string& name,
|
||||
std::unique_ptr<Image> acquire_image(int vm_id, const std::string& name,
|
||||
int uid, bool attach, std::string& error);
|
||||
|
||||
/**
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
#include "PoolSQL.h"
|
||||
#include "Image.h"
|
||||
#include "NebulaLog.h"
|
||||
#include "Datastore.h"
|
||||
#include "OneDB.h"
|
||||
|
||||
@ -87,55 +86,55 @@ public:
|
||||
int * oid,
|
||||
std::string& error_str);
|
||||
|
||||
/**
|
||||
** Function to get a Image from the pool, if the object is not in memory
|
||||
* it is loaded from the DB
|
||||
* @param oid Image unique id
|
||||
* @param lock locks the Image mutex
|
||||
* @return a pointer to the Image, 0 if the Image could not be loaded
|
||||
*/
|
||||
Image * get(int oid)
|
||||
{
|
||||
return static_cast<Image *>(PoolSQL::get(oid));
|
||||
};
|
||||
|
||||
/**
|
||||
** Function to get a read only Image from the pool, if the object is not in memory
|
||||
* it is loaded from the DB
|
||||
* @param oid Image unique id
|
||||
* @return a pointer to the Image, 0 if the Image could not be loaded
|
||||
*/
|
||||
Image * get_ro(int oid)
|
||||
{
|
||||
return static_cast<Image *>(PoolSQL::get(oid));
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets an object from the pool (if needed the object is loaded from the
|
||||
* database).
|
||||
* @param name of the object
|
||||
* @param uid id of owner
|
||||
* @param lock locks the object if true
|
||||
*
|
||||
* @return a pointer to the object, 0 in case of failure
|
||||
* database). The object is locked, other threads can't access the same
|
||||
* object. The lock is released by destructor.
|
||||
* @param oid the Image unique identifier
|
||||
* @return a pointer to the Image, nullptr in case of failure
|
||||
*/
|
||||
Image * get(const std::string& name, int uid)
|
||||
std::unique_ptr<Image> get(int oid)
|
||||
{
|
||||
return static_cast<Image *>(PoolSQL::get(name,uid));
|
||||
};
|
||||
return PoolSQL::get<Image>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a read only object from the pool (if needed the object is loaded from the
|
||||
* database).
|
||||
* database). No object lock, other threads may work with the same object.
|
||||
* @param oid the Image unique identifier
|
||||
* @return a pointer to the Image, nullptr in case of failure
|
||||
*/
|
||||
std::unique_ptr<Image> get_ro(int oid)
|
||||
{
|
||||
return PoolSQL::get_ro<Image>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an object from the pool (if needed the object is loaded from the
|
||||
* database). The object is locked, other threads can't access the same
|
||||
* object. The lock is released by destructor.
|
||||
* @param name of the object
|
||||
* @param uid id of owner
|
||||
*
|
||||
* @return a pointer to the object, 0 in case of failure
|
||||
*/
|
||||
Image * get_ro(const std::string& name, int uid)
|
||||
std::unique_ptr<Image> get(const std::string& name, int uid)
|
||||
{
|
||||
return static_cast<Image *>(PoolSQL::get_ro(name,uid));
|
||||
};
|
||||
return PoolSQL::get<Image>(name,uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a read only object from the pool (if needed the object is loaded from the
|
||||
* database). No object lock, other threads may work with the same object.
|
||||
* @param name of the object
|
||||
* @param uid id of owner
|
||||
*
|
||||
* @return a pointer to the object, 0 in case of failure
|
||||
*/
|
||||
std::unique_ptr<Image> get_ro(const std::string& name, int uid)
|
||||
{
|
||||
return PoolSQL::get_ro<Image>(name, uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstraps the database table(s) associated to the Image pool
|
||||
|
@ -34,8 +34,45 @@
|
||||
class Timer
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Empty constructor, call start method to start the thread timer
|
||||
**/
|
||||
Timer() = default;
|
||||
|
||||
/**
|
||||
* Starts async thread, which call 'timer' method every 's' seconds
|
||||
**/
|
||||
Timer(double s, std::function<void()> timer)
|
||||
{
|
||||
start(s, timer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor, stops the running thread
|
||||
**/
|
||||
~Timer()
|
||||
{
|
||||
stop();
|
||||
|
||||
if (timer_thread.joinable())
|
||||
{
|
||||
timer_thread.join();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts async thread, which call 'timer' method every 's' seconds
|
||||
* Can be called only if default constructor is used, to start the thread
|
||||
* Can be called only once per class instance
|
||||
**/
|
||||
void start(double s, std::function<void()> timer)
|
||||
{
|
||||
if (timer_thread.joinable())
|
||||
{
|
||||
NebulaLog::error("TMR", "Trying to start Timer thread twice!");
|
||||
return;
|
||||
}
|
||||
|
||||
end = false;
|
||||
|
||||
timer_thread = std::thread([&, s, timer]{
|
||||
@ -58,15 +95,12 @@ public:
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
~Timer()
|
||||
{
|
||||
stop();
|
||||
|
||||
timer_thread.join();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the running thread. It's not necessery to call this method,
|
||||
* the thread is stopped in destructor
|
||||
**/
|
||||
void stop()
|
||||
{
|
||||
std::unique_lock<std::mutex> ul(lock);
|
||||
@ -75,6 +109,7 @@ public:
|
||||
|
||||
cond.notify_one();
|
||||
}
|
||||
|
||||
private:
|
||||
std::atomic<bool> end;
|
||||
|
||||
|
@ -30,6 +30,8 @@
|
||||
class MarketPlace : public PoolObjectSQL
|
||||
{
|
||||
public:
|
||||
virtual ~MarketPlace() = default;
|
||||
|
||||
/**
|
||||
* Function to print the MarketPlace object into a string in XML format
|
||||
* @param xml the resulting XML string
|
||||
@ -184,8 +186,6 @@ private:
|
||||
int umask,
|
||||
MarketPlaceTemplate* mp_template);
|
||||
|
||||
virtual ~MarketPlace() = default;
|
||||
|
||||
// *************************************************************************
|
||||
// DataBase implementation (Private)
|
||||
// *************************************************************************
|
||||
|
@ -127,6 +127,8 @@ public:
|
||||
*/
|
||||
static Type str_to_type(std::string& str_type);
|
||||
|
||||
virtual ~MarketPlaceApp() = default;
|
||||
|
||||
/**
|
||||
* Function to print the MarketPlaceApp object into a string in XML format
|
||||
* @param xml the resulting XML string
|
||||
@ -355,8 +357,6 @@ private:
|
||||
int umask,
|
||||
MarketPlaceAppTemplate* app_template);
|
||||
|
||||
virtual ~MarketPlaceApp() = default;
|
||||
|
||||
// *************************************************************************
|
||||
// DataBase implementation (Private)
|
||||
// *************************************************************************
|
||||
|
@ -83,53 +83,55 @@ public:
|
||||
int import(const std::string& t64, int mp_id, const std::string& mp_name,
|
||||
int& app_id, std::string& error_str);
|
||||
|
||||
/**
|
||||
* Function to get a MarketPlaceApp from the pool
|
||||
* @param oid MarketPlaceApp unique id
|
||||
* @param lock locks the MarketPlaceApp mutex
|
||||
* @return a pointer to the MarketPlaceApp, 0 if not loaded
|
||||
*/
|
||||
MarketPlaceApp * get(int oid)
|
||||
{
|
||||
return static_cast<MarketPlaceApp *>(PoolSQL::get(oid));
|
||||
};
|
||||
|
||||
/**
|
||||
* Function to get a read only MarketPlaceApp from the pool
|
||||
* @param oid MarketPlaceApp unique id
|
||||
* @return a pointer to the MarketPlaceApp, 0 if not loaded
|
||||
*/
|
||||
MarketPlaceApp * get_ro(int oid)
|
||||
{
|
||||
return static_cast<MarketPlaceApp *>(PoolSQL::get_ro(oid));
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets an object from the pool (if needed the object is loaded from the
|
||||
* database).
|
||||
* @param name of the object
|
||||
* @param uid id of owner
|
||||
* @param lock locks the object if true
|
||||
*
|
||||
* @return a pointer to the object, 0 in case of failure
|
||||
* database). The object is locked, other threads can't access the same
|
||||
* object. The lock is released by destructor.
|
||||
* @param oid the MarketPlaceApp unique identifier
|
||||
* @return a pointer to the MarketPlaceApp, nullptr in case of failure
|
||||
*/
|
||||
MarketPlaceApp * get(const std::string& name, int uid)
|
||||
std::unique_ptr<MarketPlaceApp> get(int oid)
|
||||
{
|
||||
return static_cast<MarketPlaceApp *>(PoolSQL::get(name, uid));
|
||||
};
|
||||
return PoolSQL::get<MarketPlaceApp>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a read only object from the pool (if needed the object is loaded from the
|
||||
* database).
|
||||
* database). No object lock, other threads may work with the same object.
|
||||
* @param oid the MarketPlaceApp unique identifier
|
||||
* @return a pointer to the MarketPlaceApp, nullptr in case of failure
|
||||
*/
|
||||
std::unique_ptr<MarketPlaceApp> get_ro(int oid)
|
||||
{
|
||||
return PoolSQL::get_ro<MarketPlaceApp>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an object from the pool (if needed the object is loaded from the
|
||||
* database). The object is locked, other threads can't access the same
|
||||
* object. The lock is released by destructor.
|
||||
* @param name of the object
|
||||
* @param uid id of owner
|
||||
*
|
||||
* @return a pointer to the object, 0 in case of failure
|
||||
*/
|
||||
MarketPlaceApp * get_ro(const std::string& name, int uid)
|
||||
std::unique_ptr<MarketPlaceApp> get(const std::string& name, int uid)
|
||||
{
|
||||
return static_cast<MarketPlaceApp *>(PoolSQL::get_ro(name, uid));
|
||||
};
|
||||
return PoolSQL::get<MarketPlaceApp>(name, uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a read only object from the pool (if needed the object is loaded from the
|
||||
* database). No object lock, other threads may work with the same object.
|
||||
* @param name of the object
|
||||
* @param uid id of owner
|
||||
*
|
||||
* @return a pointer to the object, 0 in case of failure
|
||||
*/
|
||||
std::unique_ptr<MarketPlaceApp> get_ro(const std::string& name, int uid)
|
||||
{
|
||||
return PoolSQL::get_ro<MarketPlaceApp>(name, uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstraps the database table(s) associated to the MarketPlace pool
|
||||
|
@ -60,28 +60,27 @@ public:
|
||||
std::string& error_str);
|
||||
|
||||
/**
|
||||
* Function to get a MarketPlace from the pool, the object is loaded if not
|
||||
* in memory
|
||||
* @param oid MarketPlace unique id
|
||||
* @param lock locks the MarketPlace mutex
|
||||
* @return a pointer to the MarketPlace, 0 if not loaded
|
||||
* Gets an object from the pool (if needed the object is loaded from the
|
||||
* database). The object is locked, other threads can't access the same
|
||||
* object. The lock is released by destructor.
|
||||
* @param oid the MarketPlace unique identifier
|
||||
* @return a pointer to the MarketPlace, nullptr in case of failure
|
||||
*/
|
||||
MarketPlace * get(int oid)
|
||||
std::unique_ptr<MarketPlace> get(int oid)
|
||||
{
|
||||
return static_cast<MarketPlace *>(PoolSQL::get(oid));
|
||||
};
|
||||
return PoolSQL::get<MarketPlace>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get a read only MarketPlace from the pool, the object is loaded if not
|
||||
* in memory
|
||||
* @param oid MarketPlace unique id
|
||||
* @param lock locks the MarketPlace mutex
|
||||
* @return a pointer to the MarketPlace, 0 if not loaded
|
||||
* Gets a read only object from the pool (if needed the object is loaded from the
|
||||
* database). No object lock, other threads may work with the same object.
|
||||
* @param oid the MarketPlace unique identifier
|
||||
* @return a pointer to the MarketPlace, nullptr in case of failure
|
||||
*/
|
||||
MarketPlace * get_ro(int oid)
|
||||
std::unique_ptr<MarketPlace> get_ro(int oid)
|
||||
{
|
||||
return static_cast<MarketPlace *>(PoolSQL::get_ro(oid));
|
||||
};
|
||||
return PoolSQL::get_ro<MarketPlace>(oid);
|
||||
}
|
||||
|
||||
/** Update a particular MarketPlace
|
||||
* @param objsql points to the market
|
||||
|
@ -500,51 +500,41 @@ public:
|
||||
{
|
||||
if ( uid != -1 )
|
||||
{
|
||||
User * user = upool->get_ro(uid);
|
||||
auto user = upool->get_ro(uid);
|
||||
|
||||
if ( user == 0 )
|
||||
if (!user)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
const VectorAttribute * uconf;
|
||||
auto uconf = user->get_template_attribute("OPENNEBULA");
|
||||
|
||||
uconf = user->get_template_attribute("OPENNEBULA");
|
||||
|
||||
if ( uconf != 0 )
|
||||
if ( uconf != nullptr )
|
||||
{
|
||||
if ( uconf->vector_value(name, value) == 0 )
|
||||
{
|
||||
user->unlock();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
user->unlock();
|
||||
}
|
||||
|
||||
Group * group = gpool->get_ro(gid);
|
||||
auto group = gpool->get_ro(gid);
|
||||
|
||||
if ( group == 0 )
|
||||
if (!group)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
const VectorAttribute * gconf;
|
||||
auto gconf = group->get_template_attribute("OPENNEBULA");
|
||||
|
||||
gconf = group->get_template_attribute("OPENNEBULA");
|
||||
|
||||
if ( gconf != 0 )
|
||||
if ( gconf != nullptr )
|
||||
{
|
||||
if ( gconf->vector_value(name, value) == 0 )
|
||||
{
|
||||
group->unlock();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
group->unlock();
|
||||
|
||||
nebula_configuration->get(name, value);
|
||||
|
||||
return 0;
|
||||
|
@ -181,6 +181,7 @@ public:
|
||||
lock_owner(-1),
|
||||
lock_req_id(-1),
|
||||
lock_time(0),
|
||||
ro(false),
|
||||
mutex(0),
|
||||
table(_table)
|
||||
{
|
||||
@ -188,6 +189,11 @@ public:
|
||||
|
||||
virtual ~PoolObjectSQL()
|
||||
{
|
||||
if (!ro && mutex != 0)
|
||||
{
|
||||
pthread_mutex_unlock(mutex);
|
||||
}
|
||||
|
||||
delete obj_template;
|
||||
};
|
||||
|
||||
@ -318,21 +324,6 @@ public:
|
||||
int _other_a,
|
||||
std::string& error_str);
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/**
|
||||
* Function to unlock the object. It also frees associated resources. Object
|
||||
* cannot be access after unlocking it
|
||||
*/
|
||||
void unlock()
|
||||
{
|
||||
if (!ro && mutex != 0)
|
||||
{
|
||||
pthread_mutex_unlock(mutex);
|
||||
}
|
||||
|
||||
delete this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Function to print the object into a string in XML format
|
||||
* base64 encoded
|
||||
|
@ -18,6 +18,7 @@
|
||||
#define POOL_SQL_H_
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
#include "SqlDB.h"
|
||||
#include "PoolObjectSQL.h"
|
||||
@ -56,21 +57,68 @@ public:
|
||||
|
||||
/**
|
||||
* Gets an object from the pool (if needed the object is loaded from the
|
||||
* database).
|
||||
* database). The object is locked, other threads can't access the same
|
||||
* object. The lock is released by destructor.
|
||||
* @param oid the object unique identifier
|
||||
*
|
||||
* @return a pointer to the object, 0 in case of failure
|
||||
* @return a pointer to the object, nullptr in case of failure
|
||||
*/
|
||||
PoolObjectSQL * get(int oid);
|
||||
template<typename T>
|
||||
std::unique_ptr<T> get(int oid)
|
||||
{
|
||||
if ( oid < 0 )
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
pthread_mutex_t * object_lock = cache.lock_line(oid);
|
||||
|
||||
std::unique_ptr<T> objectsql(static_cast<T *>(create()));
|
||||
|
||||
objectsql->oid = oid;
|
||||
|
||||
objectsql->ro = false;
|
||||
|
||||
objectsql->mutex = object_lock;
|
||||
|
||||
int rc = objectsql->select(db);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return objectsql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a read only object from the pool (if needed the object is loaded from the
|
||||
* database).
|
||||
* database). No object lock, other threads may work with the same object.
|
||||
* @param oid the object unique identifier
|
||||
*
|
||||
* @return a pointer to the object, 0 in case of failure
|
||||
* @return a pointer to the object, nullptr in case of failure
|
||||
*/
|
||||
PoolObjectSQL * get_ro(int oid);
|
||||
template<typename T>
|
||||
std::unique_ptr<T> get_ro(int oid)
|
||||
{
|
||||
if ( oid < 0 )
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<T> objectsql(static_cast<T *>(create()));
|
||||
|
||||
objectsql->oid = oid;
|
||||
|
||||
objectsql->ro = true;
|
||||
|
||||
int rc = objectsql->select(db);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return objectsql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if there is an object with the same for a given user
|
||||
@ -289,13 +337,25 @@ protected:
|
||||
|
||||
/**
|
||||
* Gets an object from the pool (if needed the object is loaded from the
|
||||
* database).
|
||||
* database). The object is locked, other threads can't access the same
|
||||
* object. The lock is released by destructor.
|
||||
* @param name of the object
|
||||
* @param uid id of owner
|
||||
*
|
||||
* @return a pointer to the object, 0 in case of failure
|
||||
*/
|
||||
PoolObjectSQL * get(const std::string& name, int uid);
|
||||
template<typename T>
|
||||
std::unique_ptr<T> get(const std::string& name, int uid)
|
||||
{
|
||||
int oid = PoolObjectSQL::select_oid(db, table.c_str(), name, uid);
|
||||
|
||||
if ( oid == -1 )
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return get<T>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a read only object from the pool (if needed the object is loaded from the
|
||||
@ -305,7 +365,18 @@ protected:
|
||||
*
|
||||
* @return a pointer to the object, 0 in case of failure
|
||||
*/
|
||||
PoolObjectSQL * get_ro(const std::string& name, int uid);
|
||||
template<typename T>
|
||||
std::unique_ptr<T> get_ro(const std::string& name, int uid)
|
||||
{
|
||||
int oid = PoolObjectSQL::select_oid(db, table.c_str(), name, uid);
|
||||
|
||||
if ( oid == -1 )
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return get_ro<T>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to the database.
|
||||
|
@ -385,6 +385,8 @@ private:
|
||||
*/
|
||||
Timer timer_thread;
|
||||
|
||||
Timer purge_thread;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Volatile log index variables
|
||||
// - commit, highest log known to be committed
|
||||
@ -419,10 +421,15 @@ private:
|
||||
// Internal Raft functions
|
||||
// -------------------------------------------------------------------------
|
||||
/**
|
||||
* This function is executed periodically to purge the state log
|
||||
* This function is executed periodically to vote leader
|
||||
*/
|
||||
void timer_action();
|
||||
|
||||
/**
|
||||
* This function is executed periodically to purge the state log
|
||||
*/
|
||||
void purge_action();
|
||||
|
||||
/**
|
||||
* @param s the state to check
|
||||
* @return true if the server states matches the provided one
|
||||
|
@ -64,7 +64,7 @@ protected:
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList,
|
||||
RequestAttributes& att) override;
|
||||
|
||||
PoolObjectSQL * get_and_quota(int oid,
|
||||
std::unique_ptr<PoolObjectSQL> get_and_quota(int oid,
|
||||
int new_uid,
|
||||
int new_gid,
|
||||
RequestAttributes& att)
|
||||
@ -72,7 +72,8 @@ protected:
|
||||
return get_and_quota(oid, new_uid, new_gid, att, pool, auth_object);
|
||||
}
|
||||
|
||||
PoolObjectSQL * get_and_quota(int oid,
|
||||
std::unique_ptr<PoolObjectSQL> get_and_quota(
|
||||
int oid,
|
||||
int new_uid,
|
||||
int new_gid,
|
||||
RequestAttributes& att,
|
||||
|
@ -205,17 +205,15 @@ protected:
|
||||
int pool_allocate(int sid, Template * tmpl, int& id, RequestAttributes& att) override
|
||||
{
|
||||
DocumentPool * docpool = static_cast<DocumentPool *>(pool);
|
||||
Document * doc = docpool->get_ro(sid);
|
||||
auto doc = docpool->get_ro(sid);
|
||||
|
||||
if ( doc == 0 )
|
||||
if (!doc)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int dtype = doc->get_document_type();
|
||||
|
||||
doc->unlock();
|
||||
|
||||
return docpool->allocate(att.uid, att.gid, att.uname, att.gname,
|
||||
att.umask, dtype, tmpl, &id, att.resp_msg);
|
||||
};
|
||||
|
@ -100,7 +100,8 @@ protected:
|
||||
|
||||
virtual int del_object(Cluster* cluster, int id, std::string& error_msg) = 0;
|
||||
|
||||
virtual void get(int oid, PoolObjectSQL ** object, Clusterable ** cluster_obj) = 0;
|
||||
virtual void get(int oid, std::unique_ptr<PoolObjectSQL>& object,
|
||||
Clusterable ** cluster_obj) = 0;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -200,26 +201,27 @@ public:
|
||||
|
||||
~RequestManagerClusterDatastore(){};
|
||||
|
||||
virtual int add_object(
|
||||
int add_object(
|
||||
Cluster* cluster,
|
||||
int id,
|
||||
std::string& error_msg) override
|
||||
{
|
||||
return clpool->add_to_cluster(PoolObjectSQL::DATASTORE, cluster, id, error_msg);
|
||||
};
|
||||
}
|
||||
|
||||
virtual int del_object(Cluster* cluster, int id, std::string& error_msg) override
|
||||
int del_object(Cluster* cluster, int id, std::string& error_msg) override
|
||||
{
|
||||
return clpool->del_from_cluster(PoolObjectSQL::DATASTORE, cluster, id, error_msg);
|
||||
};
|
||||
}
|
||||
|
||||
virtual void get(int oid, PoolObjectSQL ** object, Clusterable ** cluster_obj) override
|
||||
void get(int oid, std::unique_ptr<PoolObjectSQL>& object,
|
||||
Clusterable ** cluster_obj) override
|
||||
{
|
||||
Datastore * ds = dspool->get(oid);
|
||||
auto ds = dspool->get(oid);
|
||||
|
||||
*object = static_cast<PoolObjectSQL *>(ds);
|
||||
*cluster_obj = static_cast<Clusterable *>(ds);
|
||||
};
|
||||
*cluster_obj = static_cast<Clusterable *>(ds.get());
|
||||
object = std::move(ds);
|
||||
}
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -285,26 +287,27 @@ public:
|
||||
|
||||
~RequestManagerClusterVNet(){};
|
||||
|
||||
virtual int add_object(
|
||||
int add_object(
|
||||
Cluster* cluster,
|
||||
int id,
|
||||
std::string& error_msg) override
|
||||
{
|
||||
return clpool->add_to_cluster(PoolObjectSQL::NET, cluster, id, error_msg);
|
||||
};
|
||||
}
|
||||
|
||||
virtual int del_object(Cluster* cluster, int id, std::string& error_msg) override
|
||||
int del_object(Cluster* cluster, int id, std::string& error_msg) override
|
||||
{
|
||||
return clpool->del_from_cluster(PoolObjectSQL::NET, cluster, id, error_msg);
|
||||
};
|
||||
}
|
||||
|
||||
virtual void get(int oid, PoolObjectSQL ** object, Clusterable ** cluster_obj) override
|
||||
void get(int oid, std::unique_ptr<PoolObjectSQL>& object,
|
||||
Clusterable ** cluster_obj) override
|
||||
{
|
||||
VirtualNetwork * vnet = vnpool->get(oid);
|
||||
auto vnet = vnpool->get(oid);
|
||||
|
||||
*object = static_cast<PoolObjectSQL *>(vnet);
|
||||
*cluster_obj = static_cast<Clusterable *>(vnet);
|
||||
};
|
||||
*cluster_obj = static_cast<Clusterable *>(vnet.get());
|
||||
object = std::move(vnet);
|
||||
}
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
@ -49,7 +49,9 @@ protected:
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
virtual int drop(PoolObjectSQL * obj, bool resive, RequestAttributes& att);
|
||||
virtual int drop(std::unique_ptr<PoolObjectSQL> obj,
|
||||
bool recursive,
|
||||
RequestAttributes& att);
|
||||
|
||||
virtual std::set<int> get_cluster_ids(PoolObjectSQL * object) const
|
||||
{
|
||||
@ -87,7 +89,9 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
int drop(PoolObjectSQL * obj, bool resive, RequestAttributes& att) override;
|
||||
int drop(std::unique_ptr<PoolObjectSQL> obj,
|
||||
bool recursive,
|
||||
RequestAttributes& att) override;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -129,7 +133,9 @@ protected:
|
||||
return clpool->del_from_cluster(PoolObjectSQL::NET, cluster, id, error_msg);
|
||||
};
|
||||
|
||||
int drop(PoolObjectSQL * obj, bool resive, RequestAttributes& att) override;
|
||||
int drop(std::unique_ptr<PoolObjectSQL> obj,
|
||||
bool recursive,
|
||||
RequestAttributes& att) override;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -152,7 +158,9 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
int drop(PoolObjectSQL * obj, bool resive, RequestAttributes& att) override;
|
||||
int drop(std::unique_ptr<PoolObjectSQL> obj,
|
||||
bool recursive,
|
||||
RequestAttributes& att) override;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -181,7 +189,9 @@ protected:
|
||||
return clpool->del_from_cluster(PoolObjectSQL::HOST, cluster, id, error_msg);
|
||||
};
|
||||
|
||||
int drop(PoolObjectSQL * obj, bool resive, RequestAttributes& att) override;
|
||||
int drop(std::unique_ptr<PoolObjectSQL> obj,
|
||||
bool recursive,
|
||||
RequestAttributes& att) override;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -196,7 +206,9 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
int drop(PoolObjectSQL * obj, bool resive, RequestAttributes& att) override;
|
||||
int drop(std::unique_ptr<PoolObjectSQL> obj,
|
||||
bool recursive,
|
||||
RequestAttributes& att) override;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -213,7 +225,9 @@ protected:
|
||||
|
||||
GroupPool * gpool;
|
||||
|
||||
int drop(PoolObjectSQL * obj, bool resive, RequestAttributes& att) override;
|
||||
int drop(std::unique_ptr<PoolObjectSQL> obj,
|
||||
bool recursive,
|
||||
RequestAttributes& att) override;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -238,7 +252,9 @@ public:
|
||||
return clpool->del_from_cluster(PoolObjectSQL::DATASTORE, cluster, id, error_msg);
|
||||
};
|
||||
|
||||
int drop(PoolObjectSQL * obj, bool resive, RequestAttributes& att) override;
|
||||
int drop(std::unique_ptr<PoolObjectSQL> obj,
|
||||
bool recursive,
|
||||
RequestAttributes& att) override;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -253,7 +269,9 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
int drop(PoolObjectSQL * obj, bool resive, RequestAttributes& att) override;
|
||||
int drop(std::unique_ptr<PoolObjectSQL> obj,
|
||||
bool recursive,
|
||||
RequestAttributes& att) override;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -279,7 +297,9 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
int drop(PoolObjectSQL * obj, bool resive, RequestAttributes& att) override;
|
||||
int drop(std::unique_ptr<PoolObjectSQL> obj,
|
||||
bool recursive,
|
||||
RequestAttributes& att) override;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -294,7 +314,9 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
int drop(PoolObjectSQL * obj, bool resive, RequestAttributes& att) override;
|
||||
int drop(std::unique_ptr<PoolObjectSQL> obj,
|
||||
bool recursive,
|
||||
RequestAttributes& att) override;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -319,7 +341,9 @@ public:
|
||||
~VirtualRouterDelete() = default;
|
||||
|
||||
protected:
|
||||
int drop(PoolObjectSQL * obj, bool resive, RequestAttributes& att) override;
|
||||
int drop(std::unique_ptr<PoolObjectSQL> obj,
|
||||
bool recursive,
|
||||
RequestAttributes& att) override;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -334,7 +358,9 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
int drop(PoolObjectSQL * obj, bool resive, RequestAttributes& att) override;
|
||||
int drop(std::unique_ptr<PoolObjectSQL> obj,
|
||||
bool recursive,
|
||||
RequestAttributes& att) override;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -349,7 +375,9 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
int drop(PoolObjectSQL * obj, bool resive, RequestAttributes& att) override;
|
||||
int drop(std::unique_ptr<PoolObjectSQL> obj,
|
||||
bool recursive,
|
||||
RequestAttributes& att) override;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
@ -46,9 +46,9 @@ protected:
|
||||
return;
|
||||
}
|
||||
|
||||
PoolObjectSQL * object = pool->get(oid);
|
||||
auto object = pool->get<PoolObjectSQL>(oid);
|
||||
|
||||
if ( object == 0 )
|
||||
if (!object)
|
||||
{
|
||||
att.resp_id = oid;
|
||||
failure_response(NO_EXISTS, att);
|
||||
@ -56,7 +56,7 @@ protected:
|
||||
return;
|
||||
}
|
||||
|
||||
if ( pool->drop(object, error) != 0 )
|
||||
if ( pool->drop(object.get(), error) != 0 )
|
||||
{
|
||||
att.resp_msg = error;
|
||||
failure_response(ACTION, att);
|
||||
@ -66,8 +66,6 @@ protected:
|
||||
success_response(oid, att);
|
||||
}
|
||||
|
||||
object->unlock();
|
||||
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
@ -65,7 +65,7 @@ protected:
|
||||
ErrorCode request_execute(int oid, const std::string& xml,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
PoolObjectSQL * object = pool->get(oid);
|
||||
auto object = pool->get<PoolObjectSQL>(oid);
|
||||
|
||||
if ( object == 0 )
|
||||
{
|
||||
@ -80,7 +80,6 @@ protected:
|
||||
if ( object->from_xml(xml) != 0 )
|
||||
{
|
||||
object->from_xml(old_xml);
|
||||
object->unlock();
|
||||
|
||||
att.resp_msg = "Cannot update object from XML";
|
||||
return INTERNAL;
|
||||
@ -89,15 +88,12 @@ protected:
|
||||
if ( object->get_oid() != oid )
|
||||
{
|
||||
object->from_xml(old_xml);
|
||||
object->unlock();
|
||||
|
||||
att.resp_msg = "Consistency check failed";
|
||||
return INTERNAL;
|
||||
}
|
||||
|
||||
pool->update(object);
|
||||
|
||||
object->unlock();
|
||||
pool->update(object.get());
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
@ -101,9 +101,9 @@ protected:
|
||||
int ds_id,
|
||||
RequestAttributes& att);
|
||||
|
||||
VirtualMachine * get_vm(int id, RequestAttributes& att);
|
||||
std::unique_ptr<VirtualMachine> get_vm(int id, RequestAttributes& att);
|
||||
|
||||
VirtualMachine * get_vm_ro(int id, RequestAttributes& att);
|
||||
std::unique_ptr<VirtualMachine> get_vm_ro(int id, RequestAttributes& att);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
@ -27,6 +27,8 @@ class SecurityGroup : public PoolObjectSQL
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~SecurityGroup() = default;
|
||||
|
||||
/**
|
||||
* Function to print the SecurityGroup object into a string in XML format
|
||||
* @param xml the resulting XML string
|
||||
@ -171,8 +173,6 @@ private:
|
||||
int _umask,
|
||||
Template* sgroup_template);
|
||||
|
||||
virtual ~SecurityGroup() = default;
|
||||
|
||||
/**
|
||||
* Check that a rule is valid
|
||||
* @param rule as a VectorAttribute
|
||||
|
@ -60,27 +60,27 @@ public:
|
||||
std::string& error_str);
|
||||
|
||||
/**
|
||||
* Function to get a SecurityGroup from the pool, if the object is not in memory
|
||||
* it is loaded from the DB
|
||||
* @param oid SecurityGroup unique id
|
||||
* @param lock locks the SecurityGroup mutex
|
||||
* @return a pointer to the SecurityGroup, 0 if the SecurityGroup could not be loaded
|
||||
* Gets an object from the pool (if needed the object is loaded from the
|
||||
* database). The object is locked, other threads can't access the same
|
||||
* object. The lock is released by destructor.
|
||||
* @param oid the SecurityGroup unique identifier
|
||||
* @return a pointer to the SecurityGroup, nullptr in case of failure
|
||||
*/
|
||||
SecurityGroup * get(int oid)
|
||||
std::unique_ptr<SecurityGroup> get(int oid)
|
||||
{
|
||||
return static_cast<SecurityGroup *>(PoolSQL::get(oid));
|
||||
};
|
||||
return PoolSQL::get<SecurityGroup>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get a read only SecurityGroup from the pool, if the object is not in memory
|
||||
* it is loaded from the DB
|
||||
* @param oid SecurityGroup unique id
|
||||
* @return a pointer to the SecurityGroup, 0 if the SecurityGroup could not be loaded
|
||||
* Gets a read only object from the pool (if needed the object is loaded from the
|
||||
* database). No object lock, other threads may work with the same object.
|
||||
* @param oid the SecurityGroup unique identifier
|
||||
* @return a pointer to the SecurityGroup, nullptr in case of failure
|
||||
*/
|
||||
SecurityGroup * get_ro(int oid)
|
||||
std::unique_ptr<SecurityGroup> get_ro(int oid)
|
||||
{
|
||||
return static_cast<SecurityGroup *>(PoolSQL::get_ro(oid));
|
||||
};
|
||||
return PoolSQL::get_ro<SecurityGroup>(oid);
|
||||
}
|
||||
|
||||
/** Update a particular SecurityGroup
|
||||
* @param securitygroup pointer to SecurityGroup
|
||||
|
@ -35,6 +35,8 @@ class User : public PoolObjectSQL
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~User() = default;
|
||||
|
||||
/**
|
||||
* Characters that can not be in a name
|
||||
*/
|
||||
@ -267,6 +269,7 @@ private:
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
friend class UserPool;
|
||||
friend class PoolSQL;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// User Attributes
|
||||
@ -326,6 +329,7 @@ private:
|
||||
return db->exec_local_wr(oss_user);
|
||||
}
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Reads the User (identified with its OID) from the database.
|
||||
* @param db pointer to the db
|
||||
@ -391,8 +395,6 @@ protected:
|
||||
obj_template = new UserTemplate;
|
||||
}
|
||||
|
||||
virtual ~User() = default;
|
||||
|
||||
// *************************************************************************
|
||||
// DataBase implementation
|
||||
// *************************************************************************
|
||||
|
@ -70,80 +70,80 @@ public:
|
||||
int drop(PoolObjectSQL * objsql, std::string& error_msg);
|
||||
|
||||
/**
|
||||
* Function to get a User from the pool, if the object is not in memory
|
||||
* it is loaded from the DB
|
||||
* @param oid User unique id
|
||||
* @param lock locks the User mutex
|
||||
* @return a pointer to the User, 0 if the User could not be loaded
|
||||
* Gets an object from the pool (if needed the object is loaded from the
|
||||
* database). The object is locked, other threads can't access the same
|
||||
* object. The lock is released by destructor.
|
||||
* @param oid the User unique identifier
|
||||
* @return a pointer to the User, nullptr in case of failure
|
||||
*/
|
||||
User * get(int oid)
|
||||
std::unique_ptr<User> get(int oid)
|
||||
{
|
||||
User * u = static_cast<User *>(PoolSQL::get(oid));
|
||||
auto u = PoolSQL::get<User>(oid);
|
||||
|
||||
if ( u != 0 )
|
||||
if (u)
|
||||
{
|
||||
u->session = get_session_token(oid);
|
||||
}
|
||||
|
||||
return u;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get a read only User from the pool, if the object is not in memory
|
||||
* it is loaded from the DB
|
||||
* @param oid User unique id
|
||||
* @return a pointer to the User, 0 if the User could not be loaded
|
||||
* Gets a read only object from the pool (if needed the object is loaded from the
|
||||
* database). No object lock, other threads may work with the same object.
|
||||
* @param oid the User unique identifier
|
||||
* @return a pointer to the User, nullptr in case of failure
|
||||
*/
|
||||
User * get_ro(int oid)
|
||||
std::unique_ptr<User> get_ro(int oid)
|
||||
{
|
||||
User * u = static_cast<User *>(PoolSQL::get_ro(oid));
|
||||
auto u = PoolSQL::get_ro<User>(oid);
|
||||
|
||||
if ( u != 0 )
|
||||
if (u)
|
||||
{
|
||||
u->session = get_session_token(oid);
|
||||
}
|
||||
|
||||
return u;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get a User from the pool, if the object is not in memory
|
||||
* it is loaded from the DB
|
||||
* Gets an object from the pool (if needed the object is loaded from the
|
||||
* database). The object is locked, other threads can't access the same
|
||||
* object. The lock is released by destructor.
|
||||
* @param username
|
||||
* @param lock locks the User mutex
|
||||
* @return a pointer to the User, 0 if the User could not be loaded
|
||||
*/
|
||||
User * get(std::string name)
|
||||
std::unique_ptr<User> get(std::string name)
|
||||
{
|
||||
// The owner is set to -1, because it is not used in the key() method
|
||||
User * u = static_cast<User *>(PoolSQL::get(name,-1));
|
||||
auto u = PoolSQL::get<User>(name,-1);
|
||||
|
||||
if ( u != 0 )
|
||||
if (u)
|
||||
{
|
||||
u->session = get_session_token(u->oid);
|
||||
}
|
||||
|
||||
return u;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get a read only User from the pool, if the object is not in memory
|
||||
* it is loaded from the DB
|
||||
* Gets a read only object from the pool (if needed the object is loaded from the
|
||||
* database). No object lock, other threads may work with the same object.
|
||||
* @param username
|
||||
* @return a pointer to the User, 0 if the User could not be loaded
|
||||
*/
|
||||
User * get_ro(std::string name)
|
||||
std::unique_ptr<User> get_ro(std::string name)
|
||||
{
|
||||
// The owner is set to -1, because it is not used in the key() method
|
||||
User * u = static_cast<User *>(PoolSQL::get_ro(name,-1));
|
||||
auto u = PoolSQL::get_ro<User>(name, -1);
|
||||
|
||||
if ( u != 0 )
|
||||
if (u)
|
||||
{
|
||||
u->session = get_session_token(u->oid);
|
||||
}
|
||||
|
||||
return u;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get the token password of an user from the pool
|
||||
@ -275,7 +275,7 @@ private:
|
||||
/**
|
||||
* Function to authenticate internal (known) users
|
||||
*/
|
||||
bool authenticate_internal(User * user,
|
||||
bool authenticate_internal(std::unique_ptr<User> user,
|
||||
const std::string& token,
|
||||
std::string& password,
|
||||
int& user_id,
|
||||
@ -288,7 +288,7 @@ private:
|
||||
/**
|
||||
* Function to authenticate internal users using a server driver
|
||||
*/
|
||||
bool authenticate_server(User * user,
|
||||
bool authenticate_server(std::unique_ptr<User> user,
|
||||
const std::string& token,
|
||||
std::string& password,
|
||||
int& user_id,
|
||||
|
@ -51,6 +51,8 @@ enum class VMGroupPolicy;
|
||||
class VMGroup : public PoolObjectSQL
|
||||
{
|
||||
public:
|
||||
virtual ~VMGroup() = default;
|
||||
|
||||
/**
|
||||
* Function to print the VMGroup object into a string in XML format
|
||||
* @param xml the resulting XML string
|
||||
@ -114,8 +116,6 @@ private:
|
||||
const std::string& _uname, const std::string& _gname,
|
||||
int _umask, Template * group_template);
|
||||
|
||||
virtual ~VMGroup() = default;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Role Management
|
||||
// -------------------------------------------------------------------------
|
||||
|
@ -53,30 +53,30 @@ public:
|
||||
std::string& error_str);
|
||||
|
||||
/**
|
||||
* Function to get a VMGroup from the pool, if the object is not in memory
|
||||
* it is loaded from the DB
|
||||
* @param oid VMGroup unique id
|
||||
* @param lock locks the VMGroup mutex
|
||||
* @return a pointer to the VMGroup, 0 if the VMGroup could not be loaded
|
||||
* Gets an object from the pool (if needed the object is loaded from the
|
||||
* database). The object is locked, other threads can't access the same
|
||||
* object. The lock is released by destructor.
|
||||
* @param oid the VMGroup unique identifier
|
||||
* @return a pointer to the VMGroup, nullptr in case of failure
|
||||
*/
|
||||
VMGroup * get(int oid)
|
||||
std::unique_ptr<VMGroup> get(int oid)
|
||||
{
|
||||
return static_cast<VMGroup *>(PoolSQL::get(oid));
|
||||
};
|
||||
return PoolSQL::get<VMGroup>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an object from the pool (if needed the object is loaded from the
|
||||
* database).
|
||||
* database). The object is locked, other threads can't access the same
|
||||
* object. The lock is released by destructor.
|
||||
* @param name of the object
|
||||
* @param uid id of owner
|
||||
* @param lock locks the object if true
|
||||
*
|
||||
* @return a pointer to the object, 0 in case of failure
|
||||
*/
|
||||
VMGroup * get(const std::string& name, int uid)
|
||||
std::unique_ptr<VMGroup> get(const std::string& name, int uid)
|
||||
{
|
||||
return static_cast<VMGroup *>(PoolSQL::get(name, uid));
|
||||
};
|
||||
return PoolSQL::get<VMGroup>(name, uid);
|
||||
}
|
||||
|
||||
/** Update a VMGroup
|
||||
* @param vmgroup pointer to VMGroup
|
||||
@ -155,7 +155,8 @@ private:
|
||||
* @param va the VectorAttribute
|
||||
* @param _uid default uid to look for the VMGroup
|
||||
*/
|
||||
VMGroup * get_from_attribute(const VectorAttribute *va, int _uid);
|
||||
std::unique_ptr<VMGroup> get_from_attribute(const VectorAttribute *va,
|
||||
int _uid);
|
||||
};
|
||||
|
||||
#endif /*VMGROUP_POOL_H_*/
|
||||
|
@ -30,6 +30,8 @@ class VMTemplate : public PoolObjectSQL
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~VMTemplate() = default;
|
||||
|
||||
/**
|
||||
* Function to print the VMTemplate object into a string in XML format
|
||||
* @param xml the resulting XML string
|
||||
@ -179,8 +181,6 @@ protected:
|
||||
int umask,
|
||||
VirtualMachineTemplate * _template_contents);
|
||||
|
||||
virtual ~VMTemplate() = default;
|
||||
|
||||
// *************************************************************************
|
||||
// DataBase implementation
|
||||
// *************************************************************************
|
||||
|
@ -57,28 +57,26 @@ public:
|
||||
|
||||
/**
|
||||
* Gets an object from the pool (if needed the object is loaded from the
|
||||
* database).
|
||||
* @param oid the object unique identifier
|
||||
* @param lock locks the object if true
|
||||
*
|
||||
* @return a pointer to the object, 0 in case of failure
|
||||
* database). The object is locked, other threads can't access the same
|
||||
* object. The lock is released by destructor.
|
||||
* @param oid the VMTemplate unique identifier
|
||||
* @return a pointer to the VMTemplate, nullptr in case of failure
|
||||
*/
|
||||
VMTemplate * get(int oid)
|
||||
std::unique_ptr<VMTemplate> get(int oid)
|
||||
{
|
||||
return static_cast<VMTemplate *>(PoolSQL::get(oid));
|
||||
};
|
||||
return PoolSQL::get<VMTemplate>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an object from the pool (if needed the object is loaded from the
|
||||
* database).
|
||||
* @param oid the object unique identifier
|
||||
*
|
||||
* @return a pointer to the object, 0 in case of failure
|
||||
* Gets a read only object from the pool (if needed the object is loaded from the
|
||||
* database). No object lock, other threads may work with the same object.
|
||||
* @param oid the VMTemplate unique identifier
|
||||
* @return a pointer to the VMTemplate, nullptr in case of failure
|
||||
*/
|
||||
VMTemplate * get_ro(int oid)
|
||||
std::unique_ptr<VMTemplate> get_ro(int oid)
|
||||
{
|
||||
return static_cast<VMTemplate *>(PoolSQL::get_ro(oid));
|
||||
};
|
||||
return PoolSQL::get_ro<VMTemplate>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps the pool in XML format. A filter can be also added to the
|
||||
|
@ -30,6 +30,8 @@ class VNTemplate : public PoolObjectSQL
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~VNTemplate() = default;
|
||||
|
||||
/**
|
||||
* Function to print the VNTemplate object into a string in XML format
|
||||
* @param xml the resulting XML string
|
||||
@ -115,8 +117,6 @@ protected:
|
||||
int umask,
|
||||
VirtualNetworkTemplate * _template_contents);
|
||||
|
||||
virtual ~VNTemplate() = default;
|
||||
|
||||
// *************************************************************************
|
||||
// DataBase implementation
|
||||
// *************************************************************************
|
||||
|
@ -57,28 +57,26 @@ public:
|
||||
|
||||
/**
|
||||
* Gets an object from the pool (if needed the object is loaded from the
|
||||
* database).
|
||||
* @param oid the object unique identifier
|
||||
* @param lock locks the object if true
|
||||
*
|
||||
* @return a pointer to the object, 0 in case of failure
|
||||
* database). The object is locked, other threads can't access the same
|
||||
* object. The lock is released by destructor.
|
||||
* @param oid theVNTemplate unique identifier
|
||||
* @return a pointer to the VNTemplate, nullptr in case of failure
|
||||
*/
|
||||
VNTemplate * get(int oid)
|
||||
std::unique_ptr<VNTemplate> get(int oid)
|
||||
{
|
||||
return static_cast<VNTemplate *>(PoolSQL::get(oid));
|
||||
};
|
||||
return PoolSQL::get<VNTemplate>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an object from the pool (if needed the object is loaded from the
|
||||
* database).
|
||||
* @param oid the object unique identifier
|
||||
*
|
||||
* @return a pointer to the object, 0 in case of failure
|
||||
* Gets a read only object from the pool (if needed the object is loaded from the
|
||||
* database). No object lock, other threads may work with the same object.
|
||||
* @param oid the VNTemplate unique identifier
|
||||
* @return a pointer to the VNTemplate, nullptr in case of failure
|
||||
*/
|
||||
VNTemplate * get_ro(int oid)
|
||||
std::unique_ptr<VNTemplate> get_ro(int oid)
|
||||
{
|
||||
return static_cast<VNTemplate *>(PoolSQL::get_ro(oid));
|
||||
};
|
||||
return PoolSQL::get_ro<VNTemplate>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps the pool in XML format. A filter can be also added to the
|
||||
|
@ -155,6 +155,8 @@ class Vdc : public PoolObjectSQL
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~Vdc() = default;
|
||||
|
||||
/**
|
||||
* Function to print the Vdc object into a string in XML format
|
||||
* @param xml the resulting XML string
|
||||
@ -322,8 +324,6 @@ private:
|
||||
|
||||
Vdc(int id, Template* vdc_template);
|
||||
|
||||
virtual ~Vdc() = default;
|
||||
|
||||
// *************************************************************************
|
||||
// Attributes (Private)
|
||||
// *************************************************************************
|
||||
|
@ -48,16 +48,16 @@ public:
|
||||
std::string& error_str);
|
||||
|
||||
/**
|
||||
* Function to get a Vdc from the pool, if the object is not in memory
|
||||
* it is loaded from the DB
|
||||
* @param oid Vdc unique id
|
||||
* @param lock locks the Vdc mutex
|
||||
* @return a pointer to the Vdc, 0 if the Vdc could not be loaded
|
||||
* Gets an object from the pool (if needed the object is loaded from the
|
||||
* database). The object is locked, other threads can't access the same
|
||||
* object. The lock is released by destructor.
|
||||
* @param oid the Vdc unique identifier
|
||||
* @return a pointer to the Vdc, nullptr in case of failure
|
||||
*/
|
||||
Vdc * get(int oid)
|
||||
std::unique_ptr<Vdc> get(int oid)
|
||||
{
|
||||
return static_cast<Vdc *>(PoolSQL::get(oid));
|
||||
};
|
||||
return PoolSQL::get<Vdc>(oid);
|
||||
}
|
||||
|
||||
/** Update a particular Vdc
|
||||
* @param vdc pointer to Vdc
|
||||
|
@ -149,6 +149,8 @@ public:
|
||||
|
||||
static std::string& lcm_state_to_str(std::string& st, LcmState state);
|
||||
|
||||
virtual ~VirtualMachine();
|
||||
|
||||
/**
|
||||
* Returns the VM state to string, using the lcm state if the current state
|
||||
* is ACTIVE.
|
||||
@ -1301,9 +1303,9 @@ public:
|
||||
{
|
||||
VirtualMachineDisk * disk = disks.delete_attach();
|
||||
|
||||
if (disk == 0)
|
||||
if (disk == nullptr)
|
||||
{
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
obj_template->remove(disk->vector_attribute());
|
||||
@ -1642,6 +1644,7 @@ private:
|
||||
// Friends
|
||||
// -------------------------------------------------------------------------
|
||||
friend class VirtualMachinePool;
|
||||
friend class PoolSQL;
|
||||
|
||||
// *************************************************************************
|
||||
// Virtual Machine Attributes
|
||||
@ -2147,8 +2150,6 @@ protected:
|
||||
int umask,
|
||||
VirtualMachineTemplate * _vm_template);
|
||||
|
||||
virtual ~VirtualMachine();
|
||||
|
||||
// *************************************************************************
|
||||
// DataBase implementation
|
||||
// *************************************************************************
|
||||
|
@ -184,7 +184,7 @@ protected:
|
||||
template<typename T>
|
||||
bool get_attribute(const VirtualMachine * vm,
|
||||
const Host * host,
|
||||
const Cluster* cluster,
|
||||
const Cluster * cluster,
|
||||
const std::string& name,
|
||||
const std::string& vname,
|
||||
T& value) const
|
||||
|
@ -67,34 +67,32 @@ public:
|
||||
bool on_hold = false);
|
||||
|
||||
/**
|
||||
* Function to get a VM from the pool, if the object is not in memory
|
||||
* it is loade from the DB
|
||||
* @param oid VM unique id
|
||||
* @param lock locks the VM mutex
|
||||
* @return a pointer to the VM, 0 if the VM could not be loaded
|
||||
* Gets an object from the pool (if needed the object is loaded from the
|
||||
* database). The object is locked, other threads can't access the same
|
||||
* object. The lock is released by destructor.
|
||||
* @param oid the VM unique identifier
|
||||
* @return a pointer to the VM, nullptr in case of failure
|
||||
*/
|
||||
VirtualMachine * get(
|
||||
int oid)
|
||||
std::unique_ptr<VirtualMachine> get(int oid)
|
||||
{
|
||||
return static_cast<VirtualMachine *>(PoolSQL::get(oid));
|
||||
};
|
||||
return PoolSQL::get<VirtualMachine>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get a read only VM from the pool, if the object is not
|
||||
* in memory it is loade from the DB
|
||||
* @param oid VM unique id
|
||||
* @return a pointer to the VM, 0 if the VM could not be loaded
|
||||
* Gets a read only object from the pool (if needed the object is loaded from the
|
||||
* database). No object lock, other threads may work with the same object.
|
||||
* @param oid the VM unique identifier
|
||||
* @return a pointer to the VM, nullptr in case of failure
|
||||
*/
|
||||
VirtualMachine * get_ro(
|
||||
int oid)
|
||||
std::unique_ptr<VirtualMachine> get_ro(int oid)
|
||||
{
|
||||
return static_cast<VirtualMachine *>(PoolSQL::get_ro(oid));
|
||||
};
|
||||
return PoolSQL::get_ro<VirtualMachine>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get a VM from the pool, string version for VM ID
|
||||
*/
|
||||
VirtualMachine * get(const std::string& oid_s)
|
||||
std::unique_ptr<VirtualMachine> get(const std::string& oid_s)
|
||||
{
|
||||
std::istringstream iss(oid_s);
|
||||
int oid;
|
||||
@ -106,13 +104,13 @@ public:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return static_cast<VirtualMachine *>(PoolSQL::get(oid));
|
||||
};
|
||||
return PoolSQL::get<VirtualMachine>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to get a read only VM from the pool, string version for VM ID
|
||||
*/
|
||||
VirtualMachine * get_ro(const std::string& oid_s)
|
||||
std::unique_ptr<VirtualMachine> get_ro(const std::string& oid_s)
|
||||
{
|
||||
std::istringstream iss(oid_s);
|
||||
int oid;
|
||||
@ -124,8 +122,8 @@ public:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return static_cast<VirtualMachine *>(PoolSQL::get_ro(oid));
|
||||
};
|
||||
return PoolSQL::get_ro<VirtualMachine>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a VM in the data base. The VM SHOULD be locked. It also updates
|
||||
@ -375,16 +373,16 @@ public:
|
||||
* Deletes the DISK that was in the process of being attached. Releases
|
||||
* Images and updates usage quotas
|
||||
*
|
||||
* @param vid VM id
|
||||
* @param vm unique_ptr to VM, will be release in the method
|
||||
*/
|
||||
void delete_attach_disk(int vid);
|
||||
void delete_attach_disk(std::unique_ptr<VirtualMachine> vm);
|
||||
|
||||
/**
|
||||
* Deletes the NIC that was in the process of being attached/detached
|
||||
*
|
||||
* @param vid VM id
|
||||
* @param vm unique_ptr to VM, will be release in the method
|
||||
*/
|
||||
void delete_attach_nic(int vid);
|
||||
void delete_attach_nic(std::unique_ptr<VirtualMachine> vm);
|
||||
|
||||
/**
|
||||
* Deletes an entry in the HV-2-vmid mapping table for imported VMs
|
||||
|
@ -197,6 +197,8 @@ public:
|
||||
// Virtual Network Public Methods
|
||||
// *************************************************************************
|
||||
|
||||
virtual ~VirtualNetwork() = default;
|
||||
|
||||
/**
|
||||
* Factory method for virtual network templates
|
||||
*/
|
||||
@ -808,8 +810,6 @@ private:
|
||||
const std::set<int> &_cluster_ids,
|
||||
VirtualNetworkTemplate * _vn_template = 0);
|
||||
|
||||
virtual ~VirtualNetwork() = default;
|
||||
|
||||
// *************************************************************************
|
||||
// DataBase implementation
|
||||
// *************************************************************************
|
||||
|
@ -81,57 +81,55 @@ public:
|
||||
return PoolSQL::drop(vn, error_msg);
|
||||
};
|
||||
|
||||
/**
|
||||
* Function to get a VN from the pool, if the object is not in memory
|
||||
* it is loaded from the DB
|
||||
* @param oid VN unique id
|
||||
* @param lock locks the VN mutex
|
||||
* @return a pointer to the VN, 0 if the VN could not be loaded
|
||||
*/
|
||||
VirtualNetwork * get(int oid)
|
||||
{
|
||||
return static_cast<VirtualNetwork *>(PoolSQL::get(oid));
|
||||
};
|
||||
|
||||
/**
|
||||
* Function to get a read only VN from the pool, if the object is not in memory
|
||||
* it is loaded from the DB
|
||||
* @param oid VN unique id
|
||||
* @param lock locks the VN mutex
|
||||
* @return a pointer to the VN, 0 if the VN could not be loaded
|
||||
*/
|
||||
VirtualNetwork * get_ro(int oid)
|
||||
{
|
||||
return static_cast<VirtualNetwork *>(PoolSQL::get_ro(oid));
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets an object from the pool (if needed the object is loaded from the
|
||||
* database).
|
||||
* @param name of the object
|
||||
* @param uid id of owner
|
||||
* @param lock locks the object if true
|
||||
*
|
||||
* @return a pointer to the object, 0 in case of failure
|
||||
* database). The object is locked, other threads can't access the same
|
||||
* object. The lock is released by destructor.
|
||||
* @param oid the VN unique identifier
|
||||
* @return a pointer to the VN, nullptr in case of failure
|
||||
*/
|
||||
VirtualNetwork * get(const std::string& name, int uid)
|
||||
std::unique_ptr<VirtualNetwork> get(int oid)
|
||||
{
|
||||
return static_cast<VirtualNetwork *>(PoolSQL::get(name,uid));
|
||||
};
|
||||
return PoolSQL::get<VirtualNetwork>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a read only object from the pool (if needed the object is loaded from the
|
||||
* database).
|
||||
* database). No object lock, other threads may work with the same object.
|
||||
* @param oid the VN unique identifier
|
||||
* @return a pointer to the VN, nullptr in case of failure
|
||||
*/
|
||||
std::unique_ptr<VirtualNetwork> get_ro(int oid)
|
||||
{
|
||||
return PoolSQL::get_ro<VirtualNetwork>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an object from the pool (if needed the object is loaded from the
|
||||
* database). The object is locked, other threads can't access the same
|
||||
* object. The lock is released by destructor.
|
||||
* @param name of the object
|
||||
* @param uid id of owner
|
||||
* @param lock locks the object if true
|
||||
*
|
||||
* @return a pointer to the object, 0 in case of failure
|
||||
*/
|
||||
VirtualNetwork * get_ro(const std::string& name, int uid)
|
||||
std::unique_ptr<VirtualNetwork> get(const std::string& name, int uid)
|
||||
{
|
||||
return static_cast<VirtualNetwork *>(PoolSQL::get_ro(name,uid));
|
||||
};
|
||||
return PoolSQL::get<VirtualNetwork>(name,uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a read only object from the pool (if needed the object is loaded from the
|
||||
* database). No object lock, other threads may work with the same object.
|
||||
* @param name of the object
|
||||
* @param uid id of owner
|
||||
*
|
||||
* @return a pointer to the object, 0 in case of failure
|
||||
*/
|
||||
std::unique_ptr<VirtualNetwork> get_ro(const std::string& name, int uid)
|
||||
{
|
||||
return PoolSQL::get_ro<VirtualNetwork>(name,uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstraps the database table(s) associated to the VirtualNetwork pool
|
||||
@ -322,7 +320,7 @@ private:
|
||||
* Function to get a VirtualNetwork by its name, as provided by a VM
|
||||
* template
|
||||
*/
|
||||
VirtualNetwork * get_nic_by_name(VirtualMachineNic * nic,
|
||||
std::unique_ptr<VirtualNetwork> get_nic_by_name(VirtualMachineNic * nic,
|
||||
const std::string& name,
|
||||
int _uidi,
|
||||
bool ro,
|
||||
@ -330,7 +328,8 @@ private:
|
||||
/**
|
||||
* Function to get a VirtualNetwork by its id, as provided by a VM template
|
||||
*/
|
||||
VirtualNetwork * get_nic_by_id(const std::string& id_s, bool ro,
|
||||
std::unique_ptr<VirtualNetwork> get_nic_by_id(const std::string& id_s,
|
||||
bool ro,
|
||||
std::string& error);
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
@ -34,6 +34,8 @@ class VirtualRouter : public PoolObjectSQL
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~VirtualRouter() = default;
|
||||
|
||||
/**
|
||||
* Function to print the VirtualRouter object into a string in XML format
|
||||
* @param xml the resulting XML string
|
||||
@ -225,8 +227,6 @@ private:
|
||||
int umask,
|
||||
Template * _template_contents);
|
||||
|
||||
virtual ~VirtualRouter() = default;
|
||||
|
||||
// *************************************************************************
|
||||
// DataBase implementation
|
||||
// *************************************************************************
|
||||
|
@ -64,29 +64,26 @@ public:
|
||||
|
||||
/**
|
||||
* Gets an object from the pool (if needed the object is loaded from the
|
||||
* database).
|
||||
* @param oid the object unique identifier
|
||||
* @param lock locks the object if true
|
||||
*
|
||||
* @return a pointer to the object, 0 in case of failure
|
||||
* database). The object is locked, other threads can't access the same
|
||||
* object. The lock is released by destructor.
|
||||
* @param oid the VirtualRouter unique identifier
|
||||
* @return a pointer to the VirtualRouter, nullptr in case of failure
|
||||
*/
|
||||
VirtualRouter * get(int oid)
|
||||
std::unique_ptr<VirtualRouter> get(int oid)
|
||||
{
|
||||
return static_cast<VirtualRouter *>(PoolSQL::get(oid));
|
||||
};
|
||||
return PoolSQL::get<VirtualRouter>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a read only object from the pool (if needed the object is loaded from the
|
||||
* database).
|
||||
* @param oid the object unique identifier
|
||||
* @param lock locks the object if true
|
||||
*
|
||||
* @return a pointer to the object, 0 in case of failure
|
||||
* database). No object lock, other threads may work with the same object.
|
||||
* @param oid the VirtualRouter unique identifier
|
||||
* @return a pointer to the VirtualRouter, nullptr in case of failure
|
||||
*/
|
||||
VirtualRouter * get_ro(int oid)
|
||||
std::unique_ptr<VirtualRouter> get_ro(int oid)
|
||||
{
|
||||
return static_cast<VirtualRouter *>(PoolSQL::get_ro(oid));
|
||||
};
|
||||
return PoolSQL::get_ro<VirtualRouter>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps the pool in XML format. A filter can be also added to the
|
||||
|
@ -28,6 +28,7 @@ class ZoneServer;
|
||||
class Zone : public PoolObjectSQL
|
||||
{
|
||||
public:
|
||||
virtual ~Zone();
|
||||
|
||||
/**
|
||||
* Function to print the Zone object into a string in XML format
|
||||
@ -95,8 +96,6 @@ private:
|
||||
// -------------------------------------------------------------------------
|
||||
Zone(int id, Template* zone_template);
|
||||
|
||||
virtual ~Zone();
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Zone servers
|
||||
// -------------------------------------------------------------------------
|
||||
|
@ -48,16 +48,27 @@ public:
|
||||
std::string& error_str);
|
||||
|
||||
/**
|
||||
* Function to get a Zone from the pool, if the object is not in memory
|
||||
* it is loaded from the DB
|
||||
* @param oid Zone unique id
|
||||
* @param lock locks the Zone mutex
|
||||
* @return a pointer to the Zone, 0 if the Zone could not be loaded
|
||||
* Gets an object from the pool (if needed the object is loaded from the
|
||||
* database). The object is locked, other threads can't access the same
|
||||
* object. The lock is released by destructor.
|
||||
* @param oid the Zone unique identifier
|
||||
* @return a pointer to the Zone, nullptr in case of failure
|
||||
*/
|
||||
Zone * get(int oid)
|
||||
std::unique_ptr<Zone> get(int oid)
|
||||
{
|
||||
return static_cast<Zone *>(PoolSQL::get(oid));
|
||||
};
|
||||
return PoolSQL::get<Zone>(oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a read only object from the pool (if needed the object is loaded from the
|
||||
* database). No object lock, other threads may work with the same object.
|
||||
* @param oid the Zone unique identifier
|
||||
* @return a pointer to the Zone, nullptr in case of failure
|
||||
*/
|
||||
std::unique_ptr<Zone> get_ro(int oid)
|
||||
{
|
||||
return PoolSQL::get_ro<Zone>(oid);
|
||||
}
|
||||
|
||||
/** Update a particular Zone
|
||||
* @param zone pointer to Zone
|
||||
|
@ -99,25 +99,16 @@ int Cluster::get_default_system_ds(const set<int>& ds_set)
|
||||
Nebula& nd = Nebula::instance();
|
||||
|
||||
DatastorePool* dspool = nd.get_dspool();
|
||||
Datastore* ds;
|
||||
|
||||
for (set<int>::const_iterator it = ds_set.begin(); it != ds_set.end(); it++)
|
||||
for (auto dsid : ds_set)
|
||||
{
|
||||
ds = dspool->get_ro(*it);
|
||||
|
||||
if (ds == 0)
|
||||
if ( auto ds = dspool->get_ro(dsid) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ds->get_type() == Datastore::SYSTEM_DS)
|
||||
{
|
||||
ds->unlock();
|
||||
|
||||
return *it;
|
||||
return dsid;
|
||||
}
|
||||
}
|
||||
|
||||
ds->unlock();
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
@ -57,26 +57,24 @@ ClusterPool::ClusterPool(SqlDB * db,
|
||||
|
||||
allocate(DEFAULT_CLUSTER_NAME, &rc, error_str);
|
||||
|
||||
if( rc != DEFAULT_CLUSTER_ID )
|
||||
if (rc != DEFAULT_CLUSTER_ID)
|
||||
{
|
||||
goto error_bootstrap;
|
||||
}
|
||||
|
||||
Cluster* cluster = get(DEFAULT_CLUSTER_ID);
|
||||
auto cluster = get(DEFAULT_CLUSTER_ID);
|
||||
|
||||
if (cluster == 0)
|
||||
if (!cluster)
|
||||
{
|
||||
goto error_bootstrap;
|
||||
}
|
||||
|
||||
add_to_cluster(PoolObjectSQL::DATASTORE, cluster, DatastorePool::SYSTEM_DS_ID,
|
||||
error_str);
|
||||
add_to_cluster(PoolObjectSQL::DATASTORE, cluster, DatastorePool::DEFAULT_DS_ID,
|
||||
error_str);
|
||||
add_to_cluster(PoolObjectSQL::DATASTORE, cluster, DatastorePool::FILE_DS_ID,
|
||||
error_str);
|
||||
|
||||
cluster->unlock();
|
||||
add_to_cluster(PoolObjectSQL::DATASTORE, cluster.get(),
|
||||
DatastorePool::SYSTEM_DS_ID, error_str);
|
||||
add_to_cluster(PoolObjectSQL::DATASTORE, cluster.get(),
|
||||
DatastorePool::DEFAULT_DS_ID, error_str);
|
||||
add_to_cluster(PoolObjectSQL::DATASTORE, cluster.get(),
|
||||
DatastorePool::FILE_DS_ID, error_str);
|
||||
|
||||
// User created clusters will start from ID 100
|
||||
set_lastOID(99);
|
||||
|
@ -286,17 +286,15 @@ int DatastorePool::drop(PoolObjectSQL * objsql, string& error_msg)
|
||||
|
||||
int DatastorePool::disk_attribute(int ds_id, VirtualMachineDisk * disk)
|
||||
{
|
||||
Datastore * ds = get_ro(ds_id);
|
||||
auto ds = get_ro(ds_id);
|
||||
|
||||
if (ds == 0)
|
||||
if (!ds)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
ds->disk_attribute(disk, inherit_attrs);
|
||||
|
||||
ds->unlock();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -26,9 +26,9 @@ using namespace std;
|
||||
void DispatchManager::trigger_suspend_success(int vid)
|
||||
{
|
||||
trigger([this, vid] {
|
||||
VirtualMachine * vm = vmpool->get(vid);
|
||||
auto vm = vmpool->get(vid);
|
||||
|
||||
if (vm == nullptr)
|
||||
if (!vm)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -49,12 +49,12 @@ void DispatchManager::trigger_suspend_success(int vid)
|
||||
|
||||
vm->set_state(VirtualMachine::LCM_INIT);
|
||||
|
||||
vmpool->update(vm);
|
||||
vmpool->update(vm.get());
|
||||
|
||||
int uid = vm->get_uid();
|
||||
int gid = vm->get_gid();
|
||||
|
||||
vm->unlock();
|
||||
vm.reset();
|
||||
|
||||
Quotas::vm_del(uid, gid, "a_tmpl);
|
||||
}
|
||||
@ -66,7 +66,6 @@ void DispatchManager::trigger_suspend_success(int vid)
|
||||
<< " not in ACTIVE state";
|
||||
NebulaLog::log("DiM",Log::ERROR,oss);
|
||||
|
||||
vm->unlock();
|
||||
return;
|
||||
}
|
||||
});
|
||||
@ -78,9 +77,9 @@ void DispatchManager::trigger_suspend_success(int vid)
|
||||
void DispatchManager::trigger_stop_success(int vid)
|
||||
{
|
||||
trigger([this, vid] {
|
||||
VirtualMachine * vm = vmpool->get(vid);
|
||||
auto vm = vmpool->get(vid);
|
||||
|
||||
if (vm == nullptr)
|
||||
if (!vm)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -102,15 +101,15 @@ void DispatchManager::trigger_stop_success(int vid)
|
||||
{
|
||||
vm->set_internal_action(VMActions::STOP_ACTION);
|
||||
|
||||
vmpool->update_history(vm);
|
||||
vmpool->update_history(vm.get());
|
||||
}
|
||||
|
||||
vmpool->update(vm);
|
||||
vmpool->update(vm.get());
|
||||
|
||||
int uid = vm->get_uid();
|
||||
int gid = vm->get_gid();
|
||||
|
||||
vm->unlock();
|
||||
vm.reset();
|
||||
|
||||
Quotas::vm_del(uid, gid, "a_tmpl);
|
||||
}
|
||||
@ -121,7 +120,6 @@ void DispatchManager::trigger_stop_success(int vid)
|
||||
oss << "stop_success action received but VM " << vid
|
||||
<< " not in ACTIVE state";
|
||||
NebulaLog::log("DiM",Log::ERROR,oss);
|
||||
vm->unlock();
|
||||
return;
|
||||
}
|
||||
});
|
||||
@ -133,9 +131,9 @@ void DispatchManager::trigger_stop_success(int vid)
|
||||
void DispatchManager::trigger_undeploy_success(int vid)
|
||||
{
|
||||
trigger([this, vid] {
|
||||
VirtualMachine * vm = vmpool->get(vid);
|
||||
auto vm = vmpool->get(vid);
|
||||
|
||||
if (vm == nullptr)
|
||||
if (!vm)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -158,15 +156,15 @@ void DispatchManager::trigger_undeploy_success(int vid)
|
||||
{
|
||||
vm->set_internal_action(VMActions::UNDEPLOY_ACTION);
|
||||
|
||||
vmpool->update_history(vm);
|
||||
vmpool->update_history(vm.get());
|
||||
}
|
||||
|
||||
vmpool->update(vm);
|
||||
vmpool->update(vm.get());
|
||||
|
||||
int uid = vm->get_uid();
|
||||
int gid = vm->get_gid();
|
||||
|
||||
vm->unlock();
|
||||
vm.reset();
|
||||
|
||||
Quotas::vm_del(uid, gid, "a_tmpl);
|
||||
}
|
||||
@ -178,7 +176,6 @@ void DispatchManager::trigger_undeploy_success(int vid)
|
||||
<< " not in ACTIVE state";
|
||||
NebulaLog::log("DiM",Log::ERROR,oss);
|
||||
|
||||
vm->unlock();
|
||||
return;
|
||||
}
|
||||
});
|
||||
@ -190,9 +187,9 @@ void DispatchManager::trigger_undeploy_success(int vid)
|
||||
void DispatchManager::trigger_poweroff_success(int vid)
|
||||
{
|
||||
trigger([this, vid] {
|
||||
VirtualMachine * vm = vmpool->get(vid);
|
||||
auto vm = vmpool->get(vid);
|
||||
|
||||
if (vm == nullptr)
|
||||
if (!vm)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -219,12 +216,12 @@ void DispatchManager::trigger_poweroff_success(int vid)
|
||||
|
||||
vm->set_state(VirtualMachine::LCM_INIT);
|
||||
|
||||
vmpool->update(vm);
|
||||
vmpool->update(vm.get());
|
||||
|
||||
int uid = vm->get_uid();
|
||||
int gid = vm->get_gid();
|
||||
|
||||
vm->unlock();
|
||||
vm.reset();
|
||||
|
||||
if (prev_state != VirtualMachine::DISK_SNAPSHOT_POWEROFF &&
|
||||
prev_state != VirtualMachine::DISK_SNAPSHOT_REVERT_POWEROFF &&
|
||||
@ -241,7 +238,6 @@ void DispatchManager::trigger_poweroff_success(int vid)
|
||||
<< " not in ACTIVE state";
|
||||
NebulaLog::log("DiM",Log::ERROR,oss);
|
||||
|
||||
vm->unlock();
|
||||
return;
|
||||
}
|
||||
});
|
||||
@ -253,9 +249,9 @@ void DispatchManager::trigger_poweroff_success(int vid)
|
||||
void DispatchManager::trigger_done(int vid)
|
||||
{
|
||||
trigger([this, vid] {
|
||||
VirtualMachine * vm = vmpool->get(vid);
|
||||
auto vm = vmpool->get(vid);
|
||||
|
||||
if (vm == nullptr)
|
||||
if (!vm)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -267,7 +263,7 @@ void DispatchManager::trigger_done(int vid)
|
||||
(lcm_state == VirtualMachine::EPILOG ||
|
||||
lcm_state == VirtualMachine::CLEANUP_DELETE))
|
||||
{
|
||||
free_vm_resources(vm, true);
|
||||
free_vm_resources(std::move(vm), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -275,8 +271,6 @@ void DispatchManager::trigger_done(int vid)
|
||||
|
||||
oss << "done action received but VM " << vid << " not in ACTIVE state";
|
||||
NebulaLog::log("DiM",Log::ERROR,oss);
|
||||
|
||||
vm->unlock();
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -287,9 +281,9 @@ void DispatchManager::trigger_done(int vid)
|
||||
void DispatchManager::trigger_resubmit(int vid)
|
||||
{
|
||||
trigger([this, vid] {
|
||||
VirtualMachine * vm = vmpool->get(vid);
|
||||
auto vm = vmpool->get(vid);
|
||||
|
||||
if (vm == nullptr)
|
||||
if (!vm)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -304,9 +298,7 @@ void DispatchManager::trigger_resubmit(int vid)
|
||||
|
||||
vm->set_deploy_id(""); //reset the deploy-id
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
vm->unlock();
|
||||
vmpool->update(vm.get());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -503,12 +503,9 @@ void Host::reserved_capacity(string& rcpu, string& rmem) const
|
||||
{
|
||||
auto cpool = Nebula::instance().get_clpool();
|
||||
|
||||
Cluster * cluster = cpool->get_ro(cluster_id);
|
||||
|
||||
if (cluster != nullptr)
|
||||
if (auto cluster = cpool->get_ro(cluster_id))
|
||||
{
|
||||
cluster->get_reserved_capacity(cluster_rcpu, cluster_rmem);
|
||||
cluster->unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,18 +96,14 @@ int HostPool::allocate (
|
||||
|
||||
if (*oid >= 0)
|
||||
{
|
||||
host = get(*oid);
|
||||
|
||||
if (host != nullptr)
|
||||
if ( auto host = get(*oid) )
|
||||
{
|
||||
std::string event = HookStateHost::format_message(host);
|
||||
std::string event = HookStateHost::format_message(host.get());
|
||||
|
||||
Nebula::instance().get_hm()->trigger_send_event(event);
|
||||
|
||||
auto *im = Nebula::instance().get_im();
|
||||
im->update_host(host);
|
||||
|
||||
host->unlock();
|
||||
im->update_host(host.get());
|
||||
}
|
||||
}
|
||||
|
||||
@ -139,7 +135,7 @@ int HostPool::update(PoolObjectSQL * objsql)
|
||||
{
|
||||
Host * host = dynamic_cast<Host *>(objsql);
|
||||
|
||||
if ( host == 0 )
|
||||
if ( host == nullptr )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
@ -233,7 +233,7 @@ void InformationManager::_host_state(unique_ptr<im_msg_t> msg)
|
||||
return;
|
||||
}
|
||||
|
||||
Host* host = hpool->get(msg->oid());
|
||||
auto host = hpool->get(msg->oid());
|
||||
|
||||
if (host == nullptr)
|
||||
{
|
||||
@ -242,8 +242,6 @@ void InformationManager::_host_state(unique_ptr<im_msg_t> msg)
|
||||
|
||||
if (host->get_state() == Host::OFFLINE) // Should not receive any info
|
||||
{
|
||||
host->unlock();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -265,10 +263,8 @@ void InformationManager::_host_state(unique_ptr<im_msg_t> msg)
|
||||
host->set_state(new_state);
|
||||
}
|
||||
|
||||
hpool->update(host);
|
||||
hpool->update(host.get());
|
||||
}
|
||||
|
||||
host->unlock();
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -298,7 +294,7 @@ void InformationManager::_host_system(unique_ptr<im_msg_t> msg)
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
Host* host = hpool->get(msg->oid());
|
||||
auto host = hpool->get(msg->oid());
|
||||
|
||||
if (host == nullptr)
|
||||
{
|
||||
@ -307,7 +303,6 @@ void InformationManager::_host_system(unique_ptr<im_msg_t> msg)
|
||||
|
||||
if ( host->get_state() == Host::OFFLINE ) //Should not receive any info
|
||||
{
|
||||
host->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -315,12 +310,10 @@ void InformationManager::_host_system(unique_ptr<im_msg_t> msg)
|
||||
|
||||
host->update_info(tmpl);
|
||||
|
||||
hpool->update(host);
|
||||
hpool->update(host.get());
|
||||
|
||||
NebulaLog::debug("InM", "Host " + host->get_name() + " (" +
|
||||
to_string(host->get_oid()) + ") successfully monitored.");
|
||||
|
||||
host->unlock();
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -458,7 +451,7 @@ void InformationManager::_vm_state(unique_ptr<im_msg_t> msg)
|
||||
to_string(msg->oid()) + ". VM id: " + to_string(id) + ", state: " +
|
||||
state_str);
|
||||
|
||||
auto* vm = vmpool->get(id);
|
||||
auto vm = vmpool->get(id);
|
||||
|
||||
if (vm == nullptr)
|
||||
{
|
||||
@ -469,22 +462,19 @@ void InformationManager::_vm_state(unique_ptr<im_msg_t> msg)
|
||||
if (!vm->hasHistory() || vm->get_hid() != msg->oid())
|
||||
{
|
||||
//VM is not running in this host anymore, ignore
|
||||
vm->unlock();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (vm->get_deploy_id() != deploy_id)
|
||||
{
|
||||
vm->set_deploy_id(deploy_id);
|
||||
vmpool->update(vm);
|
||||
vmpool->update(vm.get());
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Apply state changes */
|
||||
/* ------------------------------------------------------------------ */
|
||||
test_and_trigger(state_str, vm);
|
||||
|
||||
vm->unlock();
|
||||
test_and_trigger(state_str, vm.get());
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@ -503,7 +493,7 @@ void InformationManager::_vm_state(unique_ptr<im_msg_t> msg)
|
||||
return;
|
||||
}
|
||||
|
||||
Host * host = hpool->get(msg->oid());
|
||||
auto host = hpool->get(msg->oid());
|
||||
|
||||
if (host == nullptr)
|
||||
{
|
||||
@ -522,11 +512,11 @@ void InformationManager::_vm_state(unique_ptr<im_msg_t> msg)
|
||||
|
||||
host->update_zombies(zombies);
|
||||
|
||||
host->unlock();
|
||||
host.reset();
|
||||
|
||||
for (auto& it : missing)
|
||||
{
|
||||
auto* vm = vmpool->get(it);
|
||||
auto vm = vmpool->get(it);
|
||||
|
||||
if (vm == nullptr)
|
||||
{
|
||||
@ -535,7 +525,6 @@ void InformationManager::_vm_state(unique_ptr<im_msg_t> msg)
|
||||
|
||||
if (!vm->hasHistory() || (vm->get_hid() != msg->oid()))
|
||||
{
|
||||
vm->unlock();
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -546,7 +535,6 @@ void InformationManager::_vm_state(unique_ptr<im_msg_t> msg)
|
||||
vm->get_lcm_state() != VirtualMachine::SHUTDOWN_POWEROFF &&
|
||||
vm->get_lcm_state() != VirtualMachine::SHUTDOWN_UNDEPLOY))
|
||||
{
|
||||
vm->unlock();
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -562,8 +550,6 @@ void InformationManager::_vm_state(unique_ptr<im_msg_t> msg)
|
||||
{
|
||||
lcm->trigger_monitor_poweroff(vm->get_oid());
|
||||
}
|
||||
|
||||
vm->unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -184,7 +184,7 @@ void ImageManager::monitor_datastore(int ds_id)
|
||||
|
||||
const auto* imd = get();
|
||||
|
||||
if ( imd == 0 )
|
||||
if ( imd == nullptr )
|
||||
{
|
||||
oss << "Error getting ImageManagerDriver";
|
||||
|
||||
@ -192,20 +192,18 @@ void ImageManager::monitor_datastore(int ds_id)
|
||||
return;
|
||||
}
|
||||
|
||||
Datastore * ds = dspool->get_ro(ds_id);
|
||||
|
||||
if ( ds == 0 )
|
||||
if ( auto ds = dspool->get_ro(ds_id) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ds->to_xml(ds_data);
|
||||
|
||||
shared = ds->is_shared();
|
||||
ds_type = ds->get_type();
|
||||
ds_name = ds->get_name();
|
||||
|
||||
ds->unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ds_location = "";
|
||||
|
||||
|
@ -28,29 +28,27 @@ using namespace std;
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
Image * ImageManager::acquire_image(int vm_id, int image_id, bool attach,
|
||||
string& error)
|
||||
unique_ptr<Image> ImageManager::acquire_image(int vm_id, int image_id,
|
||||
bool attach, string& error)
|
||||
{
|
||||
Image * img;
|
||||
int rc;
|
||||
|
||||
img = ipool->get(image_id);
|
||||
auto img = ipool->get(image_id);
|
||||
|
||||
if ( img == nullptr )
|
||||
if (!img)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Image with ID: " << image_id << " does not exist";
|
||||
|
||||
error = oss.str();
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
rc = acquire_image(vm_id, img, attach, error);
|
||||
rc = acquire_image(vm_id, img.get(), attach, error);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
img->unlock();
|
||||
img = nullptr;
|
||||
img.reset();
|
||||
}
|
||||
|
||||
return img;
|
||||
@ -58,30 +56,28 @@ Image * ImageManager::acquire_image(int vm_id, int image_id, bool attach,
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
Image * ImageManager::acquire_image(int vm_id, const string& name, int uid,
|
||||
unique_ptr<Image> ImageManager::acquire_image(int vm_id, const string& name, int uid,
|
||||
bool attach, string& error)
|
||||
{
|
||||
Image * img;
|
||||
int rc;
|
||||
|
||||
img = ipool->get(name,uid);
|
||||
auto img = ipool->get(name,uid);
|
||||
|
||||
if ( img == nullptr )
|
||||
if (!img)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "User " << uid << " does not own an image with name: " << name
|
||||
<< " . Set IMAGE_UNAME or IMAGE_UID of owner in DISK.";
|
||||
|
||||
error = oss.str();
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
rc = acquire_image(vm_id, img, attach, error);
|
||||
rc = acquire_image(vm_id, img.get(), attach, error);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
img->unlock();
|
||||
img = nullptr;
|
||||
img.reset();
|
||||
}
|
||||
|
||||
return img;
|
||||
@ -209,9 +205,9 @@ void ImageManager::release_image(int vm_id, int iid, bool failed)
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
Image * img = ipool->get(iid);
|
||||
auto img = ipool->get(iid);
|
||||
|
||||
if ( img == nullptr )
|
||||
if (!img)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -228,7 +224,6 @@ void ImageManager::release_image(int vm_id, int iid, bool failed)
|
||||
case Image::CONTEXT:
|
||||
NebulaLog::log("ImM", Log::ERROR, "Trying to release a KERNEL, "
|
||||
"RAMDISK or CONTEXT image");
|
||||
img->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -246,9 +241,7 @@ void ImageManager::release_image(int vm_id, int iid, bool failed)
|
||||
img->set_state(Image::READY);
|
||||
}
|
||||
|
||||
ipool->update(img);
|
||||
|
||||
img->unlock();
|
||||
ipool->update(img.get());
|
||||
break;
|
||||
|
||||
case Image::LOCKED_USED_PERS:
|
||||
@ -263,9 +256,7 @@ void ImageManager::release_image(int vm_id, int iid, bool failed)
|
||||
img->set_state(Image::LOCKED);
|
||||
}
|
||||
|
||||
ipool->update(img);
|
||||
|
||||
img->unlock();
|
||||
ipool->update(img.get());
|
||||
break;
|
||||
|
||||
case Image::USED:
|
||||
@ -274,9 +265,7 @@ void ImageManager::release_image(int vm_id, int iid, bool failed)
|
||||
img->set_state(Image::READY);
|
||||
}
|
||||
|
||||
ipool->update(img);
|
||||
|
||||
img->unlock();
|
||||
ipool->update(img.get());
|
||||
break;
|
||||
|
||||
case Image::LOCKED_USED:
|
||||
@ -285,9 +274,7 @@ void ImageManager::release_image(int vm_id, int iid, bool failed)
|
||||
img->set_state(Image::LOCKED);
|
||||
}
|
||||
|
||||
ipool->update(img);
|
||||
|
||||
img->unlock();
|
||||
ipool->update(img.get());
|
||||
break;
|
||||
|
||||
case Image::LOCKED:
|
||||
@ -295,8 +282,6 @@ void ImageManager::release_image(int vm_id, int iid, bool failed)
|
||||
<< Image::state_to_str(img->get_state());
|
||||
|
||||
NebulaLog::log("ImM", Log::ERROR, oss.str());
|
||||
|
||||
img->unlock();
|
||||
break;
|
||||
|
||||
case Image::CLONE:
|
||||
@ -309,8 +294,6 @@ void ImageManager::release_image(int vm_id, int iid, bool failed)
|
||||
<< Image::state_to_str(img->get_state());
|
||||
|
||||
NebulaLog::log("ImM", Log::ERROR, oss.str());
|
||||
|
||||
img->unlock();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -321,9 +304,9 @@ void ImageManager::release_image(int vm_id, int iid, bool failed)
|
||||
void ImageManager::release_cloning_resource(
|
||||
int iid, PoolObjectSQL::ObjectType ot, int clone_oid)
|
||||
{
|
||||
Image * img = ipool->get(iid);
|
||||
auto img = ipool->get(iid);
|
||||
|
||||
if ( img == nullptr )
|
||||
if (!img)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -340,7 +323,6 @@ void ImageManager::release_cloning_resource(
|
||||
case Image::CONTEXT:
|
||||
NebulaLog::log("ImM", Log::ERROR, "Trying to release a cloning "
|
||||
"KERNEL, RAMDISK or CONTEXT image");
|
||||
img->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -353,7 +335,7 @@ void ImageManager::release_cloning_resource(
|
||||
img->set_state(Image::READY);
|
||||
}
|
||||
|
||||
ipool->update(img);
|
||||
ipool->update(img.get());
|
||||
break;
|
||||
|
||||
case Image::DELETE:
|
||||
@ -369,8 +351,6 @@ void ImageManager::release_cloning_resource(
|
||||
" in wrong state");
|
||||
break;
|
||||
}
|
||||
|
||||
img->unlock();
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -379,13 +359,12 @@ void ImageManager::release_cloning_resource(
|
||||
int ImageManager::enable_image(int iid, bool to_enable, string& error_str)
|
||||
{
|
||||
int rc = 0;
|
||||
Image * img;
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
img = ipool->get(iid);
|
||||
auto img = ipool->get(iid);
|
||||
|
||||
if ( img == nullptr )
|
||||
if (!img)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@ -396,11 +375,11 @@ int ImageManager::enable_image(int iid, bool to_enable, string& error_str)
|
||||
{
|
||||
case Image::DISABLED:
|
||||
img->set_state(Image::READY);
|
||||
ipool->update(img);
|
||||
ipool->update(img.get());
|
||||
break;
|
||||
case Image::ERROR:
|
||||
img->set_state_unlock();
|
||||
ipool->update(img);
|
||||
ipool->update(img.get());
|
||||
break;
|
||||
case Image::READY:
|
||||
break;
|
||||
@ -420,7 +399,7 @@ int ImageManager::enable_image(int iid, bool to_enable, string& error_str)
|
||||
case Image::READY:
|
||||
case Image::ERROR:
|
||||
img->set_state(Image::DISABLED);
|
||||
ipool->update(img);
|
||||
ipool->update(img.get());
|
||||
break;
|
||||
case Image::DISABLED:
|
||||
break;
|
||||
@ -434,8 +413,6 @@ int ImageManager::enable_image(int iid, bool to_enable, string& error_str)
|
||||
}
|
||||
}
|
||||
|
||||
img->unlock();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -444,14 +421,12 @@ int ImageManager::enable_image(int iid, bool to_enable, string& error_str)
|
||||
|
||||
int ImageManager::delete_image(int iid, string& error_str)
|
||||
{
|
||||
Image * img;
|
||||
Datastore * ds;
|
||||
|
||||
string source;
|
||||
string img_tmpl;
|
||||
string ds_data;
|
||||
|
||||
long long size;
|
||||
long long snap_size;
|
||||
int ds_id;
|
||||
|
||||
int uid;
|
||||
@ -461,39 +436,35 @@ int ImageManager::delete_image(int iid, string& error_str)
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
img = ipool->get_ro(iid);
|
||||
|
||||
if ( img == nullptr )
|
||||
if (auto img = ipool->get_ro(iid))
|
||||
{
|
||||
ds_id = img->get_ds_id();
|
||||
}
|
||||
else
|
||||
{
|
||||
error_str = "Image does not exist";
|
||||
return -1;
|
||||
}
|
||||
|
||||
ds_id = img->get_ds_id();
|
||||
|
||||
img->unlock();
|
||||
|
||||
ds = dspool->get_ro(ds_id);
|
||||
|
||||
if ( ds == nullptr )
|
||||
if (auto ds = dspool->get_ro(ds_id))
|
||||
{
|
||||
ds->to_xml(ds_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
error_str = "Datastore no longer exists cannot remove image";
|
||||
return -1;
|
||||
}
|
||||
|
||||
ds->to_xml(ds_data);
|
||||
auto img = ipool->get(iid);
|
||||
|
||||
ds->unlock();
|
||||
|
||||
img = ipool->get(iid);
|
||||
|
||||
if ( img == nullptr )
|
||||
if (!img)
|
||||
{
|
||||
error_str = "Image does not exist";
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch(img->get_state())
|
||||
switch (img->get_state())
|
||||
{
|
||||
case Image::READY:
|
||||
if ( img->get_running() != 0 )
|
||||
@ -501,7 +472,6 @@ int ImageManager::delete_image(int iid, string& error_str)
|
||||
oss << "There are " << img->get_running() << " VMs using it.";
|
||||
error_str = oss.str();
|
||||
|
||||
img->unlock();
|
||||
return -1; //Cannot remove images in use
|
||||
}
|
||||
break;
|
||||
@ -510,7 +480,6 @@ int ImageManager::delete_image(int iid, string& error_str)
|
||||
oss << "There are " << img->get_cloning() << " active clone operations.";
|
||||
error_str = oss.str();
|
||||
|
||||
img->unlock();
|
||||
return -1; //Cannot remove images in use
|
||||
break;
|
||||
|
||||
@ -521,7 +490,6 @@ int ImageManager::delete_image(int iid, string& error_str)
|
||||
oss << "There are " << img->get_running() << " VMs using it.";
|
||||
error_str = oss.str();
|
||||
|
||||
img->unlock();
|
||||
return -1; //Cannot remove images in use
|
||||
break;
|
||||
|
||||
@ -550,7 +518,6 @@ int ImageManager::delete_image(int iid, string& error_str)
|
||||
{
|
||||
error_str = "Error getting ImageManagerDriver";
|
||||
|
||||
img->unlock();
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -565,7 +532,7 @@ int ImageManager::delete_image(int iid, string& error_str)
|
||||
string err_str;
|
||||
int rc;
|
||||
|
||||
rc = ipool->drop(img, err_str);
|
||||
rc = ipool->drop(img.get(), err_str);
|
||||
|
||||
if ( rc < 0 )
|
||||
{
|
||||
@ -585,12 +552,12 @@ int ImageManager::delete_image(int iid, string& error_str)
|
||||
|
||||
img->clear_cloning_id();
|
||||
|
||||
ipool->update(img);
|
||||
ipool->update(img.get());
|
||||
}
|
||||
|
||||
long long snap_size = (img->get_snapshots()).get_total_size();
|
||||
snap_size = (img->get_snapshots()).get_total_size();
|
||||
|
||||
img->unlock();
|
||||
img.reset();
|
||||
|
||||
/* -------------------- Update Group & User quota counters -------------- */
|
||||
|
||||
@ -608,14 +575,10 @@ int ImageManager::delete_image(int iid, string& error_str)
|
||||
release_cloning_image(cloning_id, iid);
|
||||
}
|
||||
|
||||
ds = dspool->get(ds_id);
|
||||
|
||||
if ( ds != nullptr )
|
||||
if ( auto ds = dspool->get(ds_id) )
|
||||
{
|
||||
ds->del_image(iid);
|
||||
dspool->update(ds);
|
||||
|
||||
ds->unlock();
|
||||
dspool->update(ds.get());
|
||||
}
|
||||
|
||||
/* --------------- Release VM in hotplug -------------------------------- */
|
||||
@ -625,18 +588,15 @@ int ImageManager::delete_image(int iid, string& error_str)
|
||||
|
||||
if ( vm_saving_id != -1 )
|
||||
{
|
||||
VirtualMachine* vm;
|
||||
VirtualMachinePool* vmpool = Nebula::instance().get_vmpool();
|
||||
|
||||
if ((vm = vmpool->get(vm_saving_id)) != 0)
|
||||
if (auto vm = vmpool->get(vm_saving_id))
|
||||
{
|
||||
vm->clear_saveas_state();
|
||||
|
||||
vm->clear_saveas_disk();
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
vm->unlock();
|
||||
vmpool->update(vm.get());
|
||||
}
|
||||
}
|
||||
|
||||
@ -648,11 +608,9 @@ int ImageManager::delete_image(int iid, string& error_str)
|
||||
|
||||
int ImageManager::can_clone_image(int cloning_id, ostringstream& oss_error)
|
||||
{
|
||||
Image * img;
|
||||
auto img = ipool->get_ro(cloning_id);
|
||||
|
||||
img = ipool->get_ro(cloning_id);
|
||||
|
||||
if (img == nullptr)
|
||||
if (!img)
|
||||
{
|
||||
oss_error << "Cannot clone image, it does not exist";
|
||||
return -1;
|
||||
@ -660,8 +618,6 @@ int ImageManager::can_clone_image(int cloning_id, ostringstream& oss_error)
|
||||
|
||||
Image::ImageState state = img->get_state();
|
||||
|
||||
img->unlock();
|
||||
|
||||
switch(state)
|
||||
{
|
||||
case Image::USED_PERS:
|
||||
@ -694,9 +650,9 @@ int ImageManager::set_clone_state(
|
||||
PoolObjectSQL::ObjectType ot, int new_id, int cloning_id, string& error)
|
||||
{
|
||||
int rc = 0;
|
||||
Image * img = ipool->get(cloning_id);
|
||||
auto img = ipool->get(cloning_id);
|
||||
|
||||
if (img == nullptr)
|
||||
if (!img)
|
||||
{
|
||||
error = "Cannot clone image, it does not exist";
|
||||
return -1;
|
||||
@ -716,13 +672,13 @@ int ImageManager::set_clone_state(
|
||||
img->set_state(Image::USED);
|
||||
}
|
||||
|
||||
ipool->update(img);
|
||||
ipool->update(img.get());
|
||||
break;
|
||||
|
||||
case Image::USED:
|
||||
case Image::CLONE:
|
||||
img->inc_cloning(ot, new_id);
|
||||
ipool->update(img);
|
||||
ipool->update(img.get());
|
||||
break;
|
||||
|
||||
case Image::USED_PERS:
|
||||
@ -738,8 +694,6 @@ int ImageManager::set_clone_state(
|
||||
break;
|
||||
}
|
||||
|
||||
img->unlock();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -755,7 +709,6 @@ int ImageManager::clone_image(int new_id,
|
||||
const auto* imd = get();
|
||||
|
||||
ostringstream oss;
|
||||
Image * img;
|
||||
|
||||
string path;
|
||||
string img_tmpl;
|
||||
@ -773,7 +726,7 @@ int ImageManager::clone_image(int new_id,
|
||||
return -1;
|
||||
}
|
||||
|
||||
img = ipool->get_ro(new_id);
|
||||
auto img = ipool->get_ro(new_id);
|
||||
|
||||
if (img == nullptr)
|
||||
{
|
||||
@ -794,8 +747,6 @@ int ImageManager::clone_image(int new_id,
|
||||
|
||||
NebulaLog::log("ImM", Log::INFO, oss);
|
||||
|
||||
img->unlock();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -810,7 +761,6 @@ int ImageManager::register_image(int iid,
|
||||
const auto* imd = get();
|
||||
|
||||
ostringstream oss;
|
||||
Image * img;
|
||||
|
||||
string path;
|
||||
string img_tmpl;
|
||||
@ -823,9 +773,9 @@ int ImageManager::register_image(int iid,
|
||||
return -1;
|
||||
}
|
||||
|
||||
img = ipool->get(iid);
|
||||
auto img = ipool->get(iid);
|
||||
|
||||
if (img == nullptr)
|
||||
if (!img)
|
||||
{
|
||||
error = "Image deleted during copy operation";
|
||||
return -1;
|
||||
@ -841,7 +791,7 @@ int ImageManager::register_image(int iid,
|
||||
if ( !source.empty() ) //Source in Template
|
||||
{
|
||||
img->set_state_unlock();
|
||||
ipool->update(img);
|
||||
ipool->update(img.get());
|
||||
|
||||
oss << "Using source " << source
|
||||
<< " from template for image " << img->get_name();
|
||||
@ -866,8 +816,6 @@ int ImageManager::register_image(int iid,
|
||||
|
||||
NebulaLog::log("ImM",Log::INFO,oss);
|
||||
|
||||
img->unlock();
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -1022,9 +970,9 @@ string ImageManager::format_message(
|
||||
|
||||
void ImageManager::set_image_snapshots(int iid, const Snapshots& s)
|
||||
{
|
||||
Image * img = ipool->get(iid);
|
||||
auto img = ipool->get(iid);
|
||||
|
||||
if ( img == nullptr )
|
||||
if (!img)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -1039,13 +987,11 @@ void ImageManager::set_image_snapshots(int iid, const Snapshots& s)
|
||||
case Image::RAMDISK:
|
||||
case Image::CONTEXT:
|
||||
case Image::CDROM:
|
||||
img->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
if (img->get_state() != Image::USED_PERS)
|
||||
{
|
||||
img->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1058,9 +1004,7 @@ void ImageManager::set_image_snapshots(int iid, const Snapshots& s)
|
||||
img->set_snapshots(s);
|
||||
}
|
||||
|
||||
ipool->update(img);
|
||||
|
||||
img->unlock();
|
||||
ipool->update(img.get());
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -1078,9 +1022,9 @@ void ImageManager::clear_image_snapshots(int iid)
|
||||
|
||||
void ImageManager::set_image_size(int iid, long long size)
|
||||
{
|
||||
Image * img = ipool->get(iid);
|
||||
auto img = ipool->get(iid);
|
||||
|
||||
if ( img == nullptr )
|
||||
if (!img)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -1095,21 +1039,17 @@ void ImageManager::set_image_size(int iid, long long size)
|
||||
case Image::RAMDISK:
|
||||
case Image::CONTEXT:
|
||||
case Image::CDROM:
|
||||
img->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
if (img->get_state() != Image::USED_PERS)
|
||||
{
|
||||
img->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
img->set_size(size);
|
||||
|
||||
ipool->update(img);
|
||||
|
||||
img->unlock();
|
||||
ipool->update(img.get());
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -1127,41 +1067,36 @@ int ImageManager::delete_snapshot(int iid, int sid, string& error)
|
||||
return -1;
|
||||
}
|
||||
|
||||
Image * img = ipool->get_ro(iid);
|
||||
int ds_id;
|
||||
|
||||
if ( img == nullptr )
|
||||
if ( auto img = ipool->get_ro(iid) )
|
||||
{
|
||||
ds_id = img->get_ds_id();
|
||||
}
|
||||
else
|
||||
{
|
||||
error = "Image does not exist";
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Get DS data for driver */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int ds_id = img->get_ds_id();
|
||||
|
||||
img->unlock();
|
||||
|
||||
string ds_data;
|
||||
|
||||
Datastore * ds = dspool->get_ro(ds_id);
|
||||
|
||||
if ( ds == nullptr )
|
||||
if (auto ds = dspool->get_ro(ds_id))
|
||||
{
|
||||
ds->to_xml(ds_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
error = "Datastore no longer exists";
|
||||
return -1;
|
||||
}
|
||||
|
||||
ds->to_xml(ds_data);
|
||||
|
||||
ds->unlock();
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Check action consistency: */
|
||||
/* state is READY */
|
||||
/* snapshot can be deleted (not active, no childs, exists) */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
img = ipool->get(iid);
|
||||
auto img = ipool->get(iid);
|
||||
|
||||
if ( img == nullptr )
|
||||
{
|
||||
@ -1172,7 +1107,6 @@ int ImageManager::delete_snapshot(int iid, int sid, string& error)
|
||||
if (img->get_state() != Image::READY)
|
||||
{
|
||||
error = "Cannot delete snapshot in state " + Image::state_to_str(img->get_state());
|
||||
img->unlock();
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1180,7 +1114,6 @@ int ImageManager::delete_snapshot(int iid, int sid, string& error)
|
||||
|
||||
if (!snaps.test_delete(sid, error))
|
||||
{
|
||||
img->unlock();
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1198,9 +1131,7 @@ int ImageManager::delete_snapshot(int iid, int sid, string& error)
|
||||
|
||||
img->set_state(Image::LOCKED);
|
||||
|
||||
ipool->update(img);
|
||||
|
||||
img->unlock();
|
||||
ipool->update(img.get());
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -1220,42 +1151,37 @@ int ImageManager::revert_snapshot(int iid, int sid, string& error)
|
||||
return -1;
|
||||
}
|
||||
|
||||
Image * img = ipool->get_ro(iid);
|
||||
int ds_id;
|
||||
|
||||
if ( img == nullptr )
|
||||
if ( auto img = ipool->get_ro(iid) )
|
||||
{
|
||||
ds_id = img->get_ds_id();
|
||||
}
|
||||
else
|
||||
{
|
||||
error = "Image does not exist";
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Get DS data for driver */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int ds_id = img->get_ds_id();
|
||||
|
||||
img->unlock();
|
||||
|
||||
string ds_data;
|
||||
|
||||
Datastore * ds = dspool->get_ro(ds_id);
|
||||
|
||||
if ( ds == nullptr )
|
||||
if (auto ds = dspool->get_ro(ds_id))
|
||||
{
|
||||
ds->to_xml(ds_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
error = "Datastore no longer exists";
|
||||
return -1;
|
||||
}
|
||||
|
||||
ds->to_xml(ds_data);
|
||||
|
||||
ds->unlock();
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Check action consistency: */
|
||||
/* state is READY */
|
||||
/* snapshot exists */
|
||||
/* snapshot is not the active one */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
img = ipool->get(iid);
|
||||
auto img = ipool->get(iid);
|
||||
|
||||
if ( img == nullptr )
|
||||
{
|
||||
@ -1266,7 +1192,6 @@ int ImageManager::revert_snapshot(int iid, int sid, string& error)
|
||||
if (img->get_state() != Image::READY)
|
||||
{
|
||||
error = "Cannot revert to snapshot in state " + Image::state_to_str(img->get_state());
|
||||
img->unlock();
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1276,7 +1201,6 @@ int ImageManager::revert_snapshot(int iid, int sid, string& error)
|
||||
{
|
||||
error = "Snapshot does not exist";
|
||||
|
||||
img->unlock();
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1284,7 +1208,6 @@ int ImageManager::revert_snapshot(int iid, int sid, string& error)
|
||||
{
|
||||
error = "Snapshot is already the active one";
|
||||
|
||||
img->unlock();
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1302,9 +1225,7 @@ int ImageManager::revert_snapshot(int iid, int sid, string& error)
|
||||
|
||||
img->set_state(Image::LOCKED);
|
||||
|
||||
ipool->update(img);
|
||||
|
||||
img->unlock();
|
||||
ipool->update(img.get());
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -1324,42 +1245,37 @@ int ImageManager::flatten_snapshot(int iid, int sid, string& error)
|
||||
return -1;
|
||||
}
|
||||
|
||||
Image * img = ipool->get_ro(iid);
|
||||
int ds_id;
|
||||
|
||||
if ( img == nullptr )
|
||||
if ( auto img = ipool->get_ro(iid) )
|
||||
{
|
||||
ds_id = img->get_ds_id();
|
||||
}
|
||||
else
|
||||
{
|
||||
error = "Image does not exist";
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Get DS data for driver */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
int ds_id = img->get_ds_id();
|
||||
|
||||
img->unlock();
|
||||
|
||||
string ds_data;
|
||||
|
||||
Datastore * ds = dspool->get_ro(ds_id);
|
||||
|
||||
if ( ds == nullptr )
|
||||
if (auto ds = dspool->get_ro(ds_id))
|
||||
{
|
||||
ds->to_xml(ds_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
error = "Datastore no longer exists";
|
||||
return -1;
|
||||
}
|
||||
|
||||
ds->to_xml(ds_data);
|
||||
|
||||
ds->unlock();
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Check action consistency: */
|
||||
/* state is READY */
|
||||
/* snapshot exists */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
img = ipool->get(iid);
|
||||
auto img = ipool->get(iid);
|
||||
|
||||
if ( img == nullptr )
|
||||
{
|
||||
@ -1370,7 +1286,6 @@ int ImageManager::flatten_snapshot(int iid, int sid, string& error)
|
||||
if (img->get_state() != Image::READY)
|
||||
{
|
||||
error = "Cannot flatten snapshot in state " + Image::state_to_str(img->get_state());
|
||||
img->unlock();
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1380,7 +1295,6 @@ int ImageManager::flatten_snapshot(int iid, int sid, string& error)
|
||||
{
|
||||
error = "Snapshot does not exist";
|
||||
|
||||
img->unlock();
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1399,9 +1313,7 @@ int ImageManager::flatten_snapshot(int iid, int sid, string& error)
|
||||
|
||||
img->set_state(Image::LOCKED);
|
||||
|
||||
ipool->update(img);
|
||||
|
||||
img->unlock();
|
||||
ipool->update(img.get());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ void ImageManager::_cp(unique_ptr<image_msg_t> msg)
|
||||
|
||||
auto image = ipool->get(msg->oid());
|
||||
|
||||
if (image == nullptr)
|
||||
if (!image)
|
||||
{
|
||||
if (msg->status() == "SUCCESS")
|
||||
{
|
||||
@ -105,9 +105,9 @@ void ImageManager::_cp(unique_ptr<image_msg_t> msg)
|
||||
|
||||
image->set_state_unlock();
|
||||
|
||||
ipool->update(image);
|
||||
ipool->update(image.get());
|
||||
|
||||
image->unlock();
|
||||
image.reset();
|
||||
|
||||
oss << "Image (" << msg->oid() << ") copied and ready to use.";
|
||||
NebulaLog::log("ImM", Log::INFO, oss);
|
||||
@ -131,9 +131,9 @@ error:
|
||||
image->set_template_error_message(oss.str());
|
||||
image->set_state(Image::ERROR);
|
||||
|
||||
ipool->update(image);
|
||||
ipool->update(image.get());
|
||||
|
||||
image->unlock();
|
||||
image.reset();
|
||||
|
||||
monitor_datastore(ds_id);
|
||||
|
||||
@ -149,7 +149,7 @@ void ImageManager::_clone(unique_ptr<image_msg_t> msg)
|
||||
int cloning_id;
|
||||
int ds_id = -1;
|
||||
|
||||
Image * image = ipool->get(msg->oid());
|
||||
auto image = ipool->get(msg->oid());
|
||||
|
||||
if (image == nullptr)
|
||||
{
|
||||
@ -184,9 +184,9 @@ void ImageManager::_clone(unique_ptr<image_msg_t> msg)
|
||||
|
||||
image->clear_cloning_id();
|
||||
|
||||
ipool->update(image);
|
||||
ipool->update(image.get());
|
||||
|
||||
image->unlock();
|
||||
image.reset();
|
||||
|
||||
NebulaLog::info("ImM", "Image cloned and ready to use.");
|
||||
|
||||
@ -215,9 +215,9 @@ error:
|
||||
|
||||
image->clear_cloning_id();
|
||||
|
||||
ipool->update(image);
|
||||
ipool->update(image.get());
|
||||
|
||||
image->unlock();
|
||||
image.reset();
|
||||
|
||||
release_cloning_image(cloning_id, msg->oid());
|
||||
}
|
||||
@ -231,18 +231,16 @@ void ImageManager::_mkfs(unique_ptr<image_msg_t> msg)
|
||||
int vm_id = -1;
|
||||
int disk_id = -1;
|
||||
|
||||
VirtualMachine * vm = nullptr;
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
VirtualMachinePool * vmpool = nd.get_vmpool();
|
||||
TransferManager * tm = nd.get_tm();
|
||||
|
||||
Image * image = ipool->get(msg->oid());
|
||||
auto image = ipool->get(msg->oid());
|
||||
const string& source = msg->payload();
|
||||
|
||||
if (image == nullptr)
|
||||
if (!image)
|
||||
{
|
||||
if (msg->status() == "SUCCESS")
|
||||
{
|
||||
@ -264,7 +262,6 @@ void ImageManager::_mkfs(unique_ptr<image_msg_t> msg)
|
||||
NebulaLog::info("ImM", "Ignoring mkfs callback, image is "
|
||||
"being deleted");
|
||||
|
||||
image->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -289,9 +286,9 @@ void ImageManager::_mkfs(unique_ptr<image_msg_t> msg)
|
||||
image->set_state_unlock();
|
||||
}
|
||||
|
||||
ipool->update(image);
|
||||
ipool->update(image.get());
|
||||
|
||||
image->unlock();
|
||||
image.reset();
|
||||
|
||||
if (!is_saving)
|
||||
{
|
||||
@ -302,13 +299,8 @@ void ImageManager::_mkfs(unique_ptr<image_msg_t> msg)
|
||||
return;
|
||||
}
|
||||
|
||||
vm = vmpool->get(vm_id);
|
||||
|
||||
if (vm == nullptr)
|
||||
if ( auto vm = vmpool->get(vm_id) )
|
||||
{
|
||||
goto error_save_get;
|
||||
}
|
||||
|
||||
if (vm->set_saveas_disk(disk_id, source, msg->oid()) == -1)
|
||||
{
|
||||
goto error_save_state;
|
||||
@ -316,9 +308,12 @@ void ImageManager::_mkfs(unique_ptr<image_msg_t> msg)
|
||||
|
||||
tm->trigger_saveas_hot(vm_id);
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
vm->unlock();
|
||||
vmpool->update(vm.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
goto error_save_get;
|
||||
}
|
||||
|
||||
monitor_datastore(ds_id);
|
||||
|
||||
@ -333,7 +328,6 @@ error_save_get:
|
||||
goto error_save;
|
||||
|
||||
error_save_state:
|
||||
vm->unlock();
|
||||
oss << "Image created to save as disk but VM is no longer running";
|
||||
|
||||
error_save:
|
||||
@ -358,21 +352,19 @@ error:
|
||||
image->set_template_error_message(oss.str());
|
||||
image->set_state(Image::ERROR);
|
||||
|
||||
ipool->update(image);
|
||||
ipool->update(image.get());
|
||||
|
||||
image->unlock();
|
||||
image.reset();
|
||||
|
||||
if (is_saving && vm_id != -1)
|
||||
{
|
||||
if ((vm = vmpool->get(vm_id)) != nullptr)
|
||||
if (auto vm = vmpool->get(vm_id))
|
||||
{
|
||||
vm->clear_saveas_state();
|
||||
|
||||
vm->clear_saveas_disk();
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
vm->unlock();
|
||||
vmpool->update(vm.get());
|
||||
}
|
||||
}
|
||||
|
||||
@ -388,26 +380,25 @@ void ImageManager::_rm(unique_ptr<image_msg_t> msg)
|
||||
NebulaLog::dddebug("ImM", "_rm: " + msg->payload());
|
||||
|
||||
int ds_id = -1;
|
||||
int rc;
|
||||
|
||||
string tmp_error;
|
||||
Image * image;
|
||||
string source;
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
image = ipool->get(msg->oid());
|
||||
if ( auto image = ipool->get(msg->oid()) )
|
||||
{
|
||||
ds_id = image->get_ds_id();
|
||||
source = image->get_source();
|
||||
|
||||
if (image == nullptr)
|
||||
rc = ipool->drop(image.get(), tmp_error);
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ds_id = image->get_ds_id();
|
||||
const auto& source = image->get_source();
|
||||
|
||||
int rc = ipool->drop(image, tmp_error);
|
||||
|
||||
image->unlock();
|
||||
|
||||
if (msg->status() != "SUCCESS")
|
||||
{
|
||||
goto error;
|
||||
@ -507,9 +498,9 @@ void ImageManager::_monitor(unique_ptr<image_msg_t> msg)
|
||||
monitor_data.get("FREE_MB", free);
|
||||
monitor_data.get("USED_MB", used);
|
||||
|
||||
Datastore * ds = dspool->get(msg->oid());
|
||||
auto ds = dspool->get(msg->oid());
|
||||
|
||||
if (ds == nullptr)
|
||||
if (!ds)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -518,9 +509,7 @@ void ImageManager::_monitor(unique_ptr<image_msg_t> msg)
|
||||
|
||||
ds->update_monitor(total, free, used);
|
||||
|
||||
dspool->update(ds);
|
||||
|
||||
ds->unlock();
|
||||
dspool->update(ds.get());
|
||||
|
||||
oss << "Datastore " << ds_name << " (" << msg->oid()
|
||||
<< ") successfully monitored.";
|
||||
@ -539,9 +528,9 @@ void ImageManager::_snap_delete(unique_ptr<image_msg_t> msg)
|
||||
long long snap_size;
|
||||
int ds_id, uid, gid;
|
||||
|
||||
Image * image = ipool->get(msg->oid());
|
||||
auto image = ipool->get(msg->oid());
|
||||
|
||||
if (image == nullptr)
|
||||
if (!image)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -554,9 +543,8 @@ void ImageManager::_snap_delete(unique_ptr<image_msg_t> msg)
|
||||
{
|
||||
NebulaLog::error("ImM", "No target snapshot in callback");
|
||||
|
||||
ipool->update(image);
|
||||
ipool->update(image.get());
|
||||
|
||||
image->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -590,9 +578,9 @@ void ImageManager::_snap_delete(unique_ptr<image_msg_t> msg)
|
||||
|
||||
image->clear_target_snapshot();
|
||||
|
||||
ipool->update(image);
|
||||
ipool->update(image.get());
|
||||
|
||||
image->unlock();
|
||||
image.reset();
|
||||
|
||||
if (msg->status() == "SUCCESS")
|
||||
{
|
||||
@ -612,9 +600,9 @@ void ImageManager::_snap_revert(unique_ptr<image_msg_t> msg)
|
||||
{
|
||||
NebulaLog::dddebug("ImM", "_snap_revert: " + msg->payload());
|
||||
|
||||
Image * image = ipool->get(msg->oid());
|
||||
auto image = ipool->get(msg->oid());
|
||||
|
||||
if (image == nullptr)
|
||||
if (!image)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -627,9 +615,8 @@ void ImageManager::_snap_revert(unique_ptr<image_msg_t> msg)
|
||||
{
|
||||
NebulaLog::error("ImM", "No target snapshot in callback");
|
||||
|
||||
ipool->update(image);
|
||||
ipool->update(image.get());
|
||||
|
||||
image->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -657,9 +644,7 @@ void ImageManager::_snap_revert(unique_ptr<image_msg_t> msg)
|
||||
|
||||
image->clear_target_snapshot();
|
||||
|
||||
ipool->update(image);
|
||||
|
||||
image->unlock();
|
||||
ipool->update(image.get());
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -671,9 +656,9 @@ void ImageManager::_snap_flatten(unique_ptr<image_msg_t> msg)
|
||||
long long snap_size;
|
||||
int ds_id, uid, gid;
|
||||
|
||||
Image * image = ipool->get(msg->oid());
|
||||
auto image = ipool->get(msg->oid());
|
||||
|
||||
if (image == nullptr)
|
||||
if ( !image )
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -708,9 +693,9 @@ void ImageManager::_snap_flatten(unique_ptr<image_msg_t> msg)
|
||||
|
||||
image->clear_target_snapshot();
|
||||
|
||||
ipool->update(image);
|
||||
ipool->update(image.get());
|
||||
|
||||
image->unlock();
|
||||
image.reset();
|
||||
|
||||
if (msg->status() == "SUCCESS")
|
||||
{
|
||||
|
@ -184,15 +184,11 @@ int ImagePool::allocate (
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
img = get(*oid);
|
||||
|
||||
if ( img != 0 )
|
||||
if ( auto img = get(*oid) )
|
||||
{
|
||||
string aux_str;
|
||||
|
||||
drop(img, aux_str);
|
||||
|
||||
img->unlock();
|
||||
drop(img.get(), aux_str);
|
||||
}
|
||||
|
||||
*oid = -1;
|
||||
@ -206,15 +202,11 @@ int ImagePool::allocate (
|
||||
|
||||
if (rc == -1)
|
||||
{
|
||||
img = get(*oid);
|
||||
|
||||
if ( img != 0 )
|
||||
if ( auto img = get(*oid) )
|
||||
{
|
||||
string aux_str;
|
||||
|
||||
drop(img, aux_str);
|
||||
|
||||
img->unlock();
|
||||
drop(img.get(), aux_str);
|
||||
}
|
||||
|
||||
*oid = -1;
|
||||
@ -265,7 +257,7 @@ int ImagePool::acquire_disk(int vm_id,
|
||||
string& error_str)
|
||||
{
|
||||
string source;
|
||||
Image * img = 0;
|
||||
unique_ptr<Image> img;
|
||||
int rc = 0;
|
||||
int datastore_id;
|
||||
int iid;
|
||||
@ -281,7 +273,7 @@ int ImagePool::acquire_disk(int vm_id,
|
||||
{
|
||||
img = imagem->acquire_image(vm_id, iid, attach, error_str);
|
||||
|
||||
if ( img == 0 )
|
||||
if ( img == nullptr )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@ -303,7 +295,7 @@ int ImagePool::acquire_disk(int vm_id,
|
||||
|
||||
img = imagem->acquire_image(vm_id, source, uiid, attach, error_str);
|
||||
|
||||
if ( img == 0 )
|
||||
if ( img == nullptr )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@ -343,7 +335,7 @@ int ImagePool::acquire_disk(int vm_id,
|
||||
}
|
||||
}
|
||||
|
||||
if ( img != 0 )
|
||||
if ( img != nullptr )
|
||||
{
|
||||
DatastorePool * ds_pool = nd.get_dspool();
|
||||
|
||||
@ -352,7 +344,7 @@ int ImagePool::acquire_disk(int vm_id,
|
||||
|
||||
if (has_size && img->is_persistent() && size != img->get_size())
|
||||
{
|
||||
img->unlock();
|
||||
img.reset();
|
||||
|
||||
imagem->release_image(vm_id, iid, false);
|
||||
|
||||
@ -365,7 +357,7 @@ int ImagePool::acquire_disk(int vm_id,
|
||||
|
||||
if (has_size && img->get_type() == Image::CDROM && size != img->get_size())
|
||||
{
|
||||
img->unlock();
|
||||
img.reset();
|
||||
|
||||
imagem->release_image(vm_id, iid, false);
|
||||
|
||||
@ -378,7 +370,7 @@ int ImagePool::acquire_disk(int vm_id,
|
||||
|
||||
if (has_size && size < img->get_size())
|
||||
{
|
||||
img->unlock();
|
||||
img.reset();
|
||||
|
||||
imagem->release_image(vm_id, iid, false);
|
||||
|
||||
@ -401,7 +393,7 @@ int ImagePool::acquire_disk(int vm_id,
|
||||
(*snap)->set_disk_id(disk_id);
|
||||
}
|
||||
|
||||
img->unlock();
|
||||
img.reset();
|
||||
|
||||
if ( ds_pool->disk_attribute(datastore_id, disk) == -1 )
|
||||
{
|
||||
@ -429,7 +421,7 @@ void ImagePool::disk_attribute(
|
||||
int uid)
|
||||
{
|
||||
string source;
|
||||
Image * img = 0;
|
||||
unique_ptr<Image> img;
|
||||
int datastore_id;
|
||||
int iid;
|
||||
|
||||
@ -455,13 +447,13 @@ void ImagePool::disk_attribute(
|
||||
}
|
||||
}
|
||||
|
||||
if ( img != 0 )
|
||||
if ( img != nullptr )
|
||||
{
|
||||
img->disk_attribute(disk, img_type, dev_prefix, inherit_attrs);
|
||||
|
||||
datastore_id = img->get_ds_id();
|
||||
|
||||
img->unlock();
|
||||
img.reset();
|
||||
|
||||
ds_pool->disk_attribute(datastore_id, disk);
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ void LifeCycleManager::trigger_deploy(int vid)
|
||||
trigger([this, vid] {
|
||||
ostringstream os;
|
||||
|
||||
VirtualMachine * vm = vmpool->get(vid);
|
||||
auto vm = vmpool->get(vid);
|
||||
|
||||
if ( vm == nullptr )
|
||||
{
|
||||
@ -82,9 +82,9 @@ void LifeCycleManager::trigger_deploy(int vid)
|
||||
|
||||
vm->set_prolog_stime(thetime);
|
||||
|
||||
vmpool->update_history(vm);
|
||||
vmpool->update_history(vm.get());
|
||||
|
||||
vmpool->update(vm);
|
||||
vmpool->update(vm.get());
|
||||
|
||||
if ( rc == -1)
|
||||
{
|
||||
@ -93,15 +93,13 @@ void LifeCycleManager::trigger_deploy(int vid)
|
||||
}
|
||||
else
|
||||
{
|
||||
(tm->*tm_action)(vm);
|
||||
(tm->*tm_action)(vm.get());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
vm->log("LCM", Log::ERROR, "deploy_action, VM in a wrong state.");
|
||||
}
|
||||
|
||||
vm->unlock();
|
||||
});
|
||||
}
|
||||
|
||||
@ -115,7 +113,7 @@ void LifeCycleManager::trigger_suspend(int vid, const RequestAttributes& ra)
|
||||
int req_id = ra.req_id;
|
||||
|
||||
trigger([this, vid, uid, gid, req_id] {
|
||||
VirtualMachine * vm = vmpool->get(vid);
|
||||
auto vm = vmpool->get(vid);
|
||||
|
||||
if ( vm == nullptr )
|
||||
{
|
||||
@ -135,9 +133,9 @@ void LifeCycleManager::trigger_suspend(int vid, const RequestAttributes& ra)
|
||||
|
||||
vm->set_action(VMActions::SUSPEND_ACTION, uid, gid, req_id);
|
||||
|
||||
vmpool->update_history(vm);
|
||||
vmpool->update_history(vm.get());
|
||||
|
||||
vmpool->update(vm);
|
||||
vmpool->update(vm.get());
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
@ -147,8 +145,6 @@ void LifeCycleManager::trigger_suspend(int vid, const RequestAttributes& ra)
|
||||
{
|
||||
vm->log("LCM", Log::ERROR, "suspend_action, VM in a wrong state.");
|
||||
}
|
||||
|
||||
vm->unlock();
|
||||
});
|
||||
}
|
||||
|
||||
@ -162,7 +158,7 @@ void LifeCycleManager::trigger_stop(int vid, const RequestAttributes& ra)
|
||||
int req_id = ra.req_id;
|
||||
|
||||
trigger([this, vid, uid, gid, req_id] {
|
||||
VirtualMachine * vm = vmpool->get(vid);
|
||||
auto vm = vmpool->get(vid);
|
||||
|
||||
if ( vm == nullptr )
|
||||
{
|
||||
@ -182,9 +178,9 @@ void LifeCycleManager::trigger_stop(int vid, const RequestAttributes& ra)
|
||||
|
||||
vm->set_action(VMActions::STOP_ACTION, uid, gid, req_id);
|
||||
|
||||
vmpool->update_history(vm);
|
||||
vmpool->update_history(vm.get());
|
||||
|
||||
vmpool->update(vm);
|
||||
vmpool->update(vm.get());
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
@ -202,20 +198,18 @@ void LifeCycleManager::trigger_stop(int vid, const RequestAttributes& ra)
|
||||
|
||||
vm->set_epilog_stime(time(0));
|
||||
|
||||
vmpool->update_history(vm);
|
||||
vmpool->update_history(vm.get());
|
||||
|
||||
vmpool->update(vm);
|
||||
vmpool->update(vm.get());
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
tm->trigger_epilog_stop(vm);
|
||||
tm->trigger_epilog_stop(vm.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
vm->log("LCM", Log::ERROR, "stop_action, VM in a wrong state.");
|
||||
}
|
||||
|
||||
vm->unlock();
|
||||
});
|
||||
}
|
||||
|
||||
@ -234,7 +228,7 @@ void LifeCycleManager::trigger_migrate(int vid, const RequestAttributes& ra,
|
||||
|
||||
time_t the_time = time(0);
|
||||
|
||||
VirtualMachine * vm = vmpool->get(vid);
|
||||
auto vm = vmpool->get(vid);
|
||||
|
||||
if ( vm == nullptr )
|
||||
{
|
||||
@ -260,13 +254,13 @@ void LifeCycleManager::trigger_migrate(int vid, const RequestAttributes& ra,
|
||||
|
||||
vm->set_action(vm_action, uid, gid, req_id);
|
||||
|
||||
vmpool->update_history(vm);
|
||||
vmpool->update_history(vm.get());
|
||||
|
||||
vm->set_previous_action(vm_action, uid, gid, req_id);
|
||||
|
||||
vmpool->update_previous_history(vm);
|
||||
vmpool->update_previous_history(vm.get());
|
||||
|
||||
vmpool->update(vm);
|
||||
vmpool->update(vm.get());
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
@ -311,7 +305,7 @@ void LifeCycleManager::trigger_migrate(int vid, const RequestAttributes& ra,
|
||||
|
||||
vm->set_previous_etime(the_time);
|
||||
|
||||
vmpool->update_previous_history(vm);
|
||||
vmpool->update_previous_history(vm.get());
|
||||
|
||||
vm->set_state(VirtualMachine::ACTIVE);
|
||||
|
||||
@ -337,20 +331,18 @@ void LifeCycleManager::trigger_migrate(int vid, const RequestAttributes& ra,
|
||||
|
||||
vm->set_prolog_stime(the_time);
|
||||
|
||||
vmpool->update_history(vm);
|
||||
vmpool->update_history(vm.get());
|
||||
|
||||
vmpool->update(vm);
|
||||
vmpool->update(vm.get());
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
tm->trigger_prolog_migr(vm);
|
||||
tm->trigger_prolog_migr(vm.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
vm->log("LCM", Log::ERROR, "migrate_action, VM in a wrong state.");
|
||||
}
|
||||
|
||||
vm->unlock();
|
||||
});
|
||||
}
|
||||
|
||||
@ -366,7 +358,7 @@ void LifeCycleManager::trigger_live_migrate(int vid, const RequestAttributes& ra
|
||||
trigger([this, vid, uid, gid, req_id] {
|
||||
ostringstream os;
|
||||
|
||||
VirtualMachine * vm = vmpool->get(vid);
|
||||
auto vm = vmpool->get(vid);
|
||||
|
||||
if ( vm == nullptr )
|
||||
{
|
||||
@ -392,14 +384,14 @@ void LifeCycleManager::trigger_live_migrate(int vid, const RequestAttributes& ra
|
||||
|
||||
vm->set_stime(time(0));
|
||||
|
||||
vmpool->update_history(vm);
|
||||
vmpool->update_history(vm.get());
|
||||
|
||||
vm->set_previous_action(VMActions::LIVE_MIGRATE_ACTION, uid, gid,
|
||||
req_id);
|
||||
|
||||
vmpool->update_previous_history(vm);
|
||||
vmpool->update_previous_history(vm.get());
|
||||
|
||||
vmpool->update(vm);
|
||||
vmpool->update(vm.get());
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
@ -409,8 +401,6 @@ void LifeCycleManager::trigger_live_migrate(int vid, const RequestAttributes& ra
|
||||
{
|
||||
vm->log("LCM", Log::ERROR, "live_migrate_action, VM in a wrong state.");
|
||||
}
|
||||
|
||||
vm->unlock();
|
||||
});
|
||||
}
|
||||
|
||||
@ -425,7 +415,7 @@ void LifeCycleManager::trigger_shutdown(int vid, bool hard,
|
||||
int req_id = ra.req_id;
|
||||
|
||||
trigger([this, hard, vid, uid, gid, req_id] {
|
||||
VirtualMachine * vm = vmpool->get(vid);
|
||||
auto vm = vmpool->get(vid);
|
||||
VirtualMachineTemplate quota_tmpl;
|
||||
string error;
|
||||
|
||||
@ -483,9 +473,9 @@ void LifeCycleManager::trigger_shutdown(int vid, bool hard,
|
||||
|
||||
vm->set_resched(false);
|
||||
|
||||
vmpool->update_history(vm);
|
||||
vmpool->update_history(vm.get());
|
||||
|
||||
vmpool->update(vm);
|
||||
vmpool->update(vm.get());
|
||||
}
|
||||
else if (vm->get_state() == VirtualMachine::SUSPENDED ||
|
||||
vm->get_state() == VirtualMachine::POWEROFF)
|
||||
@ -499,13 +489,13 @@ void LifeCycleManager::trigger_shutdown(int vid, bool hard,
|
||||
|
||||
vm->set_epilog_stime(time(0));
|
||||
|
||||
vmpool->update_history(vm);
|
||||
vmpool->update_history(vm.get());
|
||||
|
||||
vmpool->update(vm);
|
||||
vmpool->update(vm.get());
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
tm->trigger_epilog(false, vm);
|
||||
tm->trigger_epilog(false, vm.get());
|
||||
}
|
||||
else if (vm->get_state() == VirtualMachine::STOPPED ||
|
||||
vm->get_state() == VirtualMachine::UNDEPLOYED)
|
||||
@ -519,20 +509,18 @@ void LifeCycleManager::trigger_shutdown(int vid, bool hard,
|
||||
|
||||
vm->set_epilog_stime(time(0));
|
||||
|
||||
vmpool->update_history(vm);
|
||||
vmpool->update_history(vm.get());
|
||||
|
||||
vmpool->update(vm);
|
||||
vmpool->update(vm.get());
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
tm->trigger_epilog(true, vm);
|
||||
tm->trigger_epilog(true, vm.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
vm->log("LCM", Log::ERROR, "shutdown_action, VM in a wrong state.");
|
||||
}
|
||||
|
||||
vm->unlock();
|
||||
});
|
||||
}
|
||||
|
||||
@ -548,7 +536,7 @@ void LifeCycleManager::trigger_undeploy(int vid, bool hard,
|
||||
|
||||
trigger([this, hard, vid, uid, gid, req_id] {
|
||||
unsigned int port;
|
||||
VirtualMachine * vm = vmpool->get(vid);
|
||||
auto vm = vmpool->get(vid);
|
||||
|
||||
if ( vm == nullptr )
|
||||
{
|
||||
@ -590,9 +578,9 @@ void LifeCycleManager::trigger_undeploy(int vid, bool hard,
|
||||
clpool->release_vnc_port(vm->get_cid(), port);
|
||||
}
|
||||
|
||||
vmpool->update_history(vm);
|
||||
vmpool->update_history(vm.get());
|
||||
|
||||
vmpool->update(vm);
|
||||
vmpool->update(vm.get());
|
||||
}
|
||||
else if (vm->get_state() == VirtualMachine::POWEROFF)
|
||||
{
|
||||
@ -607,20 +595,18 @@ void LifeCycleManager::trigger_undeploy(int vid, bool hard,
|
||||
|
||||
vm->set_epilog_stime(time(0));
|
||||
|
||||
vmpool->update_history(vm);
|
||||
vmpool->update_history(vm.get());
|
||||
|
||||
vmpool->update(vm);
|
||||
vmpool->update(vm.get());
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
tm->trigger_epilog_stop(vm);
|
||||
tm->trigger_epilog_stop(vm.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
vm->log("LCM", Log::ERROR, "undeploy_action, VM in a wrong state.");
|
||||
}
|
||||
|
||||
vm->unlock();
|
||||
});
|
||||
}
|
||||
|
||||
@ -652,7 +638,7 @@ void LifeCycleManager::trigger_poweroff(int vid, bool hard,
|
||||
int req_id = ra.req_id;
|
||||
|
||||
trigger([this, hard, vid, uid, gid, req_id] {
|
||||
VirtualMachine * vm = vmpool->get(vid);
|
||||
auto vm = vmpool->get(vid);
|
||||
|
||||
if ( vm == nullptr )
|
||||
{
|
||||
@ -685,16 +671,14 @@ void LifeCycleManager::trigger_poweroff(int vid, bool hard,
|
||||
vmm->trigger_shutdown(vid);
|
||||
}
|
||||
|
||||
vmpool->update_history(vm);
|
||||
vmpool->update_history(vm.get());
|
||||
|
||||
vmpool->update(vm);
|
||||
vmpool->update(vm.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
vm->log("LCM", Log::ERROR, "poweroff_action, VM in a wrong state.");
|
||||
}
|
||||
|
||||
vm->unlock();
|
||||
});
|
||||
}
|
||||
|
||||
@ -710,7 +694,7 @@ void LifeCycleManager::trigger_restore(int vid, const RequestAttributes& ra)
|
||||
trigger([this, vid, uid, gid, req_id] {
|
||||
ostringstream os;
|
||||
|
||||
VirtualMachine * vm = vmpool->get(vid);
|
||||
auto vm = vmpool->get(vid);
|
||||
|
||||
if ( vm == nullptr )
|
||||
{
|
||||
@ -734,7 +718,7 @@ void LifeCycleManager::trigger_restore(int vid, const RequestAttributes& ra)
|
||||
|
||||
vm->set_running_etime(the_time);
|
||||
|
||||
vmpool->update_history(vm);
|
||||
vmpool->update_history(vm.get());
|
||||
|
||||
vm->cp_history();
|
||||
|
||||
@ -744,9 +728,9 @@ void LifeCycleManager::trigger_restore(int vid, const RequestAttributes& ra)
|
||||
|
||||
vm->set_action(VMActions::RESUME_ACTION, uid, gid, req_id);
|
||||
|
||||
vmpool->insert_history(vm);
|
||||
vmpool->insert_history(vm.get());
|
||||
|
||||
vmpool->update(vm);
|
||||
vmpool->update(vm.get());
|
||||
|
||||
//----------------------------------------------------
|
||||
|
||||
@ -756,8 +740,6 @@ void LifeCycleManager::trigger_restore(int vid, const RequestAttributes& ra)
|
||||
{
|
||||
vm->log("LCM", Log::ERROR, "restore_action, VM in a wrong state.");
|
||||
}
|
||||
|
||||
vm->unlock();
|
||||
});
|
||||
}
|
||||
|
||||
@ -771,7 +753,7 @@ void LifeCycleManager::trigger_restart(int vid, const RequestAttributes& ra)
|
||||
int req_id = ra.req_id;
|
||||
|
||||
trigger([this, vid, uid, gid, req_id] {
|
||||
VirtualMachine * vm = vmpool->get(vid);
|
||||
auto vm = vmpool->get(vid);
|
||||
|
||||
if ( vm == nullptr )
|
||||
{
|
||||
@ -783,7 +765,7 @@ void LifeCycleManager::trigger_restart(int vid, const RequestAttributes& ra)
|
||||
{
|
||||
vm->set_state(VirtualMachine::BOOT_UNKNOWN);
|
||||
|
||||
vmpool->update(vm);
|
||||
vmpool->update(vm.get());
|
||||
|
||||
vmm->trigger_deploy(vid);
|
||||
}
|
||||
@ -799,7 +781,7 @@ void LifeCycleManager::trigger_restart(int vid, const RequestAttributes& ra)
|
||||
|
||||
vm->set_running_etime(the_time);
|
||||
|
||||
vmpool->update_history(vm);
|
||||
vmpool->update_history(vm.get());
|
||||
|
||||
vm->cp_history();
|
||||
|
||||
@ -809,9 +791,9 @@ void LifeCycleManager::trigger_restart(int vid, const RequestAttributes& ra)
|
||||
|
||||
vm->set_action(VMActions::RESUME_ACTION, uid, gid, req_id);
|
||||
|
||||
vmpool->insert_history(vm);
|
||||
vmpool->insert_history(vm.get());
|
||||
|
||||
vmpool->update(vm);
|
||||
vmpool->update(vm.get());
|
||||
|
||||
vmm->trigger_deploy(vid);
|
||||
}
|
||||
@ -819,8 +801,6 @@ void LifeCycleManager::trigger_restart(int vid, const RequestAttributes& ra)
|
||||
{
|
||||
vm->log("LCM", Log::ERROR, "restart_action, VM in a wrong state.");
|
||||
}
|
||||
|
||||
vm->unlock();
|
||||
});
|
||||
}
|
||||
|
||||
@ -836,17 +816,11 @@ void LifeCycleManager::trigger_delete(int vid, const RequestAttributes& ra)
|
||||
trigger([this, vid, uid, gid, req_id] {
|
||||
int image_id = -1;
|
||||
|
||||
VirtualMachine * vm = vmpool->get(vid);
|
||||
|
||||
if ( vm == nullptr )
|
||||
if ( auto vm = vmpool->get(vid) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( vm->get_state() != VirtualMachine::ACTIVE )
|
||||
{
|
||||
vm->log("LCM", Log::ERROR, "clean_action, VM in a wrong state.");
|
||||
vm->unlock();
|
||||
|
||||
return;
|
||||
}
|
||||
@ -855,31 +829,30 @@ void LifeCycleManager::trigger_delete(int vid, const RequestAttributes& ra)
|
||||
{
|
||||
case VirtualMachine::CLEANUP_RESUBMIT:
|
||||
vm->set_state(VirtualMachine::CLEANUP_DELETE);
|
||||
vmpool->update(vm);
|
||||
vmpool->update(vm.get());
|
||||
|
||||
case VirtualMachine::CLEANUP_DELETE:
|
||||
dm->trigger_done(vid);
|
||||
break;
|
||||
|
||||
default:
|
||||
clean_up_vm(vm, true, image_id, uid, gid, req_id);
|
||||
clean_up_vm(vm.get(), true, image_id, uid, gid, req_id);
|
||||
dm->trigger_done(vid);
|
||||
break;
|
||||
}
|
||||
|
||||
vm->unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( image_id != -1 )
|
||||
{
|
||||
Image * image = ipool->get(image_id);
|
||||
|
||||
if ( image != nullptr )
|
||||
if ( auto image = ipool->get(image_id) )
|
||||
{
|
||||
image->set_state(Image::ERROR);
|
||||
|
||||
ipool->update(image);
|
||||
|
||||
image->unlock();
|
||||
ipool->update(image.get());
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -902,21 +875,13 @@ void LifeCycleManager::trigger_delete_recreate(int vid,
|
||||
|
||||
int vm_uid, vm_gid;
|
||||
|
||||
VirtualMachine * vm;
|
||||
|
||||
int image_id = -1;
|
||||
|
||||
vm = vmpool->get(vid);
|
||||
|
||||
if ( vm == nullptr )
|
||||
if ( auto vm = vmpool->get(vid) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( vm->get_state() != VirtualMachine::ACTIVE )
|
||||
{
|
||||
vm->log("LCM", Log::ERROR, "clean_action, VM in a wrong state.");
|
||||
vm->unlock();
|
||||
|
||||
return;
|
||||
}
|
||||
@ -935,28 +900,27 @@ void LifeCycleManager::trigger_delete_recreate(int vid,
|
||||
vm_uid = vm->get_uid();
|
||||
vm_gid = vm->get_gid();
|
||||
|
||||
clean_up_vm(vm, false, image_id, uid, gid, req_id);
|
||||
clean_up_vm(vm.get(), false, image_id, uid, gid, req_id);
|
||||
|
||||
vm->delete_non_persistent_disk_snapshots(&vm_quotas_snp,
|
||||
ds_quotas_snp);
|
||||
|
||||
vmpool->update(vm);
|
||||
vmpool->update(vm.get());
|
||||
break;
|
||||
}
|
||||
|
||||
vm->unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ( image_id != -1 )
|
||||
{
|
||||
Image* image = ipool->get(image_id);
|
||||
|
||||
if ( image != nullptr )
|
||||
if ( auto image = ipool->get(image_id) )
|
||||
{
|
||||
image->set_state(Image::ERROR);
|
||||
|
||||
ipool->update(image);
|
||||
|
||||
image->unlock();
|
||||
ipool->update(image.get());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1708,9 +1672,8 @@ void LifeCycleManager::trigger_updatesg(int sgid)
|
||||
{
|
||||
trigger([this, sgid] {
|
||||
int vmid, rc;
|
||||
VirtualMachine * vm;
|
||||
|
||||
SecurityGroup * sg = sgpool->get(sgid);
|
||||
auto sg = sgpool->get(sgid);
|
||||
|
||||
if ( sg == nullptr )
|
||||
{
|
||||
@ -1728,26 +1691,21 @@ void LifeCycleManager::trigger_updatesg(int sgid)
|
||||
|
||||
rc = sg->get_outdated(vmid);
|
||||
|
||||
sgpool->update(sg);
|
||||
sgpool->update(sg.get());
|
||||
|
||||
sg->unlock();
|
||||
sg.reset();
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vm = vmpool->get(vmid);
|
||||
|
||||
if ( vm == nullptr )
|
||||
if ( auto vm = vmpool->get(vmid) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
VirtualMachine::LcmState lstate = vm->get_lcm_state();
|
||||
VirtualMachine::VmState state = vm->get_state();
|
||||
|
||||
if ( state != VirtualMachine::ACTIVE ) //Update just VM information
|
||||
if ( state != VirtualMachine::ACTIVE ) //Update just VM info
|
||||
{
|
||||
is_tmpl = true;
|
||||
}
|
||||
@ -1755,7 +1713,7 @@ void LifeCycleManager::trigger_updatesg(int sgid)
|
||||
{
|
||||
switch (lstate)
|
||||
{
|
||||
//Cannnot update these VMs, SG rules being updated/created
|
||||
//Cannnot update VM, SG rules being updated/created
|
||||
case VirtualMachine::BOOT:
|
||||
case VirtualMachine::BOOT_MIGRATE:
|
||||
case VirtualMachine::BOOT_SUSPENDED:
|
||||
@ -1832,9 +1790,9 @@ void LifeCycleManager::trigger_updatesg(int sgid)
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Update VM template with the new security group rules & trigger update
|
||||
// ---------------------------------------------------------------------
|
||||
// -------------------------------------------------------------
|
||||
// Update VM template with the new SG rules & trigger update
|
||||
// -------------------------------------------------------------
|
||||
if ( is_tmpl || is_update )
|
||||
{
|
||||
vector<VectorAttribute *> sg_rules;
|
||||
@ -1845,15 +1803,18 @@ void LifeCycleManager::trigger_updatesg(int sgid)
|
||||
|
||||
vm->add_template_attribute(sg_rules);
|
||||
|
||||
vmpool->update(vm);
|
||||
vmpool->update(vm.get());
|
||||
}
|
||||
|
||||
if ( is_update )
|
||||
{
|
||||
vmm->updatesg(vm, sgid);
|
||||
vmm->updatesg(vm.get(), sgid);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
vm->unlock();
|
||||
|
||||
sg = sgpool->get(sgid);
|
||||
|
||||
@ -1878,11 +1839,10 @@ void LifeCycleManager::trigger_updatesg(int sgid)
|
||||
sg->add_updating(vmid);
|
||||
}
|
||||
|
||||
sgpool->update(sg);
|
||||
sgpool->update(sg.get());
|
||||
|
||||
if (is_update)
|
||||
{
|
||||
sg->unlock();
|
||||
return;
|
||||
}
|
||||
} while (true);
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -230,20 +230,16 @@ int MarketPlaceAppPool::import(const std::string& t64, int mp_id,
|
||||
}
|
||||
}
|
||||
|
||||
MarketPlaceApp * mp_aux = get(app->name, 0);
|
||||
|
||||
if( mp_aux != 0 ) //Marketplace app already imported
|
||||
if ( auto mp_aux = get(app->name, 0) ) //Marketplace app already imported
|
||||
{
|
||||
app_id = mp_aux->oid;
|
||||
|
||||
if ( mp_aux->version != app->version || mp_aux->md5 != app->md5 )
|
||||
{
|
||||
mp_aux->from_template64(t64, error_str);
|
||||
update(mp_aux);
|
||||
update(mp_aux.get());
|
||||
}
|
||||
|
||||
mp_aux->unlock();
|
||||
|
||||
delete app;
|
||||
|
||||
return -2;
|
||||
|
@ -217,12 +217,8 @@ void MarketPlaceManager::monitor_market(int mp_id)
|
||||
return;
|
||||
}
|
||||
|
||||
MarketPlace * mp = mppool->get(mp_id);
|
||||
|
||||
if ( mp == nullptr )
|
||||
if ( auto mp = mppool->get(mp_id) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
mp_name = mp->get_name();
|
||||
|
||||
@ -231,20 +227,20 @@ void MarketPlaceManager::monitor_market(int mp_id)
|
||||
NebulaLog::log("MKP", Log::DEBUG, "Monitoring disabled for market: " +
|
||||
mp_name);
|
||||
|
||||
mp->unlock();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ( mp->get_zone_id() != Nebula::instance().get_zone_id() )
|
||||
{
|
||||
mp->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
mp->to_xml(mp_data);
|
||||
|
||||
mp->unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string drv_msg(MarketPlaceManager::format_message("", mp_data, ""));
|
||||
|
||||
|
@ -37,30 +37,28 @@ int MarketPlaceManager::import_app(
|
||||
{
|
||||
std::string app_data, image_data, ds_data;
|
||||
|
||||
Image * image;
|
||||
Datastore * ds;
|
||||
int app_id;
|
||||
int origin_id;
|
||||
|
||||
int ds_id;
|
||||
MarketPlaceApp::Type type;
|
||||
|
||||
market_msg_t msg(MarketPlaceManagerMessages::IMPORT, "", appid, "");
|
||||
|
||||
MarketPlaceApp * app = apppool->get_ro(appid);
|
||||
if ( auto app = apppool->get_ro(appid) )
|
||||
{
|
||||
app->to_xml(app_data);
|
||||
|
||||
if ( app == nullptr )
|
||||
type = app->get_type();
|
||||
|
||||
app_id = app->get_oid();
|
||||
origin_id = app->get_origin_id();
|
||||
}
|
||||
else
|
||||
{
|
||||
err = "Marketplace app no longer exists";
|
||||
return -1;
|
||||
}
|
||||
|
||||
app->to_xml(app_data);
|
||||
|
||||
MarketPlaceApp::Type type = app->get_type();
|
||||
|
||||
int app_id = app->get_oid();
|
||||
int origin_id = app->get_origin_id();
|
||||
|
||||
app->unlock();
|
||||
|
||||
auto mpmd = get();
|
||||
|
||||
if ( mpmd == nullptr )
|
||||
@ -71,34 +69,34 @@ int MarketPlaceManager::import_app(
|
||||
switch (type)
|
||||
{
|
||||
case MarketPlaceApp::IMAGE:
|
||||
image = ipool->get_ro(origin_id);
|
||||
{
|
||||
int ds_id;
|
||||
|
||||
if ( image == nullptr )
|
||||
if ( auto image = ipool->get_ro(origin_id) )
|
||||
{
|
||||
image->to_xml(image_data);
|
||||
|
||||
ds_id = image->get_ds_id();
|
||||
}
|
||||
else
|
||||
{
|
||||
goto error_noimage;
|
||||
}
|
||||
|
||||
image->to_xml(image_data);
|
||||
|
||||
ds_id = image->get_ds_id();
|
||||
|
||||
image->unlock();
|
||||
|
||||
ds = dspool->get_ro(ds_id);
|
||||
|
||||
if ( ds == nullptr )
|
||||
if ( auto ds = dspool->get_ro(ds_id) )
|
||||
{
|
||||
ds->to_xml(ds_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
goto error_nods;
|
||||
}
|
||||
|
||||
ds->to_xml(ds_data);
|
||||
|
||||
ds->unlock();
|
||||
|
||||
if (imagem->set_app_clone_state(app_id, origin_id, err) != 0)
|
||||
{
|
||||
goto error_clone;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MarketPlaceApp::VMTEMPLATE:
|
||||
@ -134,20 +132,14 @@ error_type:
|
||||
|
||||
error_clone:
|
||||
error_common:
|
||||
app = apppool->get(appid);
|
||||
|
||||
if ( app == nullptr )
|
||||
if (auto app = apppool->get(appid))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
app->set_template_error_message(err);
|
||||
|
||||
app->set_state(MarketPlaceApp::ERROR);
|
||||
|
||||
apppool->update(app);
|
||||
|
||||
app->unlock();
|
||||
apppool->update(app.get());
|
||||
}
|
||||
|
||||
NebulaLog::log("MKP", Log::ERROR, err);
|
||||
|
||||
@ -159,19 +151,19 @@ error_common:
|
||||
|
||||
void MarketPlaceManager::release_app_resources(int appid)
|
||||
{
|
||||
MarketPlaceApp * app = apppool->get_ro(appid);
|
||||
MarketPlaceApp::Type type;
|
||||
int iid;
|
||||
|
||||
if (app == nullptr)
|
||||
if (auto app = apppool->get_ro(appid))
|
||||
{
|
||||
type = app->get_type();
|
||||
iid = app->get_origin_id();
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MarketPlaceApp::Type type = app->get_type();
|
||||
|
||||
int iid = app->get_origin_id();
|
||||
|
||||
app->unlock();
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case MarketPlaceApp::IMAGE:
|
||||
@ -193,6 +185,11 @@ int MarketPlaceManager::delete_app(int appid, const std::string& market_data,
|
||||
{
|
||||
std::string app_data;
|
||||
|
||||
MarketPlaceApp::Type type;
|
||||
MarketPlaceApp::State state;
|
||||
|
||||
int market_id;
|
||||
|
||||
auto mpmd = get();
|
||||
|
||||
if ( mpmd == nullptr )
|
||||
@ -201,23 +198,21 @@ int MarketPlaceManager::delete_app(int appid, const std::string& market_data,
|
||||
return -1;
|
||||
}
|
||||
|
||||
MarketPlaceApp * app = apppool->get_ro(appid);
|
||||
if ( auto app = apppool->get_ro(appid) )
|
||||
{
|
||||
app->to_xml(app_data);
|
||||
|
||||
if (app == nullptr)
|
||||
type = app->get_type();
|
||||
state = app->get_state();
|
||||
|
||||
market_id = app->get_market_id();
|
||||
}
|
||||
else
|
||||
{
|
||||
error_str = "Marketplace app no longer exists";
|
||||
return -1;
|
||||
}
|
||||
|
||||
app->to_xml(app_data);
|
||||
|
||||
MarketPlaceApp::Type type = app->get_type();
|
||||
MarketPlaceApp::State state = app->get_state();
|
||||
|
||||
int market_id = app->get_market_id();
|
||||
|
||||
app->unlock();
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case MarketPlaceApp::IMAGE:
|
||||
@ -240,15 +235,11 @@ int MarketPlaceManager::delete_app(int appid, const std::string& market_data,
|
||||
return -1;
|
||||
}
|
||||
|
||||
MarketPlace * mp = mppool->get(market_id);
|
||||
|
||||
if ( mp != nullptr )
|
||||
if ( auto mp = mppool->get(market_id) )
|
||||
{
|
||||
mp->del_marketapp(appid);
|
||||
|
||||
mppool->update(mp);
|
||||
|
||||
mp->unlock();
|
||||
mppool->update(mp.get());
|
||||
}
|
||||
|
||||
string drv_msg(format_message(app_data, market_data, ""));
|
||||
|
@ -32,7 +32,7 @@ static void app_failure_action(
|
||||
int id,
|
||||
const string& msg)
|
||||
{
|
||||
MarketPlaceApp * app = apppool->get(id);
|
||||
auto app = apppool->get(id);
|
||||
|
||||
if (app == nullptr)
|
||||
{
|
||||
@ -45,9 +45,7 @@ static void app_failure_action(
|
||||
|
||||
app->set_state(MarketPlaceApp::ERROR);
|
||||
|
||||
apppool->update(app);
|
||||
|
||||
app->unlock();
|
||||
apppool->update(app.get());
|
||||
}
|
||||
|
||||
/* ************************************************************************** */
|
||||
@ -72,7 +70,6 @@ void MarketPlaceManager::_import(unique_ptr<market_msg_t> msg)
|
||||
|
||||
string error;
|
||||
|
||||
MarketPlaceApp * app;
|
||||
MarketPlaceAppTemplate tmpl;
|
||||
|
||||
string source;
|
||||
@ -116,7 +113,7 @@ void MarketPlaceManager::_import(unique_ptr<market_msg_t> msg)
|
||||
return;
|
||||
}
|
||||
|
||||
app = apppool->get(id);
|
||||
auto app = apppool->get(id);
|
||||
|
||||
if (app == nullptr)
|
||||
{
|
||||
@ -132,9 +129,7 @@ void MarketPlaceManager::_import(unique_ptr<market_msg_t> msg)
|
||||
|
||||
app->set_state(MarketPlaceApp::READY);
|
||||
|
||||
apppool->update(app);
|
||||
|
||||
app->unlock();
|
||||
apppool->update(app.get());
|
||||
|
||||
NebulaLog::info("MKP", "Marketplace app successfully imported");
|
||||
}
|
||||
@ -155,7 +150,7 @@ void MarketPlaceManager::_delete(unique_ptr<market_msg_t> msg)
|
||||
ostringstream eoss("Error removing app from marketplace", ios::ate);
|
||||
|
||||
int id = msg->oid();
|
||||
MarketPlaceApp * app = apppool->get(id);
|
||||
auto app = apppool->get(id);
|
||||
|
||||
if (app == nullptr)
|
||||
{
|
||||
@ -164,9 +159,7 @@ void MarketPlaceManager::_delete(unique_ptr<market_msg_t> msg)
|
||||
|
||||
source = app->get_source();
|
||||
|
||||
rc = apppool->drop(app, error);
|
||||
|
||||
app->unlock();
|
||||
rc = apppool->drop(app.get(), error);
|
||||
|
||||
if (msg->status() == "FAILURE")
|
||||
{
|
||||
@ -236,21 +229,22 @@ void MarketPlaceManager::_monitor(unique_ptr<market_msg_t> msg)
|
||||
return;
|
||||
}
|
||||
|
||||
MarketPlace * market = mppool->get(id);
|
||||
set<int> apps_mp;
|
||||
string name;
|
||||
|
||||
if (market == nullptr)
|
||||
if ( auto market = mppool->get(id) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
set<int> apps_mp = market->get_marketapp_ids();
|
||||
string name = market->get_name();
|
||||
apps_mp = market->get_marketapp_ids();
|
||||
name = market->get_name();
|
||||
|
||||
market->update_monitor(monitor_data);
|
||||
|
||||
mppool->update(market);
|
||||
|
||||
market->unlock();
|
||||
mppool->update(market.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vector<SingleAttribute *> apps;
|
||||
string err;
|
||||
@ -268,15 +262,11 @@ void MarketPlaceManager::_monitor(unique_ptr<market_msg_t> msg)
|
||||
}
|
||||
else if (rc >= 0) //-2 means app already imported
|
||||
{
|
||||
MarketPlace * market = mppool->get(id);
|
||||
|
||||
if (market != nullptr)
|
||||
if ( auto market = mppool->get(id) )
|
||||
{
|
||||
market->add_marketapp(rc);
|
||||
|
||||
mppool->update(market);
|
||||
|
||||
market->unlock();
|
||||
mppool->update(market.get());
|
||||
}
|
||||
}
|
||||
|
||||
@ -293,24 +283,20 @@ void MarketPlaceManager::_monitor(unique_ptr<market_msg_t> msg)
|
||||
{
|
||||
string error;
|
||||
|
||||
MarketPlaceApp * app = apppool->get(i);
|
||||
|
||||
if (app == nullptr)
|
||||
if (auto app = apppool->get(i))
|
||||
{
|
||||
rc = apppool->drop(app.get(), error);
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
rc = apppool->drop(app, error);
|
||||
|
||||
app->unlock();
|
||||
|
||||
market = mppool->get(id);
|
||||
auto market = mppool->get(id);
|
||||
|
||||
market->del_marketapp(i);
|
||||
|
||||
mppool->update(market);
|
||||
|
||||
market->unlock();
|
||||
mppool->update(market.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ MarketPlacePool::MarketPlacePool(SqlDB * db, bool is_federation_slave)
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
UserPool * upool = nd.get_upool();
|
||||
User * oneadmin = upool->get_ro(0);
|
||||
auto oneadmin = upool->get_ro(0);
|
||||
|
||||
string error;
|
||||
|
||||
@ -109,8 +109,6 @@ MarketPlacePool::MarketPlacePool(SqlDB * db, bool is_federation_slave)
|
||||
oneadmin->get_umask(),
|
||||
dh_tmpl);
|
||||
|
||||
oneadmin->unlock();
|
||||
|
||||
marketplace->set_permissions(1,1,1, 1,0,0, 1,0,0, error);
|
||||
lxc_marketplace->set_permissions(1,1,1, 1,0,0, 1,0,0, error);
|
||||
tk_marketplace->set_permissions(1,1,1, 1,0,0, 1,0,0, error);
|
||||
|
@ -117,8 +117,7 @@ int get_image_path(VirtualMachine * vm,
|
||||
|
||||
ImagePool * ipool = nd.get_ipool();
|
||||
UserPool * upool = nd.get_upool();
|
||||
Image * img = 0;
|
||||
User * user = 0;
|
||||
unique_ptr<Image> img;
|
||||
int iid = -1;
|
||||
|
||||
PoolObjectAuth perm;
|
||||
@ -151,7 +150,7 @@ int get_image_path(VirtualMachine * vm,
|
||||
|
||||
img = ipool->get_ro(val1, uid);
|
||||
|
||||
if ( img == 0 )
|
||||
if ( img == nullptr )
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "User " << uid << " does not own an image with name: " << val1
|
||||
@ -173,7 +172,7 @@ int get_image_path(VirtualMachine * vm,
|
||||
img = ipool->get_ro(iid);
|
||||
}
|
||||
|
||||
if ( img == 0 )
|
||||
if ( img == nullptr )
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Image with ID: " << iid << " does not exist";
|
||||
@ -193,16 +192,11 @@ int get_image_path(VirtualMachine * vm,
|
||||
|
||||
img->get_permissions(perm);
|
||||
|
||||
img->unlock();;
|
||||
|
||||
set<int> gids;
|
||||
|
||||
user = upool->get_ro(vm->get_uid());
|
||||
|
||||
if (user != 0)
|
||||
if (auto user = upool->get_ro(vm->get_uid()))
|
||||
{
|
||||
gids = user->get_groups();
|
||||
user->unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -83,8 +83,7 @@ int get_image_path(VirtualMachine * vm,
|
||||
|
||||
ImagePool * ipool = nd.get_ipool();
|
||||
UserPool * upool = nd.get_upool();
|
||||
Image * img = 0;
|
||||
User * user = 0;
|
||||
unique_ptr<Image> img;
|
||||
int iid = -1;
|
||||
|
||||
PoolObjectAuth perm;
|
||||
@ -117,7 +116,7 @@ int get_image_path(VirtualMachine * vm,
|
||||
|
||||
img = ipool->get_ro(val1, uid);
|
||||
|
||||
if ( img == 0 )
|
||||
if ( img == nullptr )
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "User " << uid << " does not own an image with name: " << val1
|
||||
@ -139,7 +138,7 @@ int get_image_path(VirtualMachine * vm,
|
||||
img = ipool->get_ro(iid);
|
||||
}
|
||||
|
||||
if ( img == 0 )
|
||||
if ( img == nullptr )
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Image with ID: " << iid << " does not exist";
|
||||
@ -159,16 +158,11 @@ int get_image_path(VirtualMachine * vm,
|
||||
|
||||
img->get_permissions(perm);
|
||||
|
||||
img->unlock();;
|
||||
|
||||
set<int> gids;
|
||||
|
||||
user = upool->get_ro(vm->get_uid());
|
||||
|
||||
if (user != 0)
|
||||
if (auto user = upool->get_ro(vm->get_uid()))
|
||||
{
|
||||
gids = user->get_groups();
|
||||
user->unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -114,7 +114,6 @@ void get_image_attribute(VirtualMachine * vm,
|
||||
Nebula& nd = Nebula::instance();
|
||||
|
||||
ImagePool * ipool = nd.get_ipool();
|
||||
Image * img;
|
||||
int iid = -1;
|
||||
|
||||
int num;
|
||||
@ -159,9 +158,9 @@ void get_image_attribute(VirtualMachine * vm,
|
||||
// ----------------------------------------------
|
||||
// Get the attribute template from the image
|
||||
// ----------------------------------------------
|
||||
img = ipool->get_ro(iid);
|
||||
auto img = ipool->get_ro(iid);
|
||||
|
||||
if ( img == 0 )
|
||||
if ( img == nullptr )
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -174,8 +173,6 @@ void get_image_attribute(VirtualMachine * vm,
|
||||
{
|
||||
img->get_template_attribute(attr_name, attr_value);
|
||||
}
|
||||
|
||||
img->unlock();
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -190,7 +187,6 @@ void get_network_attribute(VirtualMachine * vm,
|
||||
Nebula& nd = Nebula::instance();
|
||||
|
||||
VirtualNetworkPool * vnpool = nd.get_vnpool();
|
||||
VirtualNetwork * vn;
|
||||
int ar_id, vnet_id = -1;
|
||||
|
||||
int num;
|
||||
@ -264,9 +260,9 @@ void get_network_attribute(VirtualMachine * vm,
|
||||
// ----------------------------------------------
|
||||
// Get the attribute template from the image
|
||||
// ----------------------------------------------
|
||||
vn = vnpool->get_ro(vnet_id);
|
||||
auto vn = vnpool->get_ro(vnet_id);
|
||||
|
||||
if ( vn == 0 )
|
||||
if (vn == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -279,8 +275,6 @@ void get_network_attribute(VirtualMachine * vm,
|
||||
{
|
||||
vn->get_template_attribute(attr_name, attr_value, ar_id);
|
||||
}
|
||||
|
||||
vn->unlock();
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -293,13 +287,12 @@ void get_user_attribute(VirtualMachine * vm,
|
||||
Nebula& nd = Nebula::instance();
|
||||
|
||||
UserPool * upool = nd.get_upool();
|
||||
User * user;
|
||||
|
||||
attr_value.clear();
|
||||
|
||||
user = upool->get_ro(vm->get_uid());
|
||||
auto user = upool->get_ro(vm->get_uid());
|
||||
|
||||
if ( user == 0 )
|
||||
if ( user == nullptr )
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -312,8 +305,6 @@ void get_user_attribute(VirtualMachine * vm,
|
||||
{
|
||||
user->get_template_attribute(attr_name, attr_value);
|
||||
}
|
||||
|
||||
user->unlock();
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -79,7 +79,6 @@ void get_image_attribute(VirtualMachine * vm,
|
||||
Nebula& nd = Nebula::instance();
|
||||
|
||||
ImagePool * ipool = nd.get_ipool();
|
||||
Image * img;
|
||||
int iid = -1;
|
||||
|
||||
int num;
|
||||
@ -124,9 +123,9 @@ void get_image_attribute(VirtualMachine * vm,
|
||||
// ----------------------------------------------
|
||||
// Get the attribute template from the image
|
||||
// ----------------------------------------------
|
||||
img = ipool->get_ro(iid);
|
||||
auto img = ipool->get_ro(iid);
|
||||
|
||||
if ( img == 0 )
|
||||
if ( img == nullptr )
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -139,8 +138,6 @@ void get_image_attribute(VirtualMachine * vm,
|
||||
{
|
||||
img->get_template_attribute(attr_name, attr_value);
|
||||
}
|
||||
|
||||
img->unlock();
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -155,7 +152,6 @@ void get_network_attribute(VirtualMachine * vm,
|
||||
Nebula& nd = Nebula::instance();
|
||||
|
||||
VirtualNetworkPool * vnpool = nd.get_vnpool();
|
||||
VirtualNetwork * vn;
|
||||
int ar_id, vnet_id = -1;
|
||||
|
||||
int num;
|
||||
@ -229,9 +225,9 @@ void get_network_attribute(VirtualMachine * vm,
|
||||
// ----------------------------------------------
|
||||
// Get the attribute template from the image
|
||||
// ----------------------------------------------
|
||||
vn = vnpool->get_ro(vnet_id);
|
||||
auto vn = vnpool->get_ro(vnet_id);
|
||||
|
||||
if ( vn == 0 )
|
||||
if (vn == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -244,8 +240,6 @@ void get_network_attribute(VirtualMachine * vm,
|
||||
{
|
||||
vn->get_template_attribute(attr_name, attr_value, ar_id);
|
||||
}
|
||||
|
||||
vn->unlock();
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -258,13 +252,12 @@ void get_user_attribute(VirtualMachine * vm,
|
||||
Nebula& nd = Nebula::instance();
|
||||
|
||||
UserPool * upool = nd.get_upool();
|
||||
User * user;
|
||||
|
||||
attr_value.clear();
|
||||
|
||||
user = upool->get_ro(vm->get_uid());
|
||||
auto user = upool->get_ro(vm->get_uid());
|
||||
|
||||
if ( user == 0 )
|
||||
if ( user == nullptr )
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -277,8 +270,6 @@ void get_user_attribute(VirtualMachine * vm,
|
||||
{
|
||||
user->get_template_attribute(attr_name, attr_value);
|
||||
}
|
||||
|
||||
user->unlock();
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -165,66 +165,6 @@ int PoolSQL::allocate(PoolObjectSQL *objsql, string& error_str)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
PoolObjectSQL * PoolSQL::get(int oid)
|
||||
{
|
||||
if ( oid < 0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
pthread_mutex_t * object_lock = cache.lock_line(oid);
|
||||
|
||||
PoolObjectSQL * objectsql = create();
|
||||
|
||||
objectsql->oid = oid;
|
||||
|
||||
objectsql->ro = false;
|
||||
|
||||
objectsql->mutex = object_lock;
|
||||
|
||||
int rc = objectsql->select(db);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
objectsql->unlock(); //Free object and unlock cache line mutex
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return objectsql;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
PoolObjectSQL * PoolSQL::get_ro(int oid)
|
||||
{
|
||||
if ( oid < 0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
PoolObjectSQL * objectsql = create();
|
||||
|
||||
objectsql->oid = oid;
|
||||
|
||||
objectsql->ro = true;
|
||||
|
||||
int rc = objectsql->select(db);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
objectsql->unlock(); //Free object;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return objectsql;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void PoolSQL::exist(const string& id_str, std::set<int>& id_list)
|
||||
{
|
||||
std::vector<int> existing_items;
|
||||
@ -245,37 +185,6 @@ void PoolSQL::exist(const string& id_str, std::set<int>& id_list)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
PoolObjectSQL * PoolSQL::get(const string& name, int ouid)
|
||||
{
|
||||
|
||||
int oid = PoolObjectSQL::select_oid(db, table.c_str(), name, ouid);
|
||||
|
||||
if ( oid == -1 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return get(oid);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
PoolObjectSQL * PoolSQL::get_ro(const string& name, int uid)
|
||||
{
|
||||
int oid = PoolObjectSQL::select_oid(db, table.c_str(), name, uid);
|
||||
|
||||
if ( oid == -1 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return get_ro(oid);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int PoolSQL::dump(string& oss, const string& elem_name, const string& column,
|
||||
const char* table, const string& where, int sid, int eid, bool desc)
|
||||
{
|
||||
|
@ -112,26 +112,22 @@ void FedReplicaManager::update_zones(std::vector<int>& zone_ids)
|
||||
}
|
||||
else
|
||||
{
|
||||
Zone * zone = zpool->get(*it);
|
||||
|
||||
if ( zone == 0 )
|
||||
{
|
||||
it = zone_ids.erase(it);
|
||||
}
|
||||
else
|
||||
if ( auto zone = zpool->get(*it) )
|
||||
{
|
||||
std::string zedp;
|
||||
|
||||
zone->get_template_attribute("ENDPOINT", zedp);
|
||||
|
||||
zone->unlock();
|
||||
|
||||
ZoneServers * zs = new ZoneServers(*it, last_index, zedp);
|
||||
|
||||
zones.insert(make_pair(*it, zs));
|
||||
|
||||
++it;
|
||||
}
|
||||
else
|
||||
{
|
||||
it = zone_ids.erase(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -148,17 +144,15 @@ void FedReplicaManager::add_zone(int zone_id)
|
||||
Nebula& nd = Nebula::instance();
|
||||
ZonePool * zpool = nd.get_zonepool();
|
||||
|
||||
Zone * zone = zpool->get(zone_id);
|
||||
|
||||
if ( zone == 0 )
|
||||
if (auto zone = zpool->get_ro(zone_id))
|
||||
{
|
||||
zone->get_template_attribute("ENDPOINT", zedp);
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
zone->get_template_attribute("ENDPOINT", zedp);
|
||||
|
||||
zone->unlock();
|
||||
|
||||
lock_guard<mutex> ul(fed_mutex);
|
||||
|
||||
int last_index = logdb->last_federated();
|
||||
|
@ -60,7 +60,8 @@ RaftManager::RaftManager(int id, const VectorAttribute * leader_hook_mad,
|
||||
, term(0)
|
||||
, num_servers(0)
|
||||
, reconciling(false)
|
||||
, timer_thread(timer_period_ms / 1000.0, [this](){timer_action();})
|
||||
, timer_thread()
|
||||
, purge_thread(log_purge, [this](){purge_action();})
|
||||
, commit(0)
|
||||
, leader_hook(0)
|
||||
, follower_hook(0)
|
||||
@ -183,8 +184,10 @@ RaftManager::RaftManager(int id, const VectorAttribute * leader_hook_mad,
|
||||
{
|
||||
follower_hook->execute();
|
||||
}
|
||||
};
|
||||
|
||||
// timer_thread has short period, start it at the end of the constructor
|
||||
timer_thread.start(timer_period_ms / 1000.0, [this](){timer_action();});
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -192,6 +195,7 @@ RaftManager::RaftManager(int id, const VectorAttribute * leader_hook_mad,
|
||||
void RaftManager::finalize()
|
||||
{
|
||||
timer_thread.stop();
|
||||
purge_thread.stop();
|
||||
|
||||
if (is_leader())
|
||||
{
|
||||
@ -696,10 +700,6 @@ int RaftManager::update_votedfor(int _votedfor)
|
||||
|
||||
void RaftManager::timer_action()
|
||||
{
|
||||
static int mark_tics = 0;
|
||||
static int purge_tics = 0;
|
||||
ostringstream oss;
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
|
||||
if ( nd.is_cache() )
|
||||
@ -707,31 +707,6 @@ void RaftManager::timer_action()
|
||||
return;
|
||||
}
|
||||
|
||||
mark_tics++;
|
||||
purge_tics++;
|
||||
|
||||
// Thread heartbeat
|
||||
if ( (mark_tics * timer_period_ms) >= 600000 )
|
||||
{
|
||||
NebulaLog::log("RCM",Log::INFO,"--Mark--");
|
||||
mark_tics = 0;
|
||||
}
|
||||
|
||||
// Database housekeeping
|
||||
if ( (purge_tics * timer_period_ms) >= purge_period_ms )
|
||||
{
|
||||
LogDB * logdb = nd.get_logdb();
|
||||
|
||||
int rc = logdb->purge_log();
|
||||
|
||||
purge_tics = 0;
|
||||
|
||||
if (rc > 0 && purge_period_ms > 60000) //logs removed, wakeup in 60s
|
||||
{
|
||||
purge_tics = (int) ((purge_period_ms - 60000)/timer_period_ms);
|
||||
}
|
||||
}
|
||||
|
||||
// Leadership
|
||||
struct timespec the_time;
|
||||
|
||||
@ -777,6 +752,38 @@ void RaftManager::timer_action()
|
||||
return;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void RaftManager::purge_action()
|
||||
{
|
||||
static int mark_tics = 0;
|
||||
ostringstream oss;
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
|
||||
if ( nd.is_cache() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
mark_tics++;
|
||||
|
||||
// Thread heartbeat
|
||||
if ( (mark_tics * purge_period_ms) >= 600000 )
|
||||
{
|
||||
NebulaLog::log("RCM",Log::INFO,"--Mark--");
|
||||
mark_tics = 0;
|
||||
}
|
||||
|
||||
// Database housekeeping
|
||||
LogDB * logdb = nd.get_logdb();
|
||||
|
||||
logdb->purge_log();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* XML-RPC interface to talk to followers */
|
||||
|
@ -487,14 +487,13 @@ Request::ErrorCode Request::basic_authorization(
|
||||
PoolObjectSQL::ObjectType auth_object,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
PoolObjectSQL * object;
|
||||
PoolObjectAuth perms;
|
||||
|
||||
if ( oid >= 0 )
|
||||
{
|
||||
object = pool->get(oid);
|
||||
auto object = pool->get_ro<PoolObjectSQL>(oid);
|
||||
|
||||
if ( object == 0 )
|
||||
if ( object == nullptr )
|
||||
{
|
||||
att.resp_id = oid;
|
||||
|
||||
@ -502,12 +501,9 @@ Request::ErrorCode Request::basic_authorization(
|
||||
}
|
||||
|
||||
object->get_permissions(perms);
|
||||
|
||||
object->unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
perms.obj_type = auth_object;
|
||||
}
|
||||
|
||||
@ -535,13 +531,12 @@ bool Request::user_quota_authorization (Template * tmpl,
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
UserPool * upool = nd.get_upool();
|
||||
User * user;
|
||||
|
||||
bool rc = false;
|
||||
|
||||
user = upool->get(att.uid);
|
||||
auto user = upool->get(att.uid);
|
||||
|
||||
if ( user == 0 )
|
||||
if ( user == nullptr )
|
||||
{
|
||||
error_str = "User not found";
|
||||
return false;
|
||||
@ -553,7 +548,7 @@ bool Request::user_quota_authorization (Template * tmpl,
|
||||
|
||||
if (rc == true)
|
||||
{
|
||||
upool->update_quotas(user);
|
||||
upool->update_quotas(user.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -565,8 +560,6 @@ bool Request::user_quota_authorization (Template * tmpl,
|
||||
error_str = oss.str();
|
||||
}
|
||||
|
||||
user->unlock();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -579,13 +572,12 @@ bool Request::group_quota_authorization (Template * tmpl,
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
GroupPool * gpool = nd.get_gpool();
|
||||
Group * group;
|
||||
|
||||
bool rc = false;
|
||||
|
||||
group = gpool->get(att.gid);
|
||||
auto group = gpool->get(att.gid);
|
||||
|
||||
if ( group == 0 )
|
||||
if ( group == nullptr )
|
||||
{
|
||||
error_str = "Group not found";
|
||||
return false;
|
||||
@ -597,7 +589,7 @@ bool Request::group_quota_authorization (Template * tmpl,
|
||||
|
||||
if (rc == true)
|
||||
{
|
||||
gpool->update_quotas(group);
|
||||
gpool->update_quotas(group.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -609,8 +601,6 @@ bool Request::group_quota_authorization (Template * tmpl,
|
||||
error_str = oss.str();
|
||||
}
|
||||
|
||||
group->unlock();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -623,20 +613,12 @@ void Request::user_quota_rollback(Template * tmpl,
|
||||
Nebula& nd = Nebula::instance();
|
||||
UserPool * upool = nd.get_upool();
|
||||
|
||||
User * user;
|
||||
|
||||
user = upool->get(att.uid);
|
||||
|
||||
if ( user == 0 )
|
||||
if ( auto user = upool->get(att.uid) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
user->quota.quota_del(qtype, tmpl);
|
||||
|
||||
upool->update_quotas(user);
|
||||
|
||||
user->unlock();
|
||||
upool->update_quotas(user.get());
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -648,20 +630,12 @@ void Request::group_quota_rollback(Template * tmpl,
|
||||
Nebula& nd = Nebula::instance();
|
||||
GroupPool * gpool = nd.get_gpool();
|
||||
|
||||
Group * group;
|
||||
|
||||
group = gpool->get(att.gid);
|
||||
|
||||
if ( group == 0 )
|
||||
if ( auto group = gpool->get(att.gid) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
group->quota.quota_del(qtype, tmpl);
|
||||
|
||||
gpool->update_quotas(group);
|
||||
|
||||
group->unlock();
|
||||
gpool->update_quotas(group.get());
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -986,9 +960,9 @@ int Request::get_info(
|
||||
string& name,
|
||||
bool throw_error)
|
||||
{
|
||||
PoolObjectSQL * ob;
|
||||
auto ob = pool->get_ro<PoolObjectSQL>(id);
|
||||
|
||||
if ((ob = pool->get(id)) == 0 )
|
||||
if (ob == nullptr)
|
||||
{
|
||||
if (throw_error)
|
||||
{
|
||||
@ -1004,8 +978,6 @@ int Request::get_info(
|
||||
|
||||
name = ob->get_name();
|
||||
|
||||
ob->unlock();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1118,12 +1090,10 @@ void RequestAttributes::set_auth_op(VMActions::Action action)
|
||||
AuthRequest::Operation result = AuthRequest::NONE;
|
||||
|
||||
auto& nd = Nebula::instance();
|
||||
auto user = nd.get_upool()->get_ro(uid);
|
||||
|
||||
if (user != nullptr)
|
||||
if (auto user = nd.get_upool()->get_ro(uid))
|
||||
{
|
||||
result = user->get_vm_auth_op(action);
|
||||
user->unlock();
|
||||
}
|
||||
|
||||
if (result != AuthRequest::NONE)
|
||||
@ -1132,12 +1102,9 @@ void RequestAttributes::set_auth_op(VMActions::Action action)
|
||||
return;
|
||||
}
|
||||
|
||||
auto group = nd.get_gpool()->get_ro(gid);
|
||||
|
||||
if (group != nullptr)
|
||||
if (auto group = nd.get_gpool()->get_ro(gid))
|
||||
{
|
||||
result = group->get_vm_auth_op(action);
|
||||
group->unlock();
|
||||
}
|
||||
|
||||
if (result != AuthRequest::NONE)
|
||||
|
@ -181,7 +181,6 @@ void RequestManagerAllocate::request_execute(xmlrpc_c::paramList const& params,
|
||||
|
||||
int rc, id;
|
||||
|
||||
Cluster * cluster = 0;
|
||||
int cluster_id = ClusterPool::NONE_CLUSTER_ID;
|
||||
string cluster_name = ClusterPool::NONE_CLUSTER_NAME;
|
||||
PoolObjectAuth cluster_perms;
|
||||
@ -237,9 +236,11 @@ void RequestManagerAllocate::request_execute(xmlrpc_c::paramList const& params,
|
||||
|
||||
if ( cluster_id != ClusterPool::NONE_CLUSTER_ID )
|
||||
{
|
||||
cluster = clpool->get(cluster_id);
|
||||
|
||||
if ( cluster == 0 )
|
||||
if (auto cluster = clpool->get(cluster_id))
|
||||
{
|
||||
rc = add_to_cluster(cluster.get(), id, att.resp_msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
att.resp_obj = PoolObjectSQL::CLUSTER;
|
||||
att.resp_id = cluster_id;
|
||||
@ -247,38 +248,24 @@ void RequestManagerAllocate::request_execute(xmlrpc_c::paramList const& params,
|
||||
return;
|
||||
}
|
||||
|
||||
rc = add_to_cluster(cluster, id, att.resp_msg);
|
||||
|
||||
if ( rc < 0 )
|
||||
{
|
||||
string drop_err;
|
||||
PoolObjectSQL * obj = 0;
|
||||
|
||||
cluster->unlock();
|
||||
|
||||
obj = pool->get(id);
|
||||
|
||||
if ( obj != 0 )
|
||||
if ( auto obj = pool->get<PoolObjectSQL>(id) )
|
||||
{
|
||||
pool->drop(obj, drop_err);
|
||||
obj->unlock();
|
||||
pool->drop(obj.get(), drop_err);
|
||||
}
|
||||
|
||||
failure_response(INTERNAL, att);
|
||||
return;
|
||||
}
|
||||
|
||||
cluster->unlock();
|
||||
}
|
||||
|
||||
//Take object body for hooks.
|
||||
PoolObjectSQL * obj = pool->get(id);
|
||||
|
||||
if (obj != nullptr)
|
||||
if (auto obj = pool->get<PoolObjectSQL>(id))
|
||||
{
|
||||
obj->to_xml(att.extra_xml);
|
||||
|
||||
obj->unlock();
|
||||
}
|
||||
|
||||
att.resp_id = id;
|
||||
@ -412,11 +399,8 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params,
|
||||
ImageTemplate * tmpl;
|
||||
Template img_usage;
|
||||
|
||||
Datastore * ds;
|
||||
Image::DiskType ds_disk_type;
|
||||
|
||||
MarketPlaceApp * app;
|
||||
MarketPlace * market;
|
||||
int app_id;
|
||||
int market_id;
|
||||
|
||||
@ -442,23 +426,13 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params,
|
||||
}
|
||||
|
||||
// ------------------------- Check Datastore exists ------------------------
|
||||
|
||||
if ((ds = dspool->get_ro(ds_id)) == 0 )
|
||||
if ( auto ds = dspool->get_ro(ds_id) )
|
||||
{
|
||||
att.resp_id = ds_id;
|
||||
att.resp_obj = PoolObjectSQL::DATASTORE;
|
||||
failure_response(NO_EXISTS, att);
|
||||
|
||||
delete tmpl;
|
||||
return;
|
||||
}
|
||||
|
||||
ds_type = ds->get_type();
|
||||
|
||||
if ( ds_type == Datastore::SYSTEM_DS )
|
||||
{
|
||||
ds->unlock();
|
||||
|
||||
att.resp_msg = "New images cannot be allocated in a system datastore.";
|
||||
failure_response(ALLOCATE, att);
|
||||
|
||||
@ -478,8 +452,17 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params,
|
||||
ds->get_template_attribute("DRIVER", ds_driver);
|
||||
|
||||
ds->to_xml(ds_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
att.resp_id = ds_id;
|
||||
att.resp_obj = PoolObjectSQL::DATASTORE;
|
||||
failure_response(NO_EXISTS, att);
|
||||
|
||||
delete tmpl;
|
||||
return;
|
||||
}
|
||||
|
||||
ds->unlock();
|
||||
|
||||
// --------------- Get the SIZE for the Image, (DS driver) -----------------
|
||||
|
||||
@ -487,9 +470,14 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params,
|
||||
{
|
||||
// This image comes from a MarketPlaceApp. Get the Market info and
|
||||
// the size.
|
||||
app = apppool->get_ro(app_id);
|
||||
if ( auto app = apppool->get_ro(app_id) )
|
||||
{
|
||||
app->to_template(tmpl);
|
||||
|
||||
if ( app == 0 )
|
||||
size_mb = app->get_size();
|
||||
market_id = app->get_market_id();
|
||||
}
|
||||
else
|
||||
{
|
||||
att.resp_msg = "Cannot determine image SIZE.";
|
||||
failure_response(INTERNAL, att);
|
||||
@ -498,28 +486,10 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params,
|
||||
return;
|
||||
}
|
||||
|
||||
app->to_template(tmpl);
|
||||
|
||||
size_mb = app->get_size();
|
||||
market_id = app->get_market_id();
|
||||
|
||||
app->unlock();
|
||||
|
||||
market = marketpool->get_ro(market_id);
|
||||
|
||||
if ( market == 0 )
|
||||
if ( auto market = marketpool->get_ro(market_id) )
|
||||
{
|
||||
att.resp_msg = "Could not get the appliance's market.";
|
||||
failure_response(INTERNAL, att);
|
||||
|
||||
delete tmpl;
|
||||
return;
|
||||
}
|
||||
|
||||
market->to_xml(extra_data);
|
||||
|
||||
market->unlock();
|
||||
|
||||
oss << size_mb;
|
||||
size_str = oss.str();
|
||||
|
||||
@ -530,6 +500,15 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params,
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
att.resp_msg = "Could not get the appliance's market.";
|
||||
failure_response(INTERNAL, att);
|
||||
|
||||
delete tmpl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = imagem->stat_image(tmpl, ds_data, size_str);
|
||||
|
||||
@ -654,25 +633,17 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params,
|
||||
return;
|
||||
}
|
||||
|
||||
ds = dspool->get(ds_id);
|
||||
|
||||
if ( ds != 0 ) // TODO: error otherwise or leave image in ERROR?
|
||||
if ( auto ds = dspool->get(ds_id) ) // TODO: error otherwise or leave image in ERROR?
|
||||
{
|
||||
ds->add_image(id);
|
||||
|
||||
dspool->update(ds);
|
||||
|
||||
ds->unlock();
|
||||
dspool->update(ds.get());
|
||||
}
|
||||
|
||||
// Take image body for Hooks
|
||||
Image * img = ipool->get(id);
|
||||
|
||||
if (img != nullptr)
|
||||
if (auto img = ipool->get(id))
|
||||
{
|
||||
img->to_xml(att.extra_xml);
|
||||
|
||||
img->unlock();
|
||||
}
|
||||
|
||||
att.resp_id = id;
|
||||
@ -852,9 +823,9 @@ bool UserAllocate::allocate_authorization(
|
||||
{
|
||||
int tmp_gid = xmlrpc_c::value_int(*it);
|
||||
|
||||
Group* group = gpool->get_ro(tmp_gid);
|
||||
auto group = gpool->get_ro(tmp_gid);
|
||||
|
||||
if (group == 0)
|
||||
if (group == nullptr)
|
||||
{
|
||||
att.resp_id = tmp_gid;
|
||||
att.resp_obj = PoolObjectSQL::GROUP;
|
||||
@ -873,8 +844,6 @@ bool UserAllocate::allocate_authorization(
|
||||
|
||||
ar.add_auth(AuthRequest::MANAGE, perms); // MANAGE GROUP
|
||||
}
|
||||
|
||||
group->unlock();
|
||||
}
|
||||
|
||||
if (UserPool::authorize(ar) == -1)
|
||||
@ -981,15 +950,11 @@ Request::ErrorCode GroupAllocate::pool_allocate(
|
||||
return Request::INTERNAL;
|
||||
}
|
||||
|
||||
Vdc* vdc = vdcpool->get(VdcPool::DEFAULT_ID);
|
||||
|
||||
if (vdc != 0)
|
||||
if (auto vdc = vdcpool->get(VdcPool::DEFAULT_ID))
|
||||
{
|
||||
rc = vdc->add_group(id, att.resp_msg);
|
||||
|
||||
vdcpool->update(vdc);
|
||||
|
||||
vdc->unlock();
|
||||
vdcpool->update(vdc.get());
|
||||
}
|
||||
|
||||
if (rc < 0)
|
||||
@ -1262,24 +1227,18 @@ Request::ErrorCode MarketPlaceAppAllocate::pool_allocate(
|
||||
|
||||
int mp_id = xmlrpc_c::value_int(paramList.getInt(2));
|
||||
std::string mp_data;
|
||||
std::string mp_name;
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
// Get Marketplace information for this app //
|
||||
// ---------------------------------------------------------------------- //
|
||||
MarketPlace * mp = mppool->get_ro(mp_id);
|
||||
|
||||
if ( mp == 0 )
|
||||
if ( auto mp = mppool->get_ro(mp_id) )
|
||||
{
|
||||
att.resp_msg = "Cannot find associated MARKETPLACE";
|
||||
return Request::INTERNAL;
|
||||
}
|
||||
|
||||
std::string mp_name = mp->get_name();
|
||||
mp_name = mp->get_name();
|
||||
|
||||
if ( !mp->is_action_supported(MarketPlaceApp::CREATE) )
|
||||
{
|
||||
att.resp_msg = "Create disabled for market: " + mp_name;
|
||||
mp->unlock();
|
||||
|
||||
return Request::ACTION;
|
||||
}
|
||||
@ -1287,14 +1246,17 @@ Request::ErrorCode MarketPlaceAppAllocate::pool_allocate(
|
||||
if ( mp->get_zone_id() != Nebula::instance().get_zone_id() )
|
||||
{
|
||||
att.resp_msg = "Marketplace is not in this OpenNebula zone";
|
||||
mp->unlock();
|
||||
|
||||
return Request::ACTION;
|
||||
}
|
||||
|
||||
mp->to_xml(mp_data);
|
||||
|
||||
mp->unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
att.resp_msg = "Cannot find associated MARKETPLACE";
|
||||
return Request::INTERNAL;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
// Allocate MarketPlaceApp request is forwarded to master for slaves //
|
||||
@ -1307,32 +1269,26 @@ Request::ErrorCode MarketPlaceAppAllocate::pool_allocate(
|
||||
return Request::INTERNAL;
|
||||
}
|
||||
|
||||
mp = mppool->get(mp_id);
|
||||
if ( auto mp = mppool->get(mp_id) )
|
||||
{
|
||||
mp->add_marketapp(id);
|
||||
|
||||
if ( mp == 0 )
|
||||
mppool->update(mp.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
att.resp_msg = "Marketplace no longer exists";
|
||||
|
||||
MarketPlaceApp * app = appool->get(id);
|
||||
|
||||
if ( app != 0 )
|
||||
if ( auto app = appool->get(id) )
|
||||
{
|
||||
string aux_str;
|
||||
|
||||
appool->drop(app, aux_str);
|
||||
|
||||
app->unlock();
|
||||
appool->drop(app.get(), aux_str);
|
||||
}
|
||||
|
||||
return Request::INTERNAL;
|
||||
}
|
||||
|
||||
mp->add_marketapp(id);
|
||||
|
||||
mppool->update(mp);
|
||||
|
||||
mp->unlock();
|
||||
|
||||
// ---------------------------------------------------------------------- //
|
||||
// Send request operation to market driver //
|
||||
// ---------------------------------------------------------------------- //
|
||||
|
@ -81,23 +81,19 @@ Request::ErrorCode RequestManagerChmod::chmod(
|
||||
bool recursive,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
PoolObjectSQL * object;
|
||||
|
||||
AuthRequest::Operation op = AuthRequest::MANAGE;
|
||||
PoolObjectAuth perms;
|
||||
|
||||
object = pool->get(oid);
|
||||
|
||||
if ( object == 0 )
|
||||
if (auto object = pool->get_ro<PoolObjectSQL>(oid))
|
||||
{
|
||||
object->get_permissions(perms);
|
||||
}
|
||||
else
|
||||
{
|
||||
att.resp_id = oid;
|
||||
return NO_EXISTS;
|
||||
}
|
||||
|
||||
object->get_permissions(perms);
|
||||
|
||||
object->unlock();
|
||||
|
||||
if ( owner_a == perms.owner_a )
|
||||
{
|
||||
owner_a = -1;
|
||||
@ -154,9 +150,9 @@ Request::ErrorCode RequestManagerChmod::chmod(
|
||||
|
||||
// ------------- Update the object ---------------------
|
||||
|
||||
object = pool->get(oid);
|
||||
auto object = pool->get<PoolObjectSQL>(oid);
|
||||
|
||||
if ( object == 0 )
|
||||
if ( object == nullptr )
|
||||
{
|
||||
att.resp_id = oid;
|
||||
return NO_EXISTS;
|
||||
@ -167,13 +163,10 @@ Request::ErrorCode RequestManagerChmod::chmod(
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
object->unlock();
|
||||
return INTERNAL;
|
||||
}
|
||||
|
||||
pool->update(object);
|
||||
|
||||
object->unlock();
|
||||
pool->update(object.get());
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
@ -212,10 +205,7 @@ Request::ErrorCode TemplateChmod::chmod(
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
VMTemplate* tmpl = static_cast<VMTemplatePool*>(pool)->get_ro(oid);
|
||||
|
||||
vector<VectorAttribute *> vdisks;
|
||||
vector<VectorAttribute *>::iterator i;
|
||||
|
||||
VirtualMachineDisks disks(true);
|
||||
|
||||
@ -227,30 +217,31 @@ Request::ErrorCode TemplateChmod::chmod(
|
||||
Nebula& nd = Nebula::instance();
|
||||
ImagePool* ipool = nd.get_ipool();
|
||||
|
||||
if ( tmpl == 0 )
|
||||
|
||||
if ( auto tmpl = static_cast<VMTemplatePool*>(pool)->get_ro(oid) )
|
||||
{
|
||||
tmpl->clone_disks(vdisks);
|
||||
}
|
||||
else
|
||||
{
|
||||
att.resp_id = oid;
|
||||
return NO_EXISTS;
|
||||
}
|
||||
|
||||
tmpl->clone_disks(vdisks);
|
||||
|
||||
tmpl->unlock();
|
||||
|
||||
disks.init(vdisks, false);
|
||||
|
||||
disks.get_image_ids(img_ids, att.uid);
|
||||
|
||||
for (set<int>::iterator it = img_ids.begin(); it != img_ids.end(); it++)
|
||||
for (auto img_id : img_ids)
|
||||
{
|
||||
ec = img_chmod.request_execute(ipool, *it, owner_u, owner_m, owner_a,
|
||||
ec = img_chmod.request_execute(ipool, img_id, owner_u, owner_m, owner_a,
|
||||
group_u, group_m, group_a, other_u, other_m, other_a, att);
|
||||
|
||||
if ( ec != SUCCESS )
|
||||
{
|
||||
NebulaLog::log("ReM", Log::ERROR, failure_message(ec, att));
|
||||
|
||||
error_ids.insert(*it);
|
||||
error_ids.insert(img_id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -288,9 +279,6 @@ void VirtualRouterChmod::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
|
||||
bool recursive = false;
|
||||
|
||||
VirtualRouter * vrouter;
|
||||
|
||||
set<int>::const_iterator it;
|
||||
set<int> vms;
|
||||
|
||||
if (paramList.size() > 11)
|
||||
@ -298,18 +286,16 @@ void VirtualRouterChmod::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
recursive = xmlrpc_c::value_boolean(paramList.getBoolean(11));
|
||||
}
|
||||
|
||||
vrouter = vrpool->get_ro(oid);
|
||||
|
||||
if ( vrouter == 0 )
|
||||
if (auto vrouter = vrpool->get_ro(oid))
|
||||
{
|
||||
vms = vrouter->get_vms();
|
||||
}
|
||||
else
|
||||
{
|
||||
att.resp_id = oid;
|
||||
failure_response(NO_EXISTS, att);
|
||||
}
|
||||
|
||||
vms = vrouter->get_vms();
|
||||
|
||||
vrouter->unlock();
|
||||
|
||||
ErrorCode ec = chmod(vrpool, oid,
|
||||
owner_u, owner_m, owner_a,
|
||||
group_u, group_m, group_a,
|
||||
@ -322,10 +308,8 @@ void VirtualRouterChmod::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
return;
|
||||
}
|
||||
|
||||
for (it = vms.begin(); it != vms.end(); it++)
|
||||
for (auto vm_id : vms)
|
||||
{
|
||||
int vm_id = *it;
|
||||
|
||||
ErrorCode ec_aux = chmod(pool, vm_id,
|
||||
owner_u, owner_m, owner_a,
|
||||
group_u, group_m, group_a,
|
||||
|
@ -25,7 +25,7 @@ using namespace std;
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
PoolObjectSQL * RequestManagerChown::get_and_quota(
|
||||
unique_ptr<PoolObjectSQL> RequestManagerChown::get_and_quota(
|
||||
int oid,
|
||||
int new_uid,
|
||||
int new_gid,
|
||||
@ -43,11 +43,9 @@ PoolObjectSQL * RequestManagerChown::get_and_quota(
|
||||
|
||||
std::string memory, cpu;
|
||||
|
||||
PoolObjectSQL * object;
|
||||
auto object = pool->get<PoolObjectSQL>(oid);
|
||||
|
||||
object = pool->get(oid);
|
||||
|
||||
if ( object == 0 )
|
||||
if ( object == nullptr )
|
||||
{
|
||||
att.resp_id = oid;
|
||||
failure_response(NO_EXISTS, att);
|
||||
@ -56,15 +54,13 @@ PoolObjectSQL * RequestManagerChown::get_and_quota(
|
||||
|
||||
if (auth_object == PoolObjectSQL::VM)
|
||||
{
|
||||
VirtualMachine * vm = static_cast<VirtualMachine*>(object);
|
||||
VirtualMachine * vm = static_cast<VirtualMachine*>(object.get());
|
||||
|
||||
vector<Template *> ds_quotas;
|
||||
vector<Template *>::iterator it;
|
||||
|
||||
if ( vm->get_state() == VirtualMachine::DONE )
|
||||
{
|
||||
vm->unlock();
|
||||
|
||||
att.resp_msg = "Could not change VM ownership, wrong state";
|
||||
failure_response(ACTION, att);
|
||||
return 0;
|
||||
@ -97,7 +93,7 @@ PoolObjectSQL * RequestManagerChown::get_and_quota(
|
||||
}
|
||||
else if (auth_object == PoolObjectSQL::IMAGE)
|
||||
{
|
||||
Image * img = static_cast<Image *>(object);
|
||||
Image * img = static_cast<Image *>(object.get());
|
||||
Template * tmpl = new Template;
|
||||
|
||||
tmpl->add("DATASTORE", img->get_ds_id());
|
||||
@ -107,7 +103,7 @@ PoolObjectSQL * RequestManagerChown::get_and_quota(
|
||||
}
|
||||
else if (auth_object == PoolObjectSQL::NET)
|
||||
{
|
||||
VirtualNetwork * vn = static_cast<VirtualNetwork *>(object);
|
||||
VirtualNetwork * vn = static_cast<VirtualNetwork *>(object.get());
|
||||
unsigned int total = vn->get_size();
|
||||
|
||||
ostringstream oss;
|
||||
@ -132,9 +128,7 @@ PoolObjectSQL * RequestManagerChown::get_and_quota(
|
||||
}
|
||||
else
|
||||
{
|
||||
object->unlock();
|
||||
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if ( new_uid == -1 )
|
||||
@ -155,7 +149,7 @@ PoolObjectSQL * RequestManagerChown::get_and_quota(
|
||||
old_gid = object->get_gid();
|
||||
}
|
||||
|
||||
object->unlock();
|
||||
object.reset();
|
||||
|
||||
RequestAttributes att_new(new_uid, new_gid, att);
|
||||
RequestAttributes att_old(old_uid, old_gid, att);
|
||||
@ -190,18 +184,18 @@ PoolObjectSQL * RequestManagerChown::get_and_quota(
|
||||
quota_rollback(it->second, it->first, att_old);
|
||||
}
|
||||
|
||||
object = pool->get(oid);
|
||||
object = pool->get<PoolObjectSQL>(oid);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Error or object deleted. Rollback chown quota operation. Add again usage
|
||||
// to old owner, decrement to new owner.
|
||||
// -------------------------------------------------------------------------
|
||||
if ( object == 0 || error )
|
||||
if ( object == nullptr || error )
|
||||
{
|
||||
for (it = quota_to_rback.begin(); it != quota_to_rback.end(); ++it)
|
||||
{
|
||||
if ( object == 0 )
|
||||
if ( object == nullptr )
|
||||
{
|
||||
quota_authorization(it->second, it->first,att_old,att.resp_msg);
|
||||
}
|
||||
@ -219,7 +213,7 @@ PoolObjectSQL * RequestManagerChown::get_and_quota(
|
||||
failure_response(AUTHORIZATION, att);
|
||||
}
|
||||
|
||||
object = 0;
|
||||
object = nullptr;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
@ -243,24 +237,21 @@ PoolObjectSQL * RequestManagerChown::get_and_quota(
|
||||
|
||||
int RequestManagerChown::check_name_unique(int oid, int noid, RequestAttributes& att)
|
||||
{
|
||||
PoolObjectSQL * object;
|
||||
string name;
|
||||
int obj_oid;
|
||||
ostringstream oss;
|
||||
|
||||
object = pool->get(oid);
|
||||
|
||||
if ( object == 0 )
|
||||
if ( auto object = pool->get_ro<PoolObjectSQL>(oid) )
|
||||
{
|
||||
name = object->get_name();
|
||||
}
|
||||
else
|
||||
{
|
||||
att.resp_id = oid;
|
||||
failure_response(NO_EXISTS, att);
|
||||
return -1;
|
||||
}
|
||||
|
||||
name = object->get_name();
|
||||
|
||||
object->unlock();
|
||||
|
||||
obj_oid = pool->exist(name, noid);
|
||||
|
||||
if ( obj_oid != -1 )
|
||||
@ -297,7 +288,7 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
PoolObjectAuth nuperms;
|
||||
PoolObjectAuth ngperms;
|
||||
|
||||
PoolObjectSQL * object;
|
||||
unique_ptr<PoolObjectSQL> object;
|
||||
|
||||
set<int> vms;
|
||||
|
||||
@ -374,20 +365,20 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
}
|
||||
else
|
||||
{
|
||||
object = pool->get(oid);
|
||||
object = pool->get<PoolObjectSQL>(oid);
|
||||
|
||||
if ( object == 0 )
|
||||
if ( object == nullptr )
|
||||
{
|
||||
att.resp_id = oid;
|
||||
failure_response(NO_EXISTS, att);
|
||||
}
|
||||
else if ( auth_object == PoolObjectSQL::VROUTER )
|
||||
{
|
||||
vms = static_cast<VirtualRouter *>(object)->get_vms();
|
||||
vms = static_cast<VirtualRouter *>(object.get())->get_vms();
|
||||
}
|
||||
}
|
||||
|
||||
if ( object == 0 )
|
||||
if ( object == nullptr )
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -402,9 +393,9 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
object->set_group(ngid, ngname);
|
||||
}
|
||||
|
||||
pool->update(object);
|
||||
pool->update(object.get());
|
||||
|
||||
object->unlock();
|
||||
object.reset();
|
||||
|
||||
if ( auth_object != PoolObjectSQL::VROUTER )
|
||||
{
|
||||
@ -420,13 +411,11 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
|
||||
PoolSQL * vm_pool = Nebula::instance().get_vmpool();
|
||||
|
||||
for (set<int>::const_iterator it = vms.begin(); it != vms.end(); it++)
|
||||
for (auto vm_id : vms)
|
||||
{
|
||||
int vm_id = *it;
|
||||
auto vm = get_and_quota(vm_id, noid, ngid, att, vm_pool, PoolObjectSQL::VM);
|
||||
|
||||
PoolObjectSQL * vm = get_and_quota(vm_id, noid, ngid, att, vm_pool, PoolObjectSQL::VM);
|
||||
|
||||
if ( vm == 0 )
|
||||
if ( vm == nullptr )
|
||||
{
|
||||
error_vm_quotas = true;
|
||||
|
||||
@ -443,9 +432,7 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
vm->set_group(ngid, ngname);
|
||||
}
|
||||
|
||||
vm_pool->update(vm);
|
||||
|
||||
vm->unlock();
|
||||
vm_pool->update(vm.get());
|
||||
}
|
||||
|
||||
if (!error_vm_quotas)
|
||||
@ -474,9 +461,6 @@ void UserChown::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
string uname;
|
||||
string auth_driver;
|
||||
|
||||
User * user;
|
||||
Group * group;
|
||||
|
||||
PoolObjectAuth uperms;
|
||||
PoolObjectAuth ngperms;
|
||||
|
||||
@ -490,7 +474,16 @@ void UserChown::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
return;
|
||||
}
|
||||
|
||||
if ((user = upool->get_ro(oid)) == 0 )
|
||||
if ( auto user = upool->get_ro(oid) )
|
||||
{
|
||||
user->get_permissions(uperms);
|
||||
|
||||
uname = user->get_name();
|
||||
|
||||
auth_driver = user->get_auth_driver();
|
||||
new_group = user->get_groups().count(ngid) != 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
att.resp_obj = PoolObjectSQL::USER;
|
||||
att.resp_id = oid;
|
||||
@ -499,15 +492,6 @@ void UserChown::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
return;
|
||||
}
|
||||
|
||||
user->get_permissions(uperms);
|
||||
|
||||
uname = user->get_name();
|
||||
|
||||
auth_driver = user->get_auth_driver();
|
||||
new_group = user->get_groups().count(ngid) != 1;
|
||||
|
||||
user->unlock();
|
||||
|
||||
if ( Nebula::instance().get_auth_conf_attribute(auth_driver,
|
||||
"DRIVER_MANAGED_GROUPS", driver_managed_groups) != 0 )
|
||||
{
|
||||
@ -561,20 +545,10 @@ void UserChown::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
|
||||
// ------------- Change users primary group ---------------------
|
||||
|
||||
user = upool->get(oid);
|
||||
|
||||
if ( user == 0 )
|
||||
if ( auto user = upool->get(oid) )
|
||||
{
|
||||
att.resp_obj = PoolObjectSQL::USER;
|
||||
att.resp_id = oid;
|
||||
failure_response(NO_EXISTS, att);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ((old_gid = user->get_gid()) == ngid)
|
||||
{
|
||||
user->unlock();
|
||||
success_response(oid, att);
|
||||
return;
|
||||
}
|
||||
@ -593,15 +567,26 @@ void UserChown::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
user->del_group(old_gid);
|
||||
}
|
||||
|
||||
upool->update(user);
|
||||
upool->update(user.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
att.resp_obj = PoolObjectSQL::USER;
|
||||
att.resp_id = oid;
|
||||
failure_response(NO_EXISTS, att);
|
||||
|
||||
user->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
// ------------- Updates new group with this new user ---------------------
|
||||
|
||||
group = gpool->get(ngid);
|
||||
if ( auto group = gpool->get(ngid) )
|
||||
{
|
||||
group->add_user(oid);
|
||||
|
||||
if( group == 0 )
|
||||
gpool->update(group.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
//TODO Rollback
|
||||
att.resp_obj = PoolObjectSQL::GROUP;
|
||||
@ -611,25 +596,15 @@ void UserChown::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
return;
|
||||
}
|
||||
|
||||
group->add_user(oid);
|
||||
|
||||
gpool->update(group);
|
||||
|
||||
group->unlock();
|
||||
|
||||
// ------------- Updates old group removing the user ---------------------
|
||||
|
||||
if (remove_old_group)
|
||||
{
|
||||
group = gpool->get(old_gid);
|
||||
|
||||
if( group != 0 )
|
||||
if ( auto group = gpool->get(old_gid) )
|
||||
{
|
||||
group->del_user(oid);
|
||||
|
||||
gpool->update(group);
|
||||
|
||||
group->unlock();
|
||||
gpool->update(group.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,20 +63,20 @@ Request::ErrorCode RequestManagerClone::clone(int source_id, const string &name,
|
||||
int rc;
|
||||
PoolObjectAuth perms;
|
||||
|
||||
PoolObjectSQL * source_obj = pool->get(source_id);
|
||||
Template * tmpl;
|
||||
|
||||
if ( source_obj == 0 )
|
||||
if ( auto source_obj = pool->get_ro<PoolObjectSQL>(source_id) )
|
||||
{
|
||||
tmpl = clone_template(source_obj.get());
|
||||
|
||||
source_obj->get_permissions(perms);
|
||||
}
|
||||
else
|
||||
{
|
||||
att.resp_id = source_id;
|
||||
return NO_EXISTS;
|
||||
}
|
||||
|
||||
Template * tmpl = clone_template(source_obj);
|
||||
|
||||
source_obj->get_permissions(perms);
|
||||
|
||||
source_obj->unlock();
|
||||
|
||||
ErrorCode ec = merge(tmpl, s_uattr, att);
|
||||
|
||||
if (ec != SUCCESS)
|
||||
@ -157,33 +157,30 @@ Request::ErrorCode VMTemplateClone::clone(int source_id, const string &name,
|
||||
vector<VectorAttribute *> vdisks;
|
||||
|
||||
VirtualMachineDisks disks(false);
|
||||
VirtualMachineDisks::disk_iterator disk;
|
||||
|
||||
RequestAttributes del_att(att);
|
||||
RequestAttributes img_att(att);
|
||||
img_att.resp_obj = PoolObjectSQL::IMAGE;
|
||||
|
||||
VMTemplate * vmtmpl = tpool->get_ro(new_id);
|
||||
|
||||
if (vmtmpl == 0)
|
||||
if ( auto vmtmpl = tpool->get_ro(new_id) )
|
||||
{
|
||||
vmtmpl->clone_disks(vdisks);
|
||||
}
|
||||
else
|
||||
{
|
||||
att.resp_msg = "VM template was removed during clone operation";
|
||||
|
||||
return ACTION;
|
||||
}
|
||||
|
||||
vmtmpl->clone_disks(vdisks);
|
||||
|
||||
vmtmpl->unlock();
|
||||
|
||||
disks.init(vdisks, false);
|
||||
|
||||
for ( disk = disks.begin(); disk != disks.end() ; ++disk )
|
||||
for ( auto disk : disks )
|
||||
{
|
||||
int img_id;
|
||||
int new_img_id;
|
||||
|
||||
if ( (*disk)->get_image_id(img_id, att.uid) == 0)
|
||||
if ( disk->get_image_id(img_id, att.uid) == 0)
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
@ -203,10 +200,10 @@ Request::ErrorCode VMTemplateClone::clone(int source_id, const string &name,
|
||||
|
||||
for (auto attr : REMOVE_DISK_ATTRS)
|
||||
{
|
||||
(*disk)->remove(attr);
|
||||
disk->remove(attr);
|
||||
}
|
||||
|
||||
(*disk)->replace("IMAGE_ID", new_img_id);
|
||||
disk->replace("IMAGE_ID", new_img_id);
|
||||
|
||||
new_ids.push_back(new_img_id);
|
||||
}
|
||||
@ -214,20 +211,19 @@ Request::ErrorCode VMTemplateClone::clone(int source_id, const string &name,
|
||||
ndisk++;
|
||||
}
|
||||
|
||||
vmtmpl = tpool->get(new_id);
|
||||
if ( auto vmtmpl = tpool->get(new_id) )
|
||||
{
|
||||
vmtmpl->replace_disks(vdisks);
|
||||
|
||||
if (vmtmpl == 0)
|
||||
tpool->update(vmtmpl.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
att.resp_msg = "VM template was removed during clone operation.";
|
||||
|
||||
goto error_template;
|
||||
}
|
||||
|
||||
vmtmpl->replace_disks(vdisks);
|
||||
|
||||
tpool->update(vmtmpl);
|
||||
|
||||
vmtmpl->unlock();
|
||||
|
||||
return SUCCESS;
|
||||
|
||||
@ -240,18 +236,17 @@ error_images:
|
||||
goto error_template;
|
||||
|
||||
error_template:
|
||||
for (vector<int>::iterator i = new_ids.begin(); i != new_ids.end(); i++)
|
||||
for (auto id : new_ids)
|
||||
{
|
||||
if (img_delete.request_execute(*i, img_att) != SUCCESS)
|
||||
if (img_delete.request_execute(id, img_att) != SUCCESS)
|
||||
{
|
||||
NebulaLog::log("ReM", Log::ERROR, failure_message(ec, img_att));
|
||||
}
|
||||
}
|
||||
|
||||
for (vector<VectorAttribute *>::iterator it = vdisks.begin();
|
||||
it != vdisks.end() ; it++)
|
||||
for (auto disk : vdisks)
|
||||
{
|
||||
delete *it;
|
||||
delete disk;
|
||||
}
|
||||
|
||||
return ACTION;
|
||||
|
@ -35,10 +35,9 @@ void RequestManagerCluster::action_generic(
|
||||
string cluster_name;
|
||||
string obj_name;
|
||||
|
||||
Cluster * cluster = nullptr;
|
||||
Clusterable * cluster_obj = nullptr;
|
||||
|
||||
PoolObjectSQL * object = nullptr;
|
||||
unique_ptr<PoolObjectSQL> object;
|
||||
|
||||
PoolObjectAuth c_perms;
|
||||
PoolObjectAuth obj_perms;
|
||||
@ -72,7 +71,7 @@ void RequestManagerCluster::action_generic(
|
||||
}
|
||||
|
||||
// ------------- Set new cluster id in object ---------------------
|
||||
get(object_id, &object, &cluster_obj);
|
||||
get(object_id, object, &cluster_obj);
|
||||
|
||||
if ( object == nullptr )
|
||||
{
|
||||
@ -93,17 +92,16 @@ void RequestManagerCluster::action_generic(
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
object->unlock();
|
||||
success_response(cluster_id, att);
|
||||
return;
|
||||
}
|
||||
|
||||
pool->update(object);
|
||||
pool->update(object.get());
|
||||
|
||||
object->unlock();
|
||||
object.reset();
|
||||
|
||||
// ------------- Add/del object to new cluster ---------------------
|
||||
cluster = clpool->get(cluster_id);
|
||||
auto cluster = clpool->get(cluster_id);
|
||||
|
||||
if ( cluster == nullptr )
|
||||
{
|
||||
@ -112,7 +110,7 @@ void RequestManagerCluster::action_generic(
|
||||
failure_response(NO_EXISTS, att);
|
||||
|
||||
// Rollback
|
||||
get(object_id, &object, &cluster_obj);
|
||||
get(object_id, object, &cluster_obj);
|
||||
|
||||
if ( object != nullptr )
|
||||
{
|
||||
@ -125,9 +123,7 @@ void RequestManagerCluster::action_generic(
|
||||
cluster_obj->add_cluster(cluster_id);
|
||||
}
|
||||
|
||||
pool->update(object);
|
||||
|
||||
object->unlock();
|
||||
pool->update(object.get());
|
||||
}
|
||||
|
||||
return;
|
||||
@ -135,21 +131,21 @@ void RequestManagerCluster::action_generic(
|
||||
|
||||
if (add)
|
||||
{
|
||||
rc = add_object(cluster, object_id, att.resp_msg);
|
||||
rc = add_object(cluster.get(), object_id, att.resp_msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = del_object(cluster, object_id, att.resp_msg);
|
||||
rc = del_object(cluster.get(), object_id, att.resp_msg);
|
||||
}
|
||||
|
||||
if ( rc < 0 )
|
||||
{
|
||||
cluster->unlock();
|
||||
cluster.reset();
|
||||
|
||||
failure_response(ACTION, att);
|
||||
|
||||
// Rollback
|
||||
get(object_id, &object, &cluster_obj);
|
||||
get(object_id, object, &cluster_obj);
|
||||
|
||||
if ( object != nullptr )
|
||||
{
|
||||
@ -162,17 +158,13 @@ void RequestManagerCluster::action_generic(
|
||||
cluster_obj->add_cluster(cluster_id);
|
||||
}
|
||||
|
||||
pool->update(object);
|
||||
|
||||
object->unlock();
|
||||
pool->update(object.get());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
clpool->update(cluster);
|
||||
|
||||
cluster->unlock();
|
||||
clpool->update(cluster.get());
|
||||
|
||||
success_response(cluster_id, att);
|
||||
|
||||
@ -193,9 +185,6 @@ void RequestManagerClusterHost::add_generic(
|
||||
string obj_name;
|
||||
string err_msg;
|
||||
|
||||
Cluster * cluster = nullptr;
|
||||
Host * host = nullptr;
|
||||
|
||||
PoolObjectAuth c_perms;
|
||||
PoolObjectAuth obj_perms;
|
||||
|
||||
@ -230,9 +219,14 @@ void RequestManagerClusterHost::add_generic(
|
||||
return;
|
||||
}
|
||||
|
||||
cluster = clpool->get_ro(cluster_id);
|
||||
string ccpu;
|
||||
string cmem;
|
||||
|
||||
if ( cluster == nullptr )
|
||||
if (auto cluster = clpool->get_ro(cluster_id))
|
||||
{
|
||||
cluster->get_reserved_capacity(ccpu, cmem);
|
||||
}
|
||||
else
|
||||
{
|
||||
att.resp_obj = PoolObjectSQL::CLUSTER;
|
||||
att.resp_id = cluster_id;
|
||||
@ -240,17 +234,24 @@ void RequestManagerClusterHost::add_generic(
|
||||
return;
|
||||
}
|
||||
|
||||
string ccpu;
|
||||
string cmem;
|
||||
|
||||
cluster->get_reserved_capacity(ccpu, cmem);
|
||||
|
||||
cluster->unlock();
|
||||
|
||||
// ------------- Set new cluster id in object ---------------------
|
||||
host = hpool->get(host_id);
|
||||
if ( auto host = hpool->get(host_id) )
|
||||
{
|
||||
old_cluster_id = host->get_cluster_id();
|
||||
old_cluster_name = host->get_cluster_name();
|
||||
|
||||
if ( host == nullptr )
|
||||
if ( old_cluster_id == cluster_id )
|
||||
{
|
||||
success_response(cluster_id, att);
|
||||
return;
|
||||
}
|
||||
|
||||
host->set_cluster(cluster_id, cluster_name);
|
||||
host->update_reserved_capacity(ccpu, cmem);
|
||||
|
||||
hpool->update(host.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
att.resp_obj = PoolObjectSQL::HOST;
|
||||
att.resp_id = host_id;
|
||||
@ -259,31 +260,11 @@ void RequestManagerClusterHost::add_generic(
|
||||
return;
|
||||
}
|
||||
|
||||
old_cluster_id = host->get_cluster_id();
|
||||
old_cluster_name = host->get_cluster_name();
|
||||
|
||||
if ( old_cluster_id == cluster_id )
|
||||
{
|
||||
host->unlock();
|
||||
|
||||
success_response(cluster_id, att);
|
||||
return;
|
||||
}
|
||||
|
||||
host->set_cluster(cluster_id, cluster_name);
|
||||
host->update_reserved_capacity(ccpu, cmem);
|
||||
|
||||
hpool->update(host);
|
||||
|
||||
host->unlock();
|
||||
|
||||
// ------------- Add object to new cluster ---------------------
|
||||
cluster = clpool->get(cluster_id);
|
||||
auto cluster = clpool->get(cluster_id);
|
||||
|
||||
if ( clpool->add_to_cluster(PoolObjectSQL::HOST, cluster, host_id, att.resp_msg) < 0 )
|
||||
if ( clpool->add_to_cluster(PoolObjectSQL::HOST, cluster.get(), host_id, att.resp_msg) < 0 )
|
||||
{
|
||||
cluster->unlock();
|
||||
|
||||
failure_response(INTERNAL, att);
|
||||
|
||||
// Rollback
|
||||
@ -292,7 +273,6 @@ void RequestManagerClusterHost::add_generic(
|
||||
if ( cluster != nullptr )
|
||||
{
|
||||
cluster->get_reserved_capacity(ccpu, cmem);
|
||||
cluster->unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -303,23 +283,17 @@ void RequestManagerClusterHost::add_generic(
|
||||
cmem = "0";
|
||||
}
|
||||
|
||||
host = hpool->get(host_id);
|
||||
|
||||
if ( host != nullptr )
|
||||
if ( auto host = hpool->get(host_id) )
|
||||
{
|
||||
host->set_cluster(old_cluster_id, old_cluster_name);
|
||||
host->update_reserved_capacity(ccpu, cmem);
|
||||
|
||||
hpool->update(host);
|
||||
|
||||
host->unlock();
|
||||
hpool->update(host.get());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
cluster->unlock();
|
||||
|
||||
// ------------- Remove host from old cluster ---------------------
|
||||
cluster = clpool->get(old_cluster_id);
|
||||
|
||||
@ -332,16 +306,13 @@ void RequestManagerClusterHost::add_generic(
|
||||
return;
|
||||
}
|
||||
|
||||
if ( clpool->del_from_cluster(PoolObjectSQL::HOST, cluster, host_id, att.resp_msg) < 0 )
|
||||
if ( clpool->del_from_cluster(PoolObjectSQL::HOST, cluster.get(), host_id, att.resp_msg) < 0 )
|
||||
{
|
||||
cluster->unlock();
|
||||
|
||||
failure_response(INTERNAL, att);
|
||||
return;
|
||||
}
|
||||
|
||||
cluster->unlock();
|
||||
|
||||
success_response(cluster_id, att);
|
||||
|
||||
return;
|
||||
|
@ -28,16 +28,14 @@ void DatastoreEnable::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
bool enable_flag = xmlrpc_c::value_boolean(paramList.getBoolean(2));
|
||||
int rc;
|
||||
|
||||
Datastore * ds;
|
||||
|
||||
if ( basic_authorization(id, att) == false )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ds = static_cast<Datastore *>(pool->get(id));
|
||||
auto ds = pool->get<Datastore>(id);
|
||||
|
||||
if ( ds == 0 )
|
||||
if ( ds == nullptr )
|
||||
{
|
||||
att.resp_id = id;
|
||||
failure_response(NO_EXISTS, att);
|
||||
@ -50,13 +48,10 @@ void DatastoreEnable::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
{
|
||||
failure_response(INTERNAL, att);
|
||||
|
||||
ds->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
pool->update(ds);
|
||||
|
||||
ds->unlock();
|
||||
pool->update(ds.get());
|
||||
|
||||
success_response(id, att);
|
||||
}
|
||||
|
@ -52,18 +52,16 @@ static Request::ErrorCode delete_authorization(PoolSQL* pool, int oid,
|
||||
{
|
||||
PoolObjectAuth perms;
|
||||
|
||||
PoolObjectSQL * object = pool->get(oid);
|
||||
|
||||
if ( object == 0 )
|
||||
if (auto object = pool->get<PoolObjectSQL>(oid))
|
||||
{
|
||||
object->get_permissions(perms);
|
||||
}
|
||||
else
|
||||
{
|
||||
att.resp_id = oid;
|
||||
return Request::NO_EXISTS;
|
||||
}
|
||||
|
||||
object->get_permissions(perms);
|
||||
|
||||
object->unlock();
|
||||
|
||||
AuthRequest ar(att.uid, att.group_ids);
|
||||
|
||||
ar.add_auth(att.auth_op, perms); // <MANAGE|ADMIN> OBJECT
|
||||
@ -121,13 +119,9 @@ void RequestManagerDelete::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
}
|
||||
|
||||
// Save body before deleting it for hooks
|
||||
PoolObjectSQL * obj = pool->get(oid);
|
||||
|
||||
if (obj != nullptr)
|
||||
if (auto obj = pool->get_ro<PoolObjectSQL>(oid))
|
||||
{
|
||||
obj->to_xml(att.extra_xml);
|
||||
|
||||
obj->unlock();
|
||||
}
|
||||
|
||||
ErrorCode ec = delete_object(oid, recursive, att);
|
||||
@ -158,15 +152,15 @@ Request::ErrorCode RequestManagerDelete::delete_object(int oid, bool recursive,
|
||||
return ec;
|
||||
}
|
||||
|
||||
PoolObjectSQL * object = pool->get(oid);
|
||||
auto object = pool->get<PoolObjectSQL>(oid);
|
||||
|
||||
if ( object == 0 )
|
||||
if ( object == nullptr )
|
||||
{
|
||||
att.resp_id = oid;
|
||||
return NO_EXISTS;
|
||||
}
|
||||
|
||||
int rc = drop(object, recursive, att);
|
||||
int rc = drop(std::move(object), recursive, att);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
@ -184,39 +178,32 @@ Request::ErrorCode RequestManagerDelete::delete_object(int oid, bool recursive,
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
int RequestManagerDelete::drop(PoolObjectSQL * object, bool recursive,
|
||||
int RequestManagerDelete::drop(std::unique_ptr<PoolObjectSQL> object, bool recursive,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
set<int> cluster_ids = get_cluster_ids(object);
|
||||
set<int> cluster_ids = get_cluster_ids(object.get());
|
||||
|
||||
int oid = object->get_oid();
|
||||
|
||||
int rc = pool->drop(object, att.resp_msg);
|
||||
int rc = pool->drop(object.get(), att.resp_msg);
|
||||
|
||||
object->unlock();
|
||||
object.reset();
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
return rc;
|
||||
}
|
||||
|
||||
set<int>::iterator it;
|
||||
|
||||
for(it = cluster_ids.begin(); it != cluster_ids.end(); it++)
|
||||
for (auto cid : cluster_ids)
|
||||
{
|
||||
Cluster * cluster = clpool->get(*it);
|
||||
|
||||
if( cluster != 0 )
|
||||
if ( auto cluster = clpool->get(cid) )
|
||||
{
|
||||
rc = del_from_cluster(cluster, oid, att.resp_msg);
|
||||
rc = del_from_cluster(cluster.get(), oid, att.resp_msg);
|
||||
|
||||
if ( rc < 0 )
|
||||
{
|
||||
cluster->unlock();
|
||||
return rc;
|
||||
}
|
||||
|
||||
cluster->unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@ -239,7 +226,7 @@ TemplateDelete::TemplateDelete()
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
int TemplateDelete::drop(PoolObjectSQL * object, bool recursive,
|
||||
int TemplateDelete::drop(std::unique_ptr<PoolObjectSQL> object, bool recursive,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
vector<VectorAttribute *> vdisks;
|
||||
@ -249,12 +236,12 @@ int TemplateDelete::drop(PoolObjectSQL * object, bool recursive,
|
||||
|
||||
if (recursive)
|
||||
{
|
||||
static_cast<VMTemplate *>(object)->clone_disks(vdisks);
|
||||
static_cast<VMTemplate *>(object.get())->clone_disks(vdisks);
|
||||
|
||||
disks.init(vdisks, false);
|
||||
}
|
||||
|
||||
int rc = RequestManagerDelete::drop(object, false, att);
|
||||
int rc = RequestManagerDelete::drop(std::move(object), false, att);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
@ -272,14 +259,13 @@ int TemplateDelete::drop(PoolObjectSQL * object, bool recursive,
|
||||
|
||||
disks.get_image_ids(img_ids, att.uid);
|
||||
|
||||
for (set<int>::iterator it = img_ids.begin(); it != img_ids.end(); it++)
|
||||
for (auto iid : img_ids)
|
||||
{
|
||||
|
||||
if ( img_delete.request_execute(*it, att) != SUCCESS )
|
||||
if ( img_delete.request_execute(iid, att) != SUCCESS )
|
||||
{
|
||||
NebulaLog::log("ReM", Log::ERROR, att.resp_msg);
|
||||
|
||||
error_ids.insert(*it);
|
||||
error_ids.insert(iid);
|
||||
}
|
||||
}
|
||||
|
||||
@ -323,17 +309,15 @@ VirtualNetworkDelete::VirtualNetworkDelete()
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualNetworkDelete::drop(PoolObjectSQL * object, bool r, RequestAttributes& att)
|
||||
int VirtualNetworkDelete::drop(std::unique_ptr<PoolObjectSQL> object, bool r, RequestAttributes& att)
|
||||
{
|
||||
int oid = object->get_oid();
|
||||
VirtualNetwork * vnet = static_cast<VirtualNetwork *>(object);
|
||||
VirtualNetwork * vnet = static_cast<VirtualNetwork *>(object.get());
|
||||
|
||||
if ( vnet->get_used() > 0 )
|
||||
{
|
||||
att.resp_msg = "Can not remove a virtual network with leases in use";
|
||||
|
||||
vnet->unlock();
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -352,28 +336,26 @@ int VirtualNetworkDelete::drop(PoolObjectSQL * object, bool r, RequestAttributes
|
||||
if (rc != 0)
|
||||
{
|
||||
vnpool->update(vnet);
|
||||
vnet->unlock();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = RequestManagerDelete::drop(object, false, att);
|
||||
rc = RequestManagerDelete::drop(std::move(object), false, att);
|
||||
|
||||
if (pvid != -1)
|
||||
{
|
||||
vnet = (static_cast<VirtualNetworkPool *>(pool))->get(pvid);
|
||||
int freed = 0;
|
||||
if (auto vnet = pool->get<VirtualNetwork>(pvid))
|
||||
{
|
||||
freed = vnet->free_addr_by_owner(PoolObjectSQL::NET, oid);
|
||||
|
||||
if (vnet == 0)
|
||||
pool->update(vnet.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
return rc;
|
||||
}
|
||||
|
||||
int freed = vnet->free_addr_by_owner(PoolObjectSQL::NET, oid);
|
||||
|
||||
pool->update(vnet);
|
||||
|
||||
vnet->unlock();
|
||||
|
||||
if (freed > 0)
|
||||
{
|
||||
ostringstream oss;
|
||||
@ -407,19 +389,13 @@ int VirtualNetworkDelete::drop(PoolObjectSQL * object, bool r, RequestAttributes
|
||||
|
||||
for (int vdcId : vdcs)
|
||||
{
|
||||
Vdc * vdc = vdcpool->get(vdcId);
|
||||
|
||||
if ( vdc == 0 )
|
||||
if ( auto vdc = vdcpool->get(vdcId) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( vdc->del_vnet(zone_id, oid, error) == 0 )
|
||||
{
|
||||
vdcpool->update(vdc);
|
||||
vdcpool->update(vdc.get());
|
||||
}
|
||||
}
|
||||
|
||||
vdc->unlock();
|
||||
}
|
||||
|
||||
return rc;
|
||||
@ -444,9 +420,9 @@ void ImageDelete::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
{
|
||||
int oid = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
|
||||
Image* img = static_cast<ImagePool *>(pool)->get_ro(oid);
|
||||
auto img = pool->get_ro<Image>(oid);
|
||||
|
||||
if (img == 0)
|
||||
if (img == nullptr)
|
||||
{
|
||||
att.resp_id = oid;
|
||||
failure_response(NO_EXISTS, att);
|
||||
@ -462,8 +438,6 @@ void ImageDelete::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
img->to_xml(att.extra_xml);
|
||||
|
||||
|
||||
img->unlock();
|
||||
|
||||
ErrorCode ec = delete_object(oid, false, att);
|
||||
|
||||
if ( ec == SUCCESS )
|
||||
@ -479,14 +453,14 @@ void ImageDelete::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
int ImageDelete::drop(PoolObjectSQL * object, bool r, RequestAttributes& att)
|
||||
int ImageDelete::drop(std::unique_ptr<PoolObjectSQL> object, bool r, RequestAttributes& att)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
ImageManager * imagem = nd.get_imagem();
|
||||
|
||||
int oid = object->get_oid();
|
||||
|
||||
object->unlock();
|
||||
object.reset();
|
||||
|
||||
return imagem->delete_image(oid, att.resp_msg);
|
||||
}
|
||||
@ -506,21 +480,19 @@ HostDelete::HostDelete()
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
int HostDelete::drop(PoolObjectSQL * object, bool r, RequestAttributes& att)
|
||||
int HostDelete::drop(std::unique_ptr<PoolObjectSQL> object, bool r, RequestAttributes& att)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
InformationManager * im = nd.get_im();
|
||||
|
||||
std::string error;
|
||||
|
||||
Host* host = static_cast<Host *>(object);
|
||||
Host* host = static_cast<Host *>(object.get());
|
||||
|
||||
if ( host->get_share_running_vms() > 0 )
|
||||
{
|
||||
att.resp_msg = "Can not remove a host with running VMs";
|
||||
|
||||
host->unlock();
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -528,7 +500,7 @@ int HostDelete::drop(PoolObjectSQL * object, bool r, RequestAttributes& att)
|
||||
string name = host->get_name();
|
||||
int oid = host->get_oid();
|
||||
|
||||
int rc = RequestManagerDelete::drop(object, false, att);
|
||||
int rc = RequestManagerDelete::drop(std::move(object), false, att);
|
||||
|
||||
im->stop_monitor(oid, name, im_mad);
|
||||
im->delete_host(oid);
|
||||
@ -548,19 +520,13 @@ int HostDelete::drop(PoolObjectSQL * object, bool r, RequestAttributes& att)
|
||||
|
||||
for (int vdcId : vdcs)
|
||||
{
|
||||
Vdc * vdc = vdcpool->get(vdcId);
|
||||
|
||||
if ( vdc == 0 )
|
||||
if ( auto vdc = vdcpool->get(vdcId) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( vdc->del_host(zone_id, oid, error) == 0 )
|
||||
{
|
||||
vdcpool->update(vdc);
|
||||
vdcpool->update(vdc.get());
|
||||
}
|
||||
}
|
||||
|
||||
vdc->unlock();
|
||||
}
|
||||
|
||||
return rc;
|
||||
@ -582,10 +548,10 @@ GroupDelete::GroupDelete()
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
int GroupDelete::drop(PoolObjectSQL * object, bool r, RequestAttributes& att)
|
||||
int GroupDelete::drop(std::unique_ptr<PoolObjectSQL> object, bool r, RequestAttributes& att)
|
||||
{
|
||||
int oid = object->get_oid();
|
||||
int rc = RequestManagerDelete::drop(object, false, att);
|
||||
int rc = RequestManagerDelete::drop(std::move(object), false, att);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
@ -604,19 +570,13 @@ int GroupDelete::drop(PoolObjectSQL * object, bool r, RequestAttributes& att)
|
||||
|
||||
for (int vdcId : vdcs)
|
||||
{
|
||||
Vdc * vdc = vdcpool->get(vdcId);
|
||||
|
||||
if ( vdc == 0 )
|
||||
if ( auto vdc = vdcpool->get(vdcId) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( vdc->del_group(oid, error) == 0 )
|
||||
{
|
||||
vdcpool->update(vdc);
|
||||
vdcpool->update(vdc.get());
|
||||
}
|
||||
}
|
||||
|
||||
vdc->unlock();
|
||||
}
|
||||
|
||||
return rc;
|
||||
@ -639,12 +599,11 @@ UserDelete::UserDelete()
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
int UserDelete::drop(PoolObjectSQL * object, bool r, RequestAttributes& att)
|
||||
int UserDelete::drop(std::unique_ptr<PoolObjectSQL> object, bool r, RequestAttributes& att)
|
||||
{
|
||||
User * user = static_cast<User *>(object);
|
||||
User * user = static_cast<User *>(object.get());
|
||||
|
||||
set<int> group_set = user->get_groups();
|
||||
set<int>::iterator it;
|
||||
|
||||
int oid = user->get_oid();
|
||||
|
||||
@ -652,31 +611,22 @@ int UserDelete::drop(PoolObjectSQL * object, bool r, RequestAttributes& att)
|
||||
{
|
||||
att.resp_msg = "oneadmin cannot be deleted.";
|
||||
|
||||
object->unlock();
|
||||
return -1;
|
||||
}
|
||||
|
||||
int rc = pool->drop(object, att.resp_msg);
|
||||
int rc = pool->drop(object.get(), att.resp_msg);
|
||||
|
||||
object->unlock();
|
||||
object.reset();
|
||||
|
||||
if ( rc == 0 )
|
||||
{
|
||||
Group * group;
|
||||
|
||||
for ( it = group_set.begin(); it != group_set.end(); it++ )
|
||||
for (auto gid : group_set)
|
||||
{
|
||||
group = gpool->get(*it);
|
||||
|
||||
if( group == 0 )
|
||||
if ( auto group = gpool->get(gid) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
group->del_user(oid);
|
||||
gpool->update(group);
|
||||
|
||||
group->unlock();
|
||||
gpool->update(group.get());
|
||||
}
|
||||
}
|
||||
|
||||
aclm->del_uid_rules(oid);
|
||||
@ -700,11 +650,11 @@ DatastoreDelete::DatastoreDelete()
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
int DatastoreDelete::drop(PoolObjectSQL * object, bool r, RequestAttributes& att)
|
||||
int DatastoreDelete::drop(std::unique_ptr<PoolObjectSQL> object, bool r, RequestAttributes& att)
|
||||
{
|
||||
int oid = object->get_oid();
|
||||
|
||||
int rc = RequestManagerDelete::drop(object, r, att);
|
||||
int rc = RequestManagerDelete::drop(std::move(object), r, att);
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
@ -724,19 +674,13 @@ int DatastoreDelete::drop(PoolObjectSQL * object, bool r, RequestAttributes& att
|
||||
|
||||
for (int vdcId : vdcs)
|
||||
{
|
||||
Vdc * vdc = vdcpool->get(vdcId);
|
||||
|
||||
if ( vdc == 0 )
|
||||
if ( auto vdc = vdcpool->get(vdcId) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( vdc->del_datastore(zone_id, oid, error) == 0 )
|
||||
{
|
||||
vdcpool->update(vdc);
|
||||
vdcpool->update(vdc.get());
|
||||
}
|
||||
}
|
||||
|
||||
vdc->unlock();
|
||||
}
|
||||
|
||||
return rc;
|
||||
@ -758,10 +702,10 @@ ClusterDelete::ClusterDelete()
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
int ClusterDelete::drop(PoolObjectSQL * object, bool r, RequestAttributes& att)
|
||||
int ClusterDelete::drop(std::unique_ptr<PoolObjectSQL> object, bool r, RequestAttributes& att)
|
||||
{
|
||||
int oid = object->get_oid();
|
||||
int rc = RequestManagerDelete::drop(object, false, att);
|
||||
int rc = RequestManagerDelete::drop(std::move(object), false, att);
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
@ -783,19 +727,13 @@ int ClusterDelete::drop(PoolObjectSQL * object, bool r, RequestAttributes& att)
|
||||
|
||||
for (int vdcId : vdcs)
|
||||
{
|
||||
Vdc * vdc = vdcpool->get(vdcId);
|
||||
|
||||
if ( vdc == 0 )
|
||||
if ( auto vdc = vdcpool->get(vdcId) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( vdc->del_cluster(zone_id, oid, error) == 0 )
|
||||
{
|
||||
vdcpool->update(vdc);
|
||||
vdcpool->update(vdc.get());
|
||||
}
|
||||
}
|
||||
|
||||
vdc->unlock();
|
||||
}
|
||||
|
||||
return rc;
|
||||
@ -828,10 +766,10 @@ ZoneDelete::ZoneDelete()
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
int ZoneDelete::drop(PoolObjectSQL * object, bool r, RequestAttributes& att)
|
||||
int ZoneDelete::drop(std::unique_ptr<PoolObjectSQL> object, bool r, RequestAttributes& att)
|
||||
{
|
||||
int oid= object->get_oid();
|
||||
int rc = RequestManagerDelete::drop(object, false, att);
|
||||
int rc = RequestManagerDelete::drop(std::move(object), false, att);
|
||||
|
||||
if ( rc == 0 )
|
||||
{
|
||||
@ -858,29 +796,25 @@ SecurityGroupDelete::SecurityGroupDelete():
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
int SecurityGroupDelete::drop(PoolObjectSQL * object, bool r, RequestAttributes& att)
|
||||
int SecurityGroupDelete::drop(std::unique_ptr<PoolObjectSQL> object, bool r, RequestAttributes& att)
|
||||
{
|
||||
if (object->get_oid() == 0)
|
||||
{
|
||||
att.resp_msg = "The default security group (ID 0) cannot be deleted.";
|
||||
|
||||
object->unlock();
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
SecurityGroup * sgroup = static_cast<SecurityGroup *>(object);
|
||||
SecurityGroup * sgroup = static_cast<SecurityGroup *>(object.get());
|
||||
|
||||
if ( sgroup->get_vms() > 0 )
|
||||
{
|
||||
att.resp_msg = "The security group has VMs using it";
|
||||
|
||||
sgroup->unlock();
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return RequestManagerDelete::drop(object, false, att);
|
||||
return RequestManagerDelete::drop(std::move(object), false, att);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -910,13 +844,13 @@ VirtualRouterDelete::VirtualRouterDelete()
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualRouterDelete::drop(PoolObjectSQL * object, bool r, RequestAttributes& att)
|
||||
int VirtualRouterDelete::drop(std::unique_ptr<PoolObjectSQL> object, bool r, RequestAttributes& att)
|
||||
{
|
||||
VirtualRouter * vr = static_cast<VirtualRouter *>(object);
|
||||
VirtualRouter * vr = static_cast<VirtualRouter *>(object.get());
|
||||
|
||||
set<int> vms = vr->get_vms();
|
||||
|
||||
int rc = RequestManagerDelete::drop(object, false, att);
|
||||
int rc = RequestManagerDelete::drop(std::move(object), false, att);
|
||||
|
||||
if ( rc == 0 && !vms.empty())
|
||||
{
|
||||
@ -941,14 +875,20 @@ MarketPlaceDelete::MarketPlaceDelete()
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
int MarketPlaceDelete::drop(PoolObjectSQL * object, bool r, RequestAttributes& att)
|
||||
int MarketPlaceDelete::drop(std::unique_ptr<PoolObjectSQL> object, bool r, RequestAttributes& att)
|
||||
{
|
||||
MarketPlace * mp = static_cast<MarketPlace *>(object);
|
||||
std::set<int> apps = mp->get_marketapp_ids();
|
||||
bool can_del = mp->is_public() || apps.empty();
|
||||
int mp_id = mp->get_oid();
|
||||
std::set<int> apps;
|
||||
int mp_id;
|
||||
bool old_monitor;
|
||||
|
||||
if( !can_del )
|
||||
{
|
||||
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();
|
||||
|
||||
if (!can_del)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
|
||||
@ -956,53 +896,47 @@ int MarketPlaceDelete::drop(PoolObjectSQL * object, bool r, RequestAttributes& a
|
||||
<< mp->get_oid() << " is not empty.";
|
||||
att.resp_msg = oss.str();
|
||||
|
||||
mp->unlock();
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool old_monitor = mp->disable_monitor();
|
||||
|
||||
mp->unlock();
|
||||
old_monitor = mp->disable_monitor();
|
||||
}
|
||||
|
||||
int rc = 0;
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
|
||||
MarketPlaceApp * app;
|
||||
MarketPlaceAppPool * apppool = nd.get_apppool();
|
||||
|
||||
string app_error;
|
||||
|
||||
for ( set<int>::iterator i = apps.begin(); i != apps.end(); ++i )
|
||||
for (auto app_id : apps)
|
||||
{
|
||||
app = apppool->get(*i);
|
||||
auto app = apppool->get(app_id);
|
||||
|
||||
if ( app == 0 )
|
||||
if ( app == nullptr )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( apppool->drop(app, app_error) != 0 )
|
||||
if ( apppool->drop(app.get(), app_error) != 0 )
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
oss << "Cannot remove " << object_name(PoolObjectSQL::MARKETPLACEAPP)
|
||||
<< " " << *i << ": " << app_error << ". ";
|
||||
<< " " << app_id << ": " << app_error << ". ";
|
||||
|
||||
att.resp_msg = att.resp_msg + oss.str();
|
||||
|
||||
rc = -1;
|
||||
}
|
||||
|
||||
app->unlock();
|
||||
}
|
||||
|
||||
MarketPlacePool* mppool = static_cast<MarketPlacePool *>(pool);
|
||||
|
||||
mp = mppool->get(mp_id);
|
||||
auto mp = mppool->get(mp_id);
|
||||
|
||||
if (mp == 0)
|
||||
if (mp == nullptr)
|
||||
{
|
||||
att.resp_msg = "MarketPlace no longer exists";
|
||||
|
||||
@ -1011,15 +945,13 @@ int MarketPlaceDelete::drop(PoolObjectSQL * object, bool r, RequestAttributes& a
|
||||
|
||||
if ( rc == 0 )
|
||||
{
|
||||
mppool->drop(mp, att.resp_msg);
|
||||
mppool->drop(mp.get(), att.resp_msg);
|
||||
}
|
||||
else if (old_monitor)
|
||||
{
|
||||
mp->enable_monitor();
|
||||
}
|
||||
|
||||
mp->unlock();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -1038,20 +970,20 @@ MarketPlaceAppDelete::MarketPlaceAppDelete()
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
int MarketPlaceAppDelete::drop(PoolObjectSQL * object, bool r, RequestAttributes& att)
|
||||
int MarketPlaceAppDelete::drop(std::unique_ptr<PoolObjectSQL> object, bool r, RequestAttributes& att)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
|
||||
MarketPlaceManager * marketm = nd.get_marketm();
|
||||
MarketPlacePool * marketpool = nd.get_marketpool();
|
||||
|
||||
MarketPlaceApp * app = static_cast<MarketPlaceApp *>(object);
|
||||
MarketPlaceApp * app = static_cast<MarketPlaceApp *>(object.get());
|
||||
|
||||
int mp_id = app->get_market_id();
|
||||
int zone_id = app->get_zone_id();
|
||||
int oid = app->get_oid();
|
||||
|
||||
app->unlock();
|
||||
object.reset();
|
||||
|
||||
if ( zone_id != nd.get_zone_id() )
|
||||
{
|
||||
@ -1063,28 +995,27 @@ int MarketPlaceAppDelete::drop(PoolObjectSQL * object, bool r, RequestAttributes
|
||||
return -1;
|
||||
}
|
||||
|
||||
MarketPlace * mp = marketpool->get_ro(mp_id);
|
||||
|
||||
if ( mp == 0 )
|
||||
{
|
||||
att.resp_msg = "Cannot find associated MARKETPLACE";
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::string mp_name = mp->get_name();
|
||||
std::string mp_name;
|
||||
std::string mp_data;
|
||||
|
||||
if ( auto mp = marketpool->get_ro(mp_id) )
|
||||
{
|
||||
mp_name = mp->get_name();
|
||||
|
||||
if ( !mp->is_action_supported(MarketPlaceApp::DELETE) )
|
||||
{
|
||||
att.resp_msg = "Delete disabled for market: " + mp_name;
|
||||
mp->unlock();
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
mp->to_xml(mp_data);
|
||||
|
||||
mp->unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
att.resp_msg = "Cannot find associated MARKETPLACE";
|
||||
return -1;
|
||||
}
|
||||
|
||||
return marketm->delete_app(oid, mp_data, att.resp_msg);
|
||||
}
|
||||
|
@ -25,8 +25,6 @@ void GroupSetQuota::
|
||||
int id = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
string quota_str = xmlrpc_c::value_string(paramList.getString(2));
|
||||
|
||||
Group * group;
|
||||
|
||||
Template quota_tmpl;
|
||||
int rc;
|
||||
|
||||
@ -50,9 +48,9 @@ void GroupSetQuota::
|
||||
return;
|
||||
}
|
||||
|
||||
group = static_cast<Group *>(pool->get(id));
|
||||
auto group = pool->get<Group>(id);
|
||||
|
||||
if ( group == 0 )
|
||||
if ( group == nullptr )
|
||||
{
|
||||
att.resp_id = id;
|
||||
failure_response(NO_EXISTS, att);
|
||||
@ -61,9 +59,7 @@ void GroupSetQuota::
|
||||
|
||||
group->quota.set("a_tmpl, att.resp_msg);
|
||||
|
||||
static_cast<GroupPool *>(pool)->update_quotas(group);
|
||||
|
||||
group->unlock();
|
||||
static_cast<GroupPool *>(pool)->update_quotas(group.get());
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
@ -92,8 +88,6 @@ void GroupEditAdmin::request_execute(
|
||||
string user_name;
|
||||
string error_str;
|
||||
|
||||
Group* group;
|
||||
|
||||
int rc;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
@ -133,24 +127,22 @@ void GroupEditAdmin::request_execute(
|
||||
return;
|
||||
}
|
||||
|
||||
group = static_cast<GroupPool*>(pool)->get(group_id);
|
||||
auto group = pool->get<Group>(group_id);
|
||||
|
||||
if ( group == 0 )
|
||||
if ( group == nullptr )
|
||||
{
|
||||
att.resp_id = group_id;
|
||||
failure_response(NO_EXISTS, att);
|
||||
return;
|
||||
}
|
||||
|
||||
rc = edit_admin(group, user_id, att.resp_msg);
|
||||
rc = edit_admin(group.get(), user_id, att.resp_msg);
|
||||
|
||||
if (rc == 0)
|
||||
{
|
||||
pool->update(group);
|
||||
pool->update(group.get());
|
||||
}
|
||||
|
||||
group->unlock();
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
att.resp_msg = "Cannot edit group. " + att.resp_msg;
|
||||
|
@ -33,7 +33,6 @@ void HookRetry::request_execute(xmlrpc_c::paramList const& _paramList,
|
||||
HookPool* hkpool = nd.get_hkpool();
|
||||
HookLog* hklog = nd.get_hl();
|
||||
|
||||
Hook* hook;
|
||||
PoolObjectAuth hk_perms;
|
||||
|
||||
int rc;
|
||||
@ -41,7 +40,7 @@ void HookRetry::request_execute(xmlrpc_c::paramList const& _paramList,
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Get Hook */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
hook = hkpool->get_ro(hk_id);
|
||||
auto hook = hkpool->get_ro(hk_id);
|
||||
|
||||
if (hook == nullptr)
|
||||
{
|
||||
@ -60,16 +59,12 @@ void HookRetry::request_execute(xmlrpc_c::paramList const& _paramList,
|
||||
|
||||
if (UserPool::authorize(ar) == -1)
|
||||
{
|
||||
hook->unlock();
|
||||
|
||||
att.resp_msg = ar.message;
|
||||
failure_response(AUTHORIZATION, att);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
hook->unlock();
|
||||
|
||||
//How is the execution managed? what does the driver needs?
|
||||
rc = hklog->retry(hk_id, hk_exe_id, att.resp_msg);
|
||||
|
||||
|
@ -33,9 +33,9 @@ void HostStatus::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
return;
|
||||
}
|
||||
|
||||
Host * host = hpool->get(id);
|
||||
auto host = hpool->get(id);
|
||||
|
||||
if ( host == 0 )
|
||||
if ( host == nullptr )
|
||||
{
|
||||
att.resp_id = id;
|
||||
failure_response(NO_EXISTS, att);
|
||||
@ -58,13 +58,10 @@ void HostStatus::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
att.resp_msg = "Wrong status code";
|
||||
failure_response(INTERNAL, att);
|
||||
|
||||
host->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
hpool->update(host);
|
||||
|
||||
host->unlock();
|
||||
hpool->update(host.get());
|
||||
|
||||
success_response(id, att);
|
||||
}
|
||||
|
@ -96,9 +96,6 @@ Request::ErrorCode ImagePersistent::request_execute(
|
||||
ImagePool * ipool = nd.get_ipool();
|
||||
DatastorePool * dspool = nd.get_dspool();
|
||||
|
||||
Datastore * ds;
|
||||
Image * image;
|
||||
|
||||
ErrorCode ec;
|
||||
|
||||
ec = basic_authorization(ipool, id, PoolObjectSQL::IMAGE, att);
|
||||
@ -108,35 +105,31 @@ Request::ErrorCode ImagePersistent::request_execute(
|
||||
return ec;
|
||||
}
|
||||
|
||||
image = ipool->get_ro(id);
|
||||
|
||||
if ( image == 0 )
|
||||
if ( auto image = ipool->get_ro(id) )
|
||||
{
|
||||
ds_id = image->get_ds_id();
|
||||
}
|
||||
else
|
||||
{
|
||||
att.resp_id = id;
|
||||
|
||||
return NO_EXISTS;
|
||||
}
|
||||
|
||||
ds_id = image->get_ds_id();
|
||||
|
||||
image->unlock();
|
||||
|
||||
ds = dspool->get_ro(ds_id);
|
||||
|
||||
if ( ds == 0 )
|
||||
if (auto ds = dspool->get_ro(ds_id))
|
||||
{
|
||||
ds_persistent_only = ds->is_persistent_only();
|
||||
}
|
||||
else
|
||||
{
|
||||
att.resp_msg = "Datastore no longer exists.";
|
||||
|
||||
return INTERNAL;
|
||||
}
|
||||
|
||||
ds_persistent_only = ds->is_persistent_only();
|
||||
auto image = ipool->get(id);
|
||||
|
||||
ds->unlock();
|
||||
|
||||
image = ipool->get(id);
|
||||
|
||||
if ( image == 0 )
|
||||
if ( image == nullptr )
|
||||
{
|
||||
att.resp_id = id;
|
||||
|
||||
@ -154,7 +147,6 @@ Request::ErrorCode ImagePersistent::request_execute(
|
||||
case Image::RAMDISK:
|
||||
case Image::CONTEXT:
|
||||
att.resp_msg = "KERNEL, RAMDISK and CONTEXT must be non-persistent";
|
||||
image->unlock();
|
||||
|
||||
return ACTION;
|
||||
}
|
||||
@ -164,8 +156,6 @@ Request::ErrorCode ImagePersistent::request_execute(
|
||||
{
|
||||
att.resp_msg = "This Datastore only accepts persistent images.";
|
||||
|
||||
image->unlock();
|
||||
|
||||
return INTERNAL;
|
||||
}
|
||||
|
||||
@ -182,14 +172,10 @@ Request::ErrorCode ImagePersistent::request_execute(
|
||||
att.resp_msg = "Could not make image non-persistent: " + att.resp_msg;
|
||||
}
|
||||
|
||||
image->unlock();
|
||||
|
||||
return INTERNAL;
|
||||
}
|
||||
|
||||
ipool->update(image);
|
||||
|
||||
image->unlock();
|
||||
ipool->update(image.get());
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
@ -206,16 +192,14 @@ void ImageChangeType::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
|
||||
Image::ImageType itype;
|
||||
|
||||
Image * image;
|
||||
|
||||
if ( basic_authorization(id, att) == false )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
image = static_cast<Image *>(pool->get(id));
|
||||
auto image = pool->get<Image>(id);
|
||||
|
||||
if ( image == 0 )
|
||||
if ( image == nullptr )
|
||||
{
|
||||
att.resp_id = id;
|
||||
failure_response(NO_EXISTS, att);
|
||||
@ -236,7 +220,6 @@ void ImageChangeType::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
" for the current datastore.";
|
||||
failure_response(ACTION, att);
|
||||
|
||||
image->unlock();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
@ -252,7 +235,6 @@ void ImageChangeType::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
" for the current datastore.";
|
||||
failure_response(ACTION, att);
|
||||
|
||||
image->unlock();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
@ -264,13 +246,10 @@ void ImageChangeType::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
{
|
||||
failure_response(INTERNAL, att);
|
||||
|
||||
image->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
pool->update(image);
|
||||
|
||||
image->unlock();
|
||||
pool->update(image.get());
|
||||
|
||||
success_response(id, att);
|
||||
}
|
||||
@ -327,8 +306,6 @@ Request::ErrorCode ImageClone::request_execute(
|
||||
|
||||
ImageTemplate * tmpl;
|
||||
Template img_usage;
|
||||
Image * img;
|
||||
Datastore * ds;
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
|
||||
@ -336,15 +313,8 @@ Request::ErrorCode ImageClone::request_execute(
|
||||
ImagePool * ipool = nd.get_ipool();
|
||||
|
||||
// ------------------------- Get source Image info -------------------------
|
||||
|
||||
img = ipool->get_ro(clone_id);
|
||||
|
||||
if ( img == 0 )
|
||||
if ( auto img = ipool->get_ro(clone_id) )
|
||||
{
|
||||
att.resp_id = clone_id;
|
||||
return NO_EXISTS;
|
||||
}
|
||||
|
||||
switch (img->get_type())
|
||||
{
|
||||
case Image::OS:
|
||||
@ -356,7 +326,6 @@ Request::ErrorCode ImageClone::request_execute(
|
||||
case Image::RAMDISK:
|
||||
case Image::CONTEXT:
|
||||
att.resp_msg = "KERNEL, RAMDISK and CONTEXT cannot be cloned.";
|
||||
img->unlock();
|
||||
return ACTION;
|
||||
}
|
||||
|
||||
@ -365,7 +334,6 @@ Request::ErrorCode ImageClone::request_execute(
|
||||
if (snaps.size () > 0)
|
||||
{
|
||||
att.resp_msg = "Cannot clone images with snapshots";
|
||||
img->unlock();
|
||||
return ACTION;
|
||||
}
|
||||
|
||||
@ -381,8 +349,12 @@ Request::ErrorCode ImageClone::request_execute(
|
||||
ds_id_orig = img->get_ds_id();
|
||||
|
||||
size = img->get_size();
|
||||
|
||||
img->unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
att.resp_id = clone_id;
|
||||
return NO_EXISTS;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Set image persistent attribute
|
||||
@ -398,23 +370,12 @@ Request::ErrorCode ImageClone::request_execute(
|
||||
|
||||
// ----------------------- Get target Datastore info -----------------------
|
||||
|
||||
ds = dspool->get_ro(ds_id);
|
||||
|
||||
if ( ds == 0 )
|
||||
if ( auto ds = dspool->get_ro(ds_id) )
|
||||
{
|
||||
att.resp_obj = PoolObjectSQL::DATASTORE;
|
||||
att.resp_id = ds_id;
|
||||
|
||||
delete tmpl;
|
||||
return NO_EXISTS;
|
||||
}
|
||||
|
||||
if ( ds->get_type() != Datastore::IMAGE_DS )
|
||||
{
|
||||
att.resp_msg = "Clone only supported for IMAGE_DS Datastores";
|
||||
|
||||
ds->unlock();
|
||||
|
||||
delete tmpl;
|
||||
return ACTION;
|
||||
}
|
||||
@ -429,14 +390,21 @@ Request::ErrorCode ImageClone::request_execute(
|
||||
ds_name = ds->get_name();
|
||||
ds_mad = ds->get_ds_mad();
|
||||
tm_mad = ds->get_tm_mad();
|
||||
}
|
||||
else
|
||||
{
|
||||
att.resp_obj = PoolObjectSQL::DATASTORE;
|
||||
att.resp_id = ds_id;
|
||||
|
||||
ds->unlock();
|
||||
delete tmpl;
|
||||
return NO_EXISTS;
|
||||
}
|
||||
|
||||
if (ds_id != ds_id_orig) //check same DS_MAD
|
||||
{
|
||||
ds = dspool->get_ro(ds_id_orig);
|
||||
auto ds = dspool->get_ro(ds_id_orig);
|
||||
|
||||
if (ds == 0)
|
||||
if (ds == nullptr)
|
||||
{
|
||||
att.resp_obj = PoolObjectSQL::DATASTORE;
|
||||
att.resp_id = ds_id_orig;
|
||||
@ -449,8 +417,6 @@ Request::ErrorCode ImageClone::request_execute(
|
||||
{
|
||||
att.resp_msg = "Clone only supported for IMAGE_DS Datastores";
|
||||
|
||||
ds->unlock();
|
||||
|
||||
delete tmpl;
|
||||
return ACTION;
|
||||
}
|
||||
@ -459,15 +425,11 @@ Request::ErrorCode ImageClone::request_execute(
|
||||
{
|
||||
att.resp_msg = "Clone only supported to same DS_MAD Datastores";
|
||||
|
||||
ds->unlock();
|
||||
|
||||
delete tmpl;
|
||||
return ACTION;
|
||||
}
|
||||
|
||||
ds->get_permissions(ds_perms_orig);
|
||||
|
||||
ds->unlock();
|
||||
}
|
||||
|
||||
// ------------- Set authorization request ---------------------------------
|
||||
@ -546,15 +508,11 @@ Request::ErrorCode ImageClone::request_execute(
|
||||
return ALLOCATE;
|
||||
}
|
||||
|
||||
ds = dspool->get(ds_id);
|
||||
|
||||
if ( ds != 0 ) // TODO: error otherwise or leave image in ERROR?
|
||||
if ( auto ds = dspool->get(ds_id) ) // TODO: error otherwise or leave image in ERROR?
|
||||
{
|
||||
ds->add_image(new_id);
|
||||
|
||||
dspool->update(ds);
|
||||
|
||||
ds->unlock();
|
||||
dspool->update(ds.get());
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
|
@ -29,7 +29,6 @@ void RequestManagerInfo::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
int oid = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
PoolObjectSQL * object;
|
||||
string str;
|
||||
|
||||
if ( oid == -1 )
|
||||
@ -49,7 +48,7 @@ void RequestManagerInfo::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
return;
|
||||
}
|
||||
|
||||
object = pool->get_ro(oid);
|
||||
auto object = pool->get_ro<PoolObjectSQL>(oid);
|
||||
|
||||
if ( object == nullptr )
|
||||
{
|
||||
@ -70,11 +69,9 @@ void RequestManagerInfo::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
object->decrypt();
|
||||
}
|
||||
|
||||
load_monitoring(object);
|
||||
load_monitoring(object.get());
|
||||
|
||||
to_xml(att, object, str);
|
||||
|
||||
object->unlock();
|
||||
to_xml(att, object.get(), str);
|
||||
|
||||
success_response(str, att);
|
||||
|
||||
@ -88,7 +85,6 @@ void TemplateInfo::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
VMTemplatePool * tpool = static_cast<VMTemplatePool *>(pool);
|
||||
VMTemplate * vm_tmpl;
|
||||
|
||||
VirtualMachineTemplate * extended_tmpl = nullptr;
|
||||
|
||||
@ -104,7 +100,7 @@ void TemplateInfo::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
extended = xmlrpc_c::value_boolean(paramList.getBoolean(2));
|
||||
}
|
||||
|
||||
vm_tmpl = tpool->get_ro(oid);
|
||||
auto vm_tmpl = tpool->get_ro(oid);
|
||||
|
||||
if ( vm_tmpl == nullptr )
|
||||
{
|
||||
@ -120,8 +116,6 @@ void TemplateInfo::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
|
||||
vm_tmpl->get_permissions(perms);
|
||||
|
||||
vm_tmpl->unlock();
|
||||
|
||||
AuthRequest ar(att.uid, att.group_ids);
|
||||
|
||||
ar.add_auth(att.auth_op, perms); //USE TEMPLATE
|
||||
@ -142,17 +136,6 @@ void TemplateInfo::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
return;
|
||||
}
|
||||
|
||||
vm_tmpl = tpool->get_ro(oid);
|
||||
|
||||
if ( vm_tmpl == nullptr )
|
||||
{
|
||||
att.resp_id = oid;
|
||||
failure_response(NO_EXISTS, att);
|
||||
|
||||
delete extended_tmpl;
|
||||
return;
|
||||
}
|
||||
|
||||
// Check optional parameter - decrypt
|
||||
bool decrypt = false;
|
||||
|
||||
@ -177,8 +160,6 @@ void TemplateInfo::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
|
||||
delete extended_tmpl;
|
||||
|
||||
vm_tmpl->unlock();
|
||||
|
||||
success_response(str, att);
|
||||
|
||||
return;
|
||||
@ -191,14 +172,13 @@ void VirtualNetworkTemplateInfo::request_execute(xmlrpc_c::paramList const& para
|
||||
RequestAttributes& att)
|
||||
{
|
||||
VNTemplatePool * tpool = static_cast<VNTemplatePool *>(pool);
|
||||
VNTemplate * vn_tmpl;
|
||||
|
||||
PoolObjectAuth perms;
|
||||
|
||||
int oid = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
string str;
|
||||
|
||||
vn_tmpl = tpool->get_ro(oid);
|
||||
auto vn_tmpl = tpool->get_ro(oid);
|
||||
|
||||
if ( vn_tmpl == nullptr )
|
||||
{
|
||||
@ -209,8 +189,6 @@ void VirtualNetworkTemplateInfo::request_execute(xmlrpc_c::paramList const& para
|
||||
|
||||
vn_tmpl->get_permissions(perms);
|
||||
|
||||
vn_tmpl->unlock();
|
||||
|
||||
AuthRequest ar(att.uid, att.group_ids);
|
||||
|
||||
ar.add_auth(att.auth_op, perms); //USE TEMPLATE
|
||||
@ -223,16 +201,6 @@ void VirtualNetworkTemplateInfo::request_execute(xmlrpc_c::paramList const& para
|
||||
return;
|
||||
}
|
||||
|
||||
vn_tmpl = tpool->get_ro(oid);
|
||||
|
||||
if ( vn_tmpl == nullptr )
|
||||
{
|
||||
att.resp_id = oid;
|
||||
failure_response(NO_EXISTS, att);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Check optional parameter - decrypt
|
||||
bool decrypt = false;
|
||||
|
||||
@ -248,8 +216,6 @@ void VirtualNetworkTemplateInfo::request_execute(xmlrpc_c::paramList const& para
|
||||
|
||||
vn_tmpl->to_xml(str);
|
||||
|
||||
vn_tmpl->unlock();
|
||||
|
||||
success_response(str, att);
|
||||
|
||||
return;
|
||||
|
@ -39,7 +39,6 @@ void RequestManagerLock::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
int level = xmlrpc_c::value_int(paramList.getInt(2));
|
||||
int owner = att.uid;
|
||||
|
||||
PoolObjectSQL * object;
|
||||
string error_str;
|
||||
int rc;
|
||||
|
||||
@ -48,9 +47,9 @@ void RequestManagerLock::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
return;
|
||||
}
|
||||
|
||||
object = pool->get(oid);
|
||||
auto object = pool->get<PoolObjectSQL>(oid);
|
||||
|
||||
if ( object == 0 )
|
||||
if ( object == nullptr )
|
||||
{
|
||||
att.resp_id = oid;
|
||||
failure_response(NO_EXISTS, att);
|
||||
@ -59,11 +58,9 @@ void RequestManagerLock::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
|
||||
if ((auth_object & PoolObjectSQL::LockableObject) != 0)
|
||||
{
|
||||
rc = lock_db(object, owner, att.req_id, level);
|
||||
rc = lock_db(object.get(), owner, att.req_id, level);
|
||||
|
||||
pool->update(object);
|
||||
|
||||
object->unlock();
|
||||
pool->update(object.get());
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
@ -77,8 +74,6 @@ void RequestManagerLock::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
}
|
||||
else
|
||||
{
|
||||
object->unlock();
|
||||
|
||||
failure_response(AUTHORIZATION, att);
|
||||
}
|
||||
|
||||
@ -93,7 +88,6 @@ void RequestManagerUnlock::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
{
|
||||
int oid = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
|
||||
PoolObjectSQL * object;
|
||||
string error_str;
|
||||
|
||||
int owner = att.uid;
|
||||
@ -104,7 +98,7 @@ void RequestManagerUnlock::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
return;
|
||||
}
|
||||
|
||||
object = pool->get(oid);
|
||||
auto object = pool->get<PoolObjectSQL>(oid);
|
||||
|
||||
if ( object == 0 )
|
||||
{
|
||||
@ -118,18 +112,15 @@ void RequestManagerUnlock::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
owner = -1;
|
||||
}
|
||||
|
||||
if ( unlock_db(object, owner, req_id) == -1 )
|
||||
if ( unlock_db(object.get(), owner, req_id) == -1 )
|
||||
{
|
||||
att.resp_msg = "Cannot unlock: Lock is owned by another user";
|
||||
failure_response(ACTION, att);
|
||||
|
||||
object->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
pool->update(object);
|
||||
|
||||
object->unlock();
|
||||
pool->update(object.get());
|
||||
|
||||
success_response(oid, att);
|
||||
|
||||
|
@ -42,16 +42,14 @@ void MarketPlaceAppEnable::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
bool enable_flag = xmlrpc_c::value_boolean(paramList.getBoolean(2));
|
||||
int rc;
|
||||
|
||||
MarketPlaceApp * app;
|
||||
|
||||
if ( basic_authorization(id, att) == false )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
app = static_cast<MarketPlaceApp *>(pool->get(id));
|
||||
auto app = pool->get<MarketPlaceApp>(id);
|
||||
|
||||
if ( app == 0 )
|
||||
if ( app == nullptr )
|
||||
{
|
||||
att.resp_id = id;
|
||||
failure_response(NO_EXISTS, att);
|
||||
@ -64,13 +62,10 @@ void MarketPlaceAppEnable::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
{
|
||||
failure_response(INTERNAL, att);
|
||||
|
||||
app->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
pool->update(app);
|
||||
|
||||
app->unlock();
|
||||
pool->update(app.get());
|
||||
|
||||
success_response(id, att);
|
||||
}
|
||||
|
@ -35,7 +35,6 @@ void RequestManagerRename::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
string old_name;
|
||||
|
||||
PoolObjectAuth operms;
|
||||
PoolObjectSQL * object;
|
||||
|
||||
if (test_and_set_rename(oid) == false)
|
||||
{
|
||||
@ -96,10 +95,21 @@ void RequestManagerRename::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
}
|
||||
|
||||
// -------------------------- Update the object ----------------------------
|
||||
if ( auto object = pool->get<PoolObjectSQL>(oid) )
|
||||
{
|
||||
if ( object->set_name(new_name, att.resp_msg) != 0 )
|
||||
{
|
||||
failure_response(ACTION, att);
|
||||
|
||||
object = pool->get(oid);
|
||||
clear_rename(oid);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( object == 0 )
|
||||
pool->update(object.get());
|
||||
|
||||
extra_updates(object.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
att.resp_id = oid;
|
||||
failure_response(NO_EXISTS, att);
|
||||
@ -108,22 +118,6 @@ void RequestManagerRename::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
return;
|
||||
}
|
||||
|
||||
if ( object->set_name(new_name, att.resp_msg) != 0 )
|
||||
{
|
||||
object->unlock();
|
||||
|
||||
failure_response(ACTION, att);
|
||||
|
||||
clear_rename(oid);
|
||||
return;
|
||||
}
|
||||
|
||||
pool->update(object);
|
||||
|
||||
extra_updates(object);
|
||||
|
||||
object->unlock();
|
||||
|
||||
batch_rename(oid);
|
||||
|
||||
success_response(oid, att);
|
||||
@ -138,35 +132,31 @@ void RequestManagerRename::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
|
||||
void ClusterRename::batch_rename(int oid)
|
||||
{
|
||||
Cluster * cluster = static_cast<ClusterPool *>(pool)->get_ro(oid);
|
||||
set<int> hosts;
|
||||
string cluster_name;
|
||||
|
||||
if (cluster == 0)
|
||||
if ( auto cluster = pool->get_ro<Cluster>(oid) )
|
||||
{
|
||||
hosts = cluster->get_host_ids();
|
||||
|
||||
cluster_name = cluster->get_name();
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
set<int> hosts = cluster->get_host_ids();
|
||||
|
||||
string cluster_name = cluster->get_name();
|
||||
|
||||
cluster->unlock();
|
||||
|
||||
Host * host;
|
||||
HostPool* hpool = Nebula::instance().get_hpool();
|
||||
|
||||
for (set<int>::iterator it = hosts.begin(); it != hosts.end(); it++)
|
||||
for (auto hid : hosts)
|
||||
{
|
||||
host = hpool->get(*it);
|
||||
|
||||
if (host != 0)
|
||||
if (auto host = hpool->get(hid))
|
||||
{
|
||||
if (host->get_cluster_id() == oid)
|
||||
{
|
||||
host->set_cluster(oid, cluster_name);
|
||||
hpool->update(host);
|
||||
hpool->update(host.get());
|
||||
}
|
||||
|
||||
host->unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -176,37 +166,31 @@ void ClusterRename::batch_rename(int oid)
|
||||
|
||||
void DatastoreRename::batch_rename(int oid)
|
||||
{
|
||||
Datastore * datastore = static_cast<DatastorePool*>(pool)->get_ro(oid);
|
||||
set<int> images;
|
||||
string image_name;
|
||||
|
||||
if (datastore == 0)
|
||||
if ( auto datastore = pool->get_ro<Datastore>(oid) )
|
||||
{
|
||||
images = datastore->get_image_ids();
|
||||
|
||||
image_name = datastore->get_name();
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
set<int> images = datastore->get_image_ids();
|
||||
|
||||
set<int>::iterator it;
|
||||
|
||||
string image_name = datastore->get_name();
|
||||
|
||||
datastore->unlock();
|
||||
|
||||
Image * image;
|
||||
ImagePool * ipool = Nebula::instance().get_ipool();
|
||||
|
||||
for (it = images.begin(); it != images.end(); it++)
|
||||
for (auto iid : images)
|
||||
{
|
||||
image = ipool->get(*it);
|
||||
|
||||
if (image != 0)
|
||||
if (auto image = ipool->get(iid))
|
||||
{
|
||||
if (image->get_ds_id() == oid)
|
||||
{
|
||||
image->set_ds_name(image_name);
|
||||
ipool->update(image);
|
||||
ipool->update(image.get());
|
||||
}
|
||||
|
||||
image->unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -216,39 +200,33 @@ void DatastoreRename::batch_rename(int oid)
|
||||
|
||||
void HostRename::batch_rename(int oid)
|
||||
{
|
||||
Host * host = static_cast<HostPool*>(pool)->get_ro(oid);
|
||||
set<int> vms;
|
||||
string host_name;
|
||||
|
||||
if (host == 0)
|
||||
if ( auto host = pool->get_ro<Host>(oid) )
|
||||
{
|
||||
vms = host->get_vm_ids();
|
||||
|
||||
host_name = host->get_name();
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
set<int> vms = host->get_vm_ids();
|
||||
|
||||
set<int>::iterator it;
|
||||
|
||||
string host_name = host->get_name();
|
||||
|
||||
host->unlock();
|
||||
|
||||
VirtualMachine * vm;
|
||||
VirtualMachinePool * vmpool = Nebula::instance().get_vmpool();
|
||||
|
||||
for (it = vms.begin(); it != vms.end(); it++)
|
||||
for (auto vid : vms)
|
||||
{
|
||||
vm = vmpool->get(*it);
|
||||
|
||||
if (vm != 0)
|
||||
if (auto vm = vmpool->get(vid))
|
||||
{
|
||||
if (vm->hasHistory() && vm->get_hid() == oid)
|
||||
{
|
||||
vm->set_hostname(host_name);
|
||||
|
||||
vmpool->update_history(vm);
|
||||
vmpool->update_search(vm);
|
||||
vmpool->update_history(vm.get());
|
||||
vmpool->update_search(vm.get());
|
||||
}
|
||||
|
||||
vm->unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -258,37 +236,31 @@ void HostRename::batch_rename(int oid)
|
||||
|
||||
void MarketPlaceRename::batch_rename(int oid)
|
||||
{
|
||||
MarketPlace * market = static_cast<MarketPlacePool*>(pool)->get_ro(oid);
|
||||
std::set<int> apps;
|
||||
std::string market_name;
|
||||
|
||||
if (market == 0)
|
||||
if ( auto market = pool->get_ro<MarketPlace>(oid) )
|
||||
{
|
||||
apps = market->get_marketapp_ids();
|
||||
|
||||
market_name = market->get_name();
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
std::set<int> apps = market->get_marketapp_ids();
|
||||
|
||||
std::set<int>::iterator it;
|
||||
|
||||
std::string market_name = market->get_name();
|
||||
|
||||
market->unlock();
|
||||
|
||||
MarketPlaceApp * app;
|
||||
MarketPlaceAppPool * apppool = Nebula::instance().get_apppool();
|
||||
|
||||
for (it = apps.begin(); it != apps.end(); it++)
|
||||
for (auto app_id : apps)
|
||||
{
|
||||
app = apppool->get(*it);
|
||||
|
||||
if (app != 0)
|
||||
if (auto app = apppool->get(app_id))
|
||||
{
|
||||
if (app->get_market_id() == oid)
|
||||
{
|
||||
app->set_market_name(market_name);
|
||||
apppool->update(app);
|
||||
apppool->update(app.get());
|
||||
}
|
||||
|
||||
app->unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,8 +42,6 @@ void SecurityGroupCommit::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
int oid = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
bool recover = xmlrpc_c::value_boolean(paramList.getBoolean(2));
|
||||
|
||||
SecurityGroup * sg;
|
||||
|
||||
LifeCycleManager* lcm = Nebula::instance().get_lcm();
|
||||
|
||||
|
||||
@ -52,7 +50,7 @@ void SecurityGroupCommit::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
return;
|
||||
}
|
||||
|
||||
sg = static_cast<SecurityGroupPool *>(pool)->get(oid);
|
||||
auto sg = static_cast<SecurityGroupPool *>(pool)->get(oid);
|
||||
|
||||
if ( sg == 0 )
|
||||
{
|
||||
@ -63,9 +61,7 @@ void SecurityGroupCommit::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
|
||||
sg->commit(recover);
|
||||
|
||||
pool->update(sg);
|
||||
|
||||
sg->unlock();
|
||||
pool->update(sg.get());
|
||||
|
||||
lcm->trigger_updatesg(oid);
|
||||
|
||||
|
@ -75,8 +75,6 @@ void RequestManagerUpdateTemplate::request_execute(
|
||||
update_type = xmlrpc_c::value_int(paramList.getInt(3));
|
||||
}
|
||||
|
||||
PoolObjectSQL * object;
|
||||
|
||||
if ( basic_authorization(oid, att) == false )
|
||||
{
|
||||
return;
|
||||
@ -90,9 +88,9 @@ void RequestManagerUpdateTemplate::request_execute(
|
||||
}
|
||||
|
||||
|
||||
object = pool->get(oid);
|
||||
auto object = pool->get<PoolObjectSQL>(oid);
|
||||
|
||||
if ( object == 0 )
|
||||
if ( object == nullptr )
|
||||
{
|
||||
att.resp_id = oid;
|
||||
failure_response(NO_EXISTS, att);
|
||||
@ -101,27 +99,24 @@ void RequestManagerUpdateTemplate::request_execute(
|
||||
|
||||
if (update_type == 0)
|
||||
{
|
||||
rc = replace_template(object, tmpl, att, att.resp_msg);
|
||||
rc = replace_template(object.get(), tmpl, att, att.resp_msg);
|
||||
}
|
||||
else //if (update_type == 1)
|
||||
{
|
||||
rc = append_template(object, tmpl, att, att.resp_msg);
|
||||
rc = append_template(object.get(), tmpl, att, att.resp_msg);
|
||||
}
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
att.resp_msg = "Cannot update template. " + att.resp_msg;
|
||||
failure_response(INTERNAL, att);
|
||||
object->unlock();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
pool->update(object);
|
||||
pool->update(object.get());
|
||||
|
||||
extra_updates(object);
|
||||
|
||||
object->unlock();
|
||||
extra_updates(object.get());
|
||||
|
||||
success_response(oid, att);
|
||||
|
||||
@ -158,10 +153,8 @@ int ClusterUpdateTemplate::extra_updates(PoolObjectSQL * obj)
|
||||
|
||||
if (host->update_reserved_capacity(ccpu, cmem))
|
||||
{
|
||||
hpool->update(host);
|
||||
hpool->update(host.get());
|
||||
}
|
||||
|
||||
host->unlock();
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -57,9 +57,9 @@ int UserChangePassword::user_action(int user_id,
|
||||
|
||||
string new_pass = xmlrpc_c::value_string(paramList.getString(2));
|
||||
|
||||
User * user = (static_cast<UserPool *>(pool))->get(user_id);
|
||||
auto user = static_cast<UserPool *>(pool)->get(user_id);
|
||||
|
||||
if ( user == 0 )
|
||||
if ( user == nullptr )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@ -77,7 +77,6 @@ int UserChangePassword::user_action(int user_id,
|
||||
{
|
||||
error_str = "Password for driver " + user->get_auth_driver() +
|
||||
" cannot be changed.";
|
||||
user->unlock();
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -85,11 +84,9 @@ int UserChangePassword::user_action(int user_id,
|
||||
|
||||
if ( rc == 0 )
|
||||
{
|
||||
pool->update(user);
|
||||
pool->update(user.get());
|
||||
}
|
||||
|
||||
user->unlock();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -106,11 +103,9 @@ int UserChangeAuth::user_action(int user_id,
|
||||
|
||||
int rc = 0;
|
||||
|
||||
User * user;
|
||||
auto user = static_cast<UserPool *>(pool)->get(user_id);;
|
||||
|
||||
user = (static_cast<UserPool *>(pool))->get(user_id);
|
||||
|
||||
if ( user == 0 )
|
||||
if ( user == nullptr )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@ -133,11 +128,9 @@ int UserChangeAuth::user_action(int user_id,
|
||||
|
||||
if ( rc == 0 )
|
||||
{
|
||||
pool->update(user);
|
||||
pool->update(user.get());
|
||||
}
|
||||
|
||||
user->unlock();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -154,7 +147,6 @@ int UserSetQuota::user_action(int user_id,
|
||||
Template quota_tmpl;
|
||||
|
||||
int rc;
|
||||
User * user;
|
||||
|
||||
if ( user_id == UserPool::ONEADMIN_ID )
|
||||
{
|
||||
@ -169,18 +161,17 @@ int UserSetQuota::user_action(int user_id,
|
||||
return -1;
|
||||
}
|
||||
|
||||
user = (static_cast<UserPool *>(pool))->get(user_id);
|
||||
auto upool = static_cast<UserPool *>(pool);
|
||||
auto user = upool->get(user_id);
|
||||
|
||||
if ( user == 0 )
|
||||
if ( user == nullptr )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = user->quota.set("a_tmpl, error_str);
|
||||
|
||||
static_cast<UserPool *>(pool)->update_quotas(user);
|
||||
|
||||
user->unlock();
|
||||
upool->update_quotas(user.get());
|
||||
|
||||
return rc;
|
||||
}
|
||||
@ -206,9 +197,15 @@ void UserEditGroup::
|
||||
PoolObjectAuth uperms;
|
||||
PoolObjectAuth gperms;
|
||||
|
||||
User* user = upool->get_ro(user_id);
|
||||
if ( auto user = upool->get_ro(user_id) )
|
||||
{
|
||||
user->get_permissions(uperms);
|
||||
|
||||
if ( user == 0 )
|
||||
uname = user->get_name();
|
||||
|
||||
auth_driver = user->get_auth_driver();
|
||||
}
|
||||
else
|
||||
{
|
||||
att.resp_obj = PoolObjectSQL::USER;
|
||||
att.resp_id = user_id;
|
||||
@ -217,14 +214,6 @@ void UserEditGroup::
|
||||
return;
|
||||
}
|
||||
|
||||
user->get_permissions(uperms);
|
||||
|
||||
uname = user->get_name();
|
||||
|
||||
auth_driver = user->get_auth_driver();
|
||||
|
||||
user->unlock();
|
||||
|
||||
bool driver_managed_groups;
|
||||
|
||||
if (Nebula::instance().get_auth_conf_attribute(auth_driver,
|
||||
@ -278,45 +267,35 @@ int UserAddGroup::secondary_group_action(
|
||||
xmlrpc_c::paramList const& _paramList,
|
||||
string& error_str)
|
||||
{
|
||||
User * user;
|
||||
Group * group;
|
||||
|
||||
int rc;
|
||||
|
||||
user = upool->get(user_id);
|
||||
|
||||
if ( user == 0 )
|
||||
if ( auto user = upool->get(user_id) )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = user->add_group(group_id);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
user->unlock();
|
||||
|
||||
error_str = "User is already in this group";
|
||||
return -1;
|
||||
}
|
||||
|
||||
upool->update(user);
|
||||
|
||||
user->unlock();
|
||||
|
||||
group = gpool->get(group_id);
|
||||
|
||||
if( group == 0 )
|
||||
upool->update(user.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
user = upool->get(user_id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ( user != 0 )
|
||||
|
||||
auto group = gpool->get(group_id);
|
||||
|
||||
if ( group == nullptr )
|
||||
{
|
||||
if ( auto user = upool->get(user_id) )
|
||||
{
|
||||
user->del_group(group_id);
|
||||
|
||||
upool->update(user);
|
||||
|
||||
user->unlock();
|
||||
upool->update(user.get());
|
||||
}
|
||||
|
||||
error_str = "Group does not exist";
|
||||
@ -325,9 +304,7 @@ int UserAddGroup::secondary_group_action(
|
||||
|
||||
group->add_user(user_id);
|
||||
|
||||
gpool->update(group);
|
||||
|
||||
group->unlock();
|
||||
gpool->update(group.get());
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -341,19 +318,14 @@ int UserDelGroup::secondary_group_action(
|
||||
xmlrpc_c::paramList const& _paramList,
|
||||
string& error_str)
|
||||
{
|
||||
User * user;
|
||||
Group * group;
|
||||
|
||||
int rc;
|
||||
|
||||
user = upool->get(user_id);
|
||||
|
||||
if ( auto user = upool->get(user_id) )
|
||||
{
|
||||
rc = user->del_group(group_id);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
user->unlock();
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
error_str = "User is not part of this group";
|
||||
@ -370,13 +342,12 @@ int UserDelGroup::secondary_group_action(
|
||||
return rc;
|
||||
}
|
||||
|
||||
upool->update(user);
|
||||
upool->update(user.get());
|
||||
}
|
||||
|
||||
user->unlock();
|
||||
auto group = gpool->get(group_id);
|
||||
|
||||
group = gpool->get(group_id);
|
||||
|
||||
if( group == 0 )
|
||||
if ( group == nullptr )
|
||||
{
|
||||
//Group does not exist, should never occur
|
||||
error_str = "Cannot remove user from group";
|
||||
@ -385,9 +356,7 @@ int UserDelGroup::secondary_group_action(
|
||||
|
||||
group->del_user(user_id);
|
||||
|
||||
gpool->update(group);
|
||||
|
||||
group->unlock();
|
||||
gpool->update(group.get());
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -398,7 +367,6 @@ int UserDelGroup::secondary_group_action(
|
||||
void UserLogin::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
User * user;
|
||||
string error_str;
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@ -416,18 +384,18 @@ void UserLogin::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
|
||||
PoolObjectAuth perms;
|
||||
|
||||
user = static_cast<UserPool *>(pool)->get_ro(uname);
|
||||
auto upool = static_cast<UserPool *>(pool);
|
||||
|
||||
if ( user == 0 )
|
||||
if (auto user = upool->get_ro(uname))
|
||||
{
|
||||
user->get_permissions(perms);
|
||||
}
|
||||
else
|
||||
{
|
||||
failure_response(NO_EXISTS, att);
|
||||
return;
|
||||
}
|
||||
|
||||
user->get_permissions(perms);
|
||||
|
||||
user->unlock();
|
||||
|
||||
AuthRequest ar(att.uid, att.group_ids);
|
||||
|
||||
ar.add_auth(att.auth_op, perms);
|
||||
@ -439,9 +407,9 @@ void UserLogin::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
return;
|
||||
}
|
||||
|
||||
user = static_cast<UserPool *>(pool)->get(uname);
|
||||
auto user = upool->get(uname);
|
||||
|
||||
if ( user == 0 )
|
||||
if ( user == nullptr )
|
||||
{
|
||||
failure_response(NO_EXISTS, att);
|
||||
return;
|
||||
@ -466,8 +434,7 @@ void UserLogin::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
|
||||
// Reset any active token
|
||||
user->login_tokens.reset();
|
||||
pool->update(user);
|
||||
user->unlock();
|
||||
pool->update(user.get());
|
||||
|
||||
return;
|
||||
}
|
||||
@ -487,7 +454,6 @@ void UserLogin::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
att.resp_msg = "Could not find token: " + token;
|
||||
failure_response(XML_RPC_API, att);
|
||||
|
||||
user->unlock();
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -505,7 +471,6 @@ void UserLogin::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
att.resp_msg = "EGID is not in user group list";
|
||||
failure_response(XML_RPC_API, att);
|
||||
|
||||
user->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -514,7 +479,6 @@ void UserLogin::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
att.resp_msg = "Cannot create a full token with a specific group token";
|
||||
failure_response(XML_RPC_API, att);
|
||||
|
||||
user->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -523,7 +487,6 @@ void UserLogin::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
att.resp_msg = "Max number of tokens limit reached.";
|
||||
failure_response(XML_RPC_API, att);
|
||||
|
||||
user->unlock();
|
||||
return;
|
||||
|
||||
};
|
||||
@ -533,13 +496,10 @@ void UserLogin::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
att.resp_msg = "Wrong valid period for token";
|
||||
failure_response(XML_RPC_API, att);
|
||||
|
||||
user->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
pool->update(user);
|
||||
|
||||
user->unlock();
|
||||
pool->update(user.get());
|
||||
|
||||
success_response(token, att);
|
||||
}
|
||||
|
@ -47,21 +47,22 @@ void VMTemplateInstantiate::request_execute(xmlrpc_c::paramList const& paramList
|
||||
clone_template = xmlrpc_c::value_boolean(paramList.getBoolean(5));
|
||||
}
|
||||
|
||||
VMTemplate * tmpl = static_cast<VMTemplatePool* > (pool)->get_ro(id);
|
||||
bool is_vrouter;
|
||||
string original_tmpl_name;
|
||||
|
||||
if ( tmpl == 0 )
|
||||
if ( auto tmpl = pool->get_ro<VMTemplate>(id) )
|
||||
{
|
||||
is_vrouter = tmpl->is_vrouter();
|
||||
|
||||
original_tmpl_name = tmpl->get_name();
|
||||
}
|
||||
else
|
||||
{
|
||||
att.resp_id = id;
|
||||
failure_response(NO_EXISTS, att);
|
||||
return;
|
||||
}
|
||||
|
||||
bool is_vrouter = tmpl->is_vrouter();
|
||||
|
||||
string original_tmpl_name = tmpl->get_name();
|
||||
|
||||
tmpl->unlock();
|
||||
|
||||
if (is_vrouter)
|
||||
{
|
||||
att.resp_msg = "Virtual router templates cannot be instantiated";
|
||||
@ -138,11 +139,9 @@ Request::ErrorCode VMTemplateInstantiate::request_execute(int id, string name,
|
||||
VirtualMachineTemplate * tmpl;
|
||||
VirtualMachineTemplate extended_tmpl;
|
||||
VirtualMachineTemplate uattrs;
|
||||
VMTemplate * rtmpl;
|
||||
|
||||
vector<Template *> ds_quotas;
|
||||
vector<Template *> applied;
|
||||
vector<Template *>::iterator it;
|
||||
|
||||
string aname;
|
||||
string tmpl_name;
|
||||
@ -150,20 +149,18 @@ Request::ErrorCode VMTemplateInstantiate::request_execute(int id, string name,
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Get, check and clone the template */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
rtmpl = tpool->get_ro(id);
|
||||
|
||||
if ( rtmpl == 0 )
|
||||
if ( auto rtmpl = tpool->get_ro(id) )
|
||||
{
|
||||
att.resp_id = id;
|
||||
return NO_EXISTS;
|
||||
}
|
||||
|
||||
tmpl_name = rtmpl->get_name();
|
||||
tmpl = rtmpl->clone_template();
|
||||
|
||||
rtmpl->get_permissions(perms);
|
||||
|
||||
rtmpl->unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
att.resp_id = id;
|
||||
return NO_EXISTS;
|
||||
}
|
||||
|
||||
ErrorCode ec = merge(tmpl, str_uattrs, att);
|
||||
|
||||
@ -173,7 +170,7 @@ Request::ErrorCode VMTemplateInstantiate::request_execute(int id, string name,
|
||||
return ec;
|
||||
}
|
||||
|
||||
if ( extra_attrs != 0 )
|
||||
if ( extra_attrs != nullptr )
|
||||
{
|
||||
tmpl->merge(extra_attrs);
|
||||
}
|
||||
@ -259,9 +256,9 @@ Request::ErrorCode VMTemplateInstantiate::request_execute(int id, string name,
|
||||
|
||||
VirtualMachineDisks::image_ds_quotas(&extended_tmpl, ds_quotas);
|
||||
|
||||
for ( it = ds_quotas.begin() ; it != ds_quotas.end() ; ++it )
|
||||
for ( auto ds : ds_quotas )
|
||||
{
|
||||
if ( quota_authorization(*it, Quotas::DATASTORE, att, att.resp_msg)
|
||||
if ( quota_authorization(ds, Quotas::DATASTORE, att, att.resp_msg)
|
||||
== false )
|
||||
{
|
||||
ds_quota_auth = false;
|
||||
@ -269,7 +266,7 @@ Request::ErrorCode VMTemplateInstantiate::request_execute(int id, string name,
|
||||
}
|
||||
else
|
||||
{
|
||||
applied.push_back(*it);
|
||||
applied.push_back(ds);
|
||||
}
|
||||
}
|
||||
|
||||
@ -277,14 +274,14 @@ Request::ErrorCode VMTemplateInstantiate::request_execute(int id, string name,
|
||||
{
|
||||
quota_rollback(&extended_tmpl, Quotas::VIRTUALMACHINE, att);
|
||||
|
||||
for ( it = applied.begin() ; it != applied.end() ; ++it )
|
||||
for ( auto ds : applied )
|
||||
{
|
||||
quota_rollback(*it, Quotas::DATASTORE, att);
|
||||
quota_rollback(ds, Quotas::DATASTORE, att);
|
||||
}
|
||||
|
||||
for ( it = ds_quotas.begin() ; it != ds_quotas.end() ; ++it )
|
||||
for ( auto ds : ds_quotas )
|
||||
{
|
||||
delete *it;
|
||||
delete ds;
|
||||
}
|
||||
|
||||
delete tmpl;
|
||||
@ -299,18 +296,18 @@ Request::ErrorCode VMTemplateInstantiate::request_execute(int id, string name,
|
||||
{
|
||||
quota_rollback(&extended_tmpl, Quotas::VIRTUALMACHINE, att);
|
||||
|
||||
for ( it = ds_quotas.begin() ; it != ds_quotas.end() ; ++it )
|
||||
for ( auto ds : ds_quotas )
|
||||
{
|
||||
quota_rollback(*it, Quotas::DATASTORE, att);
|
||||
delete *it;
|
||||
quota_rollback(ds, Quotas::DATASTORE, att);
|
||||
delete ds;
|
||||
}
|
||||
|
||||
return ALLOCATE;
|
||||
}
|
||||
|
||||
for ( it = ds_quotas.begin() ; it != ds_quotas.end() ; ++it )
|
||||
for ( auto ds : ds_quotas )
|
||||
{
|
||||
delete *it;
|
||||
delete ds;
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
|
@ -49,20 +49,17 @@ void VNTemplateInstantiate::request_execute(xmlrpc_c::paramList const& paramList
|
||||
string name = xmlrpc_c::value_string(paramList.getString(2));
|
||||
string str_uattrs = xmlrpc_c::value_string(paramList.getString(3));
|
||||
|
||||
|
||||
VNTemplate * tmpl = static_cast<VNTemplatePool* > (pool)->get_ro(id);
|
||||
|
||||
if ( tmpl == 0 )
|
||||
if ( auto tmpl = pool->get_ro<VNTemplate>(id) )
|
||||
{
|
||||
string original_tmpl_name = tmpl->get_name();
|
||||
}
|
||||
else
|
||||
{
|
||||
att.resp_id = id;
|
||||
failure_response(NO_EXISTS, att);
|
||||
return;
|
||||
}
|
||||
|
||||
string original_tmpl_name = tmpl->get_name();
|
||||
|
||||
tmpl->unlock();
|
||||
|
||||
int instantiate_id = id;
|
||||
|
||||
int vid;
|
||||
@ -99,38 +96,30 @@ Request::ErrorCode VNTemplateInstantiate::request_execute(int id, string name,
|
||||
|
||||
VirtualNetworkTemplate * tmpl;
|
||||
VirtualNetworkTemplate extended_tmpl;
|
||||
VNTemplate * rtmpl;
|
||||
|
||||
string tmpl_name;
|
||||
|
||||
string cluster_ids_str;
|
||||
set<int> cluster_ids;
|
||||
set<int>::iterator clusters_it;
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Get, check and clone the template */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
rtmpl = vntpool->get_ro(id);
|
||||
|
||||
if ( rtmpl == 0 )
|
||||
if ( auto rtmpl = vntpool->get_ro(id) )
|
||||
{
|
||||
att.resp_id = id;
|
||||
return NO_EXISTS;
|
||||
}
|
||||
|
||||
tmpl_name = rtmpl->get_name();
|
||||
tmpl = rtmpl->clone_template();
|
||||
|
||||
rtmpl->get_permissions(perms);
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Get network clusters */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
rtmpl->get_template_attribute("CLUSTER_IDS", cluster_ids_str);
|
||||
|
||||
rtmpl->unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
att.resp_id = id;
|
||||
return NO_EXISTS;
|
||||
}
|
||||
|
||||
if (!cluster_ids_str.empty())
|
||||
{
|
||||
@ -197,21 +186,13 @@ Request::ErrorCode VNTemplateInstantiate::request_execute(int id, string name,
|
||||
return ALLOCATE;
|
||||
}
|
||||
|
||||
for (clusters_it = cluster_ids.begin(); clusters_it != cluster_ids.end(); ++clusters_it)
|
||||
for (auto cid : cluster_ids)
|
||||
{
|
||||
Cluster* cluster;
|
||||
string str_error;
|
||||
|
||||
cluster = clpool->get(*clusters_it);
|
||||
|
||||
if (cluster == 0)
|
||||
if ( auto cluster = clpool->get(cid) )
|
||||
{
|
||||
continue;
|
||||
string _er;
|
||||
clpool->add_to_cluster(PoolObjectSQL::NET, cluster.get(), vid, _er);
|
||||
}
|
||||
|
||||
clpool->add_to_cluster(PoolObjectSQL::NET, cluster, vid, str_error);
|
||||
|
||||
cluster->unlock();
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
@ -225,8 +206,6 @@ Request::ErrorCode VNTemplateInstantiate::merge(
|
||||
const string &str_uattrs,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
|
||||
|
||||
int rc;
|
||||
|
||||
VirtualNetworkTemplate uattrs;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user