[pve-devel] [PATCH 07/10] add clone panel form
Alexandre Derumier
aderumier at odiso.com
Tue Jan 22 10:14:09 CET 2013
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
www/manager/Makefile | 1 +
www/manager/qemu/Clone.js | 278 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 279 insertions(+)
create mode 100644 www/manager/qemu/Clone.js
diff --git a/www/manager/Makefile b/www/manager/Makefile
index a4feb40..9e84ef1 100644
--- a/www/manager/Makefile
+++ b/www/manager/Makefile
@@ -102,6 +102,7 @@ JSSRC= \
qemu/ScsiHwEdit.js \
qemu/Options.js \
qemu/Snapshot.js \
+ qemu/Clone.js \
qemu/SnapshotTree.js \
qemu/Config.js \
qemu/CreateWizard.js \
diff --git a/www/manager/qemu/Clone.js b/www/manager/qemu/Clone.js
new file mode 100644
index 0000000..5fe2c8d
--- /dev/null
+++ b/www/manager/qemu/Clone.js
@@ -0,0 +1,278 @@
+Ext.define('PVE.window.Clone', {
+ extend: 'Ext.window.Window',
+
+ resizable: false,
+
+
+ create_clone: function(snapname, name, newvmid, clonemode, storage, format, diskarray) {
+ var me = this;
+
+ params = { name: name, clonefrom: me.vmid, vmid: newvmid, clonemode: clonemode };
+
+ if (snapname && snapname !== 'current') {
+ params.snapname = snapname;
+ }
+
+ if (clonemode === 'copy' && storage){
+
+ Ext.Array.each(diskarray, function(disk) {
+ var myformat = format ? format : '';
+ params[disk] = storage + ':' + myformat;
+ });
+ }
+
+
+
+ PVE.Utils.API2Request({
+ params: params,
+ url: '/nodes/' + me.nodename + '/qemu',
+ waitMsgTarget: me,
+ method: 'POST',
+ failure: function(response, opts) {
+ Ext.Msg.alert('Error', response.htmlStatus);
+ },
+ success: function(response, options) {
+ me.close();
+ }
+ });
+
+ },
+
+ compute_sel1: function(clonefeature) {
+ var me = this;
+ var list = [];
+ list.push(['copy', 'Copy Clone']);
+ if(clonefeature){
+ list.push(['clone', 'Linked Clone']);
+ }
+ me.kv1.store.loadData(list);
+ me.kv1.setValue(clonefeature ? 'clone' : 'copy');
+ },
+
+ initComponent : function() {
+ var me = this;
+
+ var diskarray = [];
+
+ if (!me.nodename) {
+ throw "no node name specified";
+ }
+
+ if (!me.vmid) {
+ throw "no VM ID specified";
+ }
+
+ me.snapshotsel = Ext.create('PVE.form.SnapshotSelector', {
+ name: 'snapname',
+ fieldLabel: 'Snapshot',
+ nodename: me.nodename,
+ vmid: me.vmid,
+ disabled: false,
+ hidden: false,
+ allowBlank: false,
+ value : me.snapname,
+ listeners: {
+ change: function(f, value) {
+
+ var clonefeature;
+ var istemplate;
+ //check if it's a template
+ //fixme, how to get data from datastore ?
+
+ PVE.Utils.API2Request({
+ url: '/nodes/' + me.nodename + '/qemu/' + me.vmid + '/snapshot',
+ method: 'GET',
+ success: function(response, opts) {
+ Ext.Array.each(response.result.data, function(item) {
+ if(item.name === value && item.template){
+ istemplate = 1;
+ }
+ });
+
+ //check if linked clone feature is available
+ var params = { feature: 'clone' };
+ if (value !== 'current') {
+ params.snapname = value;
+ }
+
+ PVE.Utils.API2Request({
+ waitMsgTarget: me,
+ url: '/nodes/' + me.nodename + '/qemu/' + me.vmid + '/feature',
+ params: params,
+ method: 'GET',
+ success: function(response, options) {
+ var res = response.result.data;
+ if (res === 1 && istemplate) {
+ clonefeature = 1;
+ }
+ me.compute_sel1(clonefeature);
+ }
+ });
+
+ }
+ });
+
+ }
+ }
+ });
+
+
+ var items = [];
+
+ items.push(me.snapshotsel);
+
+ items.push(
+ {
+ xtype: 'pveVMIDSelector',
+ name: 'newvmid',
+ value: '',
+ loadNextFreeVMID: true,
+ validateExists: false
+ },
+ {
+ xtype: 'textfield',
+ name: 'name',
+ allowBlank: false,
+ fieldLabel: 'Name',
+ }
+ );
+
+ me.hdstoragesel = Ext.create('PVE.form.StorageSelector', {
+ name: 'hdstorage',
+ nodename: me.nodename,
+ fieldLabel: 'Target Storage',
+ storageContent: 'images',
+ autoSelect: me.insideWizard,
+ allowBlank: true,
+ disabled: true,
+ hidden: false,
+ listeners: {
+ change: function(f, value) {
+ var rec = f.store.getById(value);
+ if (rec.data.type === 'iscsi') {
+ me.formatsel.setValue('raw');
+ me.formatsel.setDisabled(true);
+ } else if (rec.data.type === 'lvm' ||
+ rec.data.type === 'rbd' ||
+ rec.data.type === 'sheepdog' ||
+ rec.data.type === 'nexenta'
+ ) {
+ me.formatsel.setValue('raw');
+ me.formatsel.setDisabled(true);
+ } else {
+ me.formatsel.setDisabled(false);
+ }
+
+ }
+ }
+
+ });
+
+ me.formatsel = Ext.create('PVE.form.DiskFormatSelector', {
+ name: 'diskformat',
+ fieldLabel: gettext('Format'),
+ value: 'raw',
+ disabled: true,
+ hidden: false,
+ allowBlank: false
+ });
+
+ me.kv1 = Ext.create('PVE.form.KVComboBox', {
+ fieldLabel: 'Clone Mode',
+ name: 'clonemode',
+ allowBlank: false,
+ data: []
+ });
+
+ me.mon(me.kv1, 'change', function(t, value) {
+ if (value === 'copy') {
+ me.hdstoragesel.setDisabled(false);
+ }else{
+ me.hdstoragesel.setDisabled(true);
+ me.formatsel.setDisabled(true);
+ }
+ });
+
+
+ items.push(me.kv1);
+ items.push(me.hdstoragesel);
+ items.push(me.formatsel);
+
+ me.formPanel = Ext.create('Ext.form.Panel', {
+ bodyPadding: 10,
+ border: false,
+ fieldDefaults: {
+ labelWidth: 100,
+ anchor: '100%'
+ },
+ items: items
+ });
+
+ var form = me.formPanel.getForm();
+
+ var submitBtn;
+
+ me.title = "Clone VM " + me.vmid;
+ submitBtn = Ext.create('Ext.Button', {
+ text: gettext('Clone'),
+ handler: function() {
+ if (form.isValid()) {
+ var values = form.getValues();
+ me.create_clone(values.snapname, values.name, values.newvmid, values.clonemode, values.hdstorage, values.diskformat, diskarray);
+ }
+ }
+ });
+
+
+ Ext.apply(me, {
+ modal: true,
+ width: 350,
+ height: 250,
+ border: false,
+ layout: 'fit',
+ buttons: [ submitBtn ],
+ items: [ me.formPanel ]
+ });
+
+
+ me.callParent();
+
+ if (!me.snapname) {
+ return;
+ }
+
+ me.compute_sel1(me.clonefeature);
+
+ var url;
+
+ if (me.snapsname) {
+ url = '/nodes/' + me.nodename + '/qemu/' + me.vmid + "/snapshot/" + me.snapname + '/config';
+ } else {
+ url = '/nodes/' + me.nodename + '/qemu/' + me.vmid + '/config';
+ }
+
+
+ PVE.Utils.API2Request({
+ url: url,
+ waitMsgTarget: me,
+ method: 'GET',
+ failure: function(response, opts) {
+ Ext.Msg.alert('Error', response.htmlStatus);
+ me.close();
+ },
+ success: function(response, options) {
+ var data = response.result.data;
+ Ext.Object.each(data, function(key, value) {
+
+ var drive = PVE.Parser.parseQemuDrive(key, value);
+ if (drive) {
+ var match = drive.file.match(/^([^:]+):/);
+ if (match) {
+ diskarray.push(key);
+ }
+ }
+ });
+ }
+ });
+ }
+});
--
1.7.10.4
More information about the pve-devel
mailing list