internal CloudServiceProperties(string packageUrl, string configuration, string configurationUrl, bool?startCloudService, bool?allowModelOverride, CloudServiceUpgradeMode?upgradeMode, CloudServiceRoleProfile roleProfile, CloudServiceOSProfile oSProfile, CloudServiceNetworkProfile networkProfile, CloudServiceExtensionProfile extensionProfile, string provisioningState, string uniqueId) { PackageUrl = packageUrl; Configuration = configuration; ConfigurationUrl = configurationUrl; StartCloudService = startCloudService; AllowModelOverride = allowModelOverride; UpgradeMode = upgradeMode; RoleProfile = roleProfile; OSProfile = oSProfile; NetworkProfile = networkProfile; ExtensionProfile = extensionProfile; ProvisioningState = provisioningState; UniqueId = uniqueId; }
internal CloudServiceData(ResourceIdentifier id, string name, ResourceType resourceType, SystemData systemData, IDictionary <string, string> tags, AzureLocation location, Uri packageUri, string configuration, Uri configurationUri, bool?startCloudService, bool?allowModelOverride, CloudServiceUpgradeMode?upgradeMode, CloudServiceRoleProfile roleProfile, CloudServiceOSProfile osProfile, CloudServiceNetworkProfile networkProfile, CloudServiceExtensionProfile extensionProfile, string provisioningState, string uniqueId) : base(id, name, resourceType, systemData, tags, location) { PackageUri = packageUri; Configuration = configuration; ConfigurationUri = configurationUri; StartCloudService = startCloudService; AllowModelOverride = allowModelOverride; UpgradeMode = upgradeMode; RoleProfile = roleProfile; OSProfile = osProfile; NetworkProfile = networkProfile; ExtensionProfile = extensionProfile; ProvisioningState = provisioningState; UniqueId = uniqueId; }
private void TestCloudServiceOperationsInternal(MockContext context, CloudServiceExtensionProfile extensionProfile = null, bool validateInstanceView = false, bool deleteAsPartOfTest = false) { EnsureClientsInitialized(context); // Create resource group var rgName = TestUtilities.GenerateName(TestPrefix); var csName = TestUtilities.GenerateName("cs"); string cloudServiceName = "TestCloudServiceMultiRole"; string publicIPAddressName = TestUtilities.GenerateName("cspip"); string vnetName = TestUtilities.GenerateName("csvnet"); string subnetName = TestUtilities.GenerateName("subnet"); string dnsName = TestUtilities.GenerateName("dns"); string lbName = TestUtilities.GenerateName("lb"); string lbfeName = TestUtilities.GenerateName("lbfe"); try { CreateVirtualNetwork(rgName, vnetName, subnetName); PublicIPAddress publicIPAddress = CreatePublicIP(publicIPAddressName, rgName, dnsName); /// /// Create: Create a multi-role CloudService with 2 WorkerRoles and 1 WebRole /// // Define Configurations List <string> supportedRoleInstanceSizes = GetSupportedRoleInstanceSizes(); Dictionary <string, RoleConfiguration> roleNameToPropertiesMapping = new Dictionary <string, RoleConfiguration> { { "WorkerRole1", new RoleConfiguration { InstanceCount = 1, RoleInstanceSize = supportedRoleInstanceSizes[0] } }, { "WorkerRole2", new RoleConfiguration { InstanceCount = 1, RoleInstanceSize = supportedRoleInstanceSizes[1] } }, { "WebRole1", new RoleConfiguration { InstanceCount = 2, RoleInstanceSize = supportedRoleInstanceSizes[3] } } }; // Generate the request CloudService cloudService = GenerateCloudServiceWithNetworkProfile( resourceGroupName: rgName, serviceName: cloudServiceName, cspkgSasUri: CreateCspkgSasUrl(rgName, MultiRole2Worker1WebRolesPackageSasUri), roleNameToPropertiesMapping: roleNameToPropertiesMapping, publicIPAddressName: publicIPAddressName, vnetName: vnetName, subnetName: subnetName, lbName: lbName, lbFrontendName: lbfeName); if (extensionProfile != null) { cloudService.Properties.ExtensionProfile = extensionProfile; } CloudService getResponse = CreateCloudService_NoAsyncTracking( rgName, csName, cloudService); if (validateInstanceView) { var getInstanceViewResponse = m_CrpClient.CloudServices.GetInstanceView(rgName, csName); Assert.NotNull(getInstanceViewResponse); ValidateCloudServiceInstanceView(cloudService, getInstanceViewResponse); } /// /// Delete the CloudService /// if (deleteAsPartOfTest) { m_CrpClient.CloudServices.Delete(rgName, csName); } } finally { // Fire and forget. No need to wait for RG deletion completion try { m_ResourcesClient.ResourceGroups.BeginDelete(rgName); } catch (Exception e) { // Swallow this exception so that the original exception is thrown Console.WriteLine(e); } } }
public void TestCloudServiceUpdateOperations() { using (MockContext context = MockContext.Start(this.GetType())) { EnsureClientsInitialized(context); // Create resource group var rgName = TestUtilities.GenerateName(TestPrefix); var csName = TestUtilities.GenerateName("cs"); string cloudServiceName = "TestCloudServiceMultiRole"; string publicIPAddressName = TestUtilities.GenerateName("cspip"); string vnetName = TestUtilities.GenerateName("csvnet"); string subnetName = TestUtilities.GenerateName("subnet"); string dnsName = TestUtilities.GenerateName("dns"); string lbName = TestUtilities.GenerateName("lb"); string lbfeName = TestUtilities.GenerateName("lbfe"); try { CreateVirtualNetwork(rgName, vnetName, subnetName); PublicIPAddress publicIPAddress = CreatePublicIP(publicIPAddressName, rgName, dnsName); /// /// Create: Create a multi-role CloudService with 2 WorkerRoles and 1 WebRole /// // Define Configurations List <string> supportedRoleInstanceSizes = GetSupportedRoleInstanceSizes(); Dictionary <string, RoleConfiguration> roleNameToPropertiesMapping = new Dictionary <string, RoleConfiguration> { { "WorkerRole1", new RoleConfiguration { InstanceCount = 1, RoleInstanceSize = supportedRoleInstanceSizes[0] } }, { "WorkerRole2", new RoleConfiguration { InstanceCount = 1, RoleInstanceSize = supportedRoleInstanceSizes[1] } }, { "WebRole1", new RoleConfiguration { InstanceCount = 2, RoleInstanceSize = supportedRoleInstanceSizes[3] } } }; // Generate the request CloudService cloudService = GenerateCloudServiceWithNetworkProfile( resourceGroupName: rgName, serviceName: cloudServiceName, cspkgSasUri: CreateCspkgSasUrl(rgName, MultiRole2Worker1WebRolesPackageSasUri), roleNameToPropertiesMapping: roleNameToPropertiesMapping, publicIPAddressName: publicIPAddressName, vnetName: vnetName, subnetName: subnetName, lbName: lbName, lbFrontendName: lbfeName); CloudService getResponse = CreateCloudService_NoAsyncTracking( rgName, csName, cloudService); /// /// Update[1]: Delete WorkerRole1, ScaleUp WorkerRole2 and ScaleIn WebRole1 /// roleNameToPropertiesMapping = new Dictionary <string, RoleConfiguration> { /// Delete WorkerRole1 /// { "WorkerRole1", new RoleConfiguration { InstanceCount = 1, RoleInstanceSize = supportedRoleInstanceSizes[0] } }, /// Scale-Up WorkerRole2 { "WorkerRole2", new RoleConfiguration { InstanceCount = 1, RoleInstanceSize = supportedRoleInstanceSizes[0] } }, /// Scale-In WebRole1 { "WebRole1", new RoleConfiguration { InstanceCount = 1, RoleInstanceSize = supportedRoleInstanceSizes[3] } } }; cloudService = GenerateCloudServiceWithNetworkProfile( resourceGroupName: rgName, serviceName: cloudServiceName, cspkgSasUri: CreateCspkgSasUrl(rgName, MultiRole1Worker1WebRolesPackageSasUri), roleNameToPropertiesMapping: roleNameToPropertiesMapping, publicIPAddressName: publicIPAddressName, vnetName: vnetName, subnetName: subnetName, lbName: lbName, lbFrontendName: lbfeName); CloudServiceExtensionProfile extensionProfile = new CloudServiceExtensionProfile() { Extensions = new List <Extension>() { CreateRDPExtension("RDPExtension") } }; cloudService.Properties.ExtensionProfile = extensionProfile; UpdateCloudService(rgName, csName, cloudService); var getUpdatedResponse = m_CrpClient.CloudServices.Get(rgName, csName); ValidateCloudService(cloudService, getUpdatedResponse, rgName, csName); m_CrpClient.CloudServices.Delete(rgName, csName); } finally { // Fire and forget. No need to wait for RG deletion completion try { m_ResourcesClient.ResourceGroups.BeginDelete(rgName); } catch (Exception e) { // Swallow this exception so that the original exception is thrown Console.WriteLine(e); } } } }
internal static CloudServiceData DeserializeCloudServiceData(JsonElement element) { IDictionary <string, string> tags = default; AzureLocation location = default; ResourceIdentifier id = default; string name = default; ResourceType type = default; SystemData systemData = default; Optional <Uri> packageUrl = default; Optional <string> configuration = default; Optional <Uri> configurationUrl = default; Optional <bool> startCloudService = default; Optional <bool> allowModelOverride = default; Optional <CloudServiceUpgradeMode> upgradeMode = default; Optional <CloudServiceRoleProfile> roleProfile = default; Optional <CloudServiceOSProfile> osProfile = default; Optional <CloudServiceNetworkProfile> networkProfile = default; Optional <CloudServiceExtensionProfile> extensionProfile = default; Optional <string> provisioningState = default; Optional <string> uniqueId = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("tags")) { Dictionary <string, string> dictionary = new Dictionary <string, string>(); foreach (var property0 in property.Value.EnumerateObject()) { dictionary.Add(property0.Name, property0.Value.GetString()); } tags = dictionary; continue; } if (property.NameEquals("location")) { location = new AzureLocation(property.Value.GetString()); continue; } if (property.NameEquals("id")) { id = new ResourceIdentifier(property.Value.GetString()); continue; } if (property.NameEquals("name")) { name = property.Value.GetString(); continue; } if (property.NameEquals("type")) { type = new ResourceType(property.Value.GetString()); continue; } if (property.NameEquals("systemData")) { systemData = JsonSerializer.Deserialize <SystemData>(property.Value.ToString()); continue; } if (property.NameEquals("properties")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } foreach (var property0 in property.Value.EnumerateObject()) { if (property0.NameEquals("packageUrl")) { if (property0.Value.ValueKind == JsonValueKind.Null) { packageUrl = null; continue; } packageUrl = new Uri(property0.Value.GetString()); continue; } if (property0.NameEquals("configuration")) { configuration = property0.Value.GetString(); continue; } if (property0.NameEquals("configurationUrl")) { if (property0.Value.ValueKind == JsonValueKind.Null) { configurationUrl = null; continue; } configurationUrl = new Uri(property0.Value.GetString()); continue; } if (property0.NameEquals("startCloudService")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } startCloudService = property0.Value.GetBoolean(); continue; } if (property0.NameEquals("allowModelOverride")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } allowModelOverride = property0.Value.GetBoolean(); continue; } if (property0.NameEquals("upgradeMode")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } upgradeMode = new CloudServiceUpgradeMode(property0.Value.GetString()); continue; } if (property0.NameEquals("roleProfile")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } roleProfile = CloudServiceRoleProfile.DeserializeCloudServiceRoleProfile(property0.Value); continue; } if (property0.NameEquals("osProfile")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } osProfile = CloudServiceOSProfile.DeserializeCloudServiceOSProfile(property0.Value); continue; } if (property0.NameEquals("networkProfile")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } networkProfile = CloudServiceNetworkProfile.DeserializeCloudServiceNetworkProfile(property0.Value); continue; } if (property0.NameEquals("extensionProfile")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } extensionProfile = CloudServiceExtensionProfile.DeserializeCloudServiceExtensionProfile(property0.Value); continue; } if (property0.NameEquals("provisioningState")) { provisioningState = property0.Value.GetString(); continue; } if (property0.NameEquals("uniqueId")) { uniqueId = property0.Value.GetString(); continue; } } continue; } } return(new CloudServiceData(id, name, type, systemData, tags, location, packageUrl.Value, configuration.Value, configurationUrl.Value, Optional.ToNullable(startCloudService), Optional.ToNullable(allowModelOverride), Optional.ToNullable(upgradeMode), roleProfile.Value, osProfile.Value, networkProfile.Value, extensionProfile.Value, provisioningState.Value, uniqueId.Value)); }