diff --git a/compute-huge/compute-huge/topology.py b/compute-huge/compute-huge/topology.py index f84c0c1869..08ed4c52a5 100755 --- a/compute-huge/compute-huge/topology.py +++ b/compute-huge/compute-huge/topology.py @@ -10,6 +10,7 @@ # sockets, cores per package, threads per core, # total memory, and numa nodes +from __future__ import print_function import os import sys import re @@ -182,51 +183,51 @@ class Topology(object): cpu_list.sort() total_memory_GiB = self.total_memory_MiB/1024.0 - print 'TOPOLOGY:' - print '%16s : %5d' % ('logical cpus', self.num_cpus) - print '%16s : %5d' % ('sockets', self.num_sockets) - print '%16s : %5d' % ('cores_per_pkg', self.num_cores_per_pkg) - print '%16s : %5d' % ('threads_per_core', self.num_threads_per_core) - print '%16s : %5d' % ('numa_nodes', self.num_nodes) - print '%16s : %5.2f %s' % ('total_memory', total_memory_GiB, 'GiB') - print '%16s :' % ('memory_per_node'), + print('TOPOLOGY:') + print('%16s : %5d' % ('logical cpus', self.num_cpus)) + print('%16s : %5d' % ('sockets', self.num_sockets)) + print('%16s : %5d' % ('cores_per_pkg', self.num_cores_per_pkg)) + print('%16s : %5d' % ('threads_per_core', self.num_threads_per_core)) + print('%16s : %5d' % ('numa_nodes', self.num_nodes)) + print('%16s : %5.2f %s' % ('total_memory', total_memory_GiB, 'GiB')) + print('%16s :' % ('memory_per_node'), end=' ') for node in range(self.num_nodes): node_memory_GiB = self.total_memory_nodes_MiB[node]/1024.0 - print '%5.2f' % (node_memory_GiB), - print '%s' % ('GiB') - print + print('%5.2f' % (node_memory_GiB), end=' ') + print('%s' % ('GiB')) + print('') - print 'LOGICAL CPU TOPOLOGY:' - print "%9s :" % 'cpu_id', + print('LOGICAL CPU TOPOLOGY:') + print("%9s :" % 'cpu_id', end=' ') for cpu in cpu_list: - print "%3d" % cpu, - print - print "%9s :" % 'socket_id', + print("%3d" % cpu, end=' ') + print('') + print("%9s :" % 'socket_id', end=' ') for cpu in cpu_list: socket_id = self.topology_idx[cpu]['s'] - print "%3d" % socket_id, - print - print "%9s :" % 'core_id', + print("%3d" % socket_id, end=' ') + print('') + print("%9s :" % 'core_id', end=' ') for cpu in cpu_list: core_id = self.topology_idx[cpu]['c'] - print "%3d" % core_id, - print - print "%9s :" % 'thread_id', + print("%3d" % core_id, end=' ') + print('') + print("%9s :" % 'thread_id', end=' ') for cpu in cpu_list: thread_id = self.topology_idx[cpu]['t'] - print "%3d" % thread_id, - print - print + print("%3d" % thread_id, end=' ') + print('') + print('') - print 'CORE TOPOLOGY:' - print "%6s %9s %7s %9s %s" % ('cpu_id', 'socket_id', 'core_id', 'thread_id', 'affinity') + print('CORE TOPOLOGY:') + print("%6s %9s %7s %9s %s" % ('cpu_id', 'socket_id', 'core_id', 'thread_id', 'affinity')) for cpu in cpu_list: affinity = 1< Validate a system configuration file\n" - "--region-config Validate a region configuration file\n" - % sys.argv[0]) + print("Usage: %s\n" + "Perform validation of a given configuration file\n\n" + "--system-config Validate a system configuration file\n" + "--region-config Validate a region configuration file\n" + % sys.argv[0]) exit(1) @@ -44,8 +45,8 @@ def main(): if arg < len(sys.argv): config_file = sys.argv[arg] else: - print "--system-config requires the filename of the config " \ - "file" + print("--system-config requires the filename of the config " + "file") exit(1) system_config = True elif sys.argv[arg] == "--region-config": @@ -53,19 +54,19 @@ def main(): if arg < len(sys.argv): config_file = sys.argv[arg] else: - print "--region-config requires the filename of the config " \ - "file" + print("--region-config requires the filename of the config " + "file") exit(1) region_config = True elif sys.argv[arg] in ["--help", "-h", "-?"]: show_help() else: - print "Invalid option." + print("Invalid option.") show_help() arg += 1 if [system_config, region_config].count(True) != 1: - print "Invalid combination of options selected" + print("Invalid combination of options selected") show_help() if system_config: @@ -78,12 +79,12 @@ def main(): exit(1) # Parse the system config file - print "Parsing configuration file... ", + print("Parsing configuration file... ", end=' ') system_config = parse_config(config_file) - print "DONE" + print("DONE") # Validate the system config file - print "Validating configuration file... ", + print("Validating configuration file... ", end=' ') try: # we use the presence of tsconfig to determine if we are onboard or # not since it will not be available in the offboard case @@ -97,4 +98,4 @@ def main(): print("Error parsing configuration file %s: %s" % (config_file, e)) except (ConfigFail, ValidateFail) as e: print("\nValidation failed: %s" % e) - print "DONE" + print("DONE") diff --git a/configutilities/configutilities/tox.ini b/configutilities/configutilities/tox.ini index 18d31d776e..fd39d6c86b 100644 --- a/configutilities/configutilities/tox.ini +++ b/configutilities/configutilities/tox.ini @@ -18,5 +18,20 @@ commands = {posargs} [testenv:flake8] basepython = python2.7 -deps = flake8<3.6.0 +deps = hacking + flake8<3.6.0 commands = flake8 {posargs} + +# H series are hacking +# H102: Apache 2.0 license header not found +# H104: File contains nothing but comments +# H301: one import per line +# H306: imports not in alphabetical order +# H401: docstring should not start with a space +# H403: multi line docstrings should end on a new line +# H404: multi line docstring should start without a leading new line +# H405: multi line docstring summary not separated with an empty line +# W503 line break before binary operator +[flake8] +ignore = H102,H104,H301,H306,H401,H403,H404,H405, + W503 diff --git a/controllerconfig/controllerconfig/controllerconfig/backup_restore.py b/controllerconfig/controllerconfig/controllerconfig/backup_restore.py index df5623e586..5e10b542d6 100644 --- a/controllerconfig/controllerconfig/controllerconfig/backup_restore.py +++ b/controllerconfig/controllerconfig/controllerconfig/backup_restore.py @@ -8,6 +8,7 @@ Backup & Restore """ +from __future__ import print_function import copy import filecmp import fileinput @@ -336,7 +337,7 @@ def restore_configuration(archive, staging_dir): # The INSTALL_UUID must be updated to match the new INSTALL_UUID # which was generated when this controller was installed prior to # doing the restore. - print "INSTALL_UUID=%s" % install_uuid + print("INSTALL_UUID=%s" % install_uuid) elif line.startswith("management_interface=") or \ line.startswith("oam_interface=") or \ line.startswith("infrastructure_interface=") or \ @@ -346,7 +347,7 @@ def restore_configuration(archive, staging_dir): # platform_conf manifest will add these back in. pass else: - print line, + print(line, end=' ') fileinput.close() # Move updated platform.conf file into place. os.rename(temp_platform_conf_file, tsconfig.PLATFORM_CONF_FILE) @@ -965,10 +966,10 @@ def check_size(archive_dir, cinder_config): utils.filesystem_get_free_space(archive_dir) if backup_size > archive_dir_free_space: - print ("Archive directory (%s) does not have enough free " - "space (%s), estimated backup size is %s." % - (archive_dir, utils.print_bytes(archive_dir_free_space), - utils.print_bytes(backup_size))) + print("Archive directory (%s) does not have enough free " + "space (%s), estimated backup size is %s." % + (archive_dir, utils.print_bytes(archive_dir_free_space), + utils.print_bytes(backup_size))) raise BackupFail("Not enough free space for backup.") @@ -1155,12 +1156,12 @@ def backup(backup_name, archive_dir, clone=False): system_msg += ": " + system_tar_path images_msg += ": " + images_tar_path - print system_msg + print(system_msg) if tsconfig.region_config != "yes": - print images_msg + print(images_msg) if warnings != '': - print "WARNING: The following problems occurred:" - print textwrap.fill(warnings, 80) + print("WARNING: The following problems occurred:") + print(textwrap.fill(warnings, 80)) def create_restore_runtime_config(filename): @@ -1206,11 +1207,11 @@ def restore_complete(): """ if utils.get_system_type() == sysinv_constants.TIS_AIO_BUILD: if not os.path.isfile(restore_system_ready): - print textwrap.fill( + print(textwrap.fill( "--restore-complete can only be run " "after restore-system has completed " "successfully", 80 - ) + )) return False # The iscsi target config file must be overwritten with the @@ -1222,9 +1223,9 @@ def restore_complete(): # we use use that. overwrite_iscsi_target_config() - print ("\nApplying compute manifests for %s. " % - (utils.get_controller_hostname())) - print ("Node will reboot on completion.") + print("\nApplying compute manifests for %s. " % + (utils.get_controller_hostname())) + print("Node will reboot on completion.") sysinv.do_compute_config_complete(utils.get_controller_hostname()) @@ -1241,11 +1242,11 @@ def restore_complete(): else: if not os.path.isfile(restore_system_ready): - print textwrap.fill( + print(textwrap.fill( "--restore-complete can only be run " "after restore-system has completed " "successfully", 80 - ) + )) return False overwrite_iscsi_target_config() os.remove(restore_system_ready) @@ -1258,11 +1259,11 @@ def restore_system(backup_file, include_storage_reinstall=False, clone=False): if (os.path.exists(constants.CGCS_CONFIG_FILE) or os.path.exists(tsconfig.CONFIG_PATH) or os.path.exists(constants.INITIAL_CONFIG_COMPLETE_FILE)): - print textwrap.fill( + print(textwrap.fill( "Configuration has already been done. " "A system restore operation can only be done " - "immediately after the load has been installed.", 80) - print + "immediately after the load has been installed.", 80)) + print('') raise RestoreFail("System configuration already completed") if not os.path.isabs(backup_file): @@ -1288,7 +1289,7 @@ def restore_system(backup_file, include_storage_reinstall=False, clone=False): LOG.error("The cgts-vg volume group was not found") raise RestoreFail("Volume groups not configured") - print "\nRestoring system (this will take several minutes):" + print("\nRestoring system (this will take several minutes):") # Use /scratch for the staging dir for now, # until /opt/backups is available staging_dir = tempfile.mkdtemp(dir='/scratch') @@ -1343,10 +1344,10 @@ def restore_system(backup_file, include_storage_reinstall=False, clone=False): # If the controller was impacted by patches, we need to reboot. if os.path.isfile(node_is_patched): if not clone: - print ("\nThis controller has been patched. " + - "A reboot is required.") - print ("After the reboot is complete, " + - "re-execute the restore command.") + print("\nThis controller has been patched. " + + "A reboot is required.") + print("After the reboot is complete, " + + "re-execute the restore command.") while True: user_input = input( "Enter 'reboot' to reboot controller: ") @@ -1581,7 +1582,7 @@ def restore_system(backup_file, include_storage_reinstall=False, clone=False): if tsconfig.system_mode != sysinv_constants.SYSTEM_MODE_SIMPLEX: - print "\nRestoring node states (this will take several minutes):" + print("\nRestoring node states (this will take several minutes):") backend_services = sysinv.get_storage_backend_services() @@ -1621,7 +1622,7 @@ def restore_system(backup_file, include_storage_reinstall=False, clone=False): LOG.info("At least one node is not in a disabling state. " "Continuing.") - print "\nLocking nodes:" + print("\nLocking nodes:") try: failed_hosts = client.lock_hosts(skip_hosts, utils.progress, @@ -1635,7 +1636,7 @@ def restore_system(backup_file, include_storage_reinstall=False, clone=False): failed_lock_host = True if not failed_lock_host: - print "\nPowering-off nodes:" + print("\nPowering-off nodes:") try: client.power_off_hosts(skip_hosts, utils.progress, @@ -1646,25 +1647,25 @@ def restore_system(backup_file, include_storage_reinstall=False, clone=False): if failed_lock_host or len(skip_hosts) > skip_hosts_count: if include_storage_reinstall: - print textwrap.fill( + print(textwrap.fill( "Failed to lock at least one node. " + "Please lock the unlocked nodes manually.", 80 - ) + )) else: - print textwrap.fill( + print(textwrap.fill( "Failed to lock at least one node. " + "Please lock the unlocked controller-1 or " + "compute nodes manually.", 80 - ) + )) if not clone: - print textwrap.fill( + print(textwrap.fill( "Before continuing to the next step in the restore, " + "please ensure all nodes other than controller-0 " + "and storage nodes, if they are not being " + "reinstalled, are powered off. Please refer to the " + "system administration guide for more details.", 80 - ) + )) finally: os.remove(restore_in_progress) @@ -1705,11 +1706,11 @@ def restore_images(backup_file, clone=False): """Restoring images.""" if not os.path.exists(constants.INITIAL_CONFIG_COMPLETE_FILE): - print textwrap.fill( + print(textwrap.fill( "System restore has not been done. " "An image restore operation can only be done after " - "the system restore has been completed.", 80) - print + "the system restore has been completed.", 80)) + print('') raise RestoreFail("System restore required") if not os.path.isabs(backup_file): @@ -1725,7 +1726,7 @@ def restore_images(backup_file, clone=False): newline = clone try: - print "\nRestoring images (this will take several minutes):" + print("\nRestoring images (this will take several minutes):") os.chdir('/') step = 1 diff --git a/controllerconfig/controllerconfig/controllerconfig/clone.py b/controllerconfig/controllerconfig/controllerconfig/clone.py index 3416c76b3e..0c867003a4 100644 --- a/controllerconfig/controllerconfig/controllerconfig/clone.py +++ b/controllerconfig/controllerconfig/controllerconfig/clone.py @@ -9,6 +9,7 @@ Clone a Configured System and Install the image on another identical hardware or the same hardware. """ +from __future__ import print_function import os import re import glob @@ -116,11 +117,11 @@ def check_size(archive_dir): utils.filesystem_get_free_space(archive_dir) if clone_size > archive_dir_free_space: - print ("\nArchive directory (%s) does not have enough free " - "space (%s), estimated size to create image is %s." % - (archive_dir, - utils.print_bytes(archive_dir_free_space), - utils.print_bytes(clone_size))) + print("\nArchive directory (%s) does not have enough free " + "space (%s), estimated size to create image is %s." % + (archive_dir, + utils.print_bytes(archive_dir_free_space), + utils.print_bytes(clone_size))) raise CloneFail("Not enough free space.\n") @@ -475,7 +476,7 @@ def find_and_replace_in_file(target, find, replace): fpat = r'\b' + find + r'\b' line = re.sub(fpat, replace, line) found = True - print line, + print(line, end=' ') except Exception as e: LOG.error("Failed to replace [{}] with [{}] in [{}]: {}" diff --git a/controllerconfig/controllerconfig/controllerconfig/config_management.py b/controllerconfig/controllerconfig/controllerconfig/config_management.py index df6d157f8e..b76c7168b6 100644 --- a/controllerconfig/controllerconfig/controllerconfig/config_management.py +++ b/controllerconfig/controllerconfig/controllerconfig/config_management.py @@ -5,6 +5,7 @@ SPDX-License-Identifier: Apache-2.0 """ +from __future__ import print_function import json import netaddr import os @@ -20,19 +21,19 @@ from six.moves import input def is_valid_management_address(ip_address, management_subnet): """Determine whether a management address is valid.""" if ip_address == management_subnet.network: - print "Cannot use network address" + print("Cannot use network address") return False elif ip_address == management_subnet.broadcast: - print "Cannot use broadcast address" + print("Cannot use broadcast address") return False elif ip_address.is_multicast(): - print "Invalid address - multicast address not allowed" + print("Invalid address - multicast address not allowed") return False elif ip_address.is_loopback(): - print "Invalid address - loopback address not allowed" + print("Invalid address - loopback address not allowed") return False elif ip_address not in management_subnet: - print "Address must be in the management subnet" + print("Address must be in the management subnet") return False else: return True @@ -42,7 +43,7 @@ def configure_management(): interface_list = list() lldp_interface_list = list() - print "Enabling interfaces... ", + print("Enabling interfaces... ", end=' ') ip_link_output = subprocess.check_output(['ip', '-o', 'link']) for line in ip_link_output.splitlines(): @@ -50,43 +51,44 @@ def configure_management(): if interface != 'lo': interface_list.append(interface) subprocess.call(['ip', 'link', 'set', interface, 'up']) - print 'DONE' + print('DONE') wait_seconds = 120 delay_seconds = 5 - print "Waiting %d seconds for LLDP neighbor discovery" % wait_seconds, + print("Waiting %d seconds for LLDP neighbor discovery" % wait_seconds, + end=' ') while wait_seconds > 0: sys.stdout.write('.') sys.stdout.flush() time.sleep(delay_seconds) wait_seconds -= delay_seconds - print ' DONE' + print(' DONE') - print "Retrieving neighbor details... ", + print("Retrieving neighbor details... ", end=' ') lldpcli_show_output = subprocess.check_output( ['sudo', 'lldpcli', 'show', 'neighbors', 'summary', '-f', 'json']) lldp_interfaces = json.loads(lldpcli_show_output)['lldp'][0]['interface'] - print "DONE" + print("DONE") - print "\nAvailable interfaces:" - print "%-20s %s" % ("local interface", "remote port") - print "%-20s %s" % ("---------------", "-----------") + print("\nAvailable interfaces:") + print("%-20s %s" % ("local interface", "remote port")) + print("%-20s %s" % ("---------------", "-----------")) for interface in lldp_interfaces: - print "%-20s %s" % (interface['name'], - interface['port'][0]['id'][0]['value']) + print("%-20s %s" % (interface['name'], + interface['port'][0]['id'][0]['value'])) lldp_interface_list.append(interface['name']) for interface in interface_list: if interface not in lldp_interface_list: - print "%-20s %s" % (interface, 'unknown') + print("%-20s %s" % (interface, 'unknown')) - print + print('') while True: user_input = input("Enter management interface name: ") if user_input in interface_list: management_interface = user_input break else: - print "Invalid interface name" + print("Invalid interface name") continue while True: @@ -133,31 +135,31 @@ def configure_management(): user_input, min_addresses) break except cexeptions.ValidateFail as e: - print "{}".format(e) + print("{}".format(e)) - print "Disabling non-management interfaces... ", + print("Disabling non-management interfaces... ", end=' ') for interface in interface_list: if interface != management_interface: subprocess.call(['ip', 'link', 'set', interface, 'down']) - print 'DONE' + print('DONE') - print "Configuring management interface... ", + print("Configuring management interface... ", end=' ') subprocess.call(['ip', 'addr', 'add', str(management_cidr), 'dev', management_interface]) - print "DONE" + print("DONE") - print "Adding route to System Controller... ", + print("Adding route to System Controller... ", end=' ') subprocess.call(['ip', 'route', 'add', str(system_controller_subnet), 'dev', management_interface, 'via', str(management_gateway_address)]) - print "DONE" + print("DONE") def main(): if not os.geteuid() == 0: - print "%s must be run with root privileges" % sys.argv[0] + print("%s must be run with root privileges" % sys.argv[0]) exit(1) try: configure_management() except KeyboardInterrupt: - print "\nAborted" + print("\nAborted") diff --git a/controllerconfig/controllerconfig/controllerconfig/configassistant.py b/controllerconfig/controllerconfig/controllerconfig/configassistant.py index 7b9555775a..e309e893a0 100644 --- a/controllerconfig/controllerconfig/controllerconfig/configassistant.py +++ b/controllerconfig/controllerconfig/controllerconfig/configassistant.py @@ -72,7 +72,7 @@ def prompt_for(prompt_text, default_input, validator): valid = True if not valid: - print "Invalid choice" + print("Invalid choice") return user_input @@ -533,19 +533,19 @@ class ConfigAssistant(): def set_time(): """Allow user to set the system date and time.""" - print "System date and time:" - print "---------------------\n" - print textwrap.fill( - "The system date and time must be set now. Note that UTC " - "time must be used and that the date and time must be set as " - "accurately as possible, even if NTP/PTP is to be configured " - "later.", 80) - print + print("System date and time:") + print("---------------------\n") + print(textwrap.fill( + "The system date and time must be set now. Note that UTC " + "time must be used and that the date and time must be set as " + "accurately as possible, even if NTP/PTP is to be configured " + "later.", 80)) + print('') now = datetime.datetime.utcnow() date_format = '%Y-%m-%d %H:%M:%S' - print ("Current system date and time (UTC): " + - now.strftime(date_format)) + print("Current system date and time (UTC): " + + now.strftime(date_format)) while True: user_input = input( @@ -553,12 +553,12 @@ class ConfigAssistant(): if user_input.lower() == 'q': raise UserQuit elif user_input.lower() == 'y': - print "Current system date and time will be used." + print("Current system date and time will be used.") return elif user_input.lower() == 'n': break else: - print "Invalid choice" + print("Invalid choice") new_time = None while True: @@ -572,7 +572,7 @@ class ConfigAssistant(): date_format) break except ValueError: - print "Invalid date and time specified" + print("Invalid date and time specified") continue # Set the system clock @@ -594,13 +594,13 @@ class ConfigAssistant(): def set_timezone(self): """Allow user to set the system timezone.""" - print "\nSystem timezone:" - print "----------------\n" - print textwrap.fill( - "The system timezone must be set now. The timezone " - "must be a valid timezone from /usr/share/zoneinfo " - "(e.g. UTC, Asia/Hong_Kong, etc...)", 80) - print + print("\nSystem timezone:") + print("----------------\n") + print(textwrap.fill( + "The system timezone must be set now. The timezone " + "must be a valid timezone from /usr/share/zoneinfo " + "(e.g. UTC, Asia/Hong_Kong, etc...)", 80)) + print('') while True: user_input = input( @@ -612,7 +612,7 @@ class ConfigAssistant(): break else: if not os.path.isfile("/usr/share/zoneinfo/%s" % user_input): - print "Invalid timezone specified, please try again." + print("Invalid timezone specified, please try again.") continue self.timezone = user_input break @@ -648,18 +648,18 @@ class ConfigAssistant(): def input_system_mode_config(self): """Allow user to input system mode""" - print "\nSystem Configuration:" - print "---------------------\n" - print "System mode. Available options are:\n" - print textwrap.fill( - "1) duplex-direct - two node redundant configuration. " - "Management and infrastructure networks " - "are directly connected to peer ports", 80) - print textwrap.fill( - "2) duplex - two node redundant configuration. ", 80) + print("\nSystem Configuration:") + print("---------------------\n") + print("System mode. Available options are:\n") + print(textwrap.fill( + "1) duplex-direct - two node redundant configuration. " + "Management and infrastructure networks " + "are directly connected to peer ports", 80)) + print(textwrap.fill( + "2) duplex - two node redundant configuration. ", 80)) - print textwrap.fill( - "3) simplex - single node non-redundant configuration.", 80) + print(textwrap.fill( + "3) simplex - single node non-redundant configuration.", 80)) value_mapping = { "1": sysinv_constants.SYSTEM_MODE_DUPLEX_DIRECT, @@ -674,8 +674,8 @@ class ConfigAssistant(): def input_dc_selection(self): """Allow user to input dc role""" - print "\nDistributed Cloud Configuration:" - print "--------------------------------\n" + print("\nDistributed Cloud Configuration:") + print("--------------------------------\n") value_mapping = { "y": sysinv_constants.DISTRIBUTED_CLOUD_ROLE_SYSTEMCONTROLLER, @@ -691,12 +691,12 @@ class ConfigAssistant(): """Check basic storage config.""" if get_root_disk_size() < constants.MINIMUM_ROOT_DISK_SIZE: - print textwrap.fill( - "Warning: Root Disk %s size is less than %d GiB. " - "Please consult the Software Installation Guide " - "for details." % - (self.rootfs_node, constants.MINIMUM_ROOT_DISK_SIZE), 80) - print + print(textwrap.fill( + "Warning: Root Disk %s size is less than %d GiB. " + "Please consult the Software Installation Guide " + "for details." % + (self.rootfs_node, constants.MINIMUM_ROOT_DISK_SIZE), 80)) + print('') def is_interface_in_bond(self, interface_name): """ @@ -748,22 +748,22 @@ class ConfigAssistant(): def is_valid_pxeboot_address(self, ip_address): """Determine whether a pxeboot address is valid.""" if ip_address.version != 4: - print "Invalid IP version - only IPv4 supported" + print("Invalid IP version - only IPv4 supported") return False elif ip_address == self.pxeboot_subnet.network: - print "Cannot use network address" + print("Cannot use network address") return False elif ip_address == self.pxeboot_subnet.broadcast: - print "Cannot use broadcast address" + print("Cannot use broadcast address") return False elif ip_address.is_multicast(): - print "Invalid network address - multicast address not allowed" + print("Invalid network address - multicast address not allowed") return False elif ip_address.is_loopback(): - print "Invalid network address - loopback address not allowed" + print("Invalid network address - loopback address not allowed") return False elif ip_address not in self.pxeboot_subnet: - print "Address must be in the PXEBoot subnet" + print("Address must be in the PXEBoot subnet") return False else: return True @@ -784,22 +784,22 @@ class ConfigAssistant(): def input_pxeboot_config(self): """Allow user to input pxeboot config and perform validation.""" - print "\nPXEBoot Network:" - print "----------------\n" + print("\nPXEBoot Network:") + print("----------------\n") - print textwrap.fill( - "The PXEBoot network is used for initial booting and installation " - "of each node. IP addresses on this network are reachable only " - "within the data center.", 80) - print - print textwrap.fill( - "The default configuration combines the PXEBoot network and the " - "management network. If a separate PXEBoot network is used, it " - "will share the management interface, which requires the " - "management network to be placed on a VLAN.", 80) + print(textwrap.fill( + "The PXEBoot network is used for initial booting and installation" + " of each node. IP addresses on this network are reachable only " + "within the data center.", 80)) + print('') + print(textwrap.fill( + "The default configuration combines the PXEBoot network and the " + "management network. If a separate PXEBoot network is used, it " + "will share the management interface, which requires the " + "management network to be placed on a VLAN.", 80)) while True: - print + print('') user_input = input( "Configure a separate PXEBoot network [y/N]: ") if user_input.lower() == 'q': @@ -813,7 +813,7 @@ class ConfigAssistant(): elif user_input == "": break else: - print "Invalid choice" + print("Invalid choice") continue if self.separate_pxeboot_network: @@ -828,24 +828,24 @@ class ConfigAssistant(): try: ip_input = IPNetwork(user_input) if ip_input.version != 4: - print "Invalid IP version - only IPv4 supported" + print("Invalid IP version - only IPv4 supported") continue elif ip_input.ip != ip_input.network: - print "Invalid network address" + print("Invalid network address") continue elif ip_input.size < 16: - print "PXEBoot subnet too small " \ - + "- must have at least 16 addresses" + print("PXEBoot subnet too small " + "- must have at least 16 addresses") continue if ip_input.size < 255: - print "WARNING: Subnet allows only %d addresses." \ - % ip_input.size + print("WARNING: Subnet allows only %d addresses." + % ip_input.size) self.pxeboot_subnet = ip_input break except AddrFormatError: - print "Invalid subnet - please enter a valid IPv4 subnet" + print("Invalid subnet - please enter a valid IPv4 subnet") else: # Use private subnet for pxe booting self.pxeboot_subnet = self.private_pxeboot_subnet @@ -875,25 +875,25 @@ class ConfigAssistant(): def input_management_config(self): """Allow user to input management config and perform validation.""" - print "\nManagement Network:" - print "-------------------\n" + print("\nManagement Network:") + print("-------------------\n") - print textwrap.fill( + print(textwrap.fill( "The management network is used for internal communication " "between platform components. IP addresses on this network " - "are reachable only within the data center.", 80) + "are reachable only within the data center.", 80)) while True: - print - print textwrap.fill( + print('') + print(textwrap.fill( "A management bond interface provides redundant " - "connections for the management network.", 80) + "connections for the management network.", 80)) if self.system_mode == sysinv_constants.SYSTEM_MODE_DUPLEX_DIRECT: - print textwrap.fill( + print(textwrap.fill( "It is strongly recommended to configure Management " "interface link aggregation, for All-in-one duplex-direct." - ) - print + )) + print('') user_input = input( "Management interface link aggregation [y/N]: ") if user_input.lower() == 'q': @@ -907,7 +907,7 @@ class ConfigAssistant(): elif user_input == "": break else: - print "Invalid choice" + print("Invalid choice") continue while True: @@ -921,17 +921,17 @@ class ConfigAssistant(): elif user_input == "": user_input = self.management_interface elif self.lag_management_interface: - print textwrap.fill( - "Warning: The default name for the management bond " - "interface (%s) cannot be changed." % - self.management_interface, 80) - print + print(textwrap.fill( + "Warning: The default name for the management bond " + "interface (%s) cannot be changed." % + self.management_interface, 80)) + print('') user_input = self.management_interface if self.is_interface_in_bond(user_input): - print textwrap.fill( - "Interface is already configured as part of an " - "aggregated interface.", 80) + print(textwrap.fill( + "Interface is already configured as part of an " + "aggregated interface.", 80)) continue elif self.lag_management_interface: self.management_interface = user_input @@ -942,7 +942,7 @@ class ConfigAssistant(): self.management_interface_name = user_input break else: - print "Interface does not exist" + print("Interface does not exist") continue while True: @@ -957,7 +957,7 @@ class ConfigAssistant(): self.management_mtu = user_input break else: - print "MTU is invalid/unsupported" + print("MTU is invalid/unsupported") continue while True: @@ -973,18 +973,18 @@ class ConfigAssistant(): self.management_link_capacity = user_input break else: - print "Invalid choice, select from: %s" \ - % (', '.join(map(str, constants.VALID_LINK_SPEED_MGMT))) + print("Invalid choice, select from: %s" + % (', '.join(map(str, constants.VALID_LINK_SPEED_MGMT)))) continue while True: if not self.lag_management_interface: break - print - print "Specify one of the bonding policies. Possible values are:" - print " 1) 802.3ad (LACP) policy" - print " 2) Active-backup policy" + print('') + print("Specify one of the bonding policies. Possible values are:") + print(" 1) 802.3ad (LACP) policy") + print(" 2) Active-backup policy") user_input = input( "\nManagement interface bonding policy [" + @@ -1003,17 +1003,17 @@ class ConfigAssistant(): elif user_input == "": break else: - print "Invalid choice" + print("Invalid choice") continue while True: if not self.lag_management_interface: break - print textwrap.fill( - "A maximum of 2 physical interfaces can be attached to the " - "management interface.", 80) - print + print(textwrap.fill( + "A maximum of 2 physical interfaces can be attached to the " + "management interface.", 80)) + print('') user_input = input( "First management interface member [" + @@ -1024,17 +1024,17 @@ class ConfigAssistant(): user_input = self.lag_management_interface_member0 if self.is_interface_in_bond(user_input): - print textwrap.fill( + print(textwrap.fill( "Interface is already configured as part of an " - "aggregated interface.", 80) + "aggregated interface.", 80)) continue elif self.is_interface_in_use(user_input): - print "Interface is already in use" + print("Interface is already in use") continue elif interface_exists(user_input): self.lag_management_interface_member0 = user_input else: - print "Interface does not exist" + print("Interface does not exist") self.lag_management_interface_member0 = "" continue @@ -1044,24 +1044,24 @@ class ConfigAssistant(): if user_input.lower() == 'q': raise UserQuit elif user_input == self.lag_management_interface_member0: - print "Cannot use member 0 as member 1" + print("Cannot use member 0 as member 1") continue elif user_input == "": user_input = self.lag_management_interface_member1 if self.is_interface_in_bond(user_input): - print textwrap.fill( + print(textwrap.fill( "Interface is already configured as part of an " - "aggregated interface.", 80) + "aggregated interface.", 80)) continue elif self.is_interface_in_use(user_input): - print "Interface is already in use" + print("Interface is already in use") continue elif interface_exists(user_input): self.lag_management_interface_member1 = user_input break else: - print "Interface does not exist" + print("Interface does not exist") self.lag_management_interface_member1 = "" user_input = input( "Do you want a single physical member in the bond " @@ -1074,11 +1074,11 @@ class ConfigAssistant(): continue if self.separate_pxeboot_network: - print - print textwrap.fill( + print('') + print(textwrap.fill( "A management VLAN is required because a separate PXEBoot " - "network was configured on the management interface.", 80) - print + "network was configured on the management interface.", 80)) + print('') while True: user_input = input( @@ -1092,7 +1092,7 @@ class ConfigAssistant(): self.management_interface + '.' + self.management_vlan break else: - print "VLAN is invalid/unsupported" + print("VLAN is invalid/unsupported") continue min_addresses = 8 @@ -1109,16 +1109,16 @@ class ConfigAssistant(): min_addresses) if (tmp_management_subnet.version == 6 and not self.separate_pxeboot_network): - print ("Using IPv6 management network requires " + - "use of separate PXEBoot network") + print("Using IPv6 management network requires " + + "use of separate PXEBoot network") continue self.management_subnet = tmp_management_subnet self.management_start_address = self.management_subnet[2] self.management_end_address = self.management_subnet[-2] if self.management_subnet.size < 255: - print "WARNING: Subnet allows only %d addresses.\n" \ - "This will not allow you to provision a Cinder LVM" \ - " or Ceph backend." % self.management_subnet.size + print("WARNING: Subnet allows only %d addresses.\n" + "This will not allow you to provision a Cinder LVM" + " or Ceph backend." % self.management_subnet.size) while True: user_input = raw_input( "Do you want to continue with the current " @@ -1129,11 +1129,11 @@ class ConfigAssistant(): elif user_input.lower() == 'y' or user_input == "": break else: - print "Invalid choice" + print("Invalid choice") continue break except ValidateFail as e: - print "{}".format(e) + print("{}".format(e)) if (self.system_dc_role != sysinv_constants.DISTRIBUTED_CLOUD_ROLE_SYSTEMCONTROLLER): @@ -1151,15 +1151,15 @@ class ConfigAssistant(): elif user_input == "": break else: - print "Invalid choice" + print("Invalid choice") continue else: self.use_entire_mgmt_subnet = False - print textwrap.fill( + print(textwrap.fill( "Configured as Distributed Cloud System Controller," " disallowing use of entire management subnet. " "Ensure management ip range does not include System" - " Controller gateway address(es)", 80) + " Controller gateway address(es)", 80)) if not self.use_entire_mgmt_subnet: while True: @@ -1179,7 +1179,7 @@ class ConfigAssistant(): user_input, self.management_subnet) break except ValidateFail as e: - print ("Invalid start address. \n Reason: %s" % e) + print("Invalid start address. \n Reason: %s" % e) while True: user_input = input( @@ -1195,19 +1195,19 @@ class ConfigAssistant(): user_input, self.management_subnet) break except ValidateFail as e: - print ("Invalid management end address. \n" - "Reason: %s" % e) + print("Invalid management end address. \n" + "Reason: %s" % e) if not self.management_start_address < \ self.management_end_address: - print "Start address not less than end address. " - print + print("Start address not less than end address. ") + print('') continue address_range = IPRange(str(self.management_start_address), str(self.management_end_address)) if not address_range.size >= min_addresses: - print ( + print( "Address range must contain at least %d addresses. " % min_addresses) continue @@ -1219,23 +1219,23 @@ class ConfigAssistant(): # used to communicate with the subclouds. - 2 because of # subnet and broadcast addresses. if address_range.size >= (self.management_subnet.size - 2): - print textwrap.fill( + print(textwrap.fill( "Address range too large, no addresses left " - "for System Controller gateway(s). ", 80) + "for System Controller gateway(s). ", 80)) continue break while True: - print - print textwrap.fill( + print('') + print(textwrap.fill( "IP addresses can be assigned to hosts dynamically or " "a static IP address can be specified for each host. " "This choice applies to both the management network " - "and infrastructure network (if configured). ", 80) - print textwrap.fill( + "and infrastructure network (if configured). ", 80)) + print(textwrap.fill( "Warning: Selecting 'N', or static IP address allocation, " "disables automatic provisioning of new hosts in System " "Inventory, requiring the user to manually provision using " - "the 'system host-add' command. ", 80) + "the 'system host-add' command. ", 80)) user_input = input( "Dynamic IP address allocation [Y/n]: ") if user_input.lower() == 'q': @@ -1249,7 +1249,7 @@ class ConfigAssistant(): elif user_input == "": break else: - print "Invalid choice" + print("Invalid choice") continue default_controller0_mgmt_float_ip = self.management_start_address @@ -1317,9 +1317,9 @@ class ConfigAssistant(): self.management_multicast_subnet = ip_input break except AddrFormatError: - print ("Invalid subnet - " - "please enter a valid IPv4 or IPv6 subnet" - ) + print("Invalid subnet - " + "please enter a valid IPv4 or IPv6 subnet" + ) """ Management interface configuration complete""" self.management_interface_configured = True @@ -1331,14 +1331,14 @@ class ConfigAssistant(): if management_subnet is not None: self.management_subnet = management_subnet else: - print "\nManagement Network:" - print "-------------------\n" + print("\nManagement Network:") + print("-------------------\n") - print textwrap.fill( + print(textwrap.fill( "The management network is used for internal communication " "between platform components. IP addresses on this network " - "are reachable only within the host.", 80) - print + "are reachable only within the host.", 80)) + print('') self.management_subnet = IPNetwork( constants.DEFAULT_MGMT_ON_LOOPBACK_SUBNET_IPV4) @@ -1355,13 +1355,13 @@ class ConfigAssistant(): tmp_management_subnet = validate_network_str(user_input, min_addresses) if tmp_management_subnet.version == 6: - print ("IPv6 management network not supported on " + - "simplex configuration") + print("IPv6 management network not supported on " + + "simplex configuration") continue self.management_subnet = tmp_management_subnet break except ValidateFail as e: - print "{}".format(e) + print("{}".format(e)) self.management_interface = constants.LOOPBACK_IFNAME self.management_interface_name = constants.LOOPBACK_IFNAME @@ -1381,19 +1381,19 @@ class ConfigAssistant(): def is_valid_infrastructure_address(self, ip_address): """Determine whether an infrastructure address is valid.""" if ip_address == self.infrastructure_subnet.network: - print "Cannot use network address" + print("Cannot use network address") return False elif ip_address == self.infrastructure_subnet.broadcast: - print "Cannot use broadcast address" + print("Cannot use broadcast address") return False elif ip_address.is_multicast(): - print "Invalid network address - multicast address not allowed" + print("Invalid network address - multicast address not allowed") return False elif ip_address.is_loopback(): - print "Invalid network address - loopback address not allowed" + print("Invalid network address - loopback address not allowed") return False elif ip_address not in self.infrastructure_subnet: - print "Address must be in the infrastructure subnet" + print("Address must be in the infrastructure subnet") return False else: return True @@ -1401,26 +1401,26 @@ class ConfigAssistant(): def input_infrastructure_config(self): """Allow user to input infrastructure config and perform validation.""" - print "\nInfrastructure Network:" - print "-----------------------\n" + print("\nInfrastructure Network:") + print("-----------------------\n") - print textwrap.fill( + print(textwrap.fill( "The infrastructure network is used for internal communication " "between platform components to offload the management network " "of high bandwidth services. " "IP addresses on this network are reachable only within the data " - "center.", 80) - print - print textwrap.fill( + "center.", 80)) + print('') + print(textwrap.fill( "If a separate infrastructure interface is not configured the " - "management network will be used.", 80) - print + "management network will be used.", 80)) + print('') if self.system_mode == sysinv_constants.SYSTEM_MODE_DUPLEX_DIRECT: - print textwrap.fill( + print(textwrap.fill( "It is NOT recommended to configure infrastructure network " "for All-in-one duplex-direct." - ) + )) infra_vlan_required = False @@ -1435,15 +1435,15 @@ class ConfigAssistant(): self.infrastructure_interface = "" return else: - print "Invalid choice" + print("Invalid choice") continue while True: - print - print textwrap.fill( + print('') + print(textwrap.fill( "An infrastructure bond interface provides redundant " - "connections for the infrastructure network.", 80) - print + "connections for the infrastructure network.", 80)) + print('') user_input = input( "Infrastructure interface link aggregation [y/N]: ") if user_input.lower() == 'q': @@ -1455,7 +1455,7 @@ class ConfigAssistant(): self.lag_infrastructure_interface = False break else: - print "Invalid choice" + print("Invalid choice") continue while True: @@ -1469,20 +1469,20 @@ class ConfigAssistant(): elif user_input == '': user_input = self.infrastructure_interface if user_input == '': - print "Invalid interface" + print("Invalid interface") continue elif self.lag_infrastructure_interface: - print textwrap.fill( + print(textwrap.fill( "Warning: The default name for the infrastructure bond " "interface (%s) cannot be changed." % - self.infrastructure_interface, 80) - print + self.infrastructure_interface, 80)) + print('') user_input = self.infrastructure_interface if self.is_interface_in_bond(user_input): - print textwrap.fill( + print(textwrap.fill( "Interface is already configured as part of an " - "aggregated interface.", 80) + "aggregated interface.", 80)) continue elif self.lag_infrastructure_interface: self.infrastructure_interface = user_input @@ -1499,7 +1499,7 @@ class ConfigAssistant(): infra_vlan_required = True break else: - print "Interface does not exist" + print("Interface does not exist") continue while True: @@ -1516,10 +1516,10 @@ class ConfigAssistant(): raise UserQuit elif is_valid_vlan(user_input): if user_input == self.management_vlan: - print textwrap.fill( + print(textwrap.fill( "Invalid VLAN Identifier. Configured VLAN " "Identifier is already in use by another " - "network.", 80) + "network.", 80)) continue self.infrastructure_vlan = user_input self.infrastructure_interface_name = \ @@ -1527,21 +1527,21 @@ class ConfigAssistant(): self.infrastructure_vlan break else: - print "VLAN is invalid/unsupported" + print("VLAN is invalid/unsupported") continue break elif user_input.lower() in ('n', ''): if infra_vlan_required: - print textwrap.fill( + print(textwrap.fill( "An infrastructure VLAN is required since the " "configured infrastructure interface is the " "same as the configured management or external " - "OAM interface.", 80) + "OAM interface.", 80)) continue self.infrastructure_vlan = "" break else: - print "Invalid choice" + print("Invalid choice") continue while True: @@ -1557,14 +1557,14 @@ class ConfigAssistant(): self.management_interface and self.infrastructure_vlan and user_input > self.management_mtu): - print ("Infrastructure VLAN MTU must not be larger than " - "underlying management interface MTU") + print("Infrastructure VLAN MTU must not be larger than " + "underlying management interface MTU") continue elif is_mtu_valid(user_input): self.infrastructure_mtu = user_input break else: - print "MTU is invalid/unsupported" + print("MTU is invalid/unsupported") continue while True: @@ -1580,18 +1580,18 @@ class ConfigAssistant(): self.infrastructure_link_capacity = user_input break else: - print "Invalid choice, select from: %s" \ - % (', '.join(map(str, constants.VALID_LINK_SPEED_INFRA))) + print("Invalid choice, select from: %s" % + (', '.join(map(str, constants.VALID_LINK_SPEED_INFRA)))) continue while True: if not self.lag_infrastructure_interface: break - print - print "Specify one of the bonding policies. Possible values are:" - print " 1) Active-backup policy" - print " 2) Balanced XOR policy" - print " 3) 802.3ad (LACP) policy" + print('') + print("Specify one of the bonding policies. Possible values are:") + print(" 1) Active-backup policy") + print(" 2) Balanced XOR policy") + print(" 3) 802.3ad (LACP) policy") user_input = input( "\nInfrastructure interface bonding policy [" + @@ -1618,17 +1618,17 @@ class ConfigAssistant(): elif user_input == "": break else: - print "Invalid choice" + print("Invalid choice") continue while True: if not self.lag_infrastructure_interface: break - print textwrap.fill( + print(textwrap.fill( "A maximum of 2 physical interfaces can be attached to the " - "infrastructure interface.", 80) - print + "infrastructure interface.", 80)) + print('') user_input = input( "First infrastructure interface member [" + @@ -1639,17 +1639,17 @@ class ConfigAssistant(): user_input = self.lag_infrastructure_interface_member0 if self.is_interface_in_bond(user_input): - print textwrap.fill( + print(textwrap.fill( "Interface is already configured as part of an " - "aggregated interface.", 80) + "aggregated interface.", 80)) continue elif self.is_interface_in_use(user_input): - print "Interface is already in use" + print("Interface is already in use") continue elif interface_exists(user_input): self.lag_infrastructure_interface_member0 = user_input else: - print "Interface does not exist" + print("Interface does not exist") self.lag_infrastructure_interface_member0 = "" continue @@ -1662,22 +1662,22 @@ class ConfigAssistant(): user_input = self.lag_infrastructure_interface_member1 if self.is_interface_in_bond(user_input): - print textwrap.fill( + print(textwrap.fill( "Interface is already configured as part of an " - "aggregated interface.", 80) + "aggregated interface.", 80)) continue elif self.is_interface_in_use(user_input): - print "Interface is already in use" + print("Interface is already in use") continue elif interface_exists(user_input): if user_input == self.lag_infrastructure_interface_member0: - print "Cannot use member 0 as member 1" + print("Cannot use member 0 as member 1") continue else: self.lag_infrastructure_interface_member1 = user_input break else: - print "Interface does not exist" + print("Interface does not exist") self.lag_infrastructure_interface_member1 = "" user_input = input( "Do you want a single physical member in the bond " @@ -1689,7 +1689,7 @@ class ConfigAssistant(): elif user_input.lower() in ('n', ''): continue else: - print "Invalid choice" + print("Invalid choice") continue min_addresses = 8 @@ -1704,33 +1704,33 @@ class ConfigAssistant(): try: ip_input = IPNetwork(user_input) if ip_input.ip != ip_input.network: - print "Invalid network address" + print("Invalid network address") continue elif ip_input.version != self.management_subnet.version: - print "IP version must match management network" + print("IP version must match management network") continue elif ip_input.size < min_addresses: - print ("Infrastructure subnet too small - " - "must have at least 16 addresses") + print("Infrastructure subnet too small - " + "must have at least 16 addresses") continue elif ip_input.version == 6 and ip_input.prefixlen < 64: - print ("IPv6 minimum prefix length is 64") + print("IPv6 minimum prefix length is 64") continue elif ((self.separate_pxeboot_network and ip_input.ip in self.pxeboot_subnet) or ip_input.ip in self.management_subnet): - print ("Infrastructure subnet overlaps with an already " - "configured subnet") + print("Infrastructure subnet overlaps with an already " + "configured subnet") continue if ip_input.size < 255: - print "WARNING: Subnet allows only %d addresses." \ - % ip_input.size + print("WARNING: Subnet allows only %d addresses." + % ip_input.size) self.infrastructure_subnet = ip_input break except AddrFormatError: - print "Invalid subnet - please enter a valid IPv4 subnet" + print("Invalid subnet - please enter a valid IPv4 subnet") self.infrastructure_start_address = \ self.infrastructure_subnet[2] @@ -1750,7 +1750,7 @@ class ConfigAssistant(): elif user_input == "": break else: - print "Invalid choice" + print("Invalid choice") continue if not self.use_entire_infra_subnet: @@ -1770,7 +1770,7 @@ class ConfigAssistant(): user_input, self.infrastructure_subnet) break except ValidateFail as e: - print ("Invalid start address. \n Reason: %s" % e) + print("Invalid start address. \n Reason: %s" % e) while True: user_input = input( @@ -1786,19 +1786,19 @@ class ConfigAssistant(): user_input, self.infrastructure_subnet) break except ValidateFail as e: - print ("Invalid infrastructure end address. \n" - "Reason: %s" % e) + print("Invalid infrastructure end address. \n" + "Reason: %s" % e) if not self.infrastructure_start_address < \ self.infrastructure_end_address: - print "Start address not less than end address. " - print + print("Start address not less than end address. ") + print('') continue address_range = IPRange(str(self.infrastructure_start_address), str(self.infrastructure_end_address)) if not address_range.size >= min_addresses: - print ( + print( "Address range must contain at least %d addresses. " % min_addresses) continue @@ -1831,27 +1831,27 @@ class ConfigAssistant(): def is_valid_external_oam_subnet(self, ip_subnet): """Determine whether an OAM subnet is valid.""" if ip_subnet.size < 8: - print "Subnet too small - must have at least 8 addresses" + print("Subnet too small - must have at least 8 addresses") return False elif ip_subnet.ip != ip_subnet.network: - print "Invalid network address" + print("Invalid network address") return False elif ip_subnet.version == 6 and ip_subnet.prefixlen < 64: - print ("IPv6 minimum prefix length is 64") + print("IPv6 minimum prefix length is 64") return False elif ip_subnet.is_multicast(): - print "Invalid network address - multicast address not allowed" + print("Invalid network address - multicast address not allowed") return False elif ip_subnet.is_loopback(): - print "Invalid network address - loopback address not allowed" + print("Invalid network address - loopback address not allowed") return False elif ((self.separate_pxeboot_network and ip_subnet.ip in self.pxeboot_subnet) or (ip_subnet.ip in self.management_subnet) or (self.infrastructure_interface and ip_subnet.ip in self.infrastructure_subnet)): - print ("External OAM subnet overlaps with an already " - "configured subnet") + print("External OAM subnet overlaps with an already " + "configured subnet") return False else: return True @@ -1859,19 +1859,19 @@ class ConfigAssistant(): def is_valid_external_oam_address(self, ip_address): """Determine whether an OAM address is valid.""" if ip_address == self.external_oam_subnet.network: - print "Cannot use network address" + print("Cannot use network address") return False elif ip_address == self.external_oam_subnet.broadcast: - print "Cannot use broadcast address" + print("Cannot use broadcast address") return False elif ip_address.is_multicast(): - print "Invalid network address - multicast address not allowed" + print("Invalid network address - multicast address not allowed") return False elif ip_address.is_loopback(): - print "Invalid network address - loopback address not allowed" + print("Invalid network address - loopback address not allowed") return False elif ip_address not in self.external_oam_subnet: - print "Address must be in the external OAM subnet" + print("Address must be in the external OAM subnet") return False else: return True @@ -1896,10 +1896,10 @@ class ConfigAssistant(): self.external_oam_address_1 = ip_input break except (AddrFormatError, ValueError): - print ("Invalid address - " - "please enter a valid %s address" % - ip_version_to_string(self.external_oam_subnet.version) - ) + print("Invalid address - " + "please enter a valid %s address" % + ip_version_to_string(self.external_oam_subnet.version) + ) def input_oam_ip_address(self): """Allow user to input external OAM IP and perform validation.""" @@ -1919,10 +1919,10 @@ class ConfigAssistant(): self.external_oam_floating_address = ip_input break except (AddrFormatError, ValueError): - print ("Invalid address - " - "please enter a valid %s address" % - ip_version_to_string(self.external_oam_subnet.version) - ) + print("Invalid address - " + "please enter a valid %s address" % + ip_version_to_string(self.external_oam_subnet.version) + ) while True: user_input = input("External OAM address for first " @@ -1941,10 +1941,10 @@ class ConfigAssistant(): self.external_oam_address_0 = ip_input break except (AddrFormatError, ValueError): - print ("Invalid address - " - "please enter a valid %s address" % - ip_version_to_string(self.external_oam_subnet.version) - ) + print("Invalid address - " + "please enter a valid %s address" % + ip_version_to_string(self.external_oam_subnet.version) + ) while True: user_input = input("External OAM address for second " @@ -1963,30 +1963,30 @@ class ConfigAssistant(): self.external_oam_address_1 = ip_input break except (AddrFormatError, ValueError): - print ("Invalid address - " - "please enter a valid %s address" % - ip_version_to_string(self.external_oam_subnet.version) - ) + print("Invalid address - " + "please enter a valid %s address" % + ip_version_to_string(self.external_oam_subnet.version) + ) def input_external_oam_config(self): """Allow user to input external OAM config and perform validation.""" - print "\nExternal OAM Network:" - print "---------------------\n" - print textwrap.fill( - "The external OAM network is used for management of the " - "cloud. It also provides access to the " - "platform APIs. IP addresses on this network are reachable " - "outside the data center.", 80) - print + print("\nExternal OAM Network:") + print("---------------------\n") + print(textwrap.fill( + "The external OAM network is used for management of the " + "cloud. It also provides access to the " + "platform APIs. IP addresses on this network are reachable " + "outside the data center.", 80)) + print('') ext_oam_vlan_required = False while True: - print textwrap.fill( + print(textwrap.fill( "An external OAM bond interface provides redundant " - "connections for the OAM network.", 80) - print + "connections for the OAM network.", 80)) + print('') user_input = input( "External OAM interface link aggregation [y/N]: ") if user_input.lower() == 'q': @@ -2000,7 +2000,7 @@ class ConfigAssistant(): elif user_input == "": break else: - print "Invalid choice" + print("Invalid choice") continue while True: @@ -2014,17 +2014,17 @@ class ConfigAssistant(): elif user_input == "": user_input = self.external_oam_interface elif self.lag_external_oam_interface: - print textwrap.fill( + print(textwrap.fill( "Warning: The default name for the external OAM bond " "interface (%s) cannot be changed." % - self.external_oam_interface, 80) - print + self.external_oam_interface, 80)) + print('') user_input = self.external_oam_interface if self.is_interface_in_bond(user_input): - print textwrap.fill( + print(textwrap.fill( "Interface is already configured as part of an " - "aggregated interface.", 80) + "aggregated interface.", 80)) continue elif self.lag_external_oam_interface: self.external_oam_interface = user_input @@ -2043,7 +2043,7 @@ class ConfigAssistant(): ext_oam_vlan_required = True break else: - print "Interface does not exist" + print("Interface does not exist") continue while True: @@ -2061,10 +2061,10 @@ class ConfigAssistant(): elif is_valid_vlan(user_input): if ((user_input == self.management_vlan) or (user_input == self.infrastructure_vlan)): - print textwrap.fill( + print(textwrap.fill( "Invalid VLAN Identifier. Configured VLAN " "Identifier is already in use by another " - "network.", 80) + "network.", 80)) continue self.external_oam_vlan = user_input self.external_oam_interface_name = \ @@ -2072,21 +2072,21 @@ class ConfigAssistant(): self.external_oam_vlan break else: - print "VLAN is invalid/unsupported" + print("VLAN is invalid/unsupported") continue break elif user_input.lower() in ('n', ''): if ext_oam_vlan_required: - print textwrap.fill( + print(textwrap.fill( "An external oam VLAN is required since the " "configured external oam interface is the " "same as either the configured management " - "or infrastructure interface.", 80) + "or infrastructure interface.", 80)) continue self.external_oam_vlan = "" break else: - print "Invalid choice" + print("Invalid choice") continue while True: @@ -2102,16 +2102,16 @@ class ConfigAssistant(): self.management_interface and self.external_oam_vlan and user_input > self.management_mtu): - print ("External OAM VLAN MTU must not be larger than " - "underlying management interface MTU") + print("External OAM VLAN MTU must not be larger than " + "underlying management interface MTU") continue elif (self.infrastructure_interface_configured and self.external_oam_interface == self.infrastructure_interface and self.external_oam_vlan and user_input > self.infrastructure_mtu): - print ("External OAM VLAN MTU must not be larger than " - "underlying infrastructure interface MTU") + print("External OAM VLAN MTU must not be larger than " + "underlying infrastructure interface MTU") continue elif (self.infrastructure_interface_configured and self.external_oam_interface == @@ -2119,25 +2119,25 @@ class ConfigAssistant(): self.infrastructure_vlan and not self.external_oam_vlan and user_input < self.infrastructure_mtu): - print ("External OAM interface MTU must not be smaller than " - "infrastructure VLAN interface MTU") + print("External OAM interface MTU must not be smaller than " + "infrastructure VLAN interface MTU") continue elif is_mtu_valid(user_input): self.external_oam_mtu = user_input break else: - print "MTU is invalid/unsupported" + print("MTU is invalid/unsupported") continue while True: if not self.lag_external_oam_interface: break - print - print "Specify one of the bonding policies. Possible values are:" - print " 1) Active-backup policy" - print " 2) Balanced XOR policy" - print " 3) 802.3ad (LACP) policy" + print('') + print("Specify one of the bonding policies. Possible values are:") + print(" 1) Active-backup policy") + print(" 2) Balanced XOR policy") + print(" 3) 802.3ad (LACP) policy") user_input = input( "\nExternal OAM interface bonding policy [" + @@ -2163,17 +2163,17 @@ class ConfigAssistant(): elif user_input == "": break else: - print "Invalid choice" + print("Invalid choice") continue while True: if not self.lag_external_oam_interface: break - print textwrap.fill( + print(textwrap.fill( "A maximum of 2 physical interfaces can be attached to the " - "external OAM interface.", 80) - print + "external OAM interface.", 80)) + print('') user_input = input( "First external OAM interface member [" + @@ -2184,17 +2184,17 @@ class ConfigAssistant(): user_input = self.lag_external_oam_interface_member0 if self.is_interface_in_bond(user_input): - print textwrap.fill( + print(textwrap.fill( "Interface is already configured as part of an " - "aggregated interface.", 80) + "aggregated interface.", 80)) continue elif self.is_interface_in_use(user_input): - print "Interface is already in use" + print("Interface is already in use") continue elif interface_exists(user_input): self.lag_external_oam_interface_member0 = user_input else: - print "Interface does not exist" + print("Interface does not exist") self.lag_external_oam_interface_member0 = "" continue @@ -2207,21 +2207,21 @@ class ConfigAssistant(): user_input = self.lag_external_oam_interface_member1 if self.is_interface_in_bond(user_input): - print textwrap.fill( + print(textwrap.fill( "Interface is already configured as part of an " - "aggregated interface.", 80) + "aggregated interface.", 80)) continue elif self.is_interface_in_use(user_input): - print "Interface is already in use" + print("Interface is already in use") continue elif user_input == self.lag_external_oam_interface_member0: - print "Cannot use member 0 as member 1" + print("Cannot use member 0 as member 1") continue if interface_exists(user_input): self.lag_external_oam_interface_member1 = user_input break else: - print "Interface does not exist" + print("Interface does not exist") self.lag_external_oam_interface_member1 = "" user_input = input( "Do you want a single physical member in the bond " @@ -2248,9 +2248,9 @@ class ConfigAssistant(): self.external_oam_subnet = ip_input break except AddrFormatError: - print ("Invalid subnet - " - "please enter a valid IPv4 or IPv6 subnet" - ) + print("Invalid subnet - " + "please enter a valid IPv4 or IPv6 subnet" + ) while True: user_input = input("External OAM gateway address [" + @@ -2267,10 +2267,10 @@ class ConfigAssistant(): self.external_oam_gateway_address = ip_input break except (AddrFormatError, ValueError): - print ("Invalid address - " - "please enter a valid %s address" % - ip_version_to_string(self.external_oam_subnet.version) - ) + print("Invalid address - " + "please enter a valid %s address" % + ip_version_to_string(self.external_oam_subnet.version) + ) if self.system_mode == sysinv_constants.SYSTEM_MODE_SIMPLEX: self.input_aio_simplex_oam_ip_address() @@ -2284,12 +2284,12 @@ class ConfigAssistant(): """Allow user to input authentication config and perform validation. """ - print "\nCloud Authentication:" - print "-------------------------------\n" - print textwrap.fill( + print("\nCloud Authentication:") + print("-------------------------------\n") + print(textwrap.fill( "Configure a password for the Cloud admin user " "The Password must have a minimum length of 7 character, " - "and conform to password complexity rules", 80) + "and conform to password complexity rules", 80)) password_input = "" while True: @@ -2299,7 +2299,7 @@ class ConfigAssistant(): password_input = user_input if len(password_input) < 1: - print "Password cannot be empty" + print("Password cannot be empty") continue user_input = getpass.getpass("Repeat admin user password: ") @@ -2307,10 +2307,10 @@ class ConfigAssistant(): raise UserQuit if user_input != password_input: - print "Password did not match" + print("Password did not match") continue else: - print "\n" + print("\n") self.admin_password = user_input # the admin password will be validated self.add_password_for_validation('ADMIN_PASSWORD', @@ -2332,9 +2332,9 @@ class ConfigAssistant(): def input_config(self): """Allow user to input configuration.""" - print "System Configuration" - print "====================" - print "Enter Q at any prompt to abort...\n" + print("System Configuration") + print("====================") + print("Enter Q at any prompt to abort...\n") self.set_time() self.set_timezone(self) @@ -2365,21 +2365,21 @@ class ConfigAssistant(): # The multicast subnet must belong to the same Address Family # as the management network if ip_subnet.version != self.management_subnet.version: - print textwrap.fill( + print(textwrap.fill( "Invalid network address - Management Multicast Subnet and " - " Network IP Families must be the same.", 80) + " Network IP Families must be the same.", 80)) return False elif ip_subnet.size < 16: - print "Subnet too small - must have at least 16 addresses" + print("Subnet too small - must have at least 16 addresses") return False elif ip_subnet.ip != ip_subnet.network: - print "Invalid network address" + print("Invalid network address") return False elif ip_subnet.version == 6 and ip_subnet.prefixlen < 64: - print ("IPv6 minimum prefix length is 64") + print("IPv6 minimum prefix length is 64") return False elif not ip_subnet.is_multicast(): - print "Invalid network address - must be multicast" + print("Invalid network address - must be multicast") return False else: return True @@ -2391,7 +2391,7 @@ class ConfigAssistant(): that translates region config to this format in regionconfig.py. """ if not os.path.isfile(configfile): - print "Specified answer or config file not found" + print("Specified answer or config file not found") raise ConfigFail("Answer or Config file not found") config = configparser.RawConfigParser() @@ -2678,7 +2678,7 @@ class ConfigAssistant(): 'cAUTHENTICATION', 'ADMIN_PASSWORD') if self.admin_password == "" and not restore: - print "Admin password must be set in answer file" + print("Admin password must be set in answer file") raise ConfigFail("Admin password not set in answer file") # the admin password will be validated self.add_password_for_validation('ADMIN_PASSWORD', @@ -2923,205 +2923,207 @@ class ConfigAssistant(): "no longer supported") except Exception: - print "Error parsing answer file" + print("Error parsing answer file") raise return config_sections def display_config(self): """Display configuration that will be applied.""" - print "\nThe following configuration will be applied:" + print("\nThe following configuration will be applied:") - print "\nSystem Configuration" - print "--------------------" - print "Time Zone: " + str(self.timezone) - print "System mode: %s" % self.system_mode + print("\nSystem Configuration") + print("--------------------") + print("Time Zone: " + str(self.timezone)) + print("System mode: %s" % self.system_mode) if self.system_type != sysinv_constants.TIS_AIO_BUILD: dc_role_true = "no" if (self.system_dc_role == sysinv_constants.DISTRIBUTED_CLOUD_ROLE_SYSTEMCONTROLLER): dc_role_true = "yes" - print "Distributed Cloud System Controller: %s" % dc_role_true + print("Distributed Cloud System Controller: %s" % dc_role_true) - print "\nPXEBoot Network Configuration" - print "-----------------------------" + print("\nPXEBoot Network Configuration") + print("-----------------------------") if not self.separate_pxeboot_network: - print "Separate PXEBoot network not configured" + print("Separate PXEBoot network not configured") else: - print "PXEBoot subnet: " + str(self.pxeboot_subnet.cidr) - print ("PXEBoot floating address: " + - str(self.controller_pxeboot_floating_address)) - print ("Controller 0 PXEBoot address: " + - str(self.controller_pxeboot_address_0)) - print ("Controller 1 PXEBoot address: " + - str(self.controller_pxeboot_address_1)) - print ("PXEBoot Controller floating hostname: " + - str(self.pxecontroller_floating_hostname)) + print("PXEBoot subnet: " + str(self.pxeboot_subnet.cidr)) + print("PXEBoot floating address: " + + str(self.controller_pxeboot_floating_address)) + print("Controller 0 PXEBoot address: " + + str(self.controller_pxeboot_address_0)) + print("Controller 1 PXEBoot address: " + + str(self.controller_pxeboot_address_1)) + print("PXEBoot Controller floating hostname: " + + str(self.pxecontroller_floating_hostname)) - print "\nManagement Network Configuration" - print "--------------------------------" - print "Management interface name: " + self.management_interface_name - print "Management interface: " + self.management_interface + print("\nManagement Network Configuration") + print("--------------------------------") + print("Management interface name: " + self.management_interface_name) + print("Management interface: " + self.management_interface) if self.management_vlan: - print "Management vlan: " + self.management_vlan - print "Management interface MTU: " + self.management_mtu - print ("Management interface link capacity Mbps: " + - str(self.management_link_capacity)) + print("Management vlan: " + self.management_vlan) + print("Management interface MTU: " + self.management_mtu) + print("Management interface link capacity Mbps: " + + str(self.management_link_capacity)) if self.lag_management_interface: - print ("Management ae member 0: " + - self.lag_management_interface_member0) - print ("Management ae member 1: " + - self.lag_management_interface_member1) - print ("Management ae policy : " + - self.lag_management_interface_policy) - print "Management subnet: " + str(self.management_subnet.cidr) + print("Management ae member 0: " + + self.lag_management_interface_member0) + print("Management ae member 1: " + + self.lag_management_interface_member1) + print("Management ae policy : " + + self.lag_management_interface_policy) + print("Management subnet: " + str(self.management_subnet.cidr)) if self.management_gateway_address: - print ("Management gateway address: " + - str(self.management_gateway_address)) - print ("Controller floating address: " + - str(self.controller_floating_address)) - print "Controller 0 address: " + str(self.controller_address_0) - print "Controller 1 address: " + str(self.controller_address_1) - print ("NFS Management Address 1: " + - str(self.nfs_management_address_1)) + print("Management gateway address: " + + str(self.management_gateway_address)) + print("Controller floating address: " + + str(self.controller_floating_address)) + print("Controller 0 address: " + str(self.controller_address_0)) + print("Controller 1 address: " + str(self.controller_address_1)) + print("NFS Management Address 1: " + + str(self.nfs_management_address_1)) if not self.infrastructure_interface: - print ("NFS Management Address 2: " + - str(self.nfs_management_address_2)) - print ("Controller floating hostname: " + - str(self.controller_floating_hostname)) - print "Controller hostname prefix: " + self.controller_hostname_prefix - print ("OAM Controller floating hostname: " + - str(self.oamcontroller_floating_hostname)) + print("NFS Management Address 2: " + + str(self.nfs_management_address_2)) + print("Controller floating hostname: " + + str(self.controller_floating_hostname)) + print("Controller hostname prefix: " + self.controller_hostname_prefix) + print("OAM Controller floating hostname: " + + str(self.oamcontroller_floating_hostname)) if not self.use_entire_mgmt_subnet: - print "Management start address: " + \ - str(self.management_start_address) - print "Management end address: " + \ - str(self.management_end_address) + print("Management start address: " + + str(self.management_start_address)) + print("Management end address: " + + str(self.management_end_address)) if self.dynamic_address_allocation: - print "Dynamic IP address allocation is selected" - print ("Management multicast subnet: " + - str(self.management_multicast_subnet)) + print("Dynamic IP address allocation is selected") + print("Management multicast subnet: " + + str(self.management_multicast_subnet)) - print "\nInfrastructure Network Configuration" - print "------------------------------------" + print("\nInfrastructure Network Configuration") + print("------------------------------------") if not self.infrastructure_interface: - print "Infrastructure interface not configured" + print("Infrastructure interface not configured") else: - print ("Infrastructure interface name: " + - self.infrastructure_interface_name) - print "Infrastructure interface: " + self.infrastructure_interface + print("Infrastructure interface name: " + + self.infrastructure_interface_name) + print("Infrastructure interface: " + self.infrastructure_interface) if self.infrastructure_vlan: - print "Infrastructure vlan: " + self.infrastructure_vlan - print "Infrastructure interface MTU: " + self.infrastructure_mtu - print ("Infrastructure interface link capacity Mbps: " + - str(self.infrastructure_link_capacity)) + print("Infrastructure vlan: " + self.infrastructure_vlan) + print("Infrastructure interface MTU: " + self.infrastructure_mtu) + print("Infrastructure interface link capacity Mbps: " + + str(self.infrastructure_link_capacity)) if self.lag_infrastructure_interface: - print ("Infrastructure ae member 0: " + - self.lag_infrastructure_interface_member0) - print ("Infrastructure ae member 1: " + - self.lag_infrastructure_interface_member1) - print ("Infrastructure ae policy : " + - self.lag_infrastructure_interface_policy) - print ("Infrastructure subnet: " + - str(self.infrastructure_subnet.cidr)) - print ("Controller 0 infrastructure address: " + - str(self.controller_infrastructure_address_0)) - print ("Controller 1 infrastructure address: " + - str(self.controller_infrastructure_address_1)) - print ("NFS Infrastructure Address 1: " + - str(self.nfs_infrastructure_address_1)) - print ("Controller infrastructure hostname suffix: " + - self.controller_infrastructure_hostname_suffix) + print("Infrastructure ae member 0: " + + self.lag_infrastructure_interface_member0) + print("Infrastructure ae member 1: " + + self.lag_infrastructure_interface_member1) + print("Infrastructure ae policy : " + + self.lag_infrastructure_interface_policy) + print("Infrastructure subnet: " + + str(self.infrastructure_subnet.cidr)) + print("Controller 0 infrastructure address: " + + str(self.controller_infrastructure_address_0)) + print("Controller 1 infrastructure address: " + + str(self.controller_infrastructure_address_1)) + print("NFS Infrastructure Address 1: " + + str(self.nfs_infrastructure_address_1)) + print("Controller infrastructure hostname suffix: " + + self.controller_infrastructure_hostname_suffix) if not self.use_entire_infra_subnet: - print "Infrastructure start address: " + \ - str(self.infrastructure_start_address) - print "Infrastructure end address: " + \ - str(self.infrastructure_end_address) + print("Infrastructure start address: " + + str(self.infrastructure_start_address)) + print("Infrastructure end address: " + + str(self.infrastructure_end_address)) - print "\nExternal OAM Network Configuration" - print "----------------------------------" - print ("External OAM interface name: " + - self.external_oam_interface_name) - print "External OAM interface: " + self.external_oam_interface + print("\nExternal OAM Network Configuration") + print("----------------------------------") + print("External OAM interface name: " + + self.external_oam_interface_name) + print("External OAM interface: " + self.external_oam_interface) if self.external_oam_vlan: - print "External OAM vlan: " + self.external_oam_vlan - print "External OAM interface MTU: " + self.external_oam_mtu + print("External OAM vlan: " + self.external_oam_vlan) + print("External OAM interface MTU: " + self.external_oam_mtu) if self.lag_external_oam_interface: - print ("External OAM ae member 0: " + - self.lag_external_oam_interface_member0) - print ("External OAM ae member 1: " + - self.lag_external_oam_interface_member1) - print ("External OAM ae policy : " + - self.lag_external_oam_interface_policy) - print "External OAM subnet: " + str(self.external_oam_subnet) + print("External OAM ae member 0: " + + self.lag_external_oam_interface_member0) + print("External OAM ae member 1: " + + self.lag_external_oam_interface_member1) + print("External OAM ae policy : " + + self.lag_external_oam_interface_policy) + print("External OAM subnet: " + str(self.external_oam_subnet)) if self.external_oam_gateway_address: - print ("External OAM gateway address: " + - str(self.external_oam_gateway_address)) + print("External OAM gateway address: " + + str(self.external_oam_gateway_address)) if self.system_mode != sysinv_constants.SYSTEM_MODE_SIMPLEX: - print ("External OAM floating address: " + - str(self.external_oam_floating_address)) - print "External OAM 0 address: " + str(self.external_oam_address_0) - print "External OAM 1 address: " + str(self.external_oam_address_1) + print("External OAM floating address: " + + str(self.external_oam_floating_address)) + print("External OAM 0 address: " + + str(self.external_oam_address_0)) + print("External OAM 1 address: " + + str(self.external_oam_address_1)) else: - print "External OAM address: " + str(self.external_oam_address_0) + print("External OAM address: " + str(self.external_oam_address_0)) if self.region_config: - print "\nRegion Configuration" - print "--------------------" - print "Region 1 name: " + self.region_1_name - print "Region 2 name: " + self.region_2_name - print "Admin user name: " + self.admin_username - print "Admin user domain: " + self.admin_user_domain - print "Admin project name: " + self.admin_project_name - print "Admin project domain: " + self.admin_project_domain - print "Service project name: " + self.service_project_name - print "Service user domain: " + self.service_user_domain - print "Service project domain: " + self.service_project_domain - print "Keystone auth URI: " + self.keystone_auth_uri - print "Keystone identity URI: " + self.keystone_identity_uri - print "Keystone admin URI: " + self.keystone_admin_uri - print "Keystone internal URI: " + self.keystone_internal_uri - print "Keystone public URI: " + self.keystone_public_uri - print "Keystone service name: " + self.keystone_service_name - print "Keystone service type: " + self.keystone_service_type - print "Glance user name: " + self.glance_ks_user_name - print "Glance service name: " + self.glance_service_name - print "Glance service type: " + self.glance_service_type - print "Glance cached: " + str(self.glance_cached) - print "Glance region: " + self.glance_region_name - print "Glance admin URI: " + self.glance_admin_uri - print "Glance internal URI: " + self.glance_internal_uri - print "Glance public URI: " + self.glance_public_uri - print "LDAP service name: " + self.ldap_service_name - print "LDAP region: " + self.ldap_region_name - print "LDAP service URI:" + self.ldap_service_uri - print "Nova user name: " + self.nova_ks_user_name - print "Nova service name: " + self.nova_service_name - print "Nova service type: " + self.nova_service_type - print "Placement user name: " + self.placement_ks_user_name - print "Placement service name: " + self.placement_service_name - print "Placement service type: " + self.placement_service_type - print "Neutron user name: " + self.neutron_ks_user_name - print "Neutron region name: " + self.neutron_region_name - print "Neutron service name: " + self.neutron_service_name - print "Neutron service type: " + self.neutron_service_type - print "Ceilometer user name: " + self.ceilometer_ks_user_name - print "Ceilometer service name: " + self.ceilometer_service_name - print "Ceilometer service type: " + self.ceilometer_service_type - print "Patching user name: " + self.patching_ks_user_name - print "Sysinv user name: " + self.sysinv_ks_user_name - print "Sysinv service name: " + self.sysinv_service_name - print "Sysinv service type: " + self.sysinv_service_type - print "Heat user name: " + self.heat_ks_user_name - print "Heat admin user name: " + self.heat_admin_ks_user_name + print("\nRegion Configuration") + print("--------------------") + print("Region 1 name: " + self.region_1_name) + print("Region 2 name: " + self.region_2_name) + print("Admin user name: " + self.admin_username) + print("Admin user domain: " + self.admin_user_domain) + print("Admin project name: " + self.admin_project_name) + print("Admin project domain: " + self.admin_project_domain) + print("Service project name: " + self.service_project_name) + print("Service user domain: " + self.service_user_domain) + print("Service project domain: " + self.service_project_domain) + print("Keystone auth URI: " + self.keystone_auth_uri) + print("Keystone identity URI: " + self.keystone_identity_uri) + print("Keystone admin URI: " + self.keystone_admin_uri) + print("Keystone internal URI: " + self.keystone_internal_uri) + print("Keystone public URI: " + self.keystone_public_uri) + print("Keystone service name: " + self.keystone_service_name) + print("Keystone service type: " + self.keystone_service_type) + print("Glance user name: " + self.glance_ks_user_name) + print("Glance service name: " + self.glance_service_name) + print("Glance service type: " + self.glance_service_type) + print("Glance cached: " + str(self.glance_cached)) + print("Glance region: " + self.glance_region_name) + print("Glance admin URI: " + self.glance_admin_uri) + print("Glance internal URI: " + self.glance_internal_uri) + print("Glance public URI: " + self.glance_public_uri) + print("LDAP service name: " + self.ldap_service_name) + print("LDAP region: " + self.ldap_region_name) + print("LDAP service URI:" + self.ldap_service_uri) + print("Nova user name: " + self.nova_ks_user_name) + print("Nova service name: " + self.nova_service_name) + print("Nova service type: " + self.nova_service_type) + print("Placement user name: " + self.placement_ks_user_name) + print("Placement service name: " + self.placement_service_name) + print("Placement service type: " + self.placement_service_type) + print("Neutron user name: " + self.neutron_ks_user_name) + print("Neutron region name: " + self.neutron_region_name) + print("Neutron service name: " + self.neutron_service_name) + print("Neutron service type: " + self.neutron_service_type) + print("Ceilometer user name: " + self.ceilometer_ks_user_name) + print("Ceilometer service name: " + self.ceilometer_service_name) + print("Ceilometer service type: " + self.ceilometer_service_type) + print("Patching user name: " + self.patching_ks_user_name) + print("Sysinv user name: " + self.sysinv_ks_user_name) + print("Sysinv service name: " + self.sysinv_service_name) + print("Sysinv service type: " + self.sysinv_service_type) + print("Heat user name: " + self.heat_ks_user_name) + print("Heat admin user name: " + self.heat_admin_ks_user_name) if self.subcloud_config(): - print "\nSubcloud Configuration" - print "----------------------" - print "System controller subnet: " + \ - str(self.system_controller_subnet.cidr) - print "System controller floating ip: " + \ - str(self.system_controller_floating_ip) + print("\nSubcloud Configuration") + print("----------------------") + print("System controller subnet: " + + str(self.system_controller_subnet.cidr)) + print("System controller floating ip: " + + str(self.system_controller_floating_ip)) def write_config_file(self): """Write configuration to a text file for later reference.""" @@ -3521,12 +3523,12 @@ class ConfigAssistant(): if not self.infrastructure_interface_configured and \ int(self.management_link_capacity) < \ sysinv_constants.LINK_SPEED_10G: - print - print textwrap.fill( - "Warning: The infrastructure network was not configured, " - "and the management interface link capacity is less than " - "10000 Mbps. This is not a supported configuration and " - "will result in unacceptable DRBD sync times.", 80) + print('') + print(textwrap.fill( + "Warning: The infrastructure network was not configured, " + "and the management interface link capacity is less than " + "10000 Mbps. This is not a supported configuration and " + "will result in unacceptable DRBD sync times.", 80)) def verify_branding(self): """ Verify the constraints for custom branding procedure """ @@ -3664,7 +3666,7 @@ class ConfigAssistant(): # one of the openstack passwords failed validation! fail_msg = ("%s: %s" % (stanza.keys()[0], msg)) if console: - print textwrap.fill(fail_msg, 80) + print(textwrap.fill(fail_msg, 80)) return False raise ConfigFail(fail_msg) except Exception as e: @@ -4665,7 +4667,7 @@ class ConfigAssistant(): elif user_input.lower() == 'n': raise UserQuit else: - print "Invalid choice" + print("Invalid choice") # Verify at most one branding tarball is present self.verify_branding() @@ -4673,7 +4675,7 @@ class ConfigAssistant(): self.write_config_file() utils.write_simplex_flag() - print "\nApplying configuration (this will take several minutes):" + print("\nApplying configuration (this will take several minutes):") runner = progress.ProgressRunner() runner.add(self.create_bootstrap_config, @@ -4697,33 +4699,33 @@ class ConfigAssistant(): def check_required_interfaces_status(self): if self.management_interface_configured: if not is_interface_up(self.management_interface): - print + print('') if (self.system_mode != sysinv_constants.SYSTEM_MODE_DUPLEX_DIRECT and self.system_mode != sysinv_constants.SYSTEM_MODE_SIMPLEX): - print textwrap.fill( + print(textwrap.fill( "Warning: The interface (%s) is not operational " "and some platform services will not start properly. " "Bring up the interface to enable the required " - "services." % self.management_interface, 80) + "services." % self.management_interface, 80)) if self.infrastructure_interface_configured: if not is_interface_up(self.infrastructure_interface): if self.system_mode != \ sysinv_constants.SYSTEM_MODE_DUPLEX_DIRECT: - print - print textwrap.fill( + print('') + print(textwrap.fill( "Warning: The interface (%s) is not operational " "and some platform services will not start properly. " "Bring up the interface to enable the required " - "services." % self.infrastructure_interface, 80) + "services." % self.infrastructure_interface, 80)) if self.external_oam_interface_configured: if not is_interface_up(self.external_oam_interface): - print - print textwrap.fill( - "Warning: The interface (%s) is not operational " - "and some OAM services will not start properly. " - "Bring up the interface to enable the required " - "services." % self.external_oam_interface, 80) + print('') + print(textwrap.fill( + "Warning: The interface (%s) is not operational " + "and some OAM services will not start properly. " + "Bring up the interface to enable the required " + "services." % self.external_oam_interface, 80)) diff --git a/controllerconfig/controllerconfig/controllerconfig/regionconfig.py b/controllerconfig/controllerconfig/controllerconfig/regionconfig.py index 25a1c77ded..4c0eebc35f 100755 --- a/controllerconfig/controllerconfig/controllerconfig/regionconfig.py +++ b/controllerconfig/controllerconfig/controllerconfig/regionconfig.py @@ -5,6 +5,7 @@ SPDX-License-Identifier: Apache-2.0 """ +from __future__ import print_function from six.moves import configparser import os import subprocess @@ -545,16 +546,16 @@ def configure_region(config_file, config_type=REGION_CONFIG): """Configure the region""" # Parse the region/subcloud config file - print "Parsing configuration file... ", + print("Parsing configuration file... ", end=' ') region_config = parse_system_config(config_file) - print "DONE" + print("DONE") if config_type == SUBCLOUD_CONFIG: # Set defaults in region_config for subclouds set_subcloud_config_defaults(region_config) # Validate the region/subcloud config file - print "Validating configuration file... ", + print("Validating configuration file... ", end=' ') try: create_cgcs_config_file(None, region_config, None, None, None, config_type=config_type, @@ -562,15 +563,15 @@ def configure_region(config_file, config_type=REGION_CONFIG): except configparser.Error as e: raise ConfigFail("Error parsing configuration file %s: %s" % (config_file, e)) - print "DONE" + print("DONE") # Bring up management interface to allow us to reach Region 1 - print "Configuring management interface... ", + print("Configuring management interface... ", end=' ') configure_management_interface(region_config, config_type=config_type) - print "DONE" + print("DONE") # Get token from keystone - print "Retrieving keystone token...", + print("Retrieving keystone token...", end=' ') sys.stdout.flush() auth_url = region_config.get('SHARED_SERVICES', 'KEYSTONE_ADMINURL') if region_config.has_option('SHARED_SERVICES', 'ADMIN_TENANT_NAME'): @@ -604,18 +605,19 @@ def configure_region(config_file, config_type=REGION_CONFIG): if not token: attempts += 1 if attempts < 10: - print "\rRetrieving keystone token...{}".format( - '.' * attempts), + print("\rRetrieving keystone token...{}".format( + '.' * attempts), end=' ') sys.stdout.flush() time.sleep(10) else: raise ConfigFail( "Unable to obtain keystone token. Please ensure " "networking and keystone configuration is correct.") - print "DONE" + print("DONE") # Get services, endpoints, users and domains from keystone - print "Retrieving services, endpoints and users from keystone... ", + print("Retrieving services, endpoints and users from keystone... ", + end=' ') region_name = region_config.get('SHARED_SERVICES', 'REGION_NAME') service_name = region_config.get('SHARED_SERVICES', 'KEYSTONE_SERVICE_NAME') @@ -634,12 +636,12 @@ def configure_region(config_file, config_type=REGION_CONFIG): raise ConfigFail( "Unable to retrieve services, endpoints or users from keystone. " "Please ensure networking and keystone configuration is correct.") - print "DONE" + print("DONE") user_config = None if config_type == SUBCLOUD_CONFIG: # Retrieve subcloud configuration from dcmanager - print "Retrieving configuration from dcmanager... ", + print("Retrieving configuration from dcmanager... ", end=' ') dcmanager_url = token.get_service_url( 'SystemController', 'dcmanager', 'dcmanager', "admin") subcloud_name = region_config.get('REGION_2_SERVICES', @@ -651,7 +653,7 @@ def configure_region(config_file, config_type=REGION_CONFIG): subcloud_name, hash_string) user_config = subcloud_config['users'] - print "DONE" + print("DONE") try: # Configure missing region one keystone entries @@ -659,28 +661,28 @@ def configure_region(config_file, config_type=REGION_CONFIG): # Prepare region configuration for puppet to create keystone identities if (region_config.has_option('REGION_2_SERVICES', 'CREATE') and region_config.get('REGION_2_SERVICES', 'CREATE') == 'Y'): - print "Preparing keystone configuration... ", + print("Preparing keystone configuration... ", end=' ') # If keystone configuration for this region already in place, # validate it only else: # Validate region one keystone config create = False - print "Validating keystone configuration... ", + print("Validating keystone configuration... ", end=' ') validate_region_one_keystone_config(region_config, token, api_url, users, services, endpoints, create, config_type=config_type, user_config=user_config) - print "DONE" + print("DONE") # validate ldap if it is shared if region_config.has_option('SHARED_SERVICES', 'LDAP_SERVICE_URL'): - print "Validating ldap configuration... ", + print("Validating ldap configuration... ", end=' ') validate_region_one_ldap_config(region_config) - print "DONE" + print("DONE") # Create cgcs_config file - print "Creating config apply file... ", + print("Creating config apply file... ", end=' ') try: create_cgcs_config_file(TEMP_CGCS_CONFIG_FILE, region_config, services, endpoints, domains, @@ -688,33 +690,33 @@ def configure_region(config_file, config_type=REGION_CONFIG): except configparser.Error as e: raise ConfigFail("Error parsing configuration file %s: %s" % (config_file, e)) - print "DONE" + print("DONE") # Configure controller assistant = ConfigAssistant() assistant.configure(TEMP_CGCS_CONFIG_FILE, display_config=False) except ConfigFail as e: - print "A configuration failure has occurred.", + print("A configuration failure has occurred.", end=' ') raise e def show_help_region(): - print ("Usage: %s [OPTIONS] " % sys.argv[0]) - print textwrap.fill( + print("Usage: %s [OPTIONS] " % sys.argv[0]) + print(textwrap.fill( "Perform region configuration using the region " - "configuration from CONFIG_FILE.", 80) - print ("--allow-ssh Allow configuration to be executed in " - "ssh\n") + "configuration from CONFIG_FILE.", 80)) + print("--allow-ssh Allow configuration to be executed in " + "ssh\n") def show_help_subcloud(): - print ("Usage: %s [OPTIONS] " % sys.argv[0]) - print textwrap.fill( - "Perform subcloud configuration using the subcloud " - "configuration from CONFIG_FILE.", 80) - print ("--allow-ssh Allow configuration to be executed in " - "ssh\n") + print("Usage: %s [OPTIONS] " % sys.argv[0]) + print(textwrap.fill( + "Perform subcloud configuration using the subcloud " + "configuration from CONFIG_FILE.", 80)) + print("--allow-ssh Allow configuration to be executed in " + "ssh\n") def config_main(config_type=REGION_CONFIG): @@ -739,7 +741,7 @@ def config_main(config_type=REGION_CONFIG): elif arg == len(sys.argv) - 1: config_file = sys.argv[arg] else: - print "Invalid option. Use --help for more information." + print("Invalid option. Use --help for more information.") exit(1) arg += 1 @@ -748,26 +750,26 @@ def config_main(config_type=REGION_CONFIG): # Check if that the command is being run from the console if utils.is_ssh_parent(): if allow_ssh: - print textwrap.fill(constants.SSH_WARNING_MESSAGE, 80) - print + print(textwrap.fill(constants.SSH_WARNING_MESSAGE, 80)) + print('') else: - print textwrap.fill(constants.SSH_ERROR_MESSAGE, 80) + print(textwrap.fill(constants.SSH_ERROR_MESSAGE, 80)) exit(1) if not os.path.isfile(config_file): - print "Config file %s does not exist." % config_file + print("Config file %s does not exist." % config_file) exit(1) try: configure_region(config_file, config_type=config_type) except KeyboardInterrupt: - print "\nAborting configuration" + print("\nAborting configuration") except ConfigFail as e: LOG.exception(e) - print "\nConfiguration failed: {}".format(e) + print("\nConfiguration failed: {}".format(e)) except Exception as e: LOG.exception(e) - print "\nConfiguration failed: {}".format(e) + print("\nConfiguration failed: {}".format(e)) else: print("\nConfiguration finished successfully.") finally: diff --git a/controllerconfig/controllerconfig/controllerconfig/systemconfig.py b/controllerconfig/controllerconfig/controllerconfig/systemconfig.py index 340651cdbc..8bbf629dce 100644 --- a/controllerconfig/controllerconfig/controllerconfig/systemconfig.py +++ b/controllerconfig/controllerconfig/controllerconfig/systemconfig.py @@ -5,6 +5,7 @@ SPDX-License-Identifier: Apache-2.0 """ +from __future__ import print_function from six.moves import configparser import os import readline @@ -249,73 +250,73 @@ def configure_system(config_file): """Configure the system""" # Parse the system config file - print "Parsing system configuration file... ", + print("Parsing system configuration file... ", end=' ') system_config = parse_system_config(config_file) - print "DONE" + print("DONE") # Validate the system config file - print "Validating system configuration file... ", + print("Validating system configuration file... ", end=' ') try: create_cgcs_config_file(None, system_config, None, None, None, DEFAULT_CONFIG, validate_only=True) except configparser.Error as e: raise ConfigFail("Error parsing configuration file %s: %s" % (config_file, e)) - print "DONE" + print("DONE") # Create cgcs_config file - print "Creating config apply file... ", + print("Creating config apply file... ", end=' ') try: create_cgcs_config_file(TEMP_CGCS_CONFIG_FILE, system_config, None, None, None, DEFAULT_CONFIG) except configparser.Error as e: raise ConfigFail("Error parsing configuration file %s: %s" % (config_file, e)) - print "DONE" + print("DONE") def show_help(): - print ("Usage: %s\n" - "Perform system configuration\n" - "\nThe default action is to perform the initial configuration for " - "the system.\nThe following options are also available:\n" - "--config-file Perform configuration using INI file\n" - "--backup Backup configuration using the given " - "name\n" - "--clone-iso Clone and create an image with " - "the given file name\n" - "--clone-status Status of the last installation of " - "cloned image\n" - "--restore-system " - " " - "\n" - " Restore system configuration from backup " - "file with\n" - " the given name, full path required\n" - "--restore-images Restore images from backup file with the " - "given name,\n" - " full path required\n" - "--restore-complete Complete restore of controller-0\n" - "--allow-ssh Allow configuration to be executed in " - "ssh\n" - % sys.argv[0]) + print("Usage: %s\n" + "Perform system configuration\n" + "\nThe default action is to perform the initial configuration for " + "the system.\nThe following options are also available:\n" + "--config-file Perform configuration using INI file\n" + "--backup Backup configuration using the given " + "name\n" + "--clone-iso Clone and create an image with " + "the given file name\n" + "--clone-status Status of the last installation of " + "cloned image\n" + "--restore-system " + " " + "\n" + " Restore system configuration from backup " + "file with\n" + " the given name, full path required\n" + "--restore-images Restore images from backup file with the " + "given name,\n" + " full path required\n" + "--restore-complete Complete restore of controller-0\n" + "--allow-ssh Allow configuration to be executed in " + "ssh\n" + % sys.argv[0]) def show_help_lab_only(): - print ("Usage: %s\n" - "Perform initial configuration\n" - "\nThe following options are for lab use only:\n" - "--answerfile Apply the configuration from the specified " - "file without\n" - " any validation or user interaction\n" - "--default Apply default configuration with no NTP or " - "DNS server\n" - " configuration (suitable for testing in a " - "virtual\n" - " environment)\n" - "--archive-dir Directory to store the archive in\n" - "--provision Provision initial system data only\n" - % sys.argv[0]) + print("Usage: %s\n" + "Perform initial configuration\n" + "\nThe following options are for lab use only:\n" + "--answerfile Apply the configuration from the specified " + "file without\n" + " any validation or user interaction\n" + "--default Apply default configuration with no NTP or " + "DNS server\n" + " configuration (suitable for testing in a " + "virtual\n" + " environment)\n" + "--archive-dir Directory to store the archive in\n" + "--provision Provision initial system data only\n" + % sys.argv[0]) def no_complete(text, state): @@ -356,14 +357,14 @@ def main(): if arg < len(sys.argv): answerfile = sys.argv[arg] else: - print "--answerfile option requires a file to be specified" + print("--answerfile option requires a file to be specified") exit(1) elif sys.argv[arg] == "--backup": arg += 1 if arg < len(sys.argv): backup_name = sys.argv[arg] else: - print "--backup requires the name of the backup" + print("--backup requires the name of the backup") exit(1) do_backup = True elif sys.argv[arg] == "--restore-system": @@ -377,16 +378,16 @@ def main(): if arg < len(sys.argv): backup_name = sys.argv[arg] else: - print textwrap.fill( + print(textwrap.fill( "--restore-system requires the filename " - " of the backup", 80) + " of the backup", 80)) exit(1) else: backup_name = sys.argv[arg] else: - print textwrap.fill( + print(textwrap.fill( "--restore-system requires the filename " - "of the backup", 80) + "of the backup", 80)) exit(1) do_system_restore = True elif sys.argv[arg] == "--restore-images": @@ -394,7 +395,7 @@ def main(): if arg < len(sys.argv): backup_name = sys.argv[arg] else: - print "--restore-images requires the filename of the backup" + print("--restore-images requires the filename of the backup") exit(1) do_images_restore = True elif sys.argv[arg] == "--restore-complete": @@ -404,14 +405,14 @@ def main(): if arg < len(sys.argv): archive_dir = sys.argv[arg] else: - print "--archive-dir requires a directory" + print("--archive-dir requires a directory") exit(1) elif sys.argv[arg] == "--clone-iso": arg += 1 if arg < len(sys.argv): backup_name = sys.argv[arg] else: - print "--clone-iso requires the name of the image" + print("--clone-iso requires the name of the image") exit(1) do_clone = True elif sys.argv[arg] == "--clone-status": @@ -424,7 +425,7 @@ def main(): if arg < len(sys.argv): system_config_file = sys.argv[arg] else: - print "--config-file requires the filename of the config file" + print("--config-file requires the filename of the config file") exit(1) do_non_interactive = True elif sys.argv[arg] in ["--help", "-h", "-?"]: @@ -442,7 +443,7 @@ def main(): # are stable, we will remove it and make kubernetes the default. options['kubernetes'] = True else: - print "Invalid option. Use --help for more information." + print("Invalid option. Use --help for more information.") exit(1) arg += 1 @@ -453,7 +454,7 @@ def main(): do_clone, do_default_config, do_non_interactive].count(True) > 1: - print "Invalid combination of options selected" + print("Invalid combination of options selected") exit(1) if answerfile and [do_backup, @@ -463,7 +464,8 @@ def main(): do_clone, do_default_config, do_non_interactive].count(True) > 0: - print "The --answerfile option cannot be used with the selected option" + print("The --answerfile option cannot be used with the selected " + "option") exit(1) log.configure() @@ -472,10 +474,10 @@ def main(): # Check if that the command is being run from the console if utils.is_ssh_parent(): if allow_ssh: - print textwrap.fill(constants.SSH_WARNING_MESSAGE, 80) - print + print(textwrap.fill(constants.SSH_WARNING_MESSAGE, 80)) + print('') else: - print textwrap.fill(constants.SSH_ERROR_MESSAGE, 80) + print(textwrap.fill(constants.SSH_ERROR_MESSAGE, 80)) exit(1) # Reduce the printk console log level to avoid noise during configuration @@ -490,19 +492,19 @@ def main(): try: if do_backup: backup_restore.backup(backup_name, archive_dir) - print "\nBackup complete" + print("\nBackup complete") elif do_system_restore: backup_restore.restore_system(backup_name, include_storage_reinstall) - print "\nSystem restore complete" + print("\nSystem restore complete") elif do_images_restore: backup_restore.restore_images(backup_name) - print "\nImages restore complete" + print("\nImages restore complete") elif do_complete_restore: backup_restore.restore_complete() elif do_clone: clone.clone(backup_name, archive_dir) - print "\nCloning complete" + print("\nCloning complete") elif do_provision: assistant = ConfigAssistant(**options) assistant.provision(answerfile) @@ -521,24 +523,24 @@ def main(): answerfile = TEMP_CGCS_CONFIG_FILE assistant = ConfigAssistant(**options) assistant.configure(answerfile, do_default_config) - print "\nConfiguration was applied\n" - print textwrap.fill( + print("\nConfiguration was applied\n") + print(textwrap.fill( "Please complete any out of service commissioning steps " - "with system commands and unlock controller to proceed.", 80) + "with system commands and unlock controller to proceed.", 80)) assistant.check_required_interfaces_status() except KeyboardInterrupt: - print "\nAborting configuration" + print("\nAborting configuration") except BackupFail as e: - print "\nBackup failed: {}".format(e) + print("\nBackup failed: {}".format(e)) except RestoreFail as e: - print "\nRestore failed: {}".format(e) + print("\nRestore failed: {}".format(e)) except ConfigFail as e: - print "\nConfiguration failed: {}".format(e) + print("\nConfiguration failed: {}".format(e)) except CloneFail as e: - print "\nCloning failed: {}".format(e) + print("\nCloning failed: {}".format(e)) except UserQuit: - print "\nAborted configuration" + print("\nAborted configuration") finally: if os.path.isfile(TEMP_CGCS_CONFIG_FILE): os.remove(TEMP_CGCS_CONFIG_FILE) diff --git a/controllerconfig/controllerconfig/controllerconfig/tests/test_answerfile.py b/controllerconfig/controllerconfig/controllerconfig/tests/test_answerfile.py index ce648d9d79..e0562d50e7 100644 --- a/controllerconfig/controllerconfig/controllerconfig/tests/test_answerfile.py +++ b/controllerconfig/controllerconfig/controllerconfig/tests/test_answerfile.py @@ -35,7 +35,7 @@ def _test_answerfile(tmpdir, filename, assistant.input_config_from_file(answerfile) # Test the display method - print "Output from display_config:" + print("Output from display_config:") assistant.display_config() # Ensure we can write the configuration @@ -50,7 +50,7 @@ def _test_answerfile(tmpdir, filename, f.write("\n[cAUTHENTICATION]\nADMIN_PASSWORD=Li69nux*\n") # Do a diff between the answerfile and the generated config file - print "\n\nDiff of answerfile vs. generated config file:\n" + print("\n\nDiff of answerfile vs. generated config file:\n") with open(answerfile) as a, open(constants.CGCS_CONFIG_FILE) as b: a_lines = a.readlines() b_lines = b.readlines() diff --git a/controllerconfig/controllerconfig/controllerconfig/tests/test_region_config.py b/controllerconfig/controllerconfig/controllerconfig/tests/test_region_config.py index d077411e65..7a7f2399a8 100644 --- a/controllerconfig/controllerconfig/controllerconfig/tests/test_region_config.py +++ b/controllerconfig/controllerconfig/controllerconfig/tests/test_region_config.py @@ -5,6 +5,7 @@ SPDX-License-Identifier: Apache-2.0 """ +from __future__ import print_function from six.moves import configparser import difflib import filecmp @@ -436,16 +437,16 @@ FAKE_DOMAIN_DATA = {u'domains': [ def _dump_config(config): """ Prints contents of config object """ for section in config.sections(): - print "[%s]" % section + print("[%s]" % section) for (name, value) in config.items(section): - print "%s=%s" % (name, value) + print("%s=%s" % (name, value)) def _replace_in_file(filename, old, new): """ Replaces old with new in file filename. """ for line in fileinput.FileInput(filename, inplace=1): line = line.replace(old, new) - print line, + print(line, end=' ') fileinput.close() @@ -463,7 +464,7 @@ def _test_region_config(tmpdir, inputfile, resultfile, region_config = cr.parse_system_config(inputfile) # Dump results for debugging - print "Parsed region_config:\n" + print("Parsed region_config:\n") _dump_config(region_config) # Validate the region config file @@ -477,7 +478,7 @@ def _test_region_config(tmpdir, inputfile, resultfile, shutil.copyfile(resultfile, local_resultfile) # Do a diff between the output and the expected results - print "\n\nDiff of output file vs. expected results file:\n" + print("\n\nDiff of output file vs. expected results file:\n") with open(outputfile) as a, open(local_resultfile) as b: a_lines = a.readlines() b_lines = b.readlines() @@ -515,7 +516,7 @@ def test_region_config_simple(tmpdir): def test_region_config_simple_can_ips(tmpdir): """ Test import of simple region_config file with unit ips for CAN """ - print "IN TEST ################################################" + print("IN TEST ################################################") regionfile = os.path.join( os.getcwd(), "controllerconfig/tests/files/", "region_config.simple.can_ips") diff --git a/controllerconfig/controllerconfig/controllerconfig/tests/test_system_config.py b/controllerconfig/controllerconfig/controllerconfig/tests/test_system_config.py index c0a9b8fbee..e94f3f2c35 100644 --- a/controllerconfig/controllerconfig/controllerconfig/tests/test_system_config.py +++ b/controllerconfig/controllerconfig/controllerconfig/tests/test_system_config.py @@ -22,9 +22,9 @@ import controllerconfig.systemconfig as cr # noqa: E402 def _dump_config(config): """ Prints contents of config object """ for section in config.sections(): - print "[%s]" % section + print("[%s]" % section) for (name, value) in config.items(section): - print "%s=%s" % (name, value) + print("%s=%s" % (name, value)) def _test_system_config(filename): @@ -34,7 +34,7 @@ def _test_system_config(filename): system_config = cr.parse_system_config(filename) # Dump results for debugging - print "Parsed system_config:\n" + print("Parsed system_config:\n") _dump_config(system_config) # Validate the system config file diff --git a/controllerconfig/controllerconfig/controllerconfig/tidy_storage.py b/controllerconfig/controllerconfig/controllerconfig/tidy_storage.py index 42e748abe3..bd1eecf714 100644 --- a/controllerconfig/controllerconfig/controllerconfig/tidy_storage.py +++ b/controllerconfig/controllerconfig/controllerconfig/tidy_storage.py @@ -124,10 +124,10 @@ class OpenStack(object): def show_help(): - print ("Usage: %s " % sys.argv[0]) - print textwrap.fill( + print("Usage: %s " % sys.argv[0]) + print(textwrap.fill( "Tidy storage post system restore. Check user actions " - "in the generated user_action_log_file.", 80) + "in the generated user_action_log_file.", 80)) def tidy_storage(result_file): @@ -219,7 +219,7 @@ def tidy_storage(result_file): 'rbd://{}/images/{}/snap'.format(ceph_cluster[0], image) - print ("Creating a Glance image %s ...\n " % fields['name']) + print("Creating a Glance image %s ...\n " % fields['name']) g_client_v1.images.create(**fields) except subprocess.CalledProcessError: LOG.error("Failed to access rbd image %s" % image) @@ -242,7 +242,7 @@ def tidy_storage(result_file): snaps_no_backend_vol = [] for snap in snap_l: - print ("Check if volume snapshot %s has backend " % snap.name) + print("Check if volume snapshot %s has backend " % snap.name) try: output = subprocess.check_output( ["rbd", "ls", "--pool", "cinder-volumes"], @@ -278,8 +278,8 @@ def tidy_storage(result_file): if not keep_snap: try: - print ("Volume snapshot %s has no backend data. " - "Deleting it from Cinder...\n" % snap.name) + print("Volume snapshot %s has no backend data. " + "Deleting it from Cinder...\n" % snap.name) c_client.volume_snapshots.delete(c_utils.find_resource( c_client.volume_snapshots, snap.id), force=True) @@ -387,9 +387,9 @@ def tidy_storage(result_file): # supported in rbd. So we just remove the snapshot. # Remove the snapshot - print (textwrap.fill( - "Removing snapshot %s from volume %s " - "in rbd...\n" % (snap, vol_id), 76)) + print(textwrap.fill( + "Removing snapshot %s from volume %s " + "in rbd...\n" % (snap, vol_id), 76)) del_snap = '{}@{}'.format(volume, snap) output = subprocess.check_output( ["rbd", "snap", "unprotect", del_snap], @@ -440,8 +440,8 @@ def tidy_storage(result_file): for snap in snap_l: if snap not in cinder_snap_l: - print ("Creating volume snapshot found-%s " - "in Cinder...\n" % snap) + print("Creating volume snapshot found-%s " + "in Cinder...\n" % snap) c_client.volume_snapshots.manage( volume_id=vol_id, diff --git a/controllerconfig/controllerconfig/controllerconfig/upgrades/controller.py b/controllerconfig/controllerconfig/controllerconfig/upgrades/controller.py index 4eae0ea94c..36e137b693 100644 --- a/controllerconfig/controllerconfig/controllerconfig/upgrades/controller.py +++ b/controllerconfig/controllerconfig/controllerconfig/upgrades/controller.py @@ -450,7 +450,7 @@ def import_databases(from_release, to_release, from_path=None, simplex=False): # Execute import commands for cmd in import_commands: try: - print "Importing %s" % cmd[0] + print("Importing %s" % cmd[0]) LOG.info("Executing import command: %s" % cmd[1]) subprocess.check_call([cmd[1]], shell=True, stdout=devnull) @@ -483,7 +483,7 @@ def create_databases(from_release, to_release, db_credentials): with conn: with conn.cursor() as cur: for database in databases_to_create: - print "Creating %s database" % database + print("Creating %s database" % database) username = psycopg2.extensions.AsIs( '\"%s\"' % db_credentials[database]['username']) db_name = psycopg2.extensions.AsIs('\"%s\"' % database) @@ -513,7 +513,7 @@ def migrate_sysinv_database(): sysinv_cmd = 'sysinv-dbsync' try: - print "Migrating sysinv" + print("Migrating sysinv") LOG.info("Executing migrate command: %s" % sysinv_cmd) subprocess.check_call([sysinv_cmd], shell=True, stdout=devnull, stderr=devnull) @@ -686,7 +686,7 @@ def migrate_databases(from_release, shared_services, db_credentials, # Execute migrate commands for cmd in migrate_commands: try: - print "Migrating %s" % cmd[0] + print("Migrating %s" % cmd[0]) LOG.info("Executing migrate command: %s" % cmd[1]) subprocess.check_call([cmd[1]], shell=True, stdout=devnull, stderr=devnull) @@ -826,19 +826,19 @@ def upgrade_controller(from_release, to_release): nfs_mount_filesystem(utils.POSTGRES_PATH, POSTGRES_MOUNT_PATH) # Migrate keyring data - print "Migrating keyring data..." + print("Migrating keyring data...") migrate_keyring_data(from_release, to_release) # Migrate pxeboot config - print "Migrating pxeboot configuration..." + print("Migrating pxeboot configuration...") migrate_pxeboot_config(from_release, to_release) # Migrate sysinv data. - print "Migrating sysinv configuration..." + print("Migrating sysinv configuration...") migrate_sysinv_data(from_release, to_release) # Prepare for database migration - print "Preparing for database migration..." + print("Preparing for database migration...") prepare_postgres_filesystems() # Create the postgres database @@ -863,7 +863,7 @@ def upgrade_controller(from_release, to_release): time.sleep(5) # Import databases - print "Importing databases..." + print("Importing databases...") import_databases(from_release, to_release) shared_services = get_shared_services() @@ -881,17 +881,17 @@ def upgrade_controller(from_release, to_release): db_credentials = get_db_credentials(shared_services, from_release) # Create any new databases - print "Creating new databases..." + print("Creating new databases...") create_databases(from_release, to_release, db_credentials) - print "Migrating databases..." + print("Migrating databases...") # Migrate sysinv database migrate_sysinv_database() # Migrate databases migrate_databases(from_release, shared_services, db_credentials) - print "Applying configuration..." + print("Applying configuration...") # Execute migration scripts utils.execute_migration_scripts( @@ -934,7 +934,7 @@ def upgrade_controller(from_release, to_release): LOG.info("Failed to update hiera configuration") raise - print "Shutting down upgrade processes..." + print("Shutting down upgrade processes...") # Stop postgres service LOG.info("Stopping postgresql service") @@ -957,7 +957,7 @@ def upgrade_controller(from_release, to_release): raise # Copy upgraded database back to controller-0 - print "Writing upgraded databases..." + print("Writing upgraded databases...") LOG.info("Copying upgraded database to controller-0") try: subprocess.check_call( @@ -1003,13 +1003,13 @@ def upgrade_controller(from_release, to_release): unmount_filesystem("/tmp/etc_platform") os.rmdir("/tmp/etc_platform") - print "Controller-1 upgrade complete" + print("Controller-1 upgrade complete") LOG.info("Controller-1 upgrade complete!!!") def show_help(): - print ("Usage: %s " % sys.argv[0]) - print "Upgrade controller-1. For internal use only." + print("Usage: %s " % sys.argv[0]) + print("Upgrade controller-1. For internal use only.") def main(): @@ -1026,22 +1026,22 @@ def main(): elif arg == 2: to_release = sys.argv[arg] else: - print ("Invalid option %s. Use --help for more information." % - sys.argv[arg]) + print("Invalid option %s. Use --help for more information." % + sys.argv[arg]) exit(1) arg += 1 log.configure() if not from_release or not to_release: - print "Both the FROM_RELEASE and TO_RELEASE must be specified" + print("Both the FROM_RELEASE and TO_RELEASE must be specified") exit(1) try: upgrade_controller(from_release, to_release) except Exception as e: LOG.exception(e) - print "Upgrade failed: {}".format(e) + print("Upgrade failed: {}".format(e)) # Set upgrade fail flag on mate controller LOG.info("Set upgrade fail flag on mate controller") @@ -1520,13 +1520,13 @@ def upgrade_controller_simplex(backup_file): def print_log_info(string): - print string + print(string) LOG.info(string) def show_help_simplex(): - print ("Usage: %s " % sys.argv[0]) - print "Upgrade controller-0 simplex. For internal use only." + print("Usage: %s " % sys.argv[0]) + print("Upgrade controller-0 simplex. For internal use only.") def simplex_main(): @@ -1539,8 +1539,8 @@ def simplex_main(): elif arg == 1: backup_file = sys.argv[arg] else: - print ("Invalid option %s. Use --help for more information." % - sys.argv[arg]) + print("Invalid option %s. Use --help for more information." % + sys.argv[arg]) exit(1) arg += 1 @@ -1554,14 +1554,14 @@ def simplex_main(): exit(1) if not backup_file: - print "The BACKUP_FILE must be specified" + print("The BACKUP_FILE must be specified") exit(1) try: upgrade_controller_simplex(backup_file) except Exception as e: LOG.exception(e) - print "Upgrade failed: {}".format(e) + print("Upgrade failed: {}".format(e)) # TODO SET Upgrade fail flag # Set upgrade fail flag on mate controller exit(1) diff --git a/controllerconfig/controllerconfig/controllerconfig/upgrades/utils.py b/controllerconfig/controllerconfig/controllerconfig/upgrades/utils.py index effddc4fda..2187c99200 100644 --- a/controllerconfig/controllerconfig/controllerconfig/upgrades/utils.py +++ b/controllerconfig/controllerconfig/controllerconfig/upgrades/utils.py @@ -247,5 +247,5 @@ def apply_upgrade_manifest(controller_address): subprocess.check_call(cmd, stdout=flog, stderr=flog) except subprocess.CalledProcessError: msg = "Failed to execute upgrade manifest" - print msg + print(msg) raise Exception(msg) diff --git a/controllerconfig/controllerconfig/controllerconfig/utils.py b/controllerconfig/controllerconfig/controllerconfig/utils.py index 50015d84de..00fbfc51cc 100644 --- a/controllerconfig/controllerconfig/controllerconfig/utils.py +++ b/controllerconfig/controllerconfig/controllerconfig/utils.py @@ -626,7 +626,7 @@ def apply_manifest(controller_address_0, personality, manifest, hieradata, subprocess.check_call(cmd, stdout=flog, stderr=flog) except subprocess.CalledProcessError: msg = "Failed to execute %s manifest" % manifest - print msg + print(msg) raise Exception(msg) @@ -657,7 +657,7 @@ def create_static_config(): subprocess.check_call(cmd) except subprocess.CalledProcessError: msg = "Failed to create puppet hiera static config" - print msg + print(msg) raise Exception(msg) @@ -669,7 +669,7 @@ def create_system_config(): subprocess.check_call(cmd) except subprocess.CalledProcessError: msg = "Failed to update puppet hiera system config" - print msg + print(msg) raise Exception(msg) @@ -684,7 +684,7 @@ def create_host_config(hostname=None): subprocess.check_call(cmd) except subprocess.CalledProcessError: msg = "Failed to update puppet hiera host config" - print msg + print(msg) raise Exception(msg) @@ -821,7 +821,7 @@ def apply_banner_customization(): stdout=blog, stderr=blog) except subprocess.CalledProcessError: error_text = "Failed to apply banner customization" - print "%s; see %s for detail" % (error_text, logfile) + print("%s; see %s for detail" % (error_text, logfile)) def mtce_restart(): diff --git a/controllerconfig/controllerconfig/scripts/00-sample-migration.py b/controllerconfig/controllerconfig/scripts/00-sample-migration.py index 9885d7b1e5..37b76f907c 100644 --- a/controllerconfig/controllerconfig/scripts/00-sample-migration.py +++ b/controllerconfig/controllerconfig/scripts/00-sample-migration.py @@ -52,7 +52,7 @@ def main(): elif arg == 3: action = sys.argv[arg] else: - print ("Invalid option %s." % sys.argv[arg]) + print("Invalid option %s." % sys.argv[arg]) return 1 arg += 1 @@ -65,7 +65,7 @@ def main(): do_migration_work() except Exception as ex: LOG.exception(ex) - print ex + print(ex) return 1 diff --git a/controllerconfig/controllerconfig/tox.ini b/controllerconfig/controllerconfig/tox.ini index 6e3b4ba929..7f823910b8 100644 --- a/controllerconfig/controllerconfig/tox.ini +++ b/controllerconfig/controllerconfig/tox.ini @@ -30,11 +30,26 @@ commands = pylint {posargs} controllerconfig --rcfile=./pylint.rc --extension-pk [testenv:flake8] basepython = python2.7 -deps = flake8<3.6.0 +deps = hacking + flake8<3.6.0 commands = flake8 {posargs} [flake8] -ignore = W503 +# H series are hacking +# H101: Use TODO(NAME) +# H102: Apache 2.0 license header not found +# H104: File contains nothing but comments +# H231: Python 3.x incompatible 'except x,y:' construct +# H232: Python 3.x incompatible octal 400 should be written as 0o400 +# H238: old style class declaration, use new style (inherit from `object`) +# H301: one import per line +# H306: imports not in alphabetical order +# H401: docstring should not start with a space +# H403: multi line docstrings should end on a new line +# H404: multi line docstring should start without a leading new line +# H405: multi line docstring summary not separated with an empty line +ignore = H101,H102,H104,H231,H232,H238,H301,H306,H401,H403,H404,H405, + W503 [testenv:py27] basepython = python2.7 diff --git a/controllerconfig/controllerconfig/upgrade-scripts/16-neutron-move-bindings-off-controller-1.py b/controllerconfig/controllerconfig/upgrade-scripts/16-neutron-move-bindings-off-controller-1.py index e2bb78d356..18a3e2d7b1 100755 --- a/controllerconfig/controllerconfig/upgrade-scripts/16-neutron-move-bindings-off-controller-1.py +++ b/controllerconfig/controllerconfig/upgrade-scripts/16-neutron-move-bindings-off-controller-1.py @@ -32,7 +32,7 @@ def main(): elif arg == 3: action = sys.argv[arg] else: - print ("Invalid option %s." % sys.argv[arg]) + print("Invalid option %s." % sys.argv[arg]) return 1 arg += 1 @@ -47,7 +47,7 @@ def main(): move_distributed_port_bindings_off_controller_1() except Exception as ex: LOG.exception(ex) - print ex + print(ex) return 1 diff --git a/controllerconfig/controllerconfig/upgrade-scripts/20-sysinv-retire-ceph-cache-tier-sp.py b/controllerconfig/controllerconfig/upgrade-scripts/20-sysinv-retire-ceph-cache-tier-sp.py index d03d9cc814..d31d4bb1cf 100644 --- a/controllerconfig/controllerconfig/upgrade-scripts/20-sysinv-retire-ceph-cache-tier-sp.py +++ b/controllerconfig/controllerconfig/upgrade-scripts/20-sysinv-retire-ceph-cache-tier-sp.py @@ -37,7 +37,7 @@ def main(): elif arg == 3: action = sys.argv[arg] else: - print ("Invalid option %s." % sys.argv[arg]) + print("Invalid option %s." % sys.argv[arg]) return 1 arg += 1 diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/common/utils.py b/sysinv/cgts-client/cgts-client/cgtsclient/common/utils.py index e4f1ee810a..1302515f4b 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/common/utils.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/common/utils.py @@ -14,6 +14,7 @@ # License for the specific language governing permissions and limitations # under the License. +from __future__ import print_function try: import tsconfig.tsconfig as tsc is_remote = False @@ -225,7 +226,7 @@ def _sort_for_list(objs, fields, formatters={}, sortby=0, reversesort=False): def default_printer(s): - print s + print(s) def pt_builder(field_labels, fields, formatters, paging, printer=default_printer): @@ -410,7 +411,7 @@ def print_tuple_list(tuples, tuple_labels=[], formatters={}): v = formatters[f](v) pt.add_row([l, v]) - print pt.get_string() + print(pt.get_string()) def str_height(text): @@ -465,7 +466,7 @@ def print_dict(d, dict_property="Property", wrap=0): col1 = '' else: pt.add_row([k, v]) - print pt.get_string() + print(pt.get_string()) def find_resource(manager, name_or_id): @@ -561,7 +562,7 @@ def dict_to_patch(values, op='replace'): def exit(msg=''): if msg: - print >> sys.stderr, msg + print(msg, file=sys.stderr) sys.exit(1) diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/common/wrapping_formatters.py b/sysinv/cgts-client/cgts-client/cgtsclient/common/wrapping_formatters.py index 05e75d90d5..f99fb1fe8d 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/common/wrapping_formatters.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/common/wrapping_formatters.py @@ -800,7 +800,7 @@ def _simpleTestHarness(no_wrap): utils.print_list(logs, fields, field_labels, formatters=formatters, sortby=6, reversesort=True, no_wrap_fields=['entity_instance_id']) - print "nowrap = {}".format(is_nowrap_set()) + print("nowrap = {}".format(is_nowrap_set())) if __name__ == "__main__": _simpleTestHarness(True) diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/openstack/common/config/generator.py b/sysinv/cgts-client/cgts-client/cgtsclient/openstack/common/config/generator.py index 15d7925296..df82fb0e30 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/openstack/common/config/generator.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/openstack/common/config/generator.py @@ -98,7 +98,7 @@ def generate(srcfiles): for group, opts in opts_by_group.items(): print_group_opts(group, opts) - print "# Total option count: %d" % OPTION_COUNT + print("# Total option count: %d" % OPTION_COUNT) def _import_module(mod_str): @@ -162,18 +162,18 @@ def _list_opts(obj): def print_group_opts(group, opts_by_module): - print "[%s]" % group - print + print("[%s]" % group) + print('') global OPTION_COUNT for mod, opts in opts_by_module: OPTION_COUNT += len(opts) - print '#' - print '# Options defined in %s' % mod - print '#' - print + print('#') + print('# Options defined in %s' % mod) + print('#') + print('') for opt in opts: _print_opt(opt) - print + print('') def _get_my_ip(): @@ -213,33 +213,33 @@ def _print_opt(opt): sys.stderr.write("%s\n" % str(err)) sys.exit(1) opt_help += ' (' + OPT_TYPES[opt_type] + ')' - print '#', "\n# ".join(textwrap.wrap(opt_help, WORDWRAP_WIDTH)) + print('#', "\n# ".join(textwrap.wrap(opt_help, WORDWRAP_WIDTH))) try: if opt_default is None: - print '#%s=' % opt_name + print('#%s=' % opt_name) elif opt_type == STROPT: assert(isinstance(opt_default, six.string_types)) - print '#%s=%s' % (opt_name, _sanitize_default(opt_default)) + print('#%s=%s' % (opt_name, _sanitize_default(opt_default))) elif opt_type == BOOLOPT: assert(isinstance(opt_default, bool)) - print '#%s=%s' % (opt_name, str(opt_default).lower()) + print('#%s=%s' % (opt_name, str(opt_default).lower())) elif opt_type == INTOPT: assert(isinstance(opt_default, int) and not isinstance(opt_default, bool)) - print '#%s=%s' % (opt_name, opt_default) + print('#%s=%s' % (opt_name, opt_default)) elif opt_type == FLOATOPT: assert(isinstance(opt_default, float)) - print '#%s=%s' % (opt_name, opt_default) + print('#%s=%s' % (opt_name, opt_default)) elif opt_type == LISTOPT: assert(isinstance(opt_default, list)) - print '#%s=%s' % (opt_name, ','.join(opt_default)) + print('#%s=%s' % (opt_name, ','.join(opt_default))) elif opt_type == MULTISTROPT: assert(isinstance(opt_default, list)) if not opt_default: opt_default = [''] for default in opt_default: - print '#%s=%s' % (opt_name, default) - print + print('#%s=%s' % (opt_name, default)) + print('') except Exception: sys.stderr.write('Error in option "%s"\n' % opt_name) sys.exit(1) @@ -247,7 +247,7 @@ def _print_opt(opt): def main(): if len(sys.argv) < 2: - print "usage: %s [srcfile]...\n" % sys.argv[0] + print("usage: %s [srcfile]...\n" % sys.argv[0]) sys.exit(0) generate(sys.argv[1:]) diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/shell.py index a56c1539a0..3b249ac605 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/shell.py @@ -18,6 +18,7 @@ Command-line interface for System Inventory and Maintenance """ +from __future__ import print_function import argparse import httplib2 import logging @@ -338,14 +339,14 @@ def main(): CgtsShell().main(sys.argv[1:]) except KeyboardInterrupt as e: - print >> sys.stderr, ('caught: %r, aborting' % (e)) + print(('caught: %r, aborting' % (e)), file=sys.stderr) sys.exit(0) except IOError as e: sys.exit(0) except Exception as e: - print >> sys.stderr, e + print(e, file=sys.stderr) sys.exit(1) if __name__ == "__main__": diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/address_pool_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/address_pool_shell.py index bd09ac795d..43a60289f3 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/address_pool_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/address_pool_shell.py @@ -59,7 +59,7 @@ def do_addrpool_list(cc, args): def do_addrpool_delete(cc, args): """Delete an IP address pool.""" cc.address_pool.delete(args.address_pool_uuid) - print 'Deleted address pool: %s' % (args.address_pool_uuid) + print('Deleted address pool: %s' % (args.address_pool_uuid)) def _get_range_tuples(data): diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/address_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/address_shell.py index d3e10ec9ef..226fcad6d3 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/address_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/address_shell.py @@ -51,7 +51,7 @@ def do_host_addr_list(cc, args): def do_host_addr_delete(cc, args): """Delete an IP address.""" cc.address.delete(args.address_uuid) - print 'Deleted Address: %s' % (args.address_uuid) + print('Deleted Address: %s' % (args.address_uuid)) @utils.arg('hostnameorid', diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/ceph_mon_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/ceph_mon_shell.py index f825839c1b..ee5a7ff7cd 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/ceph_mon_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/ceph_mon_shell.py @@ -62,13 +62,13 @@ def do_ceph_mon_modify(cc, args): for ceph_mon in cc.ceph_mon.list(): cc.ceph_mon.update(ceph_mon.uuid, patch) _print_ceph_mon_list(cc) - print "\nNOTE: ceph_mon_gib for both controllers are changed." + print("\nNOTE: ceph_mon_gib for both controllers are changed.") else: ceph_mon = cc.ceph_mon.update(ceph_mon.uuid, patch) _print_ceph_mon_show(ceph_mon) - print "\nSystem configuration has changed.\nplease follow the " \ - "administrator guide to complete configuring system.\n" + print("\nSystem configuration has changed.\nplease follow the " + "administrator guide to complete configuring system.\n") def do_ceph_mon_list(cc, args): diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/certificate_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/certificate_shell.py index 4f767e3d45..b71bc2f2fd 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/certificate_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/certificate_shell.py @@ -40,14 +40,14 @@ def do_certificate_show(cc, args): args.certificate_uuid = cert.uuid break else: - print "No TPM certificate installed" + print("No TPM certificate installed") return certificate = cc.certificate.get(args.certificate_uuid) if certificate: _print_certificate_show(certificate) else: - print "No Certificates installed" + print("No Certificates installed") def do_certificate_list(cc, args): @@ -85,9 +85,9 @@ def do_certificate_install(cc, args): 'mode': args.mode, 'certificate_file': os.path.abspath(args.certificate_file)} - print "WARNING: For security reasons, the original certificate, " - print "containing the private key, will be removed, " - print "once the private key is processed." + print("WARNING: For security reasons, the original certificate, ") + print("containing the private key, will be removed, ") + print("once the private key is processed.") try: response = cc.certificate.certificate_install(sec_file, data=data) diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/cluster_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/cluster_shell.py index 96ec7086fb..f156039e87 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/cluster_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/cluster_shell.py @@ -141,4 +141,4 @@ if os.path.exists('/var/run/.sysinv_running_in_lab'): def do_cluster_delete(cc, args): """Delete a Cluster.""" cc.cluster.delete(args.cluster_uuid) - print 'Deleted cluster: %s' % args.cluster_uuid + print('Deleted cluster: %s' % args.cluster_uuid) diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/drbdconfig_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/drbdconfig_shell.py index fd89fb9727..8f105a7c55 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/drbdconfig_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/drbdconfig_shell.py @@ -9,6 +9,7 @@ # All Rights Reserved. # +from __future__ import print_function import argparse import sys import time @@ -44,7 +45,7 @@ def do_drbdsync_show(cc, args): drbdconfigs = cc.drbdconfig.list() _print_drbdsync_show(drbdconfigs[0]) - print + print('') ihosts = cc.ihost.list_personality(personality=CONTROLLER) _print_controller_config_show(ihosts) @@ -72,7 +73,7 @@ def do_drbdsync_modify(cc, args): if len(attributes) > 0: attributes.append('action=apply') else: - print "No options provided." + print("No options provided.") return patch = utils.args_array_to_patch("replace", attributes) @@ -90,9 +91,9 @@ def do_drbdsync_modify(cc, args): for ihost in ihosts: if ihost.config_target and ihost.config_applied != ihost.config_target: is_config = True - print ("host %s is configuring ..." % (ihost.hostname)) + print("host %s is configuring ..." % (ihost.hostname)) if is_config: - print "Cannot apply update while controller configuration in progress." + print("Cannot apply update while controller configuration in progress.") return try: @@ -117,16 +118,16 @@ def do_drbdsync_modify(cc, args): hosts.append(ihost.hostname) if do_wait: if x == 0: - print ("waiting for hosts: %s to finish configuring" % - ', '.join(hosts)), + print(("waiting for hosts: %s to finish configuring" % + ', '.join(hosts)), end=' ') sys.stdout.flush() else: - print ".", + print(".", end=' ') sys.stdout.flush() time.sleep(wait_interval) else: - print - print "DRBD configuration finished." + print('') + print("DRBD configuration finished.") break if do_wait: - print "DRBD configuration timed out." + print("DRBD configuration timed out.") diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/health_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/health_shell.py index b1238ba178..9cbebc59bd 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/health_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/health_shell.py @@ -12,9 +12,9 @@ def do_health_query(cc, args): """Run the Health Check.""" - print cc.health.get() + print(cc.health.get()) def do_health_query_upgrade(cc, args): """Run the Health Check for an Upgrade.""" - print cc.health.get_upgrade() + print(cc.health.get_upgrade()) diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/helm_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/helm_shell.py index a92d09d117..6235299fa9 100755 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/helm_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/helm_shell.py @@ -53,8 +53,8 @@ def do_helm_override_delete(cc, args): """Delete overrides for a chart.""" try: cc.helm.delete_overrides(args.chart, args.namespace) - print 'Deleted chart overrides for %s:%s' % ( - args.chart, args.namespace) + print('Deleted chart overrides for %s:%s' % ( + args.chart, args.namespace)) except exc.HTTPNotFound: raise exc.CommandError('chart overrides not found: %s:%s' % ( args.chart, args.namespace)) diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/iHost_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/iHost_shell.py index 89ce142f6e..9dd88a3bf2 100755 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/iHost_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/iHost_shell.py @@ -191,9 +191,9 @@ def do_host_bulk_add(cc, args): success = response.get('success') error = response.get('error') if success: - print "Success: " + success + "\n" + print("Success: " + success + "\n") if error: - print "Error:\n" + error + print("Error:\n" + error) @utils.arg('-m', '--mgmt_mac', @@ -235,7 +235,7 @@ def do_host_delete(cc, args): for n in args.hostnameorid: try: cc.ihost.delete(n) - print 'Deleted host %s' % n + print('Deleted host %s' % n) except exc.HTTPNotFound: raise exc.CommandError('host not found: %s' % n) @@ -642,17 +642,17 @@ def do_host_patch_reboot(cc, args): except exc.HTTPNotFound: raise exc.CommandError('Host not found: %s' % args.hostnameorid) - print "The host-patch-reboot command has been deprecated." - print "Please use the following procedure:" - print "1. Lock the node:" - print " system host-lock %s" % ihost.hostname - print "2. Issue patch install request:" - print " sudo sw-patch host-install %s" % ihost.hostname - print " Or to issue non-blocking requests for parallel install:" - print " sudo sw-patch host-install-async %s" % ihost.hostname - print " sudo sw-patch query-hosts" - print "3. Unlock node once install completes:" - print " system host-unlock %s" % ihost.hostname + print("The host-patch-reboot command has been deprecated.") + print("Please use the following procedure:") + print("1. Lock the node:") + print(" system host-lock %s" % ihost.hostname) + print("2. Issue patch install request:") + print(" sudo sw-patch host-install %s" % ihost.hostname) + print(" Or to issue non-blocking requests for parallel install:") + print(" sudo sw-patch host-install-async %s" % ihost.hostname) + print(" sudo sw-patch query-hosts") + print("3. Unlock node once install completes:") + print(" system host-unlock %s" % ihost.hostname) @utils.arg('--filename', @@ -668,9 +668,9 @@ def do_host_bulk_export(cc, args): try: with open(config_filename, 'wb') as fw: fw.write(xml_content) - print _('Export successfully to %s') % config_filename + print(_('Export successfully to %s') % config_filename) except IOError: - print _('Cannot write to file: %s') % config_filename + print(_('Cannot write to file: %s') % config_filename) return @@ -697,7 +697,7 @@ def do_host_downgrade(cc, args): 'Are you absolutely sure you want to continue? [yes/N]: ') confirm = input(warning_message) if confirm != 'yes': - print "Operation cancelled." + print("Operation cancelled.") return ihost = cc.ihost.downgrade(args.hostid, args.force) @@ -726,7 +726,7 @@ def do_host_upgrade(cc, args): 'Are you absolutely sure you want to continue? [yes/N]: ') confirm = input(warning_message) if confirm != 'yes': - print "Operation cancelled." + print("Operation cancelled.") return ihost = cc.ihost.upgrade(args.hostid, args.force) diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/icommunity_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/icommunity_shell.py index 6578975bf9..936fe7f9e3 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/icommunity_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/icommunity_shell.py @@ -77,4 +77,4 @@ def do_snmp_comm_delete(cc, args): cc.icommunity.delete(c) except exc.HTTPNotFound: raise exc.CommandError('Community not found: %s' % c) - print 'Deleted community %s' % c + print('Deleted community %s' % c) diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/idisk_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/idisk_shell.py index 6d2c324b34..6b09baa31f 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/idisk_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/idisk_shell.py @@ -106,7 +106,7 @@ def do_host_disk_wipe(cc, args): "Continue [yes/N]: ") confirm = input(warning_message) if confirm != 'yes': - print "Operation cancelled." + print("Operation cancelled.") return ihost = ihost_utils._find_ihost(cc, args.hostnameorid) diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/iinfra_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/iinfra_shell.py index 3ec43a4828..ba43e4d46b 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/iinfra_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/iinfra_shell.py @@ -26,7 +26,7 @@ def do_infra_show(cc, args): iinfras = cc.iinfra.list() if not iinfras: - print "Infrastructure network not configured" + print("Infrastructure network not configured") return iinfra = iinfras[0] @@ -73,7 +73,7 @@ def do_infra_modify(cc, args): iinfras = cc.iinfra.list() if not iinfras: - print "Infrastructure network not configured" + print("Infrastructure network not configured") return iinfra = iinfras[0] @@ -97,7 +97,7 @@ def do_infra_modify(cc, args): def do_infra_apply(cc, args): infras = cc.iinfra.list() if not infras: - print "Infrastructure network not configured" + print("Infrastructure network not configured") return infra = infras[0] diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/iinterface_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/iinterface_shell.py index c6e7d95507..7e243aed75 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/iinterface_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/iinterface_shell.py @@ -111,7 +111,7 @@ def do_host_if_delete(cc, args): ihost = ihost_utils._find_ihost(cc, args.hostnameorid) i = _find_interface(cc, ihost, args.ifnameoruuid) cc.iinterface.delete(i.uuid) - print 'Deleted interface: host %s if %s' % (args.hostnameorid, args.ifnameoruuid) + print('Deleted interface: host %s if %s' % (args.hostnameorid, args.ifnameoruuid)) @utils.arg('hostnameorid', diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/inode_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/inode_shell.py index 2464e65c68..19dec12581 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/inode_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/inode_shell.py @@ -85,7 +85,7 @@ def do_host_node_delete(cc, args): except exc.HTTPNotFound: raise exc.CommandError('Delete node failed: host %s if %s' % (args.hostnameorid, args.inodeuuid)) - print 'Deleted node: host %s if %s' % (args.hostnameorid, args.inodeuuid) + print('Deleted node: host %s if %s' % (args.hostnameorid, args.inodeuuid)) @utils.arg('hostnameorid', diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/interface_network_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/interface_network_shell.py index 3252b056d8..4e172d19ab 100755 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/interface_network_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/interface_network_shell.py @@ -92,4 +92,4 @@ def do_interface_network_assign(cc, args): def do_interface_network_remove(cc, args): """Remove an assigned network from an interface.""" cc.interface_network.remove(args.interface_network_uuid) - print 'Deleted Interface Network: %s' % args.interface_network_uuid + print('Deleted Interface Network: %s' % args.interface_network_uuid) diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/iprofile_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/iprofile_shell.py index c759e8c569..f8dce4238b 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/iprofile_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/iprofile_shell.py @@ -163,7 +163,7 @@ def do_ifprofile_delete(cc, args): cc.iprofile.delete(iprofile.uuid) except exc.HTTPNotFound: raise exc.CommandError('if profile delete failed: %s' % n) - print 'Deleted if profile %s' % n + print('Deleted if profile %s' % n) # # CPU PROFILES @@ -281,7 +281,7 @@ def do_cpuprofile_delete(cc, args): cc.iprofile.delete(iprofile.uuid) except exc.HTTPNotFound: raise exc.CommandError('Cpu profile delete failed: %s' % n) - print 'Deleted cpu profile %s' % n + print('Deleted cpu profile %s' % n) # @@ -420,9 +420,9 @@ def do_storprofile_list(cc, args): storprofiles.append(profile) if profile_disk_invalid: - print "WARNING: Storage profiles from a previous release are " \ - "missing the persistent disk name in the disk config field. " \ - "These profiles need to be deleted and recreated." + print("WARNING: Storage profiles from a previous release are " + "missing the persistent disk name in the disk config field. " + "These profiles need to be deleted and recreated.") if storprofiles: field_labels = ['uuid', 'name', 'disk config', 'partition config', @@ -469,9 +469,9 @@ def do_storprofile_show(cc, args): profile_disk_invalid = get_storprofile_data(cc, iprofile, detailed=True) if profile_disk_invalid: - print "WARNING: This storage profile, from a previous release, is " \ - "missing the persistent disk name in the disk config field. " \ - "This profile needs to be deleted and recreated." + print("WARNING: This storage profile, from a previous release, is " + "missing the persistent disk name in the disk config field. " + "This profile needs to be deleted and recreated.") _print_storprofile_show(iprofile) @@ -518,7 +518,7 @@ def do_storprofile_delete(cc, args): cc.iprofile.delete(iprofile.uuid) except exc.HTTPNotFound: raise exc.CommandError('Storage profile delete failed: %s' % n) - print 'Deleted storage profile %s' % n + print('Deleted storage profile %s' % n) # # MEMORY PROFILES @@ -642,7 +642,7 @@ def do_memprofile_delete(cc, args): cc.iprofile.delete(iprofile.uuid) except exc.HTTPNotFound: raise exc.CommandError('Memory profile delete failed: %s' % n) - print 'Deleted memory profile %s' % n + print('Deleted memory profile %s' % n) @utils.arg('profilefilename', @@ -662,9 +662,9 @@ def do_profile_import(cc, args): if results: for result in results: if(result['result'] == 'Invalid'): - print 'error: %s is not a valid profile file.' % (filename) + print('error: %s is not a valid profile file.' % (filename)) else: - print result['msg'] + print(result['msg']) if result['detail']: - print ' %s' % (result['detail']) + print(' %s' % (result['detail'])) diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/isensor_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/isensor_shell.py index 0e408270ae..2604289584 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/isensor_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/isensor_shell.py @@ -206,5 +206,5 @@ def donot_host_sensor_delete(cc, args): ihost = ihost_utils._find_ihost(cc, args.hostnameorid) i = _find_sensor(cc, ihost, args.sensor_uuid) cc.isensor.delete(i.uuid) - print 'Deleted sensor: host %s sensor %s' % (args.hostnameorid, - args.sensor_uuid) + print('Deleted sensor: host %s sensor %s' % (args.hostnameorid, + args.sensor_uuid)) diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/isensorgroup_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/isensorgroup_shell.py index 5ba8315bff..5ec95826b6 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/isensorgroup_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/isensorgroup_shell.py @@ -185,13 +185,13 @@ def do_host_sensorgroup_relearn(cc, args): isensorgroups = cc.isensorgroup.relearn(ihost.uuid) - print ("%s sensor model and any related alarm assertions are being " - "deleted." % (args.hostnameorid)) - print ("Any sensor suppression settings at the group or sensor levels " - "will be lost.") - print ("Will attempt to preserve customized group actions and monitor " - "interval when the model is relearned on next audit interval.") - print ("The learning process may take several minutes. Please stand-by.") + print("%s sensor model and any related alarm assertions are being " + "deleted." % (args.hostnameorid)) + print("Any sensor suppression settings at the group or sensor levels " + "will be lost.") + print("Will attempt to preserve customized group actions and monitor " + "interval when the model is relearned on next audit interval.") + print("The learning process may take several minutes. Please stand-by.") @utils.arg('hostnameorid', @@ -238,5 +238,5 @@ def donot_host_sensorgroup_delete(cc, args): ihost = ihost_utils._find_ihost(cc, args.hostnameorid) i = _find_sensorgroup(cc, ihost, args.sensorgroup_uuid) cc.isensorgroup.delete(i.uuid) - print ('Deleted sensorgroup: host %s sensorgroup %s' % - (args.hostnameorid, args.sensorgroup_uuid)) + print('Deleted sensorgroup: host %s sensorgroup %s' % + (args.hostnameorid, args.sensorgroup_uuid)) diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/iservice_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/iservice_shell.py index 354981ce73..0c3d46fc40 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/iservice_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/iservice_shell.py @@ -91,7 +91,7 @@ def do_service_delete(cc, args): cc.iservice.delete(c) except exc.HTTPNotFound: raise exc.CommandError('Service not found: %s' % c) - print 'Deleted service %s' % c + print('Deleted service %s' % c) @utils.arg('iservice', diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/iservicegroup_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/iservicegroup_shell.py index fa9babb50f..ba705b94c8 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/iservicegroup_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/iservicegroup_shell.py @@ -80,7 +80,7 @@ def do_servicegroup_delete(cc, args): cc.iservicegroup.delete(c) except exc.HTTPNotFound: raise exc.CommandError('Service not found: %s' % c) - print 'Deleted servicegroup %s' % c + print('Deleted servicegroup %s' % c) @utils.arg('iservicegroup', diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/isystem_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/isystem_shell.py index 4adf2b620d..52003df00a 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/isystem_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/isystem_shell.py @@ -129,9 +129,9 @@ def do_modify(cc, args): confirm = input(warning_message) if confirm != 'yes': - print "Operation cancelled." + print("Operation cancelled.") return - print 'Please follow the admin guide to complete the reconfiguration.' + print('Please follow the admin guide to complete the reconfiguration.') field_list = ['name', 'system_mode', 'description', 'location', 'contact', 'timezone', 'sdn_enabled', 'https_enabled', 'vswitch_type', 'security_feature'] @@ -158,5 +158,5 @@ def do_modify(cc, args): _print_isystem_show(isystem) if print_https_warning: - print "HTTPS enabled with a self-signed certificate.\nThis should be " \ - "changed to a CA-signed certificate with 'system certificate-install'. " + print("HTTPS enabled with a self-signed certificate.\nThis should be " + "changed to a CA-signed certificate with 'system certificate-install'. ") diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/itrapdest_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/itrapdest_shell.py index e816b7299e..33dcb075bf 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/itrapdest_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/itrapdest_shell.py @@ -81,4 +81,4 @@ def do_snmp_trapdest_delete(cc, args): cc.itrapdest.delete(c) except exc.HTTPNotFound: raise exc.CommandError('IP not found: %s' % c) - print 'Deleted ip %s' % c + print('Deleted ip %s' % c) diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/label_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/label_shell.py index e50a21f92b..21aa479f70 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/label_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/label_shell.py @@ -75,7 +75,7 @@ def do_host_label_remove(cc, args): lbl = _find_host_label(cc, ihost, i) if lbl: cc.label.remove(lbl.uuid) - print 'Deleted host label %s for host %s' % (i, ihost.hostname) + print('Deleted host label %s for host %s' % (i, ihost.hostname)) def _find_host_label(cc, host, label): diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/license_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/license_shell.py index 726ed23f73..a478bec94e 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/license_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/license_shell.py @@ -47,6 +47,6 @@ def do_license_install(cc, args): success = response.get('success') error = response.get('error') if success: - print success + "\n" + print(success + "\n") if error: - print error + "\n" + print(error + "\n") diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/load_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/load_shell.py index 8128325c50..ec5fcf801a 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/load_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/load_shell.py @@ -53,7 +53,7 @@ def do_load_delete(cc, args): except exc.HTTPNotFound: raise exc.CommandError('Delete load failed: load %s' % args.loadid) - print 'Deleted load: load %s' % args.loadid + print('Deleted load: load %s' % args.loadid) @utils.arg('isopath', diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/network_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/network_shell.py index 2a628fa084..1750257069 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/network_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/network_shell.py @@ -76,4 +76,4 @@ def do_network_add(cc, args): def do_network_delete(cc, args): """Delete a network""" cc.network.delete(args.network_uuid) - print 'Deleted Network: %s' % args.network_uuid + print('Deleted Network: %s' % args.network_uuid) diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/ptp_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/ptp_shell.py index 24451d05ee..d9d7c18ed9 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/ptp_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/ptp_shell.py @@ -67,7 +67,7 @@ def do_ptp_modify(cc, args): if args.mechanism is not None: attributes.append('mechanism=%s' % args.mechanism) if len(attributes) == 0: - print "No options provided." + print("No options provided.") return patch = utils.args_array_to_patch("replace", attributes) diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/remotelogging_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/remotelogging_shell.py index 01438bb99d..6db34287a5 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/remotelogging_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/remotelogging_shell.py @@ -82,7 +82,7 @@ def do_remotelogging_modify(cc, args): if len(attributes) > 0: attributes.append('action=apply') else: - print "No options provided." + print("No options provided.") return patch = utils.args_array_to_patch("replace", attributes) diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/route_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/route_shell.py index b7422054f2..0d6e0ea711 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/route_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/route_shell.py @@ -51,7 +51,7 @@ def do_host_route_list(cc, args): def do_host_route_delete(cc, args): """Delete an IP route.""" cc.route.delete(args.route_uuid) - print 'Deleted Route: %s' % (args.route_uuid) + print('Deleted Route: %s' % (args.route_uuid)) @utils.arg('hostnameorid', diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/sdn_controller_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/sdn_controller_shell.py index ed8b81cc8c..00404aa548 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/sdn_controller_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/sdn_controller_shell.py @@ -100,7 +100,7 @@ def do_sdn_controller_delete(cc, args): except exc.HTTPNotFound: raise exc.CommandError("Failed to delete SDN controller entry: " "invalid uuid: %s" % args.uuid) - print 'Deleted SDN controller: uuid %s' % args.uuid + print('Deleted SDN controller: uuid %s' % args.uuid) @utils.arg('uuid', diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/service_parameter_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/service_parameter_shell.py index 583b5a740f..4e1554eb5d 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/service_parameter_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/service_parameter_shell.py @@ -61,7 +61,7 @@ def do_service_parameter_delete(cc, args): """Delete a Service Parameter.""" cc.service_parameter.delete(args.uuid) - print 'Deleted service parameter: %s' % args.uuid + print('Deleted service parameter: %s' % args.uuid) def _find_service_parameter(cc, service, section, name): @@ -132,7 +132,7 @@ def do_service_parameter_apply(cc, args): cc.service_parameter.apply(args.service) except exc.HTTPNotFound: raise exc.CommandError('Failed to apply service parameters') - print 'Applying %s service parameters' % args.service + print('Applying %s service parameters' % args.service) @utils.arg('service', diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/sm_servicegroup_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/sm_servicegroup_shell.py index 6222ca42cc..9d3392fadf 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/sm_servicegroup_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/sm_servicegroup_shell.py @@ -93,7 +93,7 @@ def donot_servicegroup_delete(cc, args): cc.smapiClient.iservicegroup.delete(c) except exc.HTTPNotFound: raise exc.CommandError('Service not found: %s' % c) - print 'Deleted servicegroup %s' % c + print('Deleted servicegroup %s' % c) @utils.arg('iservicegroup', diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/storage_backend.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/storage_backend.py index 478566c77c..25efe235c9 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/storage_backend.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/storage_backend.py @@ -130,8 +130,8 @@ def backend_show(cc, backend_name_or_uuid, asdict=False): def _display_next_steps(): - print "\nSystem configuration has changed.\nPlease follow the " \ - "administrator guide to complete configuring the system.\n" + print("\nSystem configuration has changed.\nPlease follow the " + "administrator guide to complete configuring the system.\n") def backend_add(cc, backend, args): diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/storage_backend_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/storage_backend_shell.py index fdcc8cc9f3..0f2273a04b 100644 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/storage_backend_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/storage_backend_shell.py @@ -145,4 +145,4 @@ def do_storage_backend_delete(cc, args): storage_backend_utils.backend_delete( cc, args.backend_name_or_uuid) else: - print "Deleting a storage backend is not supported." + print("Deleting a storage backend is not supported.") diff --git a/sysinv/cgts-client/cgts-client/cgtsclient/v1/upgrade_shell.py b/sysinv/cgts-client/cgts-client/cgtsclient/v1/upgrade_shell.py index 271bc1a487..7fe286cacf 100755 --- a/sysinv/cgts-client/cgts-client/cgtsclient/v1/upgrade_shell.py +++ b/sysinv/cgts-client/cgts-client/cgtsclient/v1/upgrade_shell.py @@ -28,7 +28,7 @@ def do_upgrade_show(cc, args): if upgrades: _print_upgrade_show(upgrades[0]) else: - print 'No upgrade in progress' + print('No upgrade in progress') @utils.arg('-f', '--force', @@ -131,12 +131,12 @@ def do_upgrade_abort(cc, args): confirm = input(warning_message) if confirm != 'yes': - print "Operation cancelled." + print("Operation cancelled.") return elif abort_required: confirm = input("Type 'abort' to confirm: ") if confirm != 'abort': - print "Operation cancelled." + print("Operation cancelled.") return data = dict() diff --git a/sysinv/cgts-client/cgts-client/tox.ini b/sysinv/cgts-client/cgts-client/tox.ini index ab105cba6a..949c88bbe2 100644 --- a/sysinv/cgts-client/cgts-client/tox.ini +++ b/sysinv/cgts-client/cgts-client/tox.ini @@ -54,11 +54,10 @@ commands = show-source = true exclude=.*,dist,*lib/python*,*egg,build max-complexity=25 -ignore = H102,H104,H105,H233,H238,H404,H405,E501,F841 +ignore = H102,H104,H105,H238,H404,H405,E501,F841 #H102 Apache 2.0 license header not found #H104 File contains nothing but comments #H105 Don't use author tags -#H233 Python 3.x incompatible use of print operator #H238 old style class declaration, use new style (inherit from `object`) #H404 multi line docstring should start without a leading new line #H405 multi line docstring summary not separated with an empty line diff --git a/sysinv/sysinv/sysinv/sysinv/agent/manager.py b/sysinv/sysinv/sysinv/sysinv/agent/manager.py index bef3ceab64..55d39a6a7b 100644 --- a/sysinv/sysinv/sysinv/sysinv/agent/manager.py +++ b/sysinv/sysinv/sysinv/sysinv/agent/manager.py @@ -33,6 +33,7 @@ Commands (from conductors) are received via RPC calls. """ +from __future__ import print_function import errno import fcntl import fileinput @@ -1310,9 +1311,9 @@ class AgentManager(service.PeriodicService): shutil.copyfile(tsc.PLATFORM_CONF_FILE, temp_platform_conf_file) for line in fileinput.FileInput(temp_platform_conf_file, inplace=1): if line.startswith("INSTALL_UUID="): - print "INSTALL_UUID=%s" % install_uuid + print("INSTALL_UUID=%s" % install_uuid) else: - print line, + print(line, end=' ') fileinput.close() os.rename(temp_platform_conf_file, tsc.PLATFORM_CONF_FILE) diff --git a/sysinv/sysinv/sysinv/sysinv/agent/testpci.py b/sysinv/sysinv/sysinv/sysinv/agent/testpci.py index 0cbaa1cde3..cc0a6aa089 100644 --- a/sysinv/sysinv/sysinv/sysinv/agent/testpci.py +++ b/sysinv/sysinv/sysinv/sysinv/agent/testpci.py @@ -89,7 +89,7 @@ pci_inics = my_pci_inics.pci_inics_get() # post these to database by host, pciaddr for i in pci_inics: - print ("JKUNG pciaddr=%s, iclass=%s, vendor=%s, device=%s, rev=%s, svendor=%s, sdevice=%s" % (i.pciaddr, i.iclass, i.vendor, i.device, i.revision, i.svendor, i.sdevice)) + print("JKUNG pciaddr=%s, iclass=%s, vendor=%s, device=%s, rev=%s, svendor=%s, sdevice=%s" % (i.pciaddr, i.iclass, i.vendor, i.device, i.revision, i.svendor, i.sdevice)) # try: # rpc.db_post_by_host_and_mac() diff --git a/sysinv/sysinv/sysinv/sysinv/cluster/cluster_services_api.py b/sysinv/sysinv/sysinv/sysinv/cluster/cluster_services_api.py index 16efc5b47d..4961fb68e6 100644 --- a/sysinv/sysinv/sysinv/sysinv/cluster/cluster_services_api.py +++ b/sysinv/sysinv/sysinv/sysinv/cluster/cluster_services_api.py @@ -166,19 +166,19 @@ def get_cluster_controller_services(host_names, print_to_screen=False, for service in services.list: if print_to_screen: - print " " - print "servicename: %s" % service.name - print "status : %s" % service.state + print(" ") + print("servicename: %s" % service.name) + print("status : %s" % service.state) instances_data = [] for instance in service.instances: if print_to_screen: - print "\thostname: %s" % instance.host_name - print "\tactivity: %s" % instance.activity - print "\tstate : %s" % instance.state - print "\treason : %s" % instance.reason - print " " + print("\thostname: %s" % instance.host_name) + print("\tactivity: %s" % instance.activity) + print("\tstate : %s" % instance.state) + print("\treason : %s" % instance.reason) + print(" ") instances_data += ([{'hostname': instance.host_name, 'activity': instance.activity, @@ -190,7 +190,7 @@ def get_cluster_controller_services(host_names, print_to_screen=False, 'instances': instances_data}]) if print_json_str: - print (json.dumps(services_data)) + print(json.dumps(services_data)) return json.dumps(services_data) @@ -232,14 +232,14 @@ def get_cluster_controller_node_state(host_name, print_to_screen=False, state = "unknown" if print_to_screen: - print " " - print "%s state is %s" % (host_name, state) + print(" ") + print("%s state is %s" % (host_name, state)) # Build Json Data node_data = ({'hostname': host_name, 'state': state}) if print_json_str: - print (json.dumps(node_data)) + print(json.dumps(node_data)) return json.dumps(node_data) diff --git a/sysinv/sysinv/sysinv/sysinv/cmd/helm.py b/sysinv/sysinv/sysinv/sysinv/cmd/helm.py index f968afeea8..e16a2951fa 100644 --- a/sysinv/sysinv/sysinv/sysinv/cmd/helm.py +++ b/sysinv/sysinv/sysinv/sysinv/cmd/helm.py @@ -89,4 +89,4 @@ def main(): CONF.action.repository, CONF.action.namespace) except Exception as e: - print e + print(e) diff --git a/sysinv/sysinv/sysinv/sysinv/cmd/manage-partitions b/sysinv/sysinv/sysinv/sysinv/cmd/manage-partitions index 2ebfc0f9f9..dd60291c8c 100755 --- a/sysinv/sysinv/sysinv/sysinv/cmd/manage-partitions +++ b/sysinv/sysinv/sysinv/sysinv/cmd/manage-partitions @@ -151,7 +151,7 @@ def _gpt_table_present(device_node): output, _, _ = _command(["parted", "-s", device_node, "print"], device_node=device_node) if not re.search('Partition Table: gpt', output): - print "Format of disk node %s is not GPT, returning" % device_node + print("Format of disk node %s is not GPT, returning" % device_node) return False return True @@ -395,7 +395,7 @@ def _send_inventory_update(partition_update): sw_mismatch = os.environ.get('CONTROLLER_SW_VERSIONS_MISMATCH', None) hostname = socket.gethostname() if sw_mismatch and hostname == constants.CONTROLLER_1_HOSTNAME: - print "Don't send information to N-1 sysinv conductor, return." + print("Don't send information to N-1 sysinv conductor, return.") return ctxt = context.get_admin_context() @@ -411,14 +411,14 @@ def _send_inventory_update(partition_update): rpcapi.update_partition_information(ctxt, partition_update) break except Exception as ex: - print "Exception trying to contact sysinv conductor: %s: %s " % \ - (type(ex).__name__, str(ex)) + print("Exception trying to contact sysinv conductor: %s: %s " % + (type(ex).__name__, str(ex))) if num_of_try < max_tries and "Timeout" in type(ex).__name__: - print "Could not contact sysinv conductor, try one more time.." + print("Could not contact sysinv conductor, try one more time..") continue else: - print "Quit trying to send extra info to the conductor, " \ - "sysinv agent will provide this info later..." + print("Quit trying to send extra info to the conductor, " + "sysinv agent will provide this info later...") def _wipe_partition(disk_node, start_in_sectors, size_in_sectors, sector_size): @@ -472,7 +472,7 @@ def create_partitions(data, mode, pfile): _send_inventory_update(p) return - print data + print(data) json_body = json.loads(data) for p in json_body: @@ -484,8 +484,8 @@ def create_partitions(data, mode, pfile): # Obtain parted device and parted disk for the given disk device # path. if _partition_exists(part_device_path): - print "Partition %s already exists, returning." % \ - part_device_path + print("Partition %s already exists, returning." % + part_device_path) continue # If we only allow to add and remove partition to/from the end, @@ -493,7 +493,7 @@ def create_partitions(data, mode, pfile): # the beginning and the rest of the available disk, if any). free_spaces = _get_free_space(device_node=disk_device_path) if len(free_spaces) > 2: - print ("Disk %s is fragmented. Partition creation aborted." % + print("Disk %s is fragmented. Partition creation aborted." % disk_device_path) free_space = free_spaces[-1] @@ -501,7 +501,7 @@ def create_partitions(data, mode, pfile): number_of_partitions = _get_no_of_partitions(disk_device_path) # If this is the 1st partition, allocate an extra 1MiB. if number_of_partitions == 0: - print "First partition, use an extra MiB" + print("First partition, use an extra MiB") start_mib = 1 else: # Free space in sectors. @@ -787,8 +787,8 @@ def delete_partitions(data, mode, pfile): try: # Delete the partition. - print "Delete partition %s from %s" % (disk_device_path, - part_number) + print("Delete partition %s from %s" % (disk_device_path, + part_number)) _delete_partition(disk_device_path, part_number) disk_available_mib = _get_available_space(disk_device_path) response.update({'available_mib': disk_available_mib, @@ -836,8 +836,8 @@ def check_partitions(data, mode, pfile): lambda p, q: p.get('start_mib') - q.get('start_mib')): disk = _get_disk_device_path(p.get('device_path')) if _partition_exists(p.get('device_path')): - print 'Partition {} already exists on disk {}'.format( - p.get('device_path'), disk) + print('Partition {} already exists on disk {}'.format( + p.get('device_path'), disk)) continue partition_number = _get_partition_number(p.get('device_path')) _create_partition(disk, partition_number, p.get('start_mib'), @@ -881,7 +881,7 @@ def main(argv): "pfile": CONF.action.pfile, "data": CONF.action.data}) LOG.info(msg) - print msg + print(msg) run(CONF.action.func, CONF.action.data, CONF.action.mode, CONF.action.pfile) else: diff --git a/sysinv/sysinv/sysinv/sysinv/openstack/common/config/generator.py b/sysinv/sysinv/sysinv/sysinv/openstack/common/config/generator.py index d05658cc71..3d2aaf7b98 100755 --- a/sysinv/sysinv/sysinv/sysinv/openstack/common/config/generator.py +++ b/sysinv/sysinv/sysinv/sysinv/openstack/common/config/generator.py @@ -98,7 +98,7 @@ def generate(srcfiles): for group, opts in opts_by_group.items(): print_group_opts(group, opts) - print "# Total option count: %d" % OPTION_COUNT + print("# Total option count: %d" % OPTION_COUNT) def _import_module(mod_str): @@ -162,18 +162,18 @@ def _list_opts(obj): def print_group_opts(group, opts_by_module): - print "[%s]" % group - print + print("[%s]" % group) + print('') global OPTION_COUNT for mod, opts in opts_by_module: OPTION_COUNT += len(opts) - print '#' - print '# Options defined in %s' % mod - print '#' - print + print('#') + print('# Options defined in %s' % mod) + print('#') + print('') for opt in opts: _print_opt(opt) - print + print('') def _get_my_ip(): @@ -213,33 +213,33 @@ def _print_opt(opt): sys.stderr.write("%s\n" % str(err)) sys.exit(1) opt_help += ' (' + OPT_TYPES[opt_type] + ')' - print '#', "\n# ".join(textwrap.wrap(opt_help, WORDWRAP_WIDTH)) + print('#', "\n# ".join(textwrap.wrap(opt_help, WORDWRAP_WIDTH))) try: if opt_default is None: - print '#%s=' % opt_name + print('#%s=' % opt_name) elif opt_type == STROPT: assert(isinstance(opt_default, six.string_types)) - print '#%s=%s' % (opt_name, _sanitize_default(opt_default)) + print('#%s=%s' % (opt_name, _sanitize_default(opt_default))) elif opt_type == BOOLOPT: assert(isinstance(opt_default, bool)) - print '#%s=%s' % (opt_name, str(opt_default).lower()) + print('#%s=%s' % (opt_name, str(opt_default).lower())) elif opt_type == INTOPT: assert(isinstance(opt_default, int) and not isinstance(opt_default, bool)) - print '#%s=%s' % (opt_name, opt_default) + print('#%s=%s' % (opt_name, opt_default)) elif opt_type == FLOATOPT: assert(isinstance(opt_default, float)) - print '#%s=%s' % (opt_name, opt_default) + print('#%s=%s' % (opt_name, opt_default)) elif opt_type == LISTOPT: assert(isinstance(opt_default, list)) - print '#%s=%s' % (opt_name, ','.join(opt_default)) + print('#%s=%s' % (opt_name, ','.join(opt_default))) elif opt_type == MULTISTROPT: assert(isinstance(opt_default, list)) if not opt_default: opt_default = [''] for default in opt_default: - print '#%s=%s' % (opt_name, default) - print + print('#%s=%s' % (opt_name, default)) + print('') except Exception: sys.stderr.write('Error in option "%s"\n' % opt_name) sys.exit(1) @@ -247,7 +247,7 @@ def _print_opt(opt): def main(): if len(sys.argv) < 2: - print "usage: %s [srcfile]...\n" % sys.argv[0] + print("usage: %s [srcfile]...\n" % sys.argv[0]) sys.exit(0) generate(sys.argv[1:]) diff --git a/sysinv/sysinv/sysinv/tox.ini b/sysinv/sysinv/sysinv/tox.ini index 51db912b22..6e43fde213 100644 --- a/sysinv/sysinv/sysinv/tox.ini +++ b/sysinv/sysinv/sysinv/tox.ini @@ -66,7 +66,7 @@ commands = # H501: Do not use self.__dict__ for string formatting [flake8] ignore = E126,E127,E128,E402,E501, - H101,H102,H104,H105,H231,H232,H233,H234,H235,H236,H237,H238, + H101,H102,H104,H105,H231,H232,H234,H235,H236,H237,H238, H301,H306,H401,H403,H404,H405,H501 builtins = _