Add next_volume_id

This commit is contained in:
Ian Gulliver
2016-05-10 23:19:52 +00:00
parent f43e9913e9
commit 12793caa96

View File

@@ -4,7 +4,9 @@ import argparse
import fetcher import fetcher
import json import json
import os import os
import re
import socket import socket
import subprocess
import time import time
import update_grub import update_grub
from ws4py.client import threadedclient from ws4py.client import threadedclient
@@ -56,6 +58,8 @@ FLAGS = parser.parse_args()
class Client(threadedclient.WebSocketClient): class Client(threadedclient.WebSocketClient):
_VOLUME_ID_REGEX = re.compile(b'^Volume id: (?P<volume_id>.+)$', re.MULTILINE)
def __init__(self, config_path, *args, **kwargs): def __init__(self, config_path, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
with open(config_path, 'r') as fh: with open(config_path, 'r') as fh:
@@ -70,6 +74,7 @@ class Client(threadedclient.WebSocketClient):
'hostname': socket.gethostname(), 'hostname': socket.gethostname(),
'uptime_seconds': self._Uptime(), 'uptime_seconds': self._Uptime(),
'next_timestamp': self._NextTimestamp(), 'next_timestamp': self._NextTimestamp(),
'next_volume_id': self._GetVolumeID('/isodevice/iconograph/current'),
} }
report.update(self._config) report.update(self._config)
self.send(json.dumps({ self.send(json.dumps({
@@ -86,6 +91,15 @@ class Client(threadedclient.WebSocketClient):
next_image = os.path.basename(os.readlink('/isodevice/iconograph/current')) next_image = os.path.basename(os.readlink('/isodevice/iconograph/current'))
return int(next_image.split('.', 1)[0]) return int(next_image.split('.', 1)[0])
def _GetVolumeID(self, path):
isoinfo = subprocess.check_output([
'isoinfo',
'-d',
'-i', path,
])
match = self._VOLUME_ID_REGEX.search(isoinfo)
return match.group('volume_id').decode('ascii')
def _OnImageTypes(self, data): def _OnImageTypes(self, data):
assert self._config['image_type'] in data['image_types'] assert self._config['image_type'] in data['image_types']