Commit f9463b47 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin Committed by Titouan Soulard

recipes: Move update request transaction file to librecipe

parent 0ef73cf4
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
############################################################################## ##############################################################################
import logging import logging
from slapos import slap from slapos import slap
from slapos.slap.slap import COMPUTER_PARTITION_REQUEST_LIST_TEMPLATE_FILENAME
import os import os
import zc.buildout import zc.buildout
import zc.recipe.egg import zc.recipe.egg
...@@ -57,6 +58,31 @@ def unwrap(value): ...@@ -57,6 +58,31 @@ def unwrap(value):
value = json.loads(value) value = json.loads(value)
return value return value
def updateTransactionFile(partition_id, name):
"""
Store reference to all Instances requested by this Computer Parition
"""
# Environ variable set by Slapgrid while processing this partition
instance_root = os.environ.get('SLAPGRID_INSTANCE_ROOT', '')
if not instance_root or not partition_id:
return
transaction_file_name = COMPUTER_PARTITION_REQUEST_LIST_TEMPLATE_FILENAME % partition_id
transaction_file_path = os.path.join(instance_root, partition_id,
transaction_file_name)
try:
if os.access(os.path.join(instance_root, partition_id), os.W_OK):
if not os.path.exists(transaction_file_path):
transac_file = open(transaction_file_path, 'w')
transac_file.close()
with open(transaction_file_path, 'a') as transac_file:
transac_file.write('%s\n' % name)
except OSError:
return
from .genericjioapi import GenericjIOAPIRecipe
class BaseSlapRecipe: class BaseSlapRecipe:
"""Base class for all slap.recipe.*""" """Base class for all slap.recipe.*"""
......
...@@ -26,12 +26,12 @@ ...@@ -26,12 +26,12 @@
############################################################################## ##############################################################################
import logging import logging
from zc.buildout import UserError from zc.buildout import UserError
from slapos.recipe.librecipe import wrap, JSON_SERIALISED_MAGIC_KEY from slapos.recipe.librecipe import wrap, JSON_SERIALISED_MAGIC_KEY, updateTransactionFile
import json import json
import os import os
from slapos import slap as slapmodule from slapos import slap as slapmodule
from slapos.slap import SoftwareProductCollection from slapos.slap import SoftwareProductCollection
from slapos.slap.slap import json_loads_byteified, COMPUTER_PARTITION_REQUEST_LIST_TEMPLATE_FILENAME from slapos.slap.slap import json_loads_byteified
import slapos.recipe.librecipe.generic as librecipe import slapos.recipe.librecipe.generic as librecipe
import traceback import traceback
...@@ -179,7 +179,7 @@ class Recipe(object): ...@@ -179,7 +179,7 @@ class Recipe(object):
if requested_state: if requested_state:
request_dict["state"] = requested_state request_dict["state"] = requested_state
self._updateTransactionFile(options['partition-id'], name) updateTransactionFile(options['partition-id'], name)
partition_dict = slap.jio_api_connector.post(request_dict) partition_dict = slap.jio_api_connector.post(request_dict)
if "$schema" in partition_dict and "error-response-schema.json" in partition_dict["$schema"]: if "$schema" in partition_dict and "error-response-schema.json" in partition_dict["$schema"]:
self.logger.warning( self.logger.warning(
...@@ -309,30 +309,6 @@ class Recipe(object): ...@@ -309,30 +309,6 @@ class Recipe(object):
update = install update = install
def _updateTransactionFile(self, partition_id, name):
"""
Store reference to all Instances requested by this Computer Parition
"""
# Environ variable set by Slapgrid while processing this partition
instance_root = os.environ.get('SLAPGRID_INSTANCE_ROOT', '')
if not instance_root or not partition_id:
return
transaction_file_name = COMPUTER_PARTITION_REQUEST_LIST_TEMPLATE_FILENAME % partition_id
transaction_file_path = os.path.join(instance_root, partition_id,
transaction_file_name)
try:
if os.access(os.path.join(instance_root, partition_id), os.W_OK):
if not os.path.exists(transaction_file_path):
transac_file = open(transaction_file_path, 'w')
transac_file.close()
with open(transaction_file_path, 'a') as transac_file:
transac_file.write('%s\n' % name)
except OSError:
return
class RequestOptional(Recipe): class RequestOptional(Recipe):
""" """
Request a SlapOS instance. Won't fail if request failed or is not ready. Request a SlapOS instance. Won't fail if request failed or is not ready.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment