text:
namespace Microsoft.Azure.Management.Compute
{
    using Microsoft.Rest;
    using Microsoft.Rest.Azure;
    using Microsoft.Rest.Azure.OData;
    using Models;
    using System.Threading;
    using System.Threading.Tasks;

    /// <summary>
    /// Extension methods for VirtualMachineScaleSetVMsOperations.
    /// </summary>
    public static partial class VirtualMachineScaleSetVMsOperationsExtensions
    {
            /// <summary>
            /// Reimages (upgrade the operating system) a specific virtual machine in a VM
            /// scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='tempDisk'>
            /// Specifies whether to reimage temp disk. Default value: false. Note: This
            /// temp disk reimage parameter is only supported for VM/VMSS with Ephemeral OS
            /// disk.
            /// </param>
            public static void Reimage(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, bool? tempDisk = default(bool?))
            {
                operations.ReimageAsync(resourceGroupName, vmScaleSetName, instanceId, tempDisk).GetAwaiter().GetResult();
            }

            /// <summary>
            /// Reimages (upgrade the operating system) a specific virtual machine in a VM
            /// scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='tempDisk'>
            /// Specifies whether to reimage temp disk. Default value: false. Note: This
            /// temp disk reimage parameter is only supported for VM/VMSS with Ephemeral OS
            /// disk.
            /// </param>
            /// <param name='cancellationToken'>
            /// The cancellation token.
            /// </param>
            public static async Task ReimageAsync(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, bool? tempDisk = default(bool?), CancellationToken cancellationToken = default(CancellationToken))
            {
                (await operations.ReimageWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceId, tempDisk, null, cancellationToken).ConfigureAwait(false)).Dispose();
            }

            /// <summary>
            /// Allows you to re-image all the disks ( including data disks ) in the a VM
            /// scale set instance. This operation is only supported for managed disks.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            public static void ReimageAll(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId)
            {
                operations.ReimageAllAsync(resourceGroupName, vmScaleSetName, instanceId).GetAwaiter().GetResult();
            }

            /// <summary>
            /// Allows you to re-image all the disks ( including data disks ) in the a VM
            /// scale set instance. This operation is only supported for managed disks.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='cancellationToken'>
            /// The cancellation token.
            /// </param>
            public static async Task ReimageAllAsync(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, CancellationToken cancellationToken = default(CancellationToken))
            {
                (await operations.ReimageAllWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceId, null, cancellationToken).ConfigureAwait(false)).Dispose();
            }

            /// <summary>
            /// Deallocates a specific virtual machine in a VM scale set. Shuts down the
            /// virtual machine and releases the compute resources it uses. You are not
            /// billed for the compute resources of this virtual machine once it is
            /// deallocated.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            public static void Deallocate(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId)
            {
                operations.DeallocateAsync(resourceGroupName, vmScaleSetName, instanceId).GetAwaiter().GetResult();
            }

            /// <summary>
            /// Deallocates a specific virtual machine in a VM scale set. Shuts down the
            /// virtual machine and releases the compute resources it uses. You are not
            /// billed for the compute resources of this virtual machine once it is
            /// deallocated.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='cancellationToken'>
            /// The cancellation token.
            /// </param>
            public static async Task DeallocateAsync(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, CancellationToken cancellationToken = default(CancellationToken))
            {
                (await operations.DeallocateWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceId, null, cancellationToken).ConfigureAwait(false)).Dispose();
            }

            /// <summary>
            /// Updates a virtual machine of a VM scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set where the extension should be create or
            /// updated.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='parameters'>
            /// Parameters supplied to the Update Virtual Machine Scale Sets VM operation.
            /// </param>
            public static VirtualMachineScaleSetVM Update(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, VirtualMachineScaleSetVM parameters)
            {
                return operations.UpdateAsync(resourceGroupName, vmScaleSetName, instanceId, parameters).GetAwaiter().GetResult();
            }

            /// <summary>
            /// Updates a virtual machine of a VM scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set where the extension should be create or
            /// updated.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='parameters'>
            /// Parameters supplied to the Update Virtual Machine Scale Sets VM operation.
            /// </param>
            /// <param name='cancellationToken'>
            /// The cancellation token.
            /// </param>
            public static async Task<VirtualMachineScaleSetVM> UpdateAsync(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, VirtualMachineScaleSetVM parameters, CancellationToken cancellationToken = default(CancellationToken))
            {
                using (var _result = await operations.UpdateWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceId, parameters, null, cancellationToken).ConfigureAwait(false))
                {
                    return _result.Body;
                }
            }

            /// <summary>
            /// Deletes a virtual machine from a VM scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='forceDeletion'>
            /// Optional parameter to force delete a virtual machine from a VM scale set.
            /// (Feature in Preview)
            /// </param>
            public static void Delete(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, bool? forceDeletion = default(bool?))
            {
                operations.DeleteAsync(resourceGroupName, vmScaleSetName, instanceId, forceDeletion).GetAwaiter().GetResult();
            }

            /// <summary>
            /// Deletes a virtual machine from a VM scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='forceDeletion'>
            /// Optional parameter to force delete a virtual machine from a VM scale set.
            /// (Feature in Preview)
            /// </param>
            /// <param name='cancellationToken'>
            /// The cancellation token.
            /// </param>
            public static async Task DeleteAsync(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, bool? forceDeletion = default(bool?), CancellationToken cancellationToken = default(CancellationToken))
            {
                (await operations.DeleteWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceId, forceDeletion, null, cancellationToken).ConfigureAwait(false)).Dispose();
            }

            /// <summary>
            /// Gets a virtual machine from a VM scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='expand'>
            /// The expand expression to apply on the operation. 'InstanceView' will
            /// retrieve the instance view of the virtual machine. 'UserData' will retrieve
            /// the UserData of the virtual machine. Possible values include:
            /// 'instanceView', 'userData'
            /// </param>
            public static VirtualMachineScaleSetVM Get(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, InstanceViewTypes? expand = default(InstanceViewTypes?))
            {
                return operations.GetAsync(resourceGroupName, vmScaleSetName, instanceId, expand).GetAwaiter().GetResult();
            }

            /// <summary>
            /// Gets a virtual machine from a VM scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='expand'>
            /// The expand expression to apply on the operation. 'InstanceView' will
            /// retrieve the instance view of the virtual machine. 'UserData' will retrieve
            /// the UserData of the virtual machine. Possible values include:
            /// 'instanceView', 'userData'
            /// </param>
            /// <param name='cancellationToken'>
            /// The cancellation token.
            /// </param>
            public static async Task<VirtualMachineScaleSetVM> GetAsync(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, InstanceViewTypes? expand = default(InstanceViewTypes?), CancellationToken cancellationToken = default(CancellationToken))
            {
                using (var _result = await operations.GetWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceId, expand, null, cancellationToken).ConfigureAwait(false))
                {
                    return _result.Body;
                }
            }

            /// <summary>
            /// Gets the status of a virtual machine from a VM scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            public static VirtualMachineScaleSetVMInstanceView GetInstanceView(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId)
            {
                return operations.GetInstanceViewAsync(resourceGroupName, vmScaleSetName, instanceId).GetAwaiter().GetResult();
            }

            /// <summary>
            /// Gets the status of a virtual machine from a VM scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='cancellationToken'>
            /// The cancellation token.
            /// </param>
            public static async Task<VirtualMachineScaleSetVMInstanceView> GetInstanceViewAsync(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, CancellationToken cancellationToken = default(CancellationToken))
            {
                using (var _result = await operations.GetInstanceViewWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceId, null, cancellationToken).ConfigureAwait(false))
                {
                    return _result.Body;
                }
            }

            /// <summary>
            /// Gets a list of all virtual machines in a VM scale sets.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='virtualMachineScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='odataQuery'>
            /// OData parameters to apply to the operation.
            /// </param>
            /// <param name='select'>
            /// The list parameters. Allowed values are 'instanceView',
            /// 'instanceView/statuses'.
            /// </param>
            public static IPage<VirtualMachineScaleSetVM> List(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string virtualMachineScaleSetName, ODataQuery<VirtualMachineScaleSetVM> odataQuery = default(ODataQuery<VirtualMachineScaleSetVM>), string select = default(string))
            {
                return operations.ListAsync(resourceGroupName, virtualMachineScaleSetName, odataQuery, select).GetAwaiter().GetResult();
            }

            /// <summary>
            /// Gets a list of all virtual machines in a VM scale sets.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='virtualMachineScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='odataQuery'>
            /// OData parameters to apply to the operation.
            /// </param>
            /// <param name='select'>
            /// The list parameters. Allowed values are 'instanceView',
            /// 'instanceView/statuses'.
            /// </param>
            /// <param name='cancellationToken'>
            /// The cancellation token.
            /// </param>
            public static async Task<IPage<VirtualMachineScaleSetVM>> ListAsync(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string virtualMachineScaleSetName, ODataQuery<VirtualMachineScaleSetVM> odataQuery = default(ODataQuery<VirtualMachineScaleSetVM>), string select = default(string), CancellationToken cancellationToken = default(CancellationToken))
            {
                using (var _result = await operations.ListWithHttpMessagesAsync(resourceGroupName, virtualMachineScaleSetName, odataQuery, select, null, cancellationToken).ConfigureAwait(false))
                {
                    return _result.Body;
                }
            }

            /// <summary>
            /// Power off (stop) a virtual machine in a VM scale set. Note that resources
            /// are still attached and you are getting charged for the resources. Instead,
            /// use deallocate to release resources and avoid charges.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='skipShutdown'>
            /// The parameter to request non-graceful VM shutdown. True value for this flag
            /// indicates non-graceful shutdown whereas false indicates otherwise. Default
            /// value for this flag is false if not specified
            /// </param>
            public static void PowerOff(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, bool? skipShutdown = false)
            {
                operations.PowerOffAsync(resourceGroupName, vmScaleSetName, instanceId, skipShutdown).GetAwaiter().GetResult();
            }

            /// <summary>
            /// Power off (stop) a virtual machine in a VM scale set. Note that resources
            /// are still attached and you are getting charged for the resources. Instead,
            /// use deallocate to release resources and avoid charges.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='skipShutdown'>
            /// The parameter to request non-graceful VM shutdown. True value for this flag
            /// indicates non-graceful shutdown whereas false indicates otherwise. Default
            /// value for this flag is false if not specified
            /// </param>
            /// <param name='cancellationToken'>
            /// The cancellation token.
            /// </param>
            public static async Task PowerOffAsync(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, bool? skipShutdown = false, CancellationToken cancellationToken = default(CancellationToken))
            {
                (await operations.PowerOffWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceId, skipShutdown, null, cancellationToken).ConfigureAwait(false)).Dispose();
            }

            /// <summary>
            /// Restarts a virtual machine in a VM scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            public static void Restart(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId)
            {
                operations.RestartAsync(resourceGroupName, vmScaleSetName, instanceId).GetAwaiter().GetResult();
            }

            /// <summary>
            /// Restarts a virtual machine in a VM scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='cancellationToken'>
            /// The cancellation token.
            /// </param>
            public static async Task RestartAsync(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, CancellationToken cancellationToken = default(CancellationToken))
            {
                (await operations.RestartWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceId, null, cancellationToken).ConfigureAwait(false)).Dispose();
            }

            /// <summary>
            /// Starts a virtual machine in a VM scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            public static void Start(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId)
            {
                operations.StartAsync(resourceGroupName, vmScaleSetName, instanceId).GetAwaiter().GetResult();
            }

            /// <summary>
            /// Starts a virtual machine in a VM scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='cancellationToken'>
            /// The cancellation token.
            /// </param>
            public static async Task StartAsync(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, CancellationToken cancellationToken = default(CancellationToken))
            {
                (await operations.StartWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceId, null, cancellationToken).ConfigureAwait(false)).Dispose();
            }

            /// <summary>
            /// Shuts down the virtual machine in the virtual machine scale set, moves it
            /// to a new node, and powers it back on.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            public static void Redeploy(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId)
            {
                operations.RedeployAsync(resourceGroupName, vmScaleSetName, instanceId).GetAwaiter().GetResult();
            }

            /// <summary>
            /// Shuts down the virtual machine in the virtual machine scale set, moves it
            /// to a new node, and powers it back on.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='cancellationToken'>
            /// The cancellation token.
            /// </param>
            public static async Task RedeployAsync(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, CancellationToken cancellationToken = default(CancellationToken))
            {
                (await operations.RedeployWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceId, null, cancellationToken).ConfigureAwait(false)).Dispose();
            }

            /// <summary>
            /// The operation to retrieve SAS URIs of boot diagnostic logs for a virtual
            /// machine in a VM scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='sasUriExpirationTimeInMinutes'>
            /// Expiration duration in minutes for the SAS URIs with a value between 1 to
            /// 1440 minutes. <br><br>NOTE: If not specified, SAS URIs will be
            /// generated with a default expiration duration of 120 minutes.
            /// </param>
            public static RetrieveBootDiagnosticsDataResult RetrieveBootDiagnosticsData(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, int? sasUriExpirationTimeInMinutes = default(int?))
            {
                return operations.RetrieveBootDiagnosticsDataAsync(resourceGroupName, vmScaleSetName, instanceId, sasUriExpirationTimeInMinutes).GetAwaiter().GetResult();
            }

            /// <summary>
            /// The operation to retrieve SAS URIs of boot diagnostic logs for a virtual
            /// machine in a VM scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='sasUriExpirationTimeInMinutes'>
            /// Expiration duration in minutes for the SAS URIs with a value between 1 to
            /// 1440 minutes. <br><br>NOTE: If not specified, SAS URIs will be
            /// generated with a default expiration duration of 120 minutes.
            /// </param>
            /// <param name='cancellationToken'>
            /// The cancellation token.
            /// </param>
            public static async Task<RetrieveBootDiagnosticsDataResult> RetrieveBootDiagnosticsDataAsync(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, int? sasUriExpirationTimeInMinutes = default(int?), CancellationToken cancellationToken = default(CancellationToken))
            {
                using (var _result = await operations.RetrieveBootDiagnosticsDataWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceId, sasUriExpirationTimeInMinutes, null, cancellationToken).ConfigureAwait(false))
                {
                    return _result.Body;
                }
            }

            /// <summary>
            /// Performs maintenance on a virtual machine in a VM scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            public static void PerformMaintenance(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId)
            {
                operations.PerformMaintenanceAsync(resourceGroupName, vmScaleSetName, instanceId).GetAwaiter().GetResult();
            }

            /// <summary>
            /// Performs maintenance on a virtual machine in a VM scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='cancellationToken'>
            /// The cancellation token.
            /// </param>
            public static async Task PerformMaintenanceAsync(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, CancellationToken cancellationToken = default(CancellationToken))
            {
                (await operations.PerformMaintenanceWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceId, null, cancellationToken).ConfigureAwait(false)).Dispose();
            }

            /// <summary>
            /// The operation to simulate the eviction of spot virtual machine in a VM
            /// scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            public static void SimulateEviction(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId)
            {
                operations.SimulateEvictionAsync(resourceGroupName, vmScaleSetName, instanceId).GetAwaiter().GetResult();
            }

            /// <summary>
            /// The operation to simulate the eviction of spot virtual machine in a VM
            /// scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='cancellationToken'>
            /// The cancellation token.
            /// </param>
            public static async Task SimulateEvictionAsync(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, CancellationToken cancellationToken = default(CancellationToken))
            {
                (await operations.SimulateEvictionWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceId, null, cancellationToken).ConfigureAwait(false)).Dispose();
            }

            /// <summary>
            /// Run command on a virtual machine in a VM scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='parameters'>
            /// Parameters supplied to the Run command operation.
            /// </param>
            public static RunCommandResult RunCommand(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, RunCommandInput parameters)
            {
                return operations.RunCommandAsync(resourceGroupName, vmScaleSetName, instanceId, parameters).GetAwaiter().GetResult();
            }

            /// <summary>
            /// Run command on a virtual machine in a VM scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='parameters'>
            /// Parameters supplied to the Run command operation.
            /// </param>
            /// <param name='cancellationToken'>
            /// The cancellation token.
            /// </param>
            public static async Task<RunCommandResult> RunCommandAsync(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, RunCommandInput parameters, CancellationToken cancellationToken = default(CancellationToken))
            {
                using (var _result = await operations.RunCommandWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceId, parameters, null, cancellationToken).ConfigureAwait(false))
                {
                    return _result.Body;
                }
            }

            /// <summary>
            /// Reimages (upgrade the operating system) a specific virtual machine in a VM
            /// scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='tempDisk'>
            /// Specifies whether to reimage temp disk. Default value: false. Note: This
            /// temp disk reimage parameter is only supported for VM/VMSS with Ephemeral OS
            /// disk.
            /// </param>
            public static void BeginReimage(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, bool? tempDisk = default(bool?))
            {
                operations.BeginReimageAsync(resourceGroupName, vmScaleSetName, instanceId, tempDisk).GetAwaiter().GetResult();
            }

            /// <summary>
            /// Reimages (upgrade the operating system) a specific virtual machine in a VM
            /// scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='tempDisk'>
            /// Specifies whether to reimage temp disk. Default value: false. Note: This
            /// temp disk reimage parameter is only supported for VM/VMSS with Ephemeral OS
            /// disk.
            /// </param>
            /// <param name='cancellationToken'>
            /// The cancellation token.
            /// </param>
            public static async Task BeginReimageAsync(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, bool? tempDisk = default(bool?), CancellationToken cancellationToken = default(CancellationToken))
            {
                (await operations.BeginReimageWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceId, tempDisk, null, cancellationToken).ConfigureAwait(false)).Dispose();
            }

            /// <summary>
            /// Allows you to re-image all the disks ( including data disks ) in the a VM
            /// scale set instance. This operation is only supported for managed disks.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            public static void BeginReimageAll(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId)
            {
                operations.BeginReimageAllAsync(resourceGroupName, vmScaleSetName, instanceId).GetAwaiter().GetResult();
            }

            /// <summary>
            /// Allows you to re-image all the disks ( including data disks ) in the a VM
            /// scale set instance. This operation is only supported for managed disks.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='cancellationToken'>
            /// The cancellation token.
            /// </param>
            public static async Task BeginReimageAllAsync(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, CancellationToken cancellationToken = default(CancellationToken))
            {
                (await operations.BeginReimageAllWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceId, null, cancellationToken).ConfigureAwait(false)).Dispose();
            }

            /// <summary>
            /// Deallocates a specific virtual machine in a VM scale set. Shuts down the
            /// virtual machine and releases the compute resources it uses. You are not
            /// billed for the compute resources of this virtual machine once it is
            /// deallocated.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            public static void BeginDeallocate(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId)
            {
                operations.BeginDeallocateAsync(resourceGroupName, vmScaleSetName, instanceId).GetAwaiter().GetResult();
            }

            /// <summary>
            /// Deallocates a specific virtual machine in a VM scale set. Shuts down the
            /// virtual machine and releases the compute resources it uses. You are not
            /// billed for the compute resources of this virtual machine once it is
            /// deallocated.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='cancellationToken'>
            /// The cancellation token.
            /// </param>
            public static async Task BeginDeallocateAsync(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, CancellationToken cancellationToken = default(CancellationToken))
            {
                (await operations.BeginDeallocateWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceId, null, cancellationToken).ConfigureAwait(false)).Dispose();
            }

            /// <summary>
            /// Updates a virtual machine of a VM scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set where the extension should be create or
            /// updated.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='parameters'>
            /// Parameters supplied to the Update Virtual Machine Scale Sets VM operation.
            /// </param>
            public static VirtualMachineScaleSetVM BeginUpdate(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, VirtualMachineScaleSetVM parameters)
            {
                return operations.BeginUpdateAsync(resourceGroupName, vmScaleSetName, instanceId, parameters).GetAwaiter().GetResult();
            }

            /// <summary>
            /// Updates a virtual machine of a VM scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set where the extension should be create or
            /// updated.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='parameters'>
            /// Parameters supplied to the Update Virtual Machine Scale Sets VM operation.
            /// </param>
            /// <param name='cancellationToken'>
            /// The cancellation token.
            /// </param>
            public static async Task<VirtualMachineScaleSetVM> BeginUpdateAsync(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, VirtualMachineScaleSetVM parameters, CancellationToken cancellationToken = default(CancellationToken))
            {
                using (var _result = await operations.BeginUpdateWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceId, parameters, null, cancellationToken).ConfigureAwait(false))
                {
                    return _result.Body;
                }
            }

            /// <summary>
            /// Deletes a virtual machine from a VM scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='forceDeletion'>
            /// Optional parameter to force delete a virtual machine from a VM scale set.
            /// (Feature in Preview)
            /// </param>
            public static void BeginDelete(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, bool? forceDeletion = default(bool?))
            {
                operations.BeginDeleteAsync(resourceGroupName, vmScaleSetName, instanceId, forceDeletion).GetAwaiter().GetResult();
            }

            /// <summary>
            /// Deletes a virtual machine from a VM scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='forceDeletion'>
            /// Optional parameter to force delete a virtual machine from a VM scale set.
            /// (Feature in Preview)
            /// </param>
            /// <param name='cancellationToken'>
            /// The cancellation token.
            /// </param>
            public static async Task BeginDeleteAsync(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, bool? forceDeletion = default(bool?), CancellationToken cancellationToken = default(CancellationToken))
            {
                (await operations.BeginDeleteWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceId, forceDeletion, null, cancellationToken).ConfigureAwait(false)).Dispose();
            }

            /// <summary>
            /// Power off (stop) a virtual machine in a VM scale set. Note that resources
            /// are still attached and you are getting charged for the resources. Instead,
            /// use deallocate to release resources and avoid charges.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='skipShutdown'>
            /// The parameter to request non-graceful VM shutdown. True value for this flag
            /// indicates non-graceful shutdown whereas false indicates otherwise. Default
            /// value for this flag is false if not specified
            /// </param>
            public static void BeginPowerOff(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, bool? skipShutdown = false)
            {
                operations.BeginPowerOffAsync(resourceGroupName, vmScaleSetName, instanceId, skipShutdown).GetAwaiter().GetResult();
            }

            /// <summary>
            /// Power off (stop) a virtual machine in a VM scale set. Note that resources
            /// are still attached and you are getting charged for the resources. Instead,
            /// use deallocate to release resources and avoid charges.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='skipShutdown'>
            /// The parameter to request non-graceful VM shutdown. True value for this flag
            /// indicates non-graceful shutdown whereas false indicates otherwise. Default
            /// value for this flag is false if not specified
            /// </param>
            /// <param name='cancellationToken'>
            /// The cancellation token.
            /// </param>
            public static async Task BeginPowerOffAsync(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, bool? skipShutdown = false, CancellationToken cancellationToken = default(CancellationToken))
            {
                (await operations.BeginPowerOffWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceId, skipShutdown, null, cancellationToken).ConfigureAwait(false)).Dispose();
            }

            /// <summary>
            /// Restarts a virtual machine in a VM scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            public static void BeginRestart(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId)
            {
                operations.BeginRestartAsync(resourceGroupName, vmScaleSetName, instanceId).GetAwaiter().GetResult();
            }

            /// <summary>
            /// Restarts a virtual machine in a VM scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='cancellationToken'>
            /// The cancellation token.
            /// </param>
            public static async Task BeginRestartAsync(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, CancellationToken cancellationToken = default(CancellationToken))
            {
                (await operations.BeginRestartWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceId, null, cancellationToken).ConfigureAwait(false)).Dispose();
            }

            /// <summary>
            /// Starts a virtual machine in a VM scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            public static void BeginStart(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId)
            {
                operations.BeginStartAsync(resourceGroupName, vmScaleSetName, instanceId).GetAwaiter().GetResult();
            }

            /// <summary>
            /// Starts a virtual machine in a VM scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='cancellationToken'>
            /// The cancellation token.
            /// </param>
            public static async Task BeginStartAsync(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, CancellationToken cancellationToken = default(CancellationToken))
            {
                (await operations.BeginStartWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceId, null, cancellationToken).ConfigureAwait(false)).Dispose();
            }

            /// <summary>
            /// Shuts down the virtual machine in the virtual machine scale set, moves it
            /// to a new node, and powers it back on.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            public static void BeginRedeploy(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId)
            {
                operations.BeginRedeployAsync(resourceGroupName, vmScaleSetName, instanceId).GetAwaiter().GetResult();
            }

            /// <summary>
            /// Shuts down the virtual machine in the virtual machine scale set, moves it
            /// to a new node, and powers it back on.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='cancellationToken'>
            /// The cancellation token.
            /// </param>
            public static async Task BeginRedeployAsync(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, CancellationToken cancellationToken = default(CancellationToken))
            {
                (await operations.BeginRedeployWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceId, null, cancellationToken).ConfigureAwait(false)).Dispose();
            }

            /// <summary>
            /// Performs maintenance on a virtual machine in a VM scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            public static void BeginPerformMaintenance(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId)
            {
                operations.BeginPerformMaintenanceAsync(resourceGroupName, vmScaleSetName, instanceId).GetAwaiter().GetResult();
            }

            /// <summary>
            /// Performs maintenance on a virtual machine in a VM scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='cancellationToken'>
            /// The cancellation token.
            /// </param>
            public static async Task BeginPerformMaintenanceAsync(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, CancellationToken cancellationToken = default(CancellationToken))
            {
                (await operations.BeginPerformMaintenanceWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceId, null, cancellationToken).ConfigureAwait(false)).Dispose();
            }

            /// <summary>
            /// Run command on a virtual machine in a VM scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='parameters'>
            /// Parameters supplied to the Run command operation.
            /// </param>
            public static RunCommandResult BeginRunCommand(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, RunCommandInput parameters)
            {
                return operations.BeginRunCommandAsync(resourceGroupName, vmScaleSetName, instanceId, parameters).GetAwaiter().GetResult();
            }

            /// <summary>
            /// Run command on a virtual machine in a VM scale set.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='resourceGroupName'>
            /// The name of the resource group.
            /// </param>
            /// <param name='vmScaleSetName'>
            /// The name of the VM scale set.
            /// </param>
            /// <param name='instanceId'>
            /// The instance ID of the virtual machine.
            /// </param>
            /// <param name='parameters'>
            /// Parameters supplied to the Run command operation.
            /// </param>
            /// <param name='cancellationToken'>
            /// The cancellation token.
            /// </param>
            public static async Task<RunCommandResult> BeginRunCommandAsync(this IVirtualMachineScaleSetVMsOperations operations, string resourceGroupName, string vmScaleSetName, string instanceId, RunCommandInput parameters, CancellationToken cancellationToken = default(CancellationToken))
            {
                using (var _result = await operations.BeginRunCommandWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, instanceId, parameters, null, cancellationToken).ConfigureAwait(false))
                {
                    return _result.Body;
                }
            }

            /// <summary>
            /// Gets a list of all virtual machines in a VM scale sets.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='nextPageLink'>
            /// The NextLink from the previous successful call to List operation.
            /// </param>
            public static IPage<VirtualMachineScaleSetVM> ListNext(this IVirtualMachineScaleSetVMsOperations operations, string nextPageLink)
            {
                return operations.ListNextAsync(nextPageLink).GetAwaiter().GetResult();
            }

            /// <summary>
            /// Gets a list of all virtual machines in a VM scale sets.
            /// </summary>
            /// <param name='operations'>
            /// The operations group for this extension method.
            /// </param>
            /// <param name='nextPageLink'>
            /// The NextLink from the previous successful call to List operation.
            /// </param>
            /// <param name='cancellationToken'>
            /// The cancellation token.
            /// </param>
            public static async Task<IPage<VirtualMachineScaleSetVM>> ListNextAsync(this IVirtualMachineScaleSetVMsOperations operations, string nextPageLink, CancellationToken cancellationToken = default(CancellationToken))
            {
                using (var _result = await operations.ListNextWithHttpMessagesAsync(nextPageLink, null, cancellationToken).ConfigureAwait(false))
                {
                    return _result.Body;
                }
            }

    }
}


text:
//
//  interrupts.h
//  Firedrake
//
//  Created by Sidney Just
//  Copyright (c) 2012 by Sidney Just
//  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
//  documentation files (the "Software"), to deal in the Software without restriction, including without limitation
//  the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
//  and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
//  INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
//  PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
//  FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
//  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

#ifndef _INTERRUPTS_H_
#define _INTERRUPTS_H_

#include <types.h>
#include <system/cpu.h>

#define IDT_FLAG_INTERRUPT_GATE 	0xE
#define IDT_FLAG_PRESENT 			0x80
#define IDT_FLAG_RING0 				0x00
#define IDT_FLAG_RING3				0x60

#define IDT_ENTRIES 				256

// exceptions
extern void idt_exception_divbyzero(); // 0
extern void idt_exception_debug(); // 1
extern void idt_exception_breakpoint(); // 3
extern void idt_exception_overflow(); // 4
extern void idt_exception_boundrange(); // 5
extern void idt_exception_opcode(); // 6
extern void idt_exception_devicenotavailable(); // 7
extern void idt_exception_doublefault(); // 8 error
extern void idt_exception_segmentoverrun(); // 9
extern void idt_exception_invalidtss(); // 10 error
extern void idt_exception_segmentnotpresent(); // 11 error
extern void idt_exception_stackfault(); // 12 error
extern void idt_exception_protectionfault(); // 13 error
extern void idt_exception_pagefault(); // 14 error
extern void idt_exception_fpuerror(); // 16
extern void idt_exception_alignment(); // 17 error
extern void idt_exception_machinecheck(); // 18
extern void idt_exception_simd(); // 19

// interrupts
extern void idt_interrupt_0x02(); // NMI
extern void idt_interrupt_0x20();
extern void idt_interrupt_0x21();
extern void idt_interrupt_0x22();
extern void idt_interrupt_0x23();
extern void idt_interrupt_0x24();
extern void idt_interrupt_0x25();
extern void idt_interrupt_0x26();
extern void idt_interrupt_0x27();
extern void idt_interrupt_0x28();
extern void idt_interrupt_0x29();
extern void idt_interrupt_0x2A();
extern void idt_interrupt_0x2B();
extern void idt_interrupt_0x2C();
extern void idt_interrupt_0x2D();
extern void idt_interrupt_0x2E();
extern void idt_interrupt_0x2F();

extern void idt_interrupt_0x31(); // Forced reshedule
extern void idt_interrupt_0x80(); // Syscall

// Interrupts that are free to use (ie have no special purpose)
extern void idt_interrupt_0x81();
extern void idt_interrupt_0x82();
extern void idt_interrupt_0x83();
extern void idt_interrupt_0x84();
extern void idt_interrupt_0x85();
extern void idt_interrupt_0x86();
extern void idt_interrupt_0x87();
extern void idt_interrupt_0x88();
extern void idt_interrupt_0x89();
extern void idt_interrupt_0x8A();
extern void idt_interrupt_0x8B();
extern void idt_interrupt_0x8C();
extern void idt_interrupt_0x8D();
extern void idt_interrupt_0x8E();
extern void idt_interrupt_0x8F();
extern void idt_interrupt_0x90();
extern void idt_interrupt_0x91();
extern void idt_interrupt_0x92();
extern void idt_interrupt_0x93();
extern void idt_interrupt_0x94();
extern void idt_interrupt_0x95();
extern void idt_interrupt_0x96();
extern void idt_interrupt_0x97();
extern void idt_interrupt_0x98();
extern void idt_interrupt_0x99();
extern void idt_interrupt_0x9A();
extern void idt_interrupt_0x9B();
extern void idt_interrupt_0x9C();
extern void idt_interrupt_0x9D();
extern void idt_interrupt_0x9E();
extern void idt_interrupt_0x9F();

typedef uint32_t (*ir_interrupt_handler_t)(uint32_t);
typedef void (*ir_interrupt_callback_t)(cpu_state_t *);

bool ir_isValidInterrupt(uint32_t interrupt, bool publicOnly);
uint32_t ir_interruptPublicBegin();
uint32_t ir_interruptPublicEnd();

void ir_disableInterrupts(bool disableNMI);
void ir_enableInterrupts(bool enableNMI);

void ir_setInterruptHandler(ir_interrupt_handler_t handler, uint32_t interrupt);
void ir_setInterruptCallback(ir_interrupt_callback_t callback, uint32_t interrupt);

bool ir_isInsideInterruptHandler();
uint32_t ir_lastInterruptESP();

void ir_idt_init(uint64_t *idt, uint32_t offset);
bool ir_init(void *unused);

#endif /* _INTERRUPTS_H_ */

redpajama_set_name: RedPajamaGithub


text:
(function( $ ){
//plugin buttonset vertical
$.fn.buttonsetv = function() {
  $(':radio, :checkbox', this).wrap('<div style="margin: 1px"/>');
  $(this).buttonset();
  $('label:first', this).removeClass('ui-corner-left').addClass('ui-corner-top');
  $('label:last', this).removeClass('ui-corner-right').addClass('ui-corner-bottom');
  mw = 0; // max witdh
  $('label', this).each(function(index){
     w = $(this).width();
     if (w > mw) mw = w;
  })
  $('label', this).each(function(index){
    $(this).width(mw);
  })
};
})( jQuery );


text:
package cen.comp313.student_portal;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class AllProductsActivity extends ListActivity {

	 // Progress Dialog
    private ProgressDialog pDialog;

    String studentID;

    // Creating JSON Parser object
    JSONParser jParser = new JSONParser();

    ArrayList<HashMap<String, String>> coursesList;

    // url to get all products list
    private static String url_all_products = "http://teampineapple.host22.com/andriod_connect/get_courses_by_student.php";

    // JSON Node names
    private static final String TAG_SUCCESS = "success";
    private static final String TAG_PRODUCTS = "courses";
    private static final String TAG_CID = "courseID";
    private static final String TAG_NAME = "courseName";

    // products JSONArray
    JSONArray courses = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.all_courses);

        // Hashmap for ListView
        coursesList = new ArrayList<HashMap<String, String>>();

        // Loading products in Background Thread
        new LoadAllProducts().execute();

        // Get listview
        ListView lv = getListView();

        // on seleting single product
        // launching Edit Product Screen
        lv.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
               //  getting values from selected ListItem
                 String cid = ((TextView) view.findViewById(R.id.cid)).getText().toString();

                // Starting new intent
             Intent in = new Intent(getApplicationContext(), EditCourse.class);
             //sending pid to next activity
             in.putExtra(TAG_CID, cid);
             in.putExtra("studentID", studentID);

                // starting new activity and expecting some response back
             startActivityForResult(in, 100);
            }
        });

    }

    // Response from Edit Product Activity
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        // if result code 100
        if (resultCode == 100) {
            // if result code 100 is received
            // means user edited/deleted product
            // reload this screen again
            Intent intent = getIntent();
            finish();
            startActivity(intent);
        }

    }

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
	    getMenuInflater().inflate(R.menu.course_addmenu, menu);
		return true;
	}

    @Override
	   public boolean onOptionsItemSelected(MenuItem item)
	   {
	      switch (item.getItemId())
	    {

	        case R.id.addCourse:
	            Intent i = new Intent(AllProductsActivity.this, AddCourse.class);
	            i.putExtra("studentID", studentID);
	            startActivity(i);
	            return true;
	        case R.id.courselogOut:
	        	if(Login.currentStudent != null)
	        	{
	        		Login.currentStudent = null;
	        		Intent loginIntent= new Intent(this, Login.class);
	        		startActivity(loginIntent);
	        	}
	        		return true;
	        case R.id.caHomeBtn:
//	        	  Intent in = new Intent(AllProductsActivity.this, Student_Home.class);
//		          in.putExtra("studentID", studentID);
//		          startActivity(in);
	        	startActivity(new Intent(AllProductsActivity.this, Tab_Activity.class));
	        default:
	        	return super.onOptionsItemSelected(item);
	     } // end switch
	   }

    /**
     * Background Async Task to Load all product by making HTTP Request
     * */
    class LoadAllProducts extends AsyncTask<String, String, String> {

        /**
         * Before starting background thread Show Progress Dialog
         * */
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(AllProductsActivity.this);
            pDialog.setMessage("Fetching Courses. Please wait...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(false);
            pDialog.show();
        }

        /**
         * getting All products from url
         * */
        protected String doInBackground(String... args) {
            // Building Parameters
            List<NameValuePair> params = new ArrayList<NameValuePair>();

          Bundle extras = getIntent().getExtras();

          studentID = extras.getString("studentID");

           params.add(new BasicNameValuePair("studentID", studentID));
           // params.add(new BasicNameValuePair("studentID", "1"));
            // getting JSON string from URL
            JSONObject json = jParser.makeHttpRequest(url_all_products, "GET", params);

            // Check your log cat for JSON reponse
            Log.d("All Products: ", json.toString());

            try {
                // Checking for SUCCESS TAG
                int success = json.getInt(TAG_SUCCESS);

                if (success == 1) {
                    // products found
                    // Getting Array of Products

                    courses = json.getJSONArray(TAG_PRODUCTS);

                    // looping through All Products
                    for (int i = 0; i < courses.length(); i++) {
                        JSONObject c = courses.getJSONObject(i);

                        // Storing each json item in variable
                        String id = c.getString(TAG_CID);
                        String name = c.getString(TAG_NAME);

                        // creating new HashMap
                        HashMap<String, String> map = new HashMap<String, String>();

                        // adding each child node to HashMap key => value
                        map.put(TAG_CID, id);
                        map.put(TAG_NAME, name);

                        // adding HashList to ArrayList
                        coursesList.add(map);
                    }
                } else {
                    // no products found
                    // Launch Add New product Activity
                  Intent i = new Intent(getApplicationContext(), AddCourse.class);
                  i.putExtra("studentID", studentID);
                  startActivity(i);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;
        }

        /**
         * After completing background task Dismiss the progress dialog
         * **/
        protected void onPostExecute(String file_url) {
            // dismiss the dialog after getting all products
            pDialog.dismiss();
            // updating UI from Background Thread
            runOnUiThread(new Runnable() {
                public void run() {
                    /**
                     * Updating parsed JSON data into ListView
                     * */
                    ListAdapter adapter = new SimpleAdapter(
                            AllProductsActivity.this, coursesList,
                            R.layout.list_item, new String[] { TAG_CID,
                                    TAG_NAME},
                            new int[] { R.id.cid, R.id.name });
                    // updating listview
                    setListAdapter(adapter);
                }
            });

        }

    }

}


text:
import { Microscope20 } from "../../";

export = Microscope20;


text:
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace AppStudio.Data
{
    public class IEEEFacebookDataSource : DataSourceBase<FacebookSchema>
    {
        private const long OAuthKey = 12790;
        private const string UserId = "176104589110851";

        protected override string CacheKey
        {
            get { return "IEEEFacebookDataSource"; }
        }

        public override bool HasStaticData
        {
            get { return false; }
        }

        public async override Task<IEnumerable<FacebookSchema>> LoadDataAsync()
        {
            try
            {
                var facebookDataProvider = new FacebookDataProvider(UserId, OAuthTokensRepository.GetTokens(OAuthKey));
                return await facebookDataProvider.LoadAsync();
            }
            catch (Exception ex)
            {
                AppLogs.WriteError("IEEEFacebookDataSourceDataSource.LoadData", ex.ToString());
                return new FacebookSchema[0];
            }
        }
    }
}


text:
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Threading.Tasks;
using System.Net;
using System.Web;
using System.Web.Mvc;
using ModelUNRegister.Models;

namespace ModelUNRegister.Controllers
{
    [Authorize(Roles = "Administrators")]
    public class HomePageLinksController : Controller
    {
        private ApplicationDbContext db = new ApplicationDbContext();

        // GET: HomePageLinks
        public async Task<ActionResult> Index()
        {
            return View((await db.HomePageLinks.ToListAsync()).OrderBy(l => l.Index));
        }

        // GET: HomePageLinks/Details/5
        public async Task<ActionResult> Details(Guid? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            HomePageLink homePageLink = await db.HomePageLinks.FindAsync(id);
            if (homePageLink == null)
            {
                return HttpNotFound();
            }
            return View(homePageLink);
        }

        // GET: HomePageLinks/Create
        public ActionResult Create()
        {
            return View();
        }

        // POST: HomePageLinks/Create
        // 为了防止"过多发布"攻击,请启用要绑定到的特定属性,有关
        // 详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkId=317598。
        [HttpPost]
        [ValidateAntiForgeryToken]
        public async Task<ActionResult> Create([Bind(Include = "Id,Index,Name,Description,Icon,Link")] HomePageLink homePageLink)
        {
            if (ModelState.IsValid)
            {
                homePageLink.Id = Guid.NewGuid();
                db.HomePageLinks.Add(homePageLink);
                await db.SaveChangesAsync();
                return RedirectToAction("Index");
            }

            return View(homePageLink);
        }

        // GET: HomePageLinks/Edit/5
        public async Task<ActionResult> Edit(Guid? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            HomePageLink homePageLink = await db.HomePageLinks.FindAsync(id);
            if (homePageLink == null)
            {
                return HttpNotFound();
            }
            return View(homePageLink);
        }

        // POST: HomePageLinks/Edit/5
        // 为了防止"过多发布"攻击,请启用要绑定到的特定属性,有关
        // 详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkId=317598。
        [HttpPost]
        [ValidateAntiForgeryToken]
        public async Task<ActionResult> Edit([Bind(Include = "Id,Index,Name,Description,Icon,Link")] HomePageLink homePageLink)
        {
            if (ModelState.IsValid)
            {
                db.Entry(homePageLink).State = EntityState.Modified;
                await db.SaveChangesAsync();
                return RedirectToAction("Index");
            }
            return View(homePageLink);
        }

        // GET: HomePageLinks/Delete/5
        public async Task<ActionResult> Delete(Guid? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            HomePageLink homePageLink = await db.HomePageLinks.FindAsync(id);
            if (homePageLink == null)
            {
                return HttpNotFound();
            }
            return View(homePageLink);
        }

        // POST: HomePageLinks/Delete/5
        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public async Task<ActionResult> DeleteConfirmed(Guid id)
        {
            HomePageLink homePageLink = await db.HomePageLinks.FindAsync(id);
            db.HomePageLinks.Remove(homePageLink);
            await db.SaveChangesAsync();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                db.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}


text:
{% extends path+"/scenario_prompts_00a/_layout-case-simple-full-width.html" %}

{% block citizen_content %}

{{ data.nuggets | log }}

Back

{#
Condition history
 #}

Condition history

{% if data['conditionHistoryScenarioOne'] and data['endFTFtrigger'] %}
<form action="miniReview" method="post">
{% else %}
<form action="wca-index" method="post">
{% endif %}

	Condition history details
	<textarea class="form-control form-control-1-1" name="conditionHistoryScenarioOne" id="conditionHistoryScenarioOne" rows="14">{{ conditionHistoryScenarioOne }}</textarea>

<input type="submit" class="button" value="Save" id="submitButton">

      </form>

{% endblock %}


text:
package org.ovirt.engine.core.bll.scheduling.pending;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import org.ovirt.engine.core.common.businessentities.VDS;
import org.ovirt.engine.core.common.businessentities.VM;
import org.ovirt.engine.core.common.businessentities.VmStatic;
import org.ovirt.engine.core.compat.Guid;
import org.ovirt.engine.core.vdsbroker.ResourceManager;
import org.ovirt.engine.core.vdsbroker.VdsManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Tracking service for all pending resources. All writes are synchronized and ensure that the internal
 * structures are consistent. Reads are best effort operations and require external locking if absolute consistency
 * is needed.
 */
public class PendingResourceManager {
    private static final Logger log = LoggerFactory.getLogger(PendingResourceManager.class);

    // All internal structures have to be thread-safe for concurrent access
    final Map<Guid, Set<PendingResource>> resourcesByHost = new ConcurrentHashMap<>();
    final Map<Guid, Set<PendingResource>> resourcesByVm = new ConcurrentHashMap<>();
    final Map<PendingResource, PendingResource> pendingResources = new ConcurrentHashMap<>();

    final ResourceManager resourceManager;

    public PendingResourceManager() {
        resourceManager = null;
    }

    public PendingResourceManager(ResourceManager resourceManager) {
        this.resourceManager = resourceManager;
    }

    /**
     * Remove all pending resources associated with the VM.
     * @param vm VmStatic with valid getId()
     */
    public void clearVm(VmStatic vm) {
        Set<Guid> modifiedHosts;

        synchronized (this) {
            if (!resourcesByVm.containsKey(vm.getId())) {
                return;
            }

            log.debug("Clearing pending resources for VM {}", vm.getId());
            modifiedHosts = new HashSet<>();

            /* Remove all resources associated with the VM from the global set
             * and from the byHost index
             */
            for (PendingResource resource : resourcesByVm.get(vm.getId())) {
                if (resourcesByHost.containsKey(resource.getHost())) {
                    modifiedHosts.add(resource.getHost());
                    resourcesByHost.get(resource.getHost()).remove(resource);
                }
                pendingResources.remove(resource);
            }

            resourcesByVm.get(vm.getId()).clear();
        }

        for (Guid hostId: modifiedHosts) {
            notifyHostManagers(hostId);
        }
    }

    public void clearVm(VM vm) {
        clearVm(vm.getStaticData());
    }

    /**
     * Remove all pending resources associated with the host.
     *
     * This is supposed to be used during maintenance flows to clear possible stale data.
     *
     * @param host VDS with valid getId()
     */
    public void clearHost(VDS host) {
        synchronized (this) {
            if (!resourcesByHost.containsKey(host.getId())) {
                return;
            }

            log.debug("Clearing pending resources for host {}", host.getId());

            /* Remove all resources associated with the host from the global set
             *  and from the byVm index
             */
            for (PendingResource resource : resourcesByHost.get(host.getId())) {
                if (resourcesByVm.containsKey(resource.getVm())) {
                    resourcesByVm.get(resource.getVm()).remove(resource);
                }
                pendingResources.remove(resource);
            }

            resourcesByHost.get(host.getId()).clear();
        }

        notifyHostManagers(host.getId());
    }

    /**
     * Add a resource record to the pending lists.
     *
     * IMPORTANT: Call notifyHostManagers once all resources are
     *            registered.
     *
     * @param resource Pending resource instance with valid host and vm
     *                 fields.
     */
    public void addPending(PendingResource resource) {
        synchronized (this) {
            /* Clear VM and Host indexes when the resource is added again.
             *  This should not happen in theory, but lets anticipate future bugs :)
             */
            if (pendingResources.containsKey(resource)) {
                PendingResource old = pendingResources.get(resource);
                log.warn("Clearing stale pending resource {} (host: {}, vm: {})",
                        old, old.getHost(), old.getVm());
                resourcesByVm.get(old.getVm()).remove(old);
                resourcesByHost.get(old.getHost()).remove(old);
            }

            log.debug("Adding pending resource {} (host: {}, vm: {})",
                    resource, resource.getHost(), resource.getVm());

            /* Make sure the index lists exist */
            if (!resourcesByVm.containsKey(resource.getVm())) {
                resourcesByVm.put(resource.getVm(), new HashSet<>());
            }

            if (!resourcesByHost.containsKey(resource.getHost())) {
                resourcesByHost.put(resource.getHost(), new HashSet<>());
            }

            /* Update indexes */
            resourcesByVm.get(resource.getVm()).add(resource);
            resourcesByHost.get(resource.getHost()).add(resource);
            pendingResources.put(resource, resource);
        }
    }

    /**
     * Return all currently pending resources of type "type" associated with host "vds".
     * @param host ID of a host
     * @param type Class object identifying the type of pending resources we are interested in
     * @return Iterable object with the requested resources
     */
    public <T extends PendingResource> Iterable<T> pendingHostResources(Guid host, Class<T> type) {
        if (!resourcesByHost.containsKey(host)) {
            return Collections.emptyList();
        }

        List<T> list = new ArrayList<>();
        for (PendingResource resource: resourcesByHost.get(host)) {
            if (resource.getClass().equals(type)) {
                list.add((T)resource);
            }
        }

        return list;
    }

    /**
     * Return all currently pending resources of type "type" associated with VM "vm".
     * @param vm ID of a VM
     * @param type Class object identifying the type of pending resources we are interested in
     * @return Iterable object with the requested resources
     */
    public <T extends PendingResource> Iterable<T> pendingVmResources(Guid vm, Class<T> type) {
        if (!resourcesByVm.containsKey(vm)) {
            return Collections.emptyList();
        }

        List<T> list = new ArrayList<>();
        for (PendingResource resource: resourcesByVm.get(vm)) {
            if (resource.getClass().equals(type)) {
                list.add((T)resource);
            }
        }

        return list;
    }

    /**
     * Find pending resource that matches the provided template and return it.
     * @param template resource template filled with identification-specific fields
     * @return The actual pending resource
     */
    public <T extends PendingResource> T getExactPendingResource(T template) {
        return (T)pendingResources.get(template);
    }

    /**
     * Return all currently pending resources of type "type".
     * @param type Class object identifying the type of pending resources we are interested in
     * @return Iterable object with the requested resources
     */
    public <T extends PendingResource> Iterable<T> pendingResources(Class<T> type) {
        List<T> list = new ArrayList<>();
        for (PendingResource resource: pendingResources.values()) {
            if (resource.getClass().equals(type)) {
                list.add((T)resource);
            }
        }

        return list;
    }

    /**
     * Notify host manager that the pending memory and CPU data have changed.
     * This is automatically called when a VM or Host are cleared, however the user is responsible
     * for calling it after finished with adding all new pending resources for a VM.
     * @param hostId - it of the affected host
     */
    public void notifyHostManagers(Guid hostId) {
        if (resourceManager == null) {
            return;
        }

        VdsManager vdsManager = resourceManager.getVdsManager(hostId);

        int pendingCpus = PendingCpuCores.collectForHost(this, hostId);
        int pendingMemory = PendingMemory.collectForHost(this, hostId);

        vdsManager.updatePendingData(pendingMemory, pendingCpus);
    }
}


text:
package com.palantir.lock.v2;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.palantir.common.annotations.ImmutablesStyles.PackageVisibleImmutablesStyle;
import com.palantir.lock.watch.LockWatchStateUpdate;
import org.immutables.value.Value;

@Value.Immutable
@PackageVisibleImmutablesStyle
@JsonSerialize(as = ImmutableStartTransactionWithWatchesResponse.class)
@JsonDeserialize(as = ImmutableStartTransactionWithWatchesResponse.class)
public interface StartTransactionWithWatchesResponse {
    @Value.Parameter
    StartIdentifiedAtlasDbTransactionResponse response();

    @Value.Parameter
    LockWatchStateUpdate watchState();

    static StartTransactionWithWatchesResponse of(
            StartIdentifiedAtlasDbTransactionResponse res, LockWatchStateUpdate watchStateUpdate) {
        return ImmutableStartTransactionWithWatchesResponse.of(res, watchStateUpdate);
    }
}