2016-01-14 16:31:07 +01:00
Ext . define ( 'PVE.lxc.Config' , {
extend : 'PVE.panel.Config' ,
alias : 'widget.PVE.lxc.Config' ,
2016-10-13 11:26:06 +02:00
onlineHelp : 'chapter_pct' ,
2016-09-13 13:46:13 +02:00
2016-01-14 16:31:07 +01:00
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" ;
}
2016-03-30 09:35:52 +02:00
var template = me . pveSelNode . data . template ;
2017-10-30 15:03:38 +01:00
var running = ! ! me . pveSelNode . data . uptime ;
2016-01-14 16:31:07 +01:00
var caps = Ext . state . Manager . get ( 'GuiCap' ) ;
var base _url = '/nodes/' + nodename + '/lxc/' + vmid ;
2016-03-15 13:41:27 +01:00
2017-12-11 13:50:25 +01:00
me . statusStore = Ext . create ( 'Proxmox.data.ObjectStore' , {
2016-01-14 16:31:07 +01:00
url : '/api2/json' + base _url + '/status/current' ,
interval : 1000
} ) ;
var vm _command = function ( cmd , params ) {
2018-01-15 15:18:09 +01:00
Proxmox . Utils . API2Request ( {
2016-01-14 16:31:07 +01:00
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' ) ,
2017-10-30 15:03:38 +01:00
disabled : ! caps . vms [ 'VM.PowerMgmt' ] || running ,
2016-01-14 16:31:07 +01:00
handler : function ( ) {
vm _command ( 'start' ) ;
2016-04-05 11:31:46 +02:00
} ,
iconCls : 'fa fa-play'
2016-03-15 13:41:27 +01:00
} ) ;
2016-01-14 16:31:07 +01:00
2016-04-05 11:25:33 +02:00
var stopBtn = Ext . create ( 'Ext.menu.Item' , {
2016-01-14 16:31:07 +01:00
text : gettext ( 'Stop' ) ,
disabled : ! caps . vms [ 'VM.PowerMgmt' ] ,
2018-01-15 15:18:09 +01:00
confirmMsg : Proxmox . Utils . format _task _description ( 'vzstop' , vmid ) ,
2016-04-05 11:25:33 +02:00
dangerous : true ,
2016-01-14 16:31:07 +01:00
handler : function ( ) {
vm _command ( "stop" ) ;
2016-04-05 11:31:46 +02:00
} ,
iconCls : 'fa fa-stop'
2016-01-14 16:31:07 +01:00
} ) ;
2016-03-15 13:41:27 +01:00
2016-04-05 11:25:33 +02:00
var shutdownBtn = Ext . create ( 'PVE.button.Split' , {
2016-01-14 16:31:07 +01:00
text : gettext ( 'Shutdown' ) ,
2017-10-30 15:03:38 +01:00
disabled : ! caps . vms [ 'VM.PowerMgmt' ] || ! running ,
2018-01-15 15:18:09 +01:00
confirmMsg : Proxmox . Utils . format _task _description ( 'vzshutdown' , vmid ) ,
2016-01-14 16:31:07 +01:00
handler : function ( ) {
vm _command ( 'shutdown' ) ;
2016-04-05 11:25:33 +02:00
} ,
menu : {
items : [ stopBtn ]
2016-04-05 11:31:46 +02:00
} ,
iconCls : 'fa fa-power-off'
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' ] ,
2017-08-29 11:41:18 +02:00
hidden : PVE . data . ResourceStore . getNodes ( ) . length < 2 ,
2016-01-14 16:31:07 +01:00
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 ( ) ;
2016-04-05 11:31:46 +02:00
} ,
iconCls : 'fa fa-send-o'
2016-01-14 16:31:07 +01:00
} ) ;
2018-01-15 15:18:08 +01:00
var moreBtn = Ext . create ( 'Proxmox.button.Button' , {
2017-10-17 11:48:06 +02:00
text : gettext ( 'More' ) ,
menu : { items : [
{
iconCls : 'fa fa-heartbeat ' ,
hidden : ! caps . nodes [ 'Sys.Console' ] ,
text : gettext ( 'Manage HA' ) ,
handler : function ( ) {
var ha = me . pveSelNode . data . hastate ;
Ext . create ( 'PVE.ha.VMResourceEdit' , {
vmid : vmid ,
guestType : 'ct' ,
isCreate : ( ! ha || ha === 'unmanaged' )
} ) . show ( ) ;
}
} ,
{
text : gettext ( 'Remove' ) ,
disabled : ! caps . vms [ 'VM.Allocate' ] ,
itemId : 'removeBtn' ,
handler : function ( ) {
Ext . create ( 'PVE.window.SafeDestroy' , {
url : base _url ,
item : { type : 'CT' , id : vmid }
} ) . show ( ) ;
} ,
iconCls : 'fa fa-trash-o'
}
] }
2016-01-14 16:31:07 +01:00
} ) ;
2017-09-21 11:03:26 +02:00
var vm = me . pveSelNode . data ;
2016-01-14 16:31:07 +01:00
var consoleBtn = Ext . create ( 'PVE.button.ConsoleButton' , {
disabled : ! caps . vms [ 'VM.Console' ] ,
consoleType : 'lxc' ,
2017-09-21 11:03:26 +02:00
consoleName : vm . name ,
2016-01-14 16:31:07 +01:00
nodename : nodename ,
2017-12-19 14:10:01 +01:00
vmid : vmid
2016-01-14 16:31:07 +01:00
} ) ;
Ext . apply ( me , {
2017-09-21 11:03:26 +02:00
title : Ext . String . format ( gettext ( "Container {0} on node '{1}'" ) , vm . text , nodename ) ,
2016-01-14 16:31:07 +01:00
hstateid : 'lxctab' ,
2017-10-17 11:48:06 +02:00
tbar : [ startBtn , shutdownBtn , migrateBtn , consoleBtn , moreBtn ] ,
2016-01-14 16:31:07 +01:00
defaults : { statusStore : me . statusStore } ,
items : [
{
2016-03-14 13:35:10 +01:00
title : gettext ( 'Summary' ) ,
xtype : 'pveLxcSummary' ,
2016-08-22 17:13:36 +02:00
iconCls : 'fa fa-book' ,
2016-01-14 16:31:07 +01:00
itemId : 'summary'
2016-03-03 14:43:23 +01:00
}
2016-01-14 16:31:07 +01:00
]
} ) ;
2016-03-03 14:43:23 +01:00
if ( caps . vms [ 'VM.Console' ] ) {
2017-12-11 14:55:30 +01:00
me . items . push (
{
title : gettext ( 'Console' ) ,
itemId : 'console' ,
iconCls : 'fa fa-terminal' ,
xtype : 'pveNoVncConsole' ,
vmid : vmid ,
consoleType : 'lxc' ,
nodename : nodename
} ,
{
title : gettext ( 'Console (JS)' ) ,
itemId : 'consolejs' ,
iconCls : 'fa fa-terminal' ,
xtype : 'pveNoVncConsole' ,
vmid : vmid ,
consoleType : 'lxc' ,
xtermjs : true ,
nodename : nodename
}
) ;
2016-03-03 14:43:23 +01:00
}
2016-03-15 13:41:27 +01:00
2016-09-01 11:19:08 +02:00
me . items . push (
{
title : gettext ( 'Resources' ) ,
itemId : 'resources' ,
expandedOnInit : true ,
iconCls : 'fa fa-cube' ,
xtype : 'pveLxcRessourceView'
} ,
{
title : gettext ( 'Network' ) ,
iconCls : 'fa fa-exchange' ,
itemId : 'network' ,
xtype : 'pveLxcNetworkView'
} ,
{
title : gettext ( 'DNS' ) ,
iconCls : 'fa fa-globe' ,
itemId : 'dns' ,
xtype : 'pveLxcDNS'
} ,
{
title : gettext ( 'Options' ) ,
itemId : 'options' ,
iconCls : 'fa fa-gear' ,
xtype : 'pveLxcOptions'
} ,
{
title : gettext ( 'Task History' ) ,
itemId : 'tasks' ,
iconCls : 'fa fa-list' ,
2018-01-15 15:18:02 +01:00
xtype : 'proxmoxNodeTasks' ,
nodename : nodename ,
2016-09-01 11:19:08 +02:00
vmidFilter : vmid
}
) ;
if ( caps . vms [ 'VM.Backup' ] ) {
me . items . push ( {
title : gettext ( 'Backup' ) ,
iconCls : 'fa fa-floppy-o' ,
xtype : 'pveBackupView' ,
itemId : 'backup'
2017-06-13 14:56:06 +02:00
} ,
{
title : gettext ( 'Replication' ) ,
iconCls : 'fa fa-retweet' ,
xtype : 'pveReplicaView' ,
itemId : 'replication'
2016-09-01 11:19:08 +02:00
} ) ;
}
2017-09-13 12:30:34 +02:00
if ( caps . vms [ 'VM.Snapshot' ] || caps . vms [ 'VM.Snapshot.Rollback' ] ) {
2016-03-03 14:43:23 +01:00
me . items . push ( {
title : gettext ( 'Snapshots' ) ,
2016-08-22 17:13:36 +02:00
iconCls : 'fa fa-history' ,
2016-03-03 14:43:23 +01:00
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 (
{
2016-08-22 17:13:36 +02:00
xtype : 'pveFirewallRules' ,
2016-03-03 14:43:23 +01:00
title : gettext ( 'Firewall' ) ,
2016-08-22 17:13:36 +02:00
iconCls : 'fa fa-shield' ,
allow _iface : true ,
base _url : base _url + '/firewall/rules' ,
2016-09-12 14:35:58 +02:00
list _refs _url : base _url + '/firewall/refs' ,
2016-03-03 14:43:23 +01:00
itemId : 'firewall'
2016-08-22 17:13:36 +02:00
} ,
{
xtype : 'pveFirewallOptions' ,
groups : [ 'firewall' ] ,
iconCls : 'fa fa-gear' ,
2016-10-13 11:26:06 +02:00
onlineHelp : 'pve_firewall_vm_container_configuration' ,
2016-08-22 17:13:36 +02:00
title : gettext ( 'Options' ) ,
base _url : base _url + '/firewall/options' ,
fwtype : 'vm' ,
itemId : 'firewall-options'
} ,
{
xtype : 'pveFirewallAliases' ,
title : gettext ( 'Alias' ) ,
groups : [ 'firewall' ] ,
iconCls : 'fa fa-external-link' ,
base _url : base _url + '/firewall/aliases' ,
itemId : 'firewall-aliases'
} ,
{
xtype : 'pveIPSet' ,
title : gettext ( 'IPSet' ) ,
groups : [ 'firewall' ] ,
iconCls : 'fa fa-list-ol' ,
base _url : base _url + '/firewall/ipset' ,
2016-09-12 14:35:58 +02:00
list _refs _url : base _url + '/firewall/refs' ,
2016-08-22 17:13:36 +02:00
itemId : 'firewall-ipset'
} ,
{
title : gettext ( 'Log' ) ,
groups : [ 'firewall' ] ,
iconCls : 'fa fa-list' ,
2016-10-13 11:26:06 +02:00
onlineHelp : 'chapter_pve_firewall' ,
2016-08-22 17:13:36 +02:00
itemId : 'firewall-fwlog' ,
2017-12-11 16:06:50 +01:00
xtype : 'proxmoxLogView' ,
2016-08-22 17:13:36 +02:00
url : '/api2/extjs' + base _url + '/firewall/log'
2016-03-03 14:43:23 +01:00
}
) ;
}
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' ,
2016-08-22 17:13:36 +02:00
iconCls : 'fa fa-unlock' ,
2016-03-14 13:35:10 +01:00
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 ) {
status = 'unknown' ;
} else {
var rec = s . data . get ( 'status' ) ;
status = rec ? rec . data . value : 'unknown' ;
2016-03-30 09:35:52 +02:00
rec = s . data . get ( 'template' ) ;
template = rec . data . value || false ;
2016-01-14 16:31:07 +01:00
}
2016-03-30 09:35:52 +02:00
startBtn . setDisabled ( ! caps . vms [ 'VM.PowerMgmt' ] || status === 'running' || template ) ;
2016-01-14 16:31:07 +01:00
shutdownBtn . setDisabled ( ! caps . vms [ 'VM.PowerMgmt' ] || status !== 'running' ) ;
stopBtn . setDisabled ( ! caps . vms [ 'VM.PowerMgmt' ] || status === 'stopped' ) ;
2017-10-17 11:48:06 +02:00
me . down ( '#removeBtn' ) . setDisabled ( ! caps . vms [ 'VM.Allocate' ] || status !== 'stopped' ) ;
2016-03-30 09:35:52 +02:00
consoleBtn . setDisabled ( template ) ;
2016-01-14 16:31:07 +01:00
} ) ;
me . on ( 'afterrender' , function ( ) {
me . statusStore . startUpdate ( ) ;
} ) ;
me . on ( 'destroy' , function ( ) {
me . statusStore . stopUpdate ( ) ;
} ) ;
}
} ) ;