Skip to content

Commit

Permalink
Merge pull request Azure#198 from karataliu/freebsd21
Browse files Browse the repository at this point in the history
[2.1] Support persistent hostname for FreeBSD.
  • Loading branch information
brendandixon committed Jun 1, 2016
2 parents b83e06e + 68d6520 commit 922c569
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions azurelinuxagent/distro/freebsd/osutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#
# Requires Python 2.4+ and Openssl 1.0+

import azurelinuxagent.utils.fileutil as fileutil
import azurelinuxagent.utils.shellutil as shellutil
import azurelinuxagent.utils.textutil as textutil
import azurelinuxagent.logger as logger
Expand All @@ -28,6 +29,13 @@ def __init__(self):
super(FreeBSDOSUtil, self).__init__()
self._scsi_disks_timeout_set = False

def set_hostname(self, hostname):
rc_file_path = '/etc/rc.conf'
conf_file = fileutil.read_file(rc_file_path).split("\n")
textutil.set_ini_config(conf_file, "hostname", hostname)
fileutil.write_file(rc_file_path, "\n".join(conf_file))
shellutil.run("hostname {0}".format(hostname), chk_err=False)

def restart_ssh_service(self):
return shellutil.run('service sshd restart', chk_err=False)

Expand Down
17 changes: 17 additions & 0 deletions azurelinuxagent/utils/textutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,23 @@ def set_ssh_config(config, name, val):
config.insert(i, "{0} {1}".format(name, val))
return config


def set_ini_config(config, name, val):
notfound = True
nameEqual = name + '='
length = len(config)
text = "{0}=\"{1}\"".format(name, val)

for i in reversed(range(0, length)):
if config[i].startswith(nameEqual):
config[i] = text
notfound = False
break

if notfound:
config.insert(length - 1, text)


def remove_bom(c):
if str_to_ord(c[0]) > 128 and str_to_ord(c[1]) > 128 and \
str_to_ord(c[2]) > 128:
Expand Down

0 comments on commit 922c569

Please sign in to comment.