Integrate fetcher into client.py
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import fetcher
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
@@ -14,6 +15,11 @@ parser.add_argument(
|
|||||||
dest='config',
|
dest='config',
|
||||||
action='store',
|
action='store',
|
||||||
default='/etc/iconograph.json')
|
default='/etc/iconograph.json')
|
||||||
|
parser.add_argument(
|
||||||
|
'--ca-cert',
|
||||||
|
dest='ca_cert',
|
||||||
|
action='store',
|
||||||
|
required=True)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--https-ca-cert',
|
'--https-ca-cert',
|
||||||
dest='https_ca_cert',
|
dest='https_ca_cert',
|
||||||
@@ -29,6 +35,11 @@ parser.add_argument(
|
|||||||
dest='https_client_key',
|
dest='https_client_key',
|
||||||
action='store',
|
action='store',
|
||||||
required=True)
|
required=True)
|
||||||
|
parser.add_argument(
|
||||||
|
'--image-dir',
|
||||||
|
dest='image_dir',
|
||||||
|
action='store',
|
||||||
|
required=True)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--server',
|
'--server',
|
||||||
dest='server',
|
dest='server',
|
||||||
@@ -68,10 +79,28 @@ 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 _OnImageTypes(self, data):
|
||||||
|
assert self._config['image_type'] in data['image_types']
|
||||||
|
|
||||||
|
def _OnNewManifest(self, data):
|
||||||
|
if data['image_type'] != self._config['image_type']:
|
||||||
|
return
|
||||||
|
fetch = fetcher.Fetcher(
|
||||||
|
'https://%s/image/%s' % (FLAGS.server, self._config['image_type']),
|
||||||
|
FLAGS.ca_cert,
|
||||||
|
FLAGS.image_dir,
|
||||||
|
FLAGS.https_ca_cert,
|
||||||
|
FLAGS.https_client_cert,
|
||||||
|
FLAGS.https_client_key)
|
||||||
|
fetcher.Fetch()
|
||||||
|
fetcher.DeleteOldImages()
|
||||||
|
|
||||||
def received_message(self, msg):
|
def received_message(self, msg):
|
||||||
parsed = json.loads(msg.data.decode('utf8'))
|
parsed = json.loads(msg.data.decode('utf8'))
|
||||||
if parsed['type'] == 'image_types':
|
if parsed['type'] == 'image_types':
|
||||||
assert self._config['image_type'] in parsed['data']['image_types']
|
self._OnImageTypes(parsed['data'])
|
||||||
|
elif parsed['type'] == 'new_manifest':
|
||||||
|
self._OnNewManifest(parsed['data'])
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import argparse
|
|
||||||
import codecs
|
import codecs
|
||||||
import json
|
import json
|
||||||
import hashlib
|
import hashlib
|
||||||
@@ -15,43 +14,6 @@ import tempfile
|
|||||||
from OpenSSL import crypto
|
from OpenSSL import crypto
|
||||||
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='iconograph fetcher')
|
|
||||||
parser.add_argument(
|
|
||||||
'--base-url',
|
|
||||||
dest='base_url',
|
|
||||||
action='store',
|
|
||||||
required=True)
|
|
||||||
parser.add_argument(
|
|
||||||
'--ca-cert',
|
|
||||||
dest='ca_cert',
|
|
||||||
action='store',
|
|
||||||
required=True)
|
|
||||||
parser.add_argument(
|
|
||||||
'--https-ca-cert',
|
|
||||||
dest='https_ca_cert',
|
|
||||||
action='store')
|
|
||||||
parser.add_argument(
|
|
||||||
'--https-client-cert',
|
|
||||||
dest='https_client_cert',
|
|
||||||
action='store')
|
|
||||||
parser.add_argument(
|
|
||||||
'--https-client-key',
|
|
||||||
dest='https_client_key',
|
|
||||||
action='store')
|
|
||||||
parser.add_argument(
|
|
||||||
'--image-dir',
|
|
||||||
dest='image_dir',
|
|
||||||
action='store',
|
|
||||||
required=True)
|
|
||||||
parser.add_argument(
|
|
||||||
'--max-images',
|
|
||||||
dest='max_images',
|
|
||||||
action='store',
|
|
||||||
type=int,
|
|
||||||
default=5)
|
|
||||||
FLAGS = parser.parse_args()
|
|
||||||
|
|
||||||
|
|
||||||
class Error(Exception):
|
class Error(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -204,7 +166,7 @@ class Fetcher(object):
|
|||||||
self._FetchImage(image)
|
self._FetchImage(image)
|
||||||
self._SetCurrent(image)
|
self._SetCurrent(image)
|
||||||
|
|
||||||
def DeleteOldImages(self, max_images):
|
def DeleteOldImages(self, max_images=5):
|
||||||
if not max_images:
|
if not max_images:
|
||||||
return
|
return
|
||||||
images = []
|
images = []
|
||||||
@@ -218,19 +180,3 @@ class Fetcher(object):
|
|||||||
print('Deleting old image:', filename)
|
print('Deleting old image:', filename)
|
||||||
path = os.path.join(self._image_dir, filename)
|
path = os.path.join(self._image_dir, filename)
|
||||||
os.unlink(path)
|
os.unlink(path)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
fetcher = Fetcher(
|
|
||||||
FLAGS.base_url,
|
|
||||||
FLAGS.ca_cert,
|
|
||||||
FLAGS.image_dir,
|
|
||||||
FLAGS.https_ca_cert,
|
|
||||||
FLAGS.https_client_cert,
|
|
||||||
FLAGS.https_client_key)
|
|
||||||
fetcher.Fetch()
|
|
||||||
fetcher.DeleteOldImages(FLAGS.max_images)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
||||||
|
|||||||
14
client/run
14
client/run
@@ -6,10 +6,10 @@ exec 2>&1
|
|||||||
|
|
||||||
BASE=$(dirname $0)
|
BASE=$(dirname $0)
|
||||||
|
|
||||||
FLAGS="$(cat /icon/config/client.flags)"
|
exec "${BASE}/client.py" \
|
||||||
|
--image-dir="/isodevice/iconograph" \
|
||||||
HTTPS_CLIENT_KEY="/systemid/$(hostname).www.key.pem"
|
--ca-cert="/icon/config/ca.image.cert.pem" \
|
||||||
HTTPS_CLIENT_CERT="/systemid/$(hostname).www.cert.pem"
|
--https-ca-cert="/icon/config/ca.www.cert.pem" \
|
||||||
HTTPS_CA_CERT="/icon/config/ca.www.cert.pem"
|
--https-client-cert="/systemid/$(hostname).www.cert.pem" \
|
||||||
|
--https-client-key="/systemid/$(hostname).www.key.pem" \
|
||||||
exec "${BASE}/client.py" --https-ca-cert="${HTTPS_CA_CERT}" --https-client-cert="${HTTPS_CLIENT_CERT}" --https-client-key="${HTTPS_CLIENT_KEY}" ${FLAGS}
|
$(cat /icon/config/client.flags)
|
||||||
|
|||||||
@@ -7,11 +7,6 @@ import subprocess
|
|||||||
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='iconograph install module')
|
parser = argparse.ArgumentParser(description='iconograph install module')
|
||||||
parser.add_argument(
|
|
||||||
'--base-url',
|
|
||||||
dest='base_url',
|
|
||||||
action='store',
|
|
||||||
required=True)
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--ca-cert',
|
'--ca-cert',
|
||||||
dest='ca_cert',
|
dest='ca_cert',
|
||||||
@@ -26,12 +21,6 @@ parser.add_argument(
|
|||||||
'--https-ca-cert',
|
'--https-ca-cert',
|
||||||
dest='https_ca_cert',
|
dest='https_ca_cert',
|
||||||
action='store')
|
action='store')
|
||||||
parser.add_argument(
|
|
||||||
'--max-images',
|
|
||||||
dest='max_images',
|
|
||||||
action='store',
|
|
||||||
type=int,
|
|
||||||
default=5)
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--server',
|
'--server',
|
||||||
dest='server',
|
dest='server',
|
||||||
@@ -75,14 +64,6 @@ def main():
|
|||||||
FLAGS.https_ca_cert,
|
FLAGS.https_ca_cert,
|
||||||
os.path.join(FLAGS.chroot_path, 'icon', 'config', 'ca.www.cert.pem'))
|
os.path.join(FLAGS.chroot_path, 'icon', 'config', 'ca.www.cert.pem'))
|
||||||
|
|
||||||
# TODO: remove after we integrate this into client.py
|
|
||||||
fetcher_flags = os.path.join(FLAGS.chroot_path, 'icon', 'config', 'fetcher.flags')
|
|
||||||
with open(fetcher_flags, 'w') as fh:
|
|
||||||
fh.write('--base-url=%(base_url)s --max-images=%(max_images)d\n' % {
|
|
||||||
'base_url': FLAGS.base_url,
|
|
||||||
'max_images': FLAGS.max_images,
|
|
||||||
})
|
|
||||||
|
|
||||||
client_flags = os.path.join(FLAGS.chroot_path, 'icon', 'config', 'client.flags')
|
client_flags = os.path.join(FLAGS.chroot_path, 'icon', 'config', 'client.flags')
|
||||||
with open(client_flags, 'w') as fh:
|
with open(client_flags, 'w') as fh:
|
||||||
fh.write('--server=%(server)s\n' % {
|
fh.write('--server=%(server)s\n' % {
|
||||||
|
|||||||
Reference in New Issue
Block a user