Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 126 additions & 21 deletions Consul/Operator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// limitations under the License.
// </copyright>
// -----------------------------------------------------------------------
#pragma warning disable RS0026

using System;
using System.Collections.Generic;
using System.Threading;
Expand Down Expand Up @@ -155,11 +155,17 @@ private class KeyringRequest
/// <summary>
/// RaftGetConfiguration is used to query the current Raft peer set.
/// </summary>
public Task<QueryResult<RaftConfiguration>> RaftGetConfiguration(CancellationToken ct = default)
public Task<QueryResult<RaftConfiguration>> RaftGetConfiguration(CancellationToken ct)
{
return RaftGetConfiguration(QueryOptions.Default, ct);
}

// Add a parameterless overload for convenience
public Task<QueryResult<RaftConfiguration>> RaftGetConfiguration()
{
return RaftGetConfiguration(QueryOptions.Default, CancellationToken.None);
}

/// <summary>
/// RaftGetConfiguration is used to query the current Raft peer set.
/// </summary>
Expand All @@ -173,11 +179,16 @@ public Task<QueryResult<RaftConfiguration>> RaftGetConfiguration(QueryOptions q,
/// quorum but no longer known to Serf or the catalog) by address in the form of
/// "IP:port".
/// </summary>
public Task<WriteResult> RaftRemovePeerByAddress(string address, CancellationToken ct = default)
public Task<WriteResult> RaftRemovePeerByAddress(string address, CancellationToken ct)
{
return RaftRemovePeerByAddress(address, WriteOptions.Default, ct);
}

public Task<WriteResult> RaftRemovePeerByAddress(string address)
{
return RaftRemovePeerByAddress(address, WriteOptions.Default, CancellationToken.None);
}

/// <summary>
/// RaftRemovePeerByAddress is used to kick a stale peer (one that it in the Raft
/// quorum but no longer known to Serf or the catalog) by address in the form of
Expand All @@ -199,33 +210,48 @@ public Task<WriteResult> RaftRemovePeerByAddress(string address, WriteOptions q,
/// </summary>
/// <param name="ct">Cancellation token for the request</param>
/// <returns>A write result indicating the success of the operation</returns>
public Task<WriteResult> RaftTransferLeader(CancellationToken ct = default)
public Task<WriteResult> RaftTransferLeader(CancellationToken ct)
{
return RaftTransferLeader(WriteOptions.Default, ct);
}

public Task<WriteResult> RaftTransferLeader()
{
return RaftTransferLeader(WriteOptions.Default, CancellationToken.None);
}

/// <summary>
/// Transfers Raft leadership to another server with write options
/// </summary>
/// <param name="q">Write options including datacenter and token</param>
/// <param name="ct">Cancellation token for the request</param>
/// <returns>A write result indicating the success of the operation</returns>
public Task<WriteResult> RaftTransferLeader(WriteOptions q, CancellationToken ct = default)
public Task<WriteResult> RaftTransferLeader(WriteOptions q, CancellationToken ct)
{
return _client.Post<object>("/v1/operator/raft/transfer-leader", null, q).Execute(ct);
}

public Task<WriteResult> RaftTransferLeader(WriteOptions q)
{
return RaftTransferLeader(q, CancellationToken.None);
}

/// <summary>
/// Transfers Raft leadership to another server by ID
/// </summary>
/// <param name="id">The node ID of the Raft peer to transfer leadership to</param>
/// <param name="ct">Cancellation token for the request</param>
/// <returns>A write result indicating the success of the operation</returns>
public Task<WriteResult> RaftTransferLeader(string id, CancellationToken ct = default)
public Task<WriteResult> RaftTransferLeader(string id, CancellationToken ct)
{
return RaftTransferLeader(id, WriteOptions.Default, ct);
}

public Task<WriteResult> RaftTransferLeader(string id)
{
return RaftTransferLeader(id, WriteOptions.Default, CancellationToken.None);
}

/// <summary>
/// Transfers Raft leadership to another server by ID with write options
/// </summary>
Expand All @@ -243,11 +269,16 @@ public Task<WriteResult> RaftTransferLeader(string id, WriteOptions q, Cancellat
/// <summary>
/// KeyringInstall is used to install a new gossip encryption key into the cluster
/// </summary>
public Task<WriteResult> KeyringInstall(string key, CancellationToken ct = default)
public Task<WriteResult> KeyringInstall(string key, CancellationToken ct)
{
return KeyringInstall(key, WriteOptions.Default, ct);
}

public Task<WriteResult> KeyringInstall(string key)
{
return KeyringInstall(key, WriteOptions.Default, CancellationToken.None);
}

/// <summary>
/// KeyringInstall is used to install a new gossip encryption key into the cluster
/// </summary>
Expand All @@ -259,11 +290,16 @@ public Task<WriteResult> KeyringInstall(string key, WriteOptions q, Cancellation
/// <summary>
/// KeyringList is used to list the gossip keys installed in the cluster
/// </summary>
public Task<QueryResult<KeyringResponse[]>> KeyringList(CancellationToken ct = default)
public Task<QueryResult<KeyringResponse[]>> KeyringList(CancellationToken ct)
{
return KeyringList(QueryOptions.Default, ct);
}

public Task<QueryResult<KeyringResponse[]>> KeyringList()
{
return KeyringList(QueryOptions.Default, CancellationToken.None);
}

/// <summary>
/// KeyringList is used to list the gossip keys installed in the cluster
/// </summary>
Expand All @@ -275,11 +311,16 @@ public Task<QueryResult<KeyringResponse[]>> KeyringList(QueryOptions q, Cancella
/// <summary>
/// KeyringRemove is used to remove a gossip encryption key from the cluster
/// </summary>
public Task<WriteResult> KeyringRemove(string key, CancellationToken ct = default)
public Task<WriteResult> KeyringRemove(string key, CancellationToken ct)
{
return KeyringRemove(key, WriteOptions.Default, ct);
}

public Task<WriteResult> KeyringRemove(string key)
{
return KeyringRemove(key, WriteOptions.Default, CancellationToken.None);
}

/// <summary>
/// KeyringRemove is used to remove a gossip encryption key from the cluster
/// </summary>
Expand All @@ -291,11 +332,16 @@ public Task<WriteResult> KeyringRemove(string key, WriteOptions q, CancellationT
/// <summary>
/// KeyringUse is used to change the active gossip encryption key
/// </summary>
public Task<WriteResult> KeyringUse(string key, CancellationToken ct = default)
public Task<WriteResult> KeyringUse(string key, CancellationToken ct)
{
return KeyringUse(key, WriteOptions.Default, ct);
}

public Task<WriteResult> KeyringUse(string key)
{
return KeyringUse(key, WriteOptions.Default, CancellationToken.None);
}

/// <summary>
/// KeyringUse is used to change the active gossip encryption key
/// </summary>
Expand All @@ -320,19 +366,29 @@ public Task<QueryResult<string[]>> SegmentList(QueryOptions q, CancellationToken
/// <summary>
/// // SegmentList returns all the available LAN segments.
/// </summary>
public Task<QueryResult<string[]>> SegmentList(CancellationToken ct = default)
public Task<QueryResult<string[]>> SegmentList(CancellationToken ct)
{
return SegmentList(QueryOptions.Default, ct);
}

public Task<QueryResult<string[]>> SegmentList()
{
return SegmentList(QueryOptions.Default, CancellationToken.None);
}

/// <summary>
/// CreateArea will create a new network area, a generated ID will be returned on success.
/// </summary>
public Task<WriteResult<string>> AreaCreate(AreaRequest area, CancellationToken ct = default)
public Task<WriteResult<string>> AreaCreate(AreaRequest area, CancellationToken ct)
{
return AreaCreate(area, WriteOptions.Default, ct);
}

public Task<WriteResult<string>> AreaCreate(AreaRequest area)
{
return AreaCreate(area, WriteOptions.Default, CancellationToken.None);
}

/// <summary>
/// CreateArea will create a new network area, a generated ID will be returned on success.
/// </summary>
Expand All @@ -345,11 +401,16 @@ public async Task<WriteResult<string>> AreaCreate(AreaRequest area, WriteOptions
/// <summary>
/// AreaList returns all the available network areas
/// </summary>
public Task<QueryResult<List<Area>>> AreaList(CancellationToken ct = default)
public Task<QueryResult<List<Area>>> AreaList(CancellationToken ct)
{
return AreaList(QueryOptions.Default, ct);
}

public Task<QueryResult<List<Area>>> AreaList()
{
return AreaList(QueryOptions.Default, CancellationToken.None);
}

/// <summary>
/// AreaList returns all the available network areas
/// </summary>
Expand All @@ -360,10 +421,16 @@ public Task<QueryResult<List<Area>>> AreaList(QueryOptions q, CancellationToken
/// <summary>
/// AreaUpdate will update the configuration of the network area with the given area Id.
/// </summary>
public Task<WriteResult<string>> AreaUpdate(AreaRequest area, string areaId, CancellationToken ct = default)
public Task<WriteResult<string>> AreaUpdate(AreaRequest area, string areaId, CancellationToken ct)
{
return AreaUpdate(area, areaId, WriteOptions.Default, ct);
}

public Task<WriteResult<string>> AreaUpdate(AreaRequest area, string areaId)
{
return AreaUpdate(area, areaId, WriteOptions.Default, CancellationToken.None);
}

/// <summary>
/// AreaUpdate will update the configuration of the network area with the given area Id.
/// </summary>
Expand All @@ -375,10 +442,16 @@ public async Task<WriteResult<string>> AreaUpdate(AreaRequest area, string areaI
/// <summary>
/// AreaGet returns a single network area
/// </summary>
public Task<QueryResult<Area[]>> AreaGet(string areaId, CancellationToken ct = default)
public Task<QueryResult<Area[]>> AreaGet(string areaId, CancellationToken ct)
{
return AreaGet(areaId, QueryOptions.Default, ct);
}

public Task<QueryResult<Area[]>> AreaGet(string areaId)
{
return AreaGet(areaId, QueryOptions.Default, CancellationToken.None);
}

/// <summary>
/// AreaGet returns a single network area
/// </summary>
Expand All @@ -389,10 +462,16 @@ public Task<QueryResult<Area[]>> AreaGet(string areaId, QueryOptions q, Cancella
/// <summary>
/// AreaDelete deletes the given network area.
/// </summary>
public Task<WriteResult> AreaDelete(string areaId, CancellationToken ct = default)
public Task<WriteResult> AreaDelete(string areaId, CancellationToken ct)
{
return AreaDelete(areaId, WriteOptions.Default, ct);
}

public Task<WriteResult> AreaDelete(string areaId)
{
return AreaDelete(areaId, WriteOptions.Default, CancellationToken.None);
}

/// <summary>
/// AreaDelete deletes the given network area.
/// </summary>
Expand All @@ -406,11 +485,16 @@ public Task<WriteResult> AreaDelete(string areaId, WriteOptions q, CancellationT
/// </summary>
/// <param name="cancellationToken">Cancellation token for the request</param>
/// <returns>A query result containing the Autopilot configuration</returns>
public Task<QueryResult<AutopilotConfiguration>> AutopilotGetConfiguration(CancellationToken cancellationToken = default)
public Task<QueryResult<AutopilotConfiguration>> AutopilotGetConfiguration(CancellationToken cancellationToken)
{
return AutopilotGetConfiguration(null, cancellationToken);
}

public Task<QueryResult<AutopilotConfiguration>> AutopilotGetConfiguration()
{
return AutopilotGetConfiguration(null, CancellationToken.None);
}

/// <summary>
/// Retrieves the current Autopilot configuration with query options
/// </summary>
Expand All @@ -428,11 +512,16 @@ public Task<QueryResult<AutopilotConfiguration>> AutopilotGetConfiguration(Query
/// <param name="configuration">The autopilot configuration to set</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>The write result</returns>
public Task<WriteResult> AutopilotSetConfiguration(AutopilotConfiguration configuration, CancellationToken cancellationToken = default)
public Task<WriteResult> AutopilotSetConfiguration(AutopilotConfiguration configuration, CancellationToken cancellationToken)
{
return AutopilotSetConfiguration(configuration, WriteOptions.Default, cancellationToken);
}

public Task<WriteResult> AutopilotSetConfiguration(AutopilotConfiguration configuration)
{
return AutopilotSetConfiguration(configuration, WriteOptions.Default, CancellationToken.None);
}

/// <summary>
/// Updates the autopilot configuration of the cluster
/// </summary>
Expand All @@ -451,11 +540,16 @@ public async Task<WriteResult> AutopilotSetConfiguration(AutopilotConfiguration
/// </summary>
/// <param name="cancellationToken">Query parameters</param>
/// <returns>The autopilot health information</returns>
public Task<QueryResult<AutopilotHealth>> AutopilotGetHealth(CancellationToken cancellationToken = default)
public Task<QueryResult<AutopilotHealth>> AutopilotGetHealth(CancellationToken cancellationToken)
{
return AutopilotGetHealth(null, cancellationToken);
}

public Task<QueryResult<AutopilotHealth>> AutopilotGetHealth()
{
return AutopilotGetHealth(null, CancellationToken.None);
}

/// <summary>
/// Retrieves the autopilot health status of the cluster
/// </summary>
Expand All @@ -472,11 +566,16 @@ public Task<QueryResult<AutopilotHealth>> AutopilotGetHealth(QueryOptions q, Can
/// </summary>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>The autopilot state information</returns>
public Task<QueryResult<AutopilotState>> AutopilotGetState(CancellationToken cancellationToken = default)
public Task<QueryResult<AutopilotState>> AutopilotGetState(CancellationToken cancellationToken)
{
return AutopilotGetState(null, cancellationToken);
}

public Task<QueryResult<AutopilotState>> AutopilotGetState()
{
return AutopilotGetState(null, CancellationToken.None);
}

/// <summary>
/// Retrieves the autopilot state of the cluster
/// </summary>
Expand All @@ -488,10 +587,16 @@ public Task<QueryResult<AutopilotState>> AutopilotGetState(QueryOptions q, Cance
return _client.Get<AutopilotState>("/v1/operator/autopilot/state", q).Execute(cancellationToken);
}

public Task<QueryResult<OperatorUsageInformation>> OperatorGetUsage(CancellationToken cancellationToken = default)
public Task<QueryResult<OperatorUsageInformation>> OperatorGetUsage(CancellationToken cancellationToken)
{
return OperatorGetUsage(null, cancellationToken);
}

public Task<QueryResult<OperatorUsageInformation>> OperatorGetUsage()
{
return OperatorGetUsage(null, CancellationToken.None);
}

public Task<QueryResult<OperatorUsageInformation>> OperatorGetUsage(QueryOptions q,
CancellationToken cancellationToken = default)
{
Expand Down
Loading
Loading