Skip to content

Commit

Permalink
Add support for illumos/OmniOS
Browse files Browse the repository at this point in the history
  • Loading branch information
citrus-it committed Nov 4, 2021
1 parent db6084b commit 85a621d
Show file tree
Hide file tree
Showing 26 changed files with 1,323 additions and 97 deletions.
4 changes: 2 additions & 2 deletions cloudinit/cmd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from cloudinit.reporting import events

from cloudinit.settings import (PER_INSTANCE, PER_ALWAYS, PER_ONCE,
CLOUD_CONFIG)
CLOUD_CONFIG, RUN_CLOUD_CONFIG)

from cloudinit import atomic_helper

Expand Down Expand Up @@ -626,7 +626,7 @@ def status_wrapper(name, args, data_d=None, link_d=None):
if data_d is None:
data_d = os.path.normpath("/var/lib/cloud/data")
if link_d is None:
link_d = os.path.normpath("/run/cloud-init")
link_d = os.path.dirname(os.path.normpath(RUN_CLOUD_CONFIG))

status_path = os.path.join(data_d, "status.json")
status_link = os.path.join(link_d, "status.json")
Expand Down
11 changes: 8 additions & 3 deletions cloudinit/config/cc_package_update_upgrade_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,13 @@ def _multi_cfg_bool_get(cfg, *keys):
return False


def _fire_reboot(log, wait_attempts=6, initial_sleep=1, backoff=2):
subp.subp(REBOOT_CMD)
def _fire_reboot(log, cloud, wait_attempts=6, initial_sleep=1, backoff=2):
try:
cmd = cloud.distro.shutdown_command(mode='reboot', delay='now',
message='Rebooting after package installation')
except:
cmd = REBOOT_CMD
subp.subp(cmd)
start = time.time()
wait_time = initial_sleep
for _i in range(0, wait_attempts):
Expand Down Expand Up @@ -113,7 +118,7 @@ def handle(_name, cfg, cloud, log, _args):
"%s", REBOOT_FILE)
# Flush the above warning + anything else out...
logging.flushLoggers(log)
_fire_reboot(log)
_fire_reboot(log, cloud)
except Exception as e:
util.logexc(log, "Requested reboot did not happen!")
errors.append(e)
Expand Down
77 changes: 75 additions & 2 deletions cloudinit/config/cc_resizefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@

import errno
import os
import re
import stat
from textwrap import dedent

from cloudinit.config.schema import (
get_schema_doc, validate_cloudconfig_schema)
from cloudinit.settings import PER_ALWAYS
from cloudinit import subp
from cloudinit import temp_utils
from cloudinit import util

NOBLOCK = "noblock"
Expand Down Expand Up @@ -81,7 +83,60 @@ def _resize_ufs(mount_point, devpth):
return ('growfs', '-y', mount_point)


def _resize_zfs_growpart_for_illumos(devpth):
"""Due to https://www.illumos.org/issues/14022, it is currently
necessary to grow the underlying partition before growing the
ZFS pool"""

def prtvtoc(devpth):
sectorsize = sectorcount = None
partitions = {}
(out, _) = subp.subp(['/usr/sbin/prtvtoc',
f'/dev/dsk/{devpth}'], rcs=[0])
for line in out.splitlines():
if not sectorsize:
m = re.search(rf'^\*\s+(\d+)\sbytes\/sector$', out)
if m:
sectorsize = m.group(1)
continue
if not sectorcount:
m = re.search(rf'^\*\s+(\d+)\ssectors$', out)
if m:
sectorcount = m.group(1)
continue
if line.startswith('*'):
continue
(pid, tag, flags, start, count, end) = line.split()
partitions[pid] = {
'id': pid,
'tag': tag,
'flags': flags,
'start': start,
'count': count,
'end': end,
}
return (sectorsize, sectorcount, partitions)

sectorsize, sectorcount, partitions = prtvtoc(devpth)

import pprint
pprint.pprint(partitions)


#(_, tfile) = temp_utils.mkstemp(prefix='resize-', suffix="")
#util.write_file(tfile, content="partition\nexpand\nlabel\nquit\nquit\n")
#try:
# (out, _err) = subp.subp(['/usr/sbin/format', '-d', devpth,
# '-f', tfile])
#except subp.ProcessExecutionError as e:
# LOG.warning(f"Failed to resize {devpth} for illumos")

#util.del_file(tfile)


def _resize_zfs(mount_point, devpth):
if util.is_illumos():
_resize_zfs_growpart_for_illumos(devpth)
return ('zpool', 'online', '-e', mount_point, devpth)


Expand All @@ -108,6 +163,18 @@ def _can_skip_resize_ufs(mount_point, devpth):
return False


def _can_skip_resize_zfs(zpool, devpth):
if util.is_illumos():
# ZFS resize is temporarily disabled for illumos
return True
try:
(out, _err) = subp.subp(['zpool', 'get', '-Hp', '-o', 'value',
'expandsz', zpool])
return out.strip() == '-'
except subp.ProcessExecutionError as e:
return False


# Do not use a dictionary as these commands should be able to be used
# for multiple filesystem types if possible, e.g. one command for
# ext2, ext3 and ext4.
Expand All @@ -121,7 +188,8 @@ def _can_skip_resize_ufs(mount_point, devpth):
]

RESIZE_FS_PRECHECK_CMDS = {
'ufs': _can_skip_resize_ufs
'ufs': _can_skip_resize_ufs,
'zfs': _can_skip_resize_zfs,
}


Expand Down Expand Up @@ -230,7 +298,12 @@ def handle(name, cfg, _cloud, log, args):
info = "dev=%s mnt_point=%s path=%s" % (devpth, mount_point, resize_what)
log.debug("resize_info: %s" % info)

devpth = maybe_get_writable_device_path(devpth, info, log)
if util.is_illumos() and fs_type == 'zfs':
# On illumos ZFS, the devices are just bare words like 'c0t0d0'
# which can be used directly as arguments for the resize.
pass
else:
devpth = maybe_get_writable_device_path(devpth, info, log)
if not devpth:
return # devpath was not a writable block device

Expand Down
2 changes: 1 addition & 1 deletion cloudinit/config/cc_set_passwords.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def rand_user_password(pwlen=20):


def chpasswd(distro, plist_in, hashed=False):
if util.is_BSD():
if util.is_BSD() or util.is_illumos():
for pentry in plist_in.splitlines():
u, p = pentry.split(":")
distro.set_passwd(u, p, hashed=hashed)
Expand Down
1 change: 1 addition & 0 deletions cloudinit/distros/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
'redhat': ['almalinux', 'amazon', 'centos', 'cloudlinux', 'eurolinux',
'fedora', 'openEuler', 'photon', 'rhel', 'rocky', 'virtuozzo'],
'suse': ['opensuse', 'sles'],
'illumos': ['omnios'],
}

LOG = logging.getLogger(__name__)
Expand Down
Loading

0 comments on commit 85a621d

Please sign in to comment.