def parse_args(): """Parses the command line arguments passed to this script""" parser = argparse.ArgumentParser() parser.add_argument( '-d', '--duration', type=mesos_maintenance.parse_timedelta, default='1h', help= "Duration of the maintenance window. Any pytimeparse unit is supported.", ) parser.add_argument( '-s', '--start', type=mesos_maintenance.parse_datetime, default=str(mesos_maintenance.now()), help="Time to start the maintenance window. Defaults to now.", ) parser.add_argument( 'action', choices=[ 'cluster_status', 'down', 'drain', 'is_host_down', 'is_host_drained', 'is_host_draining', 'is_hosts_past_maintenance_end', 'is_hosts_past_maintenance_start', 'is_safe_to_drain', 'is_safe_to_kill', 'schedule', 'status', 'undrain', 'up', ], help="Action to perform on the specified hosts", ) parser.add_argument( 'hostname', nargs='*', default=[getfqdn()], help='Hostname(s) of machine(s) to start draining. ' 'You can specify <hostname>|<ip> to avoid querying DNS to determine the corresponding IP.', ) parser.add_argument( '-v', '--verbose', action='count', dest="verbose", default=0, help="Print out more output.", ) return parser.parse_args()
def parse_args(): """Parses the command line arguments passed to this script""" parser = argparse.ArgumentParser() parser.add_argument( "-d", "--duration", type=mesos_maintenance.parse_timedelta, default="1h", help= "Duration of the maintenance window. Any pytimeparse unit is supported.", ) parser.add_argument( "-s", "--start", type=mesos_maintenance.parse_datetime, default=str(mesos_maintenance.now()), help="Time to start the maintenance window. Defaults to now.", ) parser.add_argument( "action", choices=[ "cluster_status", "down", "drain", "is_host_down", "is_host_drained", "is_host_draining", "is_hosts_past_maintenance_end", "is_hosts_past_maintenance_start", "is_safe_to_drain", "is_safe_to_kill", "schedule", "status", "undrain", "up", ], help="Action to perform on the specified hosts", ) parser.add_argument( "hostname", nargs="*", default=[getfqdn()], help="Hostname(s) of machine(s) to start draining. " "You can specify <hostname>|<ip> to avoid querying DNS to determine the corresponding IP.", ) parser.add_argument( "-v", "--verbose", action="count", dest="verbose", default=0, help="Print out more output.", ) return parser.parse_args()
def mark_host_at_risk(context, host): start = mesos_maintenance.datetime_to_nanoseconds(mesos_maintenance.now()) duration = mesos_maintenance.parse_timedelta("1h") with contextlib.nested( mock.patch("paasta_tools.mesos_maintenance.get_principal", autospec=True), mock.patch("paasta_tools.mesos_maintenance.get_secret", autospec=True), ) as (mock_get_principal, mock_get_secret): credentials = mesos_maintenance.load_credentials(mesos_secrets="/etc/mesos-slave-secret") mock_get_principal.return_value = credentials.principal mock_get_secret.return_value = credentials.secret mesos_maintenance.drain([host], start, duration) context.at_risk_host = host
def mark_host_at_risk(context, host): start = mesos_maintenance.datetime_to_nanoseconds(mesos_maintenance.now()) duration = mesos_maintenance.parse_timedelta('1h') with mock.patch( 'paasta_tools.mesos_maintenance.get_principal', autospec=True, ) as mock_get_principal, mock.patch( 'paasta_tools.mesos_maintenance.get_secret', autospec=True, ) as mock_get_secret: credentials = mesos_maintenance.load_credentials(mesos_secrets='/etc/mesos-slave-secret') mock_get_principal.return_value = credentials.principal mock_get_secret.return_value = credentials.secret mesos_maintenance.drain([host], start, duration) context.at_risk_host = host
def parse_args(): """Parses the command line arguments passed to this script""" parser = argparse.ArgumentParser() parser.add_argument( '-d', '--duration', type=mesos_maintenance.parse_timedelta, default='1h', help="Duration of the maintenance window. Any pytimeparse unit is supported.", ) parser.add_argument( '-s', '--start', type=mesos_maintenance.parse_datetime, default=str(mesos_maintenance.now()), help="Time to start the maintenance window. Defaults to now.", ) parser.add_argument( 'action', choices=[ 'down', 'drain', 'is_host_down', 'is_host_drained', 'is_host_draining', 'is_hosts_past_maintenance_end', 'is_hosts_past_maintenance_start', 'is_safe_to_drain', 'is_safe_to_kill', 'schedule', 'status', 'undrain', 'up', ], help="Action to perform on the specifed hosts", ) parser.add_argument( 'hostname', nargs='*', default=[getfqdn()], help='Hostname(s) of machine(s) to start draining. ' 'You can specify <hostname>|<ip> to avoid querying DNS to determine the corresponding IP.', ) parser.add_argument( '-v', '--verbose', action='count', dest="verbose", default=0, help="Print out more output." ) return parser.parse_args()