コード例 #1
0
def paasta_maintenance():
    """Manipulate the maintenance state of a PaaSTA host.
    :returns: None
    """
    args = parse_args()

    if args.verbose >= 2:
        logging.basicConfig(level=logging.DEBUG)
    elif args.verbose == 1:
        logging.basicConfig(level=logging.INFO)
    else:
        logging.basicConfig(level=logging.WARNING)

    action = args.action
    hostnames = args.hostname

    if action != 'status' and not hostnames:
        paasta_print("You must specify one or more hostnames")
        return

    start = args.start
    duration = args.duration

    ret = "Done"
    if action == 'drain':
        mesos_maintenance.drain(hostnames, start, duration)
    elif action == 'undrain':
        mesos_maintenance.undrain(hostnames)
    elif action == 'down':
        mesos_maintenance.down(hostnames)
    elif action == 'up':
        mesos_maintenance.up(hostnames)
    elif action == 'status':
        ret = mesos_maintenance.friendly_status()
    elif action == 'cluster_status':
        ret = mesos_maintenance.status()
    elif action == 'schedule':
        ret = mesos_maintenance.schedule()
    elif action == 'is_safe_to_drain':
        ret = is_safe_to_drain(hostnames[0])
    elif action == 'is_safe_to_kill':
        ret = is_safe_to_kill(hostnames[0])
    elif action == 'is_host_drained':
        ret = mesos_maintenance.is_host_drained(hostnames[0])
    elif action == 'is_host_down':
        ret = mesos_maintenance.is_host_down(hostnames[0])
    elif action == 'is_host_draining':
        ret = mesos_maintenance.is_host_draining(hostnames[0])
    elif action == 'is_host_past_maintenance_start':
        ret = mesos_maintenance.is_host_past_maintenance_start(hostnames[0])
    elif action == 'is_host_past_maintenance_end':
        ret = mesos_maintenance.is_host_past_maintenance_end(hostnames[0])
    else:
        raise NotImplementedError("Action: '%s' is not implemented." % action)
    paasta_print(ret)
    return ret
コード例 #2
0
ファイル: paasta_maintenance.py プロジェクト: somic/paasta
def paasta_maintenance():
    """Manipulate the maintenance state of a PaaSTA host.
    :returns: None
    """
    args = parse_args()

    if args.verbose >= 2:
        logging.basicConfig(level=logging.DEBUG)
    elif args.verbose == 1:
        logging.basicConfig(level=logging.INFO)
    else:
        logging.basicConfig(level=logging.WARNING)

    action = args.action
    hostnames = args.hostname

    if action != 'status' and not hostnames:
        paasta_print("You must specify one or more hostnames")
        return

    start = args.start
    duration = args.duration

    ret = "Done"
    if action == 'drain':
        mesos_maintenance.drain(hostnames, start, duration)
    elif action == 'undrain':
        mesos_maintenance.undrain(hostnames)
    elif action == 'down':
        mesos_maintenance.down(hostnames)
    elif action == 'up':
        mesos_maintenance.up(hostnames)
    elif action == 'status':
        ret = "%s" % mesos_maintenance.status()
    elif action == 'schedule':
        ret = "%s" % mesos_maintenance.schedule()
    elif action == 'is_safe_to_drain':
        ret = is_safe_to_drain(hostnames[0])
    elif action == 'is_safe_to_kill':
        ret = is_safe_to_kill(hostnames[0])
    elif action == 'is_host_drained':
        ret = mesos_maintenance.is_host_drained(hostnames[0])
    elif action == 'is_host_down':
        ret = mesos_maintenance.is_host_down(hostnames[0])
    elif action == 'is_host_draining':
        ret = mesos_maintenance.is_host_draining(hostnames[0])
    elif action == 'is_host_past_maintenance_start':
        ret = mesos_maintenance.is_host_past_maintenance_start(hostnames[0])
    elif action == 'is_host_past_maintenance_end':
        ret = mesos_maintenance.is_host_past_maintenance_end(hostnames[0])
    else:
        raise NotImplementedError("Action: '%s' is not implemented." % action)
    paasta_print(ret)
    return ret
コード例 #3
0
ファイル: test_mesos_maintenance.py プロジェクト: Yelp/paasta
def test_down(mock_build_maintenance_payload, mock_operator_api):
    fake_payload = [{"fake_schedule": "fake_value"}]
    mock_build_maintenance_payload.return_value = fake_payload
    down(hostnames=["some-host"])
    assert mock_build_maintenance_payload.call_count == 1
    assert mock_build_maintenance_payload.call_args == mock.call(
        ["some-host"], "start_maintenance")
    assert mock_operator_api.call_count == 1
    assert mock_operator_api.return_value.call_count == 1
    expected_args = mock.call(data=fake_payload)
    assert mock_operator_api.return_value.call_args == expected_args
コード例 #4
0
def test_down(
    mock_build_start_maintenance_payload,
    mock_master_api,
):
    fake_payload = [{'fake_schedule': 'fake_value'}]
    mock_build_start_maintenance_payload.return_value = fake_payload
    down(hostnames=['some-host'])
    assert mock_build_start_maintenance_payload.call_count == 1
    assert mock_build_start_maintenance_payload.call_args == mock.call(['some-host'])
    assert mock_master_api.call_count == 1
    assert mock_master_api.return_value.call_count == 1
    expected_args = mock.call(method="POST", endpoint="/machine/down", data=json.dumps(fake_payload))
    assert mock_master_api.return_value.call_args == expected_args
コード例 #5
0
def test_down(
    mock_build_maintenance_payload,
    mock_operator_api,
):
    fake_payload = [{'fake_schedule': 'fake_value'}]
    mock_build_maintenance_payload.return_value = fake_payload
    down(hostnames=['some-host'])
    assert mock_build_maintenance_payload.call_count == 1
    assert mock_build_maintenance_payload.call_args == mock.call(['some-host'], 'start_maintenance')
    assert mock_operator_api.call_count == 1
    assert mock_operator_api.return_value.call_count == 1
    expected_args = mock.call(data=fake_payload)
    assert mock_operator_api.return_value.call_args == expected_args
コード例 #6
0
def test_down(
    mock_build_start_maintenance_payload,
    mock_master_api,
):
    fake_payload = [{'fake_schedule': 'fake_value'}]
    mock_build_start_maintenance_payload.return_value = fake_payload
    down(hostnames=['some-host'])
    assert mock_build_start_maintenance_payload.call_count == 1
    assert mock_build_start_maintenance_payload.call_args == mock.call(['some-host'])
    assert mock_master_api.call_count == 1
    assert mock_master_api.return_value.call_count == 1
    expected_args = mock.call(method="POST", endpoint="/machine/down", data=json.dumps(fake_payload))
    assert mock_master_api.return_value.call_args == expected_args