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 #631 from deNBI/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
dweinholz authored Mar 1, 2021
2 parents 29a6544 + 1abbb89 commit 5dfbcb0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.9.1-buster
FROM python:3.9.2-buster
RUN apt-get update -y
RUN apt-get install -y build-essential
WORKDIR /code
Expand Down
37 changes: 26 additions & 11 deletions VirtualMachineService/VirtualMachineHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Which can be used for the PortalClient.
"""
from uuid import uuid4

try:
from VirtualMachineService import Iface
from ttypes import serverNotFoundException
Expand Down Expand Up @@ -40,14 +42,14 @@
import datetime
import json
import logging
from distutils.version import LooseVersion
import os
import parser
import socket
import time
import urllib
from contextlib import closing
from distutils.version import LooseVersion

import os
import redis
import requests as req
import yaml
Expand Down Expand Up @@ -909,7 +911,7 @@ def volume_ids(
image = self.get_image(image=image)
flavor = self.get_flavor(flavor=flavor)
network = self.get_network()
key_name = metadata.get("elixir_id")[:-18]
key_name = f"{metadata.get('elixir_id')[:-18]}{str(uuid4())[0:5]}"
public_key = urllib.parse.unquote(public_key)
key_pair = self.import_keypair(key_name, public_key)
init_script = self.create_mount_init_script(
Expand All @@ -933,10 +935,12 @@ def volume_ids(
security_groups=self.DEFAULT_SECURITY_GROUPS + custom_security_groups,
)
openstack_id = server["id"]
self.delete_keypair(key_name)

return {"openstack_id": openstack_id}

except Exception as e:
self.delete_keypair(key_name)
for security_group in custom_security_groups:
self.conn.network.delete_security_group(security_group)
LOG.exception("Start Server {1} error:{0}".format(e, servername))
Expand Down Expand Up @@ -1013,12 +1017,13 @@ def start_server_without_playbook(
custom_security_groups = self.prepare_security_groups_new_server(
resenv=resenv, servername=servername, http=http, https=https
)

key_name = None
try:
image = self.get_image(image=image)
flavor = self.get_flavor(flavor=flavor)
network = self.get_network()
key_name = metadata.get("elixir_id")[:-18]
key_name = f"{metadata.get('elixir_id')[:-18]}{str(uuid4())[0:5]}"

public_key = urllib.parse.unquote(public_key)
key_pair = self.import_keypair(key_name, public_key)
volume_ids = []
Expand All @@ -1032,7 +1037,6 @@ def start_server_without_playbook(
)
for id in volume_ids:
volumes.append(self.conn.get_volume_by_id(id=id))
LOG.info(volumes)
init_script = self.create_mount_init_script(
volume_ids_path_new=volume_ids_path_new,
volume_ids_path_attach=volume_ids_path_attach,
Expand All @@ -1049,8 +1053,6 @@ def start_server_without_playbook(
else:
init_script = self.create_add_keys_script(keys=additional_keys)

LOG.info(init_script)

server = self.conn.create_server(
name=servername,
image=image.id,
Expand All @@ -1065,9 +1067,13 @@ def start_server_without_playbook(
)

openstack_id = server["id"]
self.delete_keypair(key_name)

return {"openstack_id": openstack_id}
except Exception as e:
if key_name:
self.delete_keypair(key_name)

for security_group in custom_security_groups:
self.conn.network.delete_security_group(security_group)
LOG.exception("Start Server {1} error:{0}".format(e, servername))
Expand Down Expand Up @@ -1105,12 +1111,12 @@ def start_server(
custom_security_groups = self.prepare_security_groups_new_server(
resenv=resenv, servername=servername, http=http, https=https
)

key_name = None
try:
image = self.get_image(image=image)
flavor = self.get_flavor(flavor=flavor)
network = self.get_network()
key_name = metadata.get("elixir_id")[:-18]
key_name = f"{metadata.get('elixir_id')[:-18]}{str(uuid4())[0:5]}"
public_key = urllib.parse.unquote(public_key)
key_pair = self.import_keypair(key_name, public_key)

Expand All @@ -1126,9 +1132,12 @@ def start_server(
)

openstack_id = server["id"]
self.delete_keypair(key_name)

return {"openstack_id": openstack_id}
except Exception as e:
if key_name:
self.delete_keypair(key_name)
for security_group in custom_security_groups:
self.conn.network.delete_security_group(security_group)
LOG.exception("Start Server {1} error:{0}".format(e, servername))
Expand Down Expand Up @@ -1440,7 +1449,10 @@ def delete_backend(self, id):
verify=True,
)
if response.status_code != 200:
return str(response.json())
try:
return str(response.json())
except json.JSONDecodeError:
return response.content
elif response.status_code == 200:
return str(True)
except Timeout as e:
Expand Down Expand Up @@ -1601,10 +1613,13 @@ def check_template(self, template_name, template_version):

def get_playbook_logs(self, openstack_id):
global active_playbooks
LOG.info(f"Get Playbook logs {openstack_id}")
if self.redis.exists(openstack_id) == 1 and openstack_id in active_playbooks:
key_name = self.redis.hget(openstack_id, "name").decode("utf-8")
playbook = active_playbooks.pop(openstack_id)
status, stdout, stderr = playbook.get_logs()
LOG.info(f" Playbook logs{openstack_id} stattus: {status}")

playbook.cleanup(openstack_id)
self.delete_keypair(key_name=key_name)
return PlaybookResult(status=status, stdout=stdout, stderr=stderr)
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
setuptools==52.0.0
setuptools==53.0.0
thrift >= 0.11.0,<0.20.0
python-keystoneclient
openstacksdk ==0.53.0
deprecated == 1.2.11
Click==7.1.2
flake8==3.8.4
ansible==2.10.6
ansible==3.0.0
ruamel.yaml<0.17.0
paramiko==2.7.2
pyvim==3.0.2
Expand Down

0 comments on commit 5dfbcb0

Please sign in to comment.