diff --git a/.env b/.env deleted file mode 100644 index aec741a1..00000000 --- a/.env +++ /dev/null @@ -1 +0,0 @@ -CLOUD_CLIENT_TAG=0.1.0-beta.0.7.4 diff --git a/.env.in b/.env.in new file mode 100644 index 00000000..b3724143 --- /dev/null +++ b/.env.in @@ -0,0 +1,2 @@ +CLOUD_CLIENT_TAG= +FORC_API_KEY= \ No newline at end of file diff --git a/.gitignore b/.gitignore index 9b5413c2..c5b9da16 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ __pycache__/ # C extensions *.so - +.env # Distribution / packaging .Python build/ diff --git a/README.md b/README.md index 59c32cc7..e4b472c2 100644 --- a/README.md +++ b/README.md @@ -21,9 +21,13 @@ source NameOfRcFile.sh ~~~ #### Configuration -You can view all existing parameters in the [yaml file](VirtualMachineService/config/config.yml). +You can view (almost) all existing parameters in the [yaml file](VirtualMachineService/config/config.yml). Also you need to provide the path to your config file as the first param when starting a server. +Furthermore there are some parameters you can set in the [.env.in](.env.in) file, which are read only when starting with docker. +Important: You need to rename .env.in to .env in order for it to be read by docker. +When starting with commandline you will need to export some of them manually. + #### Security Groups The client expects a security group with the name "defaultSimpleVM" to exist which will be assigned to each machine at startup. Also, each machine will have its own security group when it starts. @@ -70,7 +74,7 @@ portal_client_start_server path/to/config.yml ~~~ ### Using Docker -Specify in the [.env](.env) file which release should be used by the client. +Specify in the .env file which release should be used by the client. Then you can start the client with: ``` $ docker-compose up diff --git a/VirtualMachineService/VirtualMachineHandler.py b/VirtualMachineService/VirtualMachineHandler.py index 429b4fc7..80e2a217 100644 --- a/VirtualMachineService/VirtualMachineHandler.py +++ b/VirtualMachineService/VirtualMachineHandler.py @@ -147,12 +147,16 @@ def __init__(self, config): "floating_ip_network" ] self.AVAIALABILITY_ZONE = cfg["openstack_connection"]["availability_zone"] - - if cfg["urls"]["forc_url"]: - self.RE_BACKEND_URL = cfg["urls"]["forc_url"] - self.logger.info(msg="BACKEND URL LOADED {0}".format(self.RE_BACKEND_URL)) - else: + # try to initialize forc connection + try: + self.RE_BACKEND_URL = cfg["forc"]["forc_url"] + self.FORC_API_KEY = os.environ["FORC_API_KEY"] + self.logger.info(msg="Forc-Backend url loaded: {0}".format(self.RE_BACKEND_URL)) + except Exception as e: + self.logger.exception(e) + self.logger.info("Forc-Backend not loaded.") self.RE_BACKEND_URL = None + self.FORC_API_KEY = None if self.USE_GATEWAY: self.GATEWAY_IP = cfg["openstack_connection"]["gateway_ip"] self.SSH_FORMULAR = cfg["openstack_connection"]["ssh_port_calc_formular"] @@ -773,7 +777,7 @@ def create_backend(self, elixir_id, user_key_url, template, template_version, up self.logger.exception(e) return {} try: - response = req.post(post_url, json=backend_info, timeout=(30, 30), headers={"X-API-KEY": "fn438hf37ffbn8"}) + response = req.post(post_url, json=backend_info, timeout=(30, 30), headers={"X-API-KEY": self.FORC_API_KEY}) try: data = response.json() except Exception as e: @@ -794,7 +798,7 @@ def create_backend(self, elixir_id, user_key_url, template, template_version, up def get_backends(self): get_url = "{0}/backends/".format(self.RE_BACKEND_URL) try: - response = req.get(get_url, timeout=(30, 30), headers={"X-API-KEY": "fn438hf37ffbn8"}) + response = req.get(get_url, timeout=(30, 30), headers={"X-API-KEY": self.FORC_API_KEY}) if response.status_code == 401: return [response.json()] else: @@ -812,7 +816,7 @@ def get_backends(self): def get_backends_by_owner(self, elixir_id): get_url = "{0}/backends/byOwner/{1}".format(self.RE_BACKEND_URL, elixir_id) try: - response = req.get(get_url, timeout=(30, 30), headers={"X-API-KEY": "fn438hf37ffbn8"}) + response = req.get(get_url, timeout=(30, 30), headers={"X-API-KEY": self.FORC_API_KEY}) if response.status_code == 401: return [response.json()] else: @@ -830,7 +834,7 @@ def get_backends_by_owner(self, elixir_id): def get_backends_by_template(self, template): get_url = "{0}/backends/byTemplate/{1}".format(self.RE_BACKEND_URL, template) try: - response = req.get(get_url, timeout=(30, 30), headers={"X-API-KEY": "fn438hf37ffbn8"}) + response = req.get(get_url, timeout=(30, 30), headers={"X-API-KEY": self.FORC_API_KEY}) if response.status_code == 401: return [response.json()] else: @@ -848,7 +852,7 @@ def get_backends_by_template(self, template): def get_backend_by_id(self, id): get_url = "{0}/backends/{1}".format(self.RE_BACKEND_URL, id) try: - response = req.get(get_url, timeout=(30, 30), headers={"X-API-KEY": "fn438hf37ffbn8"}) + response = req.get(get_url, timeout=(30, 30), headers={"X-API-KEY": self.FORC_API_KEY}) try: data = response.json() except Exception as e: @@ -865,7 +869,7 @@ def get_backend_by_id(self, id): def delete_backend(self, id): delete_url = "{0}/backends/{1}".format(self.RE_BACKEND_URL, id) try: - response = req.delete(delete_url, timeout=(30, 30), headers={"X-API-KEY": "fn438hf37ffbn8"}) + response = req.delete(delete_url, timeout=(30, 30), headers={"X-API-KEY": self.FORC_API_KEY}) if response.status_code != 200: return str(response.json()) elif response.status_code == 200: @@ -887,7 +891,7 @@ def get_templates(self): get_url = "{0}templates/".format(self.RE_BACKEND_URL) self.logger.info(get_url) try: - response = req.get(get_url, timeout=(30, 30), headers={"X-API-KEY": "fn438hf37ffbn8"}) + response = req.get(get_url, timeout=(30, 30), headers={"X-API-KEY": self.FORC_API_KEY}) self.logger.info(response.json()) if response.status_code == 401: return [response.json()] @@ -899,7 +903,7 @@ def get_templates(self): def get_templates_by_template(self, template_name): get_url = "{0}/templates/{1}".format(self.RE_BACKEND_URL, template_name) try: - response = req.get(get_url, timeout=(30, 30), headers={"X-API-KEY": "fn438hf37ffbn8"}) + response = req.get(get_url, timeout=(30, 30), headers={"X-API-KEY": self.FORC_API_KEY}) if response.status_code == 401: return [response.json()] else: @@ -910,7 +914,7 @@ def get_templates_by_template(self, template_name): def check_template(self, template_name, template_version): get_url = "{0}/templates/{1}/{2}".format(self.RE_BACKEND_URL, template_name, template_version) try: - response = req.get(get_url, timeout=(30, 30), headers={"X-API-KEY": "fn438hf37ffbn8"}) + response = req.get(get_url, timeout=(30, 30), headers={"X-API-KEY": self.FORC_API_KEY}) if response.status_code == 401: return [response.json()] else: diff --git a/VirtualMachineService/ancon/Playbook.py b/VirtualMachineService/ancon/Playbook.py index 944f7402..4be47b15 100644 --- a/VirtualMachineService/ancon/Playbook.py +++ b/VirtualMachineService/ancon/Playbook.py @@ -16,13 +16,13 @@ class Playbook(object): PLAYBOOK_FAILED = "PLAYBOOK_FAILED" def __init__(self, ip, port, playbooks_information, osi_private_key, public_key, logger, pool): - self.redis = redis.Redis(connection_pool=pool) - self.yaml_exec = ruamel.yaml.YAML() - self.vars_files = [] - self.tasks = [] + self.redis = redis.Redis(connection_pool=pool) # redis connection + self.yaml_exec = ruamel.yaml.YAML() # yaml writer/reader + self.vars_files = [] # _vars_file.yml to read + self.tasks = [] # task list self.always_tasks = [] self.logger = logger - self.process = None + self.process = None # init process, returncode, standard output, standard error output self.returncode = -1 self.stdout = "" self.stderr = "" diff --git a/VirtualMachineService/config/config.yml b/VirtualMachineService/config/config.yml index ee8b61d8..a0e15f51 100644 --- a/VirtualMachineService/config/config.yml +++ b/VirtualMachineService/config/config.yml @@ -20,5 +20,5 @@ openstack_connection: ssh_port_calc_formular: 30000 + x udp_port_calc_formular: x * 10 + 30000 -urls: +forc: forc_url: https://proxy-dev.bi.denbi.de:5000/ diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index b7fda09c..1077bf0a 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -15,6 +15,7 @@ services: - OS_PASSWORD - OS_USER_DOMAIN_NAME - OS_PROJECT_DOMAIN_ID + - FORC_API_KEY volumes: - ./VirtualMachineService/config/config.yml:/code/VirtualMachineService/config.yml diff --git a/docker-compose.yml b/docker-compose.yml index 4505497d..c0c86bd0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,6 +13,7 @@ services: - OS_PASSWORD - OS_USER_DOMAIN_NAME - OS_PROJECT_DOMAIN_ID + - FORC_API_KEY volumes: - ./VirtualMachineService/config/config.yml:/code/VirtualMachineService/config.yml