Skip to content

Commit

Permalink
bsd: upgrade support
Browse files Browse the repository at this point in the history
Implement the upgrade support:

- FreeBSD: using `pkg upgrade`
- NetBSD: with `pkgin`
  • Loading branch information
goneri committed Apr 3, 2020
1 parent 723e2bc commit aebc703
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions cloudinit/distros/bsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class BSD(distros.Distro):
group_add_cmd_prefix = []
pkg_cmd_install_prefix = []
pkg_cmd_remove_prefix = []
pkg_cmd_upgrade_prefix = []
# There is no need to update the package cache on NetBSD and OpenBSD
# TODO neither freebsd nor netbsd handles a command 'upgrade'
pkg_cmd_update_prefix = None
Expand Down Expand Up @@ -97,6 +98,10 @@ def package_command(self, command, args=None, pkgs=None):
if not self.pkg_cmd_update_prefix:
return
cmd = self.pkg_cmd_update_prefix
elif command == 'upgrade':
if not self.pkg_cmd_upgrade_prefix:
return
cmd = self.pkg_cmd_upgrade_prefix

if args and isinstance(args, str):
cmd.append(args)
Expand Down
1 change: 1 addition & 0 deletions cloudinit/distros/freebsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Distro(cloudinit.distros.bsd.BSD):
pkg_cmd_install_prefix = ["pkg", "install"]
pkg_cmd_remove_prefix = ["pkg", "remove"]
pkg_cmd_update_prefix = ["pkg", "update"]
pkg_cmd_upgrade_prefix = ["pkg", "upgrade"]

def _select_hostname(self, hostname, fqdn):
# Should be FQDN if available. See rc.conf(5) in FreeBSD
Expand Down
14 changes: 11 additions & 3 deletions cloudinit/distros/netbsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@ class NetBSD(cloudinit.distros.bsd.BSD):
"""

ci_sudoers_fn = '/usr/pkg/etc/sudoers.d/90-cloud-init-users'

group_add_cmd_prefix = ["groupadd"]
pkg_cmd_install_prefix = ["pkg_add", "-U"]
pkg_cmd_remove_prefix = ['pkg_delete']

def __init__(self, name, cfg, paths):
super().__init__(name, cfg, paths)
if os.path.exists("/usr/pkg/bin/pkgin"):
self.pkg_cmd_install_prefix = ['pkgin', '-y', 'install']
self.pkg_cmd_remove_prefix = ['pkgin', '-y', 'remove']
self.pkg_cmd_remove_prefix = ['pkgin', '-y', 'update']
self.pkg_cmd_upgrade_prefix = ['pkgin', '-y', 'upgrade']
else:
self.pkg_cmd_install_prefix = ['pkg_add', '-U']
self.pkg_cmd_remove_prefix = ['pkg_delete']

def _get_add_member_to_group_cmd(self, member_name, group_name):
return ['usermod', '-G', group_name, member_name]
Expand Down

0 comments on commit aebc703

Please sign in to comment.