]>
Commit | Line | Data |
---|---|---|
e7f07a2e DC |
1 | Ext.define('PVE.window.IPInfo', { |
2 | extend: 'Ext.window.Window', | |
3 | width: 600, | |
4 | title: gettext('Guest Agent Network Information'), | |
5 | height: 300, | |
6 | layout: { | |
f6710aac | 7 | type: 'fit', |
e7f07a2e DC |
8 | }, |
9 | modal: true, | |
10 | items: [ | |
11 | { | |
12 | xtype: 'grid', | |
3098f188 | 13 | store: {}, |
e7f07a2e | 14 | emptyText: gettext('No network information'), |
6d336ba4 AL |
15 | viewConfig: { |
16 | enableTextSelection: true, | |
17 | }, | |
e7f07a2e DC |
18 | columns: [ |
19 | { | |
20 | dataIndex: 'name', | |
21 | text: gettext('Name'), | |
f6710aac | 22 | flex: 3, |
e7f07a2e DC |
23 | }, |
24 | { | |
25 | dataIndex: 'hardware-address', | |
26 | text: gettext('MAC address'), | |
f6710aac | 27 | width: 140, |
e7f07a2e DC |
28 | }, |
29 | { | |
30 | dataIndex: 'ip-addresses', | |
31 | text: gettext('IP address'), | |
32 | align: 'right', | |
33 | flex: 4, | |
34 | renderer: function(val) { | |
35 | if (!Ext.isArray(val)) { | |
36 | return ''; | |
37 | } | |
38 | var ips = []; | |
39 | val.forEach(function(ip) { | |
40 | var addr = ip['ip-address']; | |
41 | var pref = ip.prefix; | |
8058410f | 42 | if (addr && pref) { |
e7f07a2e DC |
43 | ips.push(addr + '/' + pref); |
44 | } | |
45 | }); | |
46 | return ips.join('<br>'); | |
f6710aac TL |
47 | }, |
48 | }, | |
49 | ], | |
50 | }, | |
51 | ], | |
e7f07a2e DC |
52 | }); |
53 | ||
54 | Ext.define('PVE.qemu.AgentIPView', { | |
55 | extend: 'Ext.container.Container', | |
56 | xtype: 'pveAgentIPView', | |
57 | ||
58 | layout: { | |
59 | type: 'hbox', | |
f6710aac | 60 | align: 'top', |
e7f07a2e DC |
61 | }, |
62 | ||
63 | nics: [], | |
64 | ||
65 | items: [ | |
66 | { | |
67 | xtype: 'box', | |
f6710aac | 68 | html: '<i class="fa fa-exchange"></i> IPs', |
e7f07a2e DC |
69 | }, |
70 | { | |
71 | xtype: 'container', | |
72 | flex: 1, | |
73 | layout: { | |
74 | type: 'vbox', | |
75 | align: 'right', | |
f6710aac | 76 | pack: 'end', |
e7f07a2e DC |
77 | }, |
78 | items: [ | |
79 | { | |
80 | xtype: 'label', | |
81 | flex: 1, | |
82 | itemId: 'ipBox', | |
83 | style: { | |
f6710aac TL |
84 | 'text-align': 'right', |
85 | }, | |
e7f07a2e DC |
86 | }, |
87 | { | |
88 | xtype: 'button', | |
89 | itemId: 'moreBtn', | |
90 | hidden: true, | |
91 | ui: 'default-toolbar', | |
92 | handler: function(btn) { | |
46d9a35c | 93 | let view = this.up('pveAgentIPView'); |
e7f07a2e DC |
94 | |
95 | var win = Ext.create('PVE.window.IPInfo'); | |
46d9a35c | 96 | win.down('grid').getStore().setData(view.nics); |
e7f07a2e DC |
97 | win.show(); |
98 | }, | |
f6710aac TL |
99 | text: gettext('More'), |
100 | }, | |
101 | ], | |
102 | }, | |
e7f07a2e DC |
103 | ], |
104 | ||
105 | getDefaultIps: function(nics) { | |
106 | var me = this; | |
107 | var ips = []; | |
108 | nics.forEach(function(nic) { | |
109 | if (nic['hardware-address'] && | |
91a47a76 DJ |
110 | nic['hardware-address'] !== '00:00:00:00:00:00' && |
111 | nic['hardware-address'] !== '0:0:0:0:0:0') { | |
e7f07a2e DC |
112 | var nic_ips = nic['ip-addresses'] || []; |
113 | nic_ips.forEach(function(ip) { | |
114 | var p = ip['ip-address']; | |
115 | // show 2 ips at maximum | |
116 | if (ips.length < 2) { | |
117 | ips.push(p); | |
118 | } | |
119 | }); | |
120 | } | |
121 | }); | |
122 | ||
123 | return ips; | |
124 | }, | |
125 | ||
126 | startIPStore: function(store, records, success) { | |
127 | var me = this; | |
aa857130 TL |
128 | let agentRec = store.getById('agent'); |
129 | let state = store.getById('status'); | |
130 | ||
53e3ea84 TL |
131 | me.agent = agentRec && agentRec.data.value === 1; |
132 | me.running = state && state.data.value === 'running'; | |
e7f07a2e | 133 | |
5fa6f320 DC |
134 | var caps = Ext.state.Manager.get('GuiCap'); |
135 | ||
136 | if (!caps.vms['VM.Monitor']) { | |
137 | var errorText = gettext("Requires '{0}' Privileges"); | |
138 | me.updateStatus(false, Ext.String.format(errorText, 'VM.Monitor')); | |
139 | return; | |
140 | } | |
141 | ||
e7f07a2e DC |
142 | if (me.agent && me.running && me.ipStore.isStopped) { |
143 | me.ipStore.startUpdate(); | |
2283cff3 DC |
144 | } else if (me.ipStore.isStopped) { |
145 | me.updateStatus(); | |
e7f07a2e | 146 | } |
e7f07a2e DC |
147 | }, |
148 | ||
5fa6f320 | 149 | updateStatus: function(unsuccessful, defaulttext) { |
e7f07a2e | 150 | var me = this; |
5fa6f320 | 151 | var text = defaulttext || gettext('No network information'); |
e7f07a2e DC |
152 | var more = false; |
153 | if (unsuccessful) { | |
154 | text = gettext('Guest Agent not running'); | |
155 | } else if (me.agent && me.running) { | |
203829c7 | 156 | if (Ext.isArray(me.nics) && me.nics.length) { |
e7f07a2e DC |
157 | more = true; |
158 | var ips = me.getDefaultIps(me.nics); | |
159 | if (ips.length !== 0) { | |
160 | text = ips.join('<br>'); | |
161 | } | |
162 | } else if (me.nics && me.nics.error) { | |
e7f07a2e DC |
163 | text = Ext.String.format(text, me.nics.error.desc); |
164 | } | |
165 | } else if (me.agent) { | |
166 | text = gettext('Guest Agent not running'); | |
167 | } else { | |
168 | text = gettext('No Guest Agent configured'); | |
169 | } | |
170 | ||
171 | var ipBox = me.down('#ipBox'); | |
172 | ipBox.update(text); | |
173 | ||
174 | var moreBtn = me.down('#moreBtn'); | |
175 | moreBtn.setVisible(more); | |
176 | }, | |
177 | ||
178 | initComponent: function() { | |
179 | var me = this; | |
180 | ||
181 | if (!me.rstore) { | |
182 | throw 'rstore not given'; | |
183 | } | |
184 | ||
185 | if (!me.pveSelNode) { | |
186 | throw 'pveSelNode not given'; | |
187 | } | |
188 | ||
189 | var nodename = me.pveSelNode.data.node; | |
190 | var vmid = me.pveSelNode.data.vmid; | |
191 | ||
192 | me.ipStore = Ext.create('Proxmox.data.UpdateStore', { | |
193 | interval: 10000, | |
194 | storeid: 'pve-qemu-agent-' + vmid, | |
195 | method: 'POST', | |
196 | proxy: { | |
197 | type: 'proxmox', | |
f6710aac TL |
198 | url: '/api2/json/nodes/' + nodename + '/qemu/' + vmid + '/agent/network-get-interfaces', |
199 | }, | |
e7f07a2e DC |
200 | }); |
201 | ||
202 | me.callParent(); | |
203 | ||
204 | me.mon(me.ipStore, 'load', function(store, records, success) { | |
205 | if (records && records.length) { | |
206 | me.nics = records[0].data.result; | |
207 | } else { | |
208 | me.nics = undefined; | |
209 | } | |
210 | me.updateStatus(!success); | |
211 | }); | |
212 | ||
6386068d | 213 | me.on('destroy', me.ipStore.stopUpdate, me.ipStore); |
e7f07a2e DC |
214 | |
215 | // if we already have info about the vm, use it immediately | |
216 | if (me.rstore.getCount()) { | |
217 | me.startIPStore(me.rstore, me.rstore.getData(), false); | |
218 | } | |
219 | ||
220 | // check if the guest agent is there on every statusstore load | |
221 | me.mon(me.rstore, 'load', me.startIPStore, me); | |
f6710aac | 222 | }, |
e7f07a2e | 223 | }); |