Esempio n. 1
0
        public void DefaultExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            if (this.VM.DiagnosticsProfile == null)
            {
                var storageUri = GetOrCreateStorageAccountForBootDiagnostics();

                if (storageUri != null)
                {
                    this.VM.DiagnosticsProfile = new DiagnosticsProfile
                    {
                        BootDiagnostics = new BootDiagnostics
                        {
                            Enabled    = true,
                            StorageUri = storageUri.ToString(),
                        }
                    };
                }
            }

            CM.ExtendedLocation ExtendedLocation = null;
            if (this.EdgeZone != null)
            {
                ExtendedLocation = new CM.ExtendedLocation {
                    Name = this.EdgeZone, Type = CM.ExtendedLocationTypes.EdgeZone
                };
            }

            if (ShouldProcess(this.VM.Name, VerbsCommon.New))
            {
                ExecuteClientAction(() =>
                {
                    var parameters = new VirtualMachine
                    {
                        DiagnosticsProfile = this.VM.DiagnosticsProfile,
                        HardwareProfile    = this.VM.HardwareProfile,
                        StorageProfile     = this.VM.StorageProfile,
                        NetworkProfile     = this.VM.NetworkProfile,
                        OsProfile          = this.VM.OSProfile,
                        Plan                    = this.VM.Plan,
                        LicenseType             = this.LicenseType ?? this.VM.LicenseType,
                        AvailabilitySet         = this.VM.AvailabilitySetReference,
                        Location                = this.Location ?? this.VM.Location,
                        ExtendedLocation        = ExtendedLocation,
                        Tags                    = this.Tag != null ? this.Tag.ToDictionary() : this.VM.Tags,
                        Identity                = ComputeAutoMapperProfile.Mapper.Map <VirtualMachineIdentity>(this.VM.Identity),
                        Zones                   = this.Zone ?? this.VM.Zones,
                        ProximityPlacementGroup = this.VM.ProximityPlacementGroup,
                        Host                    = this.VM.Host,
                        VirtualMachineScaleSet  = this.VM.VirtualMachineScaleSet,
                        AdditionalCapabilities  = this.VM.AdditionalCapabilities,
                        Priority                = this.VM.Priority,
                        EvictionPolicy          = this.VM.EvictionPolicy,
                        BillingProfile          = this.VM.BillingProfile,
                        SecurityProfile         = this.VM.SecurityProfile
                    };

                    Dictionary <string, List <string> > auxAuthHeader = null;
                    if (!string.IsNullOrEmpty(parameters.StorageProfile?.ImageReference?.Id))
                    {
                        var resourceId = ResourceId.TryParse(parameters.StorageProfile.ImageReference.Id);

                        if (string.Equals(ComputeStrategy.Namespace, resourceId?.ResourceType?.Namespace, StringComparison.OrdinalIgnoreCase) &&
                            string.Equals("galleries", resourceId?.ResourceType?.Provider, StringComparison.OrdinalIgnoreCase) &&
                            !string.Equals(this.ComputeClient?.ComputeManagementClient?.SubscriptionId, resourceId?.SubscriptionId, StringComparison.OrdinalIgnoreCase))
                        {
                            List <string> resourceIds = new List <string>();
                            resourceIds.Add(parameters.StorageProfile.ImageReference.Id);
                            var auxHeaderDictionary = GetAuxilaryAuthHeaderFromResourceIds(resourceIds);
                            if (auxHeaderDictionary != null && auxHeaderDictionary.Count > 0)
                            {
                                auxAuthHeader = new Dictionary <string, List <string> >(auxHeaderDictionary);
                            }
                        }
                    }

                    var result = this.VirtualMachineClient.CreateOrUpdateWithHttpMessagesAsync(
                        this.ResourceGroupName,
                        this.VM.Name,
                        parameters,
                        auxAuthHeader).GetAwaiter().GetResult();
                    var psResult = ComputeAutoMapperProfile.Mapper.Map <PSAzureOperationResponse>(result);

                    if (!(this.DisableBginfoExtension.IsPresent || IsLinuxOs()))
                    {
                        var currentBginfoVersion = GetBginfoExtension();

                        if (!string.IsNullOrEmpty(currentBginfoVersion))
                        {
                            var extensionParameters = new VirtualMachineExtension
                            {
                                Location  = this.Location,
                                Publisher = VirtualMachineBGInfoExtensionContext.ExtensionDefaultPublisher,
                                VirtualMachineExtensionType = VirtualMachineBGInfoExtensionContext.ExtensionDefaultName,
                                TypeHandlerVersion          = currentBginfoVersion,
                                AutoUpgradeMinorVersion     = true,
                            };

                            typeof(CM.Resource).GetRuntimeProperty("Name")
                            .SetValue(extensionParameters, VirtualMachineBGInfoExtensionContext.ExtensionDefaultName);
                            typeof(CM.Resource).GetRuntimeProperty("Type")
                            .SetValue(extensionParameters, VirtualMachineExtensionType);

                            var op2 = ComputeClient.ComputeManagementClient.VirtualMachineExtensions.CreateOrUpdateWithHttpMessagesAsync(
                                this.ResourceGroupName,
                                this.VM.Name,
                                VirtualMachineBGInfoExtensionContext.ExtensionDefaultName,
                                extensionParameters).GetAwaiter().GetResult();
                            psResult = ComputeAutoMapperProfile.Mapper.Map <PSAzureOperationResponse>(op2);
                        }
                    }
                    WriteObject(psResult);
                });
            }
        }
Esempio n. 2
0
 public VirtualMachineScaleSet(string location, string id, string name, string type, IDictionary <string, string> tags, Sku sku, Plan plan, UpgradePolicy upgradePolicy, AutomaticRepairsPolicy automaticRepairsPolicy, VirtualMachineScaleSetVMProfile virtualMachineProfile, string provisioningState, bool?overprovision, bool?doNotRunExtensionsOnOverprovisionedVMs, string uniqueId, bool?singlePlacementGroup, bool?zoneBalance, int?platformFaultDomainCount, SubResource proximityPlacementGroup, SubResource hostGroup, AdditionalCapabilities additionalCapabilities, ScaleInPolicy scaleInPolicy, VirtualMachineScaleSetIdentity identity, IList <string> zones, ExtendedLocation extendedLocation)
     : base(location, id, name, type, tags)
 {
     Sku                    = sku;
     Plan                   = plan;
     UpgradePolicy          = upgradePolicy;
     AutomaticRepairsPolicy = automaticRepairsPolicy;
     VirtualMachineProfile  = virtualMachineProfile;
     ProvisioningState      = provisioningState;
     Overprovision          = overprovision;
     DoNotRunExtensionsOnOverprovisionedVMs = doNotRunExtensionsOnOverprovisionedVMs;
     UniqueId                 = uniqueId;
     SinglePlacementGroup     = singlePlacementGroup;
     ZoneBalance              = zoneBalance;
     PlatformFaultDomainCount = platformFaultDomainCount;
     ProximityPlacementGroup  = proximityPlacementGroup;
     HostGroup                = hostGroup;
     AdditionalCapabilities   = additionalCapabilities;
     ScaleInPolicy            = scaleInPolicy;
     Identity                 = identity;
     Zones            = zones;
     ExtendedLocation = extendedLocation;
     CustomInit();
 }
 /// <summary>
 /// Initializes a new instance of the VirtualMachineScaleSet class.
 /// </summary>
 /// <param name="location">Resource location</param>
 /// <param name="id">Resource Id</param>
 /// <param name="name">Resource name</param>
 /// <param name="type">Resource type</param>
 /// <param name="tags">Resource tags</param>
 /// <param name="sku">The virtual machine scale set sku.</param>
 /// <param name="plan">Specifies information about the marketplace
 /// image used to create the virtual machine. This element is only used
 /// for marketplace images. Before you can use a marketplace image from
 /// an API, you must enable the image for programmatic use.  In the
 /// Azure portal, find the marketplace image that you want to use and
 /// then click **Want to deploy programmatically, Get Started -&gt;**.
 /// Enter any required information and then click **Save**.</param>
 /// <param name="upgradePolicy">The upgrade policy.</param>
 /// <param name="automaticRepairsPolicy">Policy for automatic
 /// repairs.</param>
 /// <param name="virtualMachineProfile">The virtual machine
 /// profile.</param>
 /// <param name="provisioningState">The provisioning state, which only
 /// appears in the response.</param>
 /// <param name="overprovision">Specifies whether the Virtual Machine
 /// Scale Set should be overprovisioned.</param>
 /// <param name="doNotRunExtensionsOnOverprovisionedVMs">When
 /// Overprovision is enabled, extensions are launched only on the
 /// requested number of VMs which are finally kept. This property will
 /// hence ensure that the extensions do not run on the extra
 /// overprovisioned VMs.</param>
 /// <param name="uniqueId">Specifies the ID which uniquely identifies a
 /// Virtual Machine Scale Set.</param>
 /// <param name="singlePlacementGroup">When true this limits the scale
 /// set to a single placement group, of max size 100 virtual machines.
 /// NOTE: If singlePlacementGroup is true, it may be modified to false.
 /// However, if singlePlacementGroup is false, it may not be modified
 /// to true.</param>
 /// <param name="zoneBalance">Whether to force strictly even Virtual
 /// Machine distribution cross x-zones in case there is zone outage.
 /// zoneBalance property can only be set if the zones property of the
 /// scale set contains more than one zone. If there are no zones or
 /// only one zone specified, then zoneBalance property should not be
 /// set.</param>
 /// <param name="platformFaultDomainCount">Fault Domain count for each
 /// placement group.</param>
 /// <param name="proximityPlacementGroup">Specifies information about
 /// the proximity placement group that the virtual machine scale set
 /// should be assigned to. &lt;br&gt;&lt;br&gt;Minimum api-version:
 /// 2018-04-01.</param>
 /// <param name="hostGroup">Specifies information about the dedicated
 /// host group that the virtual machine scale set resides in.
 /// &lt;br&gt;&lt;br&gt;Minimum api-version: 2020-06-01.</param>
 /// <param name="additionalCapabilities">Specifies additional
 /// capabilities enabled or disabled on the Virtual Machines in the
 /// Virtual Machine Scale Set. For instance: whether the Virtual
 /// Machines have the capability to support attaching managed data
 /// disks with UltraSSD_LRS storage account type.</param>
 /// <param name="scaleInPolicy">Specifies the policies applied when
 /// scaling in Virtual Machines in the Virtual Machine Scale
 /// Set.</param>
 /// <param name="orchestrationMode">Specifies the orchestration mode
 /// for the virtual machine scale set. Possible values include:
 /// 'Uniform', 'Flexible'</param>
 /// <param name="spotRestorePolicy">Specifies the Spot Restore
 /// properties for the virtual machine scale set.</param>
 /// <param name="timeCreated">Specifies the time at which the Virtual
 /// Machine Scale Set resource was created.&lt;br&gt;&lt;br&gt;Minimum
 /// api-version: 2021-11-01.</param>
 /// <param name="identity">The identity of the virtual machine scale
 /// set, if configured.</param>
 /// <param name="zones">The virtual machine scale set zones. NOTE:
 /// Availability zones can only be set when you create the scale
 /// set</param>
 /// <param name="extendedLocation">The extended location of the Virtual
 /// Machine Scale Set.</param>
 public VirtualMachineScaleSet(string location, string id = default(string), string name = default(string), string type = default(string), IDictionary <string, string> tags = default(IDictionary <string, string>), Sku sku = default(Sku), Plan plan = default(Plan), UpgradePolicy upgradePolicy = default(UpgradePolicy), AutomaticRepairsPolicy automaticRepairsPolicy = default(AutomaticRepairsPolicy), VirtualMachineScaleSetVMProfile virtualMachineProfile = default(VirtualMachineScaleSetVMProfile), string provisioningState = default(string), bool?overprovision = default(bool?), bool?doNotRunExtensionsOnOverprovisionedVMs = default(bool?), string uniqueId = default(string), bool?singlePlacementGroup = default(bool?), bool?zoneBalance = default(bool?), int?platformFaultDomainCount = default(int?), SubResource proximityPlacementGroup = default(SubResource), SubResource hostGroup = default(SubResource), AdditionalCapabilities additionalCapabilities = default(AdditionalCapabilities), ScaleInPolicy scaleInPolicy = default(ScaleInPolicy), string orchestrationMode = default(string), SpotRestorePolicy spotRestorePolicy = default(SpotRestorePolicy), System.DateTime?timeCreated = default(System.DateTime?), VirtualMachineScaleSetIdentity identity = default(VirtualMachineScaleSetIdentity), IList <string> zones = default(IList <string>), ExtendedLocation extendedLocation = default(ExtendedLocation))
     : base(location, id, name, type, tags)
 {
     Sku                    = sku;
     Plan                   = plan;
     UpgradePolicy          = upgradePolicy;
     AutomaticRepairsPolicy = automaticRepairsPolicy;
     VirtualMachineProfile  = virtualMachineProfile;
     ProvisioningState      = provisioningState;
     Overprovision          = overprovision;
     DoNotRunExtensionsOnOverprovisionedVMs = doNotRunExtensionsOnOverprovisionedVMs;
     UniqueId                 = uniqueId;
     SinglePlacementGroup     = singlePlacementGroup;
     ZoneBalance              = zoneBalance;
     PlatformFaultDomainCount = platformFaultDomainCount;
     ProximityPlacementGroup  = proximityPlacementGroup;
     HostGroup                = hostGroup;
     AdditionalCapabilities   = additionalCapabilities;
     ScaleInPolicy            = scaleInPolicy;
     OrchestrationMode        = orchestrationMode;
     SpotRestorePolicy        = spotRestorePolicy;
     TimeCreated              = timeCreated;
     Identity                 = identity;
     Zones            = zones;
     ExtendedLocation = extendedLocation;
     CustomInit();
 }
Esempio n. 4
0
 public VirtualMachine(string location, string id, string name, string type, IDictionary <string, string> tags, Plan plan, HardwareProfile hardwareProfile, StorageProfile storageProfile, AdditionalCapabilities additionalCapabilities, OSProfile osProfile, NetworkProfile networkProfile, SecurityProfile securityProfile, DiagnosticsProfile diagnosticsProfile, SubResource availabilitySet, SubResource virtualMachineScaleSet, SubResource proximityPlacementGroup, string priority, string evictionPolicy, BillingProfile billingProfile, SubResource host, SubResource hostGroup, string provisioningState, VirtualMachineInstanceView instanceView, string licenseType, string vmId, string extensionsTimeBudget, int?platformFaultDomain, ScheduledEventsProfile scheduledEventsProfile, string userData, CapacityReservationProfile capacityReservation, IList <VirtualMachineExtension> resources, VirtualMachineIdentity identity, IList <string> zones, ExtendedLocation extendedLocation)
     : base(location, id, name, type, tags)
 {
     Plan                    = plan;
     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;
     Resources               = resources;
     Identity                = identity;
     Zones                   = zones;
     ExtendedLocation        = extendedLocation;
     CustomInit();
 }