Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions foremanexplore.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ def clean_dict(obj):
}

# Check to see that we have all data, or set it to '' if not
if facts.has_key('is_virtual'):
if 'is_virtual' in facts:
_is_virtual = facts['is_virtual']
else:
_is_virtual = False
if facts.has_key('serialnumber'):
if 'serialnumber' in facts:
_serialnumber = facts['serialnumber']
else:
_serialnumber = ''
if facts.has_key('processors::models'):
if 'processors::models' in facts:
_processors_models = ast.literal_eval(facts['processors::models'])
else:
_processors_models = ['']
Expand Down Expand Up @@ -210,5 +210,5 @@ def clean_dict(obj):

if __name__ == "__main__":
retval = main()
print 'Done'
print('Done')
sys.exit(retval)
19 changes: 10 additions & 9 deletions nodefilter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from six import string_types


def node_filter(ndata, filterlist):
Expand All @@ -22,7 +23,7 @@ def node_filter(ndata, filterlist):
# Here 'aroot' should contain target attribute

wrong_op = False
if isinstance(aroot, basestring):
if isinstance(aroot, string_types):
if oprt in ['iequal', 'ieq']:
retval = str(fval).lower() == aroot.lower()
elif oprt in ['equal', 'eq']:
Expand All @@ -35,13 +36,13 @@ def node_filter(ndata, filterlist):
retval = str(fval).lower() >= aroot.lower()
elif oprt in ['less', 'lt']:
retval = str(fval) >= aroot
elif optr in ['isubstr', 'icontains']:
elif oprt in ['isubstr', 'icontains']:
retval = aroot.lower().find(str(fval).lower()) >= 0
elif optr in ['substr', 'contains']:
elif oprt in ['substr', 'contains']:
retval = aroot.find(str(fval)) >= 0
elif optr in ['in', 'iin']:
elif oprt in ['in', 'iin']:
if isinstance(fval, (list, dict)):
if optr == 'in':
if oprt == 'in':
retval = aroot in fval
else: # iin - case-insensitive 'in'
retval = any([True for v in fval if aroot.lower() == v.lower()])
Expand All @@ -53,16 +54,16 @@ def node_filter(ndata, filterlist):
wrong_op = True

elif isinstance(aroot, (list, dict)):
if optr in ['has', 'contains']:
if oprt in ['has', 'contains']:
retval = str(fval) in aroot
elif optr in ['ihas', 'icontains']:
elif oprt in ['ihas', 'icontains']:
retval = any([True for v in aroot if fval.lower() == v.lower()])
elif optr in ['empty']:
elif oprt in ['empty']:
retval = not aroot
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 Down
10 changes: 5 additions & 5 deletions puppetexplore.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def d42_update(dev42, nodes, options, static_opt, mapping, from_version='3', pup
continue

if options.get('show_node'):
print node
print(node)

node_name = node['hostname']

Expand Down Expand Up @@ -209,7 +209,7 @@ def get_depth(obj):
except KeyError:
continue

if type(step) in [unicode, str, int]:
if type(step) in [str, int]:
value = step
elif type(step) in [list, tuple, dict]:
value = len(step)
Expand Down Expand Up @@ -301,7 +301,7 @@ def get_depth(obj):
updated_ips.append(updateinfo['msg'][1])
logger.info("IP %s for device %s updated/created (id %s)" % (ifs['ip6'], node_name, deviceid))
except device42.Device42HTTPError as e:
print e
print(e)

if 'network6' in ifs and 'netmask6' in ifs:
# update IPv6 subnet
Expand All @@ -316,7 +316,7 @@ def get_depth(obj):
updated_ips.append(updateinfo['msg'][1])
logger.info("Subnet %s/%s for device %s updated/created (id %s)" % (ifs['network6'], mask, node_name, deviceid))
except device42.Device42HTTPError as e:
print e
print(e)

# Delete other IPs from the device
if updated_ips:
Expand Down Expand Up @@ -406,5 +406,5 @@ def main():

if __name__ == "__main__":
retval = main()
print 'Done'
print('Done')
sys.exit(retval)
3 changes: 2 additions & 1 deletion puppetwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import json
import requests
from six import string_types
requests.packages.urllib3.disable_warnings()


Expand Down Expand Up @@ -74,7 +75,7 @@ def _from_pson(self, data):
newdata = {}
for k, v in data.items():
newdata[k] = self._from_pson(v)
elif isinstance(data, basestring):
elif isinstance(data, string_types):
# try convert ruby-styled serialized Hash to python dict
if '"=>' in data:
try:
Expand Down