[pve-devel] [PATCH manager 7/8] add CIDriveEdit
Dominik Csapak
d.csapak at proxmox.com
Thu Mar 15 16:21:35 CET 2018
and use it on the HardwareView to add/remove and display the
CloudInit drives
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
www/manager6/Makefile | 1 +
www/manager6/qemu/CIDriveEdit.js | 85 +++++++++++++++++++++++++++++++++++++++
www/manager6/qemu/HardwareView.js | 31 ++++++++++++--
3 files changed, 114 insertions(+), 3 deletions(-)
create mode 100644 www/manager6/qemu/CIDriveEdit.js
diff --git a/www/manager6/Makefile b/www/manager6/Makefile
index e6d07ae0..1c7fdf92 100644
--- a/www/manager6/Makefile
+++ b/www/manager6/Makefile
@@ -129,6 +129,7 @@ JSSRC= \
qemu/CreateWizard.js \
qemu/USBEdit.js \
qemu/AgentIPView.js \
+ qemu/CIDriveEdit.js \
qemu/SSHKey.js \
qemu/IPConfigEdit.js \
lxc/Summary.js \
diff --git a/www/manager6/qemu/CIDriveEdit.js b/www/manager6/qemu/CIDriveEdit.js
new file mode 100644
index 00000000..1148ce4e
--- /dev/null
+++ b/www/manager6/qemu/CIDriveEdit.js
@@ -0,0 +1,85 @@
+Ext.define('PVE.qemu.CIDriveInputPanel', {
+ extend: 'Proxmox.panel.InputPanel',
+ xtype: 'pveCIDriveInputPanel',
+
+ insideWizard: false,
+
+ vmconfig: {}, // used to select usused disks
+
+ onGetValues: function(values) {
+ var me = this;
+
+ var drive = {};
+ var params = {};
+ drive.file = values.hdstorage + ":cloudinit";
+ drive.format = values.diskformat;
+ params[values.controller + values.deviceid] = PVE.Parser.printQemuDrive(drive);
+ return params;
+ },
+
+ setNodename: function(nodename) {
+ var me = this;
+ me.down('#hdstorage').setNodename(nodename);
+ me.down('#hdimage').setStorage(undefined, nodename);
+ },
+
+ setVMConfig: function(config) {
+ var me = this;
+ me.down('#drive').setVMConfig(config, 'cdrom');
+ },
+
+ initComponent : function() {
+ var me = this;
+
+ me.drive = {};
+
+ me.items = [
+ {
+ xtype: 'pveControllerSelector',
+ noVirtIO: true,
+ itemId: 'drive',
+ fieldLabel: gettext('CloudInit Drive'),
+ name: 'drive'
+ },
+ {
+ xtype: 'pveDiskStorageSelector',
+ itemId: 'storselector',
+ storageContent: 'images',
+ nodename: me.nodename,
+ hideSize: true
+ }
+ ];
+ me.callParent();
+ }
+});
+
+Ext.define('PVE.qemu.CIDriveEdit', {
+ extend: 'Proxmox.window.Edit',
+ xtype: 'pveCIDriveEdit',
+
+ isCreate: true,
+ subject: gettext('CloudInit Drive'),
+
+ initComponent : function() {
+ var me = this;
+
+ var nodename = me.pveSelNode.data.node;
+ if (!nodename) {
+ throw "no node name specified";
+ }
+
+ me.items = [{
+ xtype: 'pveCIDriveInputPanel',
+ itemId: 'cipanel',
+ nodename: nodename
+ }];
+
+ me.callParent();
+
+ me.load({
+ success: function(response, opts) {
+ me.down('#cipanel').setVMConfig(response.result.data);
+ }
+ });
+ }
+});
diff --git a/www/manager6/qemu/HardwareView.js b/www/manager6/qemu/HardwareView.js
index 04fded6d..e726cb70 100644
--- a/www/manager6/qemu/HardwareView.js
+++ b/www/manager6/qemu/HardwareView.js
@@ -15,7 +15,10 @@ Ext.define('PVE.qemu.HardwareView', {
metaData.tdCls = rowdef.tdCls;
if (rowdef.tdCls == 'pve-itype-icon-storage') {
var value = me.getObjectValue(key, '', true);
- if (value.match(/media=cdrom/)) {
+ if (value.match(/vm-.*-cloudinit/)) {
+ metaData.tdCls = 'pve-itype-icon-cloud';
+ return rowdef.cloudheader;
+ } else if (value.match(/media=cdrom/)) {
metaData.tdCls = 'pve-itype-icon-cdrom';
return rowdef.cdheader;
}
@@ -155,7 +158,8 @@ Ext.define('PVE.qemu.HardwareView', {
editor: 'PVE.qemu.HDEdit',
never_delete: caps.vms['VM.Config.Disk'] ? false : true,
header: gettext('Hard Disk') + ' (' + confid +')',
- cdheader: gettext('CD/DVD Drive') + ' (' + confid +')'
+ cdheader: gettext('CD/DVD Drive') + ' (' + confid +')',
+ cloudheader: gettext('CloudInit Drive') + ' (' + confid + ')'
};
});
for (i = 0; i < 32; i++) {
@@ -484,12 +488,17 @@ Ext.define('PVE.qemu.HardwareView', {
efidisk_menuitem.setDisabled(me.rstore.getData().map.efidisk0 !== undefined);
// en/disable usb add button
var count = 0;
+ var hasCloudInit = false;
me.rstore.getData().items.forEach(function(item){
if (/^usb\d+/.test(item.id)) {
count++;
}
+ if (!hasCloudInit && /vm-.*-cloudinit/.test(item.data.value)) {
+ hasCloudInit = true;
+ }
});
me.down('#addusb').setDisabled((count >= 5));
+ me.down('#addci').setDisabled(hasCloudInit);
if (!rec) {
remove_btn.disable();
@@ -509,12 +518,14 @@ Ext.define('PVE.qemu.HardwareView', {
rowdef.tdCls == 'pve-itype-icon-storage' &&
(value && !value.match(/media=cdrom/));
+ var isCloudInit = (value && value.match(/vm-.*-cloudinit/));
+
var isEfi = (key === 'efidisk0');
remove_btn.setDisabled(rec.data['delete'] || (rowdef.never_delete === true));
remove_btn.setText(isUsedDisk ? remove_btn.altText : remove_btn.defaultText);
- edit_btn.setDisabled(rec.data['delete'] || !rowdef.editor);
+ edit_btn.setDisabled(rec.data['delete'] || !rowdef.editor || isCloudInit);
resize_btn.setDisabled(pending || !isUsedDisk);
@@ -588,6 +599,20 @@ Ext.define('PVE.qemu.HardwareView', {
win.on('destroy', reload);
win.show();
}
+ },
+ {
+ text: gettext('CloudInit Drive'),
+ itemId: 'addci',
+ iconCls: 'pve-itype-icon-cloud',
+ disabled: !caps.nodes['Sys.Console'],
+ handler: function() {
+ var win = Ext.create('PVE.qemu.CIDriveEdit', {
+ url: '/api2/extjs/' + baseurl,
+ pveSelNode: me.pveSelNode
+ });
+ win.on('destroy', reload);
+ win.show();
+ }
}
]
})
--
2.11.0
More information about the pve-devel
mailing list