F #1147: Permit to rename disk snapshot names. Sunstone changes TBD

* Add disk snaphsot rename option

* F #1147: Fis some bugs

* F #1147: Fis a bug

* F #1147: Add disksnapshotrename method to the oca

* F #1147: Add onevm disk-snapshot-rename commad

* F #1147: Fix a bug

* Do not update VM if not needed

* Add disk-snapshot-rename to list of HISTORY_ACTIONS

* Update RequestManagerVirtualMachine.cc
This commit is contained in:
Christian González authored and Ruben S. Montero committed 2018-09-25 14:33:21 +02:00
1 parent ccacaa1404
commit 1cdaff4e60
17 files changed
+239 -2

No files matched your search

+2 -1
View File
@@ -76,7 +76,8 @@ public:
DISK_SNAPSHOT_REVERT_ACTION = 41, // "one.vm.disksnapshotrevert"
RECOVER_ACTION = 42, // "one.vm.recover"
RETRY_ACTION = 43, // "one.vm.recover"
MONITOR_ACTION = 44 // internal, monitoring process
MONITOR_ACTION = 44, // internal, monitoring process
DISK_SNAPSHOT_RENAME_ACTION = 45 // "one.vm.disksnapshotrename"
};
static string action_to_str(VMAction action);
+22
View File
@@ -521,6 +521,28 @@ private:
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
class VirtualMachineDiskSnapshotRename: public RequestManagerVirtualMachine
{
public:
VirtualMachineDiskSnapshotRename():
RequestManagerVirtualMachine("one.vm.disksnapshotrename",
"Rename a disk snapshot",
"A:siiis"){
Nebula& nd = Nebula::instance();
//All VM disk snapshot operations are set to the same auth value
auth_op = nd.get_vm_auth_op(History::DISK_SNAPSHOT_RENAME_ACTION);
};
~VirtualMachineDiskSnapshotRename(){};
void request_execute(xmlrpc_c::paramList const& _paramList,
RequestAttributes& att);
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
class VirtualMachineUpdateConf: public RequestManagerVirtualMachine
{
public:
+6
View File
@@ -101,6 +101,12 @@ public:
*/
int active_snapshot(int id);
/**
* Rename the given snapshot by the given name
*/
int rename_snapshot(int id, const string& name, string& str_error);
/**
* Clear all the snapshots in the list
*/
+13
View File
@@ -1481,6 +1481,19 @@ public:
disks.delete_snapshot(disk_id, snap_id, ds_quotas, vm_quotas, io, vo);
}
/**
* Renames the snap_id from the list
* @param disk_id of the disk
* @param snap_id of the snapshot
* @param new_name of the snapshot
* @return 0 on success
*/
int rename_disk_snapshot(int disk_id, int snap_id, const string& new_name,
string& error_str)
{
return disks.rename_snapshot(disk_id, snap_id, new_name, error_str);
}
/**
* Deletes all the disk snapshots for non-persistent disks and for persistent
* disks in no shared system ds.
+27
View File
@@ -256,6 +256,24 @@ public:
return (snapshots != 0);
}
/**
* Renames a snapshot
*
* @param id_snap of the snapshot
* @param new_name of the snapshot
* @return 0 on success
*/
int rename_snapshot(int snap_id, const string& new_name, string& str_error)
{
if (!snapshots)
{
str_error = "The VM does not have any snapshot";
return -1;
}
return snapshots->rename_snapshot(snap_id, new_name, str_error);
}
/**
* Creates a new snapshot of the disk
* @param name a description for this snapshot
@@ -734,6 +752,15 @@ public:
void delete_snapshot(int disk_id, int snap_id, Template **ds_quota,
Template **vm_quota, bool& io, bool& vo);
/**
* Renames a given snapshot
* @param disk_id of the disk
* @param snap_id of the snapshot
* @param new_name of the snapshot
* @return 0 on success
*/
int rename_snapshot(int disk_id, int snap_id, const string& new_name, string& str_error);
/**
* Deletes all the disk snapshots for non-persistent disks and for persistent
* disks in no shared system ds.
+1
View File
@@ -76,6 +76,7 @@
RECOVER_ACTION = 42
RETRY_ACTION = 43
MONITOR_ACTION = 44
DISK_SNAPSHOT_RENAME_ACTION = 45
-->
<xs:element name="ACTION" type="xs:integer"/>
<xs:element name="UID" type="xs:integer"/>
+1
View File
@@ -181,6 +181,7 @@
RECOVER_ACTION = 42
RETRY_ACTION = 43
MONITOR_ACTION = 44
DISK_SNAPSHOT_RENAME_ACTION = 45
-->
<xs:element name="ACTION" type="xs:integer"/>
<xs:element name="UID" type="xs:integer"/>
+18
View File
@@ -870,6 +870,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
States: RUNNING, POWEROFF, SUSPENDED
EOT
command :"disk-snapshot-delete", disk_snapshot_delete_desc,
:vmid, :diskid, :disk_snapshot_id do
helper.perform_action(args[0],options,"disk snapshot deleted") do |o|
@@ -877,6 +878,23 @@ cmd=CommandParser::CmdParser.new(ARGV) do
end
end
disk_snapshot_rename_desc = <<-EOT.unindent
Renames a disk snapshot.
EOT
command :"disk-snapshot-rename", disk_snapshot_rename_desc,
:vmid, :diskid, :disk_snapshot_id, :new_snapshot_name do
helper.perform_action(args[0],options,"disk snapshot rename") do |o|
is_num = true if Integer(args[2]) rescue false
if !is_num
OpenNebula::Error.new("The disk snapshot ID must be an integer")
else
o.disk_snapshot_rename(args[1].to_i, args[2].to_i, args[3].to_s)
end
end
end
disk_resize_desc = <<-EOT.unindent
Resizes a VM disk. The new size should be larger than the old one.
The valid units are:
+1
View File
@@ -749,6 +749,7 @@ static int _set_vm_auth_ops(const std::string& ops_str,
ops_set.set(History::DISK_SNAPSHOT_CREATE_ACTION);
ops_set.set(History::DISK_SNAPSHOT_DELETE_ACTION);
ops_set.set(History::DISK_SNAPSHOT_REVERT_ACTION);
ops_set.set(History::DISK_SNAPSHOT_RENAME_ACTION);
}
else if ( the_op == "terminate" )
{
+6
View File
@@ -691,6 +691,12 @@ func (vm *VM) SnapshotRevert(snapID int) error {
return err
}
// DiskSnapshotRename renames a snapshot
func (vm *VM) DiskSnapshotRename(diskID, snapID int, newName string) error {
_, err := client.Call("one.vm.disksnapshotrename", vm.ID, diskID, snapID, newName)
return err
}
// Attach a new disk to the virtual machine. diskTemplate is a string containing
// a single DISK vector attribute. Syntax can be the usual attribute=value or
// XML
@@ -51,6 +51,7 @@ public class VirtualMachine extends PoolElement{
private static final String DISKSNAPSHOTCREATE = METHOD_PREFIX + "disksnapshotcreate";
private static final String DISKSNAPSHOTREVERT = METHOD_PREFIX + "disksnapshotrevert";
private static final String DISKSNAPSHOTDELETE = METHOD_PREFIX + "disksnapshotdelete";
private static final String DISKSNAPSHOTRENAME = METHOD_PREFIX + "disksnapshotrename";
private static final String DISKRESIZE = METHOD_PREFIX + "diskresize";
private static final String UPDATECONF = METHOD_PREFIX + "updateconf";
@@ -575,6 +576,23 @@ public class VirtualMachine extends PoolElement{
return client.call(DISKSNAPSHOTDELETE, id, diskId, snapId);
}
/**
* Deletes a disk snapshot
*
* @param client XML-RPC Client.
* @param id The VM id of the target VM.
* @param diskId Id of the disk
* @param snapId Id of the snapshot
* @param new_name New name of the snapshot
* @return If an error occurs the error message contains the reason.
*/
public static OneResponse diskSnapshotRename(Client client, int id,
int diskId, int snapId, String new_name)
{
return client.call(DISKSNAPSHOTRENAME, id, diskId, snapId, new_name);
}
/**
* Resize VM disk
*
+14 -1
View File
@@ -46,6 +46,7 @@ module OpenNebula
:disksnapshotcreate => "vm.disksnapshotcreate",
:disksnapshotrevert => "vm.disksnapshotrevert",
:disksnapshotdelete => "vm.disksnapshotdelete",
:disksnapshotrename => "vm.disksnapshotrename",
:diskresize => "vm.diskresize",
:updateconf => "vm.updateconf",
:lock => "vm.lock",
@@ -211,7 +212,7 @@ module OpenNebula
disk-snapshot-create disk-snapshot-delete terminate terminate-hard
disk-resize deploy chown chmod updateconf rename resize update
snapshot-resize snapshot-delete snapshot-revert disk-saveas
disk-snapshot-revert recover retry monitor}
disk-snapshot-revert recover retry monitor disk-snapshot-rename}
EXTERNAL_IP_ATTRS = [
'GUEST_IP',
@@ -649,6 +650,18 @@ module OpenNebula
return call(VM_METHODS[:disksnapshotdelete], @pe_id, disk_id, snap_id)
end
# Renames a disk snapshot
#
# @param disk_id [Integer] Id of the disk
# @param snap_id [Integer] Id of the snapshot
# @param new_name [String] New name for the snapshot
#
# @return [nil, OpenNebula::Error] nil in case of success, Error
# otherwise
def disk_snapshot_rename(disk_id, snap_id, new_name)
return call(VM_METHODS[:disksnapshotrename], @pe_id, disk_id, snap_id, new_name)
end
# Changes the size of a disk
#
# @param disk_id [Integer] Id of the disk
+2
View File
@@ -304,6 +304,7 @@ void RequestManager::register_xml_methods()
xmlrpc_c::methodPtr vm_dsnap_create(new VirtualMachineDiskSnapshotCreate());
xmlrpc_c::methodPtr vm_dsnap_revert(new VirtualMachineDiskSnapshotRevert());
xmlrpc_c::methodPtr vm_dsnap_delete(new VirtualMachineDiskSnapshotDelete());
xmlrpc_c::methodPtr vm_dsnap_rename(new VirtualMachineDiskSnapshotRename());
xmlrpc_c::methodPtr vm_recover(new VirtualMachineRecover());
xmlrpc_c::methodPtr vm_updateconf(new VirtualMachineUpdateConf());
xmlrpc_c::methodPtr vm_disk_resize(new VirtualMachineDiskResize());
@@ -505,6 +506,7 @@ void RequestManager::register_xml_methods()
RequestManagerRegistry.addMethod("one.vm.disksnapshotcreate", vm_dsnap_create);
RequestManagerRegistry.addMethod("one.vm.disksnapshotrevert", vm_dsnap_revert);
RequestManagerRegistry.addMethod("one.vm.disksnapshotdelete", vm_dsnap_delete);
RequestManagerRegistry.addMethod("one.vm.disksnapshotrename", vm_dsnap_rename);
RequestManagerRegistry.addMethod("one.vm.recover", vm_recover);
RequestManagerRegistry.addMethod("one.vm.updateconf", vm_updateconf);
RequestManagerRegistry.addMethod("one.vm.lock", vm_lock);
+66
View File
@@ -2899,6 +2899,72 @@ void VirtualMachineDiskSnapshotDelete::request_execute(
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualMachineDiskSnapshotRename::request_execute(xmlrpc_c::paramList const& paramList,
RequestAttributes& att)
{
VirtualMachine * vm;
ostringstream oss;
const VirtualMachineDisk * disk;
int rc;
int id = xmlrpc_c::value_int(paramList.getInt(1));
int did = xmlrpc_c::value_int(paramList.getInt(2));
int snap_id = xmlrpc_c::value_int(paramList.getInt(3));
string new_snap_name = xmlrpc_c::value_string(paramList.getString(4));
if ( vm_authorization(id, 0, 0, att, 0, 0, 0, auth_op) == false )
{
return;
}
if ((vm = get_vm(id, att)) == 0)
{
oss << "Could not rename the snapshot for VM " << id
<< ", VM does not exist";
att.resp_msg = oss.str();
return;
}
disk = (const_cast<const VirtualMachine *>(vm))->get_disk(did);
if (disk == 0)
{
att.resp_msg = "VM disk does not exist";
failure_response(ACTION, att);
vm->unlock();
return;
}
rc = vm->rename_disk_snapshot(did, snap_id, new_snap_name, att.resp_msg);
if ( rc != 0 )
{
failure_response(ACTION, att);
vm->unlock();
return;
}
success_response(id, att);
pool->update(vm);
vm->unlock();
return;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualMachineUpdateConf::request_execute(
xmlrpc_c::paramList const& paramList, RequestAttributes& att)
{
+7
View File
@@ -489,6 +489,9 @@ string History::action_to_str(VMAction action)
case DISK_SNAPSHOT_DELETE_ACTION:
st = "disk-snapshot-delete";
break;
case DISK_SNAPSHOT_RENAME_ACTION:
st = "disk-snapshot-rename";
break;
case DISK_RESIZE_ACTION:
st = "disk-resize";
break;
@@ -647,6 +650,10 @@ int History::action_from_str(const string& st, VMAction& action)
{
action = DISK_SNAPSHOT_DELETE_ACTION;
}
else if (st == "disk-snapshot-rename")
{
action = DISK_SNAPSHOT_RENAME_ACTION;
}
else if (st == "disk-resize")
{
action = DISK_RESIZE_ACTION;
+18
View File
@@ -274,6 +274,24 @@ int Snapshots::active_snapshot(int id)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int Snapshots::rename_snapshot(int id, const string& name, string& str_error)
{
VectorAttribute * snapshot = get_snapshot(id);
if (snapshot == 0)
{
str_error = "Snapshot does not exist";
return -1;
}
snapshot->replace("NAME", name);
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
const VectorAttribute * Snapshots::get_snapshot(int id) const
{
map<int, VectorAttribute *>::const_iterator it;
+17
View File
@@ -1381,6 +1381,23 @@ void VirtualMachineDisks::delete_snapshot(int disk_id, int snap_id,
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int VirtualMachineDisks::rename_snapshot(int disk_id, int snap_id, const string& new_name,
string& error_str)
{
VirtualMachineDisk * disk = get_disk(disk_id);
if (disk == 0)
{
error_str = "VM disk does not exist";
return -1;
}
return disk->rename_snapshot(snap_id, new_name, error_str);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualMachineDisks::delete_non_persistent_snapshots(Template **vm_quotas,
vector<Template *> &ds_quotas)
{