summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Ball <bob.ball@citrix.com>2016-09-12 09:40:48 +0100
committerBob Ball <bob.ball@citrix.com>2016-09-12 09:40:48 +0100
commitfa98aab579a6d1af1c82bbfb51a5f719f2239dbd (patch)
tree9ed1ae6e3f0d70e9fd0da39e167eb8d87806f67e
parent60c6a9cafc25ab1c66f1a5c9d3b5f688ab54396e (diff)
Check for HIMN using dhcp discovery8.0
A future plan for this plugin is to not require the HIMN XC plugin but to support adding the network just in XenCenter (with hidden objects displayed). Therefore the fuel plugin should try to auto detect the HIMN as the MAC would not be written to XenStore. Cherry-pick of 01402e857c99a3a8aa76535cde81c479e330a0a6 Change-Id: I83aa26b16f9839979b63616bdf358219ff23739f
Notes
Notes (review): Verified-1: Citrix XenServer CI Code-Review+1: John Hua <john.hua@citrix.com> Code-Review+2: huan <huan.xie@citrix.com> Workflow+1: John Hua <john.hua@citrix.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Tue, 13 Sep 2016 09:59:49 +0000 Reviewed-on: https://review.openstack.org/368640 Project: openstack/fuel-plugin-xenserver Branch: refs/heads/8.0
-rwxr-xr-xdeployment_scripts/compute_post_deployment.py92
1 files changed, 77 insertions, 15 deletions
diff --git a/deployment_scripts/compute_post_deployment.py b/deployment_scripts/compute_post_deployment.py
index 0f47cb2..928a108 100755
--- a/deployment_scripts/compute_post_deployment.py
+++ b/deployment_scripts/compute_post_deployment.py
@@ -68,7 +68,11 @@ def execute(*cmd, **kwargs):
68 logging.error(err) 68 logging.error(err)
69 69
70 if proc.returncode is not None and proc.returncode != 0: 70 if proc.returncode is not None and proc.returncode != 0:
71 raise Exception(err) 71 if proc.returncode in kwargs.get('allowed_return_codes', [0]):
72 logging.info('Swallowed acceptable return code of %d',
73 proc.returncode)
74 else:
75 raise Exception(err)
72 76
73 return out 77 return out
74 78
@@ -161,13 +165,25 @@ def get_endpoints(astute):
161 return endpoints 165 return endpoints
162 166
163 167
164def init_eth(): 168def eth_to_mac(eth):
165 """Initialize the net interface connected to HIMN 169 return netifaces.ifaddresses(eth).get(netifaces.AF_LINK)[0]['addr']
166 170
167 Returns:
168 the IP addresses of local host and XenServer.
169 """
170 171
172def detect_himn_ip(eths=None):
173 if eths is None:
174 eths = netifaces.interfaces()
175 for eth in eths:
176 ip = netifaces.ifaddresses(eth).get(netifaces.AF_INET)
177 if ip is None:
178 continue
179 himn_local = ip[0]['addr']
180 himn_xs = '.'.join(himn_local.split('.')[:-1] + ['1'])
181 if HIMN_IP == himn_xs:
182 return eth, ip
183 return None, None
184
185
186def find_eth_xenstore():
171 domid = execute('xenstore-read', 'domid') 187 domid = execute('xenstore-read', 'domid')
172 himn_mac = execute( 188 himn_mac = execute(
173 'xenstore-read', 189 'xenstore-read',
@@ -176,16 +192,56 @@ def init_eth():
176 192
177 _mac = lambda eth: \ 193 _mac = lambda eth: \
178 netifaces.ifaddresses(eth).get(netifaces.AF_LINK)[0]['addr'] 194 netifaces.ifaddresses(eth).get(netifaces.AF_LINK)[0]['addr']
179 eths = [eth for eth in netifaces.interfaces() if _mac(eth) == himn_mac] 195 eths = [eth for eth in netifaces.interfaces()
196 if eth_to_mac(eth) == himn_mac]
180 if len(eths) != 1: 197 if len(eths) != 1:
181 reportError('Cannot find eth matches himn_mac') 198 reportError('Cannot find eth matches himn_mac')
182 199
183 eth = eths[0] 200 return eths[0]
184 logging.info('himn_eth: %s' % eth) 201
202
203def detect_eth_dhclient():
204 for eth in netifaces.interfaces():
205 # Don't try and dhclient for devices an IP address already
206 ip = netifaces.ifaddresses(eth).get(netifaces.AF_INET)
207 if ip:
208 continue
209
210 # DHCP replies from HIMN should be super fast
211 execute('timeout', '2s', 'dhclient', eth,
212 allowed_return_codes=[0, 124])
213 try:
214 _, ip = detect_himn_ip([eth])
215 if ip is not None:
216 return eth
217 finally:
218 execute('dhclient', '-r', eth)
185 219
186 ip = netifaces.ifaddresses(eth).get(netifaces.AF_INET) 220
221def init_eth():
222 """Initialize the net interface connected to HIMN
223
224 Returns:
225 the IP addresses of local host and hypervisor.
226 """
227
228 eth, ip = detect_himn_ip()
187 229
188 if not ip: 230 if not ip:
231 eth = None
232 try:
233 eth = find_eth_xenstore()
234 except Exception:
235 logging.debug('Failed to find MAC through xenstore', exc_info=True)
236
237 if eth is None:
238 eth = detect_eth_dhclient()
239
240 if eth is None:
241 reportError('Failed to detect HIMN ethernet device')
242
243 logging.info('himn_eth: %s' % eth)
244
189 execute('dhclient', eth) 245 execute('dhclient', eth)
190 fname = '/etc/network/interfaces.d/ifcfg-' + eth 246 fname = '/etc/network/interfaces.d/ifcfg-' + eth
191 s = ('auto {eth}\n' 247 s = ('auto {eth}\n'
@@ -196,16 +252,22 @@ def init_eth():
196 logging.info('%s created' % fname) 252 logging.info('%s created' % fname)
197 execute('ifdown', eth) 253 execute('ifdown', eth)
198 execute('ifup', eth) 254 execute('ifup', eth)
255
199 ip = netifaces.ifaddresses(eth).get(netifaces.AF_INET) 256 ip = netifaces.ifaddresses(eth).get(netifaces.AF_INET)
200 257
201 if ip:
202 himn_local = ip[0]['addr'] 258 himn_local = ip[0]['addr']
203 himn_xs = '.'.join(himn_local.split('.')[:-1] + ['1']) 259 himn_xs = '.'.join(himn_local.split('.')[:-1] + ['1'])
204 if HIMN_IP == himn_xs: 260 if HIMN_IP != himn_xs:
205 logging.info('himn_local: %s' % himn_local) 261 # Not on the HIMN - we failed here.
206 return eth, himn_local 262 logging.info('himn_local: DHCP returned incorrect IP %s' %
263 ip[0]['addr'])
264 ip = None
265
266 if not ip:
267 reportError('HIMN failed to get IP address from Hypervisor')
207 268
208 reportError('HIMN failed to get IP address from XenServer') 269 logging.info('himn_local: %s' % ip[0]['addr'])
270 return eth, ip[0]['addr']
209 271
210 272
211def check_host_compatibility(himn, username): 273def check_host_compatibility(himn, username):