summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--newton/newton/requests/tests/test_server.py12
-rw-r--r--share/newton_base/openoapi/server.py19
2 files changed, 18 insertions, 13 deletions
diff --git a/newton/newton/requests/tests/test_server.py b/newton/newton/requests/tests/test_server.py
index 91e51a32..c5bdaeb9 100644
--- a/newton/newton/requests/tests/test_server.py
+++ b/newton/newton/requests/tests/test_server.py
@@ -64,8 +64,16 @@ TEST_CREATE_SERVER = {
{"portId": "2"}
],
"contextArray": [
- {"fileName": "file", "fileData": "test_data"},
- {"fileName": "file2", "fileData": "test_data2"}
+ {
+ "source_path": "artifacts/keys/authorized_keys",
+ "source_data_base64": "c3NoLXJzYSBBQUFBQjNOemFDMXljMkVBQUFBREFRQUJBQUFCQVFER3g2U0tyQXVDejFWOEtHZXZa\ndWVrc0xkV29QV0pQNnozcjI5WjdUbVBWRU9qTSs3UElQZVNzMkJWUngzcm5IWkJBbGFzTXJaK2ZK\nQlMyNXRzOXZmQytJdGV6UWFoL2hyOXZya213eENSNTRMYjg0cG9XK3NUb1BlRjZpNWVaWTdXK2pX\nSmZMYUZTRng5ZDJ2cDR6ZXMvZk9sVDNOdllDWGJuLzNRZHJ5UW9HbDdWRkk4b2VtWnlwVmNpa1pY\nRWxKZWVLZ0FWZFN3bnJ6dXF0Ty90bWJYY0FlU2JZdlZqa2k4eXdZY3NXTVZNWVdVV2hoKzFCQUI2\na1huVHNJV3F6cnEwUGZ2eSs4MVdEd3RpcXNxbWQ5M0hZOGhFMHNjQnJYRkJaelFTL0FZZklGQmxF\ndUZOZExjemNobnRqYlowbjdkbURYazh6SHRDWllOazdrd2I4ay8gbHVsaWFuaGFvQGxsdS1udWMx\nCg==\n",
+ "dest_path": "/home/ubuntu/.ssh/authorized_keys"
+ },
+ {
+ "source_path": "artifacts/keys/authorized_keys",
+ "source_data_base64": "c3NoLXJzYSBBQUFBQjNOemFDMXljMkVBQUFBREFRQUJBQUFCQVFER3g2U0tyQXVDejFWOEtHZXZa\ndWVrc0xkV29QV0pQNnozcjI5WjdUbVBWRU9qTSs3UElQZVNzMkJWUngzcm5IWkJBbGFzTXJaK2ZK\nQlMyNXRzOXZmQytJdGV6UWFoL2hyOXZya213eENSNTRMYjg0cG9XK3NUb1BlRjZpNWVaWTdXK2pX\nSmZMYUZTRng5ZDJ2cDR6ZXMvZk9sVDNOdllDWGJuLzNRZHJ5UW9HbDdWRkk4b2VtWnlwVmNpa1pY\nRWxKZWVLZ0FWZFN3bnJ6dXF0Ty90bWJYY0FlU2JZdlZqa2k4eXdZY3NXTVZNWVdVV2hoKzFCQUI2\na1huVHNJV3F6cnEwUGZ2eSs4MVdEd3RpcXNxbWQ5M0hZOGhFMHNjQnJYRkJaelFTL0FZZklGQmxF\ndUZOZExjemNobnRqYlowbjdkbURYazh6SHRDWllOazdrd2I4ay8gbHVsaWFuaGFvQGxsdS1udWMx\nCg==\n",
+ "dest_path": "/home/ubuntu/.ssh/authorized_keys"
+ }
],
# "volumeArray":[
# {"volumeId": "volume1"},
diff --git a/share/newton_base/openoapi/server.py b/share/newton_base/openoapi/server.py
index 29823432..ba77dc55 100644
--- a/share/newton_base/openoapi/server.py
+++ b/share/newton_base/openoapi/server.py
@@ -367,24 +367,21 @@ class Servers(APIView):
strUserData = ''
source_content = ""
dest_path = ""
+ user_data.append("#cloud-config\n")
for context in contextarray:
- if context["fileName"] == "source_path":
- source_content = context["fileData"]
- if context["fileName"] == "dest_path":
- dest_path = context["fileData"]
- if len(source_content) > 0:
- user_data.append("#cloud-config\n")
user_data.append("write_files:\n")
user_data.append("- encoding: b64\n")
- user_data.append(" content: " + source_content + "\n")
+ user_data.append(" content: " + context["source_data_base64"] + "\n")
user_data.append(" owner: root:root\n")
- user_data.append(" path: " + dest_path + "\n")
+ user_data.append(" path: " + context["dest_path"] + "\n")
user_data.append(" permissions: '0644'\n")
user_data.append("\n")
- user_data.append("runcmd:")
+ if userdata:
+ user_data.append("runcmd:\n")
user_data.append("- " + userdata + "\n")
- strUserData.join(user_data)
- server["user_data"] = user_data
+
+ strUserData.join(user_data)
+ server["user_data"] = strUserData
VimDriverUtils.replace_key_by_mapping(server,
self.keys_mapping, True)