[pve-devel] [PATCH manager v2 2/5] make clone window guest agnostic

Dominik Csapak d.csapak at proxmox.com
Wed Mar 21 15:12:14 CET 2018


so that we can reuse it for containers

while we do this, we also have to adapt the SnapshotSelector

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 www/manager6/form/SnapshotSelector.js |  6 +++++-
 www/manager6/qemu/CmdMenu.js          |  2 +-
 www/manager6/qemu/Config.js           |  2 +-
 www/manager6/window/Clone.js          | 33 +++++++++++++++++++++++----------
 4 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/www/manager6/form/SnapshotSelector.js b/www/manager6/form/SnapshotSelector.js
index 1ed420ab..96ee08c7 100644
--- a/www/manager6/form/SnapshotSelector.js
+++ b/www/manager6/form/SnapshotSelector.js
@@ -22,7 +22,7 @@ Ext.define('PVE.form.SnapshotSelector', {
 
 	me.store.setProxy({
 	    type: 'proxmox',
-	    url: '/api2/json/nodes/' + me.nodename + '/qemu/' + me.vmid +'/snapshot'
+	    url: '/api2/json/nodes/' + me.nodename + '/' + me.guestType + '/' + me.vmid +'/snapshot'
 	});
 
 	me.store.load();
@@ -39,6 +39,10 @@ Ext.define('PVE.form.SnapshotSelector', {
             throw "no VM ID specified";
         }
 
+	if (!me.guestType) {
+	    throw "no guest type specified";
+	}
+
 	var store = Ext.create('Ext.data.Store', {
 	    fields: [ 'name'],
 	    filterOnLoad: true
diff --git a/www/manager6/qemu/CmdMenu.js b/www/manager6/qemu/CmdMenu.js
index 49ea62bc..00af7cbc 100644
--- a/www/manager6/qemu/CmdMenu.js
+++ b/www/manager6/qemu/CmdMenu.js
@@ -133,7 +133,7 @@ Ext.define('PVE.qemu.CmdMenu', {
 		iconCls: 'fa fa-fw fa-clone',
 		hidden: !caps.vms['VM.Clone'],
 		handler: function() {
-		    PVE.window.Clone.wrap(nodename, vmid, me.isTemplate);
+		    PVE.window.Clone.wrap(nodename, vmid, me.isTemplate, 'qemu');
 		}
 	    },
 	    {
diff --git a/www/manager6/qemu/Config.js b/www/manager6/qemu/Config.js
index 5de39fc3..38496f4f 100644
--- a/www/manager6/qemu/Config.js
+++ b/www/manager6/qemu/Config.js
@@ -85,7 +85,7 @@ Ext.define('PVE.qemu.Config', {
 		    iconCls: 'fa fa-fw fa-clone',
 		    hidden: caps.vms['VM.Clone'] ? false : true,
 		    handler: function() {
-			PVE.window.Clone.wrap(nodename, vmid, template);
+			PVE.window.Clone.wrap(nodename, vmid, template, 'qemu');
 		    }
 		},
 		{
diff --git a/www/manager6/window/Clone.js b/www/manager6/window/Clone.js
index 0df7825e..bb7ab6e8 100644
--- a/www/manager6/window/Clone.js
+++ b/www/manager6/window/Clone.js
@@ -21,9 +21,9 @@ Ext.define('PVE.window.Clone', {
 
     statics: {
 	// display a snapshot selector only if needed
-	wrap: function(nodename, vmid, isTemplate) {
+	wrap: function(nodename, vmid, isTemplate, guestType) {
 	    Proxmox.Utils.API2Request({
-		url: '/nodes/' + nodename + '/qemu/' + vmid +'/snapshot',
+		url: '/nodes/' + nodename + '/' + guestType + '/' + vmid +'/snapshot',
 		failure: function(response, opts) {
 		    Ext.Msg.alert('Error', response.htmlStatus);
 		},
@@ -34,6 +34,7 @@ Ext.define('PVE.window.Clone', {
 
 		    Ext.create('PVE.window.Clone', {
 			nodename: nodename,
+			guestType: guestType,
 			vmid: vmid,
 			isTemplate: isTemplate,
 			hasSnapshots: hasSnapshots
@@ -57,7 +58,11 @@ Ext.define('PVE.window.Clone', {
 	}
 
 	if (values.name) {
-	    params.name = values.name;
+	    if (me.guestType === 'lxc') {
+		params.hostname = values.name;
+	    } else {
+		params.name = values.name;
+	    }
 	}
 
 	if (values.target) {
@@ -68,7 +73,7 @@ Ext.define('PVE.window.Clone', {
 	    params.full = 1;
 	    if (values.hdstorage) {
 		params.storage = values.hdstorage;
-		if (values.diskformat) {
+		if (values.diskformat && me.guestType !== 'lxc') {
 		    params.format = values.diskformat;
 		}
 	    }
@@ -76,7 +81,7 @@ Ext.define('PVE.window.Clone', {
 
 	Proxmox.Utils.API2Request({
 	    params: params,
-	    url: '/nodes/' + me.nodename + '/qemu/' + me.vmid + '/clone',
+	    url: '/nodes/' + me.nodename + '/' + me.guestType + '/' + me.vmid + '/clone',
 	    waitMsgTarget: me,
 	    method: 'POST',
 	    failure: function(response, opts) {
@@ -112,7 +117,7 @@ Ext.define('PVE.window.Clone', {
 
 	Proxmox.Utils.API2Request({
 	    waitMsgTarget: me,
-	    url: '/nodes/' + me.nodename + '/qemu/' + me.vmid + '/feature',
+	    url: '/nodes/' + me.nodename + '/' + me.guestType + '/' + me.vmid + '/feature',
 	    params: params,
 	    method: 'GET',
 	    failure: function(response, opts) {
@@ -143,7 +148,14 @@ Ext.define('PVE.window.Clone', {
 	    me.snapname = 'current';
 	}
 
-	var titletext = me.isTemplate ? "Template" : "VM";
+	if (!me.guestType) {
+	    throw "no Guest Type specified";
+	}
+
+	var titletext = me.guestType === 'lxc' ? 'CT' : 'VM';
+	if (me.isTemplate) {
+	    titletext += ' Template';
+	}
 	me.title = "Clone " + titletext + " " + me.vmid;
 
 	var col1 = [];
@@ -172,7 +184,7 @@ Ext.define('PVE.window.Clone', {
 	col1.push({
 	    xtype: 'pveGuestIDSelector',
 	    name: 'newvmid',
-	    guestType: 'qemu',
+	    guestType: me.guestType,
 	    value: '',
 	    loadNextFreeID: true,
 	    validateExists: false
@@ -181,7 +193,7 @@ Ext.define('PVE.window.Clone', {
 	    xtype: 'textfield',
 	    name: 'name',
 	    allowBlank: true,
-	    fieldLabel: gettext('Name')
+	    fieldLabel: me.guestType === 'lxc' ? gettext('Hostname') : gettext('Name')
 	},
 	{
 	    xtype: 'pvePoolSelector',
@@ -214,6 +226,7 @@ Ext.define('PVE.window.Clone', {
 	    reference: 'snapshotsel',
 	    fieldLabel: gettext('Snapshot'),
 	    nodename: me.nodename,
+	    guestType: me.guestType,
 	    vmid: me.vmid,
 	    hidden: me.isTemplate || !me.hasSnapshots ? true : false,
 	    disabled: false,
@@ -234,7 +247,7 @@ Ext.define('PVE.window.Clone', {
 	    hideSelection: true,
 	    storageLabel: gettext('Target Storage'),
 	    allowBlank: true,
-	    storageContent: 'images',
+	    storageContent: me.guestType === 'qemu' ? 'images' : 'rootdir',
 	    emptyText: gettext('Same as source'),
 	    disabled: me.isTemplate ? true : false // because default mode is clone for templates
 	});
-- 
2.11.0





More information about the pve-devel mailing list