示例#1
0
        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);
        }
示例#2
0
 public static string MinimumClientSizeForGridView(int profileId, int hdNumber)
 {
     try
     {
         var profile       = BLL.ImageProfile.ReadProfile(profileId);
         var fltClientSize = new ClientPartitionHelper(profile).HardDrive(hdNumber, 1) / 1024f / 1024f / 1024f;
         return(Math.Abs(fltClientSize) < 0.1f ? "< 100M" : fltClientSize.ToString("#.##") + " GB");
     }
     catch
     {
         return("N/A");
     }
 }
        public string GeneratePartitionScript()
        {
            imageProfile = new ImageProfileServices().ReadProfile(profileId);
            ImageSchema  = new ClientPartitionHelper(imageProfile).GetImageSchema();

            clientSchema =
                new ClientPartitionSchemaServices(HdNumberToGet, NewHdSize, imageProfile, partitionPrefix)
                .GenerateClientSchema();
            if (clientSchema == null)
            {
                return("failed");
            }

            //Handle moving from / to hard drives with different sector sizes ie 512 / 4096
            var activeCounter = HdNumberToGet;

            //Look for first active hd
            if (!ImageSchema.HardDrives[HdNumberToGet].Active)
            {
                while (activeCounter <= ImageSchema.HardDrives.Count())
                {
                    if (ImageSchema.HardDrives[activeCounter - 1].Active)
                    {
                        HdNumberToGet = activeCounter - 1;
                    }
                    activeCounter++;
                }
            }
            var LbsByte = Convert.ToInt32(ImageSchema.HardDrives[HdNumberToGet].Lbs); //logical block size in bytes

            if (LbsByte == 512 && clientBlockSize == 4096)
            {
                //fix calculations from 512 to 4096
                clientSchema.FirstPartitionStartSector             = clientSchema.FirstPartitionStartSector / 8;
                clientSchema.ExtendedPartitionHelper.AgreedSizeBlk = clientSchema.ExtendedPartitionHelper.AgreedSizeBlk /
                                                                     8;
                foreach (var partition in clientSchema.PrimaryAndExtendedPartitions)
                {
                    //efi partition on 4k drive cannot be smaller than this, and it is smaller on a 512 drive
                    if (partition.FsId.ToLower() == "ef00")
                    {
                        partition.Size = 66560;
                    }
                    else
                    {
                        partition.Size = partition.Size / 8;
                    }
                    partition.Start = partition.Size / 8;
                }

                foreach (var partition in clientSchema.LogicalPartitions)
                {
                    partition.Size  = partition.Size / 8;
                    partition.Start = partition.Size / 8;
                }

                foreach (var lv in clientSchema.LogicalVolumes)
                {
                    lv.Size = lv.Size / 8;
                }
            }
            else if (LbsByte == 4096 && clientBlockSize == 512)
            {
                //fix calculations from 4096 to 512
                clientSchema.FirstPartitionStartSector             = clientSchema.FirstPartitionStartSector * 8;
                clientSchema.ExtendedPartitionHelper.AgreedSizeBlk = clientSchema.ExtendedPartitionHelper.AgreedSizeBlk *
                                                                     8;
                foreach (var partition in clientSchema.PrimaryAndExtendedPartitions)
                {
                    partition.Size  = partition.Size * 8;
                    partition.Start = partition.Size * 8;
                }

                foreach (var partition in clientSchema.LogicalPartitions)
                {
                    partition.Size  = partition.Size * 8;
                    partition.Start = partition.Size * 8;
                }

                foreach (var lv in clientSchema.LogicalVolumes)
                {
                    lv.Size = lv.Size * 8;
                }
            }

            //otherwise both the original image block size and the destination hard block size are the same, no changes needed
            //End Handle moving from / to hard drives with different sector sizes

            if (imageProfile.Image.Environment == "linux" || string.IsNullOrEmpty(imageProfile.Image.Environment))
            {
                return(LinuxLayout());
            }

            if (imageProfile.Image.Environment == "winpe")
            {
                return(WinPELayout());
            }
            return("failed");
        }
示例#4
0
        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));
        }
示例#5
0
        private string GenerateProcessArguments()
        {
            var isUnix = Environment.OSVersion.ToString().Contains("Unix");

            var schema = new ClientPartitionHelper(_imageProfile).GetImageSchema();

            var    schemaCounter      = -1;
            var    multicastHdCounter = 0;
            string processArguments   = null;

            foreach (var hd in schema.HardDrives)
            {
                schemaCounter++;
                if (!hd.Active)
                {
                    continue;
                }
                multicastHdCounter++;

                var imagePath = Settings.PrimaryStoragePath + "images" + Path.DirectorySeparatorChar +
                                _imageProfile.Image.Name + Path.DirectorySeparatorChar + "hd" +
                                schemaCounter;

                var x = 0;
                foreach (var part in schema.HardDrives[schemaCounter].Partitions)
                {
                    if (!part.Active)
                    {
                        continue;
                    }
                    string imageFile = null;
                    foreach (var ext in new[] { ".ntfs", ".fat", ".extfs", ".hfsp", ".imager", ".winpe", ".xfs" })
                    {
                        try
                        {
                            imageFile =
                                Directory.GetFiles(
                                    imagePath + Path.DirectorySeparatorChar, "part" + part.Number + ext + ".*")
                                .FirstOrDefault();
                        }
                        catch (Exception ex)
                        {
                            Logger.Log(ex.Message);
                            return(null);
                        }


                        if (imageFile != null)
                        {
                            break;
                        }

                        //Look for lvm
                        if (part.VolumeGroup == null)
                        {
                            continue;
                        }
                        if (part.VolumeGroup.LogicalVolumes == null)
                        {
                            continue;
                        }
                        foreach (var lv in part.VolumeGroup.LogicalVolumes.Where(lv => lv.Active))
                        {
                            try
                            {
                                imageFile =
                                    Directory.GetFiles(
                                        imagePath + imagePath + Path.DirectorySeparatorChar, lv.VolumeGroup + "-" +
                                        lv.Name + ext + ".*")
                                    .FirstOrDefault();
                            }
                            catch (Exception ex)
                            {
                                Logger.Log(ex.Message);
                                return(null);
                            }
                        }
                    }

                    if (imageFile == null)
                    {
                        continue;
                    }
                    if (_imageProfile.Image.Environment == "winpe" &&
                        schema.HardDrives[schemaCounter].Table.ToLower() == "gpt")
                    {
                        if (part.Type.ToLower() == "system" || part.Type.ToLower() == "recovery" ||
                            part.Type.ToLower() == "reserved")
                        {
                            continue;
                        }
                    }
                    if (_imageProfile.Image.Environment == "winpe" &&
                        schema.HardDrives[schemaCounter].Table.ToLower() == "mbr")
                    {
                        if (part.Number == schema.HardDrives[schemaCounter].Boot && schema.HardDrives[schemaCounter].Partitions.Length > 1)
                        {
                            continue;
                        }
                    }
                    x++;

                    string minReceivers;
                    string senderArgs;
                    if (_isOnDemand)
                    {
                        senderArgs = Settings.SenderArgs;
                        if (!string.IsNullOrEmpty(_clientCount))
                        {
                            minReceivers = " --min-receivers " + _clientCount;
                        }
                        else
                        {
                            minReceivers = "";
                        }
                    }
                    else
                    {
                        senderArgs = string.IsNullOrEmpty(_imageProfile.SenderArguments)
                            ? Settings.SenderArgs
                            : _imageProfile.SenderArguments;
                        minReceivers = " --min-receivers " + _computers.Count;
                    }

                    string compAlg;
                    string stdout = "";
                    switch (Path.GetExtension(imageFile))
                    {
                    case ".lz4":
                        compAlg = isUnix ? "lz4 -d " : "lz4.exe\" -d ";
                        stdout  = " - ";
                        break;

                    case ".gz":
                        compAlg = isUnix ? "gzip -c -d " : "gzip.exe\" -c -d ";
                        stdout  = "";
                        break;

                    case ".uncp":
                        compAlg = "none";
                        break;

                    case ".wim":
                        compAlg = "none";
                        break;

                    default:
                        return(null);
                    }

                    if (isUnix)
                    {
                        string prefix = null;
                        if (multicastHdCounter == 1)
                        {
                            prefix = x == 1 ? " -c \"" : " ; ";
                        }
                        else
                        {
                            prefix = " ; ";
                        }


                        if (compAlg == "none" || Settings.MulticastDecompression == "client")
                        {
                            processArguments += (prefix + "cat " + "\"" + imageFile + "\"" + " | udp-sender" +
                                                 " --portbase " + _multicastSession.Port + minReceivers + " " +
                                                 " --ttl 32 " +
                                                 senderArgs);
                        }

                        else
                        {
                            processArguments += (prefix + compAlg + "\"" + imageFile + "\"" + stdout + " | udp-sender" +
                                                 " --portbase " + _multicastSession.Port + minReceivers + " " +
                                                 " --ttl 32 " +
                                                 senderArgs);
                        }
                    }
                    else
                    {
                        var appPath = HttpContext.Current.Server.MapPath("~") + Path.DirectorySeparatorChar + "private" +
                                      Path.DirectorySeparatorChar + "apps" + Path.DirectorySeparatorChar;

                        string prefix = null;
                        if (multicastHdCounter == 1)
                        {
                            prefix = x == 1 ? " /c \"" : " & ";
                        }
                        else
                        {
                            prefix = " & ";
                        }


                        if (compAlg == "none" || Settings.MulticastDecompression == "client")
                        {
                            processArguments += (prefix + "\"" + appPath +
                                                 "udp-sender.exe" + "\"" + " --file " + "\"" + imageFile + "\"" +
                                                 " --portbase " + _multicastSession.Port + minReceivers + " " +
                                                 " --ttl 32 " +
                                                 senderArgs);
                        }
                        else
                        {
                            processArguments += (prefix + "\"" + appPath + compAlg + "\"" + imageFile + "\"" + stdout + " | " + "\"" + appPath +
                                                 "udp-sender.exe" + "\"" +
                                                 " --portbase " + _multicastSession.Port + minReceivers + " " +
                                                 " --ttl 32 " +
                                                 senderArgs);
                        }
                    }
                }
            }

            processArguments += "\"";
            return(processArguments);
        }