Commit d7fda095 authored by Staiger, Christine's avatar Staiger, Christine
Browse files

Update YODA-connect.ipynb

parent 68c71058
......@@ -135,7 +135,7 @@
"metadata": {},
"source": [
"## 2. The data tag \"RESOURCE\"\n",
"The metadata key \"RESOURCE\" is reserved for data objects only and can only have the values 'disk', 'archive' and 'dual'."
"The metadata key \"RESOURCE\" is reserved for data objects only and can only have the values 'disk', 'archive' and 'dual'. It moves the data objects' bitstreams to the respective data resource in iRODS."
]
},
{
......
%% Cell type:markdown id: tags:
# Experimental python-irodsclient
%% Cell type:code id: tags:
``` python
pip install --upgrade python-irodsclient
```
%% Cell type:markdown id: tags:
Check if the module is available:
%% Cell type:code id: tags:
``` python
import irods
irods.__version__
```
%% Cell type:markdown id: tags:
## Connect to SURF iRODS servers (YODA, NPEC, UNLOCK, ...)
To connect to an iROD instance you need to know the URL of the iRODS server, your user credentials and in som cases also som SSL settings. Usually iRODS connections are coommunicated by a json file like this:
```
{
"irods_host": "wur-yoda.irods.surfsara.nl",
"irods_port": 1247,
"irods_user_name": "christine.staiger@wur.nl",
"irods_zone_name": "wur",
"irods_home": "/wur/home",
"irods_authentication_scheme": "pam",
"irods_encryption_num_hash_rounds": 16,
"irods_client_server_policy": "CS_NEG_REQUIRE",
"irods_encryption_algorithm": "AES-256-CBC",
"irods_encryption_salt_size": 8,
"irods_ssl_verify_server": "none",
"irods_encryption_key_size": 32
}
```
%% Cell type:code id: tags:
``` python
from irods.session import iRODSSession
import json
with open('/home/WUR/staig001/.irods/irods_environment.json') as f:
ienv = json.load(f)
with open('/home/WUR/staig001/.irods/passwd') as f:
passwd = f.readline()
session = iRODSSession(**ienv, password=passwd)
print(session.zone)
```
%% Cell type:code id: tags:
``` python
coll = session.collections.get('/'+session.zone+'/home/christine.staiger@wur.nl')
print(coll.path)
print(coll.data_objects)
print(coll.subcollections)
print("Your current collection:", coll.path)
iHome = coll.path
```
%% Cell type:markdown id: tags:
# Metadata hooks for NPEC and UNLOCK
## 1. The resource metadata tag "free_space"
%% Cell type:code id: tags:
``` python
from irods.models import Collection, DataObject, Resource, CollectionMeta, DataObjectMeta, ResourceMeta
from pprint import pprint
query = session.query(Resource.name, Resource.free_space)
print(query.all())
```
%% Cell type:markdown id: tags:
Both, bundleResc and demoResc have been disabled. One cannot put data into them:
%% Cell type:code id: tags:
``` python
import irods.keywords as kw
options = {kw.RESC_NAME_KW: 'demoResc'}
%ls
iPath = iHome+'/testUpload.txt'
session.data_objects.put('hello.py', iPath, **options)
```
%% Cell type:markdown id: tags:
## 2. The data tag "RESOURCE"
The metadata key "RESOURCE" is reserved for data objects only and can only have the values 'disk', 'archive' and 'dual'.
The metadata key "RESOURCE" is reserved for data objects only and can only have the values 'disk', 'archive' and 'dual'. It moves the data objects' bitstreams to the respective data resource in iRODS.
%% Cell type:code id: tags:
``` python
coll.metadata.add("RESOURCE", "disk")
```
%% Cell type:code id: tags:
``` python
obj = session.data_objects.get(coll.path+"/demo.txt")
obj.metadata.items()
```
%% Cell type:code id: tags:
``` python
obj.metadata.add("RESOURCE", "dual")
print(obj.metadata.items())
vars(obj)
```
%% Cell type:code id: tags:
``` python
for item in obj.metadata.items():
print(item)
```
%% Cell type:markdown id: tags:
You see that two metadata items are created with the key "RESOURCE". So metadata items are not updated but aggregated. In this case, remove the old metadata entry first and then create a new one with the new value:
%% Cell type:code id: tags:
``` python
obj.metadata.remove("RESOURCE", "disk")
obj.metadata.remove("RESOURCE", "dual")
for item in obj.metadata.items():
print(item)
```
%% Cell type:code id: tags:
``` python
# Nonsense value
obj.metadata.add("RESOURCE", "hello")
```
%% Cell type:code id: tags:
``` python
for item in obj.metadata.items():
print(item)
```
%% Cell type:code id: tags:
``` python
obj.metadata.add("RESOURCE", "archive")
for item in obj.metadata.items():
print(item)
```
......
Supports Markdown
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