Well when I try to use the create command I get this:

virsh # create /etc/libvirt/qemu/ubuntuTest.xml
error: Failed to create domain from /etc/libvirt/qemu/ubuntuTest.xml
error: unknown OS type hvm

and I'm using virt-install by using the below command:
self.runCommand("virt-install --hvm --name " + name + " --ram " + ram + " 
--file " + filename + " --file-size " + hardDriveSize + " --network bridge:br0 
--cdrom " + cdrom + " --accelerate --noautoconsole --vnc")

I'm not sure if there is some where everyone keep scripts they write but for 
now I'm putting them on my Wiki here:
They are not the best scripts but they are are written in python and it calls 
os.system(command) to run stuff on the command line.

http://software.digisoftinc.org/DigiSoftWiki/index.php/Python_Programming_Notes#Virtualization

It is all text based and requires the Linux.py class here:
http://software.digisoftinc.org/DigiSoftWiki/index.php/Python_Programming_Notes#Linux.py

To run these scripts:
1) switch to root
2) download both scripts
3) change Virtualizaiton class to executable
4) run script

Example
#> su -
<enter root password>
#> chmod +x Virtualization.py
#> ./Virtualization.py 

Let me know if you need any further info.







----- Original Message ----
From: Mark Foster <m...@foster.cc>
To: Dan Sheffner <theshef...@yahoo.com>
Cc: Matt Isaacs <matthew.isa...@gmail.com>; ubuntu-server@lists.ubuntu.com
Sent: Friday, May 8, 2009 5:09:03 PM
Subject: Re: KVM failover to another KVM server

I believe you do so the hypervisor knows about the domain.
You can use the 'create' command this. See virsh help create

Dan Sheffner wrote:
> Both machines have /etc/libvirt/qemu/ubuntuTest.xml present and I get the 
> same error. Do I have to load the xml in the vmserver06 machine?


-- I hate rascists.
Mark D. Foster <m...@foster.cc>  http://mark.foster.cc/ | http://conshell.net/


      
#!/usr/bin/python

# Created By Dan Sheffner
#This class will manage all virtualization options using virt-install, vmbuilder, virt-viewer, and virt-manager

#imported classes
import Linux
linux = Linux.Linux()

#pre defined imports
import  sys,  os, commands, shutil
from time import strftime

#import global variables
import globalVar

class Virtualization:
    
    def __init__(self):
        self.password1 = ""
        self.password2 = ""

    def runCommand(self, command):
        status = os.system(command)
        if status <> 0:
            print "A command failed to run! aborting install"
            print "The command that failed is: " + command
            sys.exit()
            
    def setPassword(self,error=""):
        linux.clearScreen()
        print error + "\n"
        print "Please enter a password you would like to use"
        print ""
        self.password1 = raw_input("Enter password: ")
                
        linux.clearScreen()
        print "Please enter your password again"
        print ""
        self.password2 = raw_input("Enter password again: ")
        
        if self.password1 <> self.password2:
            linux.clearScreen()
            self.setPassword("The password you entered do not match.  Please try again")
            
    def runCommandWarning(self, command):
        status = os.system(command)
        if status <> 0:
            print "A command failed to run! This shouldn't be a problem unless you know otherwise"
            print "The command that failed is: " + command
            
    def virtInstall(self):
        linux.clearScreen()
        print "virt-install menu"
        print "You will asked a serious of questions on what you want do."
        print ""
        print "Are you ready? y/n"
        userInput2 = (raw_input("Enter y/n: "))
        if userInput2 == "y":
            linux.clearScreen()
            print "What is the name of the virtual machine?"
            name = (raw_input("Enter Name: "))
                
            linux.clearScreen()
            print "How much RAM do you want to use in Megs?"
            ram = (raw_input("Enter size(Megs): "))
            
            linux.clearScreen()
            print "Enter the file name you want to use?"
            filename = (raw_input("Enter filename(ubunutTest.img): "))
                
            linux.clearScreen()
            print "Enter the size of the virtual machines hard drive in GB?"
            hardDriveSize = (raw_input("Enter size(GB): "))
                
            linux.clearScreen()
            print "Do you want the network bridged? y/n"
            bridgeNetwork = (raw_input("Enter y/n: "))
                
            linux.clearScreen()
            print "Enter the location of your cd-rom or ISO"
            cdrom = (raw_input("Enter path: "))
                
            if bridgeNetwork == 'y':                
                self.runCommand("virt-install --hvm --name " + name + " --ram " + ram + " --file " + filename + " --file-size " + hardDriveSize + " --network bridge:br0 --cdrom " + cdrom + " --accelerate --noautoconsole --vnc")
            else:
                self.runCommand("virt-install --hvm --name " + name + " --ram " + ram + " --file " + filename + " --file-size " + hardDriveSize + " --cdrom " + cdrom + " --accelerate --noautoconsole --vnc")
        else:
            sys.exit()
    
    def virshCommands(self):
        linux.clearScreen()
        print "virsh commands"
        print ""
        print "Running on Localhost"
        print "1) Connect to virsh console"
        print "2) List running machines"
        print "3) start machine"
        print ""
        print "Running on remote machine"
        print "4) Connect to virsh console on host"
        print "5) List running machines on host"
        print "6) start machine on host"
            
        userInput3 = int(raw_input("Enter Choice: "))
            
        if userInput3 == 1:
            self.runCommand("virsh -c qemu:///system")
        if userInput3 == 2:
            self.runCommand("virsh -c qemu:///system list")
        if userInput3 == 3:
            linux.clearScreen()
            print "Please enter the name of the machine you would like to start"
            print ""
            name = (raw_input("Enter Name: "))
            self.runCommand("virsh -c qemu:///system start " + name)
                
        if userInput3 == 4 or userInput3 == 5 or userInput3 == 6:
            linux.clearScreen()
            print "Please enter the host of the remote machine"
            print ""
            hostname = (raw_input("Enter Hostname: "))
                
        if userInput3 == 4:
            self.runCommand("virsh -c qemu+ssh://root@" + hostname + "/system")
        if userInput3 == 5:
            self.runCommand("virsh -c qemu+ssh://root@" + hostname + "/system list")
        if userInput3 == 6:
            linux.clearScreen()
            print "Please enter the name of the machine you would like to start on server " + hostname
            print ""
            name = (raw_input("Enter Name: "))
            self.runCommand("virsh -c qemu+ssh://root@" + hostname + "/system start " + name)
        
    def vmbuilder(self):
        linux.clearScreen()
        print "vm-builder commands"                
        print "You will asked a serious of questions on what you want do."
        print ""
        print "Are you ready? y/n"
        userInput2 = (raw_input("Enter y/n: "))
        if userInput2 == 'y':
            
            linux.clearScreen()
            print "Enter the name of the system you want to create"
            print ""
            hostname = (raw_input("Enter Name: "))
            
            linux.clearScreen()
            print "Enter the suite you would like to build"
            print ""
            print "1) 8.04 LTS Hardy 32 Bit"
            print "2) 8.10 Intrepid 32 Bit"
            print "3) 8.04 LTS Hardy 64 Bit"
            print "4) 8.10 Intrepid 64 Bit"
            print "5) 9.04 Jaunty 32 Bit"
            print "6) 9.04 Jauny 64 Bit"
            distro = int(raw_input("Enter Choice: "))
            
            linux.clearScreen()
            print "How much RAM is your machine going to have in Megs?"
            print ""
            ram = int(raw_input("Enter size: "))
            
            linux.clearScreen()
            print "How do you want the root parition in Megs?"
            print ""
            hardDriveSize = raw_input("Enter size: ")
            
            linux.clearScreen()
            print "Print do you have a local ubuntu mirror? y/n"
            print ""
            localMirror1 = raw_input("Enter y/n: ")
            
            if localMirror1 == 'y':
                linux.clearScreen() 
                print "Please enter the hostname of the ubuntu mirror"
                print ""
                localMirror2 = raw_input("Enter hostname: ")
                
            
            linux.clearScreen()
            print "Would you like to build this machine in the RAM? y/n"
            print ""
            buildInMem = raw_input("Enter y/n: ")
                
            linux.clearScreen()
            print "Please enter a username you would like to setup"
            print ""
            username = raw_input("Enter name: ")
            
            self.setPassword()
                       
            # Logic to build command
            # Logic for distro
            command = "vmbuilder kvm ubuntu --suite "
            if distro == 1:
                distro2 = "8.04 LTS Hardy 32 Bit"
                command = command + " hardy --flavour virtual --arch i386 -o --libvirt qemu:///system"
            if distro == 2:
                distro2 = "8.04 LTS Hardy 64 Bit"
                command = command + " hardy --flavour virtual --arch amd64 -o --libvirt qemu:///system"
            if distro == 3:
                distro2 = "8.10 Intrepid 32 Bit"
                command = command + " intrepid --flavour virtual --arch i386 -o --libvirt qemu:///system"
            if distro == 4:
                distro2 = "8.10 Intrepid 64 Bit"
                command = command + " intrepid --flavour virtual --arch amd64 -o --libvirt qemu:///system"
            if distro == 5:
                distro2 = "9.04 Jaunty 32 Bit"
                command = command + " jaunty --flavour virtual --arch i386 -o --libvirt qemu:///system"
            if distro == 6:
                distro2 = "9.04 Jaunty 64 Bit"
                command = command + " jaunty --flavour virtual --arch amd64 -o --libvirt qemu:///system"
                
            #logic for local mirror
            if localMirror1 == 'y':
                command = command + " --mirror http://"; +  localMirror2 + "/ubuntu"
                
            #hostname
            command = command + " --hostname " + hostname
            
            #logic for ram
            if buildInMem == 'y':
                command = command + " --tmpfs -"
                
            #logic for paritioning
            if linux.fileExists("/root/vmbuilder.partition"):
                linux.rotateFile("/root/", "vmbuilder.partition")
            
            fobj1 = open("/root/vmbuilder.partition","w")
            fobj1.write("root " + hardDriveSize + "\n")
            fobj1.write("swap " + str(ram * 2) + "\n")
            fobj1.close()
            
            #sets for the partion file
            command = command + " --part /root/vmbuilder.partition"
            
            #sets username and password
            command = command + " --user " + username + " --pass " + self.password1
            
            # sets the destination directory.
            
            command = command + " --dest /root/vmbuilder/" + hostname
            
            if  os.path.isdir('/root/vmbuilder/') == False:
                print "creating /root/vmbuilder/ directory"
                self.runCommand('mkdir /root/vmbuilder/')
            
            if os.path.isdir('/root/vmbuilder/' + hostname + "/"):
                print "The directory already exists for this vmserver! \n"
                print "Please delete this directory manually if you want to create another server with the same name \n"
                print "Exiting program"
                sys.exit()
            else:
                print "Creating directory /root/vmbuilder/" + hostname + "/\n"
                self.runCommand("mkdir /root/vmbuilder/" + hostname + "/\n")
                      
                linux.clearScreen()
                print "Does everything look ok? y/n"
                print ""
                print "Hostname: " + hostname 
                print "Distro: " + distro2  
                print "Ram: " + str(ram) 
                print "Hard Drive Size: " + hardDriveSize 
                if localMirror1 == 'y':
                    print "Ubuntu Mirror: " + localMirror2
                if buildInMem == "y":
                    print "Build Virtual Machine in RAM: Yes"
                else:
                    print "Build Virtual Machine in RAM: No"
                print "User Name: " + username 
                print "Password: " + self.password1
                print "Final Command is: " + command
                print "Are all the settings above correct? y/n"
                userInput6 = raw_input("Enter y/n: ")
                if userInput6 == 'y':
                  self.runCommand(command)
#                    #Below will append all extra packeges to the command line:
#                    #Generated by ubuntu-8.04.1 LTS support x86
#                    command = command + " --addpkg adduser --addpkg apparmor --addpkg apparmor-utils --addpkg apt --addpkg apt-utils \
#                    --addpkg aptitude --addpkg at --addpkg base-files --addpkg base-passwd --addpkg bash --addpkg bash-completion \
#                    --addpkg belocs-locales-bin --addpkg bind9-host --addpkg bsdmainutils --addpkg bsdutils --addpkg busybox-initramfs \
#                    --addpkg bzip2 --addpkg command-not-found --addpkg command-not-found-data --addpkg console-setup --addpkg console-terminus \
#                    --addpkg console-tools --addpkg coreutils --addpkg cpio --addpkg cpp --addpkg cpp-4.2 --addpkg cron --addpkg dash \
#                    --addpkg debconf --addpkg debconf-i18n --addpkg debianutils --addpkg dhcp3-client --addpkg dhcp3-common --addpkg diff \
#                    --addpkg dmidecode --addpkg dnsutils --addpkg dosfstools --addpkg dpkg --addpkg e2fslibs --addpkg e2fsprogs --addpkg ed \
#                    --addpkg eject --addpkg ethtool --addpkg fdutils --addpkg file --addpkg findutils --addpkg friendly-recovery --addpkg ftp \
#                    --addpkg fuse-utils --addpkg gcc-4.2-base --addpkg gettext-base --addpkg gnupg --addpkg gpgv --addpkg grep --addpkg groff-base \
#                    --addpkg grub --addpkg gzip --addpkg hdparm --addpkg hostname --addpkg ifupdown --addpkg info --addpkg initramfs-tools \
#                    --addpkg initscripts --addpkg inputattach --addpkg installation-report --addpkg iproute --addpkg iptables \
#                    --addpkg iputils-arping --addpkg iputils-ping --addpkg iputils-tracepath --addpkg klibc-utils --addpkg klogd \
#                    --addpkg laptop-detect --addpkg less --addpkg libacl1 --addpkg libatm1 --addpkg libattr1 --addpkg libbind9-30 \
#                    --addpkg libblkid1 --addpkg libbz2-1.0 --addpkg libc6 --addpkg libc6-i686 --addpkg libcap1 --addpkg libcomerr2 \
#                    --addpkg libconsole --addpkg libcurl3-gnutls --addpkg libcwidget3 --addpkg libdb4.6 --addpkg libdbus-1-3 \
#                    --addpkg libdevmapper1.02.1 --addpkg libdns32 --addpkg libedit2 --addpkg libelfg0 --addpkg libexpat1 \
#                    --addpkg libfribidi0 --addpkg libfuse2 --addpkg libgc1c2 --addpkg libgcc1 --addpkg libgcrypt11 --addpkg libgdbm3 \
#                    --addpkg libgnutls13 --addpkg libgpg-error0 --addpkg libgpmg1 --addpkg libhtml-parser-perl --addpkg libhtml-tagset-perl \
#                    --addpkg libhtml-tree-perl --addpkg libidn11 --addpkg libisc32 --addpkg libisccc30 --addpkg libisccfg30 \
#                    --addpkg libiw29 --addpkg libkeyutils1 --addpkg libklibc --addpkg libkrb53 --addpkg libldap-2.4-2 \
#                    --addpkg liblocale-gettext-perl --addpkg liblwres30 --addpkg liblzo2-2 --addpkg libmagic1 --addpkg libncurses5 \
#                    --addpkg libncursesw5 --addpkg libnewt0.52 --addpkg libntfs-3g23 --addpkg libopencdk10 --addpkg libpam-modules \
#                    --addpkg libpam-runtime --addpkg libpam0g --addpkg libparted1.7-1 --addpkg libpcap0.8 --addpkg libpopt0 --addpkg libreadline5 \
#                    --addpkg librpc-xml-perl --addpkg libsasl2-2 --addpkg libsasl2-modules --addpkg libselinux1 --addpkg libsepol1 \
#                    --addpkg libsigc++-2.0-0c2a --addpkg libslang2 --addpkg libsqlite3-0 --addpkg libss2 --addpkg libssl0.9.8 \
#                    --addpkg libstdc++6 --addpkg libsysfs2 --addpkg libtasn1-3 --addpkg libterm-readkey-perl --addpkg libtext-charwidth-perl \
#                    --addpkg libtext-iconv-perl --addpkg libtext-wrapi18n-perl --addpkg liburi-perl --addpkg libusb-0.1-4 --addpkg libuuid1 \
#                    --addpkg libvolume-id0 --addpkg libwrap0 --addpkg libwww-perl --addpkg libxml-parser-perl --addpkg linux-image-2.6.24-19-server \
#                    --addpkg linux-image-server --addpkg linux-server --addpkg linux-ubuntu-modules-2.6.24-19-server --addpkg locales \
#                    --addpkg login --addpkg logrotate --addpkg lsb-base --addpkg lsb-release --addpkg lshw --addpkg lsof --addpkg ltrace \
#                    --addpkg lzma --addpkg makedev --addpkg man-db --addpkg manpages --addpkg mawk --addpkg memtest86+ --addpkg mii-diag \
#                    --addpkg mime-support --addpkg mktemp --addpkg mlocate --addpkg module-init-tools --addpkg mount --addpkg mtr-tiny \
#                    --addpkg nano --addpkg ncurses-base --addpkg ncurses-bin --addpkg net-tools --addpkg netbase --addpkg netcat \
#                    --addpkg netcat-traditional --addpkg ntfs-3g --addpkg ntpdate --addpkg openssh-client --addpkg parted --addpkg passwd \
#                    --addpkg pciutils --addpkg pcmciautils --addpkg perl --addpkg perl-base --addpkg perl-modules --addpkg popularity-contest \
#                    --addpkg ppp --addpkg pppconfig --addpkg pppoeconf --addpkg procps --addpkg psmisc --addpkg python --addpkg python-apt \
#                    --addpkg python-central --addpkg python-gdbm --addpkg python-gnupginterface --addpkg python-minimal --addpkg python-support \
#                    --addpkg python2.5 --addpkg python2.5-minimal --addpkg readline-common --addpkg reiserfsprogs --addpkg rsync --addpkg sed \
#                    --addpkg startup-tasks --addpkg strace --addpkg sudo --addpkg sysklogd --addpkg system-services --addpkg sysv-rc \
#                    --addpkg sysvutils --addpkg tar --addpkg tasksel --addpkg tasksel-data --addpkg tcpd --addpkg tcpdump --addpkg telnet \
#                    --addpkg time --addpkg tzdata --addpkg ubuntu-keyring --addpkg ubuntu-minimal --addpkg ubuntu-standard --addpkg ucf \
#                    --addpkg udev --addpkg ufw --addpkg update-inetd --addpkg update-manager-core --addpkg upstart --addpkg upstart-compat-sysv \
#                    --addpkg upstart-logd --addpkg usbutils --addpkg util-linux --addpkg util-linux-locales --addpkg uuid-runtime \
#                    --addpkg vim-common --addpkg vim-tiny --addpkg w3m --addpkg wget --addpkg whiptail --addpkg wireless-tools \
#                    --addpkg wpasupplicant --addpkg xkb-data --addpkg zlib1g"
                    
                else:
                    sys.exit()
        else:
            sys.exit()    
    
    def virtViewer(self):
        linux.clearScreen()
        print "virt-viewer commands"
        print ""
        print "1) connect to virt machine on other host"
        print "2) connect to virt viewer on the localhost"
        
        userInput4 = int(raw_input("Enter Choice: "))
        
        if userInput4 == 1:
            linux.clearScreen()
            print "Please enter the hostname that is running your virtualization services"
            print ""
            hostname = raw_input("Enter hostname: ")
            
            linux.clearScreen()
            print "Please enter the name of the host you would like to connect to on" + hostname
            print ""
            systemConnect = raw_input("Enter name: ")
            
            self.runCommand("virt-viewer -c qemu+ssh://root@" + hostname + "/system " + systemConnect)
        if userInput4 == 2:
            linux.clearScreen()
            print "Please enter the name of the host you would like to connec to on localhost "
            print ""
            systemConnect = raw_input("Enter name: ")
            
            self.runCommand("virt-viewer -c qemu:///system " + systemConnect)
            
    def virtManager(self):
        linux.clearScreen()
        print "virt-manager commands"
        print ""
        print "1) connect to virt-manager machine on other host"
        print "2) connect to virt-manager on the localhost"
        
        userInput5 = int(raw_input("Enter Choice: "))
        
        if userInput5 == 1:
            linux.clearScreen()
            print "Please enter the hostname that is running your virtualization services"
            print ""
            hostname = raw_input("Enter hostname: ")
            self.runCommand("virt-manager -c qemu+ssh://root@" + hostname + "/system")
        
        if userInput5 == 2:
            self.runCommand("virt-manager -c qemu:///system")
            
    def menu(self):
        linux.clearScreen()
        print "Virtualization by Dan Sheffner"
        print "What would you like to do"
        print ""
        print "1) virt-install"
        print "2) virsh commands"
        print "3) vm-builder"
        print "4) virt-viewer"
        print "5) virt-manager"
        print "6) Check if processor supported by libvirt"
        print "7) Install all basic virtualization software"
        print "50) Quit"
        
        
        userInput = int(raw_input("Enter Choice: "))
        
        
        if userInput == 1:
            self.virtInstall()
                        
        if userInput == 2:
            self.virshCommands()
            
        if userInput == 3:
            self.vmbuilder()
            
        if userInput == 4:
            self.virtViewer()

        if userInput == 5:
            self.virtManager()
                
        if userInput == 6:
            linux.clearScreen()
            print "Your processor type will be displayed below if it works with virtualization."
            self.runCommand("egrep '(vmx|svm)' --color=always /proc/cpuinfo")
        
        if userInput == 7:
            linux.clearScreen()
            print "Installing all basic virtualization software"
            self.runCommand("apt-get --assume-yes install kvm libvirt-bin python-virtinst virt-manager virt-viewer ubuntu-vm-builder")

if __name__ == '__main__':
        virtualization = Virtualization()
        virtualization.menu()
        print "Virtualizatoin.py completed"
#!/usr/bin/python

# Created By Dan Sheffner
# Used to find basic linux commands
# this class should be generic and shouldn't be importing other users classes that are outside the scope of this program
# many time this file will have sym links to other projects for Linux compatibility across projects so project specific class/functions
# should not be in this program.

import os, sys, shutil, commands, datetime, time

class Linux:

    def runCommandWarning(self, command):
        status = os.system(command)
        self.status = ""
        if status <> 0:
            print "A command failed to run! This shouldn't be a problem unless you know otherwise!"
            print "The command that failed is: " + command

    def runCommand(self, command):
        status = os.system(command)
        if status <> 0:
            print "The command that failed is: " + command
            sys.exit()

    def runCommandSSHWarning(self, host, commmand, className, user='root'):
        status = os.system('ssh '+ user + " '" + command  + "'") 
        if status <> 0:
            print "A command failed to run! This shouldn't be a problem unless you know otherwise!"
            print "The command that failed is: " + command

    def runCommandSSH(self, host, command, sdout, sterr, user='root'):
        os.system("echo '" + user + "@" + host + " " + command + "'>>" + sdout)
        os.system("echo '" + user + "@" + host + " " + command + "'>>" + sterr)

        status = os.system('ssh '+ user + "@" + host + " '" + command  + "' 1>>" + sdout + " 2>>" + sterr) 
        if status <> 0:
            print "The command that failed is: " + command
            sys.exit()

        os.system('echo "" >>' + sdout)
        os.system('echo "" >>' + sterr)
        
    def runCommandSSHNoLogging(self, host, command, user='root'):
        status = os.system('ssh ' + user + "@" + host + " '" + command  + "'") 
        if status <> 0:
            print "A command failed to run!"
            print "The command that failed is: " + command
            sys.exit()

    def checkRoot(self):
        userId=os.getuid()
        if userId is not 0:
            print "You Aren't Root! Goodbye."
            sys.exit()

    def clearScreen(self):
        os.system('clear')

    def removeDirectory(self, directory):
        if os.path.exists(directory):
            #print "removed dir"
            shutil.rmtree(directory)
        else:
            print "dir does not exist"

    def createDirectory(self, directory):
        if os.path.exists(directory):
            print "Directory Already Exists! " + directory
            print "Goodbye. "
            sys.exit() 
        else:
            os.mkdir(directory)

    def copyFile(self, src, dest):
        if os.path.exists(dest):
            print "File already Exists! " + dest
            print "Goodbye."
            sys.exit()
        else:
            shutil.copy(src,dest)

    def expandJar(self, file, dest):
        os.chdir(dest)
        os.system("jar xf ./" + file)

    def runCommand(self, command):
        os.system(command)

    def procOnServer(self, server, proccess):
        #print number.strip()
        number = commands.getoutput("ssh " + server + " 'ps -elf | grep  ^" + proccess + " | wc --lines'")  	
        if number.strip() is '0':
            return 0
        else:
            return 1

    def procOnLocalhost(self, proccess):
        number = commands.getoutput("ps -elf | grep  ^" + proccess + " | wc --lines")
        if number.strip() is '0':
            return 0
        else:
            return 1

    def webSiteUp(self, file, link):
        number = os.system("wget " + link + " &> /dev/null")
        if number is 0:
            return 0
        else:
            return 1

        if os.path.exists(file):
            os.remove(file)

    def email(self, proccess, email):
        SENDMAIL = "/usr/sbin/sendmail" # sendmail location
        p = os.popen("%s -t" % SENDMAIL, "w")
        p.write("To: " + email + "\n")
        p.write("Subject: " + proccess + "\n")
        p.write("\n") # blank line separating headers from body
        p.write(proccess + "\n")
        sts = p.close()

    def getOutputSSH(self, server, command, user='root'):  
        #print ("ssh " + user + "@" + server + " '" + command + "'")
        self.output = commands.getoutput("ssh " + user + "@" + server + " '" + command + "'")
        return self.output
        #self.output = commands.getoutput("ssh " + server + " 'ps -elf | grep  ^" + proccess + " | wc --lines'")
    
    def getOutput(self, command):
        self.output = commands.getoutput(command)
        return self.output
    
    def getSoftware(self, fileName, fileLocation, downloadLocation):
        if not os.path.isdir(fileLocation):
            self.runCommand('mkdir ' + fileLocation)
        if not os.path.isfile(fileLocation + fileName):
            self.runCommand('cd ' + fileLocation + '; wget ' + downloadLocation)
            
    def checkIfLineExists(self, string, fileName):
        self.output = commands.getoutput('cat ' + fileName + " | grep '" + string + "' | wc -l")
        if int(self.output) == 0:
            return True
        else:
            return False
        
        

-- 
ubuntu-server mailing list
ubuntu-server@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-server
More info: https://wiki.ubuntu.com/ServerTeam

Reply via email to