Commit 155b8629 authored by Marco Mariani's avatar Marco Mariani

'slapos cache' subcommand

parent a80b52a4
# -*- coding: utf-8 -*-
import ast
import argparse
import ConfigParser
import hashlib
import json
import re
import sys
import urllib2
def maybe_md5(s):
return re.match('[0-9a-f]{32}', s)
def cache():
parser = argparse.ArgumentParser()
parser.add_argument("configuration_file", help="SlapOS configuration file")
parser.add_argument("software_url", help="Your software url or MD5 hash")
args = parser.parse_args()
configuration_parser = ConfigParser.SafeConfigParser()
configuration_parser.read(args.configuration_file)
configuration_parser.items('networkcache')
cache_dir = configuration_parser.get('networkcache', 'download-binary-dir-url')
if maybe_md5(args.software_url):
md5 = args.software_url
else:
md5 = hashlib.md5(args.software_url).hexdigest()
try:
response = urllib2.urlopen('%s/%s' % (cache_dir, md5))
except urllib2.HTTPError as e:
if e.code == 404:
print 'Object not in cache: %s' % args.software_url
else:
print 'Error during cache lookup: %s (%s)' % (e.code, e.reason)
sys.exit(10)
entries = json.loads(response.read())
header_printed = False
for entry in entries:
meta = json.loads(entry[0])
os = ast.literal_eval(meta['os'])
if not header_printed:
print 'Software URL: %s' % meta['software_url']
print 'MD5: %s' % md5
print '-------------'
print 'Available for: '
print 'distribution | version | id'
print '-----------------+--------------+---------------'
header_printed = True
print '%-16s | %12s | %s' % (os[0], os[1], os[2].center(14))
...@@ -36,6 +36,7 @@ from slapos.client import request as request ...@@ -36,6 +36,7 @@ from slapos.client import request as request
from slapos.client import remove as remove from slapos.client import remove as remove
from slapos.client import supply as supply from slapos.client import supply as supply
from slapos.format import main as format from slapos.format import main as format
from slapos.cache import cache
from slapos.grid.slapgrid import runComputerPartition as instance from slapos.grid.slapgrid import runComputerPartition as instance
from slapos.grid.slapgrid import runSoftwareRelease as software from slapos.grid.slapgrid import runSoftwareRelease as software
from slapos.grid.slapgrid import runUsageReport as report from slapos.grid.slapgrid import runUsageReport as report
...@@ -152,6 +153,8 @@ def dispatch(command, is_node_command): ...@@ -152,6 +153,8 @@ def dispatch(command, is_node_command):
raise EntryPointNotImplementedError(command) raise EntryPointNotImplementedError(command)
elif command == 'console': elif command == 'console':
call(console, config=USER_SLAPOS_CONFIGURATION) call(console, config=USER_SLAPOS_CONFIGURATION)
elif command == 'cache':
call(cache, config=GLOBAL_SLAPOS_CONFIGURATION)
else: else:
return False return False
...@@ -177,6 +180,7 @@ Client subcommands usage: ...@@ -177,6 +180,7 @@ Client subcommands usage:
slapos request <instance-name> <software-url> [--configuration arg1=value1 arg2=value2 ... argN=valueN] slapos request <instance-name> <software-url> [--configuration arg1=value1 arg2=value2 ... argN=valueN]
slapos supply <software-url> <node-id> slapos supply <software-url> <node-id>
slapos console slapos console
slapos cache <software-url-or-md5>
Node subcommands usage: Node subcommands usage:
slapos node slapos node
slapos node register <node-id> slapos node register <node-id>
......
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