(operator_client, hostnames, start=None, duration=None, drain=True)
return {
        "type": "UPDATE_MAINTENANCE_SCHEDULE",
        "update_maintenance_schedule": {"schedule": payload},
    }
Creates the JSON payload needed to (un)schedule maintenance on the specified hostnames.
    :param hostnames: a list of hostnames
    :param start: the time to start the maintenance, represented as number of nanoseconds since the epoch
    :param duration: length of the maintenance window, represented as number of nanoseconds since the epoch
    :param drain: boolean to note whether we are draining (True) the specified hosts or undraining (False) them
    :returns: a dictionary that can be sent to Mesos to (un)schedule maintenance
Creates the JSON payload needed to (un)schedule maintenance on the specified hostnames.
    :param hostnames: a list of hostnames
    :param start: the time to start the maintenance, represented as number of nanoseconds since the epoch
    :param duration: length of the maintenance window, represented as number of nanoseconds since the epoch
    :param drain: boolean to note whether we are draining (True) the specified hosts or undraining (False) them
    :returns: a dictionary that can be sent to Mesos to (un)schedule maintenance
Creates the JSON payload needed to ( un ) schedule maintenance on the specified hostnames . : param hostnames : a list of hostnames : param start : the time to start the maintenance represented as number of nanoseconds since the epoch : param duration : length of the maintenance window represented as number of nanoseconds since the epoch : param drain : boolean to note whether we are draining ( True ) the specified hosts or undraining ( False ) them : returns : a dictionary that can be sent to Mesos to ( un ) schedule maintenance
def build_maintenance_schedule_payload(operator_client, hostnames, start=None, duration=None, drain=True):
    """Creates the JSON payload needed to (un)schedule maintenance on the specified hostnames.
    :param hostnames: a list of hostnames
    :param start: the time to start the maintenance, represented as number of nanoseconds since the epoch
    :param duration: length of the maintenance window, represented as number of nanoseconds since the epoch
    :param drain: boolean to note whether we are draining (True) the specified hosts or undraining (False) them
    :returns: a dictionary that can be sent to Mesos to (un)schedule maintenance
    """
    schedule = get_maintenance_schedule(operator_client).json()["get_maintenance_schedule"]["schedule"]
    machine_ids = get_machine_ids(hostnames)

    if drain:
        unavailability = {
            "start": {"nanoseconds": int(start)},
            "duration": {"nanoseconds": int(duration)},
        }
        window = {"machine_ids": machine_ids, "unavailability": unavailability}

    if schedule:
        for existing_window in schedule["windows"]:
            for existing_machine_id in existing_window["machine_ids"]:
                # If we already have a maintenance window scheduled for one of the hosts,
                # replace it with the new window.
                if existing_machine_id in machine_ids:
                    existing_window["machine_ids"].remove(existing_machine_id)
                    if not existing_window["machine_ids"]:
                        schedule["windows"].remove(existing_window)
        if drain:
            windows = schedule["windows"] + [window]
        else:
            windows = schedule["windows"]
    elif drain:
        windows = [window]
    else:
        windows = []

    payload = {"windows": windows}

    return {
        "type": "UPDATE_MAINTENANCE_SCHEDULE",
        "update_maintenance_schedule": {"schedule": payload},
    }
def build_maintenance_schedule_payload ( operator_client , hostnames , start = None , duration = None , drain = True ) : schedule = get_maintenance_schedule ( operator_client ) . json ( ) [ "get_maintenance_schedule" ] [ "schedule" ] machine_ids = get_machine_ids ( hostnames ) if drain : unavailability = { "start" : { "nanoseconds" : int ( start ) } , "duration" : { "nanoseconds" : int ( duration ) } , } window = { "machine_ids" : machine_ids , "unavailability" : unavailability } if schedule : for existing_window in schedule [ "windows" ] : for existing_machine_id in existing_window [ "machine_ids" ] : # If we already have a maintenance window scheduled for one of the hosts, # replace it with the new window. if existing_machine_id in machine_ids : existing_window [ "machine_ids" ] . remove ( existing_machine_id ) if not existing_window [ "machine_ids" ] : schedule [ "windows" ] . remove ( existing_window ) if drain : windows = schedule [ "windows" ] + [ window ] else : windows = schedule [ "windows" ] elif drain : windows = [ window ] else : windows = [ ] payload = { "windows" : windows } return { "type" : "UPDATE_MAINTENANCE_SCHEDULE" , "update_maintenance_schedule" : { "schedule" : payload } , }