Skip to content
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

Support string replacement for nocloud seed path #1808

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions cloudinit/sources/DataSourceNoCloud.py
Expand Up @@ -49,6 +49,25 @@ def _get_devices(self, label):
devlist.sort(reverse=True)
return devlist

def _var_sub_seed(self, seedfrom):
allowed_string_replacements = [
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm thinking this really could just be dmi.DMIDECODE_TO_KERNEL.keys()

"chassis-asset-tag",
"system-serial-number",
]

for substr in allowed_string_replacements:
substr_formatted = "_{}_".format(substr)

if substr_formatted in seedfrom:
dmi_data_lookup = dmi.read_dmi_data(substr)
if not dmi_data_lookup:
dmi_data_lookup = ""
seedfrom = seedfrom.replace(
substr_formatted,
str(dmi_data_lookup),
)
return seedfrom

def _get_data(self):
defaults = {
"instance-id": "nocloud",
Expand Down Expand Up @@ -167,6 +186,8 @@ def _pp2d_callback(mp, data):
if not seedfound:
LOG.debug("Seed from %s not supported by %s", seedfrom, self)
return False
# check and replace instances of serial number, asset tags etc
seedfrom = self._var_sub_seed(seedfrom)

# This could throw errors, but the user told us to do it
# so if errors are raised, let them raise
Expand Down