Browse Source

Mechanism that performs user actions before Synergy deletes the VMs

In synergy is missing a useful mechanism which allows the user to
perform some actions (e.g. exporting data) into the VMs before
Synergy deletes them from the shared quota once their TTL is expired.
This commit implements such mechanism.

BUG: #1717253
Change-Id: Iabd0eb5eeda53c483189725446cb6f459c1053e8
Sem-Ver: feature
tags/2.6.0
Lisa Zangrando 2 years ago
parent
commit
a45e054ec9
2 changed files with 37 additions and 7 deletions
  1. +19
    -2
      synergy_scheduler_manager/nova_manager.py
  2. +18
    -5
      synergy_scheduler_manager/scheduler_manager.py

+ 19
- 2
synergy_scheduler_manager/nova_manager.py View File

@@ -668,6 +668,25 @@ class NovaManager(Manager):

return response_data

def setServerMetadata(self, server, key, value):
if not server:
return

id = server.getId()
data = {"metadata": {key: value}}
url = "servers/%s/metadata" % id

try:
response_data = self.getResource(url, "POST", data)
except requests.exceptions.HTTPError as ex:
raise SynergyError("error on setting the metadata (id=%r)"
": %s" % (id, ex.response.json()))

if response_data:
response_data = response_data["metadata"]

return response_data

def getHosts(self):
data = {}
url = "os-hosts"
@@ -709,7 +728,6 @@ class NovaManager(Manager):
try:
response_data = self.getResource(url, "GET", data)
except requests.exceptions.HTTPError as ex:
LOG.info(ex)
response = ex.response.json()
raise SynergyError("error on retrieving the hypervisors list: %s"
% response["badRequest"]["message"])
@@ -1048,7 +1066,6 @@ where instance_uuid='%(id)s' and deleted_at is NULL""" % {"id": server.getId()}
server.setMetadata(metadata)

servers.append(server)

except SQLAlchemyError as ex:
raise SynergyError(ex.message)
finally:


+ 18
- 5
synergy_scheduler_manager/scheduler_manager.py View File

@@ -1,7 +1,10 @@
import logging
import time

from common.quota import SharedQuota
from common.request import Request
from datetime import datetime
from datetime import timedelta
from oslo_config import cfg
from synergy.common.manager import Manager
from synergy.exception import SynergyError
@@ -259,15 +262,25 @@ class SchedulerManager(Manager):
project.setQueue(self.queue)

def _processServerEvent(self, server, event, state):
project = self.project_manager.getProject(id=server.getProjectId())

if not project:
return

if event == "compute.instance.create.end" and state == "active":
LOG.info("the server %s is now active on host %s"
% (server.getId(), server.getHost()))
else:
project = self.project_manager.getProject(id=server.getProjectId())

if not project:
return
now = datetime.now()
expiration = now + timedelta(minutes=project.getTTL())
expiration = time.mktime(expiration.timetuple())
expiration = str(expiration)[:-2]

self.nova_manager.setServerMetadata(server,
"expiration_time",
expiration)

else:
quota = project.getQuota()

if event == "compute.instance.delete.end":
@@ -378,6 +391,6 @@ class SchedulerManager(Manager):
priority))
else:
self.nova_manager.buildServer(request)
except SynergyError as ex:
except Exception as ex:
LOG.error("Exception has occured", exc_info=1)
LOG.error(ex)

Loading…
Cancel
Save