Commit 8b7ec35e authored by Yingjie Xu's avatar Yingjie Xu

Software release promise: update local contents using full computer information.

parent 267872ab
...@@ -60,6 +60,8 @@ from lxml import etree ...@@ -60,6 +60,8 @@ from lxml import etree
from time import sleep from time import sleep
from random import random from random import random
from slapos.slap.slap import NotFoundError
from hashlib import md5
MANDATORY_PARAMETER_LIST = [ MANDATORY_PARAMETER_LIST = [
'computer_id', 'computer_id',
...@@ -446,6 +448,8 @@ class Slapgrid(object): ...@@ -446,6 +448,8 @@ class Slapgrid(object):
state = software_release.getState() state = software_release.getState()
try: try:
software_release_uri = software_release.getURI() software_release_uri = software_release.getURI()
url_hash = md5(software_release_uri).hexdigest()
software_path = os.path.join(self.software_root, url_hash)
software = Software(url=software_release_uri, software = Software(url=software_release_uri,
software_root=self.software_root, software_root=self.software_root,
console=self.console, buildout=self.buildout, console=self.console, buildout=self.buildout,
...@@ -462,9 +466,18 @@ class Slapgrid(object): ...@@ -462,9 +466,18 @@ class Slapgrid(object):
shadir_cert_file=self.shadir_cert_file, shadir_cert_file=self.shadir_cert_file,
shadir_key_file=self.shadir_key_file) shadir_key_file=self.shadir_key_file)
if state == 'available': if state == 'available':
completed_tag = os.path.join(software_path, '.completed')
if not os.path.exists(completed_tag):
try:
software_release.building() software_release.building()
except NotFoundError:
pass
software.install() software.install()
file_descriptor = open(completed_tag, 'w')
file_descriptor.write(time.asctime())
file_descriptor.close()
elif state == 'destroyed': elif state == 'destroyed':
if os.path.exists(software_path):
logger.info('Destroying %r...' % software_release_uri) logger.info('Destroying %r...' % software_release_uri)
software.destroy() software.destroy()
logger.info('Destroyed %r.' % software_release_uri) logger.info('Destroyed %r.' % software_release_uri)
...@@ -479,9 +492,15 @@ class Slapgrid(object): ...@@ -479,9 +492,15 @@ class Slapgrid(object):
clean_run = False clean_run = False
else: else:
if state == 'available': if state == 'available':
try:
software_release.available() software_release.available()
except NotFoundError:
pass
elif state == 'destroyed': elif state == 'destroyed':
try:
software_release.destroyed() software_release.destroyed()
except NotFoundError:
pass
logger.info("Finished software releases...") logger.info("Finished software releases...")
return clean_run return clean_run
......
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