From 89cdfda94d45f631355c97953dfa89401986ae0a Mon Sep 17 00:00:00 2001 From: msimonin <matthieu.simonin@inria.fr> Date: Tue, 26 Feb 2019 11:48:20 +0100 Subject: [PATCH] Update README + exemples --- README.org | 95 ++++++++++++++++++++++++++++++++++++ examples/job_submission.py | 21 ++++++++ examples/node_information.py | 13 +++++ examples/storage_accesses.py | 10 ++++ 4 files changed, 139 insertions(+) create mode 100644 README.org create mode 100644 examples/job_submission.py create mode 100644 examples/node_information.py create mode 100644 examples/storage_accesses.py diff --git a/README.org b/README.org new file mode 100644 index 0000000..98e7ed3 --- /dev/null +++ b/README.org @@ -0,0 +1,95 @@ +#+TITLE: python-grid5000 +#+AUTHOR: Matthieu Simonin +#+EMAIL: {firstname.lastname}@inria.fr + +#+LANGUAGE: en +#+OPTIONS: ':t author:nil email:nil date:nil toc:nil + +#+PROPERTY: header-args:sh :eval no +#+PROPERTY: header-args:sh+ :comments org + + +~python-grid5000~ is a python package wrapping the Grid'5000 REST API. + +#+BEGIN_warning +The code is currently being developed heavily. +#+END_warning + +* Thanks + +The core code is borrowed from [[https://github.com/python-gitlab/python-gitlab][python-gitlab]] with small adaptations to +conform with Grid5000 API models (with an 's'!) + +* Examples + +** Submit a job +#+BEGIN_SRC python :tangle examples/job_submission.py +import json +import time + +from grid5000 import Grid5000 + +gk = Grid5000.from_yaml("~/.python-grid5000.yaml") + +site = gk.sites["rennes"] + +job = site.jobs.create({ + "name":"pyg5k", + "command": "sleep 3600", +}) + +while job.state != "running": + job.refresh() + print("Waiting the job to start") + time.sleep(10) + +print(job) +print("Assigned nodes : %s" % job.assigned_nodes) +#+END_SRC + +** Get node information + +#+BEGIN_SRC python :tangle examples/node_information.py +import json +import os +import time + +from grid5000 import Grid5000 + +conf_file = os.path.join(os.environ.get("HOME"), ".python-grid5000.yaml") +gk = Grid5000.from_yaml(conf_file) + +node_info = gk.sites["nancy"].clusters["grisou"].nodes["grisou-1"] +print("grisou-1 has {threads} threads and has {ram} bytes of RAM".format( + threads=node_info.architecture["nb_threads"], + ram=node_info.main_memory["ram_size"])) +#+END_SRC + +** Get Storage accesses + +#+BEGIN_SRC python :tangle examples/storage_accesses.py +import json +import os +import time + +from grid5000 import Grid5000 + +conf_file = os.path.join(os.environ.get("HOME"), ".python-grid5000.yaml") +gk = Grid5000.from_yaml(conf_file) + +print(gk.sites["rennes"].storage["msimonin"].access.list()) +#+END_SRC + +* Appendix :noexport: +** How to export this file + +- Produce ~README.rst~. + To generate the rst file, load the ~ox-rst.el~ file from + https://github.com/msnoigrs/ox-rst into emacs. Then do, ~C-c C-e r r~ or ~M-x + org-rst-export-to-rst~. + +- Produce python example scripts. + Do ~C-c C-v t~ or ~M-x + org-babel-tangle~. The scripts are available under available under ~examples~. + + diff --git a/examples/job_submission.py b/examples/job_submission.py new file mode 100644 index 0000000..ba778e1 --- /dev/null +++ b/examples/job_submission.py @@ -0,0 +1,21 @@ +import json +import time + +from grid5000 import Grid5000 + +gk = Grid5000.from_yaml("~/.python-grid5000.yaml") + +site = gk.sites["rennes"] + +job = site.jobs.create({ + "name":"pyg5k", + "command": "sleep 3600", +}) + +while job.state != "running": + job.refresh() + print("Waiting the job to start") + time.sleep(10) + +print(job) +print("Assigned nodes : %s" % job.assigned_nodes) diff --git a/examples/node_information.py b/examples/node_information.py new file mode 100644 index 0000000..a922bf0 --- /dev/null +++ b/examples/node_information.py @@ -0,0 +1,13 @@ +import json +import os +import time + +from grid5000 import Grid5000 + +conf_file = os.path.join(os.environ.get("HOME"), ".python-grid5000.yaml") +gk = Grid5000.from_yaml(conf_file) + +node_info = gk.sites["nancy"].clusters["grisou"].nodes["grisou-1"] +print("grisou-1 has {threads} threads and has {ram} bytes of RAM".format( + threads=node_info.architecture["nb_threads"], + ram=node_info.main_memory["ram_size"])) diff --git a/examples/storage_accesses.py b/examples/storage_accesses.py new file mode 100644 index 0000000..2e6ceee --- /dev/null +++ b/examples/storage_accesses.py @@ -0,0 +1,10 @@ +import json +import os +import time + +from grid5000 import Grid5000 + +conf_file = os.path.join(os.environ.get("HOME"), ".python-grid5000.yaml") +gk = Grid5000.from_yaml(conf_file) + +print(gk.sites["rennes"].storage["msimonin"].access.list()) -- GitLab