protected virtual void _EnsureVmFolderExists(IVimVm replicaVm, VmDiskInfo disk)
 {
     if (disk.Location.DirectoryExist(replicaVm.Name, this._Context.ESXHost.ClientCtx))
     {
         return;
     }
     disk.Location.CreateDirectory(replicaVm.Name);
 }
 private VmDiskInfo[] _BuildDiskList(OculiServiceVolumePersistedState[] internalVolumeInfos)
 {
     return(((IEnumerable <OculiServiceVolumePersistedState>)internalVolumeInfos).Select <OculiServiceVolumePersistedState, VmDiskInfo>((Func <OculiServiceVolumePersistedState, VmDiskInfo>)(vi =>
     {
         if (string.IsNullOrEmpty(vi.VirtualDiskPath))
         {
             this._Logger.FormatWarning("Volume missing Data Storage URL for vm {0} will use {1}", (object)this._Context.JobInfoWrapper.VmName, (object)this._Context.JobInfoWrapper.DataStoreUrl);
             vi.VirtualDiskPath = this._Context.JobInfoWrapper.DataStoreUrl;
         }
         string file = this._BuildESXDiskName(vi);
         IVimDatastore datastoreByUrl = this._ESXHost.GetDatastoreByUrl(vi.VirtualDiskPath);
         long datastoreMaxVmdkSizeMb = this._ESXHost.GetDatastoreMaxVmdkSizeMB(datastoreByUrl);
         VmDiskInfo disk = new VmDiskInfo(false, file, vi.VmSCSIBus + 1, vi.VmSCSIUnitNumber, Math.Min(vi.DesiredSize / 1048576L, datastoreMaxVmdkSizeMb), "persistent", datastoreByUrl, this._DiskProvisioningType(vi.DiskProvisioningType), vi.PreexistingDiskPath);
         this._ReportOnDisk(disk, vi);
         return disk;
     })).ToArray <VmDiskInfo>());
 }
        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);
        }
 private VmDiskInfo[] _BuildDiskList(OculiServiceVolumePersistedState[] volumes)
 {
     return(((IEnumerable <OculiServiceVolumePersistedState>)volumes).Select <OculiServiceVolumePersistedState, VmDiskInfo>((Func <OculiServiceVolumePersistedState, VmDiskInfo>)(volume =>
     {
         if (string.IsNullOrEmpty(volume.VirtualDiskPath))
         {
             this._Logger.Error("Volume missing Data Storage URL for job " + this._Context.JobInfoWrapper.Name);
             throw new OculiServiceServiceException(0, "Volume missing Data Storage URL");
         }
         string file = ESXHost.BuildDiskName(this._Context.JobInfoWrapper.SourceHostName, volume.Name);
         IVimDatastore datastoreByUrl = this._GetDatastoreByUrl(volume);
         long datastoreMaxVmdkSizeMb = this._ESXHost.GetDatastoreMaxVmdkSizeMB(datastoreByUrl);
         this._CheckDiskProvisioningType(volume);
         VmDiskInfo disk = new VmDiskInfo(false, file, volume.VmSCSIBus + 1, volume.VmSCSIUnitNumber, Math.Min(volume.DesiredSize / 1048576L, datastoreMaxVmdkSizeMb), "persistent", datastoreByUrl, volume.DiskProvisioningType, volume.PreexistingDiskPath);
         this._ReportOnDisk(disk, volume);
         return disk;
     })).ToArray <VmDiskInfo>());
 }
Example #5
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);
        }
 private void _ProcessPrestagedDisk(IVimVm replicaVm, VmDiskInfo disk)
 {
     try
     {
         IVimDatastore location = disk.Location;
         this._Logger.Information("Getting Vmdks Info on datastore: " + location.Name);
         string fileName = Path.GetFileName(disk.PreExistingDiskPath.Replace("\\", "/"));
         Dictionary <string, VmdkFileInfo> vmdksFileInfo = location.GetVmdksFileInfo(disk.PreExistingDiskPath, this._Context.ESXHost.ClientCtx);
         if (vmdksFileInfo == null && vmdksFileInfo.Count < 2)
         {
             throw new EsxException("The pre-existing disk " + disk.PreExistingDiskPath + " could not be found.", false);
         }
         VmdkFileInfo vmdkFileInfo1 = vmdksFileInfo[fileName];
         VmdkFileInfo vmdkFileInfo2 = vmdksFileInfo[vmdkFileInfo1.DataFileName];
         if (vmdkFileInfo1.Size + vmdkFileInfo2.Size <= 0UL)
         {
             throw new EsxException("The pre-existing disk " + disk.PreExistingDiskPath + " does not have a valid configuration.", false);
         }
         string str     = this._VimUtilsGetVolumeName(location) + this._Context.JobInfoWrapper.VmName + "/";
         string name    = vmdkFileInfo1.Name;
         string target1 = str + name;
         this._Logger.Information(string.Format("Pre-stage folder vmdk-s \"{0}\" moving to destination folder \"{1}\"", (object)vmdkFileInfo1.FullName, (object)target1));
         location.MoveFilesByFullName(vmdkFileInfo1.FullName, target1, this._Context.JobInfoWrapper.VmName, true, this._Context.ESXHost.ClientCtx);
         string dataFileName = vmdkFileInfo1.DataFileName;
         string target2      = str + dataFileName;
         this._Logger.Information(string.Format("Pre-stage folder vmdk-s \"{0}\" moving to destination folder \"{1}\"", (object)vmdkFileInfo2.FullName, (object)target2));
         location.MoveFilesByFullName(vmdkFileInfo2.FullName, target2, this._Context.JobInfoWrapper.VmName, true, this._Context.ESXHost.ClientCtx);
         this._Logger.Information(string.Format("Pre-stage Disk found and trying to add \"{0}\"", (object)target1));
         disk.File = target1;
         this._AddVirtualDisk(replicaVm, disk);
     }
     catch (Exception ex)
     {
         this._Logger.Error("Exception thrown on attaching a disk" + ex.ToString());
         throw ex;
     }
 }
Example #7
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 void _AddVirtualDisk(IVimVm replicaVm, VmDiskInfo disk)
 {
     new AddVirtualDiskOp(replicaVm, this._Context.ESXHost.VC_Vim, disk, this._Context.Logger, 120).Run();
 }