Exemplo n.º 1
0
        public string GetVMXMLString(SSH ssh, string vmName)
        {
            string sshCommand = "virsh dumpxml \"" + vmName + "\"";

            mySB.AppendLine(sshCommand);
            return(ssh.ExecuteSSHCommand(sshCommand));
        }
Exemplo n.º 2
0
        public List <string> GetDirNames(SSH ssh, string dirPath)
        {
            List <string> returnList = new List <string>();

            dirPath = dirPath.Replace(" ", "\\ ");
            string sshCommand = "ls -d " + dirPath + "*";

            if (appendToSB == true)
            {
                mySB.AppendLine(sshCommand);
            }
            string sshOutput = ssh.ExecuteSSHCommand(sshCommand);

            if (sshOutput.Length > 0)
            {
                var backupDirs = sshOutput.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
                foreach (var backupDir in backupDirs)
                {
                    if (backupDir.StartsWith("/"))
                    {
                        var dirSplit = backupDir.Split(new[] { "/" }, StringSplitOptions.None);
                        returnList.Add(dirSplit.Last().Trim(new Char[] { ' ', '\r', '\n' }));
                    }
                }
            }

            return(returnList);
        }
Exemplo n.º 3
0
        public void Rsync(SSH ssh, string source, string dest)
        {
            string sshCommand = "rsync -a " + "'" + source + "'" + " " + "'" + dest + "'";

            mySB.AppendLine(sshCommand);
            ssh.ExecuteSSHCommand(sshCommand);
        }
Exemplo n.º 4
0
        //
        // This method will create a VM if it does not exist. If it exists then it will
        // overwrite the VM's XML config.
        //
        public void ImportVMXML(SSH ssh, string vmName, string dirPath)
        {
            string sshCommand = "virsh define " + "'" + dirPath + vmName + ".xml" + "'";

            mySB.AppendLine(sshCommand);
            ssh.ExecuteSSHCommand(sshCommand);
        }
Exemplo n.º 5
0
        public void DumpVMXMLToFile(SSH ssh, string vmName, string dirPath)
        {
            string sshCommand = "virsh dumpxml \"" + vmName + "\"" + " > " + "'" + dirPath + vmName + ".xml" + "'";

            mySB.AppendLine(sshCommand);
            ssh.ExecuteSSHCommand(sshCommand);
        }
Exemplo n.º 6
0
        public void MakeVMServerDirectory(SSH ssh, string dirPath)
        {
            string sshCommand = "mkdir -p " + "'" + dirPath + "'";

            mySB.AppendLine(sshCommand);
            ssh.ExecuteSSHCommand(sshCommand);
        }
Exemplo n.º 7
0
        public string SetVMDesc(SSH ssh, string vmName, string vmDesc)
        {
            string vmDescOutput01, vmDescOutput02;

            string sshCommand = "virsh desc '" + vmName + "' --config --live --new-desc '" + vmDesc + "'";

            vmDescOutput01 = ssh.ExecuteSSHCommand(sshCommand);

            sshCommand     = "virsh desc '" + vmName + "' --current --new-desc '" + vmDesc + "'";
            vmDescOutput02 = ssh.ExecuteSSHCommand(sshCommand);

            return(vmDescOutput01 + "\n" + vmDescOutput02);
        }
Exemplo n.º 8
0
        public string SetVMTitle(SSH ssh, string vmName, string vmTitle)
        {
            string vmTitleOutput01, vmTitleOutput02;

            string sshCommand = "virsh desc '" + vmName + "' --config --live --title '" + vmTitle + "'";

            vmTitleOutput01 = ssh.ExecuteSSHCommand(sshCommand);

            sshCommand      = "virsh desc '" + vmName + "' --current --title '" + vmTitle + "'";
            vmTitleOutput02 = ssh.ExecuteSSHCommand(sshCommand);

            return(vmTitleOutput01 + "\n" + vmTitleOutput02);
        }
Exemplo n.º 9
0
        public string GetVMServerDate(SSH ssh)
        {
            string date;

            string sshCommand = "date +%s";

            mySB.AppendLine(sshCommand);
            date = ssh.ExecuteSSHCommand(sshCommand);
            date = date.ToString().Replace("\r\n", "");
            date = date.ToString().Replace("\r", "");
            date = date.ToString().Replace("\n", "");

            return(date);
        }
Exemplo n.º 10
0
        public string GetVMState(SSH ssh, string vmName)
        {
            string vmState = null;

            var sshOutput = ssh.ExecuteSSHCommand("virsh dominfo \"" + vmName + "\"");

            string[] vmInfoArray = sshOutput.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
            foreach (string temp in vmInfoArray)
            {
                if (temp.StartsWith("State:"))
                {
                    vmState = temp.Substring(16);
                }
            }

            return(vmState);
        }
Exemplo n.º 11
0
        public XmlDocument GetVMXML(SSH ssh, string vmName)
        {
            XmlDocument xmlDoc = new XmlDocument();

            var xmlString = GetVMXMLString(ssh, vmName);

            xmlString = xmlString.Trim(new Char[] { ' ', '\r', '\n' });

            if (xmlString.Length > 0)
            {
                xmlDoc.LoadXml(xmlString);
            }
            else
            {
                xmlDoc = null;
            }

            return(xmlDoc);
        }
Exemplo n.º 12
0
        private string GetNodeInnerText(SSH ssh, string vmName, string xpath)
        {
            XmlDocument xmlDoc = null;

            xmlDoc = GetVMXML(ssh, vmName);
            if (xmlDoc != null)
            {
                XmlNode node = xmlDoc.SelectSingleNode(xpath);
                if (node != null)
                {
                    return(node.InnerText);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 13
0
        public string GetVMDomInfo(SSH ssh, string vmName)
        {
            string sshCommand = "virsh dominfo \"" + vmName + "\"";

            return(ssh.ExecuteSSHCommand(sshCommand));
        }
Exemplo n.º 14
0
 public string GetVMDesc(SSH ssh, string vmName)
 {
     return(GetNodeInnerText(ssh, vmName, "/domain/description"));
 }
Exemplo n.º 15
0
 public string GetVMTitle(SSH ssh, string vmName)
 {
     return(GetNodeInnerText(ssh, vmName, "/domain/title"));
 }
Exemplo n.º 16
0
 public string GetVMUUID(SSH ssh, string vmName)
 {
     return(GetNodeInnerText(ssh, vmName, "/domain/uuid"));
 }