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 #125 from deNBI/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
dweinholz authored Aug 8, 2019
2 parents bef2daa + 102ad3b commit 4b7aea5
Show file tree
Hide file tree
Showing 13 changed files with 416 additions and 266 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## (2019-08-08)


#### Bug Fixes

* **Virtualmachine:** not timeout when stopping or resuming vm ([3b435835](3b435835))
* **playbook:** try except for _vars_file.yml ([58c97068](58c97068))
* **vm:** stops instead of suspending ([085f7f74](085f7f74))

## (2019-07-10)


Expand Down
69 changes: 28 additions & 41 deletions VirtualMachineService/VirtualMachineHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from ttypes import ressourceException
from ttypes import Flavor, Image, VM, PlaybookResult
from constants import VERSION
from ancon.BiocondaPlaybook import BiocondaPlaybook
from ancon.Playbook import Playbook

except Exception:
from .VirtualMachineService import Iface
Expand All @@ -28,7 +28,7 @@
from .ttypes import ressourceException
from .ttypes import Flavor, Image, VM, PlaybookResult
from .constants import VERSION
from .ancon.BiocondaPlaybook import BiocondaPlaybook
from .ancon.Playbook import Playbook

from openstack import connection
from deprecated import deprecated
Expand Down Expand Up @@ -56,9 +56,9 @@ class VirtualMachineHandler(Iface):
global osi_key_dict
BUILD = "BUILD"
ACTIVE = "ACTIVE"
PREPARE_BIOCONDA_BUILD = "PREPARE_BIOCONDA_BUILD"
BUILD_BIOCONDA = "BUILD_BIOCONDA"
BIOCONDA_FAILED = "BIOCONDA_FAILED"
PREPARE_PLAYBOOK_BUILD = "PREPARE_PLAYBOOK_BUILD"
BUILD_PLAYBOOK = "BUILD_PLAYBOOK"
PLAYBOOK_FAILED = "PLAYBOOK_FAILED"

def create_connection(self):
"""
Expand Down Expand Up @@ -633,35 +633,34 @@ def start_server_with_custom_key(self, flavor, image, servername, elixir_id, dis
openstack_id = server.to_dict()["id"]
global osi_key_dict
osi_key_dict[openstack_id] = dict(key=private_key, name=servername,
status=self.PREPARE_BIOCONDA_BUILD)
status=self.PREPARE_PLAYBOOK_BUILD)
return {"openstackid": openstack_id, "volumeId": volume_id, 'private_key': private_key}
except Exception as e:
self.delete_keypair(key_name=servername)
self.logger.exception("Start Server {1} error:{0}".format(e, servername))
return {}

def create_and_deploy_playbook(self, private_key, play_source, openstack_id):
self.logger.info(msg="Starting Bioconda Playbook for (openstack_id): {0} with packages {1}"
.format(openstack_id, play_source))
def create_and_deploy_playbook(self, public_key, playbooks_information, openstack_id):
self.logger.info(msg="Starting Playbook for (openstack_id): {0}"
.format(openstack_id))
# get ip and port for inventory
fields = self.get_ip_ports(openstack_id=openstack_id)
global osi_key_dict
global active_playbooks
key_name = osi_key_dict[openstack_id]['name']
playbook = BiocondaPlaybook(fields["IP"], fields["PORT"], play_source,
osi_key_dict[openstack_id]["key"], private_key)
playbook = Playbook(fields["IP"],
fields["PORT"],
playbooks_information,
osi_key_dict[openstack_id]["key"],
public_key,
self.logger)
active_playbooks[openstack_id] = playbook
osi_key_dict[openstack_id]["status"] = self.BUILD_BIOCONDA
osi_key_dict[openstack_id]["status"] = self.BUILD_PLAYBOOK
status, stdout, stderr = playbook.run_it()
self.delete_keypair(key_name=key_name)
if status != 0:
# self.logger.exception(msg="Bioconda playbook for {0} encountered an error with status code {1}. The messages are:"
# "stdout: {2}"
# "stderr: {3}".format(openstack_id, status, stdout, stderr))
osi_key_dict[openstack_id]["status"] = self.BIOCONDA_FAILED
osi_key_dict[openstack_id]["status"] = self.PLAYBOOK_FAILED
else:
# self.logger.info("Finished Bioconda Playbook for (openstack_id): {0} with status code: {1}"
# .format(openstack_id, status))
osi_key_dict[openstack_id]["status"] = self.ACTIVE
return status

Expand Down Expand Up @@ -783,14 +782,14 @@ def check_server_status(self, openstack_id, diskspace, volume_id):
return server

if openstack_id in osi_key_dict:
if osi_key_dict[openstack_id]["status"] == self.PREPARE_BIOCONDA_BUILD:
server.status = self.PREPARE_BIOCONDA_BUILD
if osi_key_dict[openstack_id]["status"] == self.PREPARE_PLAYBOOK_BUILD:
server.status = self.PREPARE_PLAYBOOK_BUILD
return server
elif osi_key_dict[openstack_id]["status"] == self.BUILD_BIOCONDA:
server.status = self.BUILD_BIOCONDA
elif osi_key_dict[openstack_id]["status"] == self.BUILD_PLAYBOOK:
server.status = self.BUILD_PLAYBOOK
return server
elif osi_key_dict[openstack_id]["status"] == self.BIOCONDA_FAILED:
server.status = self.BIOCONDA_FAILED
elif osi_key_dict[openstack_id]["status"] == self.PLAYBOOK_FAILED:
server.status = self.PLAYBOOK_FAILED
return server
else:
return server
Expand Down Expand Up @@ -1052,8 +1051,8 @@ def delete_server(self, openstack_id):
self.logger.exception("Instance {0} not found".format(openstack_id))
raise serverNotFoundException

if server.status == "SUSPENDED":
self.conn.compute.resume_server(server)
if server.status == "SHUTOFF":
self.conn.compute.start_server(server)
server = self.conn.compute.get_server(server)
self.conn.compute.wait_for_server(server=server, status='ACTIVE')
self.logger.info(server)
Expand Down Expand Up @@ -1146,15 +1145,9 @@ def stop_server(self, openstack_id):
raise serverNotFoundException

if server.status == "ACTIVE":
self.conn.compute.suspend_server(server)
server = self.conn.compute.get_server(server)
while server.status != "SUSPENDED":
server = self.conn.compute.get_server(server)
time.sleep(3)

self.conn.compute.stop_server(server)
return True
else:

return False
except Exception as e:
self.logger.exception("Stop Server {0} error:".format(openstack_id, e))
Expand Down Expand Up @@ -1197,16 +1190,10 @@ def resume_server(self, openstack_id):
if server is None:
self.logger.exception("Instance {0} not found".format(openstack_id))
raise serverNotFoundException

if server.status == "SUSPENDED":
self.conn.compute.resume_server(server)
while server.status != "ACTIVE":
server = self.conn.compute.get_server(server)
time.sleep(3)

if server.status == "SHUTOFF":
self.conn.compute.start_server(server)
return True
else:

return False
except Exception as e:
self.logger.exception("Resume Server {0} error:".format(openstack_id, e))
Expand Down
4 changes: 2 additions & 2 deletions VirtualMachineService/VirtualMachineService-remote
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ if len(sys.argv) <= 1 or sys.argv[1] == '--help':
print(' bool create_connection(string username, string password, string auth_url, string user_domain_name, string project_domain_name)')
print(' start_server(string flavor, string image, string public_key, string servername, string elixir_id, string diskspace, string volumename)')
print(' start_server_with_custom_key(string flavor, string image, string servername, string elixir_id, string diskspace, string volumename)')
print(' int create_and_deploy_playbook(string private_key, string play_source, string openstack_id)')
print(' int create_and_deploy_playbook(string public_key, playbooks_information, string openstack_id)')
print(' PlaybookResult get_playbook_logs(string openstack_id)')
print(' bool add_security_group_to_server(bool http, bool https, bool udp, string server_id)')
print(' VM get_server(string openstack_id)')
Expand Down Expand Up @@ -221,7 +221,7 @@ elif cmd == 'create_and_deploy_playbook':
if len(args) != 3:
print('create_and_deploy_playbook requires 3 args')
sys.exit(1)
pp.pprint(client.create_and_deploy_playbook(args[0], args[1], args[2],))
pp.pprint(client.create_and_deploy_playbook(args[0], eval(args[1]), args[2],))

elif cmd == 'get_playbook_logs':
if len(args) != 1:
Expand Down
Loading

0 comments on commit 4b7aea5

Please sign in to comment.