protected override void OnInit(EventArgs e) { base.OnInit(e); Image = !string.IsNullOrEmpty(Request["imageid"]) ? Call.ImageApi.Get(Convert.ToInt32(Request.QueryString["imageid"])) : null; ImageProfile = !string.IsNullOrEmpty(Request["profileid"]) ? Call.ImageProfileApi.Get(Convert.ToInt32(Request.QueryString["profileid"])) : null; if (Image == null) { RequiresAuthorization(AuthorizationStrings.SearchImage); } else { RequiresAuthorizationOrManagedImage(AuthorizationStrings.ReadImage, Image.Id); var isProfilePage = !string.IsNullOrEmpty(Request.QueryString["cat"]) ? true : false; if (isProfilePage) { if (ImageProfile == null) { RequiresAuthorization(AuthorizationStrings.SearchProfile); } else { RequiresAuthorization(AuthorizationStrings.ReadProfile); } } } }
public CreateTaskArguments(ComputerEntity computer, ImageProfileWithImage imageProfile, string direction) { _computer = computer; _imageProfile = imageProfile; _direction = direction; _activeTaskArguments = new StringBuilder(); _imageProfileServices = new ImageProfileServices(); }
//used for when multicasting public CreateTaskArguments(EntityComputer computer, ImageProfileWithImage imageProfile, string direction, int comServerId) { _computer = computer; _imageProfile = imageProfile; _direction = direction; _activeTaskArguments = new StringBuilder(); _imageProfileServices = new ServiceImageProfile(); _comServerId = comServerId; }
protected override void OnInit(EventArgs e) { base.OnInit(e); RequiresAuthorization(AuthorizationStrings.ImageRead); ImageEntity = !string.IsNullOrEmpty(Request.QueryString["imageId"]) ? Call.ImageApi.Get(Convert.ToInt32(Request.QueryString["imageId"])) : null; ImageProfile = !string.IsNullOrEmpty(Request["profileId"]) ? Call.ImageProfileApi.Get(Convert.ToInt32(Request.QueryString["profileId"])) : null; }
public ServiceClientPartitionSchema(int hdToGet, string newHdSize, ImageProfileWithImage imageProfile, string partitionPrefix) { _hdToGet = hdToGet; _newHdSize = (long)(Convert.ToInt64(newHdSize) * .99); _imageProfile = imageProfile; PrimaryAndExtendedPartitions = new List <ClientPartition>(); LogicalPartitions = new List <ClientPartition>(); LogicalVolumes = new List <ClientLogicalVolume>(); VolumeGroupHelpers = new List <ClientVolumeGroupHelper>(); _imageSchema = new ServiceClientPartition(_imageProfile).GetImageSchema(); }
//Constructor For Starting Multicast For On Demand public Multicast(int imageProfileId, string clientCount, int userId, string userIp, int clusterId) { _multicastSession = new ActiveMulticastSessionEntity(); _isOnDemand = true; _imageProfile = new ImageProfileServices().ReadProfile(imageProfileId); _clientCount = clientCount; _group = new GroupEntity { ImageProfileId = _imageProfile.Id }; _userId = userId; _multicastSession.ImageProfileId = _imageProfile.Id; _computerServices = new ComputerServices(); _ipAddress = userIp; _clusterId = clusterId; }
//Constructor For Starting Multicast For On Demand public Multicast(int imageProfileId, string clientCount, string sessionName, int userId, int comServerId) { _multicastSession = new EntityActiveMulticastSession(); _isOnDemand = true; _imageProfile = new ServiceImageProfile().ReadProfile(imageProfileId); _clientCount = clientCount; _group = new EntityGroup { ImageProfileId = _imageProfile.Id }; _userId = userId; _multicastSession.ImageProfileId = _imageProfile.Id; _computerServices = new ServiceComputer(); _comServerId = comServerId; _multicastSession.Name = sessionName; }
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 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"); }
public string Create() { _imageProfile = new ImageProfileServices().ReadProfile(_group.ImageProfileId); if (_imageProfile == null) { return("The Image Profile Does Not Exist"); } if (_imageProfile.Image == null) { return("The Image Does Not Exist"); } var validation = new ImageServices().CheckApprovalAndChecksum(_imageProfile.Image, _userId); if (!validation.Success) { return(validation.ErrorMessage); } _multicastSession.Port = new PortServices().GetNextPort(); if (_multicastSession.Port == 0) { return("Could Not Determine Current Port Base"); } _multicastServerId = _isOnDemand ? new GetMulticastServer(_clusterId).Run() : new GetMulticastServer(_group).Run(); if (_multicastServerId == -2) { return("Could Not Find Any Available Multicast Servers"); } _multicastSession.ServerId = _multicastServerId; _multicastSession.UserId = _userId; //End of the road for starting an on demand multicast if (_isOnDemand) { if (string.IsNullOrEmpty(_multicastSession.Name)) { _multicastSession.Name = _multicastSession.Port.ToString(); } if (string.IsNullOrEmpty(_multicastSession.Name) || !_multicastSession.Name.All(c => char.IsLetterOrDigit(c) || c == '_' || c == '-')) { return("Multicast Session Name Is Not Valid"); } _group.Name = _multicastSession.Name; var onDemandprocessArguments = GenerateProcessArguments(); if (onDemandprocessArguments == 0) { return("Could Not Start The Multicast Application"); } var ondAuditLog = new AuditLogEntity(); ondAuditLog.AuditType = AuditEntry.Type.OndMulticast; ondAuditLog.ObjectId = _imageProfile.ImageId; var ondUser = new UserServices().GetUser(_userId); if (ondUser != null) { ondAuditLog.UserName = ondUser.Name; } ondAuditLog.ObjectName = _imageProfile.Image.Name; ondAuditLog.Ip = _ipAddress; ondAuditLog.UserId = _userId; ondAuditLog.ObjectType = "Image"; ondAuditLog.ObjectJson = JsonConvert.SerializeObject(_multicastSession); new AuditLogServices().AddAuditLog(ondAuditLog); return("Successfully Started Multicast " + _group.Name); } //Continue On If multicast is for a group _multicastSession.Name = _group.Name; _computers = new GroupServices().GetGroupMembers(_group.Id); if (_computers.Count < 1) { return("The Group Does Not Have Any Members"); } var activeMulticastSessionServices = new ActiveMulticastSessionServices(); if (!activeMulticastSessionServices.AddActiveMulticastSession(_multicastSession)) { return("Could Not Create Multicast Database Task. An Existing Task May Be Running."); } if (!CreateComputerTasks()) { activeMulticastSessionServices.Delete(_multicastSession.Id); return("Could Not Create Computer Database Tasks. A Computer May Have An Existing Task."); } if (!CreatePxeFiles()) { activeMulticastSessionServices.Delete(_multicastSession.Id); return("Could Not Create Computer Boot Files"); } if (!CreateTaskArguments()) { activeMulticastSessionServices.Delete(_multicastSession.Id); return("Could Not Create Computer Task Arguments"); } var processArguments = GenerateProcessArguments(); if (processArguments == 0) { activeMulticastSessionServices.Delete(_multicastSession.Id); return("Could Not Start The Multicast Application"); } foreach (var computer in _computers) { IpServices.WakeUp(computer.Mac); } var auditLog = new AuditLogEntity(); auditLog.AuditType = AuditEntry.Type.Multicast; auditLog.ObjectId = _group.Id; var user = new UserServices().GetUser(_userId); if (user != null) { auditLog.UserName = user.Name; } auditLog.ObjectName = _group.Name; auditLog.Ip = _ipAddress; auditLog.UserId = _userId; auditLog.ObjectType = "Group"; auditLog.ObjectJson = JsonConvert.SerializeObject(_multicastSession); new AuditLogServices().AddAuditLog(auditLog); auditLog.ObjectId = _imageProfile.ImageId; auditLog.ObjectName = _imageProfile.Image.Name; auditLog.ObjectType = "Image"; new AuditLogServices().AddAuditLog(auditLog); return("Successfully Started Multicast " + _group.Name); }
public string Start() { if (_computer == null) { return("The Computer Does Not Exist"); } if (_group != null) { //unicast started via group, use that groups assigned image _imageProfile = new ServiceImageProfile().ReadProfile(_group.ImageProfileId); if (_imageProfile == null) { return("The Image Profile Doesn't Exist"); } } else { _imageProfile = new ServiceComputer().GetEffectiveImage(_computer.Id); } if (_imageProfile == null) { return("No Image Has Been Selected"); } if (_imageProfile.Image == null) { return("The Image Does Not Exist"); } if (new ServiceComputer().IsComputerActive(_computer.Id)) { return("This Computer Is Already Part Of An Active Task"); } _activeTask = new EntityActiveImagingTask { ComputerId = _computer.Id, Direction = _direction, UserId = _userId, ImageProfileId = _imageProfile.Id }; _activeTask.Type = _direction; var activeImagingTaskServices = new ServiceActiveImagingTask(); if (!activeImagingTaskServices.AddActiveImagingTask(_activeTask)) { return("Could Not Create The Database Entry For This Task"); } if (!new TaskBootMenu().RunAllServers(_computer, _imageProfile)) { activeImagingTaskServices.DeleteActiveImagingTask(_activeTask.Id); return("Could Not Create PXE Boot File"); } _activeTask.Arguments = new CreateTaskArguments(_computer, _imageProfile, _direction).Execute(); if (!activeImagingTaskServices.UpdateActiveImagingTask(_activeTask)) { activeImagingTaskServices.DeleteActiveImagingTask(_activeTask.Id); return("Could Not Create Task Arguments"); } new ServiceComputer().Wakeup(_computer.Id); var auditLog = new EntityAuditLog(); switch (_direction) { case "deploy": auditLog.AuditType = EnumAuditEntry.AuditType.Deploy; break; default: auditLog.AuditType = EnumAuditEntry.AuditType.Upload; break; } auditLog.ObjectId = _computer.Id; var user = new ServiceUser().GetUser(_userId); if (user != null) { auditLog.UserName = user.Name; } auditLog.ObjectName = _computer.Name; auditLog.UserId = _userId; auditLog.ObjectType = "Computer"; auditLog.ObjectJson = JsonConvert.SerializeObject(_activeTask); new ServiceAuditLog().AddAuditLog(auditLog); auditLog.ObjectId = _imageProfile.ImageId; auditLog.ObjectName = _imageProfile.Image.Name; auditLog.ObjectType = "Image"; new ServiceAuditLog().AddAuditLog(auditLog); return("Successfully Started Task For " + _computer.Name); }
public string Start() { if (string.IsNullOrEmpty(SettingServices.GetSettingValue(SettingStrings.ServerIdentifier))) { return("The Server Identifier Must Be Set Before Tasks Can Be Started"); } if (_computer == null) { return("The Computer Does Not Exist"); } _imageProfile = new ImageProfileServices().ReadProfile(_computer.ImageProfileId); if (_imageProfile == null) { return("The Image Profile Does Not Exist"); } if (_imageProfile.Image == null) { return("The Image Does Not Exist"); } if (_direction == "deploy" || _direction == "permanentdeploy") { var validation = new ImageServices().CheckApprovalAndChecksum(_imageProfile.Image, _userId); if (!validation.Success) { return(validation.ErrorMessage); } } var dp = new DistributionPointServices().GetPrimaryDistributionPoint(); if (dp == null) { return("Could Not Find A Primary Distribution Point"); } if (SettingServices.ServerIsClusterPrimary) { var clusterGroup = new ComputerServices().GetClusterGroup(_computer.Id); if (clusterGroup == null) { return("Could Not Find A Cluster Group For This Computer"); } } if (new ComputerServices().IsComputerActive(_computer.Id)) { return("This Computer Is Already Part Of An Active Task"); } _activeTask = new ActiveImagingTaskEntity { ComputerId = _computer.Id, Direction = _direction, UserId = _userId }; _activeTask.Type = _direction; var activeImagingTaskServices = new ActiveImagingTaskServices(); if (!activeImagingTaskServices.AddActiveImagingTask(_activeTask)) { return("Could Not Create The Database Entry For This Task"); } if (!new TaskBootMenu(_computer, _imageProfile).CreatePxeBootFiles()) { activeImagingTaskServices.DeleteActiveImagingTask(_activeTask.Id); return("Could Not Create PXE Boot File"); } _activeTask.Arguments = new CreateTaskArguments(_computer, _imageProfile, _direction).Execute(); if (!activeImagingTaskServices.UpdateActiveImagingTask(_activeTask)) { activeImagingTaskServices.DeleteActiveImagingTask(_activeTask.Id); return("Could Not Create Task Arguments"); } IpServices.WakeUp(_computer.Mac); var auditLog = new AuditLogEntity(); switch (_direction) { case "deploy": auditLog.AuditType = AuditEntry.Type.Deploy; break; case "permanentdeploy": auditLog.AuditType = AuditEntry.Type.PermanentPush; break; default: auditLog.AuditType = AuditEntry.Type.Upload; break; } auditLog.ObjectId = _computer.Id; var user = new UserServices().GetUser(_userId); if (user != null) { auditLog.UserName = user.Name; } auditLog.ObjectName = _computer.Name; auditLog.Ip = _ipAddress; auditLog.UserId = _userId; auditLog.ObjectType = "Computer"; auditLog.ObjectJson = JsonConvert.SerializeObject(_activeTask); new AuditLogServices().AddAuditLog(auditLog); auditLog.ObjectId = _imageProfile.ImageId; auditLog.ObjectName = _imageProfile.Image.Name; auditLog.ObjectType = "Image"; new AuditLogServices().AddAuditLog(auditLog); return("Successfully Started Task For " + _computer.Name); }
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); }
public string Create() { _imageProfile = new ServiceImageProfile().ReadProfile(_group.ImageProfileId); if (_imageProfile == null) { return("The Image Profile Does Not Exist"); } if (_imageProfile.Image == null) { return("The Image Does Not Exist"); } _multicastServerId = _isOnDemand ? _comServerId : new GetMulticastServer(_group).Run(); if (_multicastServerId == null) { return("Could Not Find Any Available Multicast Servers"); } var comServer = new ServiceClientComServer().GetServer(Convert.ToInt32(_multicastServerId)); if (string.IsNullOrEmpty(comServer.MulticastInterfaceIp)) { return("The Com Server's Multicast Interface IP Address Is Not Populated"); } _multicastSession.Port = new ServicePort().GetNextPort(_multicastServerId); if (_multicastSession.Port == 0) { return("Could Not Determine Current Port Base"); } _multicastSession.ComServerId = Convert.ToInt32(_multicastServerId); _multicastSession.UserId = _userId; if (_isOnDemand) { if (string.IsNullOrEmpty(_multicastSession.Name)) { _multicastSession.Name = _multicastSession.Port.ToString(); } if (string.IsNullOrEmpty(_multicastSession.Name) || !_multicastSession.Name.All(c => char.IsLetterOrDigit(c) || c == '_' || c == '-')) { return("Multicast Session Name Is Not Valid"); } _group.Name = _multicastSession.Name; var onDemandprocessArguments = GenerateProcessArguments(); if (onDemandprocessArguments == 0) { return("Could Not Start The Multicast Application"); } var ondAuditLog = new EntityAuditLog(); ondAuditLog.AuditType = EnumAuditEntry.AuditType.OnDemandMulticast; ondAuditLog.ObjectId = _imageProfile.ImageId; var ondUser = new ServiceUser().GetUser(_userId); if (ondUser != null) { ondAuditLog.UserName = ondUser.Name; } ondAuditLog.ObjectName = _imageProfile.Image.Name; ondAuditLog.UserId = _userId; ondAuditLog.ObjectType = "Image"; ondAuditLog.ObjectJson = JsonConvert.SerializeObject(_multicastSession); new ServiceAuditLog().AddAuditLog(ondAuditLog); return("Successfully Started Multicast " + _group.Name); } //End of the road for starting an on demand multicast //Continue On If multicast is for a group _multicastSession.Name = _group.Name; _computers = new ServiceGroup().GetGroupMembers(_group.Id); if (_computers.Count < 1) { return("The Group Does Not Have Any Members"); } var activeMulticastSessionServices = new ServiceActiveMulticastSession(); if (!activeMulticastSessionServices.AddActiveMulticastSession(_multicastSession)) { return("Could Not Create Multicast Database Task. An Existing Task May Be Running."); } if (!CreateComputerTasks()) { activeMulticastSessionServices.Delete(_multicastSession.Id); return("Could Not Create Computer Database Tasks. A Computer May Have An Existing Task."); } if (!CreatePxeFiles()) { activeMulticastSessionServices.Delete(_multicastSession.Id); return("Could Not Create Computer Boot Files"); } if (!CreateTaskArguments()) { activeMulticastSessionServices.Delete(_multicastSession.Id); return("Could Not Create Computer Task Arguments"); } var processArguments = GenerateProcessArguments(); if (processArguments == 0) { activeMulticastSessionServices.Delete(_multicastSession.Id); return("Could Not Start The Multicast Application"); } foreach (var computer in _computers) { _computerServices.Wakeup(computer.Id); } var auditLog = new EntityAuditLog(); auditLog.AuditType = EnumAuditEntry.AuditType.Multicast; auditLog.ObjectId = _group.Id; var user = new ServiceUser().GetUser(_userId); if (user != null) { auditLog.UserName = user.Name; } auditLog.ObjectName = _group.Name; auditLog.UserId = _userId; auditLog.ObjectType = "Group"; auditLog.ObjectJson = JsonConvert.SerializeObject(_multicastSession); new ServiceAuditLog().AddAuditLog(auditLog); auditLog.ObjectId = _imageProfile.ImageId; auditLog.ObjectName = _imageProfile.Image.Name; auditLog.ObjectType = "Image"; new ServiceAuditLog().AddAuditLog(auditLog); return("Successfully Started Multicast " + _group.Name); }