]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/qemu/AgentIPView.js
show guest-agent provided ip address in qemu summary
[pve-manager.git] / www / manager6 / qemu / AgentIPView.js
CommitLineData
e7f07a2e
DC
1Ext.define('PVE.window.IPInfo', {
2 extend: 'Ext.window.Window',
3 width: 600,
4 title: gettext('Guest Agent Network Information'),
5 height: 300,
6 layout: {
7 type: 'fit'
8 },
9 modal: true,
10 items: [
11 {
12 xtype: 'grid',
13 emptyText: gettext('No network information'),
14 columns: [
15 {
16 dataIndex: 'name',
17 text: gettext('Name'),
18 flex: 3
19 },
20 {
21 dataIndex: 'hardware-address',
22 text: gettext('MAC address'),
23 width: 140
24 },
25 {
26 dataIndex: 'ip-addresses',
27 text: gettext('IP address'),
28 align: 'right',
29 flex: 4,
30 renderer: function(val) {
31 if (!Ext.isArray(val)) {
32 return '';
33 }
34 var ips = [];
35 val.forEach(function(ip) {
36 var addr = ip['ip-address'];
37 var pref = ip.prefix;
38 if (addr && pref) {
39 ips.push(addr + '/' + pref);
40 }
41 });
42 return ips.join('<br>');
43 }
44 }
45 ]
46 }
47 ]
48});
49
50Ext.define('PVE.qemu.AgentIPView', {
51 extend: 'Ext.container.Container',
52 xtype: 'pveAgentIPView',
53
54 layout: {
55 type: 'hbox',
56 align: 'top'
57 },
58
59 nics: [],
60
61 items: [
62 {
63 xtype: 'box',
64 html: '<i class="fa fa-exchange"></i> IPs'
65 },
66 {
67 xtype: 'container',
68 flex: 1,
69 layout: {
70 type: 'vbox',
71 align: 'right',
72 pack: 'end'
73 },
74 items: [
75 {
76 xtype: 'label',
77 flex: 1,
78 itemId: 'ipBox',
79 style: {
80 'text-align': 'right'
81 }
82 },
83 {
84 xtype: 'button',
85 itemId: 'moreBtn',
86 hidden: true,
87 ui: 'default-toolbar',
88 handler: function(btn) {
89 var me = this.up('pveAgentIPView');
90
91 var win = Ext.create('PVE.window.IPInfo');
92 win.down('grid').getStore().setData(me.nics);
93 win.show();
94 },
95 text: gettext('More')
96 }
97 ]
98 }
99 ],
100
101 getDefaultIps: function(nics) {
102 var me = this;
103 var ips = [];
104 nics.forEach(function(nic) {
105 if (nic['hardware-address'] &&
106 nic['hardware-address'] != '00:00:00:00:00:00') {
107
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) {
113 ips.push(p);
114 }
115 });
116 }
117 });
118
119 return ips;
120 },
121
122 startIPStore: function(store, records, success) {
123 var me = this;
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*/
130
131 if (me.agent && me.running && me.ipStore.isStopped) {
132 me.ipStore.startUpdate();
133 }
134 me.updateStatus();
135 },
136
137 updateStatus: function(unsuccessful) {
138 var me = this;
139 var text = gettext('No network information');
140 var more = false;
141 if (unsuccessful) {
142 text = gettext('Guest Agent not running');
143 } else if (me.agent && me.running) {
144 if (Ext.isArray(me.nics)) {
145 more = true;
146 var ips = me.getDefaultIps(me.nics);
147 if (ips.length !== 0) {
148 text = ips.join('<br>');
149 }
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);
153 }
154 } else if (me.agent) {
155 text = gettext('Guest Agent not running');
156 } else {
157 text = gettext('No Guest Agent configured');
158 }
159
160 var ipBox = me.down('#ipBox');
161 ipBox.update(text);
162
163 var moreBtn = me.down('#moreBtn');
164 moreBtn.setVisible(more);
165 },
166
167 initComponent: function() {
168 var me = this;
169
170 if (!me.rstore) {
171 throw 'rstore not given';
172 }
173
174 if (!me.pveSelNode) {
175 throw 'pveSelNode not given';
176 }
177
178 var nodename = me.pveSelNode.data.node;
179 var vmid = me.pveSelNode.data.vmid;
180
181 me.ipStore = Ext.create('Proxmox.data.UpdateStore', {
182 interval: 10000,
183 storeid: 'pve-qemu-agent-' + vmid,
184 method: 'POST',
185 proxy: {
186 type: 'proxmox',
187 url: '/api2/json/nodes/' + nodename + '/qemu/' + vmid + '/agent/network-get-interfaces'
188 }
189 });
190
191 me.callParent();
192
193 me.mon(me.ipStore, 'load', function(store, records, success) {
194 if (records && records.length) {
195 me.nics = records[0].data.result;
196 } else {
197 me.nics = undefined;
198 }
199 me.updateStatus(!success);
200 });
201
202 me.on('destroy', me.ipStore.stopUpdate);
203
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);
207 }
208
209 // check if the guest agent is there on every statusstore load
210 me.mon(me.rstore, 'load', me.startIPStore, me);
211 }
212});