| 1 |
=============================== |
|---|
| 2 |
The ``utilities.srblib`` module |
|---|
| 3 |
=============================== |
|---|
| 4 |
|
|---|
| 5 |
SRB_ ("Storage Resource Broker") is a distributed filesystem, developed by the |
|---|
| 6 |
San Diego Supercomputer Center, and intended for "Grid" applications, where |
|---|
| 7 |
geographically-separated groups need to share large quantities of data. |
|---|
| 8 |
|
|---|
| 9 |
SRB comes with a client Python library, but this is very low level, and the API |
|---|
| 10 |
is not very Pythonic. This module aims to provide a more useable interface to |
|---|
| 11 |
SRB, allowing you to treat an SRB system more like a local filesystem. |
|---|
| 12 |
|
|---|
| 13 |
Various alternative high-level SRB Python interfaces are available: srboo_, |
|---|
| 14 |
SRBpy_ and pysrb_. These mostly offer more features than `srblib`, but I didn't |
|---|
| 15 |
succeed in getting any of them up-and-running, so here is another one. |
|---|
| 16 |
|
|---|
| 17 |
Installing the low-level ``srb`` module |
|---|
| 18 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 19 |
|
|---|
| 20 |
There are some good build instructions for the low-level bindings at: |
|---|
| 21 |
`<http://www.vislab.uq.edu.au/research/accessgrid/virtual_fs/building.htm>`_ |
|---|
| 22 |
|
|---|
| 23 |
If building on OS X, I found this useful: |
|---|
| 24 |
`<https://lists.sdsc.edu/pipermail/srb-chat/2007-November/004506.html>`_ |
|---|
| 25 |
|
|---|
| 26 |
Make sure you create a directory called ``.srb`` in your home directory and, in |
|---|
| 27 |
this directory, a file called ``.MdasEnv``, which should look something like this:: |
|---|
| 28 |
|
|---|
| 29 |
mdasCollectionHome '/home/srbdev.sdsc' |
|---|
| 30 |
mdasDomainHome 'sdsc' |
|---|
| 31 |
srbUser 'srbdev' |
|---|
| 32 |
srbHost 'torah.sdsc.edu' |
|---|
| 33 |
defaultResource 'unix-sdsc' |
|---|
| 34 |
AUTH_SCHEME 'ENCRYPT1' |
|---|
| 35 |
|
|---|
| 36 |
Check your configuration works using the "Scommands_" before trying the Python |
|---|
| 37 |
interface. You will find full details on the `SRB website`__. |
|---|
| 38 |
|
|---|
| 39 |
Browsing an SRB filesystem |
|---|
| 40 |
~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 41 |
|
|---|
| 42 |
If you have your ``.MdasEnv`` file setup correctly, you can connect to an SRB |
|---|
| 43 |
server using:: |
|---|
| 44 |
|
|---|
| 45 |
>>> from NeuroTools.utilities.srblib import * |
|---|
| 46 |
>>> S = SRBFileSystem('facets.inria.fr') |
|---|
| 47 |
|
|---|
| 48 |
(It is also possible to override the contents of ``.MdasEnv``, or even to have |
|---|
| 49 |
no such file at all, by passing the connection parameters (``username``, |
|---|
| 50 |
``password``, etc) as keyword arguments to the constructor.) You can now browse |
|---|
| 51 |
the server using method calls similar to the Unix command-line, e.g.:: |
|---|
| 52 |
|
|---|
| 53 |
>>> S.ls() |
|---|
| 54 |
... |
|---|
| 55 |
>>> S.cd("/INRIA/home/INRIA/WP5") |
|---|
| 56 |
>>> S.ls() |
|---|
| 57 |
>>> S.get("srbtestfile", "/tmp/localfile") |
|---|
| 58 |
>>> S.put("/tmp/localfile", "srbtestfile_copy") |
|---|
| 59 |
|
|---|
| 60 |
You can also open files and read to/write from them more-or-less as if they were |
|---|
| 61 |
on your local filesystem:: |
|---|
| 62 |
|
|---|
| 63 |
>>> f = S.open("srbtestfile2", "w") |
|---|
| 64 |
>>> f.write("Mate, this bird wouldn't 'voom' if you put four million volts through it!\n") |
|---|
| 65 |
>>> f.close() |
|---|
| 66 |
>>> f = S.open("srbtestfile2", "r") |
|---|
| 67 |
>>> print f.read() |
|---|
| 68 |
Mate, this bird wouldn't 'voom' if you put four million volts through it! |
|---|
| 69 |
>>> f.close() |
|---|
| 70 |
|
|---|
| 71 |
Accessing files by URL |
|---|
| 72 |
~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 73 |
|
|---|
| 74 |
This part of the interface was inspired by `urllib`_ from the Python standard |
|---|
| 75 |
library. There is no need to create an ``SRBServer`` object, just pass an |
|---|
| 76 |
"``srb://``" URL to the ``urlopen`` or ``urlretrieve`` functions:: |
|---|
| 77 |
|
|---|
| 78 |
>>> f = urlopen("srb://facets.inria.fr/INRIA/home/INRIA/WP5/srbtestfile2") |
|---|
| 79 |
>>> print f.read() |
|---|
| 80 |
Mate, this bird wouldn't 'voom' if you put four million volts through it! |
|---|
| 81 |
>>> f.close() |
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
.. _SRB: http://www.sdsc.edu/srb/index.php/Main_Page |
|---|
| 85 |
.. _srboo: http://www.cheshire3.org/docs/objects/api/srboo-pysrc.html |
|---|
| 86 |
.. _SRBpy: http://plone.jcu.edu.au/hpc/staff/projects/hpc-software/SRBpy |
|---|
| 87 |
.. _pysrb: http://sourceforge.net/projects/pysrb/ |
|---|
| 88 |
.. _urllib: http://docs.python.org/lib/module-urllib.html |
|---|
| 89 |
.. _Scommands: http://www.sdsc.edu/srb/index.php/Scommands |
|---|
| 90 |
|
|---|
| 91 |
__ SRB_ |
|---|