]>
git.proxmox.com Git - pve-manager.git/blob - www/manager6/qemu/CloudInit.js
1 Ext
.define('PVE.qemu.CloudInit', {
2 extend
: 'Proxmox.grid.PendingObjectGrid',
5 onlineHelp
: 'qm_cloud_init',
9 xtype
: 'proxmoxButton',
12 confirmMsg: function(rec
) {
13 let view
= 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 + view
.renderKey(entry
, {}, rec
) + "'");
22 enableFn: function(record
) {
23 let view
= this.up('grid');
24 var caps
= Ext
.state
.Manager
.get('GuiCap');
25 let caps_ci
= caps
.vms
['VM.Config.Network'] || caps
.vms
['VM.Config.Cloudinit'];
26 if (view
.rows
[record
.data
.key
].never_delete
|| !caps_ci
) {
30 if (record
.data
.key
=== 'cipassword' && !record
.data
.value
) {
36 let view
= this.up('grid');
37 let records
= view
.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];
50 Proxmox
.Utils
.API2Request({
51 url
: view
.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 view
= this.up('pveCiPanel');
70 return !!view
.rows
[rec
.data
.key
].editor
;
73 let view
= this.up('grid');
76 text
: gettext('Edit'),
82 text
: gettext('Regenerate Image'),
84 let view
= this.up('grid');
85 var eject_params
= {};
86 var insert_params
= {};
87 let disk
= PVE
.Parser
.parseQemuDrive(view
.ciDriveId
, view
.ciDrive
);
89 var stormatch
= disk
.file
.match(/^([^:]+):/);
91 storage
= stormatch
[1];
93 eject_params
[view
.ciDriveId
] = 'none,media=cdrom';
94 insert_params
[view
.ciDriveId
] = storage
+ ':cloudinit';
96 var failure = function(response
, opts
) {
97 Ext
.Msg
.alert('Error', response
.htmlStatus
);
100 Proxmox
.Utils
.API2Request({
101 url
: view
.baseurl
+ '/config',
104 params
: eject_params
,
106 callback: function() {
107 Proxmox
.Utils
.API2Request({
108 url
: view
.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 let caps_ci
= caps
.vms
['VM.Config.Cloudinit'] || caps
.vms
['VM.Config.Network'];
196 /* editor is string and object */
199 header
: gettext('User'),
200 iconCls
: 'fa fa-user',
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 Ext
.String
.htmlEncode(value
|| Proxmox
.Utils
.defaultText
);
221 header
: gettext('Password'),
222 iconCls
: 'fa fa-unlock',
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 Ext
.String
.htmlEncode(value
|| Proxmox
.Utils
.noneText
);
243 header
: gettext('DNS domain'),
244 iconCls
: 'fa fa-globe',
245 editor
: caps_ci
? 'PVE.lxc.DNSEdit' : undefined,
247 defaultValue
: gettext('use host settings'),
250 header
: gettext('DNS servers'),
251 iconCls
: 'fa fa-globe',
252 editor
: caps_ci
? 'PVE.lxc.DNSEdit' : undefined,
254 defaultValue
: gettext('use host settings'),
257 header
: gettext('SSH public key'),
258 iconCls
: 'fa fa-key',
259 editor
: caps_ci
? 'PVE.qemu.SSHKeyEdit' : undefined,
261 renderer: function(value
) {
262 value
= decodeURIComponent(value
);
263 var keys
= value
.split('\n');
265 keys
.forEach(function(key
) {
267 let res
= PVE
.Parser
.parseSSHKey(key
);
269 key
= Ext
.String
.htmlEncode(res
.comment
);
271 key
+= ' <span style="color:gray">(' + gettext('with options') + ')</span>';
276 // Most likely invalid at this point, so just stick to
278 text
.push(Ext
.String
.htmlEncode(key
));
282 return text
.join('<br>');
284 return Proxmox
.Utils
.noneText
;
290 header
: gettext('Upgrade packages'),
291 iconCls
: 'fa fa-archive',
292 renderer
: Proxmox
.Utils
.format_boolean
,
295 xtype
: 'proxmoxWindowEdit',
296 subject
: gettext('Upgrade packages on boot'),
298 xtype
: 'proxmoxcheckbox',
301 value
: 1, // serves as default value, using defaultValue is not enough
302 fieldLabel
: gettext('Upgrade packages'),
309 var ipconfig_renderer = function(value
, md
, record
, ri
, ci
, store
, pending
) {
310 var id
= record
.data
.key
;
311 var match
= id
.match(/^net(\d+)$/);
314 val
= me
.getObjectValue('ipconfig'+match
[1], '', pending
);
318 for (i
= 0; i
< 32; i
++) {
319 // we want to show an entry for every network device
320 // even if it is empty
321 me
.rows
['net' + i
.toString()] = {
322 multiKey
: ['ipconfig' + i
.toString(), 'net' + i
.toString()],
323 header
: gettext('IP Config') + ' (net' + i
.toString() +')',
324 editor
: caps_ci
? 'PVE.qemu.IPConfigEdit' : undefined,
325 iconCls
: 'fa fa-exchange',
326 renderer
: ipconfig_renderer
,
328 me
.rows
['ipconfig' + i
.toString()] = {
333 PVE
.Utils
.forEachBus(['ide', 'scsi', 'sata'], function(type
, id
) {
339 me
.mon(me
.rstore
, 'load', me
.set_button_status
, me
);