コード例 #1
0
        /// <summary>
        /// Updates the status of the specified <see cref="VSphereVirtualMachine" />.
        /// </summary>
        /// <param name="virtualMachine">The <see cref="VSphereVirtualMachine" /> to update.</param>
        /// <exception cref="ArgumentNullException"><paramref name="virtualMachine" /> is null.</exception>
        /// <exception cref="VirtualMachineOperationException">The vSphere service threw an error while processing the command.</exception>
        public void UpdateStatus(VSphereVirtualMachine virtualMachine)
        {
            if (virtualMachine == null)
            {
                throw new ArgumentNullException(nameof(virtualMachine));
            }

            VSphereManagedObject result = CallVSphere(n => n.RetrieveObject(virtualMachine.ManagedObject, VSphereVirtualMachine.StandardProperties));

            virtualMachine.UpdateStatus(result);
        }
コード例 #2
0
        /// <summary>
        /// Runs a guest process in the specified virtual machine.
        /// </summary>
        /// <param name="virtualMachine">The <see cref="VSphereVirtualMachine" /> to run the guest process.</param>
        /// <param name="fileName">The file name of the application to run.</param>
        /// <param name="arguments">The command-line arguments to pass to the application when the process starts.</param>
        /// <param name="credential">The <see cref="NetworkCredential" /> to run the process as.</param>
        /// <param name="waitForExit">if set to <c>true</c> wait for the process to exit before returning.</param>
        /// <returns>The ID of the guest process that was started.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="virtualMachine" /> is null.
        /// <para>or</para>
        /// <paramref name="credential" /> is null.
        /// </exception>
        /// <exception cref="VirtualMachineOperationException">The vSphere service threw an error while processing the command.</exception>
        public long RunGuestProcess(VSphereVirtualMachine virtualMachine, string fileName, string arguments, NetworkCredential credential, bool waitForExit)
        {
            if (virtualMachine == null)
            {
                throw new ArgumentNullException(nameof(virtualMachine));
            }

            LogInfo($"Executing guest process {fileName} on virtual machine {virtualMachine.HostName}.");

            return(CallVSphere(n => n.RunVirtualMachineGuestProcess(virtualMachine.ManagedObject, fileName, arguments, credential, waitForExit)));
        }
コード例 #3
0
        /// <summary>
        /// Reboots the specified virtual machine.
        /// </summary>
        /// <param name="virtualMachine">The <see cref="VSphereVirtualMachine" /> to reboot.</param>
        /// <exception cref="ArgumentNullException"><paramref name="virtualMachine" /> is null.</exception>
        /// <exception cref="VirtualMachineOperationException">The vSphere service threw an error while processing the command.</exception>
        public void Reboot(VSphereVirtualMachine virtualMachine)
        {
            if (virtualMachine == null)
            {
                throw new ArgumentNullException(nameof(virtualMachine));
            }

            LogInfo($"Rebooting virtual machine {virtualMachine.HostName}.");

            CallVSphere(n => n.RebootVirtualMachine(virtualMachine.ManagedObject));
            UpdateStatus(virtualMachine);
        }
コード例 #4
0
        /// <summary>
        /// Reverts the specified virtual machine to the most recent snapshot.
        /// </summary>
        /// <param name="virtualMachine">The <see cref="VSphereVirtualMachine" /> to revert.</param>
        /// <exception cref="ArgumentNullException"><paramref name="virtualMachine" /> is null.</exception>
        /// <exception cref="VirtualMachineOperationException">The vSphere service threw an error while processing the command.</exception>
        public void RevertToSnapshot(VSphereVirtualMachine virtualMachine)
        {
            if (virtualMachine == null)
            {
                throw new ArgumentNullException(nameof(virtualMachine));
            }

            LogInfo($"Reverting virtual machine {virtualMachine.HostName} to latest snapshot.");

            VSphereManagedObject task = CallVSphere(n => n.RevertVirtualMachineToSnapshot(virtualMachine.ManagedObject));

            WaitForTaskSuccess(task);
            UpdateStatus(virtualMachine);
        }
コード例 #5
0
        /// <summary>
        /// Powers off the specified virtual machine.
        /// </summary>
        /// <param name="virtualMachine">The <see cref="VSphereVirtualMachine" /> to power off.</param>
        /// <exception cref="ArgumentNullException"><paramref name="virtualMachine" /> is null.</exception>
        /// <exception cref="VirtualMachineOperationException">The vSphere service threw an error while processing the command.</exception>
        public void PowerOff(VSphereVirtualMachine virtualMachine)
        {
            if (virtualMachine == null)
            {
                throw new ArgumentNullException(nameof(virtualMachine));
            }

            LogInfo($"Powering off virtual machine {virtualMachine.HostName}.");

            VSphereManagedObject task = CallVSphere(n => n.PowerOffVirtualMachine(virtualMachine.ManagedObject));

            WaitForTaskSuccess(task);
            UpdateStatus(virtualMachine);
        }