Alow specifying the os-morphing user script phase#99
Conversation
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
c1acb74 to
f51a123
Compare
| '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.') |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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"'])
There was a problem hiding this comment.
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.") |
There was a problem hiding this comment.
That's a bit confusing, considering we accept the phase too.
| os_type, ", ".join(constants.OS_LIST))) | ||
|
|
||
| payload = None | ||
| # The user may omit the script path in order to remove all script |
There was a problem hiding this comment.
Can you please mention this in the helper string of the command?
There was a problem hiding this comment.
The behavior was already there but indeed, it should be documented.
| instance = list(params.keys())[0] | ||
| script_path = params[instance] | ||
| payload = None | ||
| # The user may omit the script path in order to remove all script |
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:
Samples: