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 Jul 8, 2022
1 parent 905d108 commit 18077c8
Show file tree
Hide file tree
Showing 26 changed files with 1,405 additions and 141 deletions.
14 changes: 12 additions & 2 deletions cloudinit/cmd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
from cloudinit import reporting
from cloudinit.reporting import events

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

from cloudinit import atomic_helper

Expand Down Expand Up @@ -394,6 +395,15 @@ def main_init(name, args):
_maybe_persist_instance_data(init)
# Stage 6
iid = init.instancify()
if init.is_new_instance():
util.multi_log("""
*********************************************************
* cloud-init is configuring this system, please wait... *
*********************************************************
""", console=True, stderr=True, log=LOG)

LOG.debug(
"[%s] %s will now be targeting instance id: %s. new=%s",
mode,
Expand Down Expand Up @@ -665,7 +675,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 @@ -59,8 +59,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(wait_attempts):
Expand Down Expand Up @@ -118,7 +123,7 @@ def handle(_name, cfg, cloud, log, _args):
)
# 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
23 changes: 21 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 import subp, util
from cloudinit.config.schema import MetaSchema, get_meta_doc
from cloudinit.distros import ALL_DISTROS
from cloudinit.settings import PER_ALWAYS
from cloudinit import temp_utils

NOBLOCK = "noblock"

Expand Down Expand Up @@ -106,6 +108,15 @@ def _can_skip_resize_ufs(mount_point, devpth):
return False


def _can_skip_resize_zfs(zpool, devpth):
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 @@ -118,7 +129,10 @@ def _can_skip_resize_ufs(mount_point, devpth):
("hammer2", _resize_hammer2),
]

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


def can_skip_resize(fs_type, resize_what, devpth):
Expand Down Expand Up @@ -239,7 +253,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 @@ -281,7 +281,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 @@ -53,6 +53,7 @@
"virtuozzo",
],
"suse": ["opensuse", "sles"],
"illumos": ["omnios"],
}

LOG = logging.getLogger(__name__)
Expand Down
Loading

0 comments on commit 18077c8

Please sign in to comment.