/// <summary>
        /// Retrieves the operating system disk encryption status from the given instance view.
        /// </summary>
        /// <param name="instanceView">Encryption extension instance view.</param>
        /// <return>Os disk status.</return>
        internal static EncryptionStatus OSDiskStatus(VirtualMachineExtensionInstanceView instanceView)
        {
            string subStatusJson = InstanceViewFirstSubStatus(instanceView);

            if (subStatusJson == null)
            {
                return(EncryptionStatus.Unknown);
            }
            JObject jObject = JObject.Parse(subStatusJson);

            if (jObject["os"] == null)
            {
                return(EncryptionStatus.Unknown);
            }
            return(EncryptionStatus.Parse((string)jObject["os"]));
        }
        ///GENMHASH:CFF730CD005B7D5386D59ADCF7C33D0C:80F0D0455B27E848B9196C7D1768B4DB
        public EncryptionStatus DataDiskStatus()
        {
            if (!HasEncryptionExtension())
            {
                return(EncryptionStatus.NotEncrypted);
            }
            string subStatusJson = InstanceViewFirstSubStatus();

            if (subStatusJson == null)
            {
                return(EncryptionStatus.Unknown);
            }
            if (subStatusJson == null)
            {
                return(EncryptionStatus.Unknown);
            }
            JObject jObject = JObject.Parse(subStatusJson);

            if (jObject["data"] == null)
            {
                return(EncryptionStatus.Unknown);
            }
            return(EncryptionStatus.Parse((string)jObject["data"]));
        }
 public EncryptionStatus OSDiskStatus()
 {
     if (virtualMachine.InstanceView == null || virtualMachine.InstanceView.Disks == null)
     {
         return(EncryptionStatus.Unknown);
     }
     foreach (DiskInstanceView diskInstanceView in virtualMachine.InstanceView.Disks)
     {
         // encryptionSettings will be set only for OSDisk
         if (diskInstanceView.EncryptionSettings != null)
         {
             foreach (InstanceViewStatus status in diskInstanceView.Statuses)
             {
                 EncryptionStatus encryptionStatus = EncryptionExtensionIdentifier.GetEncryptionStatusFromCode(status.Code);
                 if (encryptionStatus != null)
                 {
                     return(encryptionStatus);
                 }
             }
             break;
         }
     }
     return(EncryptionStatus.Unknown);
 }
        public EncryptionStatus DataDiskStatus()
        {
            if (virtualMachine.InstanceView == null || virtualMachine.InstanceView.Disks == null)
            {
                return(EncryptionStatus.Unknown);
            }
            var encryptStatuses = new HashSet <EncryptionStatus>();

            foreach (DiskInstanceView diskInstanceView in virtualMachine.InstanceView.Disks)
            {
                // encryptionSettings will be null for data disks and non-null for os disk.
                if (diskInstanceView.EncryptionSettings != null)
                {
                    continue;
                }
                foreach (InstanceViewStatus status in diskInstanceView.Statuses)
                {
                    EncryptionStatus encryptionStatus = EncryptionExtensionIdentifier.GetEncryptionStatusFromCode(status.Code);
                    if (encryptionStatus != null)
                    {
                        encryptStatuses.Add(encryptionStatus);
                        break;
                    }
                }
            }
            // Derive an overall encryption status for all data disks.
            // --------------

            if (encryptStatuses.Count == 0)
            {
                // Zero disks or disks without encryption state status.
                return(EncryptionStatus.Unknown);
            }
            else if (encryptStatuses.Count == 1)
            {
                // Single item indicate all disks are of the same encryption state.
                //
                return(encryptStatuses.First());
            }
            //
            // More than one encryptStatuses indicates multiple disks with different encryption states.
            // The precedence is UNKNOWN > NOT_MOUNTED > ENCRYPTION_INPROGRESS > VM_RESTART_PENDING
            if (encryptStatuses.Contains(EncryptionStatus.Unknown))
            {
                return(EncryptionStatus.Unknown);
            }
            else if (encryptStatuses.Contains(EncryptionStatus.NotMounted))
            {
                return(EncryptionStatus.NotMounted);
            }
            else if (encryptStatuses.Contains(EncryptionStatus.EncryptionInProgress))
            {
                return(EncryptionStatus.EncryptionInProgress);
            }
            else if (encryptStatuses.Contains(EncryptionStatus.VMRestartPending))
            {
                return(EncryptionStatus.VMRestartPending);
            }
            else
            {
                return(EncryptionStatus.Unknown);
            }
        }