Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
slapos.core
Commits
155b8629
Commit
155b8629
authored
Jan 18, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
'slapos cache' subcommand
parent
a80b52a4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
0 deletions
+64
-0
slapos/cache.py
slapos/cache.py
+60
-0
slapos/entry.py
slapos/entry.py
+4
-0
No files found.
slapos/cache.py
0 → 100644
View file @
155b8629
# -*- 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
))
slapos/entry.py
View file @
155b8629
...
...
@@ -36,6 +36,7 @@ from slapos.client import request as request
from
slapos.client
import
remove
as
remove
from
slapos.client
import
supply
as
supply
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
runSoftwareRelease
as
software
from
slapos.grid.slapgrid
import
runUsageReport
as
report
...
...
@@ -152,6 +153,8 @@ def dispatch(command, is_node_command):
raise
EntryPointNotImplementedError
(
command
)
elif
command
==
'console'
:
call
(
console
,
config
=
USER_SLAPOS_CONFIGURATION
)
elif
command
==
'cache'
:
call
(
cache
,
config
=
GLOBAL_SLAPOS_CONFIGURATION
)
else
:
return
False
...
...
@@ -177,6 +180,7 @@ Client subcommands usage:
slapos request <instance-name> <software-url> [--configuration arg1=value1 arg2=value2 ... argN=valueN]
slapos supply <software-url> <node-id>
slapos console
slapos cache <software-url-or-md5>
Node subcommands usage:
slapos node
slapos node register <node-id>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment