mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-18 19:02:53 +09:00
Merge branch 'feature-203' of opennebula.org:one into feature-203
This commit is contained in:
commit
605fb638a4
27 files changed
+677
-487
No files matched your search
+46
-56
@@ -55,7 +55,7 @@ public:
|
||||
* Triggers specific actions to the Dispatch Manager. This function
|
||||
* wraps the ActionManager trigger function.
|
||||
* @param action the DM action
|
||||
* @param vid VM unique id. This is the argument of the passed to the
|
||||
* @param vid VM unique id. This is the argument of the passed to the
|
||||
* invoked action.
|
||||
*/
|
||||
void trigger(
|
||||
@@ -63,12 +63,12 @@ public:
|
||||
int _vid);
|
||||
|
||||
/**
|
||||
* This functions creates a new thread for the Dispatch Manager. This
|
||||
* This functions creates a new thread for the Dispatch Manager. This
|
||||
* thread will wait in an action loop till it receives ACTION_FINALIZE.
|
||||
* @return 0 on success.
|
||||
*/
|
||||
int start();
|
||||
|
||||
|
||||
/**
|
||||
* Gets the thread identification.
|
||||
* @return pthread_t for the manager thread (that in the action loop).
|
||||
@@ -81,132 +81,122 @@ public:
|
||||
//--------------------------------------------------------------------------
|
||||
// DM Actions, the RM and the Scheduler will invoke this methods
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Allocates a new virtual machine
|
||||
* @return 0 on success
|
||||
*/
|
||||
int allocate (
|
||||
int uid,
|
||||
const string& stemplate,
|
||||
int * oid);
|
||||
|
||||
/**
|
||||
* Deploys a VM. A new history record MUST be added before calling this
|
||||
* function. Also the VM MUST have its mutex locked. If the function fails
|
||||
* the calling funtion is responsible for recovering from the error.
|
||||
* @param vm pointer to a VirtualMachine with its mutex locked.
|
||||
* @return 0 on success
|
||||
* @return 0 on success
|
||||
*/
|
||||
int deploy (
|
||||
VirtualMachine * vm);
|
||||
|
||||
/**
|
||||
* Migrates a VM. The following actions must be performed before calling
|
||||
* this function:
|
||||
* Migrates a VM. The following actions must be performed before calling
|
||||
* this function:
|
||||
* - Lock the VM mutex.
|
||||
* - Update the History statistics of the current host.
|
||||
* - Add a new History record with the new host.
|
||||
* If the function fails the calling funtion is responsible for recovering
|
||||
* - Add a new History record with the new host.
|
||||
* If the function fails the calling funtion is responsible for recovering
|
||||
* from the error.
|
||||
* @param vm pointer to a VirtualMachine with its mutex locked.
|
||||
* @return 0 on success
|
||||
* @return 0 on success
|
||||
*/
|
||||
int migrate(
|
||||
VirtualMachine * vm);
|
||||
|
||||
/**
|
||||
* Migrates a VM. The following actions must be performed before calling
|
||||
* this function:
|
||||
* Migrates a VM. The following actions must be performed before calling
|
||||
* this function:
|
||||
* - Lock the VM mutex.
|
||||
* - Update the History statistics of the current host.
|
||||
* - Add a new History record with the new host.
|
||||
* If the function fails the calling funtion is responsible for recovering
|
||||
* - Add a new History record with the new host.
|
||||
* If the function fails the calling funtion is responsible for recovering
|
||||
* from the error.
|
||||
* @param vm pointer to a VirtualMachine with its mutex locked.
|
||||
* @return 0 on success
|
||||
* @return 0 on success
|
||||
*/
|
||||
int live_migrate(
|
||||
VirtualMachine * vm);
|
||||
|
||||
|
||||
/**
|
||||
* Shuts down a VM.
|
||||
* @param vid VirtualMachine identification
|
||||
* @return 0 on success, -1 if the VM does not exits or -2 if the VM is
|
||||
* in a wrong a state
|
||||
*/
|
||||
* @return 0 on success, -1 if the VM does not exits or -2 if the VM is
|
||||
* in a wrong a state
|
||||
*/
|
||||
int shutdown (
|
||||
int vid);
|
||||
|
||||
/**
|
||||
* Holds a VM.
|
||||
* @param vid VirtualMachine identification
|
||||
* @return 0 on success, -1 if the VM does not exits or -2 if the VM is
|
||||
* in a wrong a state
|
||||
*/
|
||||
* @return 0 on success, -1 if the VM does not exits or -2 if the VM is
|
||||
* in a wrong a state
|
||||
*/
|
||||
int hold(
|
||||
int vid);
|
||||
|
||||
/**
|
||||
* Releases a VM.
|
||||
* @param vid VirtualMachine identification
|
||||
* @return 0 on success, -1 if the VM does not exits or -2 if the VM is
|
||||
* in a wrong a state
|
||||
*/
|
||||
* @return 0 on success, -1 if the VM does not exits or -2 if the VM is
|
||||
* in a wrong a state
|
||||
*/
|
||||
int release(
|
||||
int vid);
|
||||
|
||||
/**
|
||||
* Stops a VM.
|
||||
* @param vid VirtualMachine identification
|
||||
* @return 0 on success, -1 if the VM does not exits or -2 if the VM is
|
||||
* in a wrong a state
|
||||
*/
|
||||
* @return 0 on success, -1 if the VM does not exits or -2 if the VM is
|
||||
* in a wrong a state
|
||||
*/
|
||||
int stop(
|
||||
int vid);
|
||||
|
||||
/**
|
||||
* Cancels a VM.
|
||||
* @param vid VirtualMachine identification
|
||||
* @return 0 on success, -1 if the VM does not exits or -2 if the VM is
|
||||
* in a wrong a state
|
||||
*/
|
||||
* @return 0 on success, -1 if the VM does not exits or -2 if the VM is
|
||||
* in a wrong a state
|
||||
*/
|
||||
int cancel(
|
||||
int vid);
|
||||
|
||||
/**
|
||||
* Suspends a VM.
|
||||
* @param vid VirtualMachine identification
|
||||
* @return 0 on success, -1 if the VM does not exits or -2 if the VM is
|
||||
* in a wrong a state
|
||||
*/
|
||||
* @return 0 on success, -1 if the VM does not exits or -2 if the VM is
|
||||
* in a wrong a state
|
||||
*/
|
||||
int suspend(
|
||||
int vid);
|
||||
|
||||
/**
|
||||
* Resumes a VM.
|
||||
* @param vid VirtualMachine identification
|
||||
* @return 0 on success, -1 if the VM does not exits or -2 if the VM is
|
||||
* in a wrong a state
|
||||
*/
|
||||
* @return 0 on success, -1 if the VM does not exits or -2 if the VM is
|
||||
* in a wrong a state
|
||||
*/
|
||||
int resume(
|
||||
int vid);
|
||||
|
||||
|
||||
/**
|
||||
* Restart a previusly deployed VM.
|
||||
* @param vid VirtualMachine identification
|
||||
* @return 0 on success, -1 if the VM does not exits or -2 if the VM is
|
||||
* in a wrong a state
|
||||
*/
|
||||
* @return 0 on success, -1 if the VM does not exits or -2 if the VM is
|
||||
* in a wrong a state
|
||||
*/
|
||||
int restart(
|
||||
int vid);
|
||||
|
||||
/**
|
||||
* Ends a VM life cycle inside ONE.
|
||||
* @param vid VirtualMachine identification
|
||||
* @return 0 on success, -1 if the VM does not exits or -2 if the VM is
|
||||
* in a wrong a state
|
||||
*/
|
||||
* @return 0 on success, -1 if the VM does not exits or -2 if the VM is
|
||||
* in a wrong a state
|
||||
*/
|
||||
int finalize(
|
||||
int vid);
|
||||
|
||||
@@ -232,7 +222,7 @@ private:
|
||||
ActionManager am;
|
||||
|
||||
/**
|
||||
* Function to execute the Manager action loop method within a new pthread
|
||||
* Function to execute the Manager action loop method within a new pthread
|
||||
* (requires C linkage)
|
||||
*/
|
||||
friend void * dm_action_loop(void *arg);
|
||||
@@ -249,14 +239,14 @@ private:
|
||||
//--------------------------------------------------------------------------
|
||||
// DM Actions associated with a VM state transition
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
|
||||
void suspend_success_action(int vid);
|
||||
|
||||
void stop_success_action(int vid);
|
||||
|
||||
void done_action(int vid);
|
||||
|
||||
void failed_action(int vid);
|
||||
void failed_action(int vid);
|
||||
};
|
||||
|
||||
#endif /*DISPATCH_MANAGER_H*/
|
||||
|
||||
+7
-7
@@ -221,7 +221,7 @@ public:
|
||||
string& name,
|
||||
vector<const Attribute*>& values) const
|
||||
{
|
||||
return image_template.get(name,values);
|
||||
return image_template->get(name,values);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -235,7 +235,7 @@ public:
|
||||
vector<const Attribute*>& values) const
|
||||
{
|
||||
string str=name;
|
||||
return image_template.get(str,values);
|
||||
return image_template->get(str,values);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -248,7 +248,7 @@ public:
|
||||
string& value) const
|
||||
{
|
||||
string str=name;
|
||||
image_template.get(str,value);
|
||||
image_template->get(str,value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -261,7 +261,7 @@ public:
|
||||
int& value) const
|
||||
{
|
||||
string str=name;
|
||||
image_template.get(str,value);
|
||||
image_template->get(str,value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -270,7 +270,7 @@ public:
|
||||
*/
|
||||
int remove_template_attribute(SqlDB * db, const string& name)
|
||||
{
|
||||
return image_template.remove_attribute(db, name);
|
||||
return image_template->remove_attribute(db, name);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -332,7 +332,7 @@ private:
|
||||
/**
|
||||
* The Image template, holds the Image attributes.
|
||||
*/
|
||||
ImageTemplate image_template;
|
||||
ImageTemplate * image_template;
|
||||
|
||||
|
||||
// *************************************************************************
|
||||
@@ -382,7 +382,7 @@ protected:
|
||||
// Constructor
|
||||
// *************************************************************************
|
||||
|
||||
Image(int id=-1);
|
||||
Image(int uid=-1, ImageTemplate *img_template = 0);
|
||||
|
||||
virtual ~Image();
|
||||
|
||||
|
||||
+15
-8
@@ -27,10 +27,10 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class AuthRequest;
|
||||
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
* The Image Pool class.
|
||||
*/
|
||||
@@ -55,9 +55,9 @@ public:
|
||||
* -2 in case of template parse failure
|
||||
*/
|
||||
int allocate (
|
||||
int uid,
|
||||
const string& stemplate,
|
||||
int * oid);
|
||||
int uid,
|
||||
ImageTemplate * img_template,
|
||||
int * oid);
|
||||
|
||||
/**
|
||||
* Function to get a Image from the pool, if the object is not in memory
|
||||
@@ -133,7 +133,7 @@ public:
|
||||
{
|
||||
SingleAttribute * sattr = new SingleAttribute(name,value);
|
||||
|
||||
return image->image_template.replace_attribute(db,sattr);
|
||||
return image->image_template->replace_attribute(db,sattr);
|
||||
}
|
||||
|
||||
/** Delete an image attribute in the template (Image MUST be locked)
|
||||
@@ -145,7 +145,7 @@ public:
|
||||
Image * image,
|
||||
const string& name)
|
||||
{
|
||||
return image->image_template.remove_attribute(db, name);
|
||||
return image->image_template->remove_attribute(db, name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -170,7 +170,14 @@ public:
|
||||
* @param disk the disk to be generated
|
||||
* @return 0 on success, -1 error, -2 not using the pool
|
||||
*/
|
||||
int disk_attribute(VectorAttribute * disk, int * index, AuthRequest * ar);
|
||||
int disk_attribute(VectorAttribute * disk, int * index);
|
||||
|
||||
/**
|
||||
* Generates an Authorization token for the DISK attribute
|
||||
* @param disk the disk to be authorized
|
||||
* @param ar the AuthRequest
|
||||
*/
|
||||
void authorize_disk(VectorAttribute * disk, AuthRequest * ar);
|
||||
|
||||
static const string& source_prefix()
|
||||
{
|
||||
|
||||
@@ -184,7 +184,7 @@ private:
|
||||
<< " to perform " << action << " on " << object;
|
||||
|
||||
|
||||
if ( id != (int)NULL )
|
||||
if ( id != -1 )
|
||||
{
|
||||
oss << " [" << id << "].";
|
||||
}
|
||||
@@ -215,7 +215,7 @@ private:
|
||||
oss << "[" << method << "]" << " Error getting " <<
|
||||
object;
|
||||
|
||||
if ( id != (int)NULL )
|
||||
if ( id != -1 )
|
||||
{
|
||||
oss << " [" << id << "].";
|
||||
}
|
||||
@@ -237,19 +237,24 @@ private:
|
||||
|
||||
oss << "[" << method << "]" << " Error trying to " << action << " "
|
||||
<< object;
|
||||
|
||||
if ( id != (int)NULL )
|
||||
|
||||
switch(id)
|
||||
{
|
||||
oss << " [" << id << "].";
|
||||
case -2:
|
||||
break;
|
||||
case -1:
|
||||
oss << "Pool.";
|
||||
break;
|
||||
default:
|
||||
oss << " [" << id << "].";
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if ( rc != (int)NULL )
|
||||
{
|
||||
oss << " .Returned error code [" << rc << "].";
|
||||
oss << " Returned error code [" << rc << "].";
|
||||
}
|
||||
|
||||
NebulaLog::log("RM",Log::ERROR,oss);
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
|
||||
+11
-13
@@ -31,8 +31,6 @@ using namespace std;
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
class AuthRequest;
|
||||
|
||||
/**
|
||||
* The Virtual Machine class. It represents a VM...
|
||||
*/
|
||||
@@ -555,7 +553,7 @@ public:
|
||||
string& name,
|
||||
vector<const Attribute*>& values) const
|
||||
{
|
||||
return vm_template.get(name,values);
|
||||
return vm_template->get(name,values);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -569,7 +567,7 @@ public:
|
||||
vector<const Attribute*>& values) const
|
||||
{
|
||||
string str=name;
|
||||
return vm_template.get(str,values);
|
||||
return vm_template->get(str,values);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -583,7 +581,7 @@ public:
|
||||
string& value) const
|
||||
{
|
||||
string str=name;
|
||||
vm_template.get(str,value);
|
||||
vm_template->get(str,value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -597,7 +595,7 @@ public:
|
||||
int& value) const
|
||||
{
|
||||
string str=name;
|
||||
vm_template.get(str,value);
|
||||
vm_template->get(str,value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -606,7 +604,7 @@ public:
|
||||
*/
|
||||
void template_to_xml(string &xml) const
|
||||
{
|
||||
vm_template.to_xml(xml);
|
||||
vm_template->to_xml(xml);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -704,7 +702,7 @@ public:
|
||||
* Get all network leases for this Virtual Machine
|
||||
* @return 0 if success
|
||||
*/
|
||||
int get_network_leases(AuthRequest *ar);
|
||||
int get_network_leases();
|
||||
|
||||
/**
|
||||
* Releases all network leases taken by this Virtual Machine
|
||||
@@ -715,7 +713,7 @@ public:
|
||||
* Get all disk images for this Virtual Machine
|
||||
* @return 0 if success
|
||||
*/
|
||||
int get_disk_images(AuthRequest *ar);
|
||||
int get_disk_images();
|
||||
|
||||
/**
|
||||
* Releases all disk images taken by this Virtual Machine
|
||||
@@ -773,7 +771,7 @@ private:
|
||||
/**
|
||||
* The Virtual Machine template, holds the VM attributes.
|
||||
*/
|
||||
VirtualMachineTemplate vm_template;
|
||||
VirtualMachineTemplate* vm_template;
|
||||
|
||||
// Dynamic state of the Virtual Machine
|
||||
|
||||
@@ -932,7 +930,7 @@ private:
|
||||
int rc;
|
||||
|
||||
sattr = new SingleAttribute(name,value);
|
||||
rc = vm_template.replace_attribute(db,sattr);
|
||||
rc = vm_template->replace_attribute(db,sattr);
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
@@ -951,7 +949,7 @@ private:
|
||||
*/
|
||||
int insert_template_attribute(SqlDB * db, Attribute * attribute)
|
||||
{
|
||||
return vm_template.insert_attribute(db,attribute);
|
||||
return vm_template->insert_attribute(db,attribute);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
@@ -989,7 +987,7 @@ protected:
|
||||
// Constructor
|
||||
//**************************************************************************
|
||||
|
||||
VirtualMachine(int id=-1);
|
||||
VirtualMachine(int id=-1, VirtualMachineTemplate * _vm_template = 0);
|
||||
|
||||
virtual ~VirtualMachine();
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
/**
|
||||
* Function to allocate a new VM object
|
||||
* @param uid user id (the owner of the VM)
|
||||
* @param stemplate a string describing the VM
|
||||
* @param vm_template a VM Template object describing the VM
|
||||
* @param oid the id assigned to the VM (output)
|
||||
* @param on_hold flag to submit on hold
|
||||
* @return oid on success, -1 error inserting in DB or -2 error parsing
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
*/
|
||||
int allocate (
|
||||
int uid,
|
||||
const string& stemplate,
|
||||
VirtualMachineTemplate *vm_template,
|
||||
int * oid,
|
||||
bool on_hold = false);
|
||||
|
||||
@@ -99,9 +99,9 @@ public:
|
||||
* @return 0 on success
|
||||
*/
|
||||
int update_template_attribute(
|
||||
VirtualMachine * vm,
|
||||
string& name,
|
||||
string& value)
|
||||
VirtualMachine * vm,
|
||||
string& name,
|
||||
string& value)
|
||||
{
|
||||
return vm->update_template_attribute(db,name,value);
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ public:
|
||||
string& name,
|
||||
vector<const Attribute*>& values) const
|
||||
{
|
||||
return vn_template.get(name,values);
|
||||
return vn_template->get(name,values);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -209,7 +209,7 @@ public:
|
||||
vector<const Attribute*>& values) const
|
||||
{
|
||||
string str=name;
|
||||
return vn_template.get(str,values);
|
||||
return vn_template->get(str,values);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -222,7 +222,7 @@ public:
|
||||
string& value) const
|
||||
{
|
||||
string str=name;
|
||||
vn_template.get(str,value);
|
||||
vn_template->get(str,value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -235,7 +235,7 @@ public:
|
||||
int& value) const
|
||||
{
|
||||
string str=name;
|
||||
vn_template.get(str,value);
|
||||
vn_template->get(str,value);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -293,7 +293,7 @@ private:
|
||||
/**
|
||||
* The Virtual Network template, holds the VNW attributes.
|
||||
*/
|
||||
VirtualNetworkTemplate vn_template;
|
||||
VirtualNetworkTemplate * vn_template;
|
||||
|
||||
// *************************************************************************
|
||||
// DataBase implementation (Private)
|
||||
@@ -355,7 +355,7 @@ private:
|
||||
int rc;
|
||||
|
||||
sattr = new SingleAttribute(name,value);
|
||||
rc = vn_template.replace_attribute(db,sattr);
|
||||
rc = vn_template->replace_attribute(db,sattr);
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
@@ -371,7 +371,7 @@ protected:
|
||||
// Constructor
|
||||
//**************************************************************************
|
||||
|
||||
VirtualNetwork();
|
||||
VirtualNetwork(VirtualNetworkTemplate * _vn_template = 0);
|
||||
|
||||
~VirtualNetwork();
|
||||
|
||||
@@ -428,7 +428,7 @@ protected:
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = vn_template.drop(db);
|
||||
rc = vn_template->drop(db);
|
||||
|
||||
rc += leases->drop(db);
|
||||
|
||||
|
||||
@@ -22,10 +22,10 @@
|
||||
|
||||
#include <time.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class AuthRequest;
|
||||
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
* The Virtual Network Pool class. ...
|
||||
*/
|
||||
@@ -40,16 +40,15 @@ public:
|
||||
~VirtualNetworkPool(){};
|
||||
|
||||
/**
|
||||
* Function to allocate a new VN object
|
||||
* Function to allocate a new VNET object
|
||||
* @param uid user identifier
|
||||
* @param stemplate a string describing the VN
|
||||
* @param vn_template a VirtualNetworkTemplate describing the VNET
|
||||
* @param oid the id assigned to the VM (output)
|
||||
* @return oid on success, -1 error inserting in DB,-2 error parsing
|
||||
* the template, -3 wrong attributes in template
|
||||
* @return oid on success, -1 error
|
||||
*/
|
||||
int allocate (
|
||||
int uid,
|
||||
const string& stemplate,
|
||||
VirtualNetworkTemplate * vn_template,
|
||||
int * oid);
|
||||
|
||||
/**
|
||||
@@ -88,7 +87,14 @@ public:
|
||||
* @param vid of the VM requesting the lease
|
||||
* @return 0 on success, -1 error, -2 not using the pool
|
||||
*/
|
||||
int nic_attribute(VectorAttribute * nic, int vid, AuthRequest *ar);
|
||||
int nic_attribute(VectorAttribute * nic, int vid);
|
||||
|
||||
/**
|
||||
* Generates an Authorization token for a NIC attribute
|
||||
* @param nic the nic to be authorized
|
||||
* @param ar the AuthRequest
|
||||
*/
|
||||
void authorize_nic(VectorAttribute * nic, AuthRequest * ar);
|
||||
|
||||
/**
|
||||
* Updates the template of a VN, adding a new attribute (replacing it if
|
||||
|
||||
@@ -18,18 +18,6 @@
|
||||
#include "NebulaLog.h"
|
||||
|
||||
#include "Nebula.h"
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int DispatchManager::allocate (
|
||||
int uid,
|
||||
const string& stemplate,
|
||||
int * oid)
|
||||
{
|
||||
NebulaLog::log("DiM",Log::DEBUG,"Allocating a new VM");
|
||||
|
||||
return vmpool->allocate(uid,stemplate,oid);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
+32
-45
@@ -32,7 +32,7 @@
|
||||
/* Image :: Constructor/Destructor */
|
||||
/* ************************************************************************ */
|
||||
|
||||
Image::Image(int _uid):
|
||||
Image::Image(int _uid, ImageTemplate * _image_template):
|
||||
PoolObjectSQL(-1),
|
||||
uid(_uid),
|
||||
name(""),
|
||||
@@ -41,9 +41,24 @@ Image::Image(int _uid):
|
||||
source(""),
|
||||
state(INIT),
|
||||
running_vms(0)
|
||||
{};
|
||||
{
|
||||
if (_image_template != 0)
|
||||
{
|
||||
image_template = _image_template;
|
||||
}
|
||||
else
|
||||
{
|
||||
image_template = new ImageTemplate;
|
||||
}
|
||||
};
|
||||
|
||||
Image::~Image(){};
|
||||
Image::~Image()
|
||||
{
|
||||
if (image_template != 0)
|
||||
{
|
||||
delete image_template;
|
||||
}
|
||||
};
|
||||
|
||||
/* ************************************************************************ */
|
||||
/* Image :: Database Access Functions */
|
||||
@@ -93,7 +108,7 @@ int Image::select_cb(void * nil, int num, char **values, char ** names)
|
||||
|
||||
running_vms = atoi(values[RUNNING_VMS]);
|
||||
|
||||
image_template.id = oid;
|
||||
image_template->id = oid;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -123,7 +138,7 @@ int Image::select(SqlDB *db)
|
||||
|
||||
// Get the template
|
||||
|
||||
rc = image_template.select(db);
|
||||
rc = image_template->select(db);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
@@ -182,7 +197,7 @@ int Image::insert(SqlDB *db)
|
||||
// ------------ PUBLIC --------------------
|
||||
|
||||
get_template_attribute("PUBLIC", public_attr);
|
||||
image_template.erase("PUBLIC");
|
||||
image_template->erase("PUBLIC");
|
||||
|
||||
transform (public_attr.begin(), public_attr.end(), public_attr.begin(),
|
||||
(int(*)(int))toupper);
|
||||
@@ -198,7 +213,7 @@ int Image::insert(SqlDB *db)
|
||||
SingleAttribute * dev_att = new SingleAttribute("DEV_PREFIX",
|
||||
ImagePool::default_dev_prefix());
|
||||
|
||||
image_template.set(dev_att);
|
||||
image_template->set(dev_att);
|
||||
}
|
||||
|
||||
// ------------ SOURCE (path to store the image)--------------------
|
||||
@@ -210,37 +225,16 @@ int Image::insert(SqlDB *db)
|
||||
|
||||
source = tmp_sourcestream.str();
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Authorize this request
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( uid != 0 ) // uid == 0 means oneadmin
|
||||
{
|
||||
string t64;
|
||||
AuthRequest ar(uid);
|
||||
|
||||
ar.add_auth(AuthRequest::IMAGE,
|
||||
image_template.to_xml(t64),
|
||||
AuthRequest::CREATE,
|
||||
uid,
|
||||
public_img);
|
||||
|
||||
if (UserPool::authorize(ar) == -1)
|
||||
{
|
||||
goto error_authorize;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------ INSERT THE TEMPLATE --------------------
|
||||
|
||||
if ( image_template.id == -1 )
|
||||
if ( image_template->id == -1 )
|
||||
{
|
||||
image_template.id = oid;
|
||||
image_template->id = oid;
|
||||
}
|
||||
|
||||
state = DISABLED;
|
||||
|
||||
rc = image_template.insert(db);
|
||||
rc = image_template->insert(db);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
@@ -255,7 +249,7 @@ int Image::insert(SqlDB *db)
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
image_template.drop(db);
|
||||
image_template->drop(db);
|
||||
|
||||
return rc;
|
||||
}
|
||||
@@ -270,10 +264,6 @@ error_type:
|
||||
NebulaLog::log("IMG", Log::ERROR, "Incorrect TYPE in image template");
|
||||
goto error_common;
|
||||
|
||||
error_authorize:
|
||||
NebulaLog::log("IMG", Log::ERROR, "Error authorizing Image creation");
|
||||
goto error_common;
|
||||
|
||||
error_common:
|
||||
return -1;
|
||||
}
|
||||
@@ -399,7 +389,7 @@ int Image::drop(SqlDB * db)
|
||||
return -1;
|
||||
}
|
||||
|
||||
image_template.drop(db);
|
||||
image_template->drop(db);
|
||||
|
||||
oss << "DELETE FROM " << table << " WHERE oid=" << oid;
|
||||
|
||||
@@ -449,7 +439,7 @@ string& Image::to_xml(string& xml) const
|
||||
"<SOURCE>" << source << "</SOURCE>" <<
|
||||
"<STATE>" << state << "</STATE>" <<
|
||||
"<RUNNING_VMS>" << running_vms << "</RUNNING_VMS>" <<
|
||||
image_template.to_xml(template_xml) <<
|
||||
image_template->to_xml(template_xml) <<
|
||||
"</IMAGE>";
|
||||
|
||||
xml = oss.str();
|
||||
@@ -477,7 +467,7 @@ string& Image::to_str(string& str) const
|
||||
"STATE = " << state << endl <<
|
||||
"RUNNING_VMS = " << running_vms << endl <<
|
||||
"TEMPLATE" << endl
|
||||
<< image_template.to_str(template_str)
|
||||
<< image_template->to_str(template_str)
|
||||
<< endl;
|
||||
|
||||
str = os.str();
|
||||
@@ -560,12 +550,10 @@ int Image::disk_attribute(VectorAttribute * disk, int * index)
|
||||
{
|
||||
string overwrite;
|
||||
string saveas;
|
||||
string name;
|
||||
string bus;
|
||||
|
||||
ostringstream iid;
|
||||
|
||||
name = disk->vector_value("NAME");
|
||||
overwrite = disk->vector_value("OVERWRITE");
|
||||
saveas = disk->vector_value("SAVE_AS");
|
||||
bus = disk->vector_value("BUS");
|
||||
@@ -595,10 +583,9 @@ int Image::disk_attribute(VectorAttribute * disk, int * index)
|
||||
|
||||
map<string,string> new_disk;
|
||||
|
||||
new_disk.insert(make_pair("NAME",name));
|
||||
new_disk.insert(make_pair("IID", iid.str()));
|
||||
|
||||
new_disk.insert(make_pair("SOURCE", source));
|
||||
new_disk.insert(make_pair("IMAGE", name));
|
||||
new_disk.insert(make_pair("IMAGE_ID", iid.str()));
|
||||
new_disk.insert(make_pair("SOURCE", source));
|
||||
|
||||
if (!overwrite.empty())
|
||||
{
|
||||
|
||||
+76
-41
@@ -89,55 +89,31 @@ ImagePool::ImagePool( SqlDB * db,
|
||||
|
||||
int ImagePool::allocate (
|
||||
int uid,
|
||||
const string& stemplate,
|
||||
ImageTemplate* img_template,
|
||||
int * oid)
|
||||
{
|
||||
int rc;
|
||||
Image * img;
|
||||
|
||||
string name;
|
||||
char * error_msg;
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Build a new Image object
|
||||
// ---------------------------------------------------------------------
|
||||
img = new Image(uid);
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Parse template
|
||||
// ---------------------------------------------------------------------
|
||||
rc = img->image_template.parse(stemplate, &error_msg);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "ImagePool template parse error: " << error_msg;
|
||||
NebulaLog::log("IMG", Log::ERROR, oss);
|
||||
|
||||
free(error_msg);
|
||||
delete img;
|
||||
|
||||
return -1;
|
||||
}
|
||||
img = new Image(uid,img_template);
|
||||
|
||||
img->get_template_attribute("NAME", name);
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Insert the Object in the pool
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
*oid = PoolSQL::allocate(img);
|
||||
|
||||
if ( *oid == -1 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Add the image name to the map of image_names
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
image_names.insert(make_pair(name, *oid));
|
||||
if ( *oid != -1 )
|
||||
{
|
||||
image_names.insert(make_pair(name, *oid));
|
||||
}
|
||||
|
||||
return *oid;
|
||||
}
|
||||
@@ -189,21 +165,37 @@ int ImagePool::dump(ostringstream& oss, const string& where)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int ImagePool::disk_attribute(VectorAttribute * disk,
|
||||
int * index,
|
||||
AuthRequest * ar)
|
||||
int ImagePool::disk_attribute(VectorAttribute * disk, int * index)
|
||||
{
|
||||
string source;
|
||||
Image * img;
|
||||
Image * img = 0;
|
||||
|
||||
source = disk->vector_value("NAME");
|
||||
source = disk->vector_value("IMAGE");
|
||||
|
||||
if (source.empty())
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
istringstream is;
|
||||
int image_id;
|
||||
|
||||
img = get(source,true);
|
||||
source = disk->vector_value("IMAGE_ID");
|
||||
|
||||
if (source.empty())
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
|
||||
is.str(source);
|
||||
is >> image_id;
|
||||
|
||||
if( !is.fail() )
|
||||
{
|
||||
img = get(image_id,true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
img = get(source,true);
|
||||
}
|
||||
|
||||
if (img == 0)
|
||||
{
|
||||
@@ -212,6 +204,51 @@ int ImagePool::disk_attribute(VectorAttribute * disk,
|
||||
|
||||
int rc = img->disk_attribute(disk,index);
|
||||
|
||||
img->unlock();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void ImagePool::authorize_disk(VectorAttribute * disk, AuthRequest * ar)
|
||||
{
|
||||
string source;
|
||||
Image * img = 0;
|
||||
|
||||
source = disk->vector_value("IMAGE");
|
||||
|
||||
if (source.empty())
|
||||
{
|
||||
istringstream is;
|
||||
int image_id;
|
||||
|
||||
source = disk->vector_value("IMAGE_ID");
|
||||
|
||||
if (source.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
is.str(source);
|
||||
is >> image_id;
|
||||
|
||||
if( !is.fail() )
|
||||
{
|
||||
img = get(image_id,true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
img = get(source,true);
|
||||
}
|
||||
|
||||
if (img == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ar->add_auth(AuthRequest::IMAGE,
|
||||
img->get_iid(),
|
||||
AuthRequest::USE,
|
||||
@@ -219,6 +256,4 @@ int ImagePool::disk_attribute(VectorAttribute * disk,
|
||||
img->isPublic());
|
||||
|
||||
img->unlock();
|
||||
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -27,36 +27,108 @@ void RequestManager::VirtualMachineAllocate::execute(
|
||||
xmlrpc_c::value * const retval)
|
||||
{
|
||||
string session;
|
||||
string vm_template;
|
||||
|
||||
string str_template;
|
||||
|
||||
const string method_name = "VirtualMachineAllocate";
|
||||
|
||||
int vid;
|
||||
int vid, uid;
|
||||
int rc;
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
DispatchManager * dm = nd.get_dm();
|
||||
Nebula& nd = Nebula::instance();
|
||||
ImagePool * ipool = nd.get_ipool();
|
||||
VirtualNetworkPool* vnpool= nd.get_vnpool();
|
||||
VirtualMachinePool* vmpool= nd.get_vmpool();
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
VirtualMachineTemplate * vm_template;
|
||||
char * error_msg = 0;
|
||||
|
||||
int num;
|
||||
vector<Attribute * > vectors;
|
||||
VectorAttribute * vector;
|
||||
|
||||
NebulaLog::log("ReM",Log::DEBUG,"VirtualMachineAllocate invoked");
|
||||
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
vm_template = xmlrpc_c::value_string(paramList.getString(1));
|
||||
vm_template += "\n";
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
str_template = xmlrpc_c::value_string(paramList.getString(1));
|
||||
str_template += "\n";
|
||||
|
||||
//Authenticate the user
|
||||
rc = VirtualMachineAllocate::upool->authenticate(session);
|
||||
//--------------------------------------------------------------------------
|
||||
// Authenticate the user
|
||||
//--------------------------------------------------------------------------
|
||||
uid = VirtualMachineAllocate::upool->authenticate(session);
|
||||
|
||||
if (rc == -1)
|
||||
if (uid == -1)
|
||||
{
|
||||
goto error_authenticate;
|
||||
}
|
||||
|
||||
rc = dm->allocate(rc,vm_template,&vid);
|
||||
//--------------------------------------------------------------------------
|
||||
// Authorize this request
|
||||
//--------------------------------------------------------------------------
|
||||
vm_template = new VirtualMachineTemplate;
|
||||
|
||||
rc = vm_template->parse(str_template,&error_msg);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
goto error_parse;
|
||||
}
|
||||
|
||||
if ( uid != 0 )
|
||||
{
|
||||
AuthRequest ar(uid);
|
||||
string t64;
|
||||
|
||||
num = vm_template->get("DISK",vectors);
|
||||
|
||||
for(int i=0; i<num; i++)
|
||||
{
|
||||
|
||||
vector = dynamic_cast<VectorAttribute * >(vectors[i]);
|
||||
|
||||
if ( vector == 0 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ipool->authorize_disk(vector,&ar);
|
||||
}
|
||||
|
||||
num = vm_template->get("NIC",vectors);
|
||||
|
||||
for(int i=0; i<num; i++)
|
||||
{
|
||||
vector = dynamic_cast<VectorAttribute * >(vectors[i]);
|
||||
|
||||
if ( vector == 0 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
vnpool->authorize_nic(vector,&ar);
|
||||
}
|
||||
|
||||
ar.add_auth(AuthRequest::VM,
|
||||
vm_template->to_xml(t64),
|
||||
AuthRequest::CREATE,
|
||||
uid,
|
||||
false);
|
||||
|
||||
if (UserPool::authorize(ar) == -1)
|
||||
{
|
||||
goto error_authorize;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Allocate the VirtualMAchine
|
||||
//--------------------------------------------------------------------------
|
||||
rc = vmpool->allocate(uid,vm_template,&vid,false);
|
||||
|
||||
if ( rc < 0 )
|
||||
{
|
||||
@@ -73,15 +145,30 @@ void RequestManager::VirtualMachineAllocate::execute(
|
||||
|
||||
delete arrayresult; // and get rid of the original
|
||||
|
||||
|
||||
return;
|
||||
|
||||
error_authenticate:
|
||||
oss.str(authenticate_error(method_name));
|
||||
goto error_common;
|
||||
|
||||
error_authorize:
|
||||
oss.str(authorization_error(method_name, "CREATE", "VM", uid, -1));
|
||||
delete vm_template;
|
||||
goto error_common;
|
||||
|
||||
error_parse:
|
||||
oss.str(action_error(method_name, "PARSE", "VM TEMPLATE",-2,rc));
|
||||
if (error_msg != 0)
|
||||
{
|
||||
oss << "Reason: " << error_msg;
|
||||
free(error_msg);
|
||||
}
|
||||
|
||||
delete vm_template;
|
||||
goto error_common;
|
||||
|
||||
error_allocate:
|
||||
oss.str(action_error(method_name, "CREATE", "VM", NULL, rc));
|
||||
oss.str(action_error(method_name, "CREATE", "VM", -2, rc));
|
||||
goto error_common;
|
||||
|
||||
error_common:
|
||||
|
||||
@@ -95,7 +95,7 @@ error_authorize:
|
||||
goto error_common;
|
||||
|
||||
error_cluster_allocate:
|
||||
oss.str(action_error(method_name, "CREATE", "CLUSTER", NULL, rc));
|
||||
oss.str(action_error(method_name, "CREATE", "CLUSTER", -2, rc));
|
||||
goto error_common;
|
||||
|
||||
error_common:
|
||||
|
||||
@@ -76,7 +76,7 @@ error_authenticate:
|
||||
goto error_common;
|
||||
|
||||
error_dump:
|
||||
oss.str(get_error(method_name, "CLUSTER", NULL));
|
||||
oss.str(get_error(method_name, "CLUSTER", -1));
|
||||
goto error_common;
|
||||
|
||||
error_common:
|
||||
|
||||
@@ -36,7 +36,7 @@ void RequestManager::VirtualMachineDeploy::execute(
|
||||
string vmm_mad;
|
||||
string tm_mad;
|
||||
string vmdir;
|
||||
|
||||
|
||||
const string method_name = "VirtualMachineDeploy";
|
||||
|
||||
VirtualMachine * vm;
|
||||
@@ -148,8 +148,8 @@ error_vm_get:
|
||||
goto error_common;
|
||||
|
||||
error_state:
|
||||
oss.str(action_error(method_name, "MANAGE", "VM", vid, rc));
|
||||
oss << " Reason: VM in wrong state.";
|
||||
oss << action_error(method_name, "MANAGE", "VM", vid, -1)
|
||||
<< ". Reason: VM in wrong state.";
|
||||
goto error_common_lock;
|
||||
|
||||
error_authenticate:
|
||||
@@ -170,7 +170,7 @@ error_common_lock:
|
||||
error_common:
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(false));
|
||||
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
|
||||
|
||||
|
||||
NebulaLog::log("ReM",Log::ERROR,oss);
|
||||
|
||||
xmlrpc_c::value_array arrayresult_error(arrayData);
|
||||
|
||||
@@ -101,11 +101,11 @@ error_authenticate:
|
||||
goto error_common;
|
||||
|
||||
error_authorize:
|
||||
oss.str(authorization_error(method_name, "CREATE", "HOST", rc, NULL));
|
||||
oss.str(authorization_error(method_name, "CREATE", "HOST", rc, -1));
|
||||
goto error_common;
|
||||
|
||||
error_host_allocate:
|
||||
oss.str(action_error(method_name, "CREATE", "HOST", NULL, rc));
|
||||
oss.str(action_error(method_name, "CREATE", "HOST", -2, rc));
|
||||
goto error_common;
|
||||
|
||||
error_common:
|
||||
|
||||
@@ -29,36 +29,76 @@ void RequestManager::ImageAllocate::execute(
|
||||
xmlrpc_c::value * const retval)
|
||||
{
|
||||
string session;
|
||||
string image_template;
|
||||
string str_template;
|
||||
|
||||
ImageTemplate * img_template;
|
||||
|
||||
int iid;
|
||||
int uid;
|
||||
int rc;
|
||||
char * error_msg = 0;
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
|
||||
const string method_name = "ImageAllocate";
|
||||
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
|
||||
NebulaLog::log("ReM",Log::DEBUG,"ImageAllocate invoked");
|
||||
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
image_template = xmlrpc_c::value_string(paramList.getString(1));
|
||||
image_template += "\n";
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
str_template = xmlrpc_c::value_string(paramList.getString(1));
|
||||
str_template += "\n";
|
||||
|
||||
|
||||
// First, we need to authenticate the user
|
||||
//--------------------------------------------------------------------------
|
||||
// Authorize this request
|
||||
//--------------------------------------------------------------------------
|
||||
uid = ImageAllocate::upool->authenticate(session);
|
||||
|
||||
if ( uid == -1 )
|
||||
{
|
||||
goto error_authenticate;
|
||||
}
|
||||
|
||||
rc = ImageAllocate::ipool->allocate(uid,image_template,&iid);
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Authorize this request
|
||||
//--------------------------------------------------------------------------
|
||||
img_template = new ImageTemplate;
|
||||
|
||||
rc = img_template->parse(str_template,&error_msg);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
goto error_parse;
|
||||
}
|
||||
|
||||
if ( uid != 0 )
|
||||
{
|
||||
AuthRequest ar(uid);
|
||||
string t64;
|
||||
string pub;
|
||||
string pub_name = "PUBLIC";
|
||||
|
||||
img_template->get(pub_name, pub);
|
||||
transform (pub.begin(), pub.end(), pub.begin(),(int(*)(int))toupper);
|
||||
|
||||
ar.add_auth(AuthRequest::IMAGE,
|
||||
img_template->to_xml(t64),
|
||||
AuthRequest::CREATE,
|
||||
uid,
|
||||
(pub == "YES"));
|
||||
|
||||
if (UserPool::authorize(ar) == -1)
|
||||
{
|
||||
goto error_authorize;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Allocate the Image
|
||||
//--------------------------------------------------------------------------
|
||||
rc = ImageAllocate::ipool->allocate(uid,img_template,&iid);
|
||||
|
||||
if ( rc < 0 )
|
||||
{
|
||||
@@ -80,9 +120,25 @@ void RequestManager::ImageAllocate::execute(
|
||||
error_authenticate:
|
||||
oss.str(authenticate_error(method_name));
|
||||
goto error_common;
|
||||
|
||||
|
||||
error_authorize:
|
||||
oss.str(authorization_error(method_name, "CREATE", "IMAGE", uid, -1));
|
||||
delete img_template;
|
||||
goto error_common;
|
||||
|
||||
error_parse:
|
||||
oss.str(action_error(method_name, "PARSE", "IMAGE TEMPLATE",-2,rc));
|
||||
if (error_msg != 0)
|
||||
{
|
||||
oss << "Reason: " << error_msg;
|
||||
free(error_msg);
|
||||
}
|
||||
|
||||
delete img_template;
|
||||
goto error_common;
|
||||
|
||||
error_allocate:
|
||||
oss.str(action_error(method_name, "CREATE", "IMAGE", NULL, rc));
|
||||
oss.str(action_error(method_name, "CREATE", "IMAGE", -2, rc));
|
||||
goto error_common;
|
||||
|
||||
error_common:
|
||||
|
||||
@@ -133,8 +133,8 @@ error_authorize:
|
||||
goto error_common;
|
||||
|
||||
error_delete:
|
||||
oss.str(action_error(method_name, "DELETE", "IMAGE", iid, rc));
|
||||
oss << " VMs might be running on it.";
|
||||
oss << action_error(method_name, "DELETE", "IMAGE", iid, rc)
|
||||
<< ". Reason: VMs might be running on it.";
|
||||
image->unlock();
|
||||
goto error_common;
|
||||
|
||||
|
||||
@@ -168,8 +168,8 @@ error_history:
|
||||
goto error_common_lock;
|
||||
|
||||
error_state:
|
||||
oss.str(action_error(method_name, "MANAGE", "VM", vid, rc));
|
||||
oss << " Reason: VM in wrong state.";
|
||||
oss << action_error(method_name, "MANAGE", "VM", vid, rc)
|
||||
<< ". Reason: VM in wrong state.";
|
||||
goto error_common_lock;
|
||||
|
||||
error_common_lock:
|
||||
|
||||
@@ -25,19 +25,19 @@
|
||||
void RequestManager::UserAllocate::execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retval)
|
||||
{
|
||||
{
|
||||
string session;
|
||||
|
||||
string username;
|
||||
string password;
|
||||
|
||||
string password;
|
||||
|
||||
int uid;
|
||||
|
||||
int rc;
|
||||
int rc;
|
||||
ostringstream oss;
|
||||
|
||||
User * user;
|
||||
|
||||
|
||||
const string method_name = "UserAllocate";
|
||||
|
||||
/* -- RPC specific vars -- */
|
||||
@@ -48,17 +48,17 @@ void RequestManager::UserAllocate::execute(
|
||||
|
||||
// Get the parameters
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
|
||||
|
||||
username = xmlrpc_c::value_string(paramList.getString(1));
|
||||
password = xmlrpc_c::value_string(paramList.getString(2));
|
||||
|
||||
|
||||
rc = UserAllocate::upool->authenticate(session);
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
goto error_authenticate;
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
goto error_authenticate;
|
||||
}
|
||||
|
||||
|
||||
//Authorize the operation
|
||||
if ( rc != 0 ) // rc == 0 means oneadmin
|
||||
{
|
||||
@@ -83,56 +83,54 @@ void RequestManager::UserAllocate::execute(
|
||||
{
|
||||
goto error_duplicate;
|
||||
}
|
||||
|
||||
|
||||
// Now let's add the user
|
||||
rc = UserAllocate::upool->allocate(&uid,username,password,true);
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
goto error_allocate;
|
||||
}
|
||||
|
||||
// All nice, return the new uid to client
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
goto error_allocate;
|
||||
}
|
||||
|
||||
// All nice, return the new uid to client
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(true)); // SUCCESS
|
||||
arrayData.push_back(xmlrpc_c::value_int(uid));
|
||||
|
||||
// Copy arrayresult into retval mem space
|
||||
arrayresult = new xmlrpc_c::value_array(arrayData);
|
||||
*retval = *arrayresult;
|
||||
|
||||
|
||||
delete arrayresult; // and get rid of the original
|
||||
|
||||
return;
|
||||
|
||||
error_authenticate:
|
||||
oss.str(authenticate_error(method_name));
|
||||
goto error_common;
|
||||
|
||||
error_authorize:
|
||||
oss.str(authorization_error(method_name, "CREATE", "USER", rc, NULL));
|
||||
goto error_common;
|
||||
|
||||
error_duplicate:
|
||||
oss.str(action_error(method_name, "CREATE", "USER", NULL, NULL));
|
||||
oss << " Reason: Existing user, cannot duplicate.";
|
||||
oss.str(authenticate_error(method_name));
|
||||
goto error_common;
|
||||
|
||||
error_authorize:
|
||||
oss.str(authorization_error(method_name, "CREATE", "USER", rc, -1));
|
||||
goto error_common;
|
||||
|
||||
error_duplicate:
|
||||
oss << action_error(method_name, "CREATE", "USER", -2, -1)
|
||||
<< ". Reason: Existing user, cannot duplicate.";
|
||||
goto error_common;
|
||||
|
||||
error_allocate:
|
||||
oss.str(action_error(method_name, "CREATE", "USER", NULL, rc));
|
||||
oss.str(action_error(method_name, "CREATE", "USER", -2, rc));
|
||||
goto error_common;
|
||||
|
||||
error_common:
|
||||
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
|
||||
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
|
||||
|
||||
NebulaLog::log("ReM",Log::ERROR,oss);
|
||||
|
||||
|
||||
NebulaLog::log("ReM",Log::ERROR,oss);
|
||||
|
||||
xmlrpc_c::value_array arrayresult_error(arrayData);
|
||||
|
||||
*retval = arrayresult_error;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,15 +25,15 @@
|
||||
void RequestManager::UserDelete::execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retval)
|
||||
{
|
||||
{
|
||||
string session;
|
||||
|
||||
int uid;
|
||||
User * user;
|
||||
|
||||
int rc;
|
||||
int rc;
|
||||
ostringstream oss;
|
||||
|
||||
|
||||
const string method_name = "UserDelete";
|
||||
|
||||
/* -- RPC specific vars -- */
|
||||
@@ -51,14 +51,14 @@ void RequestManager::UserDelete::execute(
|
||||
{
|
||||
goto error_oneadmin_deletion;
|
||||
}
|
||||
|
||||
|
||||
rc = UserDelete::upool->authenticate(session);
|
||||
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
goto error_authenticate;
|
||||
}
|
||||
|
||||
|
||||
//Authorize the operation
|
||||
if ( rc != 0 ) // rc == 0 means oneadmin
|
||||
{
|
||||
@@ -76,24 +76,24 @@ void RequestManager::UserDelete::execute(
|
||||
}
|
||||
}
|
||||
|
||||
// Now let's get the user
|
||||
// Now let's get the user
|
||||
user = UserDelete::upool->get(uid,true);
|
||||
|
||||
if ( user == 0)
|
||||
|
||||
if ( user == 0)
|
||||
{
|
||||
goto error_get_user;
|
||||
}
|
||||
|
||||
|
||||
rc = UserDelete::upool->drop(user);
|
||||
|
||||
user->unlock();
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
goto error_delete;
|
||||
}
|
||||
|
||||
// All nice, return the new uid to client
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
goto error_delete;
|
||||
}
|
||||
|
||||
// All nice, return the new uid to client
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(true)); // SUCCESS
|
||||
|
||||
// Copy arrayresult into retval mem space
|
||||
@@ -105,18 +105,18 @@ void RequestManager::UserDelete::execute(
|
||||
return;
|
||||
|
||||
error_oneadmin_deletion:
|
||||
oss.str(action_error(method_name, "DELETE", "USER", uid, NULL));
|
||||
oss << " Reason: Oneadmin cannot be deleted.";
|
||||
oss << action_error(method_name, "DELETE", "USER", uid, -1)
|
||||
<< ". Reason: Oneadmin cannot be deleted.";
|
||||
goto error_common;
|
||||
|
||||
error_authenticate:
|
||||
oss.str(authenticate_error(method_name));
|
||||
oss.str(authenticate_error(method_name));
|
||||
goto error_common;
|
||||
|
||||
error_authorize:
|
||||
oss.str(authorization_error(method_name, "DELETE", "USER", rc, uid));
|
||||
goto error_common;
|
||||
|
||||
|
||||
error_get_user:
|
||||
oss.str(get_error(method_name, "USER", uid));
|
||||
goto error_common;
|
||||
@@ -128,13 +128,13 @@ error_delete:
|
||||
error_common:
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
|
||||
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
|
||||
|
||||
NebulaLog::log("ReM",Log::ERROR,oss);
|
||||
|
||||
|
||||
NebulaLog::log("ReM",Log::ERROR,oss);
|
||||
|
||||
xmlrpc_c::value_array arrayresult_error(arrayData);
|
||||
|
||||
*retval = arrayresult_error;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,19 +27,18 @@ void RequestManager::VirtualNetworkAllocate::execute(
|
||||
xmlrpc_c::value * const retval)
|
||||
{
|
||||
string session;
|
||||
string username;
|
||||
string password;
|
||||
string name;
|
||||
string stemplate;
|
||||
string str_template;
|
||||
|
||||
VirtualNetworkTemplate * vn_template;
|
||||
|
||||
int nid;
|
||||
int uid;
|
||||
int rc;
|
||||
|
||||
User * user;
|
||||
char * error_msg = 0;
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
|
||||
const string method_name = "VirtualNetworkAllocate";
|
||||
|
||||
/* -- RPC specific vars -- */
|
||||
@@ -49,27 +48,57 @@ void RequestManager::VirtualNetworkAllocate::execute(
|
||||
NebulaLog::log("ReM",Log::DEBUG,"VirtualNetworkAllocate method invoked");
|
||||
|
||||
// Get the parameters & host
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
stemplate = xmlrpc_c::value_string(paramList.getString(1));
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
str_template = xmlrpc_c::value_string(paramList.getString(1));
|
||||
|
||||
if ( User::split_secret(session,username,password) != 0 )
|
||||
//--------------------------------------------------------------------------
|
||||
// Authorize this request
|
||||
//--------------------------------------------------------------------------
|
||||
uid = VirtualNetworkAllocate::upool->authenticate(session);
|
||||
|
||||
if ( uid == -1 )
|
||||
{
|
||||
goto error_authenticate;
|
||||
}
|
||||
|
||||
// Now let's get the user
|
||||
user = VirtualNetworkAllocate::upool->get(username,true);
|
||||
//--------------------------------------------------------------------------
|
||||
// Authorize this request
|
||||
//--------------------------------------------------------------------------
|
||||
vn_template = new VirtualNetworkTemplate;
|
||||
|
||||
if ( user == 0 )
|
||||
rc = vn_template->parse(str_template,&error_msg);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
goto error_get_user;
|
||||
goto error_parse;
|
||||
}
|
||||
|
||||
uid = user->get_uid();
|
||||
if ( uid != 0 )
|
||||
{
|
||||
AuthRequest ar(uid);
|
||||
string t64;
|
||||
string pub;
|
||||
string pub_name = "PUBLIC";
|
||||
|
||||
user->unlock();
|
||||
|
||||
rc = vnpool->allocate(uid,stemplate,&nid);
|
||||
vn_template->get(pub_name, pub);
|
||||
transform (pub.begin(), pub.end(), pub.begin(),(int(*)(int))toupper);
|
||||
|
||||
ar.add_auth(AuthRequest::NET,
|
||||
vn_template->to_xml(t64),
|
||||
AuthRequest::CREATE,
|
||||
uid,
|
||||
(pub == "YES"));
|
||||
|
||||
if (UserPool::authorize(ar) == -1)
|
||||
{
|
||||
goto error_authorize;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Allocate the Virtual Network
|
||||
//--------------------------------------------------------------------------
|
||||
rc = vnpool->allocate(uid,vn_template,&nid);
|
||||
|
||||
if ( rc < 0 )
|
||||
{
|
||||
@@ -92,12 +121,24 @@ error_authenticate:
|
||||
oss.str(authenticate_error(method_name));
|
||||
goto error_common;
|
||||
|
||||
error_get_user:
|
||||
oss.str(get_error(method_name, "USER", -1));
|
||||
error_authorize:
|
||||
oss.str(authorization_error(method_name, "CREATE", "VNET", uid, -1));
|
||||
delete vn_template;
|
||||
goto error_common;
|
||||
|
||||
|
||||
error_parse:
|
||||
oss.str(action_error(method_name, "PARSE", "VNET TEMPLATE",-2,rc));
|
||||
if (error_msg != 0)
|
||||
{
|
||||
oss << "Reason: " << error_msg;
|
||||
free(error_msg);
|
||||
}
|
||||
|
||||
delete vn_template;
|
||||
goto error_common;
|
||||
|
||||
error_vn_allocate:
|
||||
oss.str(action_error(method_name, "ALLOCATE", "NET", NULL, rc));
|
||||
oss.str(action_error(method_name, "CREATE", "NET", -2, rc));
|
||||
goto error_common;
|
||||
|
||||
error_common:
|
||||
|
||||
@@ -33,7 +33,6 @@ void RequestManager::VirtualNetworkPublish::execute(
|
||||
int nid;
|
||||
bool publish_flag;
|
||||
int uid;
|
||||
int rc;
|
||||
|
||||
VirtualNetwork * vn;
|
||||
|
||||
|
||||
+39
-53
@@ -26,7 +26,6 @@
|
||||
#include "VirtualMachine.h"
|
||||
#include "VirtualNetworkPool.h"
|
||||
#include "NebulaLog.h"
|
||||
#include "AuthManager.h"
|
||||
|
||||
#include "Nebula.h"
|
||||
|
||||
@@ -37,12 +36,11 @@
|
||||
/* Virtual Machine :: Constructor/Destructor */
|
||||
/* ************************************************************************** */
|
||||
|
||||
VirtualMachine::VirtualMachine(int id):
|
||||
VirtualMachine::VirtualMachine(int id, VirtualMachineTemplate * _vm_template):
|
||||
PoolObjectSQL(id),
|
||||
uid(-1),
|
||||
last_poll(0),
|
||||
name(""),
|
||||
vm_template(),
|
||||
state(INIT),
|
||||
lcm_state(LCM_INIT),
|
||||
stime(time(0)),
|
||||
@@ -57,6 +55,14 @@ VirtualMachine::VirtualMachine(int id):
|
||||
previous_history(0),
|
||||
_log(0)
|
||||
{
|
||||
if (_vm_template != 0)
|
||||
{
|
||||
vm_template = _vm_template;
|
||||
}
|
||||
else
|
||||
{
|
||||
vm_template = new VirtualMachineTemplate;
|
||||
}
|
||||
}
|
||||
|
||||
VirtualMachine::~VirtualMachine()
|
||||
@@ -75,6 +81,11 @@ VirtualMachine::~VirtualMachine()
|
||||
{
|
||||
delete _log;
|
||||
}
|
||||
|
||||
if ( vm_template != 0 )
|
||||
{
|
||||
delete vm_template;
|
||||
}
|
||||
}
|
||||
|
||||
/* ************************************************************************** */
|
||||
@@ -141,7 +152,7 @@ int VirtualMachine::select_cb(void *nil, int num, char **values, char **names)
|
||||
last_seq = atoi(values[LAST_SEQ]);
|
||||
|
||||
// Virtual Machine template ID is the VM ID
|
||||
vm_template.id = oid;
|
||||
vm_template->id = oid;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -177,7 +188,7 @@ int VirtualMachine::select(SqlDB * db)
|
||||
}
|
||||
|
||||
//Get the template
|
||||
rc = vm_template.select(db);
|
||||
rc = vm_template->select(db);
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
@@ -268,14 +279,12 @@ int VirtualMachine::insert(SqlDB * db)
|
||||
string value;
|
||||
ostringstream oss;
|
||||
|
||||
AuthRequest ar(uid);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Set a template ID if it wasn't already assigned
|
||||
// ------------------------------------------------------------------------
|
||||
if ( vm_template.id == -1 )
|
||||
if ( vm_template->id == -1 )
|
||||
{
|
||||
vm_template.id = oid;
|
||||
vm_template->id = oid;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
@@ -286,7 +295,7 @@ int VirtualMachine::insert(SqlDB * db)
|
||||
|
||||
attr = new SingleAttribute("VMID",value);
|
||||
|
||||
vm_template.set(attr);
|
||||
vm_template->set(attr);
|
||||
|
||||
get_template_attribute("NAME",name);
|
||||
|
||||
@@ -297,7 +306,7 @@ int VirtualMachine::insert(SqlDB * db)
|
||||
name = oss.str();
|
||||
|
||||
attr = new SingleAttribute("NAME",name);
|
||||
vm_template.set(attr);
|
||||
vm_template->set(attr);
|
||||
}
|
||||
|
||||
this->name = name;
|
||||
@@ -306,7 +315,7 @@ int VirtualMachine::insert(SqlDB * db)
|
||||
// Get network leases
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
rc = get_network_leases(&ar);
|
||||
rc = get_network_leases();
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
@@ -317,7 +326,7 @@ int VirtualMachine::insert(SqlDB * db)
|
||||
// Get disk images
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
rc = get_disk_images(&ar);
|
||||
rc = get_disk_images();
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
@@ -344,31 +353,11 @@ int VirtualMachine::insert(SqlDB * db)
|
||||
|
||||
parse_graphics();
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Authorize this request
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( uid != 0 ) // uid == 0 means oneadmin
|
||||
{
|
||||
string t64;
|
||||
|
||||
ar.add_auth(AuthRequest::VM,
|
||||
vm_template.to_xml(t64),
|
||||
AuthRequest::CREATE,
|
||||
uid,
|
||||
false);
|
||||
|
||||
if (UserPool::authorize(ar) == -1)
|
||||
{
|
||||
goto error_authorize;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Insert the template first, so we get a valid template ID. Then the VM
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
rc = vm_template.insert(db);
|
||||
rc = vm_template->insert(db);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
@@ -386,7 +375,7 @@ int VirtualMachine::insert(SqlDB * db)
|
||||
|
||||
error_update:
|
||||
NebulaLog::log("ONE",Log::ERROR, "Can not update VM in the database");
|
||||
vm_template.drop(db);
|
||||
vm_template->drop(db);
|
||||
goto error_common;
|
||||
|
||||
error_template:
|
||||
@@ -410,9 +399,6 @@ error_requirements:
|
||||
NebulaLog::log("ONE",Log::ERROR, "Could not parse REQUIREMENTS for VM");
|
||||
goto error_common;
|
||||
|
||||
error_authorize:
|
||||
NebulaLog::log("ONE",Log::ERROR, "Error authorizing VM creation");
|
||||
|
||||
error_common:
|
||||
release_network_leases();
|
||||
release_disk_images();
|
||||
@@ -432,7 +418,7 @@ int VirtualMachine::parse_context()
|
||||
string * str;
|
||||
string parsed;
|
||||
|
||||
num = vm_template.remove("CONTEXT", array_context);
|
||||
num = vm_template->remove("CONTEXT", array_context);
|
||||
|
||||
if ( num == 0 )
|
||||
{
|
||||
@@ -464,7 +450,7 @@ int VirtualMachine::parse_context()
|
||||
context_parsed = new VectorAttribute("CONTEXT");
|
||||
context_parsed->unmarshall(parsed," @^_^@ ");
|
||||
|
||||
vm_template.set(context_parsed);
|
||||
vm_template->set(context_parsed);
|
||||
}
|
||||
|
||||
/* --- Delete old context attributes --- */
|
||||
@@ -490,7 +476,7 @@ void VirtualMachine::parse_graphics()
|
||||
vector<Attribute *> array_graphics;
|
||||
VectorAttribute * graphics;
|
||||
|
||||
num = vm_template.get("GRAPHICS", array_graphics);
|
||||
num = vm_template->get("GRAPHICS", array_graphics);
|
||||
|
||||
if ( num == 0 )
|
||||
{
|
||||
@@ -537,7 +523,7 @@ int VirtualMachine::parse_requirements()
|
||||
|
||||
string parsed;
|
||||
|
||||
num = vm_template.remove("REQUIREMENTS", array_reqs);
|
||||
num = vm_template->remove("REQUIREMENTS", array_reqs);
|
||||
|
||||
if ( num == 0 )
|
||||
{
|
||||
@@ -559,7 +545,7 @@ int VirtualMachine::parse_requirements()
|
||||
SingleAttribute * reqs_parsed;
|
||||
|
||||
reqs_parsed = new SingleAttribute("REQUIREMENTS",parsed);
|
||||
vm_template.set(reqs_parsed);
|
||||
vm_template->set(reqs_parsed);
|
||||
}
|
||||
|
||||
/* --- Delete old requirements attributes --- */
|
||||
@@ -819,7 +805,7 @@ void VirtualMachine::get_requirements (int& cpu, int& memory, int& disk)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualMachine::get_disk_images(AuthRequest *ar)
|
||||
int VirtualMachine::get_disk_images()
|
||||
{
|
||||
int num_disks, rc;
|
||||
vector<Attribute * > disks;
|
||||
@@ -829,7 +815,7 @@ int VirtualMachine::get_disk_images(AuthRequest *ar)
|
||||
Nebula& nd = Nebula::instance();
|
||||
ipool = nd.get_ipool();
|
||||
|
||||
num_disks = vm_template.get("DISK",disks);
|
||||
num_disks = vm_template->get("DISK",disks);
|
||||
|
||||
for(int i=0, index=0; i<num_disks; i++)
|
||||
{
|
||||
@@ -841,7 +827,7 @@ int VirtualMachine::get_disk_images(AuthRequest *ar)
|
||||
continue;
|
||||
}
|
||||
|
||||
rc = ipool->disk_attribute(disk, &index, ar);
|
||||
rc = ipool->disk_attribute(disk, &index);
|
||||
|
||||
if (rc == -1) // 0 OK, -2 not using the Image pool
|
||||
{
|
||||
@@ -879,7 +865,7 @@ void VirtualMachine::release_disk_images()
|
||||
continue;
|
||||
}
|
||||
|
||||
iid = disk->vector_value("IID");
|
||||
iid = disk->vector_value("IMAGE_ID");
|
||||
|
||||
if ( iid.empty() )
|
||||
{
|
||||
@@ -902,7 +888,7 @@ void VirtualMachine::release_disk_images()
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualMachine::get_network_leases(AuthRequest *ar)
|
||||
int VirtualMachine::get_network_leases()
|
||||
{
|
||||
int num_nics, rc;
|
||||
vector<Attribute * > nics;
|
||||
@@ -912,7 +898,7 @@ int VirtualMachine::get_network_leases(AuthRequest *ar)
|
||||
Nebula& nd = Nebula::instance();
|
||||
vnpool = nd.get_vnpool();
|
||||
|
||||
num_nics = vm_template.get("NIC",nics);
|
||||
num_nics = vm_template->get("NIC",nics);
|
||||
|
||||
for(int i=0; i<num_nics; i++)
|
||||
{
|
||||
@@ -923,7 +909,7 @@ int VirtualMachine::get_network_leases(AuthRequest *ar)
|
||||
continue;
|
||||
}
|
||||
|
||||
rc = vnpool->nic_attribute(nic, oid, ar);
|
||||
rc = vnpool->nic_attribute(nic, oid);
|
||||
|
||||
if (rc == -1)
|
||||
{
|
||||
@@ -962,7 +948,7 @@ void VirtualMachine::release_network_leases()
|
||||
continue;
|
||||
}
|
||||
|
||||
vnid = nic->vector_value("VNID");
|
||||
vnid = nic->vector_value("NETWORK_ID");
|
||||
|
||||
if ( vnid.empty() )
|
||||
{
|
||||
@@ -1152,7 +1138,7 @@ string& VirtualMachine::to_xml(string& xml) const
|
||||
<< "<NET_TX>" << net_tx << "</NET_TX>"
|
||||
<< "<NET_RX>" << net_rx << "</NET_RX>"
|
||||
<< "<LAST_SEQ>" << last_seq << "</LAST_SEQ>"
|
||||
<< vm_template.to_xml(template_xml);
|
||||
<< vm_template->to_xml(template_xml);
|
||||
|
||||
if ( hasHistory() )
|
||||
{
|
||||
@@ -1189,7 +1175,7 @@ string& VirtualMachine::to_str(string& str) const
|
||||
<< "NET TX : " << net_tx << endl
|
||||
<< "NET RX : " << net_rx << endl
|
||||
<< "LAST SEQ : " << last_seq << endl
|
||||
<< "Template" << endl << vm_template.to_str(template_str) << endl;
|
||||
<< "Template" << endl << vm_template->to_str(template_str) << endl;
|
||||
|
||||
if ( hasHistory() )
|
||||
{
|
||||
|
||||
@@ -151,19 +151,16 @@ VirtualMachinePool::VirtualMachinePool(SqlDB * db,
|
||||
|
||||
int VirtualMachinePool::allocate (
|
||||
int uid,
|
||||
const string& stemplate,
|
||||
VirtualMachineTemplate * vm_template,
|
||||
int * oid,
|
||||
bool on_hold)
|
||||
{
|
||||
VirtualMachine * vm;
|
||||
|
||||
char * error_msg;
|
||||
int rc;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Build a new Virtual Machine object
|
||||
// ------------------------------------------------------------------------
|
||||
vm = new VirtualMachine;
|
||||
vm = new VirtualMachine(-1,vm_template);
|
||||
|
||||
if (on_hold == true)
|
||||
{
|
||||
@@ -176,24 +173,6 @@ int VirtualMachinePool::allocate (
|
||||
|
||||
vm->uid = uid;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Parse template
|
||||
// ------------------------------------------------------------------------
|
||||
rc = vm->vm_template.parse(stemplate,&error_msg);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
oss << error_msg;
|
||||
NebulaLog::log("ONE", Log::ERROR, oss);
|
||||
free(error_msg);
|
||||
|
||||
delete vm;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Insert the Object in the pool
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
+33
-44
@@ -29,13 +29,23 @@
|
||||
/* Virtual Network :: Constructor/Destructor */
|
||||
/* ************************************************************************** */
|
||||
|
||||
VirtualNetwork::VirtualNetwork():
|
||||
VirtualNetwork::VirtualNetwork(VirtualNetworkTemplate *_vn_template):
|
||||
PoolObjectSQL(-1),
|
||||
name(""),
|
||||
uid(-1),
|
||||
bridge(""),
|
||||
type(UNINITIALIZED),
|
||||
leases(0){};
|
||||
leases(0)
|
||||
{
|
||||
if (_vn_template != 0)
|
||||
{
|
||||
vn_template = _vn_template;
|
||||
}
|
||||
else
|
||||
{
|
||||
vn_template = new VirtualNetworkTemplate;
|
||||
}
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@@ -46,6 +56,11 @@ VirtualNetwork::~VirtualNetwork()
|
||||
{
|
||||
delete leases;
|
||||
}
|
||||
|
||||
if (vn_template != 0)
|
||||
{
|
||||
delete vn_template;
|
||||
}
|
||||
}
|
||||
|
||||
/* ************************************************************************** */
|
||||
@@ -89,7 +104,7 @@ int VirtualNetwork::select_cb(void * nil, int num, char **values, char **names)
|
||||
public_vnet = atoi(values[PUBLIC]);
|
||||
|
||||
// Virtual Network template ID is the Network ID
|
||||
vn_template.id = oid;
|
||||
vn_template->id = oid;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -128,7 +143,7 @@ int VirtualNetwork::select(SqlDB * db)
|
||||
}
|
||||
|
||||
//Get the template
|
||||
rc = vn_template.select(db);
|
||||
rc = vn_template->select(db);
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
@@ -315,37 +330,16 @@ int VirtualNetwork::insert(SqlDB * db)
|
||||
|
||||
public_vnet = (pub == "YES");
|
||||
|
||||
vn_template.erase("PUBLIC");
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Authorize this request
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
if ( uid != 0 ) // uid == 0 means oneadmin
|
||||
{
|
||||
string t64;
|
||||
AuthRequest ar(uid);
|
||||
|
||||
ar.add_auth(AuthRequest::NET,
|
||||
vn_template.to_xml(t64),
|
||||
AuthRequest::CREATE,
|
||||
uid,
|
||||
public_vnet);
|
||||
|
||||
if (UserPool::authorize(ar) == -1)
|
||||
{
|
||||
goto error_authorize;
|
||||
}
|
||||
}
|
||||
vn_template->erase("PUBLIC");
|
||||
|
||||
// ------------ INSERT THE TEMPLATE --------------------
|
||||
|
||||
if ( vn_template.id == -1 )
|
||||
if ( vn_template->id == -1 )
|
||||
{
|
||||
vn_template.id = oid;
|
||||
vn_template->id = oid;
|
||||
}
|
||||
|
||||
rc = vn_template.insert(db);
|
||||
rc = vn_template->insert(db);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
@@ -440,17 +434,13 @@ error_bridge:
|
||||
ose << "No BRIDGE in template for Virtual Network id " << oid;
|
||||
goto error_common;
|
||||
|
||||
error_authorize:
|
||||
ose << "Error authorizing Virtual Network creation";
|
||||
goto error_common;
|
||||
|
||||
error_template:
|
||||
ose << "Can not insert in DB template for Virtual Network id " << oid;
|
||||
goto error_common;
|
||||
|
||||
error_update:
|
||||
ose << "Can not update Virtual Network id " << oid;
|
||||
vn_template.drop(db);
|
||||
vn_template->drop(db);
|
||||
goto error_common;
|
||||
|
||||
error_addr:
|
||||
@@ -531,7 +521,7 @@ int VirtualNetwork::vn_drop(SqlDB * db)
|
||||
ostringstream oss;
|
||||
int rc;
|
||||
|
||||
vn_template.drop(db);
|
||||
vn_template->drop(db);
|
||||
|
||||
if ( leases != 0 )
|
||||
{
|
||||
@@ -583,7 +573,7 @@ string& VirtualNetwork::to_xml(string& xml) const
|
||||
"<TYPE>" << type << "</TYPE>" <<
|
||||
"<BRIDGE>" << bridge << "</BRIDGE>" <<
|
||||
"<PUBLIC>" << public_vnet << "</PUBLIC>" <<
|
||||
vn_template.to_xml(template_xml);
|
||||
vn_template->to_xml(template_xml);
|
||||
if (leases)
|
||||
{
|
||||
os << leases->to_xml(leases_xml);
|
||||
@@ -621,7 +611,8 @@ string& VirtualNetwork::to_str(string& str) const
|
||||
os << "Bridge : " << bridge << endl;
|
||||
os << "Public : " << public_vnet << endl << endl;
|
||||
|
||||
os << "....: Template :...." << vn_template.to_str(template_str) << endl << endl;
|
||||
os << "....: Template :...." << vn_template->to_str(template_str) << endl <<
|
||||
endl;
|
||||
|
||||
if (leases)
|
||||
{
|
||||
@@ -640,7 +631,6 @@ int VirtualNetwork::nic_attribute(VectorAttribute *nic, int vid)
|
||||
{
|
||||
int rc;
|
||||
|
||||
string network;
|
||||
string model;
|
||||
string ip;
|
||||
string mac;
|
||||
@@ -649,7 +639,6 @@ int VirtualNetwork::nic_attribute(VectorAttribute *nic, int vid)
|
||||
|
||||
map<string,string> new_nic;
|
||||
|
||||
network = nic->vector_value("NETWORK");
|
||||
model = nic->vector_value("MODEL");
|
||||
ip = nic->vector_value("IP");
|
||||
vnid << oid;
|
||||
@@ -676,11 +665,11 @@ int VirtualNetwork::nic_attribute(VectorAttribute *nic, int vid)
|
||||
// NEW NIC ATTRIBUTES
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
new_nic.insert(make_pair("NETWORK",network));
|
||||
new_nic.insert(make_pair("MAC" ,mac));
|
||||
new_nic.insert(make_pair("BRIDGE" ,bridge));
|
||||
new_nic.insert(make_pair("VNID" ,vnid.str()));
|
||||
new_nic.insert(make_pair("IP" ,ip));
|
||||
new_nic.insert(make_pair("NETWORK" ,name));
|
||||
new_nic.insert(make_pair("MAC" ,mac));
|
||||
new_nic.insert(make_pair("BRIDGE" ,bridge));
|
||||
new_nic.insert(make_pair("NETWORK_ID",vnid.str()));
|
||||
new_nic.insert(make_pair("IP" ,ip));
|
||||
|
||||
if (!model.empty())
|
||||
{
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
#include "VirtualNetworkPool.h"
|
||||
#include "NebulaLog.h"
|
||||
#include "AuthManager.h"
|
||||
|
||||
#include "AuthManager.h"
|
||||
#include <sstream>
|
||||
#include <ctype.h>
|
||||
|
||||
@@ -71,35 +71,15 @@ VirtualNetworkPool::VirtualNetworkPool(SqlDB * db,
|
||||
|
||||
int VirtualNetworkPool::allocate (
|
||||
int uid,
|
||||
const string& stemplate,
|
||||
VirtualNetworkTemplate * vn_template,
|
||||
int * oid)
|
||||
{
|
||||
VirtualNetwork * vn;
|
||||
char * error_msg;
|
||||
int rc;
|
||||
|
||||
// Build a new Virtual Network object
|
||||
vn = new VirtualNetwork();
|
||||
vn = new VirtualNetwork(vn_template);
|
||||
|
||||
vn->uid = uid;
|
||||
|
||||
rc = vn->vn_template.parse(stemplate,&error_msg);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
oss << error_msg;
|
||||
NebulaLog::log("VNM", Log::ERROR, oss);
|
||||
free(error_msg);
|
||||
|
||||
delete vn;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Insert the VN in the pool so we have a valid OID
|
||||
|
||||
*oid = PoolSQL::allocate(vn);
|
||||
|
||||
return *oid;
|
||||
@@ -219,21 +199,37 @@ int VirtualNetworkPool::dump(ostringstream& oss, const string& where)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualNetworkPool::nic_attribute(VectorAttribute * nic,
|
||||
int vid,
|
||||
AuthRequest * ar)
|
||||
int VirtualNetworkPool::nic_attribute(VectorAttribute * nic, int vid)
|
||||
{
|
||||
string network;
|
||||
VirtualNetwork * vnet;
|
||||
VirtualNetwork * vnet = 0;
|
||||
|
||||
network = nic->vector_value("NETWORK");
|
||||
|
||||
if (network.empty())
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
istringstream is;
|
||||
int network_id;
|
||||
|
||||
vnet = get(network,true);
|
||||
network = nic->vector_value("NETWORK_ID");
|
||||
|
||||
if(network.empty())
|
||||
{
|
||||
return -2;
|
||||
}
|
||||
|
||||
is.str(network);
|
||||
is >> network_id;
|
||||
|
||||
if( !is.fail() )
|
||||
{
|
||||
vnet = get(network_id,true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
vnet = get(network,true);
|
||||
}
|
||||
|
||||
if (vnet == 0)
|
||||
{
|
||||
@@ -242,6 +238,51 @@ int VirtualNetworkPool::nic_attribute(VectorAttribute * nic,
|
||||
|
||||
int rc = vnet->nic_attribute(nic,vid);
|
||||
|
||||
vnet->unlock();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void VirtualNetworkPool::authorize_nic(VectorAttribute * nic, AuthRequest * ar)
|
||||
{
|
||||
string network;
|
||||
VirtualNetwork * vnet = 0;
|
||||
|
||||
network = nic->vector_value("NETWORK");
|
||||
|
||||
if (network.empty())
|
||||
{
|
||||
istringstream is;
|
||||
int network_id;
|
||||
|
||||
network = nic->vector_value("NETWORK_ID");
|
||||
|
||||
if(network.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
is.str(network);
|
||||
is >> network_id;
|
||||
|
||||
if( !is.fail() )
|
||||
{
|
||||
vnet = get(network_id,true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
vnet = get(network,true);
|
||||
}
|
||||
|
||||
if (vnet == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ar->add_auth(AuthRequest::NET,
|
||||
vnet->get_vnid(),
|
||||
AuthRequest::USE,
|
||||
@@ -249,6 +290,4 @@ int VirtualNetworkPool::nic_attribute(VectorAttribute * nic,
|
||||
vnet->isPublic());
|
||||
|
||||
vnet->unlock();
|
||||
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user