Skip to content
This repository has been archived by the owner on May 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #599 from deNBI/feat/mutliple_user
Browse files Browse the repository at this point in the history
feat(VirtualMachine):multiple user per userdata
  • Loading branch information
dweinholz authored Jan 28, 2021
2 parents 1016c93 + 148ff10 commit a13fc4b
Show file tree
Hide file tree
Showing 10 changed files with 477 additions and 400 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,4 @@ fabric.properties

# additional data
*.pem
*.sh
#*.sh
35 changes: 32 additions & 3 deletions VirtualMachineService/VirtualMachineHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
)

import datetime
import json
import logging
from distutils.version import LooseVersion
import parser
Expand All @@ -46,6 +47,7 @@
import urllib
from contextlib import closing

import os
import redis
import requests as req
import yaml
Expand All @@ -56,9 +58,6 @@
from openstack import connection
from openstack.exceptions import ConflictException
from oslo_utils import encodeutils

import os
import json
from requests.exceptions import Timeout

active_playbooks = dict()
Expand Down Expand Up @@ -729,6 +728,22 @@ def get_network(self):
)
return network

def create_add_keys_script(self, keys):
LOG.info(f"create add key script")
fileDir = os.path.dirname(os.path.abspath(__file__))
key_script = os.path.join(fileDir, "scripts/bash/add_keys_to_authorized.sh")
bash_keys_array = "("
for key in keys:
bash_keys_array += f'"{key}" '
bash_keys_array += ")"

with open(key_script, "r") as file:
text = file.read()
text = text.replace("KEYS_TO_ADD", bash_keys_array)
text = encodeutils.safe_encode(text.encode("utf-8"))
key_script = text
return key_script

def create_mount_init_script(
self, volume_ids_path_new=None, volume_ids_path_attach=None
):
Expand Down Expand Up @@ -977,6 +992,7 @@ def start_server_without_playbook(
resenv,
volume_ids_path_new=None,
volume_ids_path_attach=None,
additional_keys=None,
):
"""
Start a new Server.
Expand Down Expand Up @@ -1021,6 +1037,19 @@ def start_server_without_playbook(
volume_ids_path_new=volume_ids_path_new,
volume_ids_path_attach=volume_ids_path_attach,
)
if additional_keys:
if init_script:
add_key_script = self.create_add_keys_script(keys=additional_keys)
init_script = (
add_key_script
+ encodeutils.safe_encode("\n".encode("utf-8"))
+ init_script
)

else:
init_script = self.create_add_keys_script(keys=additional_keys)

LOG.info(init_script)

server = self.conn.create_server(
name=servername,
Expand Down
10 changes: 5 additions & 5 deletions VirtualMachineService/VirtualMachineService-remote
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
# Autogenerated by Thrift Compiler (0.13.0)
# Autogenerated by Thrift Compiler (0.12.0)
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
#
Expand Down Expand Up @@ -44,7 +44,7 @@ if len(sys.argv) <= 1 or sys.argv[1] == '--help':
print(' delete_metadata_from_server(string servername, keys)')
print(' string add_floating_ip_to_server(string openstack_id, string network)')
print(' bool create_connection(string username, string password, string auth_url, string user_domain_name, string project_domain_name)')
print(' start_server_without_playbook(string flavor, string image, string public_key, string servername, metadata, bool https, bool http, resenv, volume_ids_path_new, volume_ids_path_attach)')
print(' start_server_without_playbook(string flavor, string image, string public_key, string servername, metadata, bool https, bool http, resenv, volume_ids_path_new, volume_ids_path_attach, additional_keys)')
print(' bool bibigrid_available()')
print(' bool detach_ip_from_server(string server_id, string floating_ip)')
print(' start_server_with_mounted_volume(string flavor, string image, string public_key, string servername, metadata, bool https, bool http, resenv, volume_ids_path_new, volume_ids_path_attach)')
Expand Down Expand Up @@ -291,10 +291,10 @@ elif cmd == 'create_connection':
pp.pprint(client.create_connection(args[0], args[1], args[2], args[3], args[4],))

elif cmd == 'start_server_without_playbook':
if len(args) != 10:
print('start_server_without_playbook requires 10 args')
if len(args) != 11:
print('start_server_without_playbook requires 11 args')
sys.exit(1)
pp.pprint(client.start_server_without_playbook(args[0], args[1], args[2], args[3], eval(args[4]), eval(args[5]), eval(args[6]), eval(args[7]), eval(args[8]), eval(args[9]),))
pp.pprint(client.start_server_without_playbook(args[0], args[1], args[2], args[3], eval(args[4]), eval(args[5]), eval(args[6]), eval(args[7]), eval(args[8]), eval(args[9]), eval(args[10]),))

elif cmd == 'bibigrid_available':
if len(args) != 0:
Expand Down
Loading

0 comments on commit a13fc4b

Please sign in to comment.