Skip to content

Commit

Permalink
User provisioning support for Linux Openwrt
Browse files Browse the repository at this point in the history
Signed-off-by: Plessis Adrien <adr.plessis@gmail.com>
  • Loading branch information
Plessis committed Jan 11, 2019
1 parent ffcc771 commit 6d0c48a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
30 changes: 30 additions & 0 deletions azurelinuxagent/common/osutil/openwrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
8 changes: 8 additions & 0 deletions bin/waagent2.0
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6d0c48a

Please sign in to comment.