Skip to content

Commit

Permalink
Upgraded to work with python3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
rashmidhundia committed Mar 16, 2024
1 parent 9ed1895 commit 97b0526
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 32 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
settings.yaml
settings.yaml
./.idea
2 changes: 1 addition & 1 deletion device42.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def update_device(self, **kwargs):
known_fields += " customer contract_id contract"
known_fields += " aliases subtype virtual_subtype notes tags"
known_fields = atleast_fields + known_fields.split()
if not set(atleast_fields).intersection(kwargs.keys()):
if not set(atleast_fields).intersection(list(kwargs.keys())):
raise Device42BadArgumentError("At least one parameter should be passed: %s" % atleast_fields)
unknown_fields = set(kwargs.keys()) - set(known_fields)
if unknown_fields:
Expand Down
16 changes: 8 additions & 8 deletions nodefilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ def node_filter(ndata, filterlist):
# getting real value from attribute
for akey in apath:
if not isinstance(aroot, dict) or akey not in aroot:
print("Attribute %s does not match: path not found" % flt['attribute'])
print(("Attribute %s does not match: path not found" % flt['attribute']))
# retval = retval and False
return False
aroot = aroot[akey]
# Here 'aroot' should contain target attribute

wrong_op = False
if isinstance(aroot, basestring):
if isinstance(aroot, str):
if oprt in ['iequal', 'ieq']:
retval = str(fval).lower() == aroot.lower()
elif oprt in ['equal', 'eq']:
Expand All @@ -46,8 +46,8 @@ def node_filter(ndata, filterlist):
else: # iin - case-insensitive 'in'
retval = any([True for v in fval if aroot.lower() == v.lower()])
else:
print("Attribute %s: value of type %s does not support operator 'in', clause ignored" %
(flt['attribute'], type(fval)))
print(("Attribute %s: value of type %s does not support operator 'in', clause ignored" %
(flt['attribute'], type(fval))))
continue
else:
wrong_op = True
Expand All @@ -62,7 +62,7 @@ def node_filter(ndata, filterlist):
else:
wrong_op = True

elif isinstance(aroot, (int, float, long)):
elif isinstance(aroot, (int, float)):
if oprt in ['equal', 'eq']:
retval = fval == aroot
elif oprt in ['greater', 'gt']:
Expand All @@ -76,12 +76,12 @@ def node_filter(ndata, filterlist):
retval = aroot == fval

else:
print("Not supported attribute type: %s" % (type(aroot)))
print(("Not supported attribute type: %s" % (type(aroot))))
return False

if wrong_op:
print("Unknown operator '%s' for attribute '%s' of type %s, ignore clause" %
(oprt, flt['attribute'], type(aroot)))
print(("Unknown operator '%s' for attribute '%s' of type %s, ignore clause" %
(oprt, flt['attribute'], type(aroot))))
# return False
continue

Expand Down
73 changes: 56 additions & 17 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,56 @@
appdirs==1.4.0
backports-abc==0.5
certifi==2017.1.23
futures==3.0.5
Jinja2==2.9.4
MarkupSafe==0.23
msgpack-python==0.4.8
packaging==16.8
pycrypto==2.6.1
pyparsing==2.1.10
PyYAML==3.12
pyzmq==16.0.2
requests==2.13.0
salt==2016.11.1
singledispatch==3.4.0.3
six==1.10.0
tornado==4.4.2
aiohttp==3.9.3
aiosignal==1.3.1
annotated-types==0.6.0
async-timeout==4.0.3
attrs==23.2.0
autocommand==2.2.2
certifi==2024.2.2
cffi==1.16.0
charset-normalizer==3.3.2
cheroot==10.0.0
CherryPy==18.9.0
contextvars==2.4
cryptography==42.0.5
distro==1.9.0
frozenlist==1.4.1
idna==3.6
immutables==0.20
importlib_metadata==7.0.2
inflect==7.0.0
jaraco.collections==5.0.0
jaraco.context==4.3.0
jaraco.functools==4.0.0
jaraco.text==3.12.0
Jinja2==3.1.3
jmespath==1.0.1
looseversion==1.3.0
MarkupSafe==2.1.5
more-itertools==10.2.0
msgpack==1.0.8
multidict==6.0.5
packaging==24.0
portend==3.2.0
psutil==5.9.8
pycparser==2.21
pycryptodomex==3.20.0
pydantic==2.6.4
pydantic_core==2.16.3
pyOpenSSL==24.1.0
python-dateutil==2.9.0.post0
python-gnupg==0.5.2
pytz==2024.1
PyYAML==6.0.1
pyzmq==25.1.2
requests==2.31.0
rpm-vercmp==0.1.2
salt==3007.0
setproctitle==1.3.3
six==1.16.0
tempora==5.5.1
timelib==0.3.0
tornado==6.4
typing_extensions==4.10.0
urllib3==2.2.1
yarl==1.9.4
zc.lockfile==3.0.post1
zipp==3.18.1
10 changes: 5 additions & 5 deletions saltexplore.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get_config(cfgpath):
raise ValueError("Config file %s is not found!" % cfgpath)
cfgpath = os.path.join(CUR_DIR, cfgpath)
with open(cfgpath, 'r') as cfgf:
config = yaml.load(cfgf.read())
config = yaml.load(cfgf.read(), Loader=yaml.SafeLoader)
return config


Expand Down Expand Up @@ -205,7 +205,7 @@ def d42_insert(dev42, nodes, options, static_opt):
updated_ips = []

if node.get('hwaddr_interfaces'):
for ifsname, ifs in node.get('hwaddr_interfaces').items():
for ifsname, ifs in list(node.get('hwaddr_interfaces').items()):
if ifsname.startswith('lo'):
continue

Expand All @@ -215,7 +215,7 @@ def d42_insert(dev42, nodes, options, static_opt):
})

if node.get('ip_interfaces') and node.get('hwaddr_interfaces'):
for ifsname, ifs in node.get('ip_interfaces').items():
for ifsname, ifs in list(node.get('ip_interfaces').items()):
if ifsname.startswith('lo') or ifsname.startswith('tun') or ifsname.startswith('tap'):
continue # filter out local and tunnel

Expand Down Expand Up @@ -274,7 +274,7 @@ def main():
salt_nodes = all_nodes[0]
if args.onlynode:
salt_nodes = {}
for key, node in all_nodes[0].items():
for key, node in list(all_nodes[0].items()):
if node.get('nodename') in args.onlynode[0] or node.get('fqdn') in args.onlynode[0]:
salt_nodes[key] = node
logger.debug("Got %s nodes from file" % len(salt_nodes))
Expand Down Expand Up @@ -309,5 +309,5 @@ def main():

if __name__ == "__main__":
ret_val = main()
print 'Done'
print('Done')
sys.exit(ret_val)

0 comments on commit 97b0526

Please sign in to comment.