This library supports managing Microsoft Azure Stack HCI resources.
This library follows the new Azure SDK guidelines, and provides many core capabilities:
- Support MSAL.NET, Azure.Identity is out of box for supporting MSAL.NET.
- Support [OpenTelemetry](https://opentelemetry.io/) for distributed tracing.
- HTTP pipeline with custom policies.
- Better error-handling.
- Support uniform telemetry across all languages.
Install the Azure Stack HCI management library for .NET with NuGet:
dotnet add package Azure.ResourceManager.Hci
- You must have an Microsoft Azure subscription.
To create an authenticated client and start interacting with Microsoft Azure resources, see the quickstart guide here.
Key concepts of the Microsoft Azure SDK for .NET can be found here.
Documentation is available to help you learn how to use this package:
- Get the Azure token
TokenCredential cred = new DefaultAzureCredential();
ArmClient client = new ArmClient(cred);
- Update the parameters given below
string subscription = "00000000-0000-0000-0000-000000000000"; // Replace with your subscription ID
string resourceGroupName = "hcicluster-rg"; // Replace with your resource group name
- Update the parameters given below
string clusterName = "HCICluster"; // Replace with your cluster name
// Create the Payload and invoke the operation
string extensionName = "AzureMonitorWindowsAgent";
string publisherName = "Microsoft.Azure.Monitor";
string arcExtensionName = "AzureMonitorWindowsAgent";
string typeHandlerVersion = "1.10";
string workspaceId = "xx";// workspace id for the log analytics workspace to be used with AMA extension
string workspaceKey = "xx";// workspace key for the log analytics workspace to be used with AMA extension
bool enableAutomaticUpgrade = false;
ArcExtensionData data = new ArcExtensionData()
{
Publisher = publisherName,
ArcExtensionType = arcExtensionName,
TypeHandlerVersion = typeHandlerVersion,
Settings = BinaryData.FromObjectAsJson(new Dictionary<string, object>()
{
["workspaceId"] = workspaceId
}),
ProtectedSettings = BinaryData.FromObjectAsJson(new Dictionary<string, object>()
{
["workspaceKey"] = workspaceKey
}),
EnableAutomaticUpgrade = enableAutomaticUpgrade,
};
ResourceIdentifier arcSettingResourceId = ArcSettingResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, clusterName, "default");
ArcSettingResource arcSetting = client.GetArcSettingResource(arcSettingResourceId);
ArcExtensionCollection collection = arcSetting.GetArcExtensions();
// Create the Extension
ArcExtensionResource result = (await collection.CreateOrUpdateAsync(WaitUntil.Completed, extensionName, data)).Value;
// For installing Windows Admin Center, we need to enable network connectivity first
bool isEnabled = true;
ArcSettingPatch patch = new ArcSettingPatch()
{
ConnectivityProperties = BinaryData.FromObjectAsJson(new Dictionary<string, object>()
{
["enabled"] = true
})
};
ArcSettingResource result1 = await arcSetting.UpdateAsync(patch);
// Create the payload and invoke the operation
string extensionName = "AdminCenter";
string publisherName = "Microsoft.AdminCenter";
string arcExtensionType = "AdminCenter";
string typeHandlerVersion = "1.10";
string portNumber = "6516"; //port to be associated with WAC
bool enableAutoUpgrade = false; // change to true to enable automatic upgrade
ArcExtensionData data = new ArcExtensionData()
{
Publisher = publisherName,
ArcExtensionType = arcExtensionType,
TypeHandlerVersion = typeHandlerVersion,
Settings = BinaryData.FromObjectAsJson(new Dictionary<string, object>()
{
["port"] = portNumber
}),
EnableAutomaticUpgrade = enableAutoUpgrade,
};
ResourceIdentifier arcSettingResourceId = ArcSettingResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, clusterName, "default");
ArcSettingResource arcSetting = client.GetArcSettingResource(arcSettingResourceId);
ArcExtensionCollection collection = arcSetting.GetArcExtensions();
// Create the Extension
ArcExtensionResource result = (await collection.CreateOrUpdateAsync(WaitUntil.Completed, extensionName, data)).Value;
// Create the Payload
string publisherName = "Microsoft.SiteRecovery.Dra";
string arcExtensionType = "Windows";
string extensionName = "AzureSiteRecovery";
string env = "AzureCloud";
string subscriptionId = "your SubscriptionId";
string resourceGroup = "your ResourceGroup";
string resourceName = "your site recovery vault name";
string location = "your site recovery region";
string siteId = "Id for your recovery site";
string siteName = "ypur recovery site name";
string policyId = "your resource id for recovery site policy";
string pvtEndpointState = "None";
bool enableAutoUpgrade = false;
ArcExtensionData data = new ArcExtensionData()
{
Publisher = publisherName,
ArcExtensionType = arcExtensionType,
Settings = BinaryData.FromObjectAsJson(new Dictionary<string, object>()
{
{
"SubscriptionId": subscriptionId,
"Environment": env,
"ResourceGroup": resourceGroup,
"ResourceName": resourceName,
"Location": location,
"SiteId": siteId,
"SiteName": siteName,
"PolicyId": policyId,
"PrivateEndpointStateForSiteRecovery": pvtEndpointState
}
}),
EnableAutomaticUpgrade = isAutoUpgrade,
};
// Get Arc Extension Resource
ResourceIdentifier arcSettingResourceId = ArcSettingResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, clusterName, "default");
ArcSettingResource arcSetting = client.GetArcSettingResource(arcSettingResourceId);
ArcExtensionCollection collection = arcSetting.GetArcExtensions();
// Create the Extension
ArcExtensionResource result = (await collection.CreateOrUpdateAsync(WaitUntil.Completed, extensionName, data)).Value;
string extensionName = "AzureMonitorWindowsAgent"; // Replace with your extension name Some common examples are: AzureMonitorWindowsAgent, AzureSiteRecovery, AdminCenter
string targetVersion = "1.0.18062.0"; //replace with extension version you want to install
ResourceIdentifier arcExtensionResourceId = ArcExtensionResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, clusterName, "default", extensionName);
ArcExtensionResource arcExtension = client.GetArcExtensionResource(arcExtensionResourceId);
// Invoke Upgrade operation
ExtensionUpgradeContent content = new ExtensionUpgradeContent()
{
TargetVersion = targetVersion,
};
await arcExtension.UpgradeAsync(WaitUntil.Completed, content);
string extensionName = "AzureMonitorWindowsAgent"; // Replace with your extension name Some common examples are: AzureMonitorWindowsAgent, AzureSiteRecovery, AdminCenter
ResourceIdentifier arcExtensionResourceId = ArcExtensionResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, clusterName, "default", extensionName);
ArcExtensionResource arcExtension = client.GetArcExtensionResource(arcExtensionResourceId);
// Invoke the delete operation
arcExtension.DeleteAsync(WaitUntil.Completed);
// Get the HCI Cluster
string clusterName = "HCICluster"; // Replace with your cluster name,
ResourceIdentifier hciClusterResourceId = HciClusterResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, clusterName);
HciClusterResource hciCluster = client.GetHciClusterResource(hciClusterResourceId);
// Invoke get operation
HciClusterResource result = hciCluster.GetAsync().Result;
// Get the HCI Cluster
string clusterName = "HCICluster"; // Replace with your cluster name,
ResourceIdentifier hciClusterResourceId = HciClusterResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, clusterName);
HciClusterResource hciCluster = client.GetHciClusterResource(hciClusterResourceId);
// Invoke delete operation
await hciCluster.DeleteAsync(WaitUntil.Completed);
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this HciClusterResource
HciClusterCollection collection = resourceGroupResource.GetHciClusters();
// Calling the delete function for all Cluster Resources in the collection
await foreach (HciClusterResource item in collection.GetAllAsync())
{
// delete the item
await item.DeleteAsync(WaitUntil.Completed);
}
// Get the HCI Cluster
string clusterName = "HCICluster"; // Replace with your cluster name,
ResourceIdentifier hciClusterResourceId = HciClusterResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, clusterName);
HciClusterResource hciCluster = client.GetHciClusterResource(hciClusterResourceId);
// Invoke the Update Operation
string tag1 = "tag1";
string val1 = "value1";
string clusterName = "HCICluster"; // Replace with your cluster name,
ResourceIdentifier hciClusterResourceId = HciClusterResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, clusterName);
HciClusterResource hciCluster = client.GetHciClusterResource(hciClusterResourceId);
HciClusterPatch patch = new HciClusterPatch()
{
Tags =
{
[tag1] = val1
},
DesiredProperties = new HciClusterDesiredProperties()
{
WindowsServerSubscription = WindowsServerSubscription.Enabled,// It can Enabled or Disabled
DiagnosticLevel = HciClusterDiagnosticLevel.Basic,// It can be Basic or
},
};
HciClusterResource result = await hciCluster.UpdateAsync(patch);
- Invoke the Operation to Extend Azure Hybrid Benefit
string clusterName = "HCICluster"; // Replace with your cluster name,
ResourceIdentifier hciClusterResourceId = HciClusterResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, clusterName);
HciClusterResource hciCluster = client.GetHciClusterResource(hciClusterResourceId);
SoftwareAssuranceChangeContent content = new SoftwareAssuranceChangeContent()
{
SoftwareAssuranceIntent = SoftwareAssuranceIntent.Enable,
};
HciClusterResource result = (hciCluster.ExtendSoftwareAssuranceBenefitAsync(WaitUntil.Completed, content).Result).Value;
Code samples for using the management library for .NET can be found in the following locations
- File an issue via GitHub Issues.
- Check previous questions or ask new ones on Stack Overflow using Azure and .NET tags.
For more information about Microsoft Azure SDK, see this website.
For details on contributing to this repository, see the contributing guide.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (for example, label, comment). Follow the instructions provided by the bot. You'll only need to do this action once across all repositories using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact opencode@microsoft.com with any other questions or comments.