From 7a128d1debe1a3f57dee15e0e71ffeace1281f8f Mon Sep 17 00:00:00 2001 From: msimonin <matthieu.simonin@inria.fr> Date: Wed, 9 Oct 2019 14:35:32 +0200 Subject: [PATCH] from_yaml fallbacks to anonymous connection Fix #6 --- README.org | 3 ++- README.rst | 3 ++- examples/vlan_set_2.py | 4 ++-- grid5000/__init__.py | 13 ++++++++++--- grid5000/__version__.py | 2 +- tox.ini | 1 + 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/README.org b/README.org index 9212308..94c33d4 100644 --- a/README.org +++ b/README.org @@ -73,7 +73,8 @@ password: MYPASSWORD #+END_EXAMPLE #+BEGIN_hint -Inside Grid'5000, you'l probably need to set ~verify_ssl: False~ +From a Grid'5000 frontend this file is optionnal. In all other cases the +configuration file is mandatory. #+END_hint - Using a virtualenv is recommended (python 3.5+ is required) diff --git a/README.rst b/README.rst index a67a077..05b83a2 100644 --- a/README.rst +++ b/README.rst @@ -76,7 +76,8 @@ conform with the Grid5000 API models (with an ’s’!) .. hint:: - Inside Grid’5000, you’l probably need to set ``verify_ssl: False`` + From a Grid’5000 frontend this file is optionnal. In all other cases the + configuration file is mandatory. - Using a virtualenv is recommended (python 3.5+ is required) diff --git a/examples/vlan_set_2.py b/examples/vlan_set_2.py index fa9b154..00476f9 100644 --- a/examples/vlan_set_2.py +++ b/examples/vlan_set_2.py @@ -11,7 +11,7 @@ logging.basicConfig(level=logging.DEBUG) def _to_network_address(host, interface): """Translate a host to a network address e.g: - paranoia-20.rennes.grid5000.fr -> paranoia-20-eth2.rennes.grid5000.fr + paravance-20.rennes.grid5000.fr -> paravance-20-eth2.rennes.grid5000.fr """ splitted = host.split('.') splitted[0] = splitted[0] + "-" + interface @@ -26,7 +26,7 @@ site = gk.sites["rennes"] job = site.jobs.create({"name": "pyg5k", "command": "sleep 3600", - "resources": "{type='kavlan'}/vlan=1+{cluster='paranoia'}nodes=1", + "resources": "{type='kavlan'}/vlan=1+{cluster='paravance'}nodes=1", "types": ["deploy"] }) diff --git a/grid5000/__init__.py b/grid5000/__init__.py index 39bdcc6..168a761 100644 --- a/grid5000/__init__.py +++ b/grid5000/__init__.py @@ -91,9 +91,16 @@ class Grid5000(object): @classmethod def from_yaml(cls, yaml_file): - with open(yaml_file, "r") as f: - conf = yaml.load(f) - return cls(**conf) + try: + with open(yaml_file, "r") as f: + conf = yaml.load(f) + return cls(**conf) + except Exception as e: + logging.warn(e) + logging.info( + "...Falling back to anonymous connection" + ) + return cls() def __enter__(self): return self diff --git a/grid5000/__version__.py b/grid5000/__version__.py index 48fef32..b3f4756 100644 --- a/grid5000/__version__.py +++ b/grid5000/__version__.py @@ -1 +1 @@ -__version__ = "0.1.2" \ No newline at end of file +__version__ = "0.1.2" diff --git a/tox.ini b/tox.ini index 9832552..0a34650 100644 --- a/tox.ini +++ b/tox.ini @@ -31,3 +31,4 @@ ignore = E121,E122,E123,E124,E125,E127,E128,E129,E131,E241,H405,F821,W503,F405 show-source = true exclude = venv,.git,.tox,dist,*egg,ansible,tests max-complexity = 12 +max-line-length = 88 -- GitLab