Example #1
0
 internal VirtualMachineData(ResourceIdentifier id, string name, ResourceType type, SystemData systemData, IDictionary <string, string> tags, AzureLocation location, Models.Plan plan, IReadOnlyList <VirtualMachineExtensionData> resources, ManagedServiceIdentity identity, IList <string> zones, Models.ExtendedLocation extendedLocation, HardwareProfile hardwareProfile, StorageProfile storageProfile, AdditionalCapabilities additionalCapabilities, OSProfile osProfile, NetworkProfile networkProfile, SecurityProfile securityProfile, DiagnosticsProfile diagnosticsProfile, WritableSubResource availabilitySet, WritableSubResource virtualMachineScaleSet, WritableSubResource proximityPlacementGroup, VirtualMachinePriorityTypes?priority, VirtualMachineEvictionPolicyTypes?evictionPolicy, BillingProfile billingProfile, WritableSubResource host, WritableSubResource hostGroup, string provisioningState, VirtualMachineInstanceView instanceView, string licenseType, string vmId, string extensionsTimeBudget, int?platformFaultDomain, ScheduledEventsProfile scheduledEventsProfile, string userData, CapacityReservationProfile capacityReservation, ApplicationProfile applicationProfile) : base(id, name, type, systemData, tags, location)
 {
     Plan                    = plan;
     Resources               = resources;
     Identity                = identity;
     Zones                   = zones;
     ExtendedLocation        = extendedLocation;
     HardwareProfile         = hardwareProfile;
     StorageProfile          = storageProfile;
     AdditionalCapabilities  = additionalCapabilities;
     OSProfile               = osProfile;
     NetworkProfile          = networkProfile;
     SecurityProfile         = securityProfile;
     DiagnosticsProfile      = diagnosticsProfile;
     AvailabilitySet         = availabilitySet;
     VirtualMachineScaleSet  = virtualMachineScaleSet;
     ProximityPlacementGroup = proximityPlacementGroup;
     Priority                = priority;
     EvictionPolicy          = evictionPolicy;
     BillingProfile          = billingProfile;
     Host                    = host;
     HostGroup               = hostGroup;
     ProvisioningState       = provisioningState;
     InstanceView            = instanceView;
     LicenseType             = licenseType;
     VmId                    = vmId;
     ExtensionsTimeBudget    = extensionsTimeBudget;
     PlatformFaultDomain     = platformFaultDomain;
     ScheduledEventsProfile  = scheduledEventsProfile;
     UserData                = userData;
     CapacityReservation     = capacityReservation;
     ApplicationProfile      = applicationProfile;
 }
Example #2
0
 internal VirtualMachineScaleSetVmData(ResourceIdentifier id, string name, ResourceType type, IDictionary <string, string> tags, AzureLocation location, string instanceId, Models.Sku sku, Models.Plan plan, IReadOnlyList <VirtualMachineExtensionData> resources, IReadOnlyList <string> zones, bool?latestModelApplied, string vmId, VirtualMachineScaleSetVMInstanceView instanceView, HardwareProfile hardwareProfile, StorageProfile storageProfile, AdditionalCapabilities additionalCapabilities, OSProfile osProfile, SecurityProfile securityProfile, NetworkProfile networkProfile, VirtualMachineScaleSetVMNetworkProfileConfiguration networkProfileConfiguration, DiagnosticsProfile diagnosticsProfile, WritableSubResource availabilitySet, string provisioningState, string licenseType, string modelDefinitionApplied, VirtualMachineScaleSetVMProtectionPolicy protectionPolicy, string userData) : base(id, name, type, tags, location)
 {
     InstanceId                  = instanceId;
     Sku                         = sku;
     Plan                        = plan;
     Resources                   = resources;
     Zones                       = zones;
     LatestModelApplied          = latestModelApplied;
     VmId                        = vmId;
     InstanceView                = instanceView;
     HardwareProfile             = hardwareProfile;
     StorageProfile              = storageProfile;
     AdditionalCapabilities      = additionalCapabilities;
     OsProfile                   = osProfile;
     SecurityProfile             = securityProfile;
     NetworkProfile              = networkProfile;
     NetworkProfileConfiguration = networkProfileConfiguration;
     DiagnosticsProfile          = diagnosticsProfile;
     AvailabilitySet             = availabilitySet;
     ProvisioningState           = provisioningState;
     LicenseType                 = licenseType;
     ModelDefinitionApplied      = modelDefinitionApplied;
     ProtectionPolicy            = protectionPolicy;
     UserData                    = userData;
 }
 internal RestorePointSourceMetadata(HardwareProfile hardwareProfile, RestorePointSourceVmStorageProfile storageProfile, OSProfile oSProfile, DiagnosticsProfile diagnosticsProfile, string licenseType, string vmId, SecurityProfile securityProfile, string location)
 {
     HardwareProfile    = hardwareProfile;
     StorageProfile     = storageProfile;
     OSProfile          = oSProfile;
     DiagnosticsProfile = diagnosticsProfile;
     LicenseType        = licenseType;
     VmId            = vmId;
     SecurityProfile = securityProfile;
     Location        = location;
 }
Example #4
0
 internal VirtualMachineScaleSetUpdateVMProfile(VirtualMachineScaleSetUpdateOSProfile osProfile, VirtualMachineScaleSetUpdateStorageProfile storageProfile, VirtualMachineScaleSetUpdateNetworkProfile networkProfile, DiagnosticsProfile diagnosticsProfile, VirtualMachineScaleSetExtensionProfile extensionProfile, string licenseType, BillingProfile billingProfile, ScheduledEventsProfile scheduledEventsProfile)
 {
     OsProfile              = osProfile;
     StorageProfile         = storageProfile;
     NetworkProfile         = networkProfile;
     DiagnosticsProfile     = diagnosticsProfile;
     ExtensionProfile       = extensionProfile;
     LicenseType            = licenseType;
     BillingProfile         = billingProfile;
     ScheduledEventsProfile = scheduledEventsProfile;
 }
 internal VirtualMachineScaleSetVMProfile(VirtualMachineScaleSetOSProfile osProfile, VirtualMachineScaleSetStorageProfile storageProfile, VirtualMachineScaleSetNetworkProfile networkProfile, DiagnosticsProfile diagnosticsProfile, VirtualMachineScaleSetExtensionProfile extensionProfile, string licenseType, VirtualMachinePriorityTypes?priority, VirtualMachineEvictionPolicyTypes?evictionPolicy, BillingProfile billingProfile, ScheduledEventsProfile scheduledEventsProfile)
 {
     OsProfile              = osProfile;
     StorageProfile         = storageProfile;
     NetworkProfile         = networkProfile;
     DiagnosticsProfile     = diagnosticsProfile;
     ExtensionProfile       = extensionProfile;
     LicenseType            = licenseType;
     Priority               = priority;
     EvictionPolicy         = evictionPolicy;
     BillingProfile         = billingProfile;
     ScheduledEventsProfile = scheduledEventsProfile;
 }
Example #6
0
 internal VirtualMachineScaleSetVmProfile(VirtualMachineScaleSetOSProfile osProfile, VirtualMachineScaleSetStorageProfile storageProfile, VirtualMachineScaleSetNetworkProfile networkProfile, SecurityProfile securityProfile, DiagnosticsProfile diagnosticsProfile, VirtualMachineScaleSetExtensionProfile extensionProfile, string licenseType, VirtualMachinePriorityTypes?priority, VirtualMachineEvictionPolicyTypes?evictionPolicy, BillingProfile billingProfile, ScheduledEventsProfile scheduledEventsProfile, string userData, CapacityReservationProfile capacityReservation, ApplicationProfile applicationProfile)
 {
     OsProfile              = osProfile;
     StorageProfile         = storageProfile;
     NetworkProfile         = networkProfile;
     SecurityProfile        = securityProfile;
     DiagnosticsProfile     = diagnosticsProfile;
     ExtensionProfile       = extensionProfile;
     LicenseType            = licenseType;
     Priority               = priority;
     EvictionPolicy         = evictionPolicy;
     BillingProfile         = billingProfile;
     ScheduledEventsProfile = scheduledEventsProfile;
     UserData               = userData;
     CapacityReservation    = capacityReservation;
     ApplicationProfile     = applicationProfile;
 }
Example #7
0
 /// <summary>
 /// Virtual Machine property
 /// </summary>
 /// <param name="_multiVM"></param>
 /// <param name="_hasDataDisk"></param>
 /// <param name="_useAvSet"></param>
 /// <param name="_useDiagAcc"></param>
 public Property_VirtualMachine(bool _multiVM, bool _hasDataDisk, bool _useAvSet, bool _useDiagAcc)
 {
     osProfile       = new OsProfile(_multiVM);
     hardwareProfile = new HardwareProfile();
     storageProfile  = new StorageProfile(_hasDataDisk);
     networkProfile  = new NetworkProfile(_multiVM);
     // Diagnostic Account
     if (_useDiagAcc)
     {
         diagnosticsProfile = new DiagnosticsProfile();
     }
     // Availability Set
     if (_useAvSet)
     {
         availabilitySet = new AvailabilitySet();
     }
 }
Example #8
0
        internal static VirtualMachineScaleSetVmData DeserializeVirtualMachineScaleSetVmData(JsonElement element)
        {
            Optional <string>      instanceId = default;
            Optional <Models.Sku>  sku        = default;
            Optional <Models.Plan> plan       = default;
            Optional <IReadOnlyList <VirtualMachineExtensionData> > resources = default;
            Optional <IReadOnlyList <string> > zones = default;
            IDictionary <string, string>       tags  = default;
            AzureLocation      location           = default;
            ResourceIdentifier id                 = default;
            string             name               = default;
            ResourceType       type               = default;
            SystemData         systemData         = default;
            Optional <bool>    latestModelApplied = default;
            Optional <string>  vmId               = default;
            Optional <VirtualMachineScaleSetVmInstanceView> instanceView = default;
            Optional <HardwareProfile>        hardwareProfile            = default;
            Optional <StorageProfile>         storageProfile             = default;
            Optional <AdditionalCapabilities> additionalCapabilities     = default;
            Optional <OSProfile>       osProfile       = default;
            Optional <SecurityProfile> securityProfile = default;
            Optional <NetworkProfile>  networkProfile  = default;
            Optional <VirtualMachineScaleSetVmNetworkProfileConfiguration> networkProfileConfiguration = default;
            Optional <DiagnosticsProfile>  diagnosticsProfile = default;
            Optional <WritableSubResource> availabilitySet    = default;
            Optional <string> provisioningState      = default;
            Optional <string> licenseType            = default;
            Optional <string> modelDefinitionApplied = default;
            Optional <VirtualMachineScaleSetVmProtectionPolicy> protectionPolicy = default;
            Optional <string> userData = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("instanceId"))
                {
                    instanceId = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("sku"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    sku = Models.Sku.DeserializeSku(property.Value);
                    continue;
                }
                if (property.NameEquals("plan"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    plan = Models.Plan.DeserializePlan(property.Value);
                    continue;
                }
                if (property.NameEquals("resources"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <VirtualMachineExtensionData> array = new List <VirtualMachineExtensionData>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(VirtualMachineExtensionData.DeserializeVirtualMachineExtensionData(item));
                    }
                    resources = array;
                    continue;
                }
                if (property.NameEquals("zones"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <string> array = new List <string>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(item.GetString());
                    }
                    zones = array;
                    continue;
                }
                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 = 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 = 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("latestModelApplied"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            latestModelApplied = property0.Value.GetBoolean();
                            continue;
                        }
                        if (property0.NameEquals("vmId"))
                        {
                            vmId = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("instanceView"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            instanceView = VirtualMachineScaleSetVmInstanceView.DeserializeVirtualMachineScaleSetVmInstanceView(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("hardwareProfile"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            hardwareProfile = HardwareProfile.DeserializeHardwareProfile(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("storageProfile"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            storageProfile = StorageProfile.DeserializeStorageProfile(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("additionalCapabilities"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            additionalCapabilities = AdditionalCapabilities.DeserializeAdditionalCapabilities(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("osProfile"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            osProfile = OSProfile.DeserializeOSProfile(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("securityProfile"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            securityProfile = SecurityProfile.DeserializeSecurityProfile(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("networkProfile"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            networkProfile = NetworkProfile.DeserializeNetworkProfile(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("networkProfileConfiguration"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            networkProfileConfiguration = VirtualMachineScaleSetVmNetworkProfileConfiguration.DeserializeVirtualMachineScaleSetVmNetworkProfileConfiguration(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("diagnosticsProfile"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            diagnosticsProfile = DiagnosticsProfile.DeserializeDiagnosticsProfile(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("availabilitySet"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            availabilitySet = JsonSerializer.Deserialize <WritableSubResource>(property0.Value.ToString());
                            continue;
                        }
                        if (property0.NameEquals("provisioningState"))
                        {
                            provisioningState = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("licenseType"))
                        {
                            licenseType = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("modelDefinitionApplied"))
                        {
                            modelDefinitionApplied = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("protectionPolicy"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            protectionPolicy = VirtualMachineScaleSetVmProtectionPolicy.DeserializeVirtualMachineScaleSetVmProtectionPolicy(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("userData"))
                        {
                            userData = property0.Value.GetString();
                            continue;
                        }
                    }
                    continue;
                }
            }
            return(new VirtualMachineScaleSetVmData(id, name, type, systemData, tags, location, instanceId.Value, sku.Value, plan.Value, Optional.ToList(resources), Optional.ToList(zones), Optional.ToNullable(latestModelApplied), vmId.Value, instanceView.Value, hardwareProfile.Value, storageProfile.Value, additionalCapabilities.Value, osProfile.Value, securityProfile.Value, networkProfile.Value, networkProfileConfiguration.Value, diagnosticsProfile.Value, availabilitySet, provisioningState.Value, licenseType.Value, modelDefinitionApplied.Value, protectionPolicy.Value, userData.Value));
        }
        internal static VirtualMachineData DeserializeVirtualMachineData(JsonElement element)
        {
            Optional <Plan> plan = default;
            Optional <IReadOnlyList <VirtualMachineExtensionData> > resources = default;
            Optional <ResourceIdentity>  identity                                = default;
            Optional <IList <string> >   zones                                   = default;
            Optional <ExtendedLocation>  extendedLocation                        = default;
            IDictionary <string, string> tags                                    = default;
            Location                                     location                = default;
            ResourceIdentifier                           id                      = default;
            string                                       name                    = default;
            ResourceType                                 type                    = default;
            Optional <HardwareProfile>                   hardwareProfile         = default;
            Optional <StorageProfile>                    storageProfile          = default;
            Optional <AdditionalCapabilities>            additionalCapabilities  = default;
            Optional <OSProfile>                         osProfile               = default;
            Optional <NetworkProfile>                    networkProfile          = default;
            Optional <SecurityProfile>                   securityProfile         = default;
            Optional <DiagnosticsProfile>                diagnosticsProfile      = default;
            Optional <Models.SubResource>                availabilitySet         = default;
            Optional <Models.SubResource>                virtualMachineScaleSet  = default;
            Optional <Models.SubResource>                proximityPlacementGroup = default;
            Optional <VirtualMachinePriorityTypes>       priority                = default;
            Optional <VirtualMachineEvictionPolicyTypes> evictionPolicy          = default;
            Optional <BillingProfile>                    billingProfile          = default;
            Optional <Models.SubResource>                host                    = default;
            Optional <Models.SubResource>                hostGroup               = default;
            Optional <string>                            provisioningState       = default;
            Optional <VirtualMachineInstanceView>        instanceView            = default;
            Optional <string>                            licenseType             = default;
            Optional <string>                            vmId                    = default;
            Optional <string>                            extensionsTimeBudget    = default;
            Optional <int>                               platformFaultDomain     = default;
            Optional <ScheduledEventsProfile>            scheduledEventsProfile  = default;
            Optional <string>                            userData                = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("plan"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    plan = Plan.DeserializePlan(property.Value);
                    continue;
                }
                if (property.NameEquals("resources"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <VirtualMachineExtensionData> array = new List <VirtualMachineExtensionData>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(VirtualMachineExtensionData.DeserializeVirtualMachineExtensionData(item));
                    }
                    resources = array;
                    continue;
                }
                if (property.NameEquals("identity"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    identity = JsonSerializer.Deserialize <ResourceIdentity>(property.Value.ToString());
                    continue;
                }
                if (property.NameEquals("zones"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <string> array = new List <string>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(item.GetString());
                    }
                    zones = array;
                    continue;
                }
                if (property.NameEquals("extendedLocation"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    extendedLocation = ExtendedLocation.DeserializeExtendedLocation(property.Value);
                    continue;
                }
                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 = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("id"))
                {
                    id = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("type"))
                {
                    type = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("properties"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        if (property0.NameEquals("hardwareProfile"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            hardwareProfile = HardwareProfile.DeserializeHardwareProfile(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("storageProfile"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            storageProfile = StorageProfile.DeserializeStorageProfile(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("additionalCapabilities"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            additionalCapabilities = AdditionalCapabilities.DeserializeAdditionalCapabilities(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("osProfile"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            osProfile = OSProfile.DeserializeOSProfile(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("networkProfile"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            networkProfile = NetworkProfile.DeserializeNetworkProfile(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("securityProfile"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            securityProfile = SecurityProfile.DeserializeSecurityProfile(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("diagnosticsProfile"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            diagnosticsProfile = DiagnosticsProfile.DeserializeDiagnosticsProfile(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("availabilitySet"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            availabilitySet = Models.SubResource.DeserializeSubResource(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("virtualMachineScaleSet"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            virtualMachineScaleSet = Models.SubResource.DeserializeSubResource(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("proximityPlacementGroup"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            proximityPlacementGroup = Models.SubResource.DeserializeSubResource(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("priority"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            priority = new VirtualMachinePriorityTypes(property0.Value.GetString());
                            continue;
                        }
                        if (property0.NameEquals("evictionPolicy"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            evictionPolicy = new VirtualMachineEvictionPolicyTypes(property0.Value.GetString());
                            continue;
                        }
                        if (property0.NameEquals("billingProfile"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            billingProfile = BillingProfile.DeserializeBillingProfile(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("host"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            host = Models.SubResource.DeserializeSubResource(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("hostGroup"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            hostGroup = Models.SubResource.DeserializeSubResource(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("provisioningState"))
                        {
                            provisioningState = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("instanceView"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            instanceView = VirtualMachineInstanceView.DeserializeVirtualMachineInstanceView(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("licenseType"))
                        {
                            licenseType = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("vmId"))
                        {
                            vmId = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("extensionsTimeBudget"))
                        {
                            extensionsTimeBudget = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("platformFaultDomain"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            platformFaultDomain = property0.Value.GetInt32();
                            continue;
                        }
                        if (property0.NameEquals("scheduledEventsProfile"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            scheduledEventsProfile = ScheduledEventsProfile.DeserializeScheduledEventsProfile(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("userData"))
                        {
                            userData = property0.Value.GetString();
                            continue;
                        }
                    }
                    continue;
                }
            }
            return(new VirtualMachineData(id, name, type, tags, location, plan.Value, Optional.ToList(resources), identity, Optional.ToList(zones), extendedLocation.Value, hardwareProfile.Value, storageProfile.Value, additionalCapabilities.Value, osProfile.Value, networkProfile.Value, securityProfile.Value, diagnosticsProfile.Value, availabilitySet.Value, virtualMachineScaleSet.Value, proximityPlacementGroup.Value, Optional.ToNullable(priority), Optional.ToNullable(evictionPolicy), billingProfile.Value, host.Value, hostGroup.Value, provisioningState.Value, instanceView.Value, licenseType.Value, vmId.Value, extensionsTimeBudget.Value, Optional.ToNullable(platformFaultDomain), scheduledEventsProfile.Value, userData.Value));
        }
        private VirtualMachineScaleSet CreateVMScaleSetAndGetOperationResponse(
            string rgName,
            string vmssName,
            StorageAccount storageAccount,
            ImageReference imageRef,
            out VirtualMachineScaleSet inputVMScaleSet,
            VirtualMachineScaleSetExtensionProfile extensionProfile = null,
            Action <VirtualMachineScaleSet> vmScaleSetCustomizer    = null,
            bool createWithPublicIpAddress = false,
            bool createWithManagedDisks    = false,
            bool hasDiffDisks          = false,
            bool createWithHealthProbe = false,
            Subnet subnet              = null,
            IList <string> zones       = null,
            int?osDiskSizeInGB         = null,
            string ppgId               = null,
            string machineSizeType     = null,
            bool?enableUltraSSD        = false,
            string diskEncryptionSetId = null,
            AutomaticRepairsPolicy automaticRepairsPolicy = null,
            bool?encryptionAtHostEnabled = null,
            bool singlePlacementGroup    = true,
            DiagnosticsProfile bootDiagnosticsProfile = null,
            int?faultDomainCount = null,
            int?capacity         = null,
            string dedicatedHostGroupReferenceId = null,
            string dedicatedHostGroupName        = null,
            string dedicatedHostName             = null,
            string userData = null,
            string capacityReservationGroupReferenceId = null)
        {
            // Create the resource Group, it might have been already created during StorageAccount creation.
            var resourceGroup = m_ResourcesClient.ResourceGroups.CreateOrUpdate(
                rgName,
                new ResourceGroup
            {
                Location = m_location
            });

            var getPublicIpAddressResponse = createWithPublicIpAddress ? null : CreatePublicIP(rgName);

            var subnetResponse = subnet ?? CreateVNET(rgName);

            var nicResponse = CreateNIC(
                rgName,
                subnetResponse,
                getPublicIpAddressResponse != null ? getPublicIpAddressResponse.IpAddress : null);

            var loadBalancer = (getPublicIpAddressResponse != null && createWithHealthProbe) ?
                               CreatePublicLoadBalancerWithProbe(rgName, getPublicIpAddressResponse) : null;

            Assert.True(createWithManagedDisks || storageAccount != null);
            inputVMScaleSet = CreateDefaultVMScaleSetInput(rgName, storageAccount?.Name, imageRef, subnetResponse.Id, hasManagedDisks: createWithManagedDisks,
                                                           healthProbeId: loadBalancer?.Probes?.FirstOrDefault()?.Id,
                                                           loadBalancerBackendPoolId: loadBalancer?.BackendAddressPools?.FirstOrDefault()?.Id, zones: zones, osDiskSizeInGB: osDiskSizeInGB,
                                                           machineSizeType: machineSizeType, enableUltraSSD: enableUltraSSD, diskEncryptionSetId: diskEncryptionSetId, automaticRepairsPolicy: automaticRepairsPolicy,
                                                           bootDiagnosticsProfile: bootDiagnosticsProfile, faultDomainCount: faultDomainCount, capacity: capacity);
            if (vmScaleSetCustomizer != null)
            {
                vmScaleSetCustomizer(inputVMScaleSet);
            }

            if (encryptionAtHostEnabled != null)
            {
                inputVMScaleSet.VirtualMachineProfile.SecurityProfile = new SecurityProfile
                {
                    EncryptionAtHost = encryptionAtHostEnabled.Value
                };
            }

            inputVMScaleSet.VirtualMachineProfile.UserData = userData;

            if (hasDiffDisks)
            {
                VirtualMachineScaleSetOSDisk osDisk = new VirtualMachineScaleSetOSDisk();
                osDisk.Caching          = CachingTypes.ReadOnly;
                osDisk.CreateOption     = DiskCreateOptionTypes.FromImage;
                osDisk.DiffDiskSettings = new DiffDiskSettings {
                    Option    = DiffDiskOptions.Local,
                    Placement = DiffDiskPlacement.CacheDisk
                };
                inputVMScaleSet.VirtualMachineProfile.StorageProfile.OsDisk = osDisk;
            }

            inputVMScaleSet.VirtualMachineProfile.ExtensionProfile = extensionProfile;

            if (ppgId != null)
            {
                inputVMScaleSet.ProximityPlacementGroup = new Microsoft.Azure.Management.Compute.Models.SubResource()
                {
                    Id = ppgId
                };
            }

            if (dedicatedHostGroupReferenceId != null)
            {
                CreateDedicatedHostGroup(rgName, dedicatedHostGroupName, availabilityZone: null);
                CreateDedicatedHost(rgName, dedicatedHostGroupName, dedicatedHostName, "DSv3-Type1");
                inputVMScaleSet.HostGroup = new CM.SubResource()
                {
                    Id = dedicatedHostGroupReferenceId
                };
            }

            if (!string.IsNullOrEmpty(capacityReservationGroupReferenceId))
            {
                inputVMScaleSet.VirtualMachineProfile.CapacityReservation = new CapacityReservationProfile
                {
                    CapacityReservationGroup = new CM.SubResource
                    {
                        Id = capacityReservationGroupReferenceId
                    }
                };
            }

            inputVMScaleSet.SinglePlacementGroup = singlePlacementGroup ? (bool?)null : false;

            VirtualMachineScaleSet createOrUpdateResponse = null;

            try
            {
                createOrUpdateResponse = m_CrpClient.VirtualMachineScaleSets.CreateOrUpdate(rgName, vmssName, inputVMScaleSet);

                Assert.True(createOrUpdateResponse.Name == vmssName);
                Assert.True(createOrUpdateResponse.Location.ToLower() == inputVMScaleSet.Location.ToLower().Replace(" ", ""));
            }
            catch (CloudException e)
            {
                if (e.Message.Contains("the allotted time"))
                {
                    createOrUpdateResponse = m_CrpClient.VirtualMachineScaleSets.Get(rgName, vmssName);
                }
                else
                {
                    throw;
                }
            }

            ValidateVMScaleSet(inputVMScaleSet, createOrUpdateResponse, createWithManagedDisks, ppgId: ppgId, dedicatedHostGroupReferenceId: dedicatedHostGroupReferenceId);

            return(createOrUpdateResponse);
        }
        public VirtualMachineScaleSet CreateVMScaleSet_NoAsyncTracking(
            string rgName,
            string vmssName,
            StorageAccount storageAccount,
            ImageReference imageRef,
            out VirtualMachineScaleSet inputVMScaleSet,
            VirtualMachineScaleSetExtensionProfile extensionProfile = null,
            Action <VirtualMachineScaleSet> vmScaleSetCustomizer    = null,
            bool createWithPublicIpAddress = false,
            bool createWithManagedDisks    = false,
            bool hasDiffDisks          = false,
            bool createWithHealthProbe = false,
            Subnet subnet              = null,
            IList <string> zones       = null,
            int?osDiskSizeInGB         = null,
            string ppgId               = null,
            string machineSizeType     = null,
            bool?enableUltraSSD        = false,
            string diskEncryptionSetId = null,
            AutomaticRepairsPolicy automaticRepairsPolicy = null,
            bool?encryptionAtHostEnabled = null,
            bool singlePlacementGroup    = true,
            DiagnosticsProfile bootDiagnosticsProfile = null,
            int?faultDomainCount = null,
            int?capacity         = null,
            string dedicatedHostGroupReferenceId = null,
            string dedicatedHostGroupName        = null,
            string dedicatedHostName             = null,
            string userData = null,
            string capacityReservationGroupReferenceId = null)
        {
            try
            {
                var createOrUpdateResponse = CreateVMScaleSetAndGetOperationResponse(rgName,
                                                                                     vmssName,
                                                                                     storageAccount,
                                                                                     imageRef,
                                                                                     out inputVMScaleSet,
                                                                                     extensionProfile,
                                                                                     vmScaleSetCustomizer,
                                                                                     createWithPublicIpAddress,
                                                                                     createWithManagedDisks,
                                                                                     hasDiffDisks,
                                                                                     createWithHealthProbe,
                                                                                     subnet,
                                                                                     zones,
                                                                                     osDiskSizeInGB,
                                                                                     ppgId: ppgId,
                                                                                     machineSizeType: machineSizeType,
                                                                                     enableUltraSSD: enableUltraSSD,
                                                                                     diskEncryptionSetId: diskEncryptionSetId,
                                                                                     automaticRepairsPolicy: automaticRepairsPolicy,
                                                                                     encryptionAtHostEnabled: encryptionAtHostEnabled,
                                                                                     singlePlacementGroup: singlePlacementGroup,
                                                                                     bootDiagnosticsProfile: bootDiagnosticsProfile,
                                                                                     faultDomainCount: faultDomainCount,
                                                                                     capacity: capacity,
                                                                                     dedicatedHostGroupReferenceId: dedicatedHostGroupReferenceId,
                                                                                     dedicatedHostGroupName: dedicatedHostGroupName,
                                                                                     dedicatedHostName: dedicatedHostName,
                                                                                     userData: userData,
                                                                                     capacityReservationGroupReferenceId: capacityReservationGroupReferenceId);

                var getResponse = m_CrpClient.VirtualMachineScaleSets.Get(rgName, vmssName);

                return(getResponse);
            }
            catch
            {
                // TODO: It is better to issue Delete and forget.
                m_ResourcesClient.ResourceGroups.Delete(rgName);
                throw;
            }
        }
        protected VirtualMachineScaleSet CreateDefaultVMScaleSetInput(
            string rgName,
            string storageAccountName,
            ImageReference imageRef,
            string subnetId,
            bool hasManagedDisks             = false,
            string healthProbeId             = null,
            string loadBalancerBackendPoolId = null,
            IList <string> zones             = null,
            int?osDiskSizeInGB         = null,
            string machineSizeType     = null,
            bool?enableUltraSSD        = false,
            string diskEncryptionSetId = null,
            AutomaticRepairsPolicy automaticRepairsPolicy = null,
            DiagnosticsProfile bootDiagnosticsProfile     = null,
            int?faultDomainCount = null,
            int?capacity         = null)
        {
            // Generate Container name to hold disk VHds
            string containerName = TestUtilities.GenerateName(TestPrefix);
            var    vhdContainer  = "https://" + storageAccountName + ".blob.core.windows.net/" + containerName;
            var    vmssName      = TestUtilities.GenerateName("vmss");
            bool   createOSDisk  = !hasManagedDisks || osDiskSizeInGB != null;

            string vmSize = zones == null ? VirtualMachineSizeTypes.StandardA1V2 : VirtualMachineSizeTypes.StandardA1V2;

            var vmScaleSet = new VirtualMachineScaleSet()
            {
                Location = m_location,
                Tags     = new Dictionary <string, string>()
                {
                    { "RG", "rg" }, { "testTag", "1" }
                },
                Sku = new CM.Sku()
                {
                    Capacity = capacity ?? 2,
                    Name     = machineSizeType == null ? vmSize : machineSizeType
                },
                Zones         = zones,
                Overprovision = false,
                UpgradePolicy = new UpgradePolicy()
                {
                    Mode = UpgradeMode.Automatic
                },
                VirtualMachineProfile = new VirtualMachineScaleSetVMProfile()
                {
                    StorageProfile = new VirtualMachineScaleSetStorageProfile()
                    {
                        ImageReference = imageRef,
                        OsDisk         = !createOSDisk ? null : new VirtualMachineScaleSetOSDisk
                        {
                            Caching       = CachingTypes.None,
                            CreateOption  = DiskCreateOptionTypes.FromImage,
                            Name          = hasManagedDisks ? null : "test",
                            VhdContainers = hasManagedDisks ? null : new List <string> {
                                vhdContainer
                            },
                            DiskSizeGB  = osDiskSizeInGB,
                            ManagedDisk = diskEncryptionSetId == null ? null: new VirtualMachineScaleSetManagedDiskParameters()
                            {
                                StorageAccountType = StorageAccountTypes.StandardLRS,
                                DiskEncryptionSet  = new DiskEncryptionSetParameters()
                                {
                                    Id = diskEncryptionSetId
                                }
                            }
                        },
                        DataDisks = !hasManagedDisks ? null : new List <VirtualMachineScaleSetDataDisk>
                        {
                            new VirtualMachineScaleSetDataDisk
                            {
                                Lun          = 1,
                                CreateOption = DiskCreateOptionTypes.Empty,
                                DiskSizeGB   = 128,
                                ManagedDisk  = diskEncryptionSetId == null ? null: new VirtualMachineScaleSetManagedDiskParameters()
                                {
                                    StorageAccountType = StorageAccountTypes.StandardLRS,
                                    DiskEncryptionSet  = new DiskEncryptionSetParameters()
                                    {
                                        Id = diskEncryptionSetId
                                    }
                                }
                            }
                        }
                    },
                    OsProfile = new VirtualMachineScaleSetOSProfile()
                    {
                        ComputerNamePrefix = "test",
                        AdminUsername      = "******",
                        AdminPassword      = PLACEHOLDER,
                        CustomData         = Convert.ToBase64String(Encoding.UTF8.GetBytes("Custom data"))
                    },
                    NetworkProfile = new VirtualMachineScaleSetNetworkProfile()
                    {
                        HealthProbe = healthProbeId == null ? null : new ApiEntityReference
                        {
                            Id = healthProbeId
                        },
                        NetworkInterfaceConfigurations = new List <VirtualMachineScaleSetNetworkConfiguration>()
                        {
                            new VirtualMachineScaleSetNetworkConfiguration()
                            {
                                Name             = TestUtilities.GenerateName("vmsstestnetconfig"),
                                Primary          = true,
                                IpConfigurations = new List <VirtualMachineScaleSetIPConfiguration>
                                {
                                    new VirtualMachineScaleSetIPConfiguration()
                                    {
                                        Name   = TestUtilities.GenerateName("vmsstestnetconfig"),
                                        Subnet = new Microsoft.Azure.Management.Compute.Models.ApiEntityReference()
                                        {
                                            Id = subnetId
                                        },
                                        LoadBalancerBackendAddressPools = (loadBalancerBackendPoolId != null) ?
                                                                          new List <Microsoft.Azure.Management.Compute.Models.SubResource> {
                                            new Microsoft.Azure.Management.Compute.Models.SubResource(loadBalancerBackendPoolId)
                                        } : null,
                                        ApplicationGatewayBackendAddressPools = new List <Microsoft.Azure.Management.Compute.Models.SubResource>(),
                                    }
                                }
                            }
                        }
                    },
                    ExtensionProfile = new VirtualMachineScaleSetExtensionProfile(),
                },
                AutomaticRepairsPolicy = automaticRepairsPolicy
            };

            if (bootDiagnosticsProfile != null)
            {
                vmScaleSet.VirtualMachineProfile.DiagnosticsProfile = bootDiagnosticsProfile;
            }

            if (faultDomainCount != null)
            {
                vmScaleSet.PlatformFaultDomainCount = faultDomainCount;
            }

            if (enableUltraSSD == true)
            {
                vmScaleSet.AdditionalCapabilities = new AdditionalCapabilities
                {
                    UltraSSDEnabled = true
                };

                VirtualMachineScaleSetOSDisk osDisk = vmScaleSet.VirtualMachineProfile.StorageProfile.OsDisk;
                osDisk.ManagedDisk = osDisk.ManagedDisk ?? new VirtualMachineScaleSetManagedDiskParameters();
                osDisk.ManagedDisk.StorageAccountType = StorageAccountTypes.PremiumLRS;

                foreach (VirtualMachineScaleSetDataDisk dataDisk in vmScaleSet.VirtualMachineProfile.StorageProfile.DataDisks)
                {
                    dataDisk.ManagedDisk = dataDisk.ManagedDisk ?? new VirtualMachineScaleSetManagedDiskParameters();
                    dataDisk.ManagedDisk.StorageAccountType = StorageAccountTypes.UltraSSDLRS;
                }
            }

            return(vmScaleSet);
        }