diff --git a/VirtualMachineService/VirtualMachineServer.py b/VirtualMachineService/VirtualMachineServer.py index a2057d93..0d2cee8a 100644 --- a/VirtualMachineService/VirtualMachineServer.py +++ b/VirtualMachineService/VirtualMachineServer.py @@ -14,15 +14,30 @@ from thrift.server import TServer import yaml import click -import socket -from contextlib import closing + +USERNAME = 'OS_USERNAME' +PASSWORD = 'OS_PASSWORD' +PROJECT_NAME = 'OS_PROJECT_NAME' +PROJECT_ID = 'OS_PROJECT_ID' +USER_DOMAIN_ID = 'OS_USER_DOMAIN_NAME' +AUTH_URL = 'OS_AUTH_URL' + +environment_variables = [ + USERNAME, + PASSWORD, + PROJECT_NAME, + PROJECT_ID, + USER_DOMAIN_ID, + AUTH_URL, +] + @click.command() @click.argument('config') def startServer(config): click.echo("Start Cloud-Client-Portal Server") - CONFIG_FILE=config + CONFIG_FILE = config with open(CONFIG_FILE, 'r') as ymlfile: cfg = yaml.load(ymlfile) @@ -41,9 +56,15 @@ def startServer(config): server.serve() +def check_environment_variables(envs): + def check_env(var): + if var not in os.environ: + click.echo("ERROR: There is no {} set in environment.".format(var)) + click.echo("Please make sure you have sourced your openstack rc file") + sys.exit() + list(map(lambda var: check_env(var), envs)) + + if __name__ == '__main__': - with closing( - socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as sock: - r = sock.connect_ex(('129.70.51.6', 30072)) - print(r) + check_environment_variables(environment_variables) startServer()