mirror of
https://github.com/OpenNebula/one.git
synced 2025-02-22 17:57:46 +03:00
feature #523: work on the release image methods
This commit is contained in:
parent
23ea7a6a97
commit
9db8829d35
@ -94,6 +94,15 @@ public:
|
||||
return (persistent_img == 1);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the source path of the image
|
||||
* @return source of image
|
||||
*/
|
||||
const string& get_source()
|
||||
{
|
||||
return source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the image state
|
||||
* @return state of image
|
||||
|
@ -172,6 +172,13 @@ private:
|
||||
* @return 0 on success
|
||||
*/
|
||||
int acquire_image(Image *img);
|
||||
|
||||
/**
|
||||
* Moves a file to an image in the repository
|
||||
* @param image to be updated (it's source attribute)
|
||||
* @param source path of the disk file
|
||||
*/
|
||||
void move_image(Image *img, const string& source);
|
||||
};
|
||||
|
||||
#endif /*IMAGE_MANAGER_H*/
|
||||
|
@ -70,7 +70,7 @@ private:
|
||||
*/
|
||||
//Template driver_conf;
|
||||
|
||||
void cp(int oid, const string& source, const string& destination);
|
||||
void cp(int oid, const string& source, const string& destination) const;
|
||||
|
||||
/**
|
||||
* Sends a move request to the MAD: "MV IMAGE_ID SRC_PATH DST_PATH"
|
||||
@ -78,7 +78,7 @@ private:
|
||||
* @param destination is the path to the image to be created
|
||||
* @param size_mb of the image to be created
|
||||
*/
|
||||
void mv(int oid, const string& source, const string& destination);
|
||||
void mv(int oid, const string& source, const string& destination) const;
|
||||
|
||||
/**
|
||||
* Sends a make filesystem request to the MAD: "MKFS IMAGE_ID PATH SIZE_MB"
|
||||
@ -87,14 +87,17 @@ private:
|
||||
* @param fs type
|
||||
* @param size_mb of the image to be created
|
||||
*/
|
||||
void mkfs(int oid, const string& destination, const string& fs, int size_mb);
|
||||
void mkfs(int oid,
|
||||
const string& destination,
|
||||
const string& fs,
|
||||
int size_mb) const;
|
||||
|
||||
/**
|
||||
* Sends a delete request to the MAD: "DELETE IMAGE_ID PATH"
|
||||
* @param oid the image id.
|
||||
* @param destination is the path to the image to be removed
|
||||
*/
|
||||
void rm(int oid, const string& destination);
|
||||
void rm(int oid, const string& destination) const;
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -80,6 +80,7 @@ int ImageManager::acquire_image(Image *img)
|
||||
case Image::READY:
|
||||
img->inc_running();
|
||||
img->set_state(Image::USED);
|
||||
ipool->update(img);
|
||||
break;
|
||||
|
||||
case Image::USED:
|
||||
@ -90,6 +91,7 @@ int ImageManager::acquire_image(Image *img)
|
||||
else
|
||||
{
|
||||
img->inc_running();
|
||||
ipool->update(img);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -103,6 +105,28 @@ int ImageManager::acquire_image(Image *img)
|
||||
|
||||
return rc;
|
||||
}
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void ImageManager::move_image(Image *img, const string& source)
|
||||
{
|
||||
const ImageManagerDriver* imd = get();
|
||||
ostringstream oss;
|
||||
|
||||
if ( imd == 0 )
|
||||
{
|
||||
NebulaLog::log("ImM",Log::ERROR,
|
||||
"Could not get driver to update repository");
|
||||
return;
|
||||
}
|
||||
|
||||
oss << "Moving disk " << source << " to repository image "
|
||||
<< img->get_oid() << " as " << img->get_source();
|
||||
|
||||
imd->mv(img->get_oid(),source,img->get_source());
|
||||
|
||||
NebulaLog::log("ImM",Log::INFO,oss);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -120,6 +144,8 @@ void ImageManager::release_image(const string& image_id,
|
||||
istringstream iss;
|
||||
Image * img;
|
||||
|
||||
ostringstream disk_file;
|
||||
|
||||
iss.str(image_id);
|
||||
|
||||
iss >> iid;
|
||||
@ -145,12 +171,15 @@ void ImageManager::release_image(const string& image_id,
|
||||
|
||||
if ( img->isPersistent() )
|
||||
{
|
||||
disk_file << disk_path << "/disk." << disk_num;
|
||||
|
||||
img->set_state(Image::LOCKED);
|
||||
|
||||
//TODO issue move from disk to source (imgage)
|
||||
move_image(img,disk_file.str());
|
||||
|
||||
ipool->update(img);
|
||||
|
||||
img->unlock();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -159,6 +188,8 @@ void ImageManager::release_image(const string& image_id,
|
||||
img->set_state(Image::READY);
|
||||
}
|
||||
|
||||
ipool->update(img);
|
||||
|
||||
img->unlock();
|
||||
|
||||
if ( sid != -1 )
|
||||
@ -167,10 +198,15 @@ void ImageManager::release_image(const string& image_id,
|
||||
|
||||
if ( img == 0 )
|
||||
{
|
||||
//TODO Warning in oned.log
|
||||
NebulaLog::log("ImM",Log::ERROR,
|
||||
"Could not get image to saveas disk.");
|
||||
}
|
||||
else
|
||||
{
|
||||
disk_file << disk_path << "/disk." << disk_num;
|
||||
|
||||
//TODO issue move from disk to source (save_image)
|
||||
move_image(img,disk_file.str());
|
||||
}
|
||||
|
||||
img->unlock();
|
||||
}
|
||||
@ -181,6 +217,8 @@ void ImageManager::release_image(const string& image_id,
|
||||
case Image::READY:
|
||||
case Image::ERROR:
|
||||
case Image::LOCKED:
|
||||
NebulaLog::log("ImM",Log::ERROR,
|
||||
"Trying to release image in wrong state.");
|
||||
default:
|
||||
img->unlock();
|
||||
break;
|
||||
|
@ -28,7 +28,7 @@
|
||||
|
||||
void ImageManagerDriver::cp(int oid,
|
||||
const string& source,
|
||||
const string& destination)
|
||||
const string& destination) const
|
||||
{
|
||||
ostringstream os;
|
||||
|
||||
@ -41,7 +41,7 @@ void ImageManagerDriver::cp(int oid,
|
||||
|
||||
void ImageManagerDriver::mv(int oid,
|
||||
const string& source,
|
||||
const string& destination)
|
||||
const string& destination) const
|
||||
{
|
||||
ostringstream os;
|
||||
|
||||
@ -55,7 +55,7 @@ void ImageManagerDriver::mv(int oid,
|
||||
void ImageManagerDriver::mkfs(int oid,
|
||||
const string& destination,
|
||||
const string& fs,
|
||||
int size_mb)
|
||||
int size_mb) const
|
||||
{
|
||||
ostringstream os;
|
||||
|
||||
@ -66,7 +66,7 @@ void ImageManagerDriver::mkfs(int oid,
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void ImageManagerDriver::rm(int oid, const string& destination)
|
||||
void ImageManagerDriver::rm(int oid, const string& destination) const
|
||||
{
|
||||
ostringstream os;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user