public ImageSchemaFEServices(ImageSchemaRequestDTO schemaRequest) { string schema = null; //Only To display the main image specs file when not using a profile. if (schemaRequest.image != null) { schema = new FilesystemServices().ReadSchemaFile(schemaRequest.image.Name); } if (schemaRequest.imageProfile != null) { if (!string.IsNullOrEmpty(schemaRequest.imageProfile.CustomSchema) && schemaRequest.schemaType == "deploy") { schema = schemaRequest.imageProfile.CustomSchema; } else if (!string.IsNullOrEmpty(schemaRequest.imageProfile.CustomUploadSchema) && schemaRequest.schemaType == "upload") { schema = schemaRequest.imageProfile.CustomUploadSchema; } else { schema = new FilesystemServices().ReadSchemaFile(schemaRequest.imageProfile.Image.Name); } } if (!string.IsNullOrEmpty(schema)) { _imageSchema = JsonConvert.DeserializeObject <ImageSchemaGridView>(schema); } }
public ActionResultDTO AddImage(ImageEntity image) { var validationResult = ValidateImage(image, true); var actionResult = new ActionResultDTO(); if (validationResult.Success) { _uow.ImageRepository.Insert(image); _uow.Save(); actionResult.Id = image.Id; var defaultProfile = SeedDefaultImageProfile(image.Id); defaultProfile.ImageId = image.Id; new ImageProfileServices().AddProfile(defaultProfile); var dirCreateResult = new FilesystemServices().CreateNewImageFolders(image.Name); actionResult.Success = dirCreateResult; } else { actionResult.ErrorMessage = validationResult.ErrorMessage; return(actionResult); } return(actionResult); }
public void DeleteImage(int profileId) { var profile = new ImageProfileServices().ReadProfile(profileId); if (string.IsNullOrEmpty(profile.Image.Name)) { return; } //Remove existing custom deploy schema, it may not match newly updated image profile.CustomSchema = string.Empty; new ImageProfileServices().UpdateProfile(profile); var delResult = new FilesystemServices().DeleteImageFolders(profile.Image.Name); if (delResult) { new FilesystemServices().CreateNewImageFolders(profile.Image.Name); } }
public ActionResultDTO DeleteImage(int imageId) { var image = GetImage(imageId); if (image == null) { return new ActionResultDTO { ErrorMessage = "Image Not Found", Id = 0 } } ; var result = new ActionResultDTO(); if (Convert.ToBoolean(image.Protected)) { result.ErrorMessage = "This Image Is Protected And Cannot Be Deleted"; return(result); } _uow.ImageRepository.Delete(image.Id); _uow.Save(); result.Id = imageId; //Check if image name is empty or null, return if so or something will be deleted that shouldn't be if (string.IsNullOrEmpty(image.Name)) { return(result); } DeleteAllUserManagementsForImage(image.Id); DeleteAllProfilesForImage(image.Id); var delDirectoryResult = new FilesystemServices().DeleteImageFolders(image.Name); result.Success = delDirectoryResult; return(result); }
public ClientPartitionHelper(ImageProfileWithImage imageProfile) { string schema = null; if (imageProfile != null) { _imageProfile = imageProfile; if ((imageProfile.PartitionMethod == "Dynamic" || imageProfile.PartitionMethod == "Standard" || imageProfile.PartitionMethod == "Standard Core Storage") && !string.IsNullOrEmpty(imageProfile.CustomSchema)) { schema = imageProfile.CustomSchema; } else { schema = new FilesystemServices().ReadSchemaFile(imageProfile.Image.Name); } } if (!string.IsNullOrEmpty(schema)) { _imageSchema = JsonConvert.DeserializeObject <ImageSchema>(schema); } }
public ActionResultDTO DeleteImage(int imageId) { var image = GetImage(imageId); if (image == null) { return new ActionResultDTO { ErrorMessage = "Image Not Found", Id = 0 } } ; var result = new ActionResultDTO(); if (Convert.ToBoolean(image.Protected)) { result.ErrorMessage = "This Image Is Protected And Cannot Be Deleted"; return(result); } _uow.ImageRepository.Delete(image.Id); _uow.Save(); result.Id = imageId; //Check if image name is empty or null, return if so or something will be deleted that shouldn't be if (string.IsNullOrEmpty(image.Name)) { return(result); } var computers = _uow.ComputerRepository.Get(x => x.ImageId == imageId); var computerService = new ComputerServices(); foreach (var computer in computers) { computer.ImageId = -1; computer.ImageProfileId = -1; computerService.UpdateComputer(computer); } var groups = _uow.GroupRepository.Get(x => x.ImageId == imageId); var groupService = new GroupServices(); foreach (var group in groups) { group.ImageId = -1; group.ImageProfileId = -1; groupService.UpdateGroup(group); } var groupProperties = _uow.GroupPropertyRepository.Get(x => x.ImageId == imageId); var groupPropertyService = new GroupPropertyServices(); foreach (var groupProperty in groupProperties) { groupProperty.ImageId = -1; groupProperty.ImageProfileId = -1; groupPropertyService.UpdateGroupProperty(groupProperty); } var delDirectoryResult = new FilesystemServices().DeleteImageFolders(image.Name); result.Success = delDirectoryResult; return(result); }
/// <summary> /// Calculates the minimum block size required for a single partition, taking into account any children partitions. /// </summary> public PartitionHelper Partition(int hdNumberToGet, int partNumberToGet, long newHdSize) { var partition = _imageSchema.HardDrives[hdNumberToGet].Partitions[partNumberToGet]; var partitionHelper = new PartitionHelper { MinSizeBlk = 0 }; var extendedPartitionHelper = new ExtendedPartitionHelper(); if (partition.Type.ToLower() == "extended") { extendedPartitionHelper = ExtendedPartition(hdNumberToGet, newHdSize); } partitionHelper.VolumeGroupHelper = VolumeGroup(hdNumberToGet, partNumberToGet, newHdSize); var lbsByte = _imageSchema.HardDrives[hdNumberToGet].Lbs; //Look if any volume groups are present for this partition. If so set the volumesize for the volume group to the minimum size //required for the volume group. Volume groups are always treated as resizable even if none of the individual //logical volumes are resizable if (partitionHelper.VolumeGroupHelper.Pv != null) { partitionHelper.PartitionHasVolumeGroup = true; partition.VolumeSize = partitionHelper.VolumeGroupHelper.MinSizeBlk * lbsByte / 1024 / 1024; } if (partition.ForceFixedSize) { partitionHelper.MinSizeBlk = partition.Size; partitionHelper.IsDynamicSize = false; } //Use partition size that user has set for the partition, if it is set. else if (!string.IsNullOrEmpty(partition.CustomSize) && !string.IsNullOrEmpty(partition.CustomSizeUnit)) { long customSizeBytes = 0; switch (partition.CustomSizeUnit) { case "MB": customSizeBytes = Convert.ToInt64(partition.CustomSize) * 1024 * 1024; break; case "GB": customSizeBytes = Convert.ToInt64(partition.CustomSize) * 1024 * 1024 * 1024; break; case "%": var hdPercent = Convert.ToDouble(partition.CustomSize) / 100; customSizeBytes = Convert.ToInt64(hdPercent * newHdSize); break; } partitionHelper.MinSizeBlk = customSizeBytes / lbsByte; partitionHelper.IsDynamicSize = false; } //If partition is not resizable. Determine partition size. Also if the partition is less than 5 gigs assume it is that // size for a reason, do not resize it even if it is marked as a resizable partition else if ((partition.VolumeSize == 0 && partition.Type.ToLower() != "extended") || (partition.Type.ToLower() == "extended" && extendedPartitionHelper.IsOnlySwap) || partition.Size * lbsByte <= 5368709120 || partition.FsType == "swap") { partitionHelper.MinSizeBlk = partition.Size; partitionHelper.IsDynamicSize = false; } //If resizable determine what percent of drive partition was originally and match that to the new drive //while making sure the min size is still less than the resized size. else { partitionHelper.IsDynamicSize = true; if (partition.Type.ToLower() == "extended") { partitionHelper.MinSizeBlk = extendedPartitionHelper.MinSizeBlk; } else if (partitionHelper.VolumeGroupHelper.Pv != null) { partitionHelper.MinSizeBlk = partitionHelper.VolumeGroupHelper.MinSizeBlk; } else { string imageFile = null; foreach (var ext in new[] { "ntfs", "fat", "extfs", "hfsp", "imager", "winpe", "xfs" }) { imageFile = new FilesystemServices().GetFileNameWithFullPath(_imageProfile.Image.Name, hdNumberToGet.ToString(), partition.Number, ext); if (!string.IsNullOrEmpty(imageFile)) { break; } } if (Path.GetExtension(imageFile) == ".wim") { partitionHelper.MinSizeBlk = partition.UsedMb * 1024 * 1024 / lbsByte; } else { //The resize value and used_mb value are calculated during upload by two different methods //Use the one that is bigger just in case. if (partition.VolumeSize > partition.UsedMb) { partitionHelper.MinSizeBlk = partition.VolumeSize * 1024 * 1024 / lbsByte; } else { partitionHelper.MinSizeBlk = partition.UsedMb * 1024 * 1024 / lbsByte; } } } } return(partitionHelper); }
/// <summary> /// Calculates the minimum block size required for a single logical volume, assuming the logical volume cannot have any /// children. /// </summary> public PartitionHelper LogicalVolume(LogicalVolume lv, int lbsByte, long newHdSize, int hdNumberToGet) { var logicalVolumeHelper = new PartitionHelper { MinSizeBlk = 0 }; if (lv.ForceFixedSize) { logicalVolumeHelper.MinSizeBlk = lv.Size; logicalVolumeHelper.IsDynamicSize = false; } else if (!string.IsNullOrEmpty(lv.CustomSize) && !string.IsNullOrEmpty(lv.CustomSizeUnit)) { long customSizeBytes = 0; switch (lv.CustomSizeUnit) { case "MB": customSizeBytes = Convert.ToInt64(lv.CustomSize) * 1024 * 1024; break; case "GB": customSizeBytes = Convert.ToInt64(lv.CustomSize) * 1024 * 1024 * 1024; break; case "%": var hdPercent = Convert.ToDouble(lv.CustomSize) / 100; customSizeBytes = Convert.ToInt64(hdPercent * newHdSize); break; } logicalVolumeHelper.MinSizeBlk = customSizeBytes / lbsByte; logicalVolumeHelper.IsDynamicSize = false; } else { logicalVolumeHelper.IsDynamicSize = true; string imageFile = null; foreach (var ext in new[] { "ntfs", "fat", "extfs", "hfsp", "imager", "xfs" }) { imageFile = new FilesystemServices().GetLVMFileNameWithFullPath(_imageProfile.Image.Name, hdNumberToGet.ToString(), lv.VolumeGroup, lv.Name, ext); if (!string.IsNullOrEmpty(imageFile)) { break; } } if (Path.GetExtension(imageFile) == ".wim") { logicalVolumeHelper.MinSizeBlk = lv.UsedMb * 1024 * 1024 / lbsByte; } else { //fix me - a hack when using core storage with dynamic partitions on macos environment if (lv.FsType.ToLower().Contains("hfs") && newHdSize <= 121332826112) { //assume fusion, set minsize to full size of drive logicalVolumeHelper.MinSizeBlk = Convert.ToInt64(newHdSize * .8) / lbsByte; } else { if (lv.VolumeSize > lv.UsedMb) { logicalVolumeHelper.MinSizeBlk = lv.VolumeSize * 1024 * 1024 / lbsByte; } else { logicalVolumeHelper.MinSizeBlk = lv.UsedMb * 1024 * 1024 / lbsByte; } } } } return(logicalVolumeHelper); }
public List <PhysicalPartition> GetActivePartitions(int schemaHdNumber, ImageProfileWithImage imageProfile) { var listPhysicalPartition = new List <PhysicalPartition>(); foreach ( var partition in _imageSchema.HardDrives[schemaHdNumber].Partitions.Where(partition => partition.Active) ) { var physicalPartition = new PhysicalPartition(); physicalPartition.Number = partition.Number; physicalPartition.Guid = partition.Guid; physicalPartition.Uuid = partition.Uuid; physicalPartition.FileSystem = partition.FsType; physicalPartition.Type = partition.Type; physicalPartition.EfiBootLoader = partition.EfiBootLoader; string imageFile = null; foreach (var ext in new[] { "ntfs", "fat", "extfs", "hfsp", "imager", "xfs" }) { imageFile = new FilesystemServices().GetFileNameWithFullPath(imageProfile.Image.Name, schemaHdNumber.ToString(), partition.Number, ext); if (!string.IsNullOrEmpty(imageFile)) { physicalPartition.PartcloneFileSystem = ext; break; } } switch (Path.GetExtension(imageFile)) { case ".lz4": physicalPartition.Compression = "lz4"; physicalPartition.ImageType = "Block"; break; case ".gz": physicalPartition.Compression = "gz"; physicalPartition.ImageType = "Block"; break; case ".uncp": physicalPartition.Compression = "uncp"; physicalPartition.ImageType = "Block"; break; case ".wim": physicalPartition.ImageType = "File"; break; } if (partition.VolumeGroup.Name != null) { physicalPartition.VolumeGroup = new VolumeGroup(); physicalPartition.VolumeGroup.Name = partition.VolumeGroup.Name; var listLogicalVolumes = new List <CloneDeploy_Entities.DTOs.ClientImaging.LogicalVolume>(); var logicalVolumeCounter = 0; foreach (var logicalVolume in partition.VolumeGroup.LogicalVolumes.Where(x => x.Active)) { logicalVolumeCounter++; var clientLogicalVolume = new CloneDeploy_Entities.DTOs.ClientImaging.LogicalVolume(); clientLogicalVolume.Name = logicalVolume.Name; clientLogicalVolume.FileSystem = logicalVolume.FsType; clientLogicalVolume.Uuid = logicalVolume.Uuid; foreach (var ext in new[] { "ntfs", "fat", "extfs", "hfsp", "imager", "xfs" }) { imageFile = new FilesystemServices().GetLVMFileNameWithFullPath(imageProfile.Image.Name, schemaHdNumber.ToString(), partition.VolumeGroup.Name, logicalVolume.Name, ext); if (!string.IsNullOrEmpty(imageFile)) { clientLogicalVolume.PartcloneFileSystem = ext; break; } } switch (Path.GetExtension(imageFile)) { case ".lz4": clientLogicalVolume.Compression = "lz4"; clientLogicalVolume.ImageType = "Block"; break; case ".gz": clientLogicalVolume.Compression = "gz"; clientLogicalVolume.ImageType = "Block"; break; case ".uncp": clientLogicalVolume.Compression = "uncp"; clientLogicalVolume.ImageType = "Block"; break; case ".wim": clientLogicalVolume.ImageType = "File"; break; } listLogicalVolumes.Add(clientLogicalVolume); } physicalPartition.VolumeGroup.LogicalVolumeCount = logicalVolumeCounter; physicalPartition.VolumeGroup.LogicalVolumes = listLogicalVolumes; } listPhysicalPartition.Add(physicalPartition); } return(listPhysicalPartition); }
/// <summary> /// Calculates the minimum block size required for a single logical volume, assuming the logical volume cannot have any /// children. /// </summary> public PartitionHelper LogicalVolume(LogicalVolume lv, int lbsByte, long newHdSize, int hdNumberToGet) { var logicalVolumeHelper = new PartitionHelper { MinSizeBlk = 0 }; if (lv.ForceFixedSize) { logicalVolumeHelper.MinSizeBlk = lv.Size; logicalVolumeHelper.IsDynamicSize = false; } else if (!string.IsNullOrEmpty(lv.CustomSize) && !string.IsNullOrEmpty(lv.CustomSizeUnit)) { long customSizeBytes = 0; switch (lv.CustomSizeUnit) { case "MB": customSizeBytes = Convert.ToInt64(lv.CustomSize) * 1024 * 1024; break; case "GB": customSizeBytes = Convert.ToInt64(lv.CustomSize) * 1024 * 1024 * 1024; break; case "%": var hdPercent = Convert.ToDouble(lv.CustomSize) / 100; customSizeBytes = Convert.ToInt64(hdPercent * newHdSize); break; } logicalVolumeHelper.MinSizeBlk = customSizeBytes / lbsByte; logicalVolumeHelper.IsDynamicSize = false; } else { logicalVolumeHelper.IsDynamicSize = true; string imageFile = null; foreach (var ext in new[] { "ntfs", "fat", "extfs", "hfsp", "imager", "xfs" }) { imageFile = new FilesystemServices().GetLVMFileNameWithFullPath(_imageProfile.Image.Name, hdNumberToGet.ToString(), lv.VolumeGroup, lv.Name, ext); if (!string.IsNullOrEmpty(imageFile)) { break; } } if (Path.GetExtension(imageFile) == ".wim") { logicalVolumeHelper.MinSizeBlk = lv.UsedMb * 1024 * 1024 / lbsByte; } else { if (lv.VolumeSize > lv.UsedMb) { logicalVolumeHelper.MinSizeBlk = lv.VolumeSize * 1024 * 1024 / lbsByte; } else { logicalVolumeHelper.MinSizeBlk = lv.UsedMb * 1024 * 1024 / lbsByte; } } } return(logicalVolumeHelper); }