From 6d0c48ac1f9186bb4b055b20cf6a9ce1c02798da Mon Sep 17 00:00:00 2001 From: Plessis Date: Mon, 3 Dec 2018 11:52:36 +0100 Subject: [PATCH] User provisioning support for Linux Openwrt Signed-off-by: Plessis Adrien --- azurelinuxagent/common/osutil/openwrt.py | 30 ++++++++++++++++++++++++ bin/waagent2.0 | 8 +++++++ 2 files changed, 38 insertions(+) diff --git a/azurelinuxagent/common/osutil/openwrt.py b/azurelinuxagent/common/osutil/openwrt.py index 5c5b02b704..5534b8eba5 100644 --- a/azurelinuxagent/common/osutil/openwrt.py +++ b/azurelinuxagent/common/osutil/openwrt.py @@ -34,7 +34,33 @@ def __init__(self): self.ip_command_output = re.compile('^\d+:\s+(\w+):\s+(.*)$') self.jit_enabled = True + def eject_dvd(self, chk_err=True): + logger.warn('eject is not supported on OpenWRT') + + def useradd(self, username, expiration=None, comment=None): + """ + Create user account with 'username' + """ + userentry = self.get_userentry(username) + if userentry is not None: + logger.info("User {0} already exists, skip useradd", username) + return + + if expiration is not None: + cmd = "useradd -m {0} -s /bin/ash -e {1}".format(username, expiration) + else: + cmd = "useradd -m {0} -s /bin/ash".format(username) + if not os.path.exists("/home"): + os.mkdir("/home") + + if comment is not None: + cmd += " -c {0}".format(comment) + retcode, out = shellutil.run_get_output(cmd) + if retcode != 0: + raise OSUtilError(("Failed to create user account:{0}, " + "retcode:{1}, " + "output:{2}").format(username, retcode, out)) def is_dhcp_enabled(self): pass @@ -65,3 +91,7 @@ def register_agent_service(self): def unregister_agent_service(self): return shellutil.run("/etc/init.d/waagent disable", chk_err=True) + + def set_hostname(self, hostname): + fileutil.write_file('/etc/hostname', hostname) + shellutil.run("uci set system.@system[0].hostname='{0}' && uci commit system && /etc/init.d/system reload".format(hostname), chk_err=False) diff --git a/bin/waagent2.0 b/bin/waagent2.0 index 3f9c9ddc4a..f24bf3d1ee 100644 --- a/bin/waagent2.0 +++ b/bin/waagent2.0 @@ -3,6 +3,7 @@ # Azure Linux Agent # # Copyright 2015 Microsoft Corporation +# Copyright 2018 Sonus Networks, Inc. (d.b.a. Ribbon Communications Operating Company) # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -2253,6 +2254,13 @@ class OpenWRTDistro(AbstractDistro): self.installAgentServiceScriptFiles() return Run('/etc/init.d/' + self.agent_service_name + ' enable ') + def setHostname(self,name): + """ + Shell call to uci. + Returns resulting exit code. + """ + return Run("uci set system.@system[0].hostname='{0}' && uci commit system && /etc/init.d/system reload".format(name)) + def startAgentService(self): """ Service call to start the Agent service