-
Notifications
You must be signed in to change notification settings - Fork 69
WIP Refactor provider options #503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Cristi1324
wants to merge
2
commits into
cloudbase:master
Choose a base branch
from
Cristi1324:refactor-target-options
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,220 @@ | ||
| # Copyright 2026 Cloudbase Solutions Srl | ||
| # All Rights Reserved. | ||
|
|
||
| """Provider-agnostic destination options registered with oslo.config. | ||
|
|
||
| Core dest-options are a list of wizard rows. The worker merges the | ||
| provider list onto that catalog with jsonmerge arrayMergeById on name. | ||
| The provider overwrites matching fields. Core rows always stay. | ||
| Provider-written schema properties are kept. | ||
| Destination environment values take precedence over provider values. | ||
| Provider values take precedence over coriolis.conf. | ||
| """ | ||
|
|
||
| import copy | ||
|
|
||
| from jsonmerge import Merger | ||
| from oslo_config import cfg | ||
| from oslo_log import log as logging | ||
|
|
||
| from coriolis.osmorphing import windows | ||
|
|
||
| CORE_SCHEMA_PROPERTIES = { | ||
| "cloudbase_init_plugins": { | ||
| "type": "array", | ||
| "items": {"type": "string"}, | ||
| "title": "Cloudbase-Init Plugins", | ||
| "description": ( | ||
| "Cloudbase-Init plugins written into Windows guests during " | ||
| "OS morphing. Destination environment takes precedence. " | ||
| "When dest-env omits this key, the destination provider " | ||
| "value is used. When the provider also omits it, " | ||
| "coriolis.conf is used if set, otherwise the Windows " | ||
| "morphing default." | ||
| ), | ||
| }, | ||
| "data_transfer_mechanism": { | ||
| "type": "string", | ||
| "title": "Data Transfer Mechanism", | ||
| "enum": ["SSH", "HTTPS"], | ||
| "description": ( | ||
| "Mechanism used to send disk data from Coriolis to " | ||
| "destination worker VMs. HTTPS uses TCP/5566 and is " | ||
| "faster. SSH uses TCP/22. When dest-env omits this key, " | ||
| "the destination provider value is used. When the " | ||
| "provider also omits it, coriolis.conf is used if set. " | ||
| "Default is HTTPS." | ||
| ), | ||
| }, | ||
| "set_dhcp": { | ||
| "type": "boolean", | ||
| "title": "Set DHCP", | ||
| "description": ( | ||
| "Configure guest NICs with DHCP during OS morphing. " | ||
| "Destination environment takes precedence. When dest-env " | ||
| "omits this key, the provider value is kept. When the " | ||
| "provider also omits it, coriolis.conf set_dhcp is used. " | ||
| "Default is true." | ||
| ), | ||
| }, | ||
| } | ||
|
|
||
| CORE_DESTINATION_OPTIONS = ( | ||
| windows.CLOUDBASE_INIT_PLUGINS_DESTINATION_OPTION, | ||
| { | ||
| "name": "data_transfer_mechanism", | ||
| "values": ["SSH", "HTTPS"], | ||
| "config_default": "HTTPS", | ||
| }, | ||
| { | ||
| "name": "set_dhcp", | ||
| "values": [], | ||
| "config_default": True, | ||
| }, | ||
| ) | ||
|
|
||
| CORE_OPTION_NAMES = {row["name"] for row in CORE_DESTINATION_OPTIONS} | ||
| OSMORPHING_OPTION_NAMES = frozenset( | ||
| ( | ||
| "cloudbase_init_plugins", | ||
| "set_dhcp", | ||
| ) | ||
| ) | ||
|
|
||
| _DEST_OPTIONS_MERGER = Merger( | ||
| { | ||
| "mergeStrategy": "arrayMergeById", | ||
| "mergeOptions": {"idRef": "/name"}, | ||
| "items": { | ||
| "type": "object", | ||
| "mergeStrategy": "objectMerge", | ||
| }, | ||
| } | ||
| ) | ||
|
|
||
| opts = [ | ||
| cfg.ListOpt( | ||
| "cloudbase_init_plugins", | ||
| default=None, | ||
| help=CORE_SCHEMA_PROPERTIES["cloudbase_init_plugins"]["description"], | ||
| ), | ||
| cfg.StrOpt( | ||
| "data_transfer_mechanism", | ||
| default="HTTPS", | ||
| choices=["SSH", "HTTPS"], | ||
| help=CORE_SCHEMA_PROPERTIES["data_transfer_mechanism"]["description"], | ||
| ), | ||
| cfg.BoolOpt( | ||
| "set_dhcp", default=True, help=CORE_SCHEMA_PROPERTIES["set_dhcp"]["description"] | ||
| ), | ||
| ] | ||
|
|
||
| CONF = cfg.CONF | ||
| CONF.register_opts(opts) | ||
|
|
||
| LOG = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def merge_core_destination_options(provider_options, option_names=None): | ||
| """Merge provider dest-options onto the core list. | ||
|
|
||
| Use jsonmerge arrayMergeById on name. Core is the base. The | ||
| provider list is the head. Matching rows merge field by field. | ||
| Provider-only rows are appended. Core rows always stay. | ||
| Treat ``None`` and ``{}`` as a request for all destination options. | ||
| Skip a core option when a non-empty name list does not include it. | ||
| """ | ||
| if isinstance(option_names, (list, tuple, set)): | ||
| requested = set(option_names) if option_names else None | ||
| else: | ||
| requested = None | ||
| core = [ | ||
| copy.deepcopy(row) | ||
| for row in CORE_DESTINATION_OPTIONS | ||
| if requested is None or row["name"] in requested | ||
| ] | ||
| if not isinstance(provider_options, (list, tuple)): | ||
| provider_options = [] | ||
| provider_options = list(provider_options) | ||
| LOG.info( | ||
| "Destination options before merge: core=%s provider=%s", core, provider_options | ||
| ) | ||
| merged = _DEST_OPTIONS_MERGER.merge(core, provider_options) | ||
| LOG.info("Destination options after merge: %s", merged) | ||
| return merged | ||
|
|
||
|
|
||
| def _inject_core_schema_property(object_schema, name, schema_fragment): | ||
| props = object_schema.get("properties") | ||
| if not isinstance(props, dict): | ||
| return | ||
| if name in props: | ||
| return | ||
| props[name] = copy.deepcopy(schema_fragment) | ||
|
|
||
|
|
||
| def inject_core_target_environment_schema(schema): | ||
| """Write core destination fields onto a provider schema. | ||
|
|
||
| Skip a property when the provider already declared it. | ||
| """ | ||
| if not isinstance(schema, dict): | ||
| return schema | ||
| schema = copy.deepcopy(schema) | ||
| for name, fragment in CORE_SCHEMA_PROPERTIES.items(): | ||
| _inject_core_schema_property(schema, name, fragment) | ||
| for key in ("oneOf", "anyOf"): | ||
| for alt in schema.get(key) or []: | ||
| if isinstance(alt, dict): | ||
| _inject_core_schema_property(alt, name, fragment) | ||
| return schema | ||
|
|
||
|
|
||
| def filter_core_option_names(option_names): | ||
| """Remove injected options so destination providers do not reject them.""" | ||
| if not isinstance(option_names, (list, tuple, set)): | ||
| return option_names | ||
| names = CORE_OPTION_NAMES | ||
| return [name for name in option_names if name not in names] | ||
|
|
||
|
|
||
| def apply_core_destination_overrides(osmorphing_info, target_environment): | ||
| """Copy dest-env morphing options onto osmorphing_parameters. | ||
|
|
||
| Dest-env wins when the key is present, including False and []. | ||
| Do not replace provider-written values when dest-env omits the key. | ||
| Do not copy non-osmorphing params. | ||
| """ | ||
| if not isinstance(osmorphing_info, dict): | ||
| osmorphing_info = osmorphing_info or {} | ||
| if isinstance(target_environment, dict): | ||
| dest_env = target_environment | ||
| else: | ||
| dest_env = {} | ||
|
|
||
| osmorphing_info = dict(osmorphing_info) | ||
| params = dict(osmorphing_info.get("osmorphing_parameters") or {}) | ||
| LOG.info( | ||
| "Destination options before apply: dest-env=%s params=%s", | ||
| {n: dest_env[n] for n in OSMORPHING_OPTION_NAMES if n in dest_env}, | ||
| {n: params[n] for n in OSMORPHING_OPTION_NAMES if n in params}, | ||
| ) | ||
|
|
||
| for name in OSMORPHING_OPTION_NAMES: | ||
| if name in dest_env: | ||
| value = dest_env[name] | ||
| elif name not in params: | ||
| value = getattr(CONF, name, None) | ||
| else: | ||
| value = None | ||
| if value is None: | ||
| continue | ||
| params[name] = value | ||
| LOG.info("Applying destination option '%s': %s", name, value) | ||
|
|
||
| osmorphing_info["osmorphing_parameters"] = params | ||
| LOG.info( | ||
| "Destination options after apply: params=%s", | ||
| {n: params[n] for n in OSMORPHING_OPTION_NAMES if n in params}, | ||
| ) | ||
| return osmorphing_info |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,10 +41,6 @@ | |
| "type": "object" | ||
| } | ||
| }, | ||
| "nics_set_dhcp": { | ||
| "type": "boolean", | ||
| "default": "true" | ||
| }, | ||
| "ignore_devices": { | ||
| "type": "array", | ||
| "items": { | ||
|
|
@@ -57,6 +53,18 @@ | |
| "retain_user_credentials": { | ||
| "type": "boolean", | ||
| "default": false | ||
| }, | ||
| "cloudbase_init_plugins": { | ||
| "type": "array", | ||
| "items": { | ||
| "type": "string" | ||
| }, | ||
| "description": "Cloudbase-Init plugin class names for Windows guests. When set, this list is written into the guest. When omitted, the provider plugin list is used, then coriolis.conf, then the Windows morphing default." | ||
| }, | ||
| "set_dhcp": { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, there is also |
||
| "type": "boolean", | ||
| "default": true, | ||
| "description": "Configure guest NICs with DHCP during OS morphing." | ||
| } | ||
| } | ||
| } | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems duplicated from #501, I assume that PR is the best location for this, no?