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

Commit

Permalink
feat(Client): added info when rc file isn't sourced
Browse files Browse the repository at this point in the history
  • Loading branch information
dweinholz committed Apr 3, 2019
1 parent 891b28a commit 1912165
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions VirtualMachineService/VirtualMachineServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()

0 comments on commit 1912165

Please sign in to comment.