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

Som irODS policy behaviour and effect on the API

parent 4222fa7b
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Experimental python-irodsclient"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pip install --upgrade python-irodsclient"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Check if the module is available:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import irods\n",
"irods.__version__"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Connect to SURF iRODS servers (YODA, NPEC, UNLOCK, ...)\n",
"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:\n",
"\n",
"```\n",
"{\n",
" \"irods_host\": \"wur-yoda.irods.surfsara.nl\",\n",
" \"irods_port\": 1247,\n",
" \"irods_user_name\": \"christine.staiger@wur.nl\",\n",
" \"irods_zone_name\": \"wur\",\n",
" \"irods_home\": \"/wur/home\",\n",
" \"irods_authentication_scheme\": \"pam\",\n",
" \"irods_encryption_num_hash_rounds\": 16,\n",
" \"irods_client_server_policy\": \"CS_NEG_REQUIRE\",\n",
" \"irods_encryption_algorithm\": \"AES-256-CBC\",\n",
" \"irods_encryption_salt_size\": 8,\n",
" \"irods_ssl_verify_server\": \"none\",\n",
" \"irods_encryption_key_size\": 32\n",
"}\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from irods.session import iRODSSession\n",
"import json\n",
"\n",
"with open('/home/WUR/staig001/.irods/irods_environment.json') as f:\n",
" ienv = json.load(f)\n",
"with open('/home/WUR/staig001/.irods/passwd') as f:\n",
" passwd = f.readline()\n",
"session = iRODSSession(**ienv, password=passwd)\n",
"print(session.zone)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"coll = session.collections.get('/'+session.zone+'/home/christine.staiger@wur.nl')\n",
"print(coll.path)\n",
"print(coll.data_objects)\n",
"print(coll.subcollections)\n",
"print(\"Your current collection:\", coll.path)\n",
"iHome = coll.path"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Metadata hooks for NPEC and UNLOCK\n",
"## 1. The resource metadata tag \"free_space\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from irods.models import Collection, DataObject, Resource, CollectionMeta, DataObjectMeta, ResourceMeta\n",
"from pprint import pprint\n",
"\n",
"query = session.query(Resource.name, Resource.free_space)\n",
"print(query.all())\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Both, bundleResc and demoResc hav been disabled. One cannot put data into them:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import irods.keywords as kw\n",
"options = {kw.RESC_NAME_KW: 'demoResc'}\n",
"%ls\n",
"iPath = iHome+'/testUpload.txt'\n",
"session.data_objects.put('hello.py', iPath, **options)"
]
},
{
"cell_type": "markdown",
"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'."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"coll.metadata.add(\"RESOURCE\", \"disk\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"obj = session.data_objects.get(coll.path+\"/demo.txt\")\n",
"obj.metadata.items()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"obj.metadata.add(\"RESOURCE\", \"dual\")\n",
"print(obj.metadata.items())\n",
"vars(obj)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for item in obj.metadata.items():\n",
" print(item)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"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",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"obj.metadata.remove(\"RESOURCE\", \"disk\")\n",
"obj.metadata.remove(\"RESOURCE\", \"dual\")\n",
"for item in obj.metadata.items():\n",
" print(item)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Nonsense value\n",
"obj.metadata.add(\"RESOURCE\", \"hello\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for item in obj.metadata.items():\n",
" print(item)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"obj.metadata.add(\"RESOURCE\", \"archive\")\n",
"for item in obj.metadata.items():\n",
" print(item)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "python 3.8.5",
"language": "python",
"name": "python3.8.5"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
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