]>
git.proxmox.com Git - pve-manager.git/blob - www/manager6/qemu/AgentIPView.js
1 Ext
.define('PVE.window.IPInfo', {
2 extend
: 'Ext.window.Window',
4 title
: gettext('Guest Agent Network Information'),
14 emptyText
: gettext('No network information'),
18 text
: gettext('Name'),
22 dataIndex
: 'hardware-address',
23 text
: gettext('MAC address'),
27 dataIndex
: 'ip-addresses',
28 text
: gettext('IP address'),
31 renderer: function(val
) {
32 if (!Ext
.isArray(val
)) {
36 val
.forEach(function(ip
) {
37 var addr
= ip
['ip-address'];
40 ips
.push(addr
+ '/' + pref
);
43 return ips
.join('<br>');
51 Ext
.define('PVE.qemu.AgentIPView', {
52 extend
: 'Ext.container.Container',
53 xtype
: 'pveAgentIPView',
65 html
: '<i class="fa fa-exchange"></i> IPs',
81 'text-align': 'right',
88 ui
: 'default-toolbar',
89 handler: function(btn
) {
90 let view
= this.up('pveAgentIPView');
92 var win
= Ext
.create('PVE.window.IPInfo');
93 win
.down('grid').getStore().setData(view
.nics
);
96 text
: gettext('More'),
102 getDefaultIps: function(nics
) {
105 nics
.forEach(function(nic
) {
106 if (nic
['hardware-address'] &&
107 nic
['hardware-address'] !== '00:00:00:00:00:00' &&
108 nic
['hardware-address'] !== '0:0:0:0:0:0') {
109 var nic_ips
= nic
['ip-addresses'] || [];
110 nic_ips
.forEach(function(ip
) {
111 var p
= ip
['ip-address'];
112 // show 2 ips at maximum
113 if (ips
.length
< 2) {
123 startIPStore: function(store
, records
, success
) {
125 let agentRec
= store
.getById('agent');
126 let state
= store
.getById('status');
128 me
.agent
= agentRec
&& agentRec
.data
.value
=== 1;
129 me
.running
= state
&& state
.data
.value
=== 'running';
131 var caps
= Ext
.state
.Manager
.get('GuiCap');
133 if (!caps
.vms
['VM.Monitor']) {
134 var errorText
= gettext("Requires '{0}' Privileges");
135 me
.updateStatus(false, Ext
.String
.format(errorText
, 'VM.Monitor'));
139 if (me
.agent
&& me
.running
&& me
.ipStore
.isStopped
) {
140 me
.ipStore
.startUpdate();
141 } else if (me
.ipStore
.isStopped
) {
146 updateStatus: function(unsuccessful
, defaulttext
) {
148 var text
= defaulttext
|| gettext('No network information');
151 text
= gettext('Guest Agent not running');
152 } else if (me
.agent
&& me
.running
) {
153 if (Ext
.isArray(me
.nics
) && me
.nics
.length
) {
155 var ips
= me
.getDefaultIps(me
.nics
);
156 if (ips
.length
!== 0) {
157 text
= ips
.join('<br>');
159 } else if (me
.nics
&& me
.nics
.error
) {
160 text
= Ext
.String
.format(text
, me
.nics
.error
.desc
);
162 } else if (me
.agent
) {
163 text
= gettext('Guest Agent not running');
165 text
= gettext('No Guest Agent configured');
168 var ipBox
= me
.down('#ipBox');
171 var moreBtn
= me
.down('#moreBtn');
172 moreBtn
.setVisible(more
);
175 initComponent: function() {
179 throw 'rstore not given';
182 if (!me
.pveSelNode
) {
183 throw 'pveSelNode not given';
186 var nodename
= me
.pveSelNode
.data
.node
;
187 var vmid
= me
.pveSelNode
.data
.vmid
;
189 me
.ipStore
= Ext
.create('Proxmox.data.UpdateStore', {
191 storeid
: 'pve-qemu-agent-' + vmid
,
195 url
: '/api2/json/nodes/' + nodename
+ '/qemu/' + vmid
+ '/agent/network-get-interfaces',
201 me
.mon(me
.ipStore
, 'load', function(store
, records
, success
) {
202 if (records
&& records
.length
) {
203 me
.nics
= records
[0].data
.result
;
207 me
.updateStatus(!success
);
210 me
.on('destroy', me
.ipStore
.stopUpdate
, me
.ipStore
);
212 // if we already have info about the vm, use it immediately
213 if (me
.rstore
.getCount()) {
214 me
.startIPStore(me
.rstore
, me
.rstore
.getData(), false);
217 // check if the guest agent is there on every statusstore load
218 me
.mon(me
.rstore
, 'load', me
.startIPStore
, me
);