applied the except and raise fixers to the master branch to close the gap with py3
[nepi.git] / src / nepi / resources / planetlab / sfa_node.py
index 0fce837..fca374e 100644 (file)
@@ -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
@@ -17,6 +16,8 @@
 #
 # Author: Lucia Guevgeozian <lucia.guevgeozian_odizzio@inria.fr>
 
+from __future__ import print_function
+
 from nepi.execution.attribute import Attribute, Flags, Types
 from nepi.execution.resource import ResourceManager, clsinit_copy, \
         ResourceState
@@ -190,10 +191,12 @@ class PlanetlabSfaNode(LinuxNode):
         plblacklist_file = os.path.join(nepi_home, "plblacklist.txt")
         if not os.path.exists(plblacklist_file):
             if os.path.isdir(nepi_home):
-                open(plblacklist_file, 'w').close()
+                with open(plblacklist_file, 'w') as clear:
+                    pass
             else:
                 os.makedirs(nepi_home)
-                open(plblacklist_file, 'w').close()
+                with open(plblacklist_file, 'w') as clear:
+                    pass
 
     def _skip_provision(self):
         sfa_user = self.get("sfauser")
@@ -530,10 +533,10 @@ class PlanetlabSfaNode(LinuxNode):
             # and perform ping to check that is really alive
             if not self._blacklisted(host_hrn):
                 if not self._reserved(host_hrn):
-                    print self.sfaapi._reserved ,self.guid
+                    print(self.sfaapi._reserved ,self.guid)
                     for hostname, hrn in nodes.iteritems():
                         if host_hrn == hrn:
-                            print 'hostname' ,hostname
+                            print('hostname' ,hostname)
                             ping_ok = self._do_ping(hostname)
                 
                     if not ping_ok:
@@ -647,24 +650,24 @@ class PlanetlabSfaNode(LinuxNode):
     def fail_discovery(self):
         msg = "Discovery failed. No candidates found for node"
         self.error(msg)
-        raise RuntimeError, msg
+        raise RuntimeError(msg)
 
     def fail_node_not_alive(self, hostname=None):
         msg = "Node %s not alive" % hostname
-        raise RuntimeError, msg
+        raise RuntimeError(msg)
     
     def fail_node_not_available(self, hostname):
         msg = "Node %s not available for provisioning" % hostname
-        raise RuntimeError, msg
+        raise RuntimeError(msg)
 
     def fail_not_enough_nodes(self):
         msg = "Not enough nodes available for provisioning"
-        raise RuntimeError, msg
+        raise RuntimeError(msg)
 
     def fail_sfaapi(self):
         msg = "Failing while trying to instanciate the SFA API.\nSet the" + \
             " attributes sfauser and sfaPrivateKey."
-        raise RuntimeError, msg
+        raise RuntimeError(msg)
 
     def valid_connection(self, guid):
         # TODO: Validate!