1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

py3 print fix

This commit is contained in:
nitzmahone 2016-08-18 14:32:44 -07:00
parent 2a2d866c0d
commit 4fbd17d949

View file

@ -20,6 +20,7 @@
# -- Josh Preston <jpreston@redhat.com> # -- Josh Preston <jpreston@redhat.com>
# #
from __future__ import print_function
import argparse import argparse
import ConfigParser import ConfigParser
import os import os
@ -61,7 +62,7 @@ class CloudFormsInventory(object):
# Data to print # Data to print
if self.args.host: if self.args.host:
if self.args.debug: if self.args.debug:
print "Fetching host [%s]" % self.args.host print("Fetching host [%s]" % self.args.host)
data_to_print += self.get_host_info(self.args.host) data_to_print += self.get_host_info(self.args.host)
else: else:
self.inventory['_meta'] = {'hostvars': {}} self.inventory['_meta'] = {'hostvars': {}}
@ -82,7 +83,7 @@ class CloudFormsInventory(object):
Determines if the cache files have expired, or if it is still valid Determines if the cache files have expired, or if it is still valid
""" """
if self.args.debug: if self.args.debug:
print "Determining if cache [%s] is still valid (< %s seconds old)" % (self.cache_path_hosts, self.cache_max_age) print("Determining if cache [%s] is still valid (< %s seconds old)" % (self.cache_path_hosts, self.cache_max_age))
if os.path.isfile(self.cache_path_hosts): if os.path.isfile(self.cache_path_hosts):
mod_time = os.path.getmtime(self.cache_path_hosts) mod_time = os.path.getmtime(self.cache_path_hosts)
@ -90,11 +91,11 @@ class CloudFormsInventory(object):
if (mod_time + self.cache_max_age) > current_time: if (mod_time + self.cache_max_age) > current_time:
if os.path.isfile(self.cache_path_inventory): if os.path.isfile(self.cache_path_inventory):
if self.args.debug: if self.args.debug:
print "Cache is still valid!" print("Cache is still valid!")
return True return True
if self.args.debug: if self.args.debug:
print "Cache is stale or does not exist." print("Cache is stale or does not exist.")
return False return False
@ -114,7 +115,7 @@ class CloudFormsInventory(object):
if self.args.debug: if self.args.debug:
for config_path in config_paths: for config_path in config_paths:
print "Reading from configuration file [%s]" % config_path print("Reading from configuration file [%s]" % config_path)
config.read(config_paths) config.read(config_paths)
@ -192,18 +193,18 @@ class CloudFormsInventory(object):
self.cache_max_age = config.getint('cache', 'max_age') self.cache_max_age = config.getint('cache', 'max_age')
if self.args.debug: if self.args.debug:
print "CloudForms settings:" print("CloudForms settings:")
print "cloudforms_url = %s" % self.cloudforms_url print("cloudforms_url = %s" % self.cloudforms_url)
print "cloudforms_username = %s" % self.cloudforms_username print("cloudforms_username = %s" % self.cloudforms_username)
print "cloudforms_pw = %s" % self.cloudforms_pw print("cloudforms_pw = %s" % self.cloudforms_pw)
print "cloudforms_ssl_verify = %s" % self.cloudforms_ssl_verify print("cloudforms_ssl_verify = %s" % self.cloudforms_ssl_verify)
print "cloudforms_version = %s" % self.cloudforms_version print("cloudforms_version = %s" % self.cloudforms_version)
print "cloudforms_limit = %s" % self.cloudforms_limit print("cloudforms_limit = %s" % self.cloudforms_limit)
print "cloudforms_purge_actions = %s" % self.cloudforms_purge_actions print("cloudforms_purge_actions = %s" % self.cloudforms_purge_actions)
print "Cache settings:" print("Cache settings:")
print "cache_max_age = %s" % self.cache_max_age print("cache_max_age = %s" % self.cache_max_age)
print "cache_path_hosts = %s" % self.cache_path_hosts print("cache_path_hosts = %s" % self.cache_path_hosts)
print "cache_path_inventory = %s" % self.cache_path_inventory print("cache_path_inventory = %s" % self.cache_path_inventory)
def parse_cli_args(self): def parse_cli_args(self):
""" """
@ -237,13 +238,13 @@ class CloudFormsInventory(object):
results = {} results = {}
if self.args.debug: if self.args.debug:
print "=======================================================================" print("=======================================================================")
print "=======================================================================" print("=======================================================================")
print "=======================================================================" print("=======================================================================")
print ret.text print(ret.text)
print "=======================================================================" print("=======================================================================")
print "=======================================================================" print("=======================================================================")
print "=======================================================================" print("=======================================================================")
return results return results
@ -276,13 +277,13 @@ class CloudFormsInventory(object):
self.hosts = dict() self.hosts = dict()
if self.args.debug: if self.args.debug:
print "Updating cache..." print("Updating cache...")
for host in self._get_hosts(): for host in self._get_hosts():
# Ignore VMs that are not powered on # Ignore VMs that are not powered on
if host['power_state'] != 'on': if host['power_state'] != 'on':
if self.args.debug: if self.args.debug:
print "Skipping %s because power_state = %s" % (host['name'], host['power_state']) print("Skipping %s because power_state = %s" % (host['name'], host['power_state']))
continue continue
# purge actions # purge actions
@ -303,7 +304,7 @@ class CloudFormsInventory(object):
safe_key = self.to_safe(group['name']) safe_key = self.to_safe(group['name'])
if safe_key: if safe_key:
if self.args.debug: if self.args.debug:
print "Adding sub-group '%s' to parent 'tags'" % safe_key print("Adding sub-group '%s' to parent 'tags'" % safe_key)
if safe_key not in self.inventory['tags']['children']: if safe_key not in self.inventory['tags']['children']:
self.push(self.inventory['tags'], 'children', safe_key) self.push(self.inventory['tags'], 'children', safe_key)
@ -311,7 +312,7 @@ class CloudFormsInventory(object):
self.push(self.inventory, safe_key, host['name']) self.push(self.inventory, safe_key, host['name'])
if self.args.debug: if self.args.debug:
print "Found tag [%s] for host which will be mapped to [%s]" % (group['name'], safe_key) print("Found tag [%s] for host which will be mapped to [%s]" % (group['name'], safe_key))
else: else:
# expand the tags into nested groups / sub-groups # expand the tags into nested groups / sub-groups
# Create nested groups for tags # Create nested groups for tags
@ -320,15 +321,15 @@ class CloudFormsInventory(object):
tag_hierarchy = tag['name'][1:].split('/') tag_hierarchy = tag['name'][1:].split('/')
if self.args.debug: if self.args.debug:
print "Working on list %s" % tag_hierarchy print("Working on list %s" % tag_hierarchy)
for tag_name in tag_hierarchy: for tag_name in tag_hierarchy:
if self.args.debug: if self.args.debug:
print "Working on tag_name = %s" % tag_name print("Working on tag_name = %s" % tag_name)
safe_tag_name = self.to_safe(tag_name) safe_tag_name = self.to_safe(tag_name)
if self.args.debug: if self.args.debug:
print "Using sanitized name %s" % safe_tag_name print("Using sanitized name %s" % safe_tag_name)
# Create sub-group # Create sub-group
if safe_tag_name not in self.inventory: if safe_tag_name not in self.inventory:
@ -337,7 +338,7 @@ class CloudFormsInventory(object):
# Add sub-group, as a child of top-level # Add sub-group, as a child of top-level
if safe_parent_tag_name: if safe_parent_tag_name:
if self.args.debug: if self.args.debug:
print "Adding sub-group '%s' to parent '%s'" % (safe_tag_name, safe_parent_tag_name) print("Adding sub-group '%s' to parent '%s'" % (safe_tag_name, safe_parent_tag_name))
if safe_tag_name not in self.inventory[safe_parent_tag_name]['children']: if safe_tag_name not in self.inventory[safe_parent_tag_name]['children']:
self.push(self.inventory[safe_parent_tag_name], 'children', safe_tag_name) self.push(self.inventory[safe_parent_tag_name], 'children', safe_tag_name)
@ -376,7 +377,7 @@ class CloudFormsInventory(object):
self.push(self.inventory, 'all', host['name']) self.push(self.inventory, 'all', host['name'])
if self.args.debug: if self.args.debug:
print "Saving cached data" print("Saving cached data")
self.write_to_cache(self.hosts, self.cache_path_hosts) self.write_to_cache(self.hosts, self.cache_path_hosts)
self.write_to_cache(self.inventory, self.cache_path_inventory) self.write_to_cache(self.inventory, self.cache_path_inventory)
@ -391,14 +392,14 @@ class CloudFormsInventory(object):
if host not in self.hosts: if host not in self.hosts:
if self.args.debug: if self.args.debug:
print "[%s] not found in cache." % host print("[%s] not found in cache." % host)
# try updating the cache # try updating the cache
self.update_cache() self.update_cache()
if host not in self.hosts: if host not in self.hosts:
if self.args.debug: if self.args.debug:
print "[%s] does not exist after cache update." % host print("[%s] does not exist after cache update." % host)
# host might not exist anymore # host might not exist anymore
return self.json_format_dict({}, self.args.pretty) return self.json_format_dict({}, self.args.pretty)