public ManagerVersion BuildUpdatedVersion(ManagerSession session, IManagerCommandLogger logger, string topic) { //Download the update logger.Log(topic, "Downloading new updates..."); if (DownloadUpdate(session, logger, topic) != 0) { logger.FinishFail("Failed to download updates. Aborting!"); return(null); } //Create new version ID string id = ObjectId.GenerateNewId().ToString(); while (session.versions.ContainsKey(id)) { id = ObjectId.GenerateNewId().ToString(); } //Create new version ManagerVersion version = new ManagerVersion { id = id, package_name = name, time = DateTime.UtcNow }; //Create output folder Directory.CreateDirectory(version.GetPath(session)); //Build new version logger.Log(topic, "Building version from source..."); if (CLITool.RunCLIProcess(session.dotnet_path, $"build -o {version.GetPath(session)} {GetProjectPath(session)}", logger, topic, "Building project files...") != 0) { logger.FinishFail("Failed to build project. Aborting!"); return(null); } //Add to versions lock (session.versions) session.versions.Add(id, version); latest_version = version.id; session.Save(); //Log logger.FinishSuccess($"Successfully created new version {version.id} for package {version.package_name}."); return(version); }
public void DeleteVersion(ManagerSession session, IManagerCommandLogger logger) { //Make sure there aren't any instances using this version int uses = 0; foreach (var i in session.instances) { if (i.version_id == id) { uses++; } } //Check if failed if (uses != 0) { logger.FinishFail($"Can't delete version. There are {uses} other instances using this version that must be updated or removed first."); return; } //Remove version session.versions.Remove(id); //If the current package has this set as the latest version, clear that var package = GetPackage(session); if (package != null && package.latest_version == id) { package.latest_version = null; } //Delete directory Directory.Delete(GetPath(session), true); //Save session.Save(); //Finish logger.FinishSuccess("Successfully removed version."); }
public void UpdateInstance(ManagerSession session, IManagerCommandLogger logger) { //Get the ID of the new version ID ManagerPackage package = GetPackage(session); string newId = package.latest_version; if (newId == null) { logger.FinishFail("There is no current version to upgrade to!"); return; } if (version_id == package.latest_version) { logger.FinishSuccess("The version is already up to date."); return; } //Stop the current instance logger.Log("UpdateInstance", "Shutting down current instance..."); if (StopInstance()) { logger.Log("UpdateInstance", "Instance shut down gracefully."); } else { logger.Log("UpdateInstance", "Waiting for stop timed out after 10 seconds. Instance was forcefully killed."); } //Update logger.Log("UpdateInstance", "Applying changes and restarting instance..."); version_id = newId; StartInstance(session); //Save session.Save(); //Done logger.FinishSuccess("Successfully updated instance to version " + newId + "!"); }
public MasterConnection(ManagerSession session) : base(session, new UnencryptedTransport(), new MinorMajorVersionPair(Program.APP_VERSION_MAJOR, Program.APP_VERSION_MINOR), new IPEndPoint(IPAddress.Parse(Program.connectionConfig.master_ip), Program.connectionConfig.master_port)) { this.session = session; OnConnected += MasterConnection_OnConnected; OnRouterReceiveMessage += MasterConnection_OnRouterReceiveMessage; }
public string GetUpTime(string server) { StringBuilder uptime = new StringBuilder(); try { ManagerSession sess = new ManagerSession(server,community); uint[] oid = new uint[] {1,3,6,1,2,1,1,3,0}; ManagerItem mi = new ManagerItem(sess,oid); string delim = "[]"; int ticks = Convert.ToInt32(mi.Value.ToString().Trim(delim.ToCharArray()).Replace("NULL","")); ticks /= 100; int days = ticks / (60*60*24); ticks -= days * (60*60*24); int hours = ticks / (60*60); ticks -= hours*(60*60); int mins = ticks/(60); ticks -= mins*60; int secs = ticks; //uptime.AppendFormat("{0,2:00}d{1,2:00}h{2,2:00}m{3,2:00}s", days,hours,mins,secs); uptime.AppendFormat("{0,3} days, {1,2} hours, {2,2} mins, {3,2} secs", days,hours,mins,secs); } catch ( Exception ex) { uptime.AppendFormat("{0}",ex.Message); } return(uptime.ToString()); }
public string na_GetStatus(string server) { StringBuilder status = new StringBuilder(); try { ManagerSession sess = new ManagerSession(server,community); uint[] oid = new uint[] {1,3,6,1,4,1,789,1,2,2,25,0}; ManagerItem mi = new ManagerItem(sess,oid); string delim = "\""; status.Append(mi.Value.ToString().Trim(delim.ToCharArray()).Trim().Replace("NULL","")); } catch ( Exception ex) { status.Append(ex.Message); } return(status.ToString()); }
public ManagerVersion GetVersion(ManagerSession session) { return(session.versions[version_id]); }
public ManagerPackage GetPackage(ManagerSession session) { return(session.packages[package_name]); }
private static void getVolStatus(string hostname, string community) { try { uint[] na_dfNumber = new uint[] {1,3,6,1,4,1,789,1,5,6,0}; //uint[] na_dfFileSys= new uint[] {1,3,6,1,4,1,789,1,5,4,1,2,1}; uint[] oid = new uint[] {1,3,6,1,2,1,1,3,0}; UInt64 dfNumber = 0; { ManagerSession sess = new ManagerSession(hostname,community); ManagerItem mi = new ManagerItem(sess,na_dfNumber); string value = mi.Value.ToString(); dfNumber = Convert.ToUInt64(value); } for(uint i=1; i<dfNumber; i+=2) { uint[] na_dfFileSys= new uint[] {1,3,6,1,4,1,789,1,5,4,1,2,i}; uint[] na_dfKBytesTotal= new uint[] {1,3,6,1,4,1,789,1,5,4,1,3,i}; uint[] na_dfKBytesUsed= new uint[] {1,3,6,1,4,1,789,1,5,4,1,4,i}; uint[] na_dfPercentKBytesCapacity= new uint[] {1,3,6,1,4,1,789,1,5,4,1,6,i}; ManagerSession sess = new ManagerSession(hostname,community); string dfFileSys, dfKBytesTotal, dfKBytesUsed, dfPercentKBytesCapacity = ""; { ManagerItem mi = new ManagerItem(sess,na_dfFileSys); dfFileSys = mi.Value.ToString(); Match m = Regex.Match(dfFileSys, @"/vol/(?<volume>\S+)/"); if(m.Success) dfFileSys = m.Groups[1].ToString(); } { ManagerItem mi = new ManagerItem(sess,na_dfKBytesTotal); dfKBytesTotal = mi.Value.ToString(); dfKBytesTotal = Convert.ToString(Convert.ToUInt64(dfKBytesTotal) / 1024); } { ManagerItem mi = new ManagerItem(sess,na_dfKBytesUsed); dfKBytesUsed = mi.Value.ToString(); dfKBytesUsed = Convert.ToString(Convert.ToUInt64(dfKBytesUsed) / 1024); } { ManagerItem mi = new ManagerItem(sess,na_dfPercentKBytesCapacity); dfPercentKBytesCapacity = mi.Value.ToString(); } Console.WriteLine("{0}!{1}!{2}!{3}!{4}", hostname, dfFileSys, dfKBytesTotal,dfKBytesUsed,dfPercentKBytesCapacity); } } catch ( Exception ex) { Console.WriteLine("error: {0}",ex.Message); } }
public string GetExecPath(ManagerSession session) { return(GetPath(session) + GetPackage(session).exec); }
public string GetPath(ManagerSession session) { return(session.bin_path + id + "/"); }
private static int getDisksStatus(string hostname, string community) { try { uint[] na_diskTotalCount = new uint[] {1,3,6,1,4,1,789,1,6,4,1,0}; uint[] na_diskActiveCount = new uint[] {1,3,6,1,4,1,789,1,6,4,2,0}; uint[] na_diskFailedCount = new uint[] {1,3,6,1,4,1,789,1,6,4,7,0}; uint[] na_diskSpareCount = new uint[] {1,3,6,1,4,1,789,1,6,4,8,0}; uint[] na_diskFailedMessage = new uint[] {1,3,6,1,4,1,789,1,6,4,10,0}; int diskTotalCount = 0; { ManagerSession sess = new ManagerSession(hostname,community); ManagerItem mi = new ManagerItem(sess,na_diskTotalCount); string value = mi.Value.ToString(); diskTotalCount = Convert.ToInt32(value); } int diskActiveCount = 0; { ManagerSession sess = new ManagerSession(hostname,community); ManagerItem mi = new ManagerItem(sess,na_diskActiveCount); string value = mi.Value.ToString(); diskActiveCount = Convert.ToInt32(value); } int diskFailedCount = 0; { ManagerSession sess = new ManagerSession(hostname,community); ManagerItem mi = new ManagerItem(sess,na_diskFailedCount); string value = mi.Value.ToString(); diskFailedCount = Convert.ToInt32(value); } int diskSpareCount = 0; { ManagerSession sess = new ManagerSession(hostname,community); ManagerItem mi = new ManagerItem(sess,na_diskSpareCount); string value = mi.Value.ToString(); diskSpareCount = Convert.ToInt32(value); } string diskFailedMessage = ""; { ManagerSession sess = new ManagerSession(hostname,community); ManagerItem mi = new ManagerItem(sess,na_diskFailedMessage); string value = mi.Value.ToString(); diskFailedMessage = Convert.ToString(value); } Console.WriteLine("{0},{1},{2},{3},{4},{5}", hostname, diskTotalCount,diskActiveCount,diskFailedCount, diskSpareCount,diskFailedMessage); return diskTotalCount; } catch ( Exception ex) { Console.WriteLine("error: {0}",ex.Message); return 0; } }
private static string getuptime(string hostname, string community) { try { ManagerSession sess = new ManagerSession(hostname,community); uint[] oid = new uint[] {1,3,6,1,2,1,1,3,0}; ManagerItem mi = new ManagerItem(sess,oid); string delim = "[]"; int ticks = Convert.ToInt32(mi.Value.ToString().Trim(delim.ToCharArray())); ticks /= 100; int days = ticks / (60*60*24); ticks -= days * (60*60*24); int hours = ticks / (60*60); ticks -= hours*(60*60); int mins = ticks/(60); ticks -= mins*60; int secs = ticks; if (days > 1) { //return (String.Format("{0} days, {1,2:00}:{2,2:00}:{3,2:00}", days,hours,mins,secs)); return (String.Format("{0} days, {1} hours, {2} mins, {3} secs", days,hours,mins,secs)); } else { //return (String.Format("{1} day, {1,2:00}:{2,2:00}:{3,2:00}", days,hours,mins,secs)) return (String.Format("{0} days, {1} hours, {2} mins, {3} secs", days,hours,mins,secs));; } } catch ( Exception ex) { return (String.Format("error: {0}",ex.Message)); } }
public string GetProjectPath(ManagerSession session) { return(GetGitPath(session) + project_path); }
public string GetGitPath(ManagerSession session) { return(session.build_path + name + "/"); }