summaryrefslogtreecommitdiff
path: root/src/etc/vmware-tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/etc/vmware-tools')
-rwxr-xr-xsrc/etc/vmware-tools/scripts/resume-vm-default.d/ether-resume.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/etc/vmware-tools/scripts/resume-vm-default.d/ether-resume.py b/src/etc/vmware-tools/scripts/resume-vm-default.d/ether-resume.py
index 72da317f5..dc751c45c 100755
--- a/src/etc/vmware-tools/scripts/resume-vm-default.d/ether-resume.py
+++ b/src/etc/vmware-tools/scripts/resume-vm-default.d/ether-resume.py
@@ -15,11 +15,12 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
-import subprocess
import syslog as sl
from vyos.config import Config
-from vyos.util import vyos
+from vyos import ConfigError
+from vyos.util import run
+
def get_config():
c = Config()
@@ -28,7 +29,7 @@ def get_config():
# skip interfaces that are disabled or is configured for dhcp
check_disable = "interfaces ethernet {} disable".format(intf)
check_dhcp = "interfaces ethernet {} address dhcp".format(intf)
- if c.exists_effective(check_disable) or c.exists_effective(check_dhcp):
+ if c.exists_effective(check_disable):
continue
# get addresses configured on the interface
@@ -38,23 +39,28 @@ def get_config():
interfaces[intf] = [addr.strip("'") for addr in intf_addresses]
return interfaces
+
def apply(config):
for intf, addresses in config.items():
# bring the interface up
cmd = ["ip", "link", "set", "dev", intf, "up"]
sl.syslog(sl.LOG_NOTICE, " ".join(cmd))
- subprocess.call(cmd)
+ run(cmd)
# add configured addresses to interface
for addr in addresses:
- cmd = ["ip", "address", "add", addr, "dev", intf]
+ if addr == "dhcp":
+ cmd = ["dhclient", intf]
+ else:
+ cmd = ["ip", "address", "add", addr, "dev", intf]
sl.syslog(sl.LOG_NOTICE, " ".join(cmd))
- subprocess.call(cmd)
+ run(cmd)
+
if __name__ == '__main__':
try:
config = get_config()
apply(config)
- except vyos.ConfigError as e:
+ except ConfigError as e:
print(e)
sys.exit(1)