mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-28 14:50:08 +03:00
This commit is contained in:
parent
f411c685d7
commit
fc6aa51c0d
@ -82,17 +82,19 @@ public:
|
||||
/**
|
||||
* Try to acquire an image from the repository for a VM.
|
||||
* @param image_id id of image
|
||||
* @param error string describing the error
|
||||
* @return pointer to the image or 0 if could not be acquired
|
||||
*/
|
||||
Image * acquire_image(int image_id);
|
||||
Image * acquire_image(int image_id, string& error);
|
||||
|
||||
/**
|
||||
* Try to acquire an image from the repository for a VM.
|
||||
* @param name of the image
|
||||
* @param id of owner
|
||||
* @param error string describing the error
|
||||
* @return pointer to the image or 0 if could not be acquired
|
||||
*/
|
||||
Image * acquire_image(const string& name, int uid);
|
||||
Image * acquire_image(const string& name, int uid, string& error);
|
||||
|
||||
/**
|
||||
* Releases an image and triggers any needed operations in the repo
|
||||
@ -212,7 +214,7 @@ private:
|
||||
* @param image pointer to image, it should be locked
|
||||
* @return 0 on success
|
||||
*/
|
||||
int acquire_image(Image *img);
|
||||
int acquire_image(Image *img, string& error);
|
||||
|
||||
/**
|
||||
* Moves a file to an image in the repository
|
||||
|
@ -139,6 +139,7 @@ public:
|
||||
* @param img_type will be set to the used image's type
|
||||
* @param uid of VM owner (to look for the image id within its images)
|
||||
* @param image_id on success returns the acquired image id
|
||||
* @param error_str string describing the error
|
||||
* @return 0 on success,
|
||||
* -1 error,
|
||||
* -2 not using the pool,
|
||||
@ -148,7 +149,8 @@ public:
|
||||
int * index,
|
||||
Image::ImageType * img_type,
|
||||
int uid,
|
||||
int& image_id);
|
||||
int& image_id,
|
||||
string& error_str);
|
||||
/**
|
||||
* Generates an Authorization token for the DISK attribute
|
||||
* @param disk the disk to be authorized
|
||||
|
@ -92,11 +92,12 @@ public:
|
||||
* metadata
|
||||
* @param nic the nic attribute to be generated
|
||||
* @param vid of the VM requesting the lease
|
||||
* @param error_str string describing the error
|
||||
* @return 0 on success,
|
||||
* -1 error,
|
||||
* -2 not using the pool
|
||||
*/
|
||||
int nic_attribute(VectorAttribute * nic, int uid, int vid);
|
||||
int nic_attribute(VectorAttribute * nic, int uid, int vid, string& error_str);
|
||||
|
||||
/**
|
||||
* Generates an Authorization token for a NIC attribute
|
||||
@ -171,12 +172,13 @@ private:
|
||||
*/
|
||||
VirtualNetwork * get_nic_by_name(VectorAttribute * nic,
|
||||
const string& name,
|
||||
int _uid);
|
||||
int _uidi,
|
||||
string& error);
|
||||
|
||||
/**
|
||||
* Function to get a VirtualNetwork by its id, as provided by a VM template
|
||||
*/
|
||||
VirtualNetwork * get_nic_by_id(const string& id_s);
|
||||
VirtualNetwork * get_nic_by_id(const string& id_s, string& error);
|
||||
};
|
||||
|
||||
#endif /*VIRTUAL_NETWORK_POOL_H_*/
|
||||
|
@ -22,7 +22,7 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
Image * ImageManager::acquire_image(int image_id)
|
||||
Image * ImageManager::acquire_image(int image_id, string& error)
|
||||
{
|
||||
Image * img;
|
||||
int rc;
|
||||
@ -31,10 +31,14 @@ Image * ImageManager::acquire_image(int image_id)
|
||||
|
||||
if ( img == 0 )
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Image with ID: " << image_id << " does not exists";
|
||||
|
||||
error = oss.str();
|
||||
return 0;
|
||||
}
|
||||
|
||||
rc = acquire_image(img);
|
||||
rc = acquire_image(img, error);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
@ -47,7 +51,7 @@ Image * ImageManager::acquire_image(int image_id)
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
Image * ImageManager::acquire_image(const string& name, int uid)
|
||||
Image * ImageManager::acquire_image(const string& name, int uid, string& error)
|
||||
{
|
||||
Image * img;
|
||||
int rc;
|
||||
@ -56,10 +60,14 @@ Image * ImageManager::acquire_image(const string& name, int uid)
|
||||
|
||||
if ( img == 0 )
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Image " << name << " does not exists for user " << uid;
|
||||
|
||||
error = oss.str();
|
||||
return 0;
|
||||
}
|
||||
|
||||
rc = acquire_image(img);
|
||||
rc = acquire_image(img, error);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
@ -72,7 +80,7 @@ Image * ImageManager::acquire_image(const string& name, int uid)
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int ImageManager::acquire_image(Image *img)
|
||||
int ImageManager::acquire_image(Image *img, string& error)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
@ -87,7 +95,8 @@ int ImageManager::acquire_image(Image *img)
|
||||
case Image::USED:
|
||||
if (img->isPersistent())
|
||||
{
|
||||
rc = -1;
|
||||
error = "Cannot aquire persistent image, it is already in use";
|
||||
rc = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -97,10 +106,19 @@ int ImageManager::acquire_image(Image *img)
|
||||
break;
|
||||
|
||||
case Image::DISABLED:
|
||||
error = "Cannot aquire image, it is disabled";
|
||||
rc = -1;
|
||||
break;
|
||||
case Image::LOCKED:
|
||||
error = "Cannot aquire image, it is locked";
|
||||
rc = -1;
|
||||
break;
|
||||
case Image::ERROR:
|
||||
error = "Cannot aquire image, it is in an error state";
|
||||
rc = -1;
|
||||
break;
|
||||
default:
|
||||
rc = -1;
|
||||
rc = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -216,7 +216,8 @@ int ImagePool::disk_attribute(VectorAttribute * disk,
|
||||
int * index,
|
||||
Image::ImageType * img_type,
|
||||
int uid,
|
||||
int& image_id)
|
||||
int& image_id,
|
||||
string& error_str)
|
||||
{
|
||||
string source;
|
||||
Image * img = 0;
|
||||
@ -227,8 +228,6 @@ int ImagePool::disk_attribute(VectorAttribute * disk,
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
ImageManager * imagem = nd.get_imagem();
|
||||
DatastorePool * ds_pool = nd.get_dspool();
|
||||
Datastore * ds = 0;
|
||||
|
||||
if (!(source = disk->vector_value("IMAGE")).empty())
|
||||
{
|
||||
@ -236,10 +235,11 @@ int ImagePool::disk_attribute(VectorAttribute * disk,
|
||||
|
||||
if ( uiid == -1)
|
||||
{
|
||||
error_str = "Cannot get user set in IMAGE_UID or IMAGE_UNAME.";
|
||||
return -1;
|
||||
}
|
||||
|
||||
img = imagem->acquire_image(source, uiid);
|
||||
img = imagem->acquire_image(source, uiid, error_str);
|
||||
|
||||
if ( img == 0 )
|
||||
{
|
||||
@ -252,13 +252,15 @@ int ImagePool::disk_attribute(VectorAttribute * disk,
|
||||
|
||||
if ( iid == -1)
|
||||
{
|
||||
error_str = "Wrong ID set in IMAGE_ID";
|
||||
return -1;
|
||||
}
|
||||
|
||||
img = imagem->acquire_image(iid);
|
||||
img = imagem->acquire_image(iid, error_str);
|
||||
|
||||
if ( img == 0 )
|
||||
{
|
||||
error_str = "Cannot acquire image, it does not exists or in use.";
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -288,6 +290,9 @@ int ImagePool::disk_attribute(VectorAttribute * disk,
|
||||
|
||||
if ( img != 0 )
|
||||
{
|
||||
DatastorePool * ds_pool = nd.get_dspool();
|
||||
Datastore * ds;
|
||||
|
||||
img->disk_attribute(disk, index, img_type);
|
||||
|
||||
image_id = img->get_oid();
|
||||
@ -301,6 +306,7 @@ int ImagePool::disk_attribute(VectorAttribute * disk,
|
||||
|
||||
if ( ds == 0 )
|
||||
{
|
||||
error_str = "Associated datastore for the image does not exist";
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -743,8 +743,13 @@ int VirtualMachine::get_disk_images(string& error_str)
|
||||
continue;
|
||||
}
|
||||
|
||||
rc = ipool->disk_attribute(disk, i, &index, &img_type, uid, image_id);
|
||||
|
||||
rc = ipool->disk_attribute(disk,
|
||||
i,
|
||||
&index,
|
||||
&img_type,
|
||||
uid,
|
||||
image_id,
|
||||
error_str);
|
||||
if (rc == 0 )
|
||||
{
|
||||
acquired_images.push_back(image_id);
|
||||
@ -781,7 +786,7 @@ int VirtualMachine::get_disk_images(string& error_str)
|
||||
}
|
||||
else if ( rc == -1 )
|
||||
{
|
||||
goto error_image;
|
||||
goto error_common;
|
||||
}
|
||||
}
|
||||
|
||||
@ -799,10 +804,6 @@ error_max_db:
|
||||
error_str = "VM can not use more than 10 DATABLOCK images.";
|
||||
goto error_common;
|
||||
|
||||
error_image:
|
||||
error_str = "Could not get disk image for VM.";
|
||||
goto error_common;
|
||||
|
||||
error_common:
|
||||
ImageManager * imagem = nd.get_imagem();
|
||||
|
||||
@ -893,19 +894,15 @@ int VirtualMachine::get_network_leases(string& estr)
|
||||
continue;
|
||||
}
|
||||
|
||||
rc = vnpool->nic_attribute(nic, uid, oid);
|
||||
rc = vnpool->nic_attribute(nic, uid, oid, estr);
|
||||
|
||||
if (rc == -1)
|
||||
{
|
||||
goto error_vnet;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
error_vnet:
|
||||
estr = "Could not get virtual network for VM.";
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -620,8 +620,8 @@ int VirtualNetwork::nic_attribute(VectorAttribute *nic, int vid)
|
||||
|
||||
ostringstream vnid;
|
||||
|
||||
ip = nic->vector_value("IP");
|
||||
vnid << oid;
|
||||
ip = nic->vector_value("IP");
|
||||
vnid << oid;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// GET NETWORK LEASE
|
||||
|
@ -141,7 +141,8 @@ error_common:
|
||||
|
||||
VirtualNetwork * VirtualNetworkPool::get_nic_by_name(VectorAttribute * nic,
|
||||
const string& name,
|
||||
int _uid)
|
||||
int _uid,
|
||||
string& error)
|
||||
{
|
||||
istringstream is;
|
||||
|
||||
@ -149,6 +150,8 @@ VirtualNetwork * VirtualNetworkPool::get_nic_by_name(VectorAttribute * nic,
|
||||
string uname;
|
||||
int uid;
|
||||
|
||||
VirtualNetwork * vnet;
|
||||
|
||||
if (!(uid_s = nic->vector_value("NETWORK_UID")).empty())
|
||||
{
|
||||
is.str(uid_s);
|
||||
@ -156,6 +159,7 @@ VirtualNetwork * VirtualNetworkPool::get_nic_by_name(VectorAttribute * nic,
|
||||
|
||||
if( is.fail() )
|
||||
{
|
||||
error = "Cannot get user in NETWORK_UID";
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -169,6 +173,7 @@ VirtualNetwork * VirtualNetworkPool::get_nic_by_name(VectorAttribute * nic,
|
||||
|
||||
if ( user == 0 )
|
||||
{
|
||||
error = "User set in NETWORK_UNAME does not exist";
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -181,39 +186,63 @@ VirtualNetwork * VirtualNetworkPool::get_nic_by_name(VectorAttribute * nic,
|
||||
uid = _uid;
|
||||
}
|
||||
|
||||
return get(name,uid,true);
|
||||
vnet = get(name,uid,true);
|
||||
|
||||
if (vnet == 0)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Virtual network " << name << " does not exist for user " << uid;
|
||||
|
||||
error = oss.str();
|
||||
}
|
||||
|
||||
return vnet;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
VirtualNetwork * VirtualNetworkPool::get_nic_by_id(const string& id_s)
|
||||
VirtualNetwork * VirtualNetworkPool::get_nic_by_id(const string& id_s,
|
||||
string& error)
|
||||
{
|
||||
istringstream is;
|
||||
int id;
|
||||
|
||||
VirtualNetwork * vnet = 0;
|
||||
|
||||
is.str(id_s);
|
||||
is >> id;
|
||||
|
||||
if( is.fail() )
|
||||
if( !is.fail() )
|
||||
{
|
||||
return 0;
|
||||
vnet = get(id,true);
|
||||
}
|
||||
|
||||
return get(id,true);
|
||||
if (vnet == 0)
|
||||
{
|
||||
ostringstream oss;
|
||||
oss << "Virtual network with ID: " << id_s << " does not exist";
|
||||
|
||||
error = oss.str();
|
||||
}
|
||||
|
||||
return vnet;
|
||||
}
|
||||
|
||||
int VirtualNetworkPool::nic_attribute(VectorAttribute * nic, int uid, int vid)
|
||||
int VirtualNetworkPool::nic_attribute(VectorAttribute * nic,
|
||||
int uid,
|
||||
int vid,
|
||||
string& error)
|
||||
{
|
||||
string network;
|
||||
VirtualNetwork * vnet = 0;
|
||||
|
||||
if (!(network = nic->vector_value("NETWORK")).empty())
|
||||
{
|
||||
vnet = get_nic_by_name (nic, network, uid);
|
||||
vnet = get_nic_by_name (nic, network, uid, error);
|
||||
}
|
||||
else if (!(network = nic->vector_value("NETWORK_ID")).empty())
|
||||
{
|
||||
vnet = get_nic_by_id(network);
|
||||
vnet = get_nic_by_id(network, error);
|
||||
}
|
||||
else //Not using a pre-defined network
|
||||
{
|
||||
@ -231,6 +260,10 @@ int VirtualNetworkPool::nic_attribute(VectorAttribute * nic, int uid, int vid)
|
||||
{
|
||||
update(vnet);
|
||||
}
|
||||
else
|
||||
{
|
||||
error = "Cannot get IP/MAC lease from virtual network.";
|
||||
}
|
||||
|
||||
vnet->unlock();
|
||||
|
||||
@ -247,14 +280,15 @@ void VirtualNetworkPool::authorize_nic(VectorAttribute * nic,
|
||||
string network;
|
||||
VirtualNetwork * vnet = 0;
|
||||
PoolObjectAuth perm;
|
||||
string error;
|
||||
|
||||
if (!(network = nic->vector_value("NETWORK")).empty())
|
||||
{
|
||||
vnet = get_nic_by_name (nic, network, uid);
|
||||
vnet = get_nic_by_name (nic, network, uid, error);
|
||||
}
|
||||
else if (!(network = nic->vector_value("NETWORK_ID")).empty())
|
||||
{
|
||||
vnet = get_nic_by_id(network);
|
||||
vnet = get_nic_by_id(network, error);
|
||||
}
|
||||
else //Not using a pre-defined network
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user