X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=src%2Fnepi%2Fresources%2Fplanetlab%2Fplcapi.py;h=d2970e8c733b461f04c6f0d1010122243266335d;hb=6285ca51026efb69642eea9dfc7c480e722d84a9;hp=4f4bf5cd519efdbbe914094c5d6a297a04a12095;hpb=2e80f0fafa0c2ef6a5f536efd4c868c91468f962;p=nepi.git diff --git a/src/nepi/resources/planetlab/plcapi.py b/src/nepi/resources/planetlab/plcapi.py index 4f4bf5cd..d2970e8c 100644 --- a/src/nepi/resources/planetlab/plcapi.py +++ b/src/nepi/resources/planetlab/plcapi.py @@ -3,9 +3,8 @@ # Copyright (C) 2013 INRIA # # This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation; # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -177,7 +176,7 @@ class PLCAPI(object): self.threadlocal = threading.local() # Load blacklist from file - if self._ecobj.get_global('PlanetlabNode', 'persist_blacklist'): + if self._ecobj.get_global('planetlab::Node', 'persist_blacklist'): self._set_blacklist() @property @@ -213,7 +212,7 @@ class PLCAPI(object): try: # test authorization network_types = _retry(self.mcapi.GetNetworkTypes)(self.auth) - except (xmlrpclib.ProtocolError, xmlrpclib.Fault),e: + except (xmlrpclib.ProtocolError, xmlrpclib.Fault) as e: warnings.warn(str(e)) return True @@ -285,7 +284,7 @@ class PLCAPI(object): * plain : boolean, use plain bootstrapfs image if set (for tests) """ if not isinstance(node, (str, int, long)): - raise ValueError, "Node must be either a non-unicode string or an int" + raise ValueError("Node must be either a non-unicode string or an int") return _retry(self.mcapi.GetNodeFlavour)(self.auth, node) def get_nodes(self, node_id_or_name = None, fields = None, **kw): @@ -493,19 +492,24 @@ class PLCAPI(object): def release(self): self.count -= 1 - if self._ecobj.get_global('PlanetlabNode', 'persist_blacklist') and self.count == 0: - if self._blacklist: - to_blacklist = list() - hostnames = self.get_nodes(list(self._blacklist), ['hostname']) - for hostname in hostnames: - to_blacklist.append(hostname['hostname']) - - nepi_home = os.path.join(os.path.expanduser("~"), ".nepi") - plblacklist_file = os.path.join(nepi_home, "plblacklist.txt") - - with open(plblacklist_file, 'w') as f: - for host in to_blacklist: - f.write("%s\n" % host) + if self.count == 0: + blacklist = self._blacklist + self._blacklist = set() + self._reserved = set() + if self._ecobj.get_global('PlanetlabNode', 'persist_blacklist'): + if blacklist: + to_blacklist = list() + hostnames = self.get_nodes(list(blacklist), ['hostname']) + for hostname in hostnames: + to_blacklist.append(hostname['hostname']) + + nepi_home = os.path.join(os.path.expanduser("~"), ".nepi") + plblacklist_file = os.path.join(nepi_home, "plblacklist.txt") + + with open(plblacklist_file, 'w') as f: + for host in to_blacklist: + f.write("%s\n" % host) + class PLCAPIFactory(object): """