summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2016-04-04 12:13:18 -0400
committerScott Moser <smoser@ubuntu.com>2016-04-04 12:13:18 -0400
commit098241594ff83a2e2070a2e9b4581301e19a76f9 (patch)
tree077848b793d4511f353dd7edb420d84cf0a5b719 /cloudinit
parent210b041b2fead7a57af91f60a6f89d9e5aa1ed4a (diff)
parent9f8d6be677bfd62181f2e54bfc39a044844a195e (diff)
downloadvyos-cloud-init-098241594ff83a2e2070a2e9b4581301e19a76f9.tar.gz
vyos-cloud-init-098241594ff83a2e2070a2e9b4581301e19a76f9.zip
FreeBSD: improvements for packages, setting password and timezone
- Implement set_passwd - Implement set_timezone - support installing packages - Use /bin/tcsh as default user shell (FreeBSD default) - Change default username to freebsd - Enable set-passwords, package-update-upgrade-install and timezone modules
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/distros/freebsd.py50
1 files changed, 43 insertions, 7 deletions
diff --git a/cloudinit/distros/freebsd.py b/cloudinit/distros/freebsd.py
index 72012056..91bf4a4e 100644
--- a/cloudinit/distros/freebsd.py
+++ b/cloudinit/distros/freebsd.py
@@ -16,6 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+import os
import six
from six import StringIO
@@ -30,6 +31,8 @@ from cloudinit import util
from cloudinit.distros import net_util
from cloudinit.distros.parsers.resolv_conf import ResolvConf
+from cloudinit.settings import PER_INSTANCE
+
LOG = logging.getLogger(__name__)
@@ -236,9 +239,21 @@ class Distro(distros.Distro):
util.logexc(LOG, "Failed to create user %s", name)
raise e
- # TODO:
def set_passwd(self, user, passwd, hashed=False):
- return False
+ cmd = ['pw', 'usermod', user]
+
+ if hashed:
+ cmd.append('-H')
+ else:
+ cmd.append('-h')
+
+ cmd.append('0')
+
+ try:
+ util.subp(cmd, passwd, logstring="chpasswd for %s" % user)
+ except Exception as e:
+ util.logexc(LOG, "Failed to set password for %s", user)
+ raise e
def lock_passwd(self, name):
try:
@@ -369,13 +384,34 @@ class Distro(distros.Distro):
LOG.warn("Error running %s: %s", cmd, err)
def install_packages(self, pkglist):
- return
+ self.update_package_sources()
+ self.package_command('install', pkgs=pkglist)
+
+ def package_command(self, command, args=None, pkgs=None):
+ if pkgs is None:
+ pkgs = []
+
+ e = os.environ.copy()
+ e['ASSUME_ALWAYS_YES'] = 'YES'
+
+ cmd = ['pkg']
+ if args and isinstance(args, str):
+ cmd.append(args)
+ elif args and isinstance(args, list):
+ cmd.extend(args)
+
+ if command:
+ cmd.append(command)
+
+ pkglist = util.expand_package_list('%s-%s', pkgs)
+ cmd.extend(pkglist)
- def package_command(self, cmd, args=None, pkgs=None):
- return
+ # Allow the output of this to flow outwards (ie not be captured)
+ util.subp(cmd, env=e, capture=False)
def set_timezone(self, tz):
- return
+ distros.set_etc_timezone(tz=tz, tz_file=self._find_tz_file(tz))
def update_package_sources(self):
- return
+ self._runner.run("update-sources", self.package_command,
+ ["update"], freq=PER_INSTANCE)