#NEWLINE# @ task #NEWLINE# def reboot_server( name ) : #NEWLINE# #INDENT# '\n    Simply reboot a server by name.\n    The trick here is to change the env vars to that of the server\n    to be rebooted. Perform the reboot and change env vars back\n    to their original value.\n\n    Usage:\n        fab reboot_server:name\n    ' #NEWLINE# __shared_setup ( ) #NEWLINE# try : #NEWLINE# #INDENT# server = [ s for s in env . bootmachine_servers if ( s . name == name ) ] [ 0 ] #NEWLINE# #UNINDENT# except IndexError : #NEWLINE# #INDENT# abort ( "The server '{0}' was not found." . format ( name ) ) #NEWLINE# #UNINDENT# original_user = env . user #NEWLINE# original_host_string = env . host_string #NEWLINE# try : #NEWLINE# #INDENT# env . port = 22 #NEWLINE# telnetlib . Telnet ( server . public_ip , env . port ) #NEWLINE# env . user = 'root' #NEWLINE# #UNINDENT# except IOError : #NEWLINE# #INDENT# env . port = int ( settings . SSH_PORT ) #NEWLINE# env . user = getpass . getuser ( ) #NEWLINE# telnetlib . Telnet ( server . public_ip , env . port ) #NEWLINE# #UNINDENT# env . host_string = '{0}:{1}' . format ( server . public_ip , env . port ) #NEWLINE# env . keepalive = 30 #NEWLINE# with fabric_settings ( warn_only = True ) : #NEWLINE# #INDENT# reboot ( ) #NEWLINE# #UNINDENT# env . user = original_user #NEWLINE# env . host_string = original_host_string