Python 3 compatibility: convert raw_input to input

Story: 2003433
Task: 26063

Change-Id: Ia3739a55f36e614d6fe626fcd2917a9d6f6b2765
Signed-off-by: zhangyangyang <zhangyangyang@unionpay.com>
This commit is contained in:
zhangyangyang 2018-09-04 23:08:13 +08:00
parent 3a29c1170d
commit fd9a8a0714
8 changed files with 95 additions and 87 deletions

View File

@ -33,6 +33,7 @@ import openstack
import tsconfig.tsconfig as tsconfig
import utils
import sysinv_api as sysinv
from six.moves import input
LOG = log.get_logger(__name__)
@ -1348,7 +1349,7 @@ def restore_system(backup_file, clone=False):
print ("After the reboot is complete, " +
"re-execute the restore command.")
while True:
user_input = raw_input(
user_input = input(
"Enter 'reboot' to reboot controller: ")
if user_input == 'reboot':
break

View File

@ -14,6 +14,7 @@ import time
import configutilities.common.exceptions as cexeptions
import configutilities.common.utils as cutils
from six.moves import input
def is_valid_management_address(ip_address, management_subnet):
@ -80,7 +81,7 @@ def configure_management():
print
while True:
user_input = raw_input("Enter management interface name: ")
user_input = input("Enter management interface name: ")
if user_input in interface_list:
management_interface = user_input
break
@ -89,8 +90,8 @@ def configure_management():
continue
while True:
user_input = raw_input("Enter management IP address in CIDR "
"notation, ie. ip/prefix_length: ")
user_input = input("Enter management IP address in CIDR "
"notation, ie. ip/prefix_length: ")
try:
management_cidr = netaddr.IPNetwork(user_input)
management_ip = management_cidr.ip
@ -107,8 +108,8 @@ def configure_management():
"CIDR notation.")
while True:
user_input = raw_input("Enter management gateway IP address [" +
str(management_network[1]) + "]: ")
user_input = input("Enter management gateway IP address [" +
str(management_network[1]) + "]: ")
if user_input == "":
user_input = management_network[1]
@ -125,8 +126,8 @@ def configure_management():
min_addresses = 8
while True:
user_input = raw_input("Enter System Controller subnet in "
"CIDR notation: ")
user_input = input("Enter System Controller subnet in "
"CIDR notation: ")
try:
system_controller_subnet = cutils.validate_network_str(
user_input, min_addresses)

View File

@ -41,6 +41,7 @@ from common import constants
from common import log
from common.exceptions import KeystoneFail, SysInvFail
from common.exceptions import UserQuit
from six.moves import input
LOG = log.get_logger(__name__)
@ -59,7 +60,7 @@ def timestamped(dname, fmt='{dname}_%Y-%m-%d-%H-%M-%S'):
def prompt_for(prompt_text, default_input, validator):
valid = False
while not valid:
user_input = raw_input(prompt_text)
user_input = input(prompt_text)
if user_input.lower() == 'q':
raise UserQuit
elif user_input == "":
@ -545,7 +546,7 @@ class ConfigAssistant():
now.strftime(date_format))
while True:
user_input = raw_input(
user_input = input(
"\nIs the current date and time correct? [y/n]: ")
if user_input.lower() == 'q':
raise UserQuit
@ -559,8 +560,8 @@ class ConfigAssistant():
new_time = None
while True:
user_input = raw_input("\nEnter new system date and time (UTC) " +
"in YYYY-MM-DD HH:MM:SS format: \n")
user_input = input("\nEnter new system date and time (UTC) " +
"in YYYY-MM-DD HH:MM:SS format: \n")
if user_input.lower() == 'q':
raise UserQuit
else:
@ -600,7 +601,7 @@ class ConfigAssistant():
print
while True:
user_input = raw_input(
user_input = input(
"Please input the timezone[" + self.timezone + "]:")
if user_input == 'Q' or user_input == 'q':
@ -797,7 +798,7 @@ class ConfigAssistant():
while True:
print
user_input = raw_input(
user_input = input(
"Configure a separate PXEBoot network [y/N]: ")
if user_input.lower() == 'q':
raise UserQuit
@ -815,8 +816,8 @@ class ConfigAssistant():
if self.separate_pxeboot_network:
while True:
user_input = raw_input("PXEBoot subnet [" +
str(self.pxeboot_subnet) + "]: ")
user_input = input("PXEBoot subnet [" +
str(self.pxeboot_subnet) + "]: ")
if user_input.lower() == 'q':
raise UserQuit
elif user_input == "":
@ -891,7 +892,7 @@ class ConfigAssistant():
"interface link aggregation, for All-in-one duplex-direct."
)
print
user_input = raw_input(
user_input = input(
"Management interface link aggregation [y/N]: ")
if user_input.lower() == 'q':
raise UserQuit
@ -911,8 +912,8 @@ class ConfigAssistant():
if self.lag_management_interface:
self.management_interface = self.get_next_lag_name()
user_input = raw_input("Management interface [" +
str(self.management_interface) + "]: ")
user_input = input("Management interface [" +
str(self.management_interface) + "]: ")
if user_input.lower() == 'q':
raise UserQuit
elif user_input == "":
@ -943,8 +944,8 @@ class ConfigAssistant():
continue
while True:
user_input = raw_input("Management interface MTU [" +
str(self.management_mtu) + "]: ")
user_input = input("Management interface MTU [" +
str(self.management_mtu) + "]: ")
if user_input.lower() == 'q':
raise UserQuit
elif user_input == "":
@ -958,7 +959,7 @@ class ConfigAssistant():
continue
while True:
user_input = raw_input(
user_input = input(
"Management interface link capacity Mbps [" +
str(self.management_link_capacity) + "]: ")
if user_input.lower() == 'q':
@ -983,7 +984,7 @@ class ConfigAssistant():
print " 1) 802.3ad (LACP) policy"
print " 2) Active-backup policy"
user_input = raw_input(
user_input = input(
"\nManagement interface bonding policy [" +
str(self.lag_management_interface_policy) + "]: ")
if user_input.lower() == 'q':
@ -1012,7 +1013,7 @@ class ConfigAssistant():
"management interface.", 80)
print
user_input = raw_input(
user_input = input(
"First management interface member [" +
str(self.lag_management_interface_member0) + "]: ")
if user_input.lower() == 'q':
@ -1035,7 +1036,7 @@ class ConfigAssistant():
self.lag_management_interface_member0 = ""
continue
user_input = raw_input(
user_input = input(
"Second management interface member [" +
str(self.lag_management_interface_member1) + "]: ")
if user_input.lower() == 'q':
@ -1060,7 +1061,7 @@ class ConfigAssistant():
else:
print "Interface does not exist"
self.lag_management_interface_member1 = ""
user_input = raw_input(
user_input = input(
"Do you want a single physical member in the bond "
"interface [y/n]: ")
if user_input.lower() == 'q':
@ -1078,7 +1079,7 @@ class ConfigAssistant():
print
while True:
user_input = raw_input(
user_input = input(
"Management VLAN Identifier [" +
str(self.management_vlan) + "]: ")
if user_input.lower() == 'q':
@ -1094,8 +1095,8 @@ class ConfigAssistant():
min_addresses = 8
while True:
user_input = raw_input("Management subnet [" +
str(self.management_subnet) + "]: ")
user_input = input("Management subnet [" +
str(self.management_subnet) + "]: ")
if user_input.lower() == 'q':
raise UserQuit
elif user_input == "":
@ -1135,7 +1136,7 @@ class ConfigAssistant():
if (self.system_dc_role !=
sysinv_constants.DISTRIBUTED_CLOUD_ROLE_SYSTEMCONTROLLER):
while True:
user_input = raw_input(
user_input = input(
"Use entire management subnet [Y/n]: ")
if user_input.lower() == 'q':
raise UserQuit
@ -1163,7 +1164,7 @@ class ConfigAssistant():
self.management_start_address = self.management_subnet[2]
self.management_end_address = self.management_subnet[-2]
while True:
user_input = raw_input(
user_input = input(
"Management network start address [" +
str(self.management_start_address) + "]: ")
if user_input.lower() == 'q':
@ -1179,7 +1180,7 @@ class ConfigAssistant():
print ("Invalid start address. \n Reason: %s" % e)
while True:
user_input = raw_input(
user_input = input(
"Management network end address [" +
str(self.management_end_address) + "]: ")
if user_input == 'Q' or user_input == 'q':
@ -1233,7 +1234,7 @@ class ConfigAssistant():
"disables automatic provisioning of new hosts in System "
"Inventory, requiring the user to manually provision using "
"the 'system host-add' command. ", 80)
user_input = raw_input(
user_input = input(
"Dynamic IP address allocation [Y/n]: ")
if user_input.lower() == 'q':
raise UserQuit
@ -1299,9 +1300,9 @@ class ConfigAssistant():
self.management_multicast_subnet = \
IPNetwork(constants.DEFAULT_MULTICAST_SUBNET_IPV6)
user_input = raw_input("Management Network Multicast subnet [" +
str(self.management_multicast_subnet) +
"]: ")
user_input = input("Management Network Multicast subnet [" +
str(self.management_multicast_subnet) +
"]: ")
if user_input.lower() == 'q':
raise UserQuit
elif user_input == "":
@ -1388,7 +1389,7 @@ class ConfigAssistant():
infra_vlan_required = False
while True:
user_input = raw_input(
user_input = input(
"Configure an infrastructure interface [y/N]: ")
if user_input.lower() == 'q':
raise UserQuit
@ -1407,7 +1408,7 @@ class ConfigAssistant():
"An infrastructure bond interface provides redundant "
"connections for the infrastructure network.", 80)
print
user_input = raw_input(
user_input = input(
"Infrastructure interface link aggregation [y/N]: ")
if user_input.lower() == 'q':
raise UserQuit
@ -1425,8 +1426,8 @@ class ConfigAssistant():
if self.lag_infrastructure_interface:
self.infrastructure_interface = self.get_next_lag_name()
user_input = raw_input("Infrastructure interface [" +
str(self.infrastructure_interface) + "]: ")
user_input = input("Infrastructure interface [" +
str(self.infrastructure_interface) + "]: ")
if user_input.lower() == 'q':
raise UserQuit
elif user_input == '':
@ -1466,13 +1467,13 @@ class ConfigAssistant():
continue
while True:
user_input = raw_input(
user_input = input(
"Configure an infrastructure VLAN [y/N]: ")
if user_input.lower() == 'q':
raise UserQuit
elif user_input.lower() == 'y':
while True:
user_input = raw_input(
user_input = input(
"Infrastructure VLAN Identifier [" +
str(self.infrastructure_vlan) + "]: ")
if user_input.lower() == 'q':
@ -1508,8 +1509,8 @@ class ConfigAssistant():
continue
while True:
user_input = raw_input("Infrastructure interface MTU [" +
str(self.infrastructure_mtu) + "]: ")
user_input = input("Infrastructure interface MTU [" +
str(self.infrastructure_mtu) + "]: ")
if user_input.lower() == 'q':
raise UserQuit
elif user_input == "":
@ -1531,7 +1532,7 @@ class ConfigAssistant():
continue
while True:
user_input = raw_input(
user_input = input(
"Infrastructure interface link capacity Mbps [" +
str(self.infrastructure_link_capacity) + "]: ")
if user_input.lower() == 'q':
@ -1556,7 +1557,7 @@ class ConfigAssistant():
print " 2) Balanced XOR policy"
print " 3) 802.3ad (LACP) policy"
user_input = raw_input(
user_input = input(
"\nInfrastructure interface bonding policy [" +
str(self.lag_infrastructure_interface_policy) + "]: ")
if user_input.lower() == 'q':
@ -1593,7 +1594,7 @@ class ConfigAssistant():
"infrastructure interface.", 80)
print
user_input = raw_input(
user_input = input(
"First infrastructure interface member [" +
str(self.lag_infrastructure_interface_member0) + "]: ")
if user_input.lower() == 'q':
@ -1616,7 +1617,7 @@ class ConfigAssistant():
self.lag_infrastructure_interface_member0 = ""
continue
user_input = raw_input(
user_input = input(
"Second infrastructure interface member [" +
str(self.lag_infrastructure_interface_member1) + "]: ")
if user_input.lower() == 'q':
@ -1642,7 +1643,7 @@ class ConfigAssistant():
else:
print "Interface does not exist"
self.lag_infrastructure_interface_member1 = ""
user_input = raw_input(
user_input = input(
"Do you want a single physical member in the bond "
"interface [y/n]: ")
if user_input.lower() == 'q':
@ -1657,8 +1658,8 @@ class ConfigAssistant():
min_addresses = 8
while True:
user_input = raw_input("Infrastructure subnet [" +
str(self.infrastructure_subnet) + "]: ")
user_input = input("Infrastructure subnet [" +
str(self.infrastructure_subnet) + "]: ")
if user_input.lower() == 'q':
raise UserQuit
elif user_input == "":
@ -1700,7 +1701,7 @@ class ConfigAssistant():
self.infrastructure_end_address = \
self.infrastructure_subnet[-2]
while True:
user_input = raw_input(
user_input = input(
"Use entire infrastructure subnet [Y/n]: ")
if user_input.lower() == 'q':
raise UserQuit
@ -1719,7 +1720,7 @@ class ConfigAssistant():
if not self.use_entire_infra_subnet:
while True:
while True:
user_input = raw_input(
user_input = input(
"Infrastructure network start address [" +
str(self.infrastructure_start_address) + "]: ")
if user_input.lower() == 'q':
@ -1736,7 +1737,7 @@ class ConfigAssistant():
print ("Invalid start address. \n Reason: %s" % e)
while True:
user_input = raw_input(
user_input = input(
"Infrastructure network end address [" +
str(self.infrastructure_end_address) + "]: ")
if user_input.lower() == 'q':
@ -1842,7 +1843,7 @@ class ConfigAssistant():
def input_aio_simplex_oam_ip_address(self):
"""Allow user to input external OAM IP and perform validation."""
while True:
user_input = raw_input(
user_input = input(
"External OAM address [" +
str(self.external_oam_gateway_address + 1) + "]: ")
if user_input.lower() == 'q':
@ -1867,7 +1868,7 @@ class ConfigAssistant():
def input_oam_ip_address(self):
"""Allow user to input external OAM IP and perform validation."""
while True:
user_input = raw_input(
user_input = input(
"External OAM floating address [" +
str(self.external_oam_gateway_address + 1) + "]: ")
if user_input.lower() == 'q':
@ -1888,10 +1889,10 @@ class ConfigAssistant():
)
while True:
user_input = raw_input("External OAM address for first "
"controller node [" +
str(self.external_oam_floating_address + 1)
+ "]: ")
user_input = input("External OAM address for first "
"controller node [" +
str(self.external_oam_floating_address + 1)
+ "]: ")
if user_input.lower() == 'q':
raise UserQuit
elif user_input == "":
@ -1910,10 +1911,10 @@ class ConfigAssistant():
)
while True:
user_input = raw_input("External OAM address for second "
"controller node [" +
str(self.external_oam_address_0 + 1) +
"]: ")
user_input = input("External OAM address for second "
"controller node [" +
str(self.external_oam_address_0 + 1) +
"]: ")
if user_input.lower() == 'q':
raise UserQuit
elif user_input == "":
@ -1950,7 +1951,7 @@ class ConfigAssistant():
"An external OAM bond interface provides redundant "
"connections for the OAM network.", 80)
print
user_input = raw_input(
user_input = input(
"External OAM interface link aggregation [y/N]: ")
if user_input.lower() == 'q':
raise UserQuit
@ -1970,8 +1971,8 @@ class ConfigAssistant():
if self.lag_external_oam_interface:
self.external_oam_interface = self.get_next_lag_name()
user_input = raw_input("External OAM interface [" +
str(self.external_oam_interface) + "]: ")
user_input = input("External OAM interface [" +
str(self.external_oam_interface) + "]: ")
if user_input.lower() == 'q':
raise UserQuit
elif user_input == "":
@ -2010,13 +2011,13 @@ class ConfigAssistant():
continue
while True:
user_input = raw_input(
user_input = input(
"Configure an external OAM VLAN [y/N]: ")
if user_input.lower() == 'q':
raise UserQuit
elif user_input.lower() == 'y':
while True:
user_input = raw_input(
user_input = input(
"External OAM VLAN Identifier [" +
str(self.external_oam_vlan) + "]: ")
if user_input.lower() == 'q':
@ -2053,8 +2054,8 @@ class ConfigAssistant():
continue
while True:
user_input = raw_input("External OAM interface MTU [" +
str(self.external_oam_mtu) + "]: ")
user_input = input("External OAM interface MTU [" +
str(self.external_oam_mtu) + "]: ")
if user_input.lower() == 'q':
raise UserQuit
elif user_input == "":
@ -2102,7 +2103,7 @@ class ConfigAssistant():
print " 2) Balanced XOR policy"
print " 3) 802.3ad (LACP) policy"
user_input = raw_input(
user_input = input(
"\nExternal OAM interface bonding policy [" +
str(self.lag_external_oam_interface_policy) + "]: ")
if user_input.lower() == 'q':
@ -2138,7 +2139,7 @@ class ConfigAssistant():
"external OAM interface.", 80)
print
user_input = raw_input(
user_input = input(
"First external OAM interface member [" +
str(self.lag_external_oam_interface_member0) + "]: ")
if user_input.lower() == 'q':
@ -2161,7 +2162,7 @@ class ConfigAssistant():
self.lag_external_oam_interface_member0 = ""
continue
user_input = raw_input(
user_input = input(
"Second external oam interface member [" +
str(self.lag_external_oam_interface_member1) + "]: ")
if user_input.lower() == 'q':
@ -2186,7 +2187,7 @@ class ConfigAssistant():
else:
print "Interface does not exist"
self.lag_external_oam_interface_member1 = ""
user_input = raw_input(
user_input = input(
"Do you want a single physical member in the bond "
"interface [y/n]: ")
if user_input.lower() == 'q':
@ -2197,8 +2198,8 @@ class ConfigAssistant():
continue
while True:
user_input = raw_input("External OAM subnet [" +
str(self.external_oam_subnet) + "]: ")
user_input = input("External OAM subnet [" +
str(self.external_oam_subnet) + "]: ")
if user_input.lower() == 'q':
raise UserQuit
elif user_input == "":
@ -2216,8 +2217,8 @@ class ConfigAssistant():
)
while True:
user_input = raw_input("External OAM gateway address [" +
str(self.external_oam_subnet[1]) + "]: ")
user_input = input("External OAM gateway address [" +
str(self.external_oam_subnet[1]) + "]: ")
if user_input.lower() == 'q':
raise UserQuit
elif user_input == "":
@ -4589,7 +4590,7 @@ class ConfigAssistant():
if not configfile and not default_config:
while True:
user_input = raw_input(
user_input = input(
"\nApply the above configuration? [y/n]: ")
if user_input.lower() == 'q':
raise UserQuit

View File

@ -46,6 +46,7 @@ from functools import wraps
from wrapping_formatters import _get_width
from cgtsclient.common import wrapping_formatters
from six.moves import input
class HelpFormatter(argparse.HelpFormatter):
@ -277,7 +278,7 @@ def pt_builder(field_labels, fields, formatters, paging, printer=default_printer
if self.terminal_lines_left > 0:
printer("\n" * (self.terminal_lines_left - 1))
s = raw_input("Press Enter to continue or 'q' to exit...")
s = input("Press Enter to continue or 'q' to exit...")
if s == 'q':
self.quit = True
return False

View File

@ -23,6 +23,7 @@ from cgtsclient.v1 import ihost as ihost_utils
from cgtsclient.v1 import iinterface as iinterface_utils
from cgtsclient.v1 import iprofile as iprofile_utils
from cgtsclient.v1 import istor as istor_utils
from six.moves import input
def _print_ihost_show(ihost):
@ -694,7 +695,7 @@ def do_host_downgrade(cc, args):
'Only proceed once the system data has been copied to another '
'system.\n'
'Are you absolutely sure you want to continue? [yes/N]: ')
confirm = raw_input(warning_message)
confirm = input(warning_message)
if confirm != 'yes':
print "Operation cancelled."
return
@ -723,7 +724,7 @@ def do_host_upgrade(cc, args):
'Only proceed once the system data has been copied to another '
'system.\n'
'Are you absolutely sure you want to continue? [yes/N]: ')
confirm = raw_input(warning_message)
confirm = input(warning_message)
if confirm != 'yes':
print "Operation cancelled."
return

View File

@ -15,6 +15,7 @@ from cgtsclient.common import utils
from cgtsclient import exc
from cgtsclient.v1 import ihost as ihost_utils
import math
from six.moves import input
def _print_idisk_show(idisk):
@ -103,7 +104,7 @@ def do_host_disk_wipe(cc, args):
("WARNING: This operation is irreversible and all data on the "
"specified disk will be lost.\n"
"Continue [yes/N]: ")
confirm = raw_input(warning_message)
confirm = input(warning_message)
if confirm != 'yes':
print "Operation cancelled."
return

View File

@ -13,6 +13,7 @@
from cgtsclient.common import constants
from cgtsclient.common import utils
from cgtsclient import exc
from six.moves import input
def _print_isystem_show(isystem):
@ -126,7 +127,7 @@ def do_modify(cc, args):
'before continue.\n'
'Are you sure you want to continue [yes/N]: ' % mode_text)
confirm = raw_input(warning_message)
confirm = input(warning_message)
if confirm != 'yes':
print "Operation cancelled."
return

View File

@ -12,6 +12,7 @@
from cgtsclient.common import constants
from cgtsclient.common import utils
from cgtsclient import exc
from six.moves import input
def _print_upgrade_show(obj):
@ -128,12 +129,12 @@ def do_upgrade_abort(cc, args):
'revert to the state when controller-0 was last active.\n\n'
'Continue [yes/N]: ')
confirm = raw_input(warning_message)
confirm = input(warning_message)
if confirm != 'yes':
print "Operation cancelled."
return
elif abort_required:
confirm = raw_input("Type 'abort' to confirm: ")
confirm = input("Type 'abort' to confirm: ")
if confirm != 'abort':
print "Operation cancelled."
return