Skip to content
Snippets Groups Projects
Commit 98740c03 authored by escaleira's avatar escaleira Committed by aticig
Browse files

Bug 2217 fixed: modified the cloud-init merge configs and defined the default...

Bug 2217 fixed: modified the cloud-init merge configs and defined the default SSH keys within the system_info instead of users

Change-Id: I12e26a88fb9b50c4a78b9fa8ee2cb5d4b4bf6d00
Signed-off-by: escaleira's avatarPedro Escaleira <escaleira@av.it.pt>
parent d586d89b
No related branches found
No related tags found
No related merge requests found
Pipeline #9948 passed with warnings with stage
in 3 minutes and 34 seconds
......@@ -293,13 +293,32 @@ class VimConnector:
userdata = None
userdata_list = []
# For more information, check https://cloudinit.readthedocs.io/en/latest/reference/merging.html
# Basically, with this, we don't override the provider's cloud config
merge_how = yaml.safe_dump(
{
"merge_how": [
{
"name": "list",
"settings": ["append", "recurse_dict", "recurse_list"],
},
{
"name": "dict",
"settings": ["no_replace", "recurse_list", "recurse_dict"],
},
]
},
indent=4,
default_flow_style=False,
)
if isinstance(cloud_config, dict):
if cloud_config.get("user-data"):
if isinstance(cloud_config["user-data"], str):
userdata_list.append(cloud_config["user-data"])
userdata_list.append(cloud_config["user-data"] + f"\n{merge_how}")
else:
for u in cloud_config["user-data"]:
userdata_list.append(u)
userdata_list.append(u + f"\n{merge_how}")
if cloud_config.get("boot-data-drive") is not None:
config_drive = cloud_config["boot-data-drive"]
......@@ -314,12 +333,12 @@ class VimConnector:
# default user
if cloud_config.get("key-pairs"):
userdata_dict["ssh-authorized-keys"] = cloud_config["key-pairs"]
userdata_dict["users"] = [
{
"default": None,
"ssh-authorized-keys": cloud_config["key-pairs"],
userdata_dict["system_info"] = {
"default_user": {
"ssh_authorized_keys": cloud_config["key-pairs"],
}
]
}
userdata_dict["users"] = ["default"]
if cloud_config.get("users"):
if "users" not in userdata_dict:
......@@ -358,6 +377,7 @@ class VimConnector:
userdata_list.append(
"#cloud-config\n"
+ yaml.safe_dump(userdata_dict, indent=4, default_flow_style=False)
+ f"\n{merge_how}"
)
userdata = self._create_mimemultipart(userdata_list)
self.logger.debug("userdata: %s", userdata)
......
#######################################################################################
# Copyright ETSI Contributors and Others.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#######################################################################################
---
fixes:
- |
This fixes bug 2217. Modified the cloud-init merge configs and defined the default SSH keys within the system_info instead of users
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment