mirror of
https://github.com/OpenNebula/one.git
synced 2025-04-01 06:50:25 +03:00
feature #200: New enable/publish methods, changed ImagePool interface for modifying template attributes.
This commit is contained in:
parent
09adf06c4b
commit
1c9e70dd80
@ -152,16 +152,21 @@ public:
|
||||
|
||||
/**
|
||||
* Enables the image
|
||||
* @param to_enable true will enable the image.
|
||||
* @return 0 on success
|
||||
*/
|
||||
int enable()
|
||||
int enable(bool to_enable)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
if (state == DISABLED)
|
||||
if ((to_enable == true) && (state == DISABLED))
|
||||
{
|
||||
state = READY;
|
||||
}
|
||||
else if ((to_enable == false) && (state == READY))
|
||||
{
|
||||
state = DISABLED;
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = -1;
|
||||
@ -171,23 +176,20 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables the image
|
||||
* Publish or unpublish an image
|
||||
* @param pub true to publish the image
|
||||
* @return 0 on success
|
||||
*/
|
||||
int disable()
|
||||
void publish(bool pub)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
if (state == READY)
|
||||
if (pub == true)
|
||||
{
|
||||
state = DISABLED;
|
||||
public_img = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = -1;
|
||||
public_img = 0;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -261,29 +263,6 @@ public:
|
||||
image_template.get(str,value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates the template of an Image, adding a new attribute (replacing it
|
||||
* if already defined), the image's mutex SHOULD be locked
|
||||
* @param db pointer to the database
|
||||
* @param name of the new attribute
|
||||
* @param value of the new attribute
|
||||
* @return 0 on success
|
||||
*/
|
||||
int update_template_attribute(
|
||||
SqlDB * db,
|
||||
string& name,
|
||||
string& value)
|
||||
{
|
||||
SingleAttribute * sattr;
|
||||
int rc;
|
||||
|
||||
sattr = new SingleAttribute(name,value);
|
||||
rc = image_template.replace_attribute(db,sattr);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an Image attribute
|
||||
* @param name of the attribute
|
||||
|
@ -48,7 +48,7 @@ public:
|
||||
* @param uid the user id of the image's owner
|
||||
* @param stemplate template associated with the image
|
||||
* @param oid the id assigned to the Image
|
||||
* @return the oid assigned to the object,
|
||||
* @return the oid assigned to the object,
|
||||
* -1 in case of failure
|
||||
* -2 in case of template parse failure
|
||||
*/
|
||||
@ -70,7 +70,7 @@ public:
|
||||
{
|
||||
return static_cast<Image *>(PoolSQL::get(oid,lock));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Function to get an Image from the pool using the image name
|
||||
* @param name of the image
|
||||
@ -101,7 +101,7 @@ public:
|
||||
{
|
||||
return image->update(db);
|
||||
};
|
||||
|
||||
|
||||
/** Drops an image from the DB, the image mutex MUST BE locked
|
||||
* @param image pointer to Image
|
||||
* @return 0 on success
|
||||
@ -117,34 +117,34 @@ public:
|
||||
|
||||
return rc;
|
||||
};
|
||||
|
||||
/** Modify an image attribute in the template OR the public attribute
|
||||
* and updates it in the DB (Image MUST be locked)
|
||||
|
||||
/** Modify an image attribute in the template (Image MUST be locked)
|
||||
* @param image pointer to Image
|
||||
* @param name of the attribute to be changed
|
||||
* @param new value for the attribute
|
||||
* @return 0 on success, -1 otherwise
|
||||
*/
|
||||
int modify_image_attribute(
|
||||
Image * image,
|
||||
string& name,
|
||||
string& value)
|
||||
int replace_attribute(
|
||||
Image * image,
|
||||
const string& name,
|
||||
const string& value)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
if ( name == "PUBLIC" && ( value == "YES" || value == "NO" ))
|
||||
{
|
||||
image->public_img = value=="YES"?1:0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return image->update_template_attribute(db, name, value);
|
||||
}
|
||||
|
||||
image->update(db);
|
||||
|
||||
return rc;
|
||||
}
|
||||
SingleAttribute * sattr = new SingleAttribute(name,value);
|
||||
|
||||
return image->image_template.replace_attribute(db,sattr);
|
||||
}
|
||||
|
||||
/** Delete an image attribute in the template (Image MUST be locked)
|
||||
* @param image pointer to Image
|
||||
* @param name of the attribute to be removed
|
||||
* @return 0 on success, -1 otherwise
|
||||
*/
|
||||
int remove_attribute(
|
||||
Image * image,
|
||||
const string& name)
|
||||
{
|
||||
return image->image_template.remove_attribute(db, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstraps the database table(s) associated to the Image pool
|
||||
@ -153,7 +153,7 @@ public:
|
||||
{
|
||||
Image::bootstrap(_db);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Dumps the Image pool in XML format. A filter can be also added to the
|
||||
* query
|
||||
@ -168,12 +168,12 @@ private:
|
||||
* This map stores the association between IIDs and Image names
|
||||
*/
|
||||
map<string, int> image_names;
|
||||
|
||||
|
||||
/**
|
||||
* Path to the image repository
|
||||
**/
|
||||
string source_prefix;
|
||||
|
||||
|
||||
/**
|
||||
* Default image type
|
||||
**/
|
||||
@ -183,7 +183,7 @@ private:
|
||||
* Default device prefix
|
||||
**/
|
||||
string default_dev_prefix;
|
||||
|
||||
|
||||
/**
|
||||
* Factory method to produce Image objects
|
||||
* @return a pointer to the new Image
|
||||
|
Loading…
x
Reference in New Issue
Block a user