Skip to content

Alow specifying the os-morphing user script phase#99

Open
petrutlucian94 wants to merge 1 commit into
cloudbase:masterfrom
petrutlucian94:script_phases
Open

Alow specifying the os-morphing user script phase#99
petrutlucian94 wants to merge 1 commit into
cloudbase:masterfrom
petrutlucian94:script_phases

Conversation

@petrutlucian94
Copy link
Copy Markdown
Member

@petrutlucian94 petrutlucian94 commented May 19, 2026

When deploying replicas, Coriolis users can specify scripts that will be executed during os-morphing, right after the OS partition is mounted on the minion instance.

In some situations, this is too late since user scripts may be needed in order to be able to mount the OS disk, for example if it’s encrypted.

In other situations it’s too early. Some scripts may need to be executed on the replica instance. This may require provider assistance.

To accommodate these use cases, we’ve extended the deployment API, allowing the user to specify when a given script should be executed. Each script may specify one of the following execution phases:

  • osmorphing-pre-os-mount
  • osmorphing-post-os-mount (default)
  • replica-initial-boot (TBD)

Samples:

  • Explicit phase --user-script-global linux=/some/script.sh,phase=osmorphing-pre-os-mount
  • Implicit phase, defaults to osmorphing-post-os-mount --user-script-global linux=/some/script.sh
  • Repeating the flag, specifying multiple scripts:
--user-script-instance some-instance=/some/script.sh,phase=osmorphing-pre-os-mount
--user-script-instance some-instance=/other/script.sh,phase=osmorphing-pre-os-mount
--user-script-instance some-instance=/another/script.sh,phase=osmorphing-post-os-mount

When deploying replicas, Coriolis users can specify scripts that will be executed
during os-morphing, right after the OS partition is mounted on the minion instance.

In some situations, this is too late since user scripts may be needed in order
to be able to mount the OS disk, for example if it’s encrypted.

In other situations it’s too early. Some scripts may need to be executed on
the replica instance. This may require provider assistance.

To accommodate these use cases, we’ve extended the deployment API, allowing the
user to specify when a given script should be executed. Each script may specify
one of the following execution phases:

* osmorphing-pre-os-mount
* osmorphing-post-os-mount (default)
* replica-initial-boot (TBD)

Samples:

* Explicit phase
    --user-script-global linux=/some/script.sh,phase=osmorphing-pre-os-mount
* Implicit phase, defaults to osmorphing-post-os-mount
    --user-script-global linux=/some/script.sh
* Repeating the flag, specifying multiple scripts:
    --user-script-instance some-instance=/some/script.sh,phase=osmorphing-pre-os-mount
    --user-script-instance some-instance=/other/script.sh,phase=osmorphing-pre-os-mount
    --user-script-instance some-instance=/another/script.sh,phase=osmorphing-post-os-mount
@petrutlucian94 petrutlucian94 marked this pull request as draft May 19, 2026 14:52
@petrutlucian94 petrutlucian94 marked this pull request as ready for review May 22, 2026 10:47
'specified in --user-script-global for this '
'instance. Can optionally include a script phase: '
'instance_name=/path/to/script.ps1,'
'phase=osmorphing_pre_os_mount.')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we also mention what the phases are, and what the default is?

return value


def comma_separated_kv_to_dict(input_string: str) -> dict:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, I wonder. cliff uses argsparse. Could we instead have something like:

        parser.add_argument(
            '--user-script-instance',
            action='append',
            required=False,
            dest="instance_scripts",
            type=comma_separated_kv_to_dict,
            default={},

If it can, this may also simplify the handling before, we basically let cliff handle this for us.

Source: https://docs.python.org/3/library/argparse.html#type

...
User defined functions can be used as well:

def hyphenated(string):
    return '-'.join([word[:4] for word in string.casefold().split()])

parser = argparse.ArgumentParser()
_ = parser.add_argument('short_title', type=hyphenated)
parser.parse_args(['"The Tale of Two Cities"'])

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'll give it a try.

"Available options are: %s" % ", ".join(constants.OS_LIST))
if len(params.keys()) > 1:
raise ValueError(
"Too many parameters. Expecting just the OS type.")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a bit confusing, considering we accept the phase too.

Comment thread coriolisclient/cli/utils.py
os_type, ", ".join(constants.OS_LIST)))

payload = None
# The user may omit the script path in order to remove all script
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please mention this in the helper string of the command?

Copy link
Copy Markdown
Member Author

@petrutlucian94 petrutlucian94 May 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behavior was already there but indeed, it should be documented.

Comment thread coriolisclient/cli/utils.py
instance = list(params.keys())[0]
script_path = params[instance]
payload = None
# The user may omit the script path in order to remove all script
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants