public void TestCreateGetDeleteVirtualCluster() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { string resourceGroupName = "RG_MIPlayground"; SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); string managedInstanceName = "sqlcl-vccrudtests-dotnetsdk1"; string login = "******"; string password = "******"; Dictionary <string, string> tags = new Dictionary <string, string>() { { "tagKey1", "TagValue1" } }; Microsoft.Azure.Management.Sql.Models.Sku sku = new Microsoft.Azure.Management.Sql.Models.Sku(); sku.Name = "MIGP8G4"; sku.Tier = "GeneralPurpose"; sku.Family = "Gen4"; string subnetId = "/subscriptions/a8c9a924-06c0-4bde-9788-e7b1370969e1/resourceGroups/RG_MIPlayground/providers/Microsoft.Network/virtualNetworks/VNET_MIPlayground/subnets/VCReservedSubnet"; string location = "eastus"; //Create server var managedInstance = sqlClient.ManagedInstances.CreateOrUpdate(resourceGroupName, managedInstanceName, new ManagedInstance() { AdministratorLogin = login, AdministratorLoginPassword = password, Sku = sku, SubnetId = subnetId, Tags = tags, Location = location, }); SqlManagementTestUtilities.ValidateManagedInstance(managedInstance, managedInstanceName, login, tags, location); // Get and verify Virtual cluster var virtualClusters = sqlClient.VirtualClusters.List(); Assert.True(virtualClusters.Count() > 0); var virtualCluster = virtualClusters.Single(vc => vc.SubnetId == subnetId); Assert.Equal(location, virtualCluster.Location, ignoreCase: true); string virtualClusterName = virtualCluster.Name; virtualCluster = sqlClient.VirtualClusters.ListByResourceGroup(resourceGroupName).Single(vc => vc.SubnetId == subnetId); Assert.Equal(location, virtualCluster.Location, ignoreCase: true); Assert.Equal(virtualClusterName, virtualCluster.Name); virtualCluster = sqlClient.VirtualClusters.Get(resourceGroupName, virtualClusterName); Assert.Equal(location, virtualCluster.Location, ignoreCase: true); Assert.Equal(virtualClusterName, virtualCluster.Name); Assert.Equal(subnetId, virtualCluster.SubnetId); // Drop managed server sqlClient.ManagedInstances.Delete(resourceGroupName, managedInstanceName); // Delete Virtual Cluster sqlClient.VirtualClusters.Delete(resourceGroupName, virtualClusterName); Assert.Throws <Microsoft.Rest.Azure.CloudException>(() => sqlClient.VirtualClusters.Get(resourceGroupName, virtualClusterName)); } }
public ManagedInstance CreateManagedInstance(ResourceGroup resourceGroup, string location) { SqlManagementClient sqlClient = GetClient <SqlManagementClient>(); string miName = "crud-tests-" + SqlManagementTestUtilities.GenerateName(); Dictionary <string, string> tags = new Dictionary <string, string>(); string subnetId = "/subscriptions/a8c9a924-06c0-4bde-9788-e7b1370969e1/resourceGroups/RG_MIPlayground/providers/Microsoft.Network/virtualNetworks/VNET_MIPlayground/subnets/MISubnet"; Microsoft.Azure.Management.Sql.Models.Sku sku = new Microsoft.Azure.Management.Sql.Models.Sku(name: "CLS3", tier: "Standard"); var managedInstance = sqlClient.ManagedInstances.CreateOrUpdate(resourceGroup.Name, miName, new ManagedInstance() { AdministratorLogin = SqlManagementTestUtilities.DefaultLogin, AdministratorLoginPassword = SqlManagementTestUtilities.DefaultPassword, Sku = sku, SubnetId = subnetId, Tags = tags, Location = location, }); SqlManagementTestUtilities.ValidateManagedInstance(managedInstance, miName, SqlManagementTestUtilities.DefaultLogin, tags, location); return(managedInstance); }
public void TestCreateUpdateGetDropInstancePool() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); // Setup string subscriptionId = "2e7fe4bd-90c7-454e-8bb6-dc44649f27b2"; string resourceGroupName = "sqlcrudtest-5294"; string instancePoolName = "sqlcl-crudtestinstancepool-dotnetsdk1"; string subnetId = $"/subscriptions/2e7fe4bd-90c7-454e-8bb6-dc44649f27b2/resourceGroups/instancepoolnetsdkcanadacentral/providers/Microsoft.Network/virtualNetworks/vnet-instancepoolnetsdkcanadacentral/subnets/InstancePool"; string location = "canadacentral"; int instancePoolVCores = 32; var tags1 = new Dictionary <string, string>() { { "tagKey1", "TagValue1" } }; var tags2 = new Dictionary <string, string>() { { "tagKey2", "TagValue2" } }; // Create an instance pool var instancePool = sqlClient.InstancePools.CreateOrUpdate( resourceGroupName, instancePoolName, parameters: new InstancePool() { LicenseType = "LicenseIncluded", Sku = new Sku() { Name = "GP_Gen5", Tier = "GeneralPurpose", Family = "Gen5" }, SubnetId = subnetId, Tags = tags1, VCores = instancePoolVCores, Location = location }); SqlManagementTestUtilities.ValidateInstancePool( instancePool, instancePoolName, vCores: instancePoolVCores, subnetId: subnetId, location: location, tags: tags1); // Update the instance pool tags instancePool = sqlClient.InstancePools.Update( resourceGroupName, instancePoolName, parameters: new InstancePoolUpdate(tags: tags2)); SqlManagementTestUtilities.ValidateInstancePool( instancePool, instancePoolName, vCores: instancePoolVCores, subnetId: subnetId, location: location, tags: tags2); // Get the instance pool instancePool = sqlClient.InstancePools.Get( resourceGroupName, instancePoolName); SqlManagementTestUtilities.ValidateInstancePool( instancePool, instancePoolName, vCores: instancePoolVCores, subnetId: subnetId, location: location, tags: tags2); // Get the resource group instance pools var instancePoolsRg = sqlClient.InstancePools.ListByResourceGroup(resourceGroupName); Assert.NotNull(instancePoolsRg); // Gets all instance pools in sub var instancePoolsSub = sqlClient.InstancePools.List(); Assert.NotNull(instancePoolsSub); // Verify usage var instancePoolUsage = sqlClient.Usages.ListByInstancePool(resourceGroupName, instancePoolName, true).ToList(); SqlManagementTestUtilities.ValidateInstancePoolUsage(instancePoolUsage[0], currentValue: 0, limit: instancePoolVCores, requestedLimit: null, usageName: "VCore utilization"); SqlManagementTestUtilities.ValidateInstancePoolUsage(instancePoolUsage[1], currentValue: 0, limit: 8192, requestedLimit: null, usageName: "Storage utilization"); SqlManagementTestUtilities.ValidateInstancePoolUsage(instancePoolUsage[2], currentValue: 0, limit: 100, requestedLimit: null, usageName: "Database utilization"); var instanceParams = new ManagedInstance { AdministratorLogin = "******", AdministratorLoginPassword = "******", InstancePoolId = instancePool.Id, Location = location, PublicDataEndpointEnabled = true, Sku = new Sku { Name = "GP_Gen5", Tier = "GeneralPurpose", Family = "Gen5" }, StorageSizeInGB = 32, SubnetId = instancePool.SubnetId, VCores = 2, Tags = tags1 }; // Create instance 1 in pool var instance1 = sqlClient.ManagedInstances.CreateOrUpdate(resourceGroupName, "netsdk-instance-in-pool-1-cc", parameters: instanceParams); SqlManagementTestUtilities.ValidateManagedInstance(instance1, "netsdk-instance-in-pool-1-cc", "cloudsa", tags1, location, instancePool.Id); // Create instance 2 in pool var instance2 = sqlClient.ManagedInstances.CreateOrUpdate(resourceGroupName, "netsdk-instance-in-pool-2-cc", parameters: instanceParams); SqlManagementTestUtilities.ValidateManagedInstance(instance2, "netsdk-instance-in-pool-2-cc", "cloudsa", tags1, location, instancePool.Id); // Gets instances in an instance pool var instances = sqlClient.ManagedInstances.ListByInstancePool(resourceGroupName, instancePoolName); instances = sqlClient.ManagedInstances.ListByInstancePool(resourceGroupName, instancePoolName); Assert.Equal(2, instances.Count()); // Validate instance pool usage instancePoolUsage = sqlClient.Usages.ListByInstancePool(resourceGroupName, instancePoolName, true).ToList(); SqlManagementTestUtilities.ValidateInstancePoolUsage(instancePoolUsage[0], currentValue: 4, limit: instancePoolVCores, requestedLimit: null, usageName: "VCore utilization"); SqlManagementTestUtilities.ValidateInstancePoolUsage(instancePoolUsage[1], currentValue: 64, limit: 8192, requestedLimit: null, usageName: "Storage utilization"); SqlManagementTestUtilities.ValidateInstancePoolUsage(instancePoolUsage[2], currentValue: 0, limit: 100, requestedLimit: null, usageName: "Database utilization"); // Delete the instances in the instance pool foreach (var instance in instances) { sqlClient.ManagedInstances.Delete(resourceGroupName, instance.Name); } // Delete the instance pool sqlClient.InstancePools.Delete(resourceGroupName, instancePool.Name); } }
public void TestCreateUpdateGetDropManagedInstance() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); string managedInstanceName = "sqlcl-crudtestswithdnszone-dotnetsdk1"; string login = "******"; string password = "******"; Dictionary <string, string> tags = new Dictionary <string, string>() { { "tagKey1", "TagValue1" } }; Microsoft.Azure.Management.Sql.Models.Sku sku = new Microsoft.Azure.Management.Sql.Models.Sku(); sku.Name = "MIGP8G4"; sku.Tier = "GeneralPurpose"; string subnetId = "/subscriptions/a8c9a924-06c0-4bde-9788-e7b1370969e1/resourceGroups/StdjordjTestResourceGroup/providers/Microsoft.Network/virtualNetworks/ZiwaVirtualNetwork4/subnets/default"; string location = "westcentralus"; //Create server var managedInstance1 = sqlClient.ManagedInstances.CreateOrUpdate(resourceGroup.Name, managedInstanceName, new ManagedInstance() { AdministratorLogin = login, AdministratorLoginPassword = password, Sku = sku, SubnetId = subnetId, Tags = tags, Location = location, }); SqlManagementTestUtilities.ValidateManagedInstance(managedInstance1, managedInstanceName, login, tags, TestEnvironmentUtilities.DefaultLocationId); // Create second server string managedInstanceName2 = "sqlcl-crudtestswithdnszone-dotnetsdk2"; var managedInstance2 = sqlClient.ManagedInstances.CreateOrUpdate(resourceGroup.Name, managedInstanceName2, new ManagedInstance() { AdministratorLogin = login, AdministratorLoginPassword = password, Sku = sku, SubnetId = subnetId, Tags = tags, Location = location, DnsZonePartner = string.Format("/subscriptions/a8c9a924-06c0-4bde-9788-e7b1370969e1/resourceGroups/{0}/providers/Microsoft.Sql/managedInstances/sqlcl-crudtestswithdnszone-dotnetsdk1", resourceGroup.Name) }); SqlManagementTestUtilities.ValidateManagedInstance(managedInstance2, managedInstanceName2, login, tags, TestEnvironmentUtilities.DefaultLocationId); // Get first server var getMI1 = sqlClient.ManagedInstances.Get(resourceGroup.Name, managedInstanceName); SqlManagementTestUtilities.ValidateManagedInstance(getMI1, managedInstanceName, login, tags, TestEnvironmentUtilities.DefaultLocationId); // Get second server var getMI2 = sqlClient.ManagedInstances.Get(resourceGroup.Name, managedInstanceName2); SqlManagementTestUtilities.ValidateManagedInstance(getMI2, managedInstanceName2, login, tags, TestEnvironmentUtilities.DefaultLocationId); // Verify that dns zone value is correctly inherited from dns zone partner Assert.Equal(getMI1.DnsZone, getMI2.DnsZone); var listMI = sqlClient.ManagedInstances.ListByResourceGroup(resourceGroup.Name); Assert.Equal(2, listMI.Count()); // Update first server Dictionary <string, string> newTags = new Dictionary <string, string>() { { "asdf", "zxcv" } }; var updateMI1 = sqlClient.ManagedInstances.Update(resourceGroup.Name, managedInstanceName, new ManagedInstanceUpdate { Tags = newTags }); SqlManagementTestUtilities.ValidateManagedInstance(updateMI1, managedInstanceName, login, newTags, TestEnvironmentUtilities.DefaultLocationId); // Drop server, update count sqlClient.ManagedInstances.DeleteAsync(resourceGroup.Name, managedInstanceName); var listMI2 = sqlClient.ManagedInstances.ListByResourceGroup(resourceGroup.Name); Assert.Equal(1, listMI2.Count()); sqlClient.ManagedInstances.DeleteAsync(resourceGroup.Name, managedInstanceName2); var listMI3 = sqlClient.ManagedInstances.ListByResourceGroup(resourceGroup.Name); Assert.Empty(listMI3); } }
public void TestCreateUpdateGetDropManagedInstance() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { ResourceGroup resourceGroup = context.CreateResourceGroup(); SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); Random r = new Random(); string managedInstanceName = "sqlcl-crudtestswithdnszone-dotnetsdk1"; string login = "******"; string password = "******"; Dictionary <string, string> tags = new Dictionary <string, string>() { { "tagKey1", "TagValue1" } }; Microsoft.Azure.Management.Sql.Models.Sku sku = new Microsoft.Azure.Management.Sql.Models.Sku(); sku.Name = "MIGP8G4"; sku.Tier = "GeneralPurpose"; sku.Family = "Gen5"; string subnetId = "/subscriptions/a8c9a924-06c0-4bde-9788-e7b1370969e1/resourceGroups/v-urmila/providers/Microsoft.Network/virtualNetworks/MIVirtualNetwork/subnets/ManagedInsanceSubnet"; string location = "westeurope"; bool publicDataEndpointEnabled = true; string proxyOverride = ManagedInstanceProxyOverride.Proxy; //Create server var managedInstance1 = sqlClient.ManagedInstances.CreateOrUpdate(resourceGroup.Name, managedInstanceName, new ManagedInstance() { AdministratorLogin = login, AdministratorLoginPassword = password, Sku = sku, SubnetId = subnetId, Tags = tags, Location = location, }); SqlManagementTestUtilities.ValidateManagedInstance(managedInstance1, managedInstanceName, login, tags, TestEnvironmentUtilities.DefaultLocationId, shouldCheckState: true); // Create second server string managedInstanceName2 = "sqlcl-crudtestswithdnszone-dotnetsdk2"; var managedInstance2 = sqlClient.ManagedInstances.CreateOrUpdate(resourceGroup.Name, managedInstanceName2, new ManagedInstance() { AdministratorLogin = login, AdministratorLoginPassword = password, Sku = sku, SubnetId = subnetId, Tags = tags, Location = location, DnsZonePartner = string.Format("/subscriptions/a8c9a924-06c0-4bde-9788-e7b1370969e1/resourceGroups/{0}/providers/Microsoft.Sql/managedInstances/{1}", resourceGroup.Name, managedInstanceName), PublicDataEndpointEnabled = publicDataEndpointEnabled, ProxyOverride = proxyOverride }); SqlManagementTestUtilities.ValidateManagedInstance(managedInstance2, managedInstanceName2, login, tags, TestEnvironmentUtilities.DefaultLocationId, shouldCheckState: true); // Get first server var getMI1 = sqlClient.ManagedInstances.Get(resourceGroup.Name, managedInstanceName); SqlManagementTestUtilities.ValidateManagedInstance(getMI1, managedInstanceName, login, tags, TestEnvironmentUtilities.DefaultLocationId, shouldCheckState: true); // Get second server var getMI2 = sqlClient.ManagedInstances.Get(resourceGroup.Name, managedInstanceName2); SqlManagementTestUtilities.ValidateManagedInstance(getMI2, managedInstanceName2, login, tags, TestEnvironmentUtilities.DefaultLocationId, shouldCheckState: true); // Verify that dns zone value is correctly inherited from dns zone partner Assert.Equal(getMI1.DnsZone, getMI2.DnsZone); // Verify PublicDataEndpointEnabled value for second server Assert.Equal(publicDataEndpointEnabled, getMI2.PublicDataEndpointEnabled); // Verify ProxyOverride value for second server Assert.Equal(proxyOverride, getMI2.ProxyOverride); var listMI = sqlClient.ManagedInstances.ListByResourceGroup(resourceGroup.Name); Assert.Equal(2, listMI.Count()); // Update first server Dictionary <string, string> newTags = new Dictionary <string, string>() { { "asdf", "zxcv" } }; var updateMI1 = sqlClient.ManagedInstances.Update(resourceGroup.Name, managedInstanceName, new ManagedInstanceUpdate { Tags = newTags, LicenseType = "LicenseIncluded" }); SqlManagementTestUtilities.ValidateManagedInstance(updateMI1, managedInstanceName, login, newTags, TestEnvironmentUtilities.DefaultLocationId); // Drop server, update count sqlClient.ManagedInstances.DeleteAsync(resourceGroup.Name, managedInstanceName).ConfigureAwait(true); var listMI2 = sqlClient.ManagedInstances.ListByResourceGroup(resourceGroup.Name); Assert.Equal(1, listMI2.Count()); sqlClient.ManagedInstances.DeleteAsync(resourceGroup.Name, managedInstanceName2).ConfigureAwait(true); var listMI3 = sqlClient.ManagedInstances.ListByResourceGroup(resourceGroup.Name); Assert.Empty(listMI3); } }
public void TestCreateUpdateGetDropManagedInstance() { using (SqlManagementTestContext context = new SqlManagementTestContext(this)) { SqlManagementClient sqlClient = context.GetClient <SqlManagementClient>(); Dictionary <string, string> tags = new Dictionary <string, string>() { { "tagKey1", "TagValue1" } }; bool publicDataEndpointEnabled = true; string proxyOverride = ManagedInstanceProxyOverride.Proxy; string requestedBSR = "Geo"; string publicResourceName = "SQL_Default"; string maintenanceConfigurationId = ManagedInstanceTestUtilities.getManagedInstanceFullMaintenanceResourceid(); // Create resource group var resourceGroup = context.CreateResourceGroup(ManagedInstanceTestUtilities.Region); //Create server var managedInstance1 = context.CreateManagedInstance(resourceGroup, new ManagedInstance() { Tags = tags, MaintenanceConfigurationId = maintenanceConfigurationId }); SqlManagementTestUtilities.ValidateManagedInstance(managedInstance1, tags, shouldCheckState: true); // Create second server var managedInstance2 = context.CreateManagedInstance(resourceGroup, new ManagedInstance() { DnsZonePartner = string.Format( "/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Sql/managedInstances/{2}", ManagedInstanceTestUtilities.SubscriptionId, ManagedInstanceTestUtilities.ResourceGroupName, managedInstance1.Name), PublicDataEndpointEnabled = publicDataEndpointEnabled, ProxyOverride = proxyOverride }); SqlManagementTestUtilities.ValidateManagedInstance(managedInstance2, shouldCheckState: true); // Get first server var getMI1 = sqlClient.ManagedInstances.Get(resourceGroup.Name, managedInstance1.Name); SqlManagementTestUtilities.ValidateManagedInstance(getMI1, tags, shouldCheckState: true); // Get second server var getMI2 = sqlClient.ManagedInstances.Get(resourceGroup.Name, managedInstance2.Name); SqlManagementTestUtilities.ValidateManagedInstance(getMI2, shouldCheckState: true); // Verify that maintenanceConfigurationId value is correctly set Assert.Contains(publicResourceName, getMI1.MaintenanceConfigurationId); // Verify that storageAccountType value is correctly set Assert.Equal(requestedBSR, getMI1.RequestedBackupStorageRedundancy); Assert.Equal(requestedBSR, getMI2.RequestedBackupStorageRedundancy); Assert.Equal(requestedBSR, getMI1.CurrentBackupStorageRedundancy); Assert.Equal(requestedBSR, getMI2.CurrentBackupStorageRedundancy); // Verify that dns zone value is correctly inherited from dns zone partner Assert.Equal(getMI1.DnsZone, getMI2.DnsZone); // Verify PublicDataEndpointEnabled value for second server Assert.Equal(publicDataEndpointEnabled, getMI2.PublicDataEndpointEnabled); // Verify ProxyOverride value for second server Assert.Equal(proxyOverride, getMI2.ProxyOverride); var listMI = context.ListManagedInstanceByResourceGroup(resourceGroup.Name); Assert.Equal(2, listMI.Count()); // Update first server Dictionary <string, string> newTags = new Dictionary <string, string>() { { "asdf", "zxcv" } }; var updateMI1 = sqlClient.ManagedInstances.Update(resourceGroup.Name, getMI1.Name, new ManagedInstanceUpdate { Tags = newTags, LicenseType = "LicenseIncluded" }); SqlManagementTestUtilities.ValidateManagedInstance(updateMI1, newTags); // Drop server, update count sqlClient.ManagedInstances.Delete(resourceGroup.Name, getMI1.Name); var listMI2 = context.ListManagedInstanceByResourceGroup(resourceGroup.Name); Assert.Single(listMI2); sqlClient.ManagedInstances.Delete(resourceGroup.Name, managedInstance2.Name); var listMI3 = context.ListManagedInstanceByResourceGroup(resourceGroup.Name); Assert.Empty(listMI3); } }