Add support for timestamps in reboot commands
This commit is contained in:
@@ -97,14 +97,17 @@ class Client(threadedclient.WebSocketClient):
|
|||||||
return
|
return
|
||||||
self._OnNewManifest2()
|
self._OnNewManifest2()
|
||||||
|
|
||||||
def _OnNewManifest2(self):
|
def _GetFetcher(self):
|
||||||
fetch = fetcher.Fetcher(
|
return fetcher.Fetcher(
|
||||||
'https://%s/image/%s' % (FLAGS.server, self._config['image_type']),
|
'https://%s/image/%s' % (FLAGS.server, self._config['image_type']),
|
||||||
FLAGS.ca_cert,
|
FLAGS.ca_cert,
|
||||||
FLAGS.image_dir,
|
FLAGS.image_dir,
|
||||||
FLAGS.https_ca_cert,
|
FLAGS.https_ca_cert,
|
||||||
FLAGS.https_client_cert,
|
FLAGS.https_client_cert,
|
||||||
FLAGS.https_client_key)
|
FLAGS.https_client_key)
|
||||||
|
|
||||||
|
def _OnNewManifest2(self):
|
||||||
|
fetch = self._GetFetcher()
|
||||||
fetch.Fetch()
|
fetch.Fetch()
|
||||||
fetch.DeleteOldImages(skip={'%d.iso' % self._config['timestamp']})
|
fetch.DeleteOldImages(skip={'%d.iso' % self._config['timestamp']})
|
||||||
|
|
||||||
@@ -115,7 +118,14 @@ class Client(threadedclient.WebSocketClient):
|
|||||||
|
|
||||||
def _OnCommand(self, data):
|
def _OnCommand(self, data):
|
||||||
if data['command'] == 'reboot':
|
if data['command'] == 'reboot':
|
||||||
subprocess.check_call(['reboot'])
|
self._OnReboot(data)
|
||||||
|
|
||||||
|
def _OnReboot(self, data):
|
||||||
|
if data['timestamp']:
|
||||||
|
fetch = self._GetFetcher()
|
||||||
|
fetch.Fetch(data['timestamp'])
|
||||||
|
|
||||||
|
subprocess.check_call(['reboot'])
|
||||||
|
|
||||||
def received_message(self, msg):
|
def received_message(self, msg):
|
||||||
parsed = json.loads(msg.data.decode('utf8'))
|
parsed = json.loads(msg.data.decode('utf8'))
|
||||||
|
|||||||
@@ -107,6 +107,12 @@ class Fetcher(object):
|
|||||||
with open(path, 'w') as fh:
|
with open(path, 'w') as fh:
|
||||||
json.dump(new_manifest, fh, indent=4)
|
json.dump(new_manifest, fh, indent=4)
|
||||||
|
|
||||||
|
def _FindImage(self, manifest, timestamp):
|
||||||
|
for image in manifest['images']:
|
||||||
|
if image['timestamp'] == timestamp:
|
||||||
|
return image
|
||||||
|
raise NoValidImage
|
||||||
|
|
||||||
def _ChooseImage(self, manifest):
|
def _ChooseImage(self, manifest):
|
||||||
hostname = socket.gethostname()
|
hostname = socket.gethostname()
|
||||||
hash_base = hashlib.sha256(hostname.encode('ascii'))
|
hash_base = hashlib.sha256(hostname.encode('ascii'))
|
||||||
@@ -160,9 +166,12 @@ class Fetcher(object):
|
|||||||
os.symlink(filename, temp_path)
|
os.symlink(filename, temp_path)
|
||||||
os.rename(temp_path, current_path)
|
os.rename(temp_path, current_path)
|
||||||
|
|
||||||
def Fetch(self):
|
def Fetch(self, force_timestamp=None):
|
||||||
manifest = self._GetManifest()
|
manifest = self._GetManifest()
|
||||||
image = self._ChooseImage(manifest)
|
if force_timestamp:
|
||||||
|
image = self._FindImage(manifest, timestamp)
|
||||||
|
else:
|
||||||
|
image = self._ChooseImage(manifest)
|
||||||
self._FetchImage(image)
|
self._FetchImage(image)
|
||||||
self._SetCurrent(image)
|
self._SetCurrent(image)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user