]>
git.proxmox.com Git - pve-manager.git/blob - www/manager6/qemu/CloudInit.js
cbb4af9d5c89ed4471a46137b8a5d0bcfff7ee11
1 Ext
.define('PVE.qemu.CloudInit', {
2 extend
: 'Proxmox.grid.PendingObjectGrid',
5 onlineHelp
: 'qm_cloud_init',
9 xtype
: 'proxmoxButton',
12 confirmMsg: function(rec
) {
13 var me
= this.up('grid');
14 var warn
= gettext('Are you sure you want to remove entry {0}');
16 var entry
= rec
.data
.key
;
17 var msg
= Ext
.String
.format(warn
, "'"
18 + me
.renderKey(entry
, {}, rec
) + "'");
22 enableFn: function(record
) {
23 var me
= this.up('grid');
24 var caps
= Ext
.state
.Manager
.get('GuiCap');
25 if (me
.rows
[record
.data
.key
].never_delete
||
26 !caps
.vms
['VM.Config.Network']) {
30 if (record
.data
.key
=== 'cipassword' && !record
.data
.value
) {
36 var me
= this.up('grid');
37 var records
= me
.getSelection();
38 if (!records
|| !records
.length
) {
42 var id
= records
[0].data
.key
;
43 var match
= id
.match(/^net(\d+)$/);
45 id
= 'ipconfig' + match
[1];
49 params
['delete'] = id
;
50 Proxmox
.Utils
.API2Request({
51 url
: me
.baseurl
+ '/config',
55 failure: function(response
, opts
) {
56 Ext
.Msg
.alert('Error', response
.htmlStatus
);
58 callback: function() {
63 text
: gettext('Remove')
66 xtype
: 'proxmoxButton',
68 enableFn: function(rec
) {
69 let me
= this.up('pveCiPanel');
70 return !!me
.rows
[rec
.data
.key
].editor
;
73 var me
= this.up('grid');
82 text
: gettext('Regenerate Image'),
84 var me
= this.up('grid');
85 var eject_params
= {};
86 var insert_params
= {};
87 var disk
= PVE
.Parser
.parseQemuDrive(me
.ciDriveId
, me
.ciDrive
);
89 var stormatch
= disk
.file
.match(/^([^\:]+)\:/);
91 storage
= stormatch
[1];
93 eject_params
[me
.ciDriveId
] = 'none,media=cdrom';
94 insert_params
[me
.ciDriveId
] = storage
+ ':cloudinit';
96 var failure = function(response
, opts
) {
97 Ext
.Msg
.alert('Error', response
.htmlStatus
);
100 Proxmox
.Utils
.API2Request({
101 url
: me
.baseurl
+ '/config',
104 params
: eject_params
,
106 callback: function() {
107 Proxmox
.Utils
.API2Request({
108 url
: me
.baseurl
+ '/config',
111 params
: insert_params
,
113 callback: function() {
125 set_button_status: function(rstore
, records
, success
) {
126 if (!success
|| records
.length
< 1) {
131 records
.forEach(function(record
) {
135 var id
= record
.data
.key
;
136 var value
= record
.data
.value
;
137 var ciregex
= new RegExp("vm-" + me
.pveSelNode
.data
.vmid
+ "-cloudinit");
138 if (id
.match(/^(ide|scsi|sata)\d+$/) && ciregex
.test(value
)) {
140 me
.ciDriveId
= found
;
145 me
.down('#savebtn').setDisabled(!found
);
146 me
.setDisabled(!found
);
148 me
.getView().mask(gettext('No CloudInit Drive found'), ['pve-static-mask']);
150 me
.getView().unmask();
154 renderKey: function(key
, metaData
, rec
, rowIndex
, colIndex
, store
) {
157 var rowdef
= rows
[key
] || {};
160 if (rowdef
.iconCls
) {
161 icon
= '<i class="' + rowdef
.iconCls
+ '"></i> ';
163 return icon
+ (rowdef
.header
|| key
);
167 activate: function () {
169 me
.rstore
.startUpdate();
171 itemdblclick: function() {
177 initComponent: function() {
180 var nodename
= me
.pveSelNode
.data
.node
;
182 throw "no node name specified";
185 var vmid
= me
.pveSelNode
.data
.vmid
;
187 throw "no VM ID specified";
189 var caps
= Ext
.state
.Manager
.get('GuiCap');
190 me
.baseurl
= '/api2/extjs/nodes/' + nodename
+ '/qemu/' + vmid
;
191 me
.url
= me
.baseurl
+ '/pending';
192 me
.editorConfig
.url
= me
.baseurl
+ '/config';
193 me
.editorConfig
.pveSelNode
= me
.pveSelNode
;
195 /*jslint confusion: true*/
196 /* editor is string and object */
199 header
: gettext('User'),
200 iconCls
: 'fa fa-user',
203 editor
: caps
.vms
['VM.Config.Options'] ? {
204 xtype
: 'proxmoxWindowEdit',
205 subject
: gettext('User'),
208 xtype
: 'proxmoxtextfield',
210 emptyText
: Proxmox
.Utils
.defaultText
,
211 fieldLabel
: gettext('User'),
216 renderer: function(value
) {
217 return value
|| Proxmox
.Utils
.defaultText
;
221 header
: gettext('Password'),
222 iconCls
: 'fa fa-unlock',
224 editor
: caps
.vms
['VM.Config.Options'] ? {
225 xtype
: 'proxmoxWindowEdit',
226 subject
: gettext('Password'),
229 xtype
: 'proxmoxtextfield',
230 inputType
: 'password',
232 emptyText
: Proxmox
.Utils
.noneText
,
233 fieldLabel
: gettext('Password'),
238 renderer: function(value
) {
239 return value
|| Proxmox
.Utils
.noneText
;
243 header
: gettext('DNS domain'),
244 iconCls
: 'fa fa-globe',
245 editor
: caps
.vms
['VM.Config.Network'] ? 'PVE.lxc.DNSEdit' : undefined,
247 defaultValue
: gettext('use host settings')
250 header
: gettext('DNS servers'),
251 iconCls
: 'fa fa-globe',
252 editor
: caps
.vms
['VM.Config.Network'] ? 'PVE.lxc.DNSEdit' : undefined,
254 defaultValue
: gettext('use host settings')
257 header
: gettext('SSH public key'),
258 iconCls
: 'fa fa-key',
259 editor
: caps
.vms
['VM.Config.Network'] ? 'PVE.qemu.SSHKeyEdit' : undefined,
261 renderer: function(value
) {
262 value
= decodeURIComponent(value
);
263 var keys
= value
.split('\n');
265 keys
.forEach(function(key
) {
267 // First erase all quoted strings (eg. command="foo"
268 var v
= key
.replace(/"(?:\\.|[^"\\])*"/g, '');
269 // Now try to detect the comment:
270 var res
= v
.match(/^\s*(\S+\s+)?(?:ssh-(?:dss|rsa|ed25519)|ecdsa-sha2-nistp\d+)\s+\S+\s+(.*?)\s*$/, '');
272 key
= Ext
.String
.htmlEncode(res
[2]);
274 key
+= ' <span style="color:gray">(' + gettext('with options') + ')</span>';
279 // Most likely invalid at this point, so just stick to
281 text
.push(Ext
.String
.htmlEncode(key
));
285 return text
.join('<br>');
287 return Proxmox
.Utils
.noneText
;
294 var ipconfig_renderer = function(value
, md
, record
, ri
, ci
, store
, pending
) {
295 var id
= record
.data
.key
;
296 var match
= id
.match(/^net(\d+)$/);
299 val
= me
.getObjectValue('ipconfig'+match
[1], '', pending
);
303 for (i
= 0; i
< 32; i
++) {
304 // we want to show an entry for every network device
305 // even if it is empty
306 me
.rows
['net' + i
.toString()] = {
307 multiKey
: ['ipconfig' + i
.toString(), 'net' + i
.toString()],
308 header
: gettext('IP Config') + ' (net' + i
.toString() +')',
309 editor
: caps
.vms
['VM.Config.Network'] ? 'PVE.qemu.IPConfigEdit' : undefined,
310 iconCls
: 'fa fa-exchange',
311 renderer
: ipconfig_renderer
313 me
.rows
['ipconfig' + i
.toString()] = {
317 /*jslint confusion: false*/
319 PVE
.Utils
.forEachBus(['ide', 'scsi', 'sata'], function(type
, id
) {
325 me
.mon(me
.rstore
, 'load', me
.set_button_status
, me
);