private void TestCreatePurchaseResponse(ArmOperation <ReservationOrderResponseResource> purchaseResponse, PurchaseRequestContent purchaseRequest, string reservationOrderId) { Assert.IsTrue(purchaseResponse.HasCompleted); Assert.IsTrue(purchaseResponse.HasValue); Assert.AreEqual(purchaseRequest.BillingPlan.ToString(), purchaseResponse.Value.Data.BillingPlan.ToString()); Assert.AreEqual(string.Format("/providers/microsoft.capacity/reservationOrders/{0}", reservationOrderId), purchaseResponse.Value.Data.Id.ToString()); Assert.AreEqual("Microsoft.Capacity", purchaseResponse.Value.Data.ResourceType.Namespace); Assert.AreEqual("reservationOrders", purchaseResponse.Value.Data.ResourceType.Type); Assert.AreEqual(purchaseRequest.DisplayName, purchaseResponse.Value.Data.DisplayName); Assert.AreEqual(reservationOrderId, purchaseResponse.Value.Data.Name); Assert.AreEqual(1, purchaseResponse.Value.Data.OriginalQuantity); Assert.AreEqual(purchaseRequest.Term.ToString(), purchaseResponse.Value.Data.Term.ToString()); Assert.IsNotNull(purchaseResponse.Value.Data.Reservations); Assert.AreEqual(1, purchaseResponse.Value.Data.Reservations.Count); }
public async Task CreateResourceGroupAsync() { #region Snippet:Creating_A_Virtual_Network_CreateResourceGroup ArmClient client = new ArmClient(new DefaultAzureCredential()); Subscription subscription = await client.GetDefaultSubscriptionAsync(); ResourceGroupCollection resourceGroups = subscription.GetResourceGroups(); string resourceGroupName = "myResourceGroup"; ResourceGroupData resourceGroupData = new ResourceGroupData(AzureLocation.WestUS2); ArmOperation <ResourceGroup> operation = await resourceGroups.CreateOrUpdateAsync(true, resourceGroupName, resourceGroupData); ResourceGroup resourceGroup = operation.Value; #endregion Snippet:Creating_A_Virtual_Network_CreateResourceGroup }
protected async Task initialize() { ArmClient armClient = new ArmClient(new DefaultAzureCredential()); SubscriptionResource subscription = await armClient.GetDefaultSubscriptionAsync(); ResourceGroupCollection rgCollection = subscription.GetResourceGroups(); // With the collection, we can create a new resource group with an specific name string rgName = "myRgName"; AzureLocation location = AzureLocation.WestUS2; ArmOperation <ResourceGroupResource> lro = await rgCollection.CreateOrUpdateAsync(WaitUntil.Completed, rgName, new ResourceGroupData(location)); ResourceGroupResource resourceGroup = lro.Value; this.resourceGroup = resourceGroup; }
public async Task CreateCommunicationService() { #region Snippet:Managing_CommunicationService_CreateAnApplicationDefinition CommunicationServiceCollection collection = resourceGroup.GetCommunicationServices(); string communicationServiceName = "myCommunicationService"; CommunicationServiceData data = new CommunicationServiceData() { Location = "global", DataLocation = "UnitedStates", }; ArmOperation <CommunicationService> communicationServiceLro = await collection.CreateOrUpdateAsync(true, communicationServiceName, data); CommunicationService communicationService = communicationServiceLro.Value; #endregion Snippet:Managing_CommunicationService_CreateAnApplicationDefinition }
public async Task PITR() { //update storage account to v2 PatchableStorageAccountData updateParameters = new PatchableStorageAccountData() { Kind = StorageKind.StorageV2 }; _storageAccount = await _storageAccount.UpdateAsync(updateParameters); _blobService = await _blobService.GetAsync(); BlobServiceData properties = _blobService.Data; properties.DeleteRetentionPolicy = new DeleteRetentionPolicy(); properties.DeleteRetentionPolicy.Enabled = true; properties.DeleteRetentionPolicy.Days = 30; properties.ChangeFeed = new ChangeFeed(); properties.ChangeFeed.Enabled = true; properties.IsVersioningEnabled = true; properties.RestorePolicy = new RestorePolicyProperties(true) { Days = 5 }; _blobService = (await _blobService.CreateOrUpdateAsync(WaitUntil.Completed, properties)).Value; if (Mode != RecordedTestMode.Playback) { await Task.Delay(10000); } //create restore ranges List <Models.BlobRestoreRange> ranges = new List <Models.BlobRestoreRange>(); ranges.Add(new Models.BlobRestoreRange("", "container1/blob1")); ranges.Add(new Models.BlobRestoreRange("container1/blob2", "container2/blob3")); ranges.Add(new Models.BlobRestoreRange("container3/blob3", "")); //start restore Models.BlobRestoreParameters parameters = new Models.BlobRestoreParameters(Recording.Now.AddSeconds(-1).ToUniversalTime(), ranges); ArmOperation <BlobRestoreStatus> restoreOperation = _storageAccount.RestoreBlobRanges(WaitUntil.Started, parameters); //wait for restore completion Models.BlobRestoreStatus restoreStatus = await restoreOperation.WaitForCompletionAsync(); Assert.IsTrue(restoreStatus.Status == BlobRestoreProgressStatus.Complete || restoreStatus.Status == BlobRestoreProgressStatus.InProgress); }
public async Task <ResourceGroup> CreateResourceGroupAsync() { string resourceGroupName = Recording.GenerateAssetName("testeventhubRG-"); ArmOperation <ResourceGroup> operation = await DefaultSubscription.GetResourceGroups().CreateOrUpdateAsync( true, resourceGroupName, new ResourceGroupData(DefaultLocation) { Tags = { { "test", "env" } } }); return(operation.Value); }
public async Task <ResourceGroupResource> CreateResourceGroupAsync() { string resourceGroupName = Recording.GenerateAssetName("teststorageRG-"); ArmOperation <ResourceGroupResource> operation = await DefaultSubscription.GetResourceGroups().CreateOrUpdateAsync( WaitUntil.Completed, resourceGroupName, new ResourceGroupData(DefaultLocation) { Tags = { { "test", "env" } } }); return(operation.Value); }
public async Task CreateOrUpdate() { #region Snippet:Managing_StorageAccounts_CreateStorageAccount //first we need to define the StorageAccountCreateParameters Sku sku = new Sku(SkuName.StandardGRS); Kind kind = Kind.Storage; string location = "westus2"; StorageAccountCreateParameters parameters = new StorageAccountCreateParameters(sku, kind, location); //now we can create a storage account with defined account name and parameters StorageAccountCollection accountCollection = resourceGroup.GetStorageAccounts(); string accountName = "myAccount"; ArmOperation <StorageAccount> accountCreateOperation = await accountCollection.CreateOrUpdateAsync(true, accountName, parameters); StorageAccount storageAccount = accountCreateOperation.Value; #endregion }
public async Task NewCode() { #region Snippet:Changelog_NewCode ArmClient armClient = new ArmClient(new DefaultAzureCredential()); SubscriptionResource subscription = await armClient.GetDefaultSubscriptionAsync(); ResourceGroupResource resourceGroup = await subscription.GetResourceGroups().GetAsync("myRgName"); VaultCollection vaultCollection = resourceGroup.GetVaults(); VaultCreateOrUpdateParameters parameters = new VaultCreateOrUpdateParameters(AzureLocation.WestUS2, new VaultProperties(Guid.NewGuid(), new KeyVaultSku(KeyVaultSkuFamily.A, KeyVaultSkuName.Standard))); ArmOperation <VaultResource> lro = await vaultCollection.CreateOrUpdateAsync(WaitUntil.Completed, "myVaultName", parameters); VaultResource vault = lro.Value; #endregion }
public async Task RemoteApplicationGroupList1AG() { string hostPoolName = "testRemoteApplicationGroupList1AGHP"; string applicationGroupName = "testRemoteApplicationGroupList1AGAG"; string resourceGroupName = Recording.GetVariable("DESKTOPVIRTUALIZATION_RESOURCE_GROUP", DefaultResourceGroupName); ResourceGroupResource rg = (ResourceGroupResource)await ResourceGroups.GetAsync(resourceGroupName); Assert.IsNotNull(rg); HostPoolCollection hostPoolCollection = rg.GetHostPools(); HostPoolData hostPoolData = new HostPoolData( DefaultLocation, HostPoolType.Pooled, LoadBalancerType.BreadthFirst, PreferredAppGroupType.Desktop); ArmOperation <HostPoolResource> opHostPoolCreate = await hostPoolCollection.CreateOrUpdateAsync( WaitUntil.Completed, hostPoolName, hostPoolData); VirtualApplicationGroupCollection agCollection = rg.GetVirtualApplicationGroups(); VirtualApplicationGroupData agData = new VirtualApplicationGroupData(DefaultLocation, opHostPoolCreate.Value.Data.Id, ApplicationGroupType.RemoteApp); ArmOperation <VirtualApplicationGroupResource> op = await agCollection.CreateOrUpdateAsync( WaitUntil.Completed, applicationGroupName, agData); AsyncPageable <VirtualApplicationGroupResource> agListPaged = agCollection.GetAllAsync(); IAsyncEnumerable <Page <VirtualApplicationGroupResource> > f = agListPaged.AsPages(); var pageEnumerator = f.GetAsyncEnumerator(); var b = await pageEnumerator.MoveNextAsync(); Assert.IsTrue(b); Assert.AreEqual(1, pageEnumerator.Current.Values.Count); Assert.AreEqual(null, pageEnumerator.Current.ContinuationToken); await pageEnumerator.Current.Values[0].DeleteAsync(WaitUntil.Completed); await opHostPoolCreate.Value.DeleteAsync(WaitUntil.Completed); }
public async Task createResourceGroup() { #region Snippet:Managing_StorageAccounts_DefaultSubscription ArmClient armClient = new ArmClient(new DefaultAzureCredential()); SubscriptionResource subscription = await armClient.GetDefaultSubscriptionAsync(); #endregion #region Snippet:Managing_StorageAccounts_GetResourceGroupCollection string rgName = "myRgName"; AzureLocation location = AzureLocation.WestUS2; ArmOperation <ResourceGroupResource> operation = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, rgName, new ResourceGroupData(location)); ResourceGroupResource resourceGroup = operation.Value; #endregion this.resourceGroup = resourceGroup; }
public async Task createResourceGroup() { #region Snippet:Managing_ServiceBusNamespaces_GetSubscription ArmClient armClient = new ArmClient(new DefaultAzureCredential()); Subscription subscription = await armClient.GetDefaultSubscriptionAsync(); #endregion #region Snippet:Managing_ServiceBusNamespaces_CreateResourceGroup string rgName = "myRgName"; AzureLocation location = AzureLocation.WestUS2; ArmOperation <ResourceGroup> operation = await subscription.GetResourceGroups().CreateOrUpdateAsync(true, rgName, new ResourceGroupData(location)); ResourceGroup resourceGroup = operation.Value; #endregion this.resourceGroup = resourceGroup; }
public async Task KeyVaultManagementListVaults() { IgnoreTestInLiveMode(); int n = 3; int top = 2; VaultProperties.EnableSoftDelete = null; List <string> resourceIds = new List <string>(); List <VaultResource> vaultList = new List <VaultResource>(); for (int i = 0; i < n; i++) { string vaultName = Recording.GenerateAssetName("sdktest-vault-"); VaultCreateOrUpdateContent parameters = new VaultCreateOrUpdateContent(Location, VaultProperties); parameters.Tags.InitializeFrom(Tags); ArmOperation <VaultResource> createdVault = await VaultCollection.CreateOrUpdateAsync(WaitUntil.Completed, vaultName, parameters).ConfigureAwait(false); VaultResource vaultValue = createdVault.Value; Assert.NotNull(vaultValue); Assert.NotNull(vaultValue.Id); resourceIds.Add(vaultValue.Id); vaultList.Add(vaultValue); } AsyncPageable <VaultResource> vaults = VaultCollection.GetAllAsync(top); await foreach (var v in vaults) { Assert.True(resourceIds.Remove(v.Id)); } Assert.True(resourceIds.Count == 0); AsyncPageable <VaultResource> allVaults = VaultCollection.GetAllAsync(top); Assert.NotNull(vaults); // Delete foreach (var item in vaultList) { await item.DeleteAsync(WaitUntil.Completed); } }
public async Task CreateApplicationDefinitions() { #region Snippet:Managing_ApplicationDefinitions_CreateAnApplicationDefinition // First we need to get the application definition collection from the resource group ApplicationDefinitionCollection applicationDefinitionCollection = resourceGroup.GetApplicationDefinitions(); // Use the same location as the resource group string applicationDefinitionName = "myApplicationDefinition"; var input = new ApplicationDefinitionData(resourceGroup.Data.Location, ApplicationLockLevel.None) { DisplayName = applicationDefinitionName, Description = $"{applicationDefinitionName} description", PackageFileUri = new Uri("https://raw.githubusercontent.com/Azure/azure-managedapp-samples/master/Managed%20Application%20Sample%20Packages/201-managed-storage-account/managedstorage.zip") }; ArmOperation <ApplicationDefinition> lro = await applicationDefinitionCollection.CreateOrUpdateAsync(WaitUntil.Completed, applicationDefinitionName, input); ApplicationDefinition applicationDefinition = lro.Value; #endregion Snippet:Managing_ApplicationDefinitions_CreateAnApplicationDefinition }
public async Task CreateDeploymentsUsingString() { #region Snippet:Managing_Deployments_CreateADeploymentUsingString // First we need to get the deployment collection from the resource group DeploymentCollection deploymentCollection = resourceGroup.GetDeployments(); // Use the same location as the resource group string deploymentName = "myDeployment"; // Passing string to template and parameters var input = new DeploymentInput(new DeploymentProperties(DeploymentMode.Incremental) { Template = File.ReadAllText("storage-template.json"), Parameters = File.ReadAllText("storage-parameters.json") }); ArmOperation <Deployment> lro = await deploymentCollection.CreateOrUpdateAsync(true, deploymentName, input); Deployment deployment = lro.Value; #endregion Snippet:Managing_Deployments_CreateADeployment }
public async Task CreateInstances() { #region Snippet:Managing_Instances_CreateAnInstance // Create a new account string accountName = "myAccount"; DeviceUpdateAccountData input1 = new DeviceUpdateAccountData(AzureLocation.WestUS2); ArmOperation <DeviceUpdateAccountResource> lro1 = await resourceGroup.GetDeviceUpdateAccounts().CreateOrUpdateAsync(WaitUntil.Completed, accountName, input1); DeviceUpdateAccountResource account = lro1.Value; // Get the instance collection from the specific account and create an instance string instanceName = "myInstance"; DeviceUpdateInstanceData input2 = new DeviceUpdateInstanceData(AzureLocation.WestUS2); input2.IotHubs.Add(new IotHubSettings("/subscriptions/.../resourceGroups/.../providers/Microsoft.Devices/IotHubs/...")); ArmOperation <DeviceUpdateInstanceResource> lro2 = await account.GetDeviceUpdateInstances().CreateOrUpdateAsync(WaitUntil.Completed, instanceName, input2); DeviceUpdateInstanceResource instance = lro2.Value; #endregion Snippet:Managing_Instances_CreateAnInstance }
public async Task CreateDeploymentsUsingString() { #region Snippet:Managing_Deployments_CreateADeploymentUsingString // First we need to get the deployment collection from the resource group ArmDeploymentCollection ArmDeploymentCollection = resourceGroup.GetArmDeployments(); // Use the same location as the resource group string deploymentName = "myDeployment"; // Passing string to template and parameters var input = new ArmDeploymentInput(new ArmDeploymentProperties(ArmDeploymentMode.Incremental) { Template = BinaryData.FromString(File.ReadAllText("storage-template.json")), Parameters = BinaryData.FromString(File.ReadAllText("storage-parameters.json")) }); ArmOperation <ArmDeploymentResource> lro = await ArmDeploymentCollection.CreateOrUpdateAsync(WaitUntil.Completed, deploymentName, input); ArmDeploymentResource deployment = lro.Value; #endregion Snippet:Managing_Deployments_CreateADeployment }
public async Task CreateResourceGroup() { #region Snippet:Managing_Resource_Groups_CreateAResourceGroup // First, initialize the ArmClient and get the default subscription ArmClient client = new ArmClient(new DefaultAzureCredential()); // Now we get a ResourceGroup collection for that subscription Subscription subscription = await client.GetDefaultSubscriptionAsync(); ResourceGroupCollection resourceGroups = subscription.GetResourceGroups(); // With the collection, we can create a new resource group with an specific name string resourceGroupName = "myRgName"; AzureLocation location = AzureLocation.WestUS2; ResourceGroupData resourceGroupData = new ResourceGroupData(location); ArmOperation <ResourceGroup> operation = await resourceGroups.CreateOrUpdateAsync(true, resourceGroupName, resourceGroupData); ResourceGroup resourceGroup = operation.Value; #endregion Snippet:Managing_Resource_Groups_CreateAResourceGroup }
public async Task UpdateAccounts() { #region Snippet:Managing_Accounts_UpdateAnAccount // First we need to get the account collection from the specific resource group DeviceUpdateAccountCollection accountCollection = resourceGroup.GetDeviceUpdateAccounts(); // Now we can get the account with GetAsync() DeviceUpdateAccount account = await accountCollection.GetAsync("myAccount"); // With UpdateAsync(), we can update the account DeviceUpdateAccountUpdateOptions updateOptions = new DeviceUpdateAccountUpdateOptions() { Location = AzureLocation.WestUS2, Identity = new ManagedServiceIdentity(ResourceManager.Models.ManagedServiceIdentityType.None) }; ArmOperation <DeviceUpdateAccount> lro = await account.UpdateAsync(true, updateOptions); account = lro.Value; #endregion Snippet:Managing_Accounts_UpdateAnAccount }
public async Task KeyVaultManagementListDeletedVaults() { IgnoreTestInLiveMode(); int n = 3; List <string> resourceIds = new List <string>(); List <VaultResource> vaultList = new List <VaultResource>(); VaultCreateOrUpdateContent parameters = new VaultCreateOrUpdateContent(Location, VaultProperties); parameters.Tags.InitializeFrom(Tags); for (int i = 0; i < n; i++) { string vaultName = Recording.GenerateAssetName("sdktest-vault-"); ArmOperation <VaultResource> createdRawVault = await VaultCollection.CreateOrUpdateAsync(WaitUntil.Completed, vaultName, parameters).ConfigureAwait(false); VaultResource createdVault = createdRawVault.Value; Assert.NotNull(createdVault.Data); Assert.NotNull(createdVault.Data.Id); resourceIds.Add(createdVault.Data.Id); vaultList.Add(createdVault); await createdVault.DeleteAsync(WaitUntil.Completed).ConfigureAwait(false); Response <DeletedVaultResource> deletedVault = await DeletedVaultCollection.GetAsync(Location, vaultName).ConfigureAwait(false); Assert.IsTrue(deletedVault.Value.Data.Name.Equals(createdVault.Data.Name)); } List <DeletedVaultResource> deletedVaults = Subscription.GetDeletedVaultsAsync().ToEnumerableAsync().Result; Assert.NotNull(deletedVaults); foreach (var v in deletedVaults) { bool exists = resourceIds.Remove(v.Data.Properties.VaultId); if (resourceIds.Count == 0) { break; } } Assert.True(resourceIds.Count == 0); }
protected async Task initialize() { #region Snippet:Readme_DefaultSubscription ArmClient armClient = new ArmClient(new DefaultAzureCredential()); Subscription subscription = await armClient.GetDefaultSubscriptionAsync(); #endregion #region Snippet:Readme_GetResourceGroupCollection ResourceGroupCollection rgCollection = subscription.GetResourceGroups(); // With the collection, we can create a new resource group with a specific name string rgName = "myRgName"; AzureLocation location = AzureLocation.WestUS2; ArmOperation <ResourceGroup> lro = await rgCollection.CreateOrUpdateAsync(true, rgName, new ResourceGroupData(location)); ResourceGroup resourceGroup = lro.Value; #endregion this.resourceGroup = resourceGroup; }
public async Task CreateOriginGroups() { #region Snippet:Managing_OriginGroups_CreateAnOriginGroup // Create a new cdn profile string profileName = "myProfile"; var input1 = new ProfileData(AzureLocation.WestUS, new CdnSku { Name = CdnSkuName.StandardMicrosoft }); ArmOperation <ProfileResource> lro1 = await resourceGroup.GetProfiles().CreateOrUpdateAsync(WaitUntil.Completed, profileName, input1); ProfileResource profile = lro1.Value; // Get the cdn endpoint collection from the specific ProfileResource and create an endpoint string endpointName = "myEndpoint"; var input2 = new CdnEndpointData(AzureLocation.WestUS) { IsHttpAllowed = true, IsHttpsAllowed = true, OptimizationType = OptimizationType.GeneralWebDelivery }; DeepCreatedOrigin deepCreatedOrigin = new DeepCreatedOrigin("myOrigin") { HostName = "testsa4dotnetsdk.blob.core.windows.net", Priority = 3, Weight = 100 }; input2.Origins.Add(deepCreatedOrigin); ArmOperation <CdnEndpointResource> lro2 = await profile.GetCdnEndpoints().CreateOrUpdateAsync(WaitUntil.Completed, endpointName, input2); CdnEndpointResource endpoint = lro2.Value; // Get the cdn origin group collection from the specific endpoint and create an origin group string originGroupName = "myOriginGroup"; var input3 = new CdnOriginGroupData(); input3.Origins.Add(new WritableSubResource { Id = new ResourceIdentifier($"{endpoint.Id}/origins/myOrigin") }); ArmOperation <CdnOriginGroupResource> lro3 = await endpoint.GetCdnOriginGroups().CreateOrUpdateAsync(WaitUntil.Completed, originGroupName, input3); CdnOriginGroupResource originGroup = lro3.Value; #endregion Snippet:Managing_OriginGroups_CreateAnOriginGroup }
public async Task CreateAvailabilitySet() { // First, initialize the ArmClient and get the default subscription ArmClient armClient = new ArmClient(new DefaultAzureCredential()); // Now we get a ResourceGroupResource collection for that subscription SubscriptionResource subscription = await armClient.GetDefaultSubscriptionAsync(); ResourceGroupCollection rgCollection = subscription.GetResourceGroups(); // With the collection, we can create a new resource group with an specific name string rgName = "myRgName"; AzureLocation location = AzureLocation.WestUS2; ArmOperation<ResourceGroupResource> rgLro = await rgCollection.CreateOrUpdateAsync(WaitUntil.Completed, rgName, new ResourceGroupData(location)); ResourceGroupResource resourceGroup = rgLro.Value; #region Snippet:Managing_Availability_Set_CreateAnAvailabilitySet AvailabilitySetCollection availabilitySetCollection = resourceGroup.GetAvailabilitySets(); string availabilitySetName = "myAvailabilitySet"; AvailabilitySetData input = new AvailabilitySetData(location); ArmOperation<AvailabilitySetResource> lro = await availabilitySetCollection.CreateOrUpdateAsync(WaitUntil.Completed, availabilitySetName, input); AvailabilitySetResource availabilitySet = lro.Value; #endregion Snippet:Managing_Availability_Set_CreateAnAvailabilitySet }
public async Task createNamespace() { #region Snippet:Managing_ServiceBusQueues_DefaultSubscription ArmClient armClient = new ArmClient(new DefaultAzureCredential()); SubscriptionResource subscription = await armClient.GetDefaultSubscriptionAsync(); #endregion #region Snippet:Managing_ServiceBusQueues_CreateResourceGroup string rgName = "myRgName"; AzureLocation location = AzureLocation.WestUS2; ArmOperation <ResourceGroupResource> operation = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, rgName, new ResourceGroupData(location)); ResourceGroupResource resourceGroup = operation.Value; #endregion #region Snippet:Managing_ServiceBusQueues_CreateNamespace string namespaceName = "myNamespace"; ServiceBusNamespaceCollection namespaceCollection = resourceGroup.GetServiceBusNamespaces(); ServiceBusNamespaceResource serviceBusNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new ServiceBusNamespaceData(location))).Value; ServiceBusQueueCollection serviceBusQueueCollection = serviceBusNamespace.GetServiceBusQueues(); #endregion this.serviceBusQueueCollection = serviceBusQueueCollection; }
public async Task CreateADnsZone() { #region Snippet:Managing_DnsZones_CreateADnsZones ArmClient armClient = new ArmClient(new DefaultAzureCredential()); SubscriptionResource subscription = await armClient.GetDefaultSubscriptionAsync(); // first we need to get the resource group string rgName = "myRgName"; ResourceGroupResource resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName); // Now we get the DnsZone collection from the resource group DnsZoneCollection dnsZoneCollection = resourceGroup.GetDnsZones(); // Use the same location as the resource group string dnsZoneName = "sample.com"; DnsZoneData data = new DnsZoneData("Global") { }; ArmOperation <DnsZoneResource> lro = await dnsZoneCollection.CreateOrUpdateAsync(WaitUntil.Completed, dnsZoneName, data); DnsZoneResource dnsZone = lro.Value; #endregion Snippet:Managing_DnsZones_CreateADnsZones }
public async Task CreateNamespace() { #region Snippet:Managing_EventHubs_DefaultSubscription ArmClient armClient = new ArmClient(new DefaultAzureCredential()); Subscription subscription = await armClient.GetDefaultSubscriptionAsync(); #endregion #region Snippet:Managing_EventHubs_CreateResourceGroup string rgName = "myRgName"; AzureLocation location = AzureLocation.WestUS2; ArmOperation <ResourceGroup> operation = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, rgName, new ResourceGroupData(location)); ResourceGroup resourceGroup = operation.Value; #endregion #region Snippet:Managing_EventHubs_CreateNamespace string namespaceName = "myNamespace"; EventHubNamespaceCollection namespaceCollection = resourceGroup.GetEventHubNamespaces(); EventHubNamespace eHNamespace = (await namespaceCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, new EventHubNamespaceData(location))).Value; EventHubCollection eventHubCollection = eHNamespace.GetEventHubs(); #endregion this.eventHubCollection = eventHubCollection; }
public async Task NewCode() { #endif ArmClient armClient = new ArmClient(new DefaultAzureCredential()); SubscriptionResource subscription = await armClient.GetDefaultSubscriptionAsync(); ResourceGroupResource resourceGroup = await subscription.GetResourceGroups().GetAsync("abc"); VirtualNetworkCollection virtualNetworkContainer = resourceGroup.GetVirtualNetworks(); // Create VNet VirtualNetworkData vnet = new VirtualNetworkData() { Location = "westus", }; vnet.AddressSpace.AddressPrefixes.Add("10.0.0.0/16"); vnet.Subnets.Add(new SubnetData { Name = "mySubnet", AddressPrefix = "10.0.0.0/24", }); ArmOperation<VirtualNetworkResource> vnetOperation = await virtualNetworkContainer.CreateOrUpdateAsync(WaitUntil.Completed, "_vent", vnet); VirtualNetworkResource virtualNetwork = vnetOperation.Value; #endregion }
public static async Task <bool> SubmitDeployment(string subscriptionId, string resourceGroupName, string templateFileContents, string parameters, string deploymentName) { try { var sub = GetSubscriptionResource(subscriptionId); var rg = GetResourceGroup(sub, resourceGroupName); var deployments = rg.GetArmDeployments(); var input = new ArmDeploymentContent(new ArmDeploymentProperties(ArmDeploymentMode.Incremental) { Template = BinaryData.FromString(templateFileContents), Parameters = BinaryData.FromString(parameters) }); ArmOperation <ArmDeploymentResource> lro = await deployments.CreateOrUpdateAsync(WaitUntil.Completed, deploymentName, input); ArmDeploymentResource dep = lro.Value; return(true); } catch (Exception exe) { log.LogError($"Deployment '{deploymentName}' failed. {exe.Message}"); return(false); } }
public async Task NewCode() { #endif var armClient = new ArmClient(new DefaultAzureCredential()); var location = AzureLocation.WestUS; // Create ResourceGroup Subscription subscription = await armClient.GetDefaultSubscriptionAsync(); ArmOperation<ResourceGroup> rgOperation = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, "myResourceGroup", new ResourceGroupData(location)); ResourceGroup resourceGroup = rgOperation.Value; // Create AvailabilitySet var availabilitySetData = new AvailabilitySetData(location) { PlatformUpdateDomainCount = 5, PlatformFaultDomainCount = 2, Sku = new ComputeSku() { Name = "Aligned" } }; ArmOperation<AvailabilitySet> asetOperation = await resourceGroup.GetAvailabilitySets().CreateOrUpdateAsync(WaitUntil.Completed, "myAvailabilitySet", availabilitySetData); AvailabilitySet availabilitySet = asetOperation.Value; // Create VNet var vnetData = new VirtualNetworkData() { Location = location, Subnets = { new SubnetData() { Name = "mySubnet", AddressPrefix = "10.0.0.0/24", } }, }; vnetData.AddressPrefixes.Add("10.0.0.0/16"); ArmOperation<VirtualNetwork> vnetOperation = await resourceGroup.GetVirtualNetworks().CreateOrUpdateAsync(WaitUntil.Completed, "myVirtualNetwork", vnetData); VirtualNetwork vnet = vnetOperation.Value; // Create Network interface var nicData = new NetworkInterfaceData() { Location = location, IPConfigurations = { new NetworkInterfaceIPConfigurationData() { Name = "Primary", Primary = true, Subnet = new SubnetData() { Id = vnet.Data.Subnets.First().Id }, PrivateIPAllocationMethod = IPAllocationMethod.Dynamic, } } }; ArmOperation<NetworkInterface> nicOperation = await resourceGroup.GetNetworkInterfaces().CreateOrUpdateAsync(WaitUntil.Completed, "myNetworkInterface", nicData); NetworkInterface nic = nicOperation.Value; var vmData = new VirtualMachineData(location) { AvailabilitySet = new WritableSubResource() { Id = availabilitySet.Id }, NetworkProfile = new Compute.Models.NetworkProfile { NetworkInterfaces = { new NetworkInterfaceReference() { Id = nic.Id } } }, OSProfile = new OSProfile { ComputerName = "testVM", AdminUsername = "******", AdminPassword = "******", LinuxConfiguration = new LinuxConfiguration { DisablePasswordAuthentication = false, ProvisionVmAgent = true } }, StorageProfile = new StorageProfile() { ImageReference = new ImageReference() { Offer = "UbuntuServer", Publisher = "Canonical", Sku = "18.04-LTS", Version = "latest" } }, HardwareProfile = new HardwareProfile() { VmSize = VirtualMachineSizeTypes.StandardB1Ms }, }; ArmOperation<VirtualMachine> vmOperation = await resourceGroup.GetVirtualMachines().CreateOrUpdateAsync(WaitUntil.Completed, "myVirtualMachine", vmData); VirtualMachine vm = vmOperation.Value; #endregion }
public async Task CreateVirtualMachine() { #region Snippet:Managing_VirtualMachines_CreateAVirtualMachine ArmClient armClient = new ArmClient(new DefaultAzureCredential()); SubscriptionResource subscription = await armClient.GetDefaultSubscriptionAsync(); // first we need to get the resource group string rgName = "myRgName"; ResourceGroupResource resourceGroup = await subscription.GetResourceGroups().GetAsync(rgName); // Now we get the virtual machine collection from the resource group VirtualMachineCollection vmCollection = resourceGroup.GetVirtualMachines(); // Use the same location as the resource group string vmName = "myVM"; var input = new VirtualMachineData(resourceGroup.Data.Location) { HardwareProfile = new HardwareProfile() { VmSize = VirtualMachineSizeTypes.StandardF2 }, OSProfile = new OSProfile() { AdminUsername = "******", ComputerName = "myVM", LinuxConfiguration = new LinuxConfiguration() { DisablePasswordAuthentication = true, SshPublicKeys = { new SshPublicKeyInfo() { Path = $"/home/adminUser/.ssh/authorized_keys", KeyData = "<value of the public ssh key>", } } } }, NetworkProfile = new NetworkProfile() { NetworkInterfaces = { new NetworkInterfaceReference() { Id = new ResourceIdentifier("/subscriptions/<subscriptionId>/resourceGroups/<rgName>/providers/Microsoft.Network/networkInterfaces/<nicName>"), Primary = true, } } }, StorageProfile = new StorageProfile() { OSDisk = new OSDisk(DiskCreateOptionTypes.FromImage) { OSType = OperatingSystemTypes.Linux, Caching = CachingTypes.ReadWrite, ManagedDisk = new ManagedDiskParameters() { StorageAccountType = StorageAccountTypes.StandardLRS } }, ImageReference = new ImageReference() { Publisher = "Canonical", Offer = "UbuntuServer", Sku = "16.04-LTS", Version = "latest", } } }; ArmOperation <VirtualMachineResource> lro = await vmCollection.CreateOrUpdateAsync(WaitUntil.Completed, vmName, input); VirtualMachineResource vm = lro.Value; #endregion Snippet:Managing_VirtualMachines_CreateAVirtualMachine }