Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.libnetworkcache
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Łukasz Nowak
slapos.libnetworkcache
Commits
2a9024fc
Commit
2a9024fc
authored
Jan 19, 2012
by
Yingjie Xu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extend methods to use binary cache.
parent
ec6baeee
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
4 deletions
+30
-4
slapos/libnetworkcache.py
slapos/libnetworkcache.py
+30
-4
No files found.
slapos/libnetworkcache.py
View file @
2a9024fc
...
@@ -24,7 +24,8 @@ import tempfile
...
@@ -24,7 +24,8 @@ import tempfile
import
traceback
import
traceback
import
urllib2
import
urllib2
import
urlparse
import
urlparse
import
ctypes
from
ctypes
import
util
class
NetworkcacheClient
(
object
):
class
NetworkcacheClient
(
object
):
'''
'''
...
@@ -112,7 +113,7 @@ class NetworkcacheClient(object):
...
@@ -112,7 +113,7 @@ class NetworkcacheClient(object):
self
.
shadir_cert_file
=
shadir_cert_file
self
.
shadir_cert_file
=
shadir_cert_file
def
upload
(
self
,
file_descriptor
,
key
=
None
,
urlmd5
=
None
,
file_name
=
None
,
def
upload
(
self
,
file_descriptor
,
key
=
None
,
urlmd5
=
None
,
file_name
=
None
,
valid_until
=
None
,
architecture
=
None
):
valid_until
=
None
,
architecture
=
None
,
kernel
=
None
,
libc_version
=
None
):
''' Upload the file to the server.
''' Upload the file to the server.
If urlmd5 is None it must only upload to SHACACHE.
If urlmd5 is None it must only upload to SHACACHE.
Otherwise, it must create a new entry on SHADIR.
Otherwise, it must create a new entry on SHADIR.
...
@@ -161,6 +162,10 @@ class NetworkcacheClient(object):
...
@@ -161,6 +162,10 @@ class NetworkcacheClient(object):
kw
[
'valid-until'
]
=
valid_until
kw
[
'valid-until'
]
=
valid_until
if
architecture
is
not
None
:
if
architecture
is
not
None
:
kw
[
'architecture'
]
=
architecture
kw
[
'architecture'
]
=
architecture
if
kernel
is
not
None
:
kw
[
'kernel'
]
=
kernel
if
libc_version
is
not
None
:
kw
[
'libc-version'
]
=
libc_version
sha_entry
=
json
.
dumps
(
kw
)
sha_entry
=
json
.
dumps
(
kw
)
try
:
try
:
...
@@ -200,7 +205,7 @@ class NetworkcacheClient(object):
...
@@ -200,7 +205,7 @@ class NetworkcacheClient(object):
headers
=
self
.
shadir_header_dict
)
headers
=
self
.
shadir_header_dict
)
return
urllib2
.
urlopen
(
request
)
return
urllib2
.
urlopen
(
request
)
def
select
(
self
,
key
):
def
select
(
self
,
key
,
binary_mode
=
False
):
''' Download a file from shacache by selecting the entry in shadir
''' Download a file from shacache by selecting the entry in shadir
Raise DirectoryNotFound if multiple files are found.
Raise DirectoryNotFound if multiple files are found.
'''
'''
...
@@ -218,7 +223,8 @@ class NetworkcacheClient(object):
...
@@ -218,7 +223,8 @@ class NetworkcacheClient(object):
if
self
.
signature_certificate_list
is
not
None
:
if
self
.
signature_certificate_list
is
not
None
:
for
data
in
data_list
:
for
data
in
data_list
:
if
len
(
data
[
1
]):
if
len
(
data
[
1
]):
if
self
.
_verifySignatureInCertificateList
(
data
[
0
],
data
[
1
]):
if
self
.
_verifySignatureInCertificateList
(
data
[
0
],
data
[
1
])
and
\
self
.
_isCompatible
(
data
[
0
],
binary_mode
=
binary_mode
):
filtered_data_list
.
append
(
data
)
filtered_data_list
.
append
(
data
)
else
:
else
:
filtered_data_list
=
data_list
filtered_data_list
=
data_list
...
@@ -318,6 +324,26 @@ class NetworkcacheClient(object):
...
@@ -318,6 +324,26 @@ class NetworkcacheClient(object):
content_file
.
close
()
content_file
.
close
()
pubkey_file
.
close
()
pubkey_file
.
close
()
def
_isCompatible
(
self
,
information_json
,
binary_mode
=
False
):
if
not
binary_mode
:
return
True
try
:
information_dict
=
json
.
loads
(
information_json
)
except
Exception
:
raise
DirectoryNotFound
(
'It was impossible to parse json-in-json '
'response:
\
n
%s'
%
traceback
.
format_exc
())
_
,
_
,
kernel
,
_
,
_
=
os
.
uname
()
LIBC
=
ctypes
.
cdll
.
LoadLibrary
(
ctypes
.
util
.
find_library
(
'c'
))
libc_version
=
LIBC
.
gnu_get_libc_version
libc_version
.
restype
=
ctypes
.
c_char_p
try
:
if
kernel
!=
information_dict
.
get
(
'kernel'
):
return
False
if
(
"libc-%s"
%
libc_version
())
!=
information_dict
.
get
(
'libc-version'
):
return
False
except
Exception
:
return
False
return
True
class
DirectoryNotFound
(
Exception
):
class
DirectoryNotFound
(
Exception
):
pass
pass
...
...
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