2016-01-14 16:31:07 +01:00
Ext . define ( 'PVE.lxc.Config' , {
extend : 'PVE.panel.Config' ,
alias : 'widget.PVE.lxc.Config' ,
initComponent : function ( ) {
var me = this ;
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 base _url = '/nodes/' + nodename + '/lxc/' + vmid ;
2016-03-15 13:41:27 +01:00
2016-01-14 16:31:07 +01:00
me . statusStore = Ext . create ( 'PVE.data.ObjectStore' , {
url : '/api2/json' + base _url + '/status/current' ,
interval : 1000
} ) ;
var vm _command = function ( cmd , params ) {
PVE . Utils . API2Request ( {
params : params ,
url : base _url + "/status/" + cmd ,
waitMsgTarget : me ,
method : 'POST' ,
failure : function ( response , opts ) {
Ext . Msg . alert ( 'Error' , response . htmlStatus ) ;
}
} ) ;
} ;
2016-03-15 13:41:27 +01:00
var startBtn = Ext . create ( 'Ext.Button' , {
2016-01-14 16:31:07 +01:00
text : gettext ( 'Start' ) ,
disabled : ! caps . vms [ 'VM.PowerMgmt' ] ,
handler : function ( ) {
vm _command ( 'start' ) ;
2016-03-15 13:41:27 +01:00
}
} ) ;
2016-01-14 16:31:07 +01:00
2016-03-15 13:41:27 +01:00
var umountBtn = Ext . create ( 'Ext.Button' , {
2016-01-14 16:31:07 +01:00
text : gettext ( 'Unmount' ) ,
disabled : true ,
hidden : true ,
handler : function ( ) {
vm _command ( 'umount' ) ;
2016-03-15 13:41:27 +01:00
}
} ) ;
2016-01-14 16:31:07 +01:00
var stopBtn = Ext . create ( 'PVE.button.Button' , {
text : gettext ( 'Stop' ) ,
disabled : ! caps . vms [ 'VM.PowerMgmt' ] ,
confirmMsg : Ext . String . format ( gettext ( "Do you really want to stop VM {0}?" ) , vmid ) ,
handler : function ( ) {
vm _command ( "stop" ) ;
}
} ) ;
2016-03-15 13:41:27 +01:00
2016-01-14 16:31:07 +01:00
var shutdownBtn = Ext . create ( 'PVE.button.Button' , {
text : gettext ( 'Shutdown' ) ,
disabled : ! caps . vms [ 'VM.PowerMgmt' ] ,
confirmMsg : Ext . String . format ( gettext ( "Do you really want to shutdown VM {0}?" ) , vmid ) ,
handler : function ( ) {
vm _command ( 'shutdown' ) ;
2016-03-15 13:41:27 +01:00
}
2016-01-14 16:31:07 +01:00
} ) ;
2016-03-15 13:41:27 +01:00
var migrateBtn = Ext . create ( 'Ext.Button' , {
2016-01-14 16:31:07 +01:00
text : gettext ( 'Migrate' ) ,
disabled : ! caps . vms [ 'VM.Migrate' ] ,
handler : function ( ) {
2016-03-15 13:41:27 +01:00
var win = Ext . create ( 'PVE.window.Migrate' , {
2016-01-14 16:31:07 +01:00
vmtype : 'lxc' ,
nodename : nodename ,
vmid : vmid
} ) ;
win . show ( ) ;
}
} ) ;
var removeBtn = Ext . create ( 'PVE.button.Button' , {
text : gettext ( 'Remove' ) ,
disabled : ! caps . vms [ 'VM.Allocate' ] ,
dangerous : true ,
confirmMsg : Ext . String . format ( gettext ( 'Are you sure you want to remove VM {0}? This will permanently erase all VM data.' ) , vmid ) ,
handler : function ( ) {
PVE . Utils . API2Request ( {
url : base _url ,
method : 'DELETE' ,
waitMsgTarget : me ,
failure : function ( response , opts ) {
Ext . Msg . alert ( 'Error' , response . htmlStatus ) ;
}
} ) ;
}
} ) ;
var vmname = me . pveSelNode . data . name ;
var consoleBtn = Ext . create ( 'PVE.button.ConsoleButton' , {
disabled : ! caps . vms [ 'VM.Console' ] ,
consoleType : 'lxc' ,
consoleName : vmname ,
nodename : nodename ,
vmid : vmid
} ) ;
var descr = vmid + " (" + ( vmname ? "'" + vmname + "' " : "'CT " + vmid + "'" ) + ")" ;
Ext . apply ( me , {
title : Ext . String . format ( gettext ( "Container {0} on node {1}" ) , descr , "'" + nodename + "'" ) ,
hstateid : 'lxctab' ,
2016-03-15 13:41:27 +01:00
tbar : [ startBtn , shutdownBtn , umountBtn , stopBtn , removeBtn ,
2016-01-14 16:31:07 +01:00
migrateBtn , consoleBtn ] ,
defaults : { statusStore : me . statusStore } ,
items : [
{
2016-03-14 13:35:10 +01:00
title : gettext ( 'Summary' ) ,
xtype : 'pveLxcSummary' ,
2016-01-14 16:31:07 +01:00
itemId : 'summary'
} ,
2016-03-03 14:43:23 +01:00
{
title : gettext ( 'Resources' ) ,
itemId : 'resources' ,
xtype : 'pveLxcRessourceView'
} ,
{
title : gettext ( 'Network' ) ,
itemId : 'network' ,
xtype : 'pveLxcNetworkView'
} ,
{
title : gettext ( 'DNS' ) ,
itemId : 'dns' ,
xtype : 'pveLxcDNS'
} ,
{
title : gettext ( 'Options' ) ,
itemId : 'options' ,
xtype : 'pveLxcOptions'
} ,
{
title : gettext ( 'Task History' ) ,
itemId : 'tasks' ,
xtype : 'pveNodeTasks' ,
vmidFilter : vmid
}
2016-01-14 16:31:07 +01:00
]
} ) ;
2016-03-14 13:35:10 +01:00
if ( caps . vms [ 'VM.Backup' ] ) {
me . items . push ( {
title : gettext ( 'Backup' ) ,
xtype : 'pveBackupView' ,
itemId : 'backup'
} ) ;
}
2016-01-25 15:19:27 +01:00
2016-03-03 14:43:23 +01:00
if ( caps . vms [ 'VM.Console' ] ) {
me . items . push ( {
title : gettext ( 'Console' ) ,
itemId : 'console' ,
xtype : 'pveNoVncConsole' ,
vmid : vmid ,
consoleType : 'lxc' ,
nodename : nodename
} ) ;
}
2016-03-15 13:41:27 +01:00
2016-03-03 14:43:23 +01:00
if ( caps . vms [ 'VM.Snapshot' ] ) {
me . items . push ( {
title : gettext ( 'Snapshots' ) ,
xtype : 'pveLxcSnapshotTree' ,
itemId : 'snapshot'
} ) ;
}
2016-01-25 15:19:27 +01:00
2016-03-03 14:43:23 +01:00
if ( caps . vms [ 'VM.Console' ] ) {
me . items . push (
{
xtype : 'pveFirewallPanel' ,
title : gettext ( 'Firewall' ) ,
base _url : base _url + '/firewall' ,
fwtype : 'vm' ,
phstateid : me . hstateid ,
itemId : 'firewall'
}
) ;
}
2016-01-25 15:19:27 +01:00
2016-03-14 13:35:10 +01:00
if ( caps . vms [ 'Permissions.Modify' ] ) {
me . items . push ( {
xtype : 'pveACLView' ,
title : gettext ( 'Permissions' ) ,
itemId : 'permissions' ,
path : '/vms/' + vmid
} ) ;
}
2016-01-14 16:31:07 +01:00
me . callParent ( ) ;
2016-03-15 13:41:27 +01:00
me . mon ( me . statusStore , 'load' , function ( s , records , success ) {
2016-01-14 16:31:07 +01:00
var status ;
if ( ! success ) {
me . workspace . checkVmMigration ( me . pveSelNode ) ;
status = 'unknown' ;
} else {
var rec = s . data . get ( 'status' ) ;
status = rec ? rec . data . value : 'unknown' ;
}
startBtn . setDisabled ( ! caps . vms [ 'VM.PowerMgmt' ] || status === 'running' ) ;
shutdownBtn . setDisabled ( ! caps . vms [ 'VM.PowerMgmt' ] || status !== 'running' ) ;
stopBtn . setDisabled ( ! caps . vms [ 'VM.PowerMgmt' ] || status === 'stopped' ) ;
removeBtn . setDisabled ( ! caps . vms [ 'VM.Allocate' ] || status !== 'stopped' ) ;
if ( status === 'mounted' ) {
umountBtn . setDisabled ( false ) ;
umountBtn . setVisible ( true ) ;
stopBtn . setVisible ( false ) ;
} else {
umountBtn . setDisabled ( true ) ;
umountBtn . setVisible ( false ) ;
stopBtn . setVisible ( true ) ;
}
} ) ;
me . on ( 'afterrender' , function ( ) {
me . statusStore . startUpdate ( ) ;
} ) ;
me . on ( 'destroy' , function ( ) {
me . statusStore . stopUpdate ( ) ;
} ) ;
}
} ) ;