|
Lines 1-27
Link Here
|
| 1 |
--- google_compute_engine/network_setup/network_setup.py.orig 2017-09-29 00:21:28 UTC |
|
|
| 2 |
+++ google_compute_engine/network_setup/network_setup.py |
| 3 |
@@ -107,12 +107,18 @@ class NetworkSetup(object): |
| 4 |
self.logger.info('Enabling the Ethernet interfaces %s.', interfaces) |
| 5 |
dhclient_command = ['dhclient'] |
| 6 |
if os.path.exists(self.dhclient_script): |
| 7 |
- dhclient_command += ['-sf', self.dhclient_script] |
| 8 |
- try: |
| 9 |
- subprocess.check_call(dhclient_command + ['-x'] + interfaces) |
| 10 |
- subprocess.check_call(dhclient_command + interfaces) |
| 11 |
- except subprocess.CalledProcessError: |
| 12 |
- self.logger.warning('Could not enable interfaces %s.', interfaces) |
| 13 |
+ dhclient_conf = '/etc/dhclient.conf' |
| 14 |
+ if os.path.exists(dhclient_conf): |
| 15 |
+ subprocess.call('sed -i "" "/^script/d" ' + dhclient_conf, shell=True) |
| 16 |
+ subprocess.call('echo \'script "%s";\' >> %s' % (self.dhclient_script, dhclient_conf), shell=True) |
| 17 |
+ for interface in interfaces: |
| 18 |
+ try: |
| 19 |
+ subprocess.check_call(['ifconfig', interface, 'down', 'delete']) |
| 20 |
+ # wait previous dhclient to exit |
| 21 |
+ subprocess.check_call(['sleep', '3']) |
| 22 |
+ subprocess.check_call(dhclient_command + [interface]) |
| 23 |
+ except subprocess.CalledProcessError: |
| 24 |
+ self.logger.warning('Could not enable interface %s.', interface) |
| 25 |
|
| 26 |
def _EnableNetworkInterfaces(self, interfaces): |
| 27 |
"""Enable the list of network interfaces. |