2016-03-16 09:12:22 +01:00
/*jslint confusion: true */
Ext . define ( 'PVE.qemu.Options' , {
extend : 'PVE.grid.PendingObjectGrid' ,
alias : [ 'widget.PVE.qemu.Options' ] ,
initComponent : function ( ) {
var me = this ;
var i ;
var nodename = me . pveSelNode . data . node ;
if ( ! nodename ) {
throw "no node name specified" ;
}
var vmid = me . pveSelNode . data . vmid ;
if ( ! vmid ) {
throw "no VM ID specified" ;
}
var caps = Ext . state . Manager . get ( 'GuiCap' ) ;
var rows = {
name : {
required : true ,
defaultValue : me . pveSelNode . data . name ,
header : gettext ( 'Name' ) ,
editor : caps . vms [ 'VM.Config.Options' ] ? {
xtype : 'pveWindowEdit' ,
subject : gettext ( 'Name' ) ,
items : {
xtype : 'textfield' ,
name : 'name' ,
vtype : 'DnsName' ,
value : '' ,
fieldLabel : gettext ( 'Name' ) ,
allowBlank : true
}
} : undefined
} ,
onboot : {
header : gettext ( 'Start at boot' ) ,
defaultValue : '' ,
renderer : PVE . Utils . format _boolean ,
editor : caps . vms [ 'VM.Config.Options' ] ? {
xtype : 'pveWindowEdit' ,
subject : gettext ( 'Start at boot' ) ,
items : {
xtype : 'pvecheckbox' ,
name : 'onboot' ,
uncheckedValue : 0 ,
defaultValue : 0 ,
deleteDefaultValue : true ,
fieldLabel : gettext ( 'Start at boot' )
}
} : undefined
} ,
startup : {
header : gettext ( 'Start/Shutdown order' ) ,
defaultValue : '' ,
renderer : PVE . Utils . render _kvm _startup ,
editor : caps . vms [ 'VM.Config.Options' ] && caps . nodes [ 'Sys.Modify' ] ?
'PVE.qemu.StartupEdit' : undefined
} ,
ostype : {
header : gettext ( 'OS Type' ) ,
editor : caps . vms [ 'VM.Config.Options' ] ? 'PVE.qemu.OSTypeEdit' : undefined ,
renderer : PVE . Utils . render _kvm _ostype ,
defaultValue : 'other'
} ,
bootdisk : {
visible : false
} ,
boot : {
header : gettext ( 'Boot order' ) ,
defaultValue : 'cdn' ,
editor : caps . vms [ 'VM.Config.Disk' ] ? 'PVE.qemu.BootOrderEdit' : undefined ,
2016-04-26 14:41:57 +02:00
multiKey : [ 'boot' , 'bootdisk' ] ,
2016-03-16 09:12:22 +01:00
renderer : function ( order , metaData , record , rowIndex , colIndex , store , pending ) {
var i ;
var text = '' ;
var bootdisk = me . getObjectValue ( 'bootdisk' , undefined , pending ) ;
order = order || 'cdn' ;
for ( i = 0 ; i < order . length ; i ++ ) {
var sel = order . substring ( i , i + 1 ) ;
if ( text ) {
text += ', ' ;
}
if ( sel === 'c' ) {
if ( bootdisk ) {
text += "Disk '" + bootdisk + "'" ;
} else {
text += "Disk" ;
}
} else if ( sel === 'n' ) {
text += 'Network' ;
} else if ( sel === 'a' ) {
text += 'Floppy' ;
} else if ( sel === 'd' ) {
text += 'CD-ROM' ;
} else {
text += sel ;
}
}
return text ;
}
} ,
tablet : {
header : gettext ( 'Use tablet for pointer' ) ,
defaultValue : true ,
renderer : PVE . Utils . format _boolean ,
editor : caps . vms [ 'VM.Config.HWType' ] ? {
xtype : 'pveWindowEdit' ,
subject : gettext ( 'Use tablet for pointer' ) ,
items : {
xtype : 'pvecheckbox' ,
name : 'tablet' ,
checked : true ,
uncheckedValue : 0 ,
defaultValue : 1 ,
deleteDefaultValue : true ,
fieldLabel : gettext ( 'Enabled' )
}
} : undefined
} ,
hotplug : {
header : gettext ( 'Hotplug' ) ,
defaultValue : 'disk,network,usb' ,
renderer : PVE . Utils . render _hotplug _features ,
editor : caps . vms [ 'VM.Config.HWType' ] ? {
xtype : 'pveWindowEdit' ,
subject : gettext ( 'Hotplug' ) ,
items : {
xtype : 'pveHotplugFeatureSelector' ,
name : 'hotplug' ,
value : '' ,
multiSelect : true ,
fieldLabel : gettext ( 'Hotplug' ) ,
allowBlank : true
}
} : undefined
} ,
acpi : {
header : gettext ( 'ACPI support' ) ,
defaultValue : true ,
renderer : PVE . Utils . format _boolean ,
editor : caps . vms [ 'VM.Config.HWType' ] ? {
xtype : 'pveWindowEdit' ,
subject : gettext ( 'ACPI support' ) ,
items : {
xtype : 'pvecheckbox' ,
name : 'acpi' ,
checked : true ,
uncheckedValue : 0 ,
defaultValue : 1 ,
deleteDefaultValue : true ,
fieldLabel : gettext ( 'Enabled' )
}
} : undefined
} ,
scsihw : {
header : gettext ( 'SCSI Controller Type' ) ,
editor : caps . vms [ 'VM.Config.Options' ] ? 'PVE.qemu.ScsiHwEdit' : undefined ,
renderer : PVE . Utils . render _scsihw ,
defaultValue : ''
} ,
bios : {
header : 'BIOS' ,
editor : caps . vms [ 'VM.Config.Options' ] ? 'PVE.qemu.BiosEdit' : undefined ,
renderer : PVE . Utils . render _qemu _bios ,
defaultValue : ''
} ,
kvm : {
header : gettext ( 'KVM hardware virtualization' ) ,
defaultValue : true ,
renderer : PVE . Utils . format _boolean ,
editor : caps . vms [ 'VM.Config.HWType' ] ? {
xtype : 'pveWindowEdit' ,
subject : gettext ( 'KVM hardware virtualization' ) ,
items : {
xtype : 'pvecheckbox' ,
name : 'kvm' ,
checked : true ,
uncheckedValue : 0 ,
defaultValue : 1 ,
deleteDefaultValue : true ,
fieldLabel : gettext ( 'Enabled' )
}
} : undefined
} ,
freeze : {
header : gettext ( 'Freeze CPU at startup' ) ,
defaultValue : false ,
renderer : PVE . Utils . format _boolean ,
editor : caps . vms [ 'VM.PowerMgmt' ] ? {
xtype : 'pveWindowEdit' ,
subject : gettext ( 'Freeze CPU at startup' ) ,
items : {
xtype : 'pvecheckbox' ,
name : 'freeze' ,
uncheckedValue : 0 ,
defaultValue : 0 ,
deleteDefaultValue : true ,
labelWidth : 140 ,
fieldLabel : gettext ( 'Freeze CPU at startup' )
}
} : undefined
} ,
localtime : {
header : gettext ( 'Use local time for RTC' ) ,
defaultValue : false ,
renderer : PVE . Utils . format _boolean ,
editor : caps . vms [ 'VM.Config.Options' ] ? {
xtype : 'pveWindowEdit' ,
subject : gettext ( 'Use local time for RTC' ) ,
items : {
xtype : 'pvecheckbox' ,
name : 'localtime' ,
uncheckedValue : 0 ,
defaultValue : 0 ,
deleteDefaultValue : true ,
labelWidth : 140 ,
fieldLabel : gettext ( 'Use local time for RTC' )
}
} : undefined
} ,
startdate : {
header : gettext ( 'RTC start date' ) ,
defaultValue : 'now' ,
editor : caps . vms [ 'VM.Config.Options' ] ? {
xtype : 'pveWindowEdit' ,
subject : gettext ( 'RTC start date' ) ,
items : {
xtype : 'pvetextfield' ,
name : 'startdate' ,
deleteEmpty : true ,
value : 'now' ,
fieldLabel : gettext ( 'RTC start date' ) ,
vtype : 'QemuStartDate' ,
allowBlank : true
}
} : undefined
} ,
smbios1 : {
header : gettext ( 'SMBIOS settings (type1)' ) ,
defaultValue : '' ,
renderer : Ext . String . htmlEncode ,
editor : caps . vms [ 'VM.Config.HWType' ] ? 'PVE.qemu.Smbios1Edit' : undefined
} ,
agent : {
header : gettext ( 'Qemu Agent' ) ,
defaultValue : false ,
renderer : PVE . Utils . format _boolean ,
editor : caps . vms [ 'VM.Config.Options' ] ? {
xtype : 'pveWindowEdit' ,
subject : gettext ( 'Qemu Agent' ) ,
items : {
xtype : 'pvecheckbox' ,
name : 'agent' ,
uncheckedValue : 0 ,
defaultValue : 0 ,
deleteDefaultValue : true ,
fieldLabel : gettext ( 'Enabled' )
}
} : undefined
} ,
protection : {
2016-04-04 16:59:52 +02:00
header : gettext ( 'Protection' ) ,
2016-03-16 09:12:22 +01:00
defaultValue : false ,
renderer : PVE . Utils . format _boolean ,
editor : caps . vms [ 'VM.Config.Options' ] ? {
xtype : 'pveWindowEdit' ,
2016-04-04 16:59:52 +02:00
subject : gettext ( 'Protection' ) ,
2016-03-16 09:12:22 +01:00
items : {
xtype : 'pvecheckbox' ,
name : 'protection' ,
uncheckedValue : 0 ,
defaultValue : 0 ,
deleteDefaultValue : true ,
fieldLabel : gettext ( 'Enabled' )
}
} : undefined
}
} ;
var baseurl = 'nodes/' + nodename + '/qemu/' + vmid + '/config' ;
var reload = function ( ) {
me . rstore . load ( ) ;
} ;
var run _editor = function ( ) {
var sm = me . getSelectionModel ( ) ;
var rec = sm . getSelection ( ) [ 0 ] ;
if ( ! rec ) {
return ;
}
var rowdef = rows [ rec . data . key ] ;
if ( ! rowdef . editor ) {
return ;
}
var win ;
if ( Ext . isString ( rowdef . editor ) ) {
win = Ext . create ( rowdef . editor , {
pveSelNode : me . pveSelNode ,
confid : rec . data . key ,
url : '/api2/extjs/' + baseurl
} ) ;
} else {
var config = Ext . apply ( {
pveSelNode : me . pveSelNode ,
confid : rec . data . key ,
url : '/api2/extjs/' + baseurl
} , rowdef . editor ) ;
win = Ext . createWidget ( rowdef . editor . xtype , config ) ;
win . load ( ) ;
}
win . show ( ) ;
win . on ( 'destroy' , reload ) ;
} ;
var edit _btn = new Ext . Button ( {
text : gettext ( 'Edit' ) ,
disabled : true ,
handler : run _editor
} ) ;
var revert _btn = new PVE . button . Button ( {
text : gettext ( 'Revert' ) ,
disabled : true ,
handler : function ( ) {
var sm = me . getSelectionModel ( ) ;
var rec = sm . getSelection ( ) [ 0 ] ;
if ( ! rec ) {
return ;
}
2016-04-26 14:41:57 +02:00
var rowdef = me . rows [ rec . data . key ] || { } ;
var keys = rowdef . multiKey || [ rec . data . key ] ;
var revert = keys . join ( ',' ) ;
2016-03-16 09:12:22 +01:00
PVE . Utils . API2Request ( {
url : '/api2/extjs/' + baseurl ,
waitMsgTarget : me ,
method : 'PUT' ,
params : {
2016-04-26 14:41:57 +02:00
'revert' : revert
2016-03-16 09:12:22 +01:00
} ,
callback : function ( ) {
reload ( ) ;
} ,
failure : function ( response , opts ) {
Ext . Msg . alert ( 'Error' , response . htmlStatus ) ;
}
} ) ;
}
} ) ;
var set _button _status = function ( ) {
var sm = me . getSelectionModel ( ) ;
var rec = sm . getSelection ( ) [ 0 ] ;
if ( ! rec ) {
edit _btn . disable ( ) ;
return ;
}
var key = rec . data . key ;
var pending = rec . data [ 'delete' ] || me . hasPendingChanges ( key ) ;
var rowdef = rows [ key ] ;
edit _btn . setDisabled ( ! rowdef . editor ) ;
revert _btn . setDisabled ( ! pending ) ;
} ;
2016-03-21 10:53:13 +01:00
Ext . apply ( me , {
2016-03-16 09:12:22 +01:00
url : "/api2/json/nodes/" + nodename + "/qemu/" + vmid + "/pending" ,
interval : 5000 ,
2016-05-10 15:01:54 +02:00
cwidth1 : 250 ,
2016-03-16 09:12:22 +01:00
tbar : [ edit _btn , revert _btn ] ,
rows : rows ,
listeners : {
itemdblclick : run _editor ,
selectionchange : set _button _status
}
} ) ;
me . callParent ( ) ;
2016-03-21 10:53:13 +01:00
me . on ( 'activate' , me . rstore . startUpdate ) ;
2016-03-16 09:12:22 +01:00
me . on ( 'hide' , me . rstore . stopUpdate ) ;
me . on ( 'destroy' , me . rstore . stopUpdate ) ;
me . rstore . on ( 'datachanged' , function ( ) {
set _button _status ( ) ;
} ) ;
}
} ) ;