]>
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'),
13 emptyText
: gettext('No network information'),
17 text
: gettext('Name'),
21 dataIndex
: 'hardware-address',
22 text
: gettext('MAC address'),
26 dataIndex
: 'ip-addresses',
27 text
: gettext('IP address'),
30 renderer: function(val
) {
31 if (!Ext
.isArray(val
)) {
35 val
.forEach(function(ip
) {
36 var addr
= ip
['ip-address'];
39 ips
.push(addr
+ '/' + pref
);
42 return ips
.join('<br>');
50 Ext
.define('PVE.qemu.AgentIPView', {
51 extend
: 'Ext.container.Container',
52 xtype
: 'pveAgentIPView',
64 html
: '<i class="fa fa-exchange"></i> IPs'
87 ui
: 'default-toolbar',
88 handler: function(btn
) {
89 var me
= this.up('pveAgentIPView');
91 var win
= Ext
.create('PVE.window.IPInfo');
92 win
.down('grid').getStore().setData(me
.nics
);
101 getDefaultIps: function(nics
) {
104 nics
.forEach(function(nic
) {
105 if (nic
['hardware-address'] &&
106 nic
['hardware-address'] != '00:00:00:00:00:00') {
108 var nic_ips
= nic
['ip-addresses'] || [];
109 nic_ips
.forEach(function(ip
) {
110 var p
= ip
['ip-address'];
111 // show 2 ips at maximum
112 if (ips
.length
< 2) {
122 startIPStore: function(store
, records
, success
) {
124 var agentRec
= store
.getById('agent');
125 /*jslint confusion: true*/
126 /* value is number and string */
127 me
.agent
= (agentRec
&& agentRec
.data
.value
=== 1);
128 me
.running
= (store
.getById('status').data
.value
=== 'running');
129 /*jslint confusion: false*/
131 if (me
.agent
&& me
.running
&& me
.ipStore
.isStopped
) {
132 me
.ipStore
.startUpdate();
137 updateStatus: function(unsuccessful
) {
139 var text
= gettext('No network information');
142 text
= gettext('Guest Agent not running');
143 } else if (me
.agent
&& me
.running
) {
144 if (Ext
.isArray(me
.nics
)) {
146 var ips
= me
.getDefaultIps(me
.nics
);
147 if (ips
.length
!== 0) {
148 text
= ips
.join('<br>');
150 } else if (me
.nics
&& me
.nics
.error
) {
151 var msg
= gettext('Cannot get info from Guest Agent<br>Error: {0}');
152 text
= Ext
.String
.format(text
, me
.nics
.error
.desc
);
154 } else if (me
.agent
) {
155 text
= gettext('Guest Agent not running');
157 text
= gettext('No Guest Agent configured');
160 var ipBox
= me
.down('#ipBox');
163 var moreBtn
= me
.down('#moreBtn');
164 moreBtn
.setVisible(more
);
167 initComponent: function() {
171 throw 'rstore not given';
174 if (!me
.pveSelNode
) {
175 throw 'pveSelNode not given';
178 var nodename
= me
.pveSelNode
.data
.node
;
179 var vmid
= me
.pveSelNode
.data
.vmid
;
181 me
.ipStore
= Ext
.create('Proxmox.data.UpdateStore', {
183 storeid
: 'pve-qemu-agent-' + vmid
,
187 url
: '/api2/json/nodes/' + nodename
+ '/qemu/' + vmid
+ '/agent/network-get-interfaces'
193 me
.mon(me
.ipStore
, 'load', function(store
, records
, success
) {
194 if (records
&& records
.length
) {
195 me
.nics
= records
[0].data
.result
;
199 me
.updateStatus(!success
);
202 me
.on('destroy', me
.ipStore
.stopUpdate
);
204 // if we already have info about the vm, use it immediately
205 if (me
.rstore
.getCount()) {
206 me
.startIPStore(me
.rstore
, me
.rstore
.getData(), false);
209 // check if the guest agent is there on every statusstore load
210 me
.mon(me
.rstore
, 'load', me
.startIPStore
, me
);