Fix: Make osmclient Python 3 compatible.
authorpeusterm <manuel.peuster@uni-paderborn.de>
Thu, 14 Jun 2018 19:32:55 +0000 (21:32 +0200)
committerpeusterm <manuel.peuster@uni-paderborn.de>
Thu, 14 Jun 2018 20:12:14 +0000 (22:12 +0200)
The Python 3 compatibility of osmclient was
completely broken, e.g., print statements without ().
This fixes are mostly done with the automated 2to3
conversion tool.
Some fixes (mixed tabs and spaces) were fixed by hand.

Change-Id: Idea46a4b07e55eaa5bcf5defff64af3f751d740f
Signed-off-by: peusterm <manuel.peuster@upb.de>
13 files changed:
osmclient/common/utils.py
osmclient/scripts/osm.py
osmclient/sol005/client.py
osmclient/sol005/http.py
osmclient/sol005/ns.py
osmclient/sol005/nsd.py
osmclient/sol005/package.py
osmclient/sol005/sdncontroller.py
osmclient/sol005/vim.py
osmclient/sol005/vnfd.py
osmclient/v1/client.py
osmclient/v1/ns.py
tox.ini

index a3f4bc8..8ef325f 100644 (file)
@@ -67,10 +67,10 @@ def get_key_val_from_pkg(descriptor_file):
 
     dict = yaml.load(tar.extractfile(yamlfile))
     result = {}
-    for k1, v1 in dict.items():
+    for k1, v1 in list(dict.items()):
         if not k1.endswith('-catalog'):
             continue
-        for k2, v2 in v1.items():
+        for k2, v2 in list(v1.items()):
             if not k2.endswith('nsd') and not k2.endswith('vnfd'):
                 continue
 
@@ -80,7 +80,7 @@ def get_key_val_from_pkg(descriptor_file):
                 result['type'] = 'vnfd'
 
             for entry in v2:
-                for k3, v3 in entry.items():
+                for k3, v3 in list(entry.items()):
                     # strip off preceeding chars before :
                     key_name = k3.split(':').pop()
 
index d581228..ba8ef5a 100755 (executable)
@@ -76,9 +76,9 @@ def check_client_version(obj, what, version='sol005'):
 @click.pass_context
 def cli(ctx, hostname, so_port, so_project, ro_hostname, ro_port, sol005):
     if hostname is None:
-        print(
+        print((
             "either hostname option or OSM_HOSTNAME " +
-            "environment variable needs to be specified")
+            "environment variable needs to be specified"))
         exit(1)
     kwargs={}
     if so_port is not None:
@@ -228,7 +228,7 @@ def vnf_list(ctx, ns):
         else:
             resp = ctx.obj.vnf.list()
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
     fullclassname = ctx.obj.__module__ + "." + ctx.obj.__class__.__name__
     if fullclassname == 'osmclient.sol005.client.Client':
@@ -280,7 +280,7 @@ def ns_op_list(ctx, name):
         check_client_version(ctx.obj, ctx.command.name)
         resp = ctx.obj.ns.list_op(name)
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
 
     table = PrettyTable(['id', 'operation', 'status'])
@@ -299,15 +299,15 @@ def nsd_show(ctx, name, literal):
         resp = ctx.obj.nsd.get(name)
         #resp = ctx.obj.nsd.get_individual(name)
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
 
     if literal:
-        print yaml.safe_dump(resp)
+        print(yaml.safe_dump(resp))
         return
 
     table = PrettyTable(['field', 'value'])
-    for k, v in resp.items():
+    for k, v in list(resp.items()):
         table.add_row([k, json.dumps(v, indent=2)])
     table.align = 'l'
     print(table)
@@ -344,15 +344,15 @@ def vnfd_show(ctx, name, literal):
         resp = ctx.obj.vnfd.get(name)
         #resp = ctx.obj.vnfd.get_individual(name)
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
 
     if literal:
-        print yaml.safe_dump(resp)
+        print(yaml.safe_dump(resp))
         return
 
     table = PrettyTable(['field', 'value'])
-    for k, v in resp.items():
+    for k, v in list(resp.items()):
         table.add_row([k, json.dumps(v, indent=2)])
     table.align = 'l'
     print(table)
@@ -398,16 +398,16 @@ def ns_show(ctx, name, literal, filter):
     try:
         ns = ctx.obj.ns.get(name)
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
 
     if literal:
-        print yaml.safe_dump(resp)
+        print(yaml.safe_dump(ns))
         return
 
     table = PrettyTable(['field', 'value'])
 
-    for k, v in ns.items():
+    for k, v in list(ns.items()):
         if filter is None or filter in k:
             table.add_row([k, json.dumps(v, indent=2)])
 
@@ -415,7 +415,7 @@ def ns_show(ctx, name, literal, filter):
     if fullclassname != 'osmclient.sol005.client.Client':
         nsopdata = ctx.obj.ns.get_opdata(ns['id'])
         nsr_optdata = nsopdata['nsr:nsr']
-        for k, v in nsr_optdata.items():
+        for k, v in list(nsr_optdata.items()):
             if filter is None or filter in k:
                 table.add_row([k, json.dumps(v, indent=2)])
     table.align = 'l'
@@ -437,15 +437,15 @@ def vnf_show(ctx, name, literal, filter):
         check_client_version(ctx.obj, ctx.command.name)
         resp = ctx.obj.vnf.get(name)
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
 
     if literal:
-        print yaml.safe_dump(resp)
+        print(yaml.safe_dump(resp))
         return
 
     table = PrettyTable(['field', 'value'])
-    for k, v in resp.items():
+    for k, v in list(resp.items()):
         if filter is None or filter in k:
             table.add_row([k, json.dumps(v, indent=2)])
     table.align = 'l'
@@ -460,7 +460,7 @@ def vnf_monitoring_show(ctx, vnf_name):
         check_client_version(ctx.obj, ctx.command.name, 'v1')
         resp = ctx.obj.vnf.get_monitoring(vnf_name)
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
 
     table = PrettyTable(['vnf name', 'monitoring name', 'value', 'units'])
@@ -483,11 +483,11 @@ def ns_monitoring_show(ctx, ns_name):
         check_client_version(ctx.obj, ctx.command.name, 'v1')
         resp = ctx.obj.ns.get_monitoring(ns_name)
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
 
     table = PrettyTable(['vnf name', 'monitoring name', 'value', 'units'])
-    for key, val in resp.items():
+    for key, val in list(resp.items()):
         for monitor in val:
             table.add_row(
                 [key,
@@ -510,11 +510,11 @@ def ns_op_show(ctx, id, filter):
         check_client_version(ctx.obj, ctx.command.name)
         op_info = ctx.obj.ns.get_op(id)
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
 
     table = PrettyTable(['field', 'value'])
-    for k, v in op_info.items():
+    for k, v in list(op_info.items()):
         if filter is None or filter in k:
             table.add_row([k, json.dumps(v, indent=2)])
     table.align = 'l'
@@ -530,7 +530,7 @@ def nsd_create(ctx, filename, overwrite):
         check_client_version(ctx.obj, ctx.command.name)
         ctx.obj.nsd.create(filename, overwrite)
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
 
 
@@ -565,7 +565,7 @@ def vnfd_create(ctx, filename, overwrite):
         check_client_version(ctx.obj, ctx.command.name)
         ctx.obj.vnfd.create(filename, overwrite)
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
 
 
@@ -631,7 +631,7 @@ def ns_create(ctx,
             ssh_keys=ssh_keys,
             account=vim_account)
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
 
 
@@ -644,7 +644,7 @@ def nsd_update(ctx, name, content):
         check_client_version(ctx.obj, ctx.command.name)
         ctx.obj.nsd.update(name, content)
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
 
 @cli.command(name='nsd-update', short_help='updates a NSD/NSpkg')
@@ -678,7 +678,7 @@ def vnfd_update(ctx, name, content):
         check_client_version(ctx.obj, ctx.command.name)
         ctx.obj.vnfd.update(name, content)
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
 
 
@@ -720,7 +720,7 @@ def nsd_delete(ctx, name, force):
             check_client_version(ctx.obj, '--force')
             ctx.obj.nsd.delete(name, force)
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
 
 
@@ -756,7 +756,7 @@ def vnfd_delete(ctx, name, force):
             check_client_version(ctx.obj, '--force')
             ctx.obj.vnfd.delete(name, force)
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
 
 
@@ -800,7 +800,7 @@ def ns_delete(ctx, name, force):
             check_client_version(ctx.obj, '--force')
             ctx.obj.ns.delete(name, force)
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
 
 
@@ -869,7 +869,7 @@ def vim_create(ctx,
         else:
             ctx.obj.vim.create(name, vim)
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
 
 
@@ -915,7 +915,7 @@ def vim_update(ctx,
         if config: vim['config'] = config
         ctx.obj.vim.update(name, vim, sdn_controller, sdn_port_mapping)
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
 
 
@@ -935,7 +935,7 @@ def vim_delete(ctx, name, force):
             check_client_version(ctx.obj, '--force')
             ctx.obj.vim.delete(name, force)
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
 
 
@@ -977,11 +977,11 @@ def vim_show(ctx, name):
         if 'vim_password' in resp:
             resp['vim_password']='********'
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
 
     table = PrettyTable(['key', 'attribute'])
-    for k, v in resp.items():
+    for k, v in list(resp.items()):
         table.add_row([k, json.dumps(v, indent=2)])
     table.align = 'l'
     print(table)
@@ -1047,7 +1047,7 @@ def sdnc_create(ctx,
         check_client_version(ctx.obj, ctx.command.name)
         ctx.obj.sdnc.create(name, sdncontroller)
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
 
 
 @cli.command(name='sdnc-update', short_help='updates an SDN controller')
@@ -1102,7 +1102,7 @@ def sdnc_update(ctx,
         check_client_version(ctx.obj, ctx.command.name)
         ctx.obj.sdnc.update(name, sdncontroller)
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
 
 
@@ -1119,7 +1119,7 @@ def sdnc_delete(ctx, name, force):
         check_client_version(ctx.obj, ctx.command.name)
         ctx.obj.sdnc.delete(name, force)
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
 
 
@@ -1133,7 +1133,7 @@ def sdnc_list(ctx, filter):
         check_client_version(ctx.obj, ctx.command.name)
         resp = ctx.obj.sdnc.list(filter)
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
     table = PrettyTable(['name', 'id'])
     for sdnc in resp:
@@ -1154,11 +1154,11 @@ def sdnc_show(ctx, name):
         check_client_version(ctx.obj, ctx.command.name)
         resp = ctx.obj.sdnc.get(name)
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
 
     table = PrettyTable(['key', 'attribute'])
-    for k, v in resp.items():
+    for k, v in list(resp.items()):
         table.add_row([k, json.dumps(v, indent=2)])
     table.align = 'l'
     print(table)
@@ -1205,7 +1205,7 @@ def ns_alarm_create(ctx, name, ns, vnf, vdu, metric, severity,
         check_client_version(ctx.obj, ctx.command.name)
         ctx.obj.ns.create_alarm(alarm)
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
 
 
@@ -1256,15 +1256,15 @@ def ns_metric_export(ctx, ns, vnf, vdu, metric, interval):
     try:
         check_client_version(ctx.obj, ctx.command.name)
         if not interval:
-            print '{}'.format(ctx.obj.ns.export_metric(metric_data))
+            print('{}'.format(ctx.obj.ns.export_metric(metric_data)))
         else:
             i = 1
             while True:
-                print '{} {}'.format(ctx.obj.ns.export_metric(metric_data),i)
+                print('{} {}'.format(ctx.obj.ns.export_metric(metric_data),i))
                 time.sleep(int(interval))
                 i+=1
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
 
 
@@ -1286,7 +1286,7 @@ def upload_package(ctx, filename):
         if fullclassname != 'osmclient.sol005.client.Client':
             ctx.obj.package.wait_for_upload(filename)
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
 
 
@@ -1302,7 +1302,7 @@ def show_ns_scaling(ctx, ns_name):
         check_client_version(ctx.obj, ctx.command.name, 'v1')
         resp = ctx.obj.ns.list()
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
 
     table = PrettyTable(
@@ -1346,7 +1346,7 @@ def ns_scale(ctx, ns_name, ns_scale_group, index):
         check_client_version(ctx.obj, ctx.command.name, 'v1')
         ctx.obj.ns.scale(ns_name, ns_scale_group, index)
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
 
 
@@ -1357,7 +1357,7 @@ def config_agent_list(ctx):
     try:
         check_client_version(ctx.obj, ctx.command.name, 'v1')
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
     table = PrettyTable(['name', 'account-type', 'details'])
     for account in ctx.obj.vca.list():
@@ -1381,7 +1381,7 @@ def config_agent_delete(ctx, name):
         check_client_version(ctx.obj, ctx.command.name, 'v1')
         ctx.obj.vca.delete(name)
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
 
 
@@ -1405,7 +1405,7 @@ def config_agent_add(ctx, name, account_type, server, user, secret):
         check_client_version(ctx.obj, ctx.command.name, 'v1')
         ctx.obj.vca.create(name, account_type, server, user, secret)
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
 
 @cli.command(name='ro-dump')
@@ -1415,7 +1415,7 @@ def ro_dump(ctx):
     check_client_version(ctx.obj, ctx.command.name, 'v1')
     resp = ctx.obj.vim.get_resource_orchestrator()
     table = PrettyTable(['key', 'attribute'])
-    for k, v in resp.items():
+    for k, v in list(resp.items()):
         table.add_row([k, json.dumps(v, indent=2)])
     table.align = 'l'
     print(table)
@@ -1458,7 +1458,7 @@ def ns_action(ctx,
         ctx.obj.ns.exec_op(ns_name, op_name='action', op_data=op_data)
 
     except ClientException as inst:
-        print(inst.message)
+        print((inst.message))
         exit(1)
 
 
index cec7436..479fc9a 100644 (file)
@@ -68,7 +68,7 @@ class Client(object):
         self._headers['Accept'] = 'application/json'
         self._headers['Content-Type'] = 'application/yaml'
         http_header = ['{}: {}'.format(key,val)
-                      for (key,val) in self._headers.items()]
+                      for (key,val) in list(self._headers.items())]
         self._http_client.set_http_header(http_header)
 
         token = self.get_token()
index 4debf0d..7988d89 100644 (file)
@@ -17,9 +17,7 @@
 from io import BytesIO
 import pycurl
 import json
-import yaml
 from osmclient.common import http
-from osmclient.common.exceptions import ClientException
 
 class Http(http.Http):
 
index 75cdf3f..c60baa0 100644 (file)
@@ -84,9 +84,9 @@ class Ns(object):
         #print 'HTTP CODE: {}'.format(http_code)
         #print 'RESP: {}'.format(resp)
         if http_code == 202:
-            print 'Deletion in progress'
+            print('Deletion in progress')
         elif http_code == 204:
-            print 'Deleted'
+            print('Deleted')
         else:
             msg = ""
             if resp:
@@ -143,7 +143,7 @@ class Ns(object):
                     if vld.get("vim-network-name"):
                         if isinstance(vld["vim-network-name"], dict):
                             vim_network_name_dict = {}
-                            for vim_account, vim_net in vld["vim-network-name"].items():
+                            for vim_account, vim_net in list(vld["vim-network-name"].items()):
                                 vim_network_name_dict[get_vim_account_id(vim_account)] = vim_net
                             vld["vim-network-name"] = vim_network_name_dict
                 ns["vld"] = ns_config["vld"]
@@ -169,7 +169,7 @@ class Ns(object):
                 if not resp or 'id' not in resp:
                     raise ClientException('unexpected response from server - {} '.format(
                                       resp))
-                print resp['id']
+                print(resp['id'])
             else:
                 msg = ""
                 if resp:
@@ -273,7 +273,7 @@ class Ns(object):
                 if not resp or 'id' not in resp:
                     raise ClientException('unexpected response from server - {}'.format(
                                       resp))
-                print resp['id']
+                print(resp['id'])
             else:
                 msg = ""
                 if resp:
@@ -299,7 +299,7 @@ class Ns(object):
             #print 'RESP: {}'.format(resp)
             if http_code in (200, 201, 202, 204):
                 #resp = json.loads(resp)
-                print 'Alarm created'
+                print('Alarm created')
             else:
                 msg = ""
                 if resp:
@@ -327,7 +327,7 @@ class Ns(object):
             #print 'RESP: {}'.format(resp)
             if http_code in (200, 201, 202, 204):
                 #resp = json.loads(resp)
-                print 'Alarm deleted'
+                print('Alarm deleted')
             else:
                 msg = ""
                 if resp:
@@ -339,7 +339,7 @@ class Ns(object):
                                       http_code, msg))
         except ClientException as exc:
             message="failed to delete alarm: alarm {}\n{}".format(
-                    alarm,
+                    name,
                     exc.message)
             raise ClientException(message)
 
index 10ad38f..0dbec43 100644 (file)
@@ -21,7 +21,6 @@ OSM nsd API handling
 from osmclient.common.exceptions import NotFound
 from osmclient.common.exceptions import ClientException
 from osmclient.common import utils
-import yaml
 import json
 import magic
 #from os import stat
@@ -109,9 +108,9 @@ class Nsd(object):
         #print 'HTTP CODE: {}'.format(http_code)
         #print 'RESP: {}'.format(resp)
         if http_code == 202:
-            print 'Deletion in progress'
+            print('Deletion in progress')
         elif http_code == 204:
-            print 'Deleted'
+            print('Deleted')
         else:
             msg = ""
             if resp:
@@ -143,7 +142,7 @@ class Nsd(object):
                   )
         headers["Content-File-MD5"] = utils.md5(filename)
         http_header = ['{}: {}'.format(key,val)
-                      for (key,val) in headers.items()]
+                      for (key,val) in list(headers.items())]
         self._http.set_http_header(http_header)
         if update_endpoint:
             http_code, resp = self._http.put_cmd(endpoint=update_endpoint, filename=filename)
@@ -164,7 +163,7 @@ class Nsd(object):
             if not resp or 'id' not in resp:
                 raise ClientException('unexpected response from server - {}'.format(
                                       resp))
-            print resp['id']
+            print(resp['id'])
         else:
             msg = "Error {}".format(http_code)
             if resp:
index 172ee45..887539b 100644 (file)
 OSM package API handling
 """
 
-import tarfile
-import re
-import yaml
 #from os import stat
 #from os.path import basename
 from osmclient.common.exceptions import ClientException
-from osmclient.common.exceptions import NotFound
 from osmclient.common import utils
 import json
 
@@ -56,7 +52,7 @@ class Package(object):
         #headers['Content-Range'] = 'bytes 0-{}/{}'.format(file_size - 1, file_size)
         headers["Content-File-MD5"] = utils.md5(filename)
         http_header = ['{}: {}'.format(key,val)
-                      for (key,val) in headers.items()]
+                      for (key,val) in list(headers.items())]
         self._http.set_http_header(http_header)
         http_code, resp = self._http.post_cmd(endpoint=endpoint, filename=filename)
         #print 'HTTP CODE: {}'.format(http_code)
@@ -67,7 +63,7 @@ class Package(object):
             if not resp or 'id' not in resp:
                 raise ClientException('unexpected response from server - {}'.format(
                                       resp))
-            print resp['id']
+            print(resp['id'])
         else:
             msg = ""
             if resp:
@@ -75,5 +71,5 @@ class Package(object):
                      msg = json.loads(resp)
                 except ValueError:
                     msg = resp
-            raise ClientException("failed to delete ns {} - {}".format(name, msg))
+            raise ClientException("failed to upload package - {}".format(msg))
 
index 39ad3be..6129961 100644 (file)
@@ -21,7 +21,6 @@ OSM SDN controller API handling
 from osmclient.common import utils
 from osmclient.common.exceptions import ClientException
 from osmclient.common.exceptions import NotFound
-import yaml
 import json
 
 
@@ -45,7 +44,7 @@ class SdnController(object):
             if not resp or 'id' not in resp:
                 raise ClientException('unexpected response from server - {}'.format(
                                       resp))
-            print resp['id']
+            print(resp['id'])
         else:
             msg = ""
             if resp:
@@ -67,7 +66,7 @@ class SdnController(object):
             if not resp or 'id' not in resp:
                 raise ClientException('unexpected response from server - {}'.format(
                                       resp))
-            print resp['id']
+            print(resp['id'])
         else:
             msg = ""
             if resp:
@@ -87,11 +86,11 @@ class SdnController(object):
         #print 'HTTP CODE: {}'.format(http_code)
         #print 'RESP: {}'.format(resp)
         if http_code == 202:
-            print 'Deletion in progress'
+            print('Deletion in progress')
         elif http_code == 204:
-            print 'Deleted'
+            print('Deleted')
         elif resp and 'result' in resp:
-            print 'Deleted'
+            print('Deleted')
         else:
             msg = ""
             if resp:
index 6e15e5b..293362a 100644 (file)
@@ -66,7 +66,7 @@ class Vim(object):
             if not resp or 'id' not in resp:
                 raise ClientException('unexpected response from server - {}'.format(
                                       resp))
-            print resp['id']
+            print(resp['id'])
         else:
             msg = ""
             if resp:
@@ -81,9 +81,9 @@ class Vim(object):
 
         vim_config = {}
         if 'config' in vim_account:
-            if config=="" and (sdncontroller or sdn_port_mapping):
+            if vim_account.get('config')=="" and (sdn_controller or sdn_port_mapping):
                 raise ClientException("clearing config is incompatible with updating SDN info")
-            if config=="":
+            if vim_account.get('config')=="":
                 vim_config = None
             else:
                 vim_config = yaml.safe_load(vim_account['config'])
@@ -105,7 +105,7 @@ class Vim(object):
             if not resp or 'id' not in resp:
                 raise ClientException('unexpected response from server - {}'.format(
                                       resp))
-            print resp['id']
+            print(resp['id'])
         else:
             msg = ""
             if resp:
@@ -144,9 +144,9 @@ class Vim(object):
         #print 'HTTP CODE: {}'.format(http_code)
         #print 'RESP: {}'.format(resp)
         if http_code == 202:
-            print 'Deletion in progress'
+            print('Deletion in progress')
         elif http_code == 204:
-            print 'Deleted'
+            print('Deleted')
         else:
             msg = ""
             if resp:
index b4d7987..c769d4c 100644 (file)
@@ -21,7 +21,6 @@ OSM vnfd API handling
 from osmclient.common.exceptions import NotFound
 from osmclient.common.exceptions import ClientException
 from osmclient.common import utils
-import yaml
 import json
 import magic
 #from os import stat
@@ -108,9 +107,9 @@ class Vnfd(object):
         #print 'HTTP CODE: {}'.format(http_code)
         #print 'RESP: {}'.format(resp)
         if http_code == 202:
-            print 'Deletion in progress'
+            print('Deletion in progress')
         elif http_code == 204:
-            print 'Deleted'
+            print('Deleted')
         else:
             msg = ""
             if resp:
@@ -121,7 +120,7 @@ class Vnfd(object):
             raise ClientException("failed to delete vnfd {} - {}".format(name, msg))
 
     def create(self, filename, overwrite=None, update_endpoint=None):
-       mime_type = magic.from_file(filename, mime=True)
+        mime_type = magic.from_file(filename, mime=True)
         if mime_type is None:
             raise ClientException(
                      "failed to guess MIME type for file '{}'".format(filename))
@@ -142,7 +141,7 @@ class Vnfd(object):
                   )
         headers["Content-File-MD5"] = utils.md5(filename)
         http_header = ['{}: {}'.format(key,val)
-                      for (key,val) in headers.items()]
+                      for (key,val) in list(headers.items())]
         self._http.set_http_header(http_header)
         if update_endpoint:
             http_code, resp = self._http.put_cmd(endpoint=update_endpoint, filename=filename)
@@ -163,7 +162,7 @@ class Vnfd(object):
             if not resp or 'id' not in resp:
                 raise ClientException('unexpected response from server: '.format(
                                       resp))
-            print resp['id']
+            print(resp['id'])
         else:
             msg = "Error {}".format(http_code)
             if resp:
index 7a332eb..b7ce83b 100644 (file)
@@ -120,7 +120,7 @@ class Client(object):
                 # SO Version 5.x.x.x.x translates to OSM V3
                 return 'v3'
             return 'v2'
-        except Exception as e:
+        except Exception:
             return 'v2'
 
 
index 65f816d..3d638e1 100644 (file)
@@ -122,7 +122,7 @@ class Ns(object):
             for network in ns_config['vim-network-name']:
                 # now find this network
                 vld_name = network['name']
-                vim_vld_name = network['vim-network-name']
+                vim_vld_name = network['vim-network-name']
 
                 for index, vld in enumerate(nsr['nsd']['vld']):
                     if vld['name'] == vld_name:
diff --git a/tox.ini b/tox.ini
index 134636b..5c85c60 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -1,5 +1,5 @@
 [tox]
-envlist = py27,py3,flake8
+envlist = py27,py3,flake8,pyflakes
 toxworkdir={homedir}/.tox
 
 [testenv]
@@ -13,6 +13,12 @@ deps = flake8
 commands =
     flake8 setup.py
 
+[testenv:pyflakes]
+basepython = python3
+deps = pyflakes
+commands =
+    pyflakes osmclient
+
 [testenv:build]
 basepython = python
 deps = stdeb