Beispiel #1
0
 public bool Invoke(OculiServiceVolumePersistedState volumeInfo)
 {
     lock (Win32Utils.HelperOSLock)
     {
         this._PrepareToConnectDrive(volumeInfo);
         List <string> volumeIds = CVolume.GetAllVolumeIDs();
         this._ConnectDrive(volumeInfo);
         this._OnlineNewDisk(volumeInfo);
         List <string> local_3 = new List <string>();
         for (int local_4 = 0; local_4 < this._VolumeIdRetryCount; ++local_4)
         {
             local_3 = CVolume.GetAllVolumeIDs().Where <string>((Func <string, bool>)(v => !volumeIds.Contains(v))).ToList <string>();
             this._Logger.FormatVerbose("Volumes after attaching attempt {1}: {0}", (object)string.Join(", ", local_3.ToArray()), (object)local_4);
             if (local_3.Count <= 0)
             {
                 Thread.Sleep(this._VolumeIdRetryDelay);
             }
             else
             {
                 break;
             }
         }
         if (local_3.Count > 1)
         {
             throw new OculiServiceServiceException(0, "Too many volumes added with disk " + volumeInfo.VirtualDiskFilename);
         }
         if (local_3.Count == 0)
         {
             throw new OculiServiceServiceException(0, "No volumes added with disk " + volumeInfo.VirtualDiskFilename);
         }
         volumeInfo.VolumeName = local_3[0];
     }
     return(true);
 }
 protected void _AssertVolumeNotAttached(OculiServiceVolumePersistedState volume)
 {
     if (!((IEnumerable <VmdkProperties>) this._GetHelperVmVMDKInfo()).Any <VmdkProperties>((Func <VmdkProperties, bool>)(vmdkInfo => vmdkInfo.FileName == volume.VirtualDiskFilename)))
     {
         return;
     }
     this._Logger.FormatError("The volume associated with the filename {0} is already attached.  Something is wrong.", (object)volume.VirtualDiskFilename);
     this._RemoveDrive(volume);
 }
        private void _CheckDiskProvisioningType(OculiServiceVolumePersistedState volume)
        {
            string provisioningType = volume.DiskProvisioningType;

            if (provisioningType != "Dynamic" && provisioningType != "Fixed" && provisioningType != "Flat Disk")
            {
                throw new OculiServiceServiceException(0, "Unknown DiskProvisioningType \"" + provisioningType + "\"");
            }
        }
        protected void _SetSCSISlot(OculiServiceVolumePersistedState volume)
        {
            if (this._AvailableSCSISlots.Count < 1)
            {
                throw new OculiServiceServiceException(0, "No slots available for drive");
            }
            ScsiSlot availableScsiSlot = this._AvailableSCSISlots[0];

            this._AvailableSCSISlots.RemoveAt(0);
            volume.ApplianceSCSIBus        = availableScsiSlot.bus;
            volume.ApplianceSCSIUnitNumber = availableScsiSlot.unit;
        }
        private void _ReportOnDisk(VmDiskInfo disk, OculiServiceVolumePersistedState volume)
        {
            this._Logger.Information("Volume " + volume.VolumeName + ":");
            this._Logger.Information("Format:         " + volume.DriveFormat);
            this._Logger.Information("Label:          " + volume.Label);
            this._Logger.Information("Disk size:      " + (object)this.asMB(volume.Size) + " MB");
            string message = string.Format("Target disk size:      {0}MB", (object)this.asMB(new long?(volume.DesiredSize)));
            long   datastoreMaxVmdkSizeMb = this._ESXHost.GetDatastoreMaxVmdkSizeMB(disk.Location);

            if (this.asMB(new long?(volume.DesiredSize)) > datastoreMaxVmdkSizeMb)
            {
                message += string.Format(" which is greater than the maximum size supported, using {0} MB.", (object)datastoreMaxVmdkSizeMb);
            }
            this._Logger.Information(message);
            this._Logger.Information("Vm SCSIBus:        " + (object)volume.VmSCSIBus);
            this._Logger.Information("Vm SCSIUnitNumber: " + (object)volume.VmSCSIUnitNumber);
            this._Logger.Information("DiskFileName:   " + disk.File);
        }
Beispiel #6
0
 private void _PrepareToConnectDrive(OculiServiceVolumePersistedState volumeInfo)
 {
     this._Logger.Verbose("Preparing to connect drive.");
     this._AvailableSCSISlots = this._GetAvailableSCSISlots();
     this._SetSCSISlot(volumeInfo);
     if (string.IsNullOrEmpty(volumeInfo.VirtualDiskFilename))
     {
         volumeInfo.VirtualDiskFilename = ((IEnumerable <VmdkProperties>) this._GetVmVMDKInfo()).Where <VmdkProperties>((Func <VmdkProperties, bool>)(vmdkInfo =>
         {
             if (vmdkInfo.BusNumber == volumeInfo.VmSCSIBus)
             {
                 return(vmdkInfo.UnitNumber == volumeInfo.VmSCSIUnitNumber);
             }
             return(false);
         })).First <VmdkProperties>().FileName;
     }
     this._AssertVolumeNotAttached(volumeInfo);
     this._Logger.FormatVerbose("The disk associated with filename \"{0}\" will be attached to bus {1} and unit {2}", (object)volumeInfo.VirtualDiskFilename, (object)volumeInfo.ApplianceSCSIBus, (object)volumeInfo.ApplianceSCSIUnitNumber);
 }
Beispiel #7
0
        private void _ReportOnDisk(VmDiskInfo disk, OculiServiceVolumePersistedState volume)
        {
            this._Context.Logger.Information("Volume " + volume.Name + ":");
            this._Context.Logger.Information("Format:         " + volume.DriveFormat);
            this._Context.Logger.Information("Label:          " + volume.Label);
            ILogger logger = this._Context.Logger;
            string  str1   = "Disk size:      ";
            long?   size   = volume.Size;
            long    num    = 1048576;
            // ISSUE: variable of a boxed type
            object local   = (ValueType)(size.HasValue ? new long?(size.GetValueOrDefault() / num) : new long?());
            string str2    = " MB";
            string message = str1 + (object)local + str2;

            logger.Information(message);
            this._Context.Logger.Information("Target disk size:      " + (object)(volume.DesiredSize / 1048576L) + " MB");
            this._Context.Logger.Information("Vm SCSIBus:        " + (object)volume.VmSCSIBus);
            this._Context.Logger.Information("Vm SCSIUnitNumber: " + (object)volume.VmSCSIUnitNumber);
            this._Context.Logger.Information("DiskFileName:   " + disk.File);
        }
Beispiel #8
0
        private void _ConnectDrive(OculiServiceVolumePersistedState volumeInfo)
        {
            this._Logger.Verbose("Connecting disk.");
            int keyFromHelperBus = this._GetSCSIControllerKeyFromHelperBus(volumeInfo);

            VmDiskInfo[] vmDiskInfos = new VmDiskInfo[1] {
                new VmDiskInfo(true, volumeInfo.VirtualDiskFilename, keyFromHelperBus, volumeInfo.ApplianceSCSIUnitNumber, 0L, "persistent", (IVimDatastore)null, volumeInfo.PreexistingDiskPath)
            };
            Dictionary <uint, DiskInformation> currentDiskInformation = this._GetCurrentDiskInformation();

            ConnectVirtualDiskESXCommon.LogDiskInformation(currentDiskInformation, this._Logger);
            CUtils.Retry(this._ConnectAttempts, this._ConnectDelay, (CUtils.Workload)(() => this._AddVirtualDisksToHelper(vmDiskInfos)));
            this._Logger.Verbose("VMWare has been asked to add these disks:  " + string.Join(",", ((IEnumerable <VmDiskInfo>)vmDiskInfos).Select <VmDiskInfo, string>((Func <VmDiskInfo, string>)(vmDiskInfo => vmDiskInfo.File)).ToArray <string>()));
            try
            {
                this._FillVolumeInfoFromNewDisk(this._GetNewDisks(currentDiskInformation, 1), volumeInfo);
            }
            catch (Exception ex)
            {
                this._ResetESXConnection();
                this._RemoveVirtDiskFromAppliance(volumeInfo);
                throw;
            }
        }
 protected virtual string _BuildESXDiskName(OculiServiceVolumePersistedState vi)
 {
     return(ESXHost.BuildDiskName(this._Context.JobInfoWrapper.SourceHostName, vi.Name));
 }
 protected virtual int _GetSCSIControllerKeyFromHelperBus(OculiServiceVolumePersistedState info)
 {
     return(ESXSCSIHelper.GetSCSIControllerKey(this._Context.ESXHost.HelperVm(), info.ApplianceSCSIBus));
 }
Beispiel #11
0
 protected virtual void _OnlineNewDisk(OculiServiceVolumePersistedState volumeInfo)
 {
     this._Context.Invoker.OnlineDisk(volumeInfo);
 }
Beispiel #12
0
 protected virtual void _InitializeVirtualDisk(OculiServiceVolumePersistedState tempVolumeInfo)
 {
     this._Context.Invoker.InitializeVirtualDisk(tempVolumeInfo);
 }
Beispiel #13
0
 protected virtual void _RemoveVirtDiskFromAppliance(OculiServiceVolumePersistedState volumeInfo)
 {
     this._Context.Invoker.RemoveDrive(volumeInfo);
 }
 protected void _FillVolumeInfoFromNewDisk(Dictionary <uint, DiskInformation> newDisks, OculiServiceVolumePersistedState volume)
 {
     foreach (KeyValuePair <uint, DiskInformation> newDisk in newDisks)
     {
         if ((int)newDisk.Value.ScsiTargetId == volume.ApplianceSCSIUnitNumber)
         {
             this._Logger.FormatVerbose("Adding information to volume with filename \"{0}\"", (object)volume.VirtualDiskFilename);
             volume.DriveName   = newDisk.Value.DeviceID;
             volume.DriveIndex  = (int)newDisk.Value.Index;
             volume.PNPDeviceID = newDisk.Value.PNPDeviceID;
             if (volume.VolumeSignature != null)
             {
                 return;
             }
             if ((int)newDisk.Value.Signature == -1)
             {
                 volume.VolumeSignature = this._GetPartitionMountInfo(volume).ToArray();
                 return;
             }
             uint signature = newDisk.Value.Signature;
             volume.VolumeSignature = new byte[4]
             {
                 (byte)(signature & (uint)byte.MaxValue),
                 (byte)((signature & 65280U) >> 8),
                 (byte)((signature & 16711680U) >> 16),
                 (byte)((signature & 4278190080U) >> 24)
             };
             return;
         }
     }
     throw new OculiServiceServiceException(0, "Disk not found for volume " + volume.Name);
 }
 protected virtual List <byte> _GetPartitionMountInfo(OculiServiceVolumePersistedState volumeInfo)
 {
     return(OculiServiceHelper.Instance.GetPartitionMountInfo((SSMLoggingEventHandler) new OculiService.SSMLogger(this._Context.Logger), volumeInfo.DriveName));
 }
 protected virtual void _RemoveDrive(OculiServiceVolumePersistedState volume)
 {
     this._Context.Invoker.RemoveDrive(volume);
 }
 protected virtual IVimDatastore _GetDatastoreByUrl(OculiServiceVolumePersistedState volume)
 {
     return(this._GetDatastoreByUrl(volume.VirtualDiskPath));
 }