X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=src%2Fnepi%2Futil%2Fsfaapi.py;h=f460b7e8a2f665f565aab79d3e86850206a4dc60;hb=58a2b493f8df1072a1faa653c8abb6a3f9ba21fa;hp=9c3b5d34dd18ae8a9ec6d71347b8e8cb03275de3;hpb=2baa343634b0a1ead1ee1eaad371c2a85cc80dbe;p=nepi.git diff --git a/src/nepi/util/sfaapi.py b/src/nepi/util/sfaapi.py index 9c3b5d34..f460b7e8 100644 --- a/src/nepi/util/sfaapi.py +++ b/src/nepi/util/sfaapi.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 @@ -212,7 +211,7 @@ class SFAAPI(object): else: slice_resources = [] if slice_resources: slice_resources_hrn = self.get_resources_hrn(slice_resources) - for s_hrn_key, s_hrn_value in slice_resources_hrn.iteritems(): + for s_hrn_key, s_hrn_value in slice_resources_hrn.items(): s_parts = s_hrn_value.split('.') s_hrn = '.'.join(s_parts[:2]) + '.' + '\\.'.join(s_parts[2:]) resources_hrn_new.append(s_hrn) @@ -220,10 +219,9 @@ class SFAAPI(object): resources_urn = self._get_resources_urn(resources_hrn_new) rspec = self.rspec_proc.build_sfa_rspec(slicename, resources_urn, None, leases) - f = open("/tmp/rspec_input.rspec", "w") - f.truncate(0) - f.write(rspec) - f.close() + with open("/tmp/rspec_input.rspec", "w") as f: + f.truncate(0) + f.write(rspec) if not os.path.getsize("/tmp/rspec_input.rspec") > 0: raise RuntimeError("Fail to create rspec file to allocate resource in slice %s" % slicename) @@ -270,10 +268,9 @@ class SFAAPI(object): # Re implementing urn from hrn because the library sfa-common doesn't work for wilabt resources_urn = self._get_urn(resources_hrn_new) rspec = self.rspec_proc.build_sfa_rspec(slicename, resources_urn, properties, leases) - f = open("/tmp/rspec_input.rspec", "w") - f.truncate(0) - f.write(rspec) - f.close() + with open("/tmp/rspec_input.rspec", "w") as f: + f.truncate(0) + f.write(rspec) if not os.path.getsize("/tmp/rspec_input.rspec") > 0: raise RuntimeError("Fail to create rspec file to allocate resources in slice %s" % slicename)