public TftpServerDTO GetAllTftpServers() { var tftpDto = new TftpServerDTO(); tftpDto.TftpServers = new List <string>(); if (SettingServices.ServerIsNotClustered) { tftpDto.TftpServers.Add( StringManipulationServices.PlaceHolderReplace( SettingServices.GetSettingValue(SettingStrings.TftpServerIp))); } else { if (SettingServices.TftpServerRole) { tftpDto.TftpServers.Add( StringManipulationServices.PlaceHolderReplace( SettingServices.GetSettingValue(SettingStrings.TftpServerIp))); } var tftpServers = new SecondaryServerServices().SearchSecondaryServers().Where(x => x.TftpRole == 1 && x.IsActive == 1); foreach (var tftpServer in tftpServers) { var tServer = new APICall(new SecondaryServerServices().GetToken(tftpServer.Name)).ServiceAccountApi .GetTftpServer(); if (!string.IsNullOrEmpty(tServer)) { tftpDto.TftpServers.Add(tServer); } } } return(tftpDto); }
public bool UpdatePxeSettings(List <SettingEntity> settings) { if (!UpdateSetting(settings)) { return(false); } if (!ServerIsNotClustered) { var secondaryServers = new SecondaryServerServices().SearchSecondaryServers() .Where(x => x.TftpRole == 1 && x.IsActive == 1); foreach (var server in secondaryServers) { var result = new APICall(new SecondaryServerServices().GetToken(server.Name)) .ServiceAccountApi.UpdateSettings(settings); if (!result) { return(false); } } return(true); } return(true); }
public TftpServerDTO GetComputerTftpServers(string mac) { var tftpDto = new TftpServerDTO(); tftpDto.TftpServers = new List <string>(); if (SettingServices.ServerIsNotClustered) { tftpDto.TftpServers.Add( StringManipulationServices.PlaceHolderReplace( SettingServices.GetSettingValue(SettingStrings.TftpServerIp))); } else { var clusterServices = new ClusterGroupServices(); var secondaryServerServices = new SecondaryServerServices(); List <ClusterGroupServerEntity> clusterServers; var computer = new ComputerServices().GetComputerFromMac(mac); if (computer == null) { var cg = new ClusterGroupServices().GetDefaultClusterGroup(); clusterServers = clusterServices.GetActiveClusterServers(cg.Id); } else { var cg = new ComputerServices().GetClusterGroup(computer.Id); clusterServers = clusterServices.GetActiveClusterServers(cg.Id); } foreach (var tftpServer in clusterServers.Where(x => x.TftpRole == 1)) { if (tftpServer.ServerId == -1) { tftpDto.TftpServers.Add( StringManipulationServices.PlaceHolderReplace( SettingServices.GetSettingValue(SettingStrings.TftpServerIp))); } else { var serverIdentifier = secondaryServerServices.GetSecondaryServer(tftpServer.ServerId).Name; var tServer = new APICall(new SecondaryServerServices().GetToken(serverIdentifier)).ServiceAccountApi .GetTftpServer(); if (tServer != null) { tftpDto.TftpServers.Add(tServer); } } } } return(tftpDto); }
public bool CreateBootFiles(int id) { var computer = GetComputer(id); if (new ComputerServices().IsComputerActive(computer.Id)) { return(false); //Files Will Be Processed When task is done } var bootMenu = new ComputerServices().GetComputerBootMenu(computer.Id); if (bootMenu == null) { return(false); } var pxeMac = StringManipulationServices.MacToPxeMac(computer.Mac); string path; if (SettingServices.GetSettingValue(SettingStrings.ProxyDhcp) == "Yes") { var list = new List <Tuple <string, string, string> > { Tuple.Create("bios", "", bootMenu.BiosMenu), Tuple.Create("bios", ".ipxe", bootMenu.BiosMenu), Tuple.Create("efi32", "", bootMenu.Efi32Menu), Tuple.Create("efi32", ".ipxe", bootMenu.Efi32Menu), Tuple.Create("efi64", "", bootMenu.Efi64Menu), Tuple.Create("efi64", ".ipxe", bootMenu.Efi64Menu), Tuple.Create("efi64", ".cfg", bootMenu.Efi64Menu) }; if (SettingServices.ServerIsNotClustered) { foreach (var tuple in list) { path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "proxy" + Path.DirectorySeparatorChar + tuple.Item1 + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + pxeMac + tuple.Item2; if (!string.IsNullOrEmpty(tuple.Item3)) { new FileOpsServices().WritePath(path, tuple.Item3); } } } else { if (SettingServices.TftpServerRole) { foreach (var tuple in list) { path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "proxy" + Path.DirectorySeparatorChar + tuple.Item1 + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + pxeMac + tuple.Item2; if (!string.IsNullOrEmpty(tuple.Item3)) { new FileOpsServices().WritePath(path, tuple.Item3); } } } var secondaryServers = new SecondaryServerServices().SearchSecondaryServers().Where(x => x.TftpRole == 1 && x.IsActive == 1); foreach (var server in secondaryServers) { var tftpPath = new APICall(new SecondaryServerServices().GetToken(server.Name)) .SettingApi.GetSetting("Tftp Path").Value; foreach (var tuple in list) { path = tftpPath + "proxy" + Path.DirectorySeparatorChar + tuple.Item1 + Path.DirectorySeparatorChar + "pxelinux.cfg" + Path.DirectorySeparatorChar + pxeMac + tuple.Item2; new APICall(new SecondaryServerServices().GetToken(server.Name)) .ServiceAccountApi.WriteTftpFile(new TftpFileDTO { Path = path, Contents = tuple.Item3 }); } } } } else { var mode = SettingServices.GetSettingValue(SettingStrings.PxeMode); path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "pxelinux.cfg" + Path.DirectorySeparatorChar + pxeMac; if (SettingServices.ServerIsNotClustered) { if (mode.Contains("ipxe")) { path += ".ipxe"; } else if (mode.Contains("grub")) { path += ".cfg"; } if (!string.IsNullOrEmpty(bootMenu.BiosMenu)) { new FileOpsServices().WritePath(path, bootMenu.BiosMenu); } } else { if (SettingServices.TftpServerRole) { path = SettingServices.GetSettingValue(SettingStrings.TftpPath) + "pxelinux.cfg" + Path.DirectorySeparatorChar + pxeMac; if (mode.Contains("ipxe")) { path += ".ipxe"; } else if (mode.Contains("grub")) { path += ".cfg"; } if (!string.IsNullOrEmpty(bootMenu.BiosMenu)) { new FileOpsServices().WritePath(path, bootMenu.BiosMenu); } } var secondaryServers = new SecondaryServerServices().SearchSecondaryServers().Where(x => x.TftpRole == 1 && x.IsActive == 1); foreach (var server in secondaryServers) { var tftpPath = new APICall(new SecondaryServerServices().GetToken(server.Name)) .SettingApi.GetSetting("Tftp Path").Value; path = tftpPath + "pxelinux.cfg" + Path.DirectorySeparatorChar + pxeMac; if (mode.Contains("ipxe")) { path += ".ipxe"; } else if (mode.Contains("grub")) { path += ".cfg"; } new APICall(new SecondaryServerServices().GetToken(server.Name)) .ServiceAccountApi.WriteTftpFile(new TftpFileDTO { Path = path, Contents = bootMenu.BiosMenu }); } } } return(true); }