public string GetOriginalLvm(int profileId, string clientHd, string hdToGet, string partitionPrefix) { string result = null; var imageProfile = BLL.ImageProfile.ReadProfile(profileId); var hdNumberToGet = Convert.ToInt32(hdToGet); var partitionHelper = new ClientPartitionHelper(imageProfile); var imageSchema = partitionHelper.GetImageSchema(); foreach (var part in from part in imageSchema.HardDrives[hdNumberToGet].Partitions where part.Active where part.VolumeGroup != null where part.VolumeGroup.LogicalVolumes != null select part) { result = "pvcreate -u " + part.Uuid + " --norestorefile -yf " + clientHd + partitionPrefix + part.VolumeGroup.PhysicalVolume[part.VolumeGroup.PhysicalVolume.Length - 1] + "\r\n"; result += "vgcreate " + part.VolumeGroup.Name + " " + clientHd + partitionPrefix + part.VolumeGroup.PhysicalVolume[part.VolumeGroup.PhysicalVolume.Length - 1] + " -yf" + "\r\n"; result += "echo \"" + part.VolumeGroup.Uuid + "\" >>/tmp/vg-" + part.VolumeGroup.Name + "\r\n"; foreach (var lv in part.VolumeGroup.LogicalVolumes.Where(lv => lv.Active)) { result += "lvcreate --yes -L " + lv.Size + "s -n " + lv.Name + " " + lv.VolumeGroup + "\r\n"; result += "echo \"" + lv.Uuid + "\" >>/tmp/" + lv.VolumeGroup + "-" + lv.Name + "\r\n"; } result += "vgcfgbackup -f /tmp/lvm-" + part.VolumeGroup.Name + "\r\n"; } return(result); }
public string CheckHdRequirements(int profileId, int clientHdNumber, string newHdSize, string imageSchemaDrives, int clientLbs) { var result = new Services.Client.HardDriveSchema(); var imageProfile = BLL.ImageProfile.ReadProfile(profileId); var partitionHelper = new ClientPartitionHelper(imageProfile); var imageSchema = partitionHelper.GetImageSchema(); if (clientHdNumber > imageSchema.HardDrives.Count()) { result.IsValid = "false"; result.Message = "No Image Exists To Download To This Hard Drive. There Are More" + "Hard Drive's Than The Original Image"; return(JsonConvert.SerializeObject(result)); } var listSchemaDrives = new List <int>(); if (!string.IsNullOrEmpty(imageSchemaDrives)) { listSchemaDrives.AddRange(imageSchemaDrives.Split(' ').Select(hd => Convert.ToInt32(hd))); } result.SchemaHdNumber = partitionHelper.NextActiveHardDrive(listSchemaDrives, clientHdNumber); if (result.SchemaHdNumber == -1) { result.IsValid = "false"; result.Message = "No Active Hard Drive Images Were Found To Deploy."; return(JsonConvert.SerializeObject(result)); } var newHdBytes = Convert.ToInt64(newHdSize); var minimumSize = partitionHelper.HardDrive(result.SchemaHdNumber, newHdBytes); if (clientLbs != 0) //if zero should be from the osx imaging environment or winpe { if (clientLbs != imageSchema.HardDrives[result.SchemaHdNumber].Lbs) { Logger.Log("Error: The Logical Block Size Of This Hard Drive " + clientLbs + " Does Not Match The Original Image " + imageSchema.HardDrives[result.SchemaHdNumber].Lbs); result.IsValid = "false"; result.Message = "The Logical Block Size Of This Hard Drive " + clientLbs + " Does Not Match The Original Image " + imageSchema.HardDrives[result.SchemaHdNumber].Lbs; return(JsonConvert.SerializeObject(result)); } } if (minimumSize > newHdBytes) { Logger.Log("Error: " + newHdBytes / 1024 / 1024 + " MB Is Less Than The Minimum Required HD Size For This Image(" + minimumSize / 1024 / 1024 + " MB)"); result.IsValid = "false"; result.Message = newHdBytes / 1024 / 1024 + " MB Is Less Than The Minimum Required HD Size For This Image(" + minimumSize / 1024 / 1024 + " MB)"; return(JsonConvert.SerializeObject(result)); } if (minimumSize == newHdBytes) { result.IsValid = "original"; result.PhysicalPartitions = partitionHelper.GetActivePartitions(result.SchemaHdNumber, imageProfile); result.PhysicalPartitionCount = partitionHelper.GetActivePartitionCount(result.SchemaHdNumber); result.PartitionType = imageSchema.HardDrives[result.SchemaHdNumber].Table; result.BootPartition = imageSchema.HardDrives[result.SchemaHdNumber].Boot; result.UsesLvm = partitionHelper.CheckForLvm(result.SchemaHdNumber); result.Guid = imageSchema.HardDrives[result.SchemaHdNumber].Guid; return(JsonConvert.SerializeObject(result)); } result.IsValid = "true"; result.PhysicalPartitions = partitionHelper.GetActivePartitions(result.SchemaHdNumber, imageProfile); result.PhysicalPartitionCount = partitionHelper.GetActivePartitionCount(result.SchemaHdNumber); result.PartitionType = imageSchema.HardDrives[result.SchemaHdNumber].Table; result.BootPartition = imageSchema.HardDrives[result.SchemaHdNumber].Boot; result.UsesLvm = partitionHelper.CheckForLvm(result.SchemaHdNumber); result.Guid = imageSchema.HardDrives[result.SchemaHdNumber].Guid; return(JsonConvert.SerializeObject(result)); }