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