@@ -4481,15 +4481,27 @@ def get_parser(self, prog_name):
44814481 '(repeat option to set multiple properties)'
44824482 ),
44834483 )
4484+ parser .add_argument (
4485+ '--auto-approve' ,
4486+ action = 'store_true' ,
4487+ help = _ (
4488+ "Allow server state override without asking for confirmation"
4489+ ),
4490+ )
44844491 parser .add_argument (
44854492 '--state' ,
44864493 metavar = '<state>' ,
44874494 choices = ['active' , 'error' ],
44884495 help = _ (
4489- 'New server state '
4490- '**WARNING** This can result in instances that are no longer '
4491- 'usable and should be used with caution '
4492- '(admin only)'
4496+ 'New server state.'
4497+ '**WARNING** Resetting the state is intended to work around '
4498+ 'servers stuck in an intermediate state, such as deleting. '
4499+ 'If the server is in an error state then this is almost '
4500+ 'never the correct command to run and you should prefer hard '
4501+ 'reboot where possible. In particular, if the server is in '
4502+ 'an error state due to a move operation, setting the state '
4503+ 'can result in instances that are no longer usable. Proceed '
4504+ 'with caution. (admin only)'
44934505 ),
44944506 )
44954507 parser .add_argument (
@@ -4524,6 +4536,20 @@ def get_parser(self, prog_name):
45244536 )
45254537 return parser
45264538
4539+ @staticmethod
4540+ def ask_user_yesno (msg ):
4541+ """Ask user Y/N question
4542+
4543+ :param str msg: question text
4544+ :return bool: User choice
4545+ """
4546+ while True :
4547+ answer = getpass .getpass ('{} [{}]: ' .format (msg , 'y/n' ))
4548+ if answer in ('y' , 'Y' , 'yes' ):
4549+ return True
4550+ elif answer in ('n' , 'N' , 'no' ):
4551+ return False
4552+
45274553 def take_action (self , parsed_args ):
45284554 compute_client = self .app .client_manager .compute
45294555 server = compute_client .find_server (
@@ -4574,6 +4600,17 @@ def take_action(self, parsed_args):
45744600 )
45754601
45764602 if parsed_args .state :
4603+ if not parsed_args .auto_approve :
4604+ if not self .ask_user_yesno (
4605+ _ (
4606+ "Resetting the server state can make it much harder "
4607+ "to recover a server from an error state. If the "
4608+ "server is in error status due to a failed move "
4609+ "operation then this is likely not the correct "
4610+ "approach to fix the problem. Do you wish to continue?"
4611+ )
4612+ ):
4613+ return
45774614 compute_client .reset_server_state (server , state = parsed_args .state )
45784615
45794616 if parsed_args .root_password :
0 commit comments