From e7be9787f28a3327360e0b671f6abaa80c242b7e Mon Sep 17 00:00:00 2001 From: Clement Trebuchet Date: Wed, 4 Jul 2018 01:33:26 +0200 Subject: [PATCH 1/3] Fixes: https://github.com/ansible/ansible/pull/41900 by handling the ptr:record object --- flaskapp.py | 181 +++++++++++++++++++++++++++------------------------- 1 file changed, 93 insertions(+), 88 deletions(-) mode change 100644 => 100755 flaskapp.py diff --git a/flaskapp.py b/flaskapp.py old mode 100644 new mode 100755 index 315eb50..48098b7 --- a/flaskapp.py +++ b/flaskapp.py @@ -3,16 +3,12 @@ # https://www.infoblox.com/wp-content/uploads/infoblox-deployment-infoblox-rest-api.pdf import base64 -import sys +from pprint import pprint -import flask from flask import Flask from flask import jsonify from flask import request from flask_basicauth import BasicAuth -from pprint import pprint - - app = Flask(__name__) app.config['BASIC_AUTH_USERNAME'] = 'admin' @@ -28,6 +24,7 @@ class NetworkView(object): _uid = None is_default = False name = None + ptrdname = None comment = None extattrs = {} network_view = 'default' @@ -36,11 +33,13 @@ class NetworkView(object): fqdn = None ipv4addrs = [] ipv6addrs = [] + ipv4addr = None + ipv6addr = None def __init__(self, uid=None, isdefault=False, name=None, viewtype='network', network=None, comment=None): # `ZG5zLm5ldHdvcmskMS4wLjAuMC8yNC8w` == `dns.network$1.0.0.0/24/0` - #self.uid = uid - #self.uid = (base64.b64encode(str.encode(str(viewtype) + '$' + str(network) + '$' + str(name)))).decode('utf-8') + # self.uid = uid + # self.uid = (base64.b64encode(str.encode(str(viewtype) + '$' + str(network) + '$' + str(name)))).decode('utf-8') if uid: self._uid = uid self.default = isdefault @@ -57,7 +56,7 @@ def uid(self): # CHILD: ZG5zLnpvbmUkLl9kZWZhdWx0LmFuc2libGUtZG5z == # dns.zone$._default.ansible-dns - ''' + """ $ for X in $(cat uuids.sorted.txt); do echo $X; echo $X | base64 -D ; echo ""; done; ZG5zLm5ldHdvcmskMTkyLjE2OC4xMC4wLzI0LzA dns.network$192.168.10.0/24 @@ -75,7 +74,7 @@ def uid(self): dns.view$._default ZG5zLnpvbmUkLl9kZWZhdWx0LmFuc2libGUtZG5z dns.zone$._default.ansible-dns - ''' + """ if self._uid: return self._uid @@ -87,7 +86,7 @@ def uid(self): else: try: uid += str.encode(self.viewtype) - except: + except Exception: uid += self.viewtype uid += '$' @@ -100,7 +99,7 @@ def uid(self): else: try: uid += str.encode(self.network) - except: + except Exception: uid += self.network uid = str.encode(uid) uid = base64.b64encode(uid) @@ -128,7 +127,7 @@ def _refid(self): @property def _ref(self): - ''' + """ (ansidev) jtanner-OSX:AP-NIOS_FLASK_MOCK jtanner$ curl -k -u admin:infoblox 'https://192.168.10.10/wapi/v2.1/network' [ { @@ -153,7 +152,7 @@ def _ref(self): ] network/ZG5zLm5ldHdvcmskMTkyLjE2OC4xMC4wLzI0LzA:192.168.10.0/24/default - ''' + """ # /:[/] if self.viewtype == 'network': out = self.viewtype @@ -168,30 +167,33 @@ def _ref(self): out += '/' out += self.uid out += ':' - out += self.name + out += self.name if self.ptrdname is None else self.get_ptr_name() out += '/' out += str(self.default).lower() - return out - #return self.viewtype + '/' + self.uid + ':' + self.name + '/' + str(self.default).lower() - - def to_dict(self, fields=[]): - ddict = { - 'uid': self.uid, - '_ref': self._ref, - #'_ref': self.uid, - 'is_default': self.default, - 'name': self.name, - 'comment': self.comment, - 'extattrs': self.extattrs, - 'network_view': self.network_view, - 'network': self.network, - 'view': self.view, - 'viewtype': self.viewtype, - 'options': self.options, - 'fqdn': self.fqdn, - 'ipv4addrs': self.ipv4addrs, - 'ipv6addrs': self.ipv6addrs - } + return out # return self.viewtype + '/' + self.uid + ':' + self.name + '/' + str(self.default).lower() + + def to_dict(self, fields=None): + if fields is None: + fields = [] + ddict = {'uid': self.uid, + '_ref': self._ref, # '_ref': self.uid, + 'is_default': self.default, + 'name': self.name, + 'ptrdname': self.ptrdname, + 'comment': self.comment, + 'extattrs': self.extattrs, + 'network_view': self.network_view, + 'network': self.network, + 'view': self.view, + 'viewtype': self.viewtype, + 'options': self.options, + 'fqdn': self.fqdn, + 'ipv4addrs': self.ipv4addrs, + 'ipv6addrs': self.ipv6addrs, + 'ipv4addr': self.ipv4addr, + 'ipv6addr': self.ipv6addr + + } if fields: for x in fields: if x not in ddict: @@ -201,30 +203,31 @@ def to_dict(self, fields=[]): ddict[x] = getattr(self, x) return ddict + def get_ptr_name(self): + """Get the name in the _ref for PTR:RECORD + + :return: str + """ + pget = self.ipv6addr if self.ipv4addr is None else self.ipv4addr + return "%s.in-addr.arpa" % '.'.join(reversed(str(pget).split('.'))) + +# noinspection PyProtectedMember class DataModel(object): def __init__(self): - self.views = { - 'network': [NetworkView(uid='ZG5zLm5ldHdvcmtfdmlldyQw', isdefault=True, name='default', network='1.0.0.0/24')], - 'networkview': [NetworkView(uid='ZG5zLm5ldHdvcmtfdmlldyQw', isdefault=True, name='default', network='1.0.0.0/24')], - 'ipv6network': [NetworkView(uid='ZG5zLm5ldHdvcmskZmU4MDo6LzY0LzA', isdefault=True, name='default', network='fe80::/64')], - 'zone_auth': [], - 'view': [NetworkView(isdefault=True, name='default', viewtype='view')], - 'record:host': [] - } - # ZG5zLm5ldHdvcmtfdmlldyQw == dns.network_view$0 - # ZG5zLm5ldHdvcmskZmU4MDo6LzY0LzA == dns.network$fe80::/64 + self.views = {'network': [NetworkView(uid='ZG5zLm5ldHdvcmtfdmlldyQw', isdefault=True, name='default', network='1.0.0.0/24')], + 'networkview': [NetworkView(uid='ZG5zLm5ldHdvcmtfdmlldyQw', isdefault=True, name='default', network='1.0.0.0/24')], + 'ipv6network': [NetworkView(uid='ZG5zLm5ldHdvcmskZmU4MDo6LzY0LzA', isdefault=True, name='default', network='fe80::/64')], 'zone_auth': [], + 'view': [NetworkView(isdefault=True, name='default', viewtype='view')], + 'record:host': [], + 'record:ptr': [], } # ZG5zLm5ldHdvcmtfdmlldyQw == dns.network_view$0 # ZG5zLm5ldHdvcmskZmU4MDo6LzY0LzA == dns.network$fe80::/64 def create_view(self, payload, viewtype='view', parent=None): # '{"name": "ansible-dns", "network_view": "default"}' # res = DATA.create_view(request.get_json()) - print ('########### VIEWTYPE: ' + viewtype) - view = NetworkView( - uid=None, - isdefault=False, - name=payload.get('name', ''), - viewtype=viewtype - ) + print('########### VIEWTYPE: ' + viewtype) + name = payload.get('name', None) + view = NetworkView(uid=None, isdefault=False, name=name, viewtype=viewtype) ''' if payload.get('network'): view.network = payload['network'] @@ -235,29 +238,28 @@ def create_view(self, payload, viewtype='view', parent=None): ''' if parent: view.parent = parent - for k,v in payload.items(): + for k, v in payload.items(): setattr(view, k, v) self.views[viewtype].append(view) return view def delete_view_by_refid(self, refid, viewtype=None): - for k,v in self.views.items(): + for k, v in self.views.items(): if viewtype and viewtype != k: continue - for idx,x in enumerate(v): + for idx, x in enumerate(v): if x._ref == refid: print('REMOVING %s' % x._ref) - self.views[k].remove(x) - #break + self.views[k].remove(x) # break def update_view_by_refid(self, refid, params): print('# UPDATING REFID %s' % refid) - #refid = refid.replace('view', 'networkview') + # refid = refid.replace('view', 'networkview') viewk = None viewix = None changed = False - for k,v in self.views.items(): - for idx,x in enumerate(v): + for k, v in self.views.items(): + for idx, x in enumerate(v): if x._refid != refid: print('# %s != %s' % (x._refid, refid)) else: @@ -265,7 +267,7 @@ def update_view_by_refid(self, refid, params): if x._ref == refid: viewk = k viewix = idx - for pk,pv in params.items(): + for pk, pv in params.items(): print('# pk: %s pv: %s' % (pk, pv)) if pk == 'options': # INPUT ... @@ -283,12 +285,12 @@ def update_view_by_refid(self, refid, params): if not opts: opts = pv[:] else: - for idr,reqopt in enumerate(pv): + for idr, reqopt in enumerate(pv): isset = False - for idv,viewopt in enumerate(opts): + for idv, viewopt in enumerate(opts): if viewopt.get('name') != reqopt.get('name'): continue - for rk,rv in reqopt.items(): + for rk, rv in reqopt.items(): opts[idv][rk] = rv isset = False if not isset: @@ -344,7 +346,7 @@ def update_view_by_uid(self, uid, params): def serialize_views(self, viewtype=None, name=None): res = [] - for k,v in self.views.items(): + for k, v in self.views.items(): if viewtype and viewtype != k: continue if name: @@ -358,13 +360,15 @@ def serialize_views(self, viewtype=None, name=None): return res def serialize_view(self, view_type, name=None): - #print('serializing %s view' % view_type) + # print('serializing %s view' % view_type) res = [x.to_dict() for x in self.views[view_type]] return res - def serialize_view_by_refid(self, refid, returnfields=[]): + def serialize_view_by_refid(self, refid, returnfields=None): + if returnfields is None: + returnfields = [] view = None - for k,v in self.views.items(): + for k, v in self.views.items(): for x in v: if x._ref == refid: view = x @@ -377,28 +381,31 @@ def serialize_view_by_refid(self, refid, returnfields=[]): DATA = DataModel() +# noinspection PyProtectedMember @app.route('/wapi/v2.1/', methods=['GET', 'POST', 'PUT', 'DELETE']) def v21_base(viewtype): - #if viewtype != 'view': + # if viewtype != 'view': # viewtype = viewtype.replace('view', '') - #print('VIEWTYPE: %s METHOD: %s' % (viewtype, request.method)) + # print('VIEWTYPE: %s METHOD: %s' % (viewtype, request.method)) - print('# METHOD: %s VIEWTYPE: %s' % ( - request.method, viewtype - )) + print('# METHOD: %s VIEWTYPE: %s' % (request.method, viewtype)) args = request.args.to_dict() print('# REQARGS ...') pprint(args) print('# REQJSON ...') try: pprint(request.get_json()) - except: + except Exception: pprint({}) if request.method == 'GET': print('# FETCHED VIEW ...') - #payload = DATA.serialize_view(viewtype, name=args.get('name')) - payload = DATA.serialize_views(viewtype=viewtype, name=args.get('name')) + # payload = DATA.serialize_view(viewtype, name=args.get('name')) + print('# ARGS ...') + name = args.get('name', None) + if name is None: + name = args.get('ptrdname', None) + payload = DATA.serialize_views(viewtype=viewtype, name=name) pprint(payload) return jsonify(payload) @@ -412,13 +419,13 @@ def v21_base(viewtype): return jsonify({}) + # /wapi/v2.1/network/bmV0d29yayQxLjAuMC4wLzI0JGRlZmF1bHQ%3D%3A1.0.0.0/24/default -#@app.route('/wapi/v2.1///', methods=['GET', 'POST', 'PUT', 'DELETE']) -#@app.route('/wapi/v2.1////subsubname', methods=['GET', 'POST', 'PUT', 'DELETE']) +# @app.route('/wapi/v2.1///', methods=['GET', 'POST', 'PUT', 'DELETE']) +# @app.route('/wapi/v2.1////subsubname', methods=['GET', 'POST', 'PUT', 'DELETE']) @app.route('/wapi/v2.1//', methods=['GET', 'POST', 'PUT', 'DELETE']) def v21_abstractview_ref(viewtype, refid=None, subname=None, refpath=None, subsubname=None): - - ''' + """ _refid = 'view/' + refid + '/' + subname __refid = refid.split(':')[0] if viewtype != 'view': @@ -427,14 +434,12 @@ def v21_abstractview_ref(viewtype, refid=None, subname=None, refpath=None, subsu print('VIEWTYPE: %s METHOD: %s REFID: %s _REFID: %s' % ( viewtype, request.method, __refid, _refid )) - ''' + """ print('# REFPATH: %s' % refpath) _refid = viewtype + '/' + refpath uid = refpath.split('/')[1].split(':')[0] - print('# METHOD: %s VIEWTYPE: %s UID: %s _REFID: %s' % ( - request.method, viewtype, uid, _refid - )) + print('# METHOD: %s VIEWTYPE: %s UID: %s _REFID: %s' % (request.method, viewtype, uid, _refid)) args = request.args.to_dict() print('# REQARGS ...') @@ -442,11 +447,11 @@ def v21_abstractview_ref(viewtype, refid=None, subname=None, refpath=None, subsu print('# REQJSON ...') try: pprint(request.get_json()) - except: + except Exception: pprint({}) if request.method == 'GET': - view = DATA.serialize_view_by_refid(__refid, return_fields=args.get('_return_fields', [])) + view = DATA.serialize_view_by_refid(_refid, returnfields=args.get('_return_fields', [])) print('# FETCHED VIEW [%s]...' % _refid) pprint(view) return jsonify(view) @@ -458,7 +463,7 @@ def v21_abstractview_ref(viewtype, refid=None, subname=None, refpath=None, subsu return jsonify(view.to_dict()), 201 elif request.method == 'PUT': view = DATA.update_view_by_refid(_refid, request.get_json()) - #view = DATA.update_view_by_uid(__refid, request.get_json()) + # view = DATA.update_view_by_uid(__refid, request.get_json()) if not view: print('# ERROR!!! MODIFYING [%s] RETURN NO VIEW!' % _refid) return jsonify({}) @@ -472,7 +477,7 @@ def v21_abstractview_ref(viewtype, refid=None, subname=None, refpath=None, subsu return jsonify({}) print('default return ...') - #return '' + # return '' return jsonify({}) From 01a2ee47a79e11e361eb11cae1ff40483acacab3 Mon Sep 17 00:00:00 2001 From: Clement Trebuchet Date: Wed, 4 Jul 2018 10:50:54 +0200 Subject: [PATCH 2/3] REM: style related changes --- flaskapp.py | 162 ++++++++++++++++++++++++++++------------------------ 1 file changed, 88 insertions(+), 74 deletions(-) diff --git a/flaskapp.py b/flaskapp.py index 48098b7..9e68f08 100755 --- a/flaskapp.py +++ b/flaskapp.py @@ -3,12 +3,16 @@ # https://www.infoblox.com/wp-content/uploads/infoblox-deployment-infoblox-rest-api.pdf import base64 -from pprint import pprint +import sys +import flask from flask import Flask from flask import jsonify from flask import request from flask_basicauth import BasicAuth +from pprint import pprint + + app = Flask(__name__) app.config['BASIC_AUTH_USERNAME'] = 'admin' @@ -38,8 +42,8 @@ class NetworkView(object): def __init__(self, uid=None, isdefault=False, name=None, viewtype='network', network=None, comment=None): # `ZG5zLm5ldHdvcmskMS4wLjAuMC8yNC8w` == `dns.network$1.0.0.0/24/0` - # self.uid = uid - # self.uid = (base64.b64encode(str.encode(str(viewtype) + '$' + str(network) + '$' + str(name)))).decode('utf-8') + #self.uid = uid + #self.uid = (base64.b64encode(str.encode(str(viewtype) + '$' + str(network) + '$' + str(name)))).decode('utf-8') if uid: self._uid = uid self.default = isdefault @@ -56,7 +60,7 @@ def uid(self): # CHILD: ZG5zLnpvbmUkLl9kZWZhdWx0LmFuc2libGUtZG5z == # dns.zone$._default.ansible-dns - """ + ''' $ for X in $(cat uuids.sorted.txt); do echo $X; echo $X | base64 -D ; echo ""; done; ZG5zLm5ldHdvcmskMTkyLjE2OC4xMC4wLzI0LzA dns.network$192.168.10.0/24 @@ -74,7 +78,7 @@ def uid(self): dns.view$._default ZG5zLnpvbmUkLl9kZWZhdWx0LmFuc2libGUtZG5z dns.zone$._default.ansible-dns - """ + ''' if self._uid: return self._uid @@ -86,7 +90,7 @@ def uid(self): else: try: uid += str.encode(self.viewtype) - except Exception: + except: uid += self.viewtype uid += '$' @@ -99,7 +103,7 @@ def uid(self): else: try: uid += str.encode(self.network) - except Exception: + except: uid += self.network uid = str.encode(uid) uid = base64.b64encode(uid) @@ -127,7 +131,7 @@ def _refid(self): @property def _ref(self): - """ + ''' (ansidev) jtanner-OSX:AP-NIOS_FLASK_MOCK jtanner$ curl -k -u admin:infoblox 'https://192.168.10.10/wapi/v2.1/network' [ { @@ -152,7 +156,7 @@ def _ref(self): ] network/ZG5zLm5ldHdvcmskMTkyLjE2OC4xMC4wLzI0LzA:192.168.10.0/24/default - """ + ''' # /:[/] if self.viewtype == 'network': out = self.viewtype @@ -170,30 +174,30 @@ def _ref(self): out += self.name if self.ptrdname is None else self.get_ptr_name() out += '/' out += str(self.default).lower() - return out # return self.viewtype + '/' + self.uid + ':' + self.name + '/' + str(self.default).lower() - - def to_dict(self, fields=None): - if fields is None: - fields = [] - ddict = {'uid': self.uid, - '_ref': self._ref, # '_ref': self.uid, - 'is_default': self.default, - 'name': self.name, - 'ptrdname': self.ptrdname, - 'comment': self.comment, - 'extattrs': self.extattrs, - 'network_view': self.network_view, - 'network': self.network, - 'view': self.view, - 'viewtype': self.viewtype, - 'options': self.options, - 'fqdn': self.fqdn, - 'ipv4addrs': self.ipv4addrs, - 'ipv6addrs': self.ipv6addrs, - 'ipv4addr': self.ipv4addr, - 'ipv6addr': self.ipv6addr - - } + return out + #return self.viewtype + '/' + self.uid + ':' + self.name + '/' + str(self.default).lower() + + def to_dict(self, fields=[]): + ddict = { + 'uid': self.uid, + '_ref': self._ref, + #'_ref': self.uid, + 'is_default': self.default, + 'name': self.name, + 'ptrdname': self.ptrdname, + 'comment': self.comment, + 'extattrs': self.extattrs, + 'network_view': self.network_view, + 'network': self.network, + 'view': self.view, + 'viewtype': self.viewtype, + 'options': self.options, + 'fqdn': self.fqdn, + 'ipv4addrs': self.ipv4addrs, + 'ipv6addrs': self.ipv6addrs, + 'ipv4addr': self.ipv4addr, + 'ipv6addr': self.ipv6addr + } if fields: for x in fields: if x not in ddict: @@ -215,19 +219,28 @@ def get_ptr_name(self): # noinspection PyProtectedMember class DataModel(object): def __init__(self): - self.views = {'network': [NetworkView(uid='ZG5zLm5ldHdvcmtfdmlldyQw', isdefault=True, name='default', network='1.0.0.0/24')], - 'networkview': [NetworkView(uid='ZG5zLm5ldHdvcmtfdmlldyQw', isdefault=True, name='default', network='1.0.0.0/24')], - 'ipv6network': [NetworkView(uid='ZG5zLm5ldHdvcmskZmU4MDo6LzY0LzA', isdefault=True, name='default', network='fe80::/64')], 'zone_auth': [], - 'view': [NetworkView(isdefault=True, name='default', viewtype='view')], - 'record:host': [], - 'record:ptr': [], } # ZG5zLm5ldHdvcmtfdmlldyQw == dns.network_view$0 # ZG5zLm5ldHdvcmskZmU4MDo6LzY0LzA == dns.network$fe80::/64 + self.views = { + 'network': [NetworkView(uid='ZG5zLm5ldHdvcmtfdmlldyQw', isdefault=True, name='default', network='1.0.0.0/24')], + 'networkview': [NetworkView(uid='ZG5zLm5ldHdvcmtfdmlldyQw', isdefault=True, name='default', network='1.0.0.0/24')], + 'ipv6network': [NetworkView(uid='ZG5zLm5ldHdvcmskZmU4MDo6LzY0LzA', isdefault=True, name='default', network='fe80::/64')], + 'zone_auth': [], + 'view': [NetworkView(isdefault=True, name='default', viewtype='view')], + 'record:host': [], + 'record:ptr': [], + } + # ZG5zLm5ldHdvcmtfdmlldyQw == dns.network_view$0 + # ZG5zLm5ldHdvcmskZmU4MDo6LzY0LzA == dns.network$fe80::/64 def create_view(self, payload, viewtype='view', parent=None): # '{"name": "ansible-dns", "network_view": "default"}' # res = DATA.create_view(request.get_json()) - print('########### VIEWTYPE: ' + viewtype) - name = payload.get('name', None) - view = NetworkView(uid=None, isdefault=False, name=name, viewtype=viewtype) + print ('########### VIEWTYPE: ' + viewtype) + view = NetworkView( + uid=None, + isdefault=False, + name=payload.get('name', ''), + viewtype=viewtype + ) ''' if payload.get('network'): view.network = payload['network'] @@ -238,28 +251,29 @@ def create_view(self, payload, viewtype='view', parent=None): ''' if parent: view.parent = parent - for k, v in payload.items(): + for k,v in payload.items(): setattr(view, k, v) self.views[viewtype].append(view) return view def delete_view_by_refid(self, refid, viewtype=None): - for k, v in self.views.items(): + for k,v in self.views.items(): if viewtype and viewtype != k: continue - for idx, x in enumerate(v): + for idx,x in enumerate(v): if x._ref == refid: print('REMOVING %s' % x._ref) - self.views[k].remove(x) # break + self.views[k].remove(x) + #break def update_view_by_refid(self, refid, params): print('# UPDATING REFID %s' % refid) - # refid = refid.replace('view', 'networkview') + #refid = refid.replace('view', 'networkview') viewk = None viewix = None changed = False - for k, v in self.views.items(): - for idx, x in enumerate(v): + for k,v in self.views.items(): + for idx,x in enumerate(v): if x._refid != refid: print('# %s != %s' % (x._refid, refid)) else: @@ -267,7 +281,7 @@ def update_view_by_refid(self, refid, params): if x._ref == refid: viewk = k viewix = idx - for pk, pv in params.items(): + for pk,pv in params.items(): print('# pk: %s pv: %s' % (pk, pv)) if pk == 'options': # INPUT ... @@ -285,12 +299,12 @@ def update_view_by_refid(self, refid, params): if not opts: opts = pv[:] else: - for idr, reqopt in enumerate(pv): + for idr,reqopt in enumerate(pv): isset = False - for idv, viewopt in enumerate(opts): + for idv,viewopt in enumerate(opts): if viewopt.get('name') != reqopt.get('name'): continue - for rk, rv in reqopt.items(): + for rk,rv in reqopt.items(): opts[idv][rk] = rv isset = False if not isset: @@ -346,7 +360,7 @@ def update_view_by_uid(self, uid, params): def serialize_views(self, viewtype=None, name=None): res = [] - for k, v in self.views.items(): + for k,v in self.views.items(): if viewtype and viewtype != k: continue if name: @@ -360,15 +374,13 @@ def serialize_views(self, viewtype=None, name=None): return res def serialize_view(self, view_type, name=None): - # print('serializing %s view' % view_type) + #print('serializing %s view' % view_type) res = [x.to_dict() for x in self.views[view_type]] return res - def serialize_view_by_refid(self, refid, returnfields=None): - if returnfields is None: - returnfields = [] + def serialize_view_by_refid(self, refid, returnfields=[]): view = None - for k, v in self.views.items(): + for k,v in self.views.items(): for x in v: if x._ref == refid: view = x @@ -381,27 +393,27 @@ def serialize_view_by_refid(self, refid, returnfields=None): DATA = DataModel() -# noinspection PyProtectedMember @app.route('/wapi/v2.1/', methods=['GET', 'POST', 'PUT', 'DELETE']) def v21_base(viewtype): - # if viewtype != 'view': + #if viewtype != 'view': # viewtype = viewtype.replace('view', '') - # print('VIEWTYPE: %s METHOD: %s' % (viewtype, request.method)) + #print('VIEWTYPE: %s METHOD: %s' % (viewtype, request.method)) - print('# METHOD: %s VIEWTYPE: %s' % (request.method, viewtype)) + print('# METHOD: %s VIEWTYPE: %s' % ( + request.method, viewtype + )) args = request.args.to_dict() print('# REQARGS ...') pprint(args) print('# REQJSON ...') try: pprint(request.get_json()) - except Exception: + except: pprint({}) if request.method == 'GET': print('# FETCHED VIEW ...') # payload = DATA.serialize_view(viewtype, name=args.get('name')) - print('# ARGS ...') name = args.get('name', None) if name is None: name = args.get('ptrdname', None) @@ -419,13 +431,13 @@ def v21_base(viewtype): return jsonify({}) - # /wapi/v2.1/network/bmV0d29yayQxLjAuMC4wLzI0JGRlZmF1bHQ%3D%3A1.0.0.0/24/default -# @app.route('/wapi/v2.1///', methods=['GET', 'POST', 'PUT', 'DELETE']) -# @app.route('/wapi/v2.1////subsubname', methods=['GET', 'POST', 'PUT', 'DELETE']) +#@app.route('/wapi/v2.1///', methods=['GET', 'POST', 'PUT', 'DELETE']) +#@app.route('/wapi/v2.1////subsubname', methods=['GET', 'POST', 'PUT', 'DELETE']) @app.route('/wapi/v2.1//', methods=['GET', 'POST', 'PUT', 'DELETE']) def v21_abstractview_ref(viewtype, refid=None, subname=None, refpath=None, subsubname=None): - """ + + ''' _refid = 'view/' + refid + '/' + subname __refid = refid.split(':')[0] if viewtype != 'view': @@ -434,12 +446,14 @@ def v21_abstractview_ref(viewtype, refid=None, subname=None, refpath=None, subsu print('VIEWTYPE: %s METHOD: %s REFID: %s _REFID: %s' % ( viewtype, request.method, __refid, _refid )) - """ + ''' print('# REFPATH: %s' % refpath) _refid = viewtype + '/' + refpath uid = refpath.split('/')[1].split(':')[0] - print('# METHOD: %s VIEWTYPE: %s UID: %s _REFID: %s' % (request.method, viewtype, uid, _refid)) + print('# METHOD: %s VIEWTYPE: %s UID: %s _REFID: %s' % ( + request.method, viewtype, uid, _refid + )) args = request.args.to_dict() print('# REQARGS ...') @@ -447,7 +461,7 @@ def v21_abstractview_ref(viewtype, refid=None, subname=None, refpath=None, subsu print('# REQJSON ...') try: pprint(request.get_json()) - except Exception: + except: pprint({}) if request.method == 'GET': @@ -463,7 +477,7 @@ def v21_abstractview_ref(viewtype, refid=None, subname=None, refpath=None, subsu return jsonify(view.to_dict()), 201 elif request.method == 'PUT': view = DATA.update_view_by_refid(_refid, request.get_json()) - # view = DATA.update_view_by_uid(__refid, request.get_json()) + #view = DATA.update_view_by_uid(__refid, request.get_json()) if not view: print('# ERROR!!! MODIFYING [%s] RETURN NO VIEW!' % _refid) return jsonify({}) @@ -477,7 +491,7 @@ def v21_abstractview_ref(viewtype, refid=None, subname=None, refpath=None, subsu return jsonify({}) print('default return ...') - # return '' + #return '' return jsonify({}) From d8213c5a88687563c34c08e0ca98854647c479f0 Mon Sep 17 00:00:00 2001 From: Clement Trebuchet Date: Wed, 4 Jul 2018 10:59:18 +0200 Subject: [PATCH 3/3] REM: noinspection PyProtectedMember --- flaskapp.py | 1 - 1 file changed, 1 deletion(-) diff --git a/flaskapp.py b/flaskapp.py index 9e68f08..6ff08ec 100755 --- a/flaskapp.py +++ b/flaskapp.py @@ -216,7 +216,6 @@ def get_ptr_name(self): return "%s.in-addr.arpa" % '.'.join(reversed(str(pget).split('.'))) -# noinspection PyProtectedMember class DataModel(object): def __init__(self): self.views = {