]>
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 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',
69 var me
= this.up('grid');
78 text
: gettext('Regenerate Image'),
80 var me
= this.up('grid');
81 var eject_params
= {};
82 var insert_params
= {};
83 var disk
= PVE
.Parser
.parseQemuDrive(me
.ciDriveId
, me
.ciDrive
);
85 var stormatch
= disk
.file
.match(/^([^\:]+)\:/);
87 storage
= stormatch
[1];
89 eject_params
[me
.ciDriveId
] = 'none,media=cdrom';
90 insert_params
[me
.ciDriveId
] = storage
+ ':cloudinit';
92 var failure = function(response
, opts
) {
93 Ext
.Msg
.alert('Error', response
.htmlStatus
);
96 Proxmox
.Utils
.API2Request({
97 url
: me
.baseurl
+ '/config',
100 params
: eject_params
,
102 callback: function() {
103 Proxmox
.Utils
.API2Request({
104 url
: me
.baseurl
+ '/config',
107 params
: insert_params
,
109 callback: function() {
121 set_button_status: function(rstore
, records
, success
) {
122 if (!success
|| records
.length
< 1) {
127 records
.forEach(function(record
) {
131 var id
= record
.data
.key
;
132 var value
= record
.data
.value
;
133 var ciregex
= new RegExp("vm-" + me
.pveSelNode
.data
.vmid
+ "-cloudinit");
134 if (id
.match(/^(ide|scsi|sata)\d+$/) && ciregex
.test(value
)) {
136 me
.ciDriveId
= found
;
141 me
.down('#savebtn').setDisabled(!found
);
142 me
.setDisabled(!found
);
144 me
.getView().mask(gettext('No CloudInit Drive found'), ['pve-static-mask']);
146 me
.getView().unmask();
150 renderKey: function(key
, metaData
, rec
, rowIndex
, colIndex
, store
) {
153 var rowdef
= rows
[key
] || {};
156 if (rowdef
.iconCls
) {
157 icon
= '<i class="' + rowdef
.iconCls
+ '"></i> ';
159 return icon
+ (rowdef
.header
|| key
);
163 activate: function () {
165 me
.rstore
.startUpdate();
167 itemdblclick: function() {
173 initComponent: function() {
176 var nodename
= me
.pveSelNode
.data
.node
;
178 throw "no node name specified";
181 var vmid
= me
.pveSelNode
.data
.vmid
;
183 throw "no VM ID specified";
185 var caps
= Ext
.state
.Manager
.get('GuiCap');
186 me
.baseurl
= '/api2/extjs/nodes/' + nodename
+ '/qemu/' + vmid
;
187 me
.url
= me
.baseurl
+ '/pending';
188 me
.editorConfig
.url
= me
.baseurl
+ '/config';
189 me
.editorConfig
.pveSelNode
= me
.pveSelNode
;
191 /*jslint confusion: true*/
192 /* editor is string and object */
195 header
: gettext('User'),
196 iconCls
: 'fa fa-user',
199 editor
: caps
.vms
['VM.Config.Options'] ? {
200 xtype
: 'proxmoxWindowEdit',
201 subject
: gettext('User'),
204 xtype
: 'proxmoxtextfield',
206 emptyText
: Proxmox
.Utils
.defaultText
,
207 fieldLabel
: gettext('User'),
212 renderer: function(value
) {
213 return value
|| Proxmox
.Utils
.defaultText
;
217 header
: gettext('Password'),
218 iconCls
: 'fa fa-unlock',
220 editor
: caps
.vms
['VM.Config.Options'] ? {
221 xtype
: 'proxmoxWindowEdit',
222 subject
: gettext('Password'),
225 xtype
: 'proxmoxtextfield',
226 inputType
: 'password',
228 emptyText
: Proxmox
.Utils
.noneText
,
229 fieldLabel
: gettext('Password'),
234 renderer: function(value
) {
235 return value
|| Proxmox
.Utils
.noneText
;
239 header
: gettext('DNS domain'),
240 iconCls
: 'fa fa-globe',
241 editor
: caps
.vms
['VM.Config.Network'] ? 'PVE.lxc.DNSEdit' : undefined,
243 defaultValue
: gettext('use host settings')
246 header
: gettext('DNS servers'),
247 iconCls
: 'fa fa-globe',
248 editor
: caps
.vms
['VM.Config.Network'] ? 'PVE.lxc.DNSEdit' : undefined,
250 defaultValue
: gettext('use host settings')
253 header
: gettext('SSH public key'),
254 iconCls
: 'fa fa-key',
255 editor
: caps
.vms
['VM.Config.Network'] ? 'PVE.qemu.SSHKeyEdit' : undefined,
257 renderer: function(value
) {
258 value
= decodeURIComponent(value
);
259 var keys
= value
.split('\n');
261 keys
.forEach(function(key
) {
263 // First erase all quoted strings (eg. command="foo"
264 var v
= key
.replace(/"(?:\\.|[^"\\])*"/g, '');
265 // Now try to detect the comment:
266 var res
= v
.match(/^\s*(\S+\s+)?(?:ssh-(?:dss|rsa|ed25519)|ecdsa-sha2-nistp\d+)\s+\S+\s+(.*?)\s*$/, '');
268 key
= Ext
.String
.htmlEncode(res
[2]);
270 key
+= ' <span style="color:gray">(' + gettext('with options') + ')</span>';
275 // Most likely invalid at this point, so just stick to
277 text
.push(Ext
.String
.htmlEncode(key
));
281 return text
.join('<br>');
283 return Proxmox
.Utils
.noneText
;
290 var ipconfig_renderer = function(value
, md
, record
, ri
, ci
, store
, pending
) {
291 var id
= record
.data
.key
;
292 var match
= id
.match(/^net(\d+)$/);
295 val
= me
.getObjectValue('ipconfig'+match
[1], '', pending
);
299 for (i
= 0; i
< 32; i
++) {
300 // we want to show an entry for every network device
301 // even if it is empty
302 me
.rows
['net' + i
.toString()] = {
303 multiKey
: ['ipconfig' + i
.toString(), 'net' + i
.toString()],
304 header
: gettext('IP Config') + ' (net' + i
.toString() +')',
305 editor
: caps
.vms
['VM.Config.Network'] ? 'PVE.qemu.IPConfigEdit' : undefined,
306 iconCls
: 'fa fa-exchange',
307 renderer
: ipconfig_renderer
309 me
.rows
['ipconfig' + i
.toString()] = {
313 /*jslint confusion: false*/
315 PVE
.Utils
.forEachBus(['ide', 'scsi', 'sata'], function(type
, id
) {
321 me
.mon(me
.rstore
, 'load', me
.set_button_status
, me
);