kvmtools/kvm/action.py
author Jens Kasten <jens@kasten-edv.de>
Sun, 08 Apr 2012 00:24:35 +0200
changeset 113 d180b27d13a9
parent 112 0ca5084026ff
child 115 75c299d0bf5a
permissions -rw-r--r--
add 'status all --full' options, update README
53
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
     1
#
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
     2
# Modulde which contain the methodes which can call from commandline
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
     3
#
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
     4
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
     5
"""
105
938d696a213e restructe:
Jens Kasten <jens@kasten-edv.de>
parents: 77
diff changeset
     6
(c) 2011-2012 Jens Kasten <jens@kasten-edv.de>
53
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
     7
"""
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
     8
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
     9
import os
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    10
import sys
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    11
from subprocess import Popen, PIPE
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    12
from time import sleep
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    13
105
938d696a213e restructe:
Jens Kasten <jens@kasten-edv.de>
parents: 77
diff changeset
    14
from kvmtools.kvm.domain import Domain
53
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    15
55
1d4c061d1502 update and fixes for new structur
Jens Kasten <jens@kasten-edv.de>
parents: 54
diff changeset
    16
1d4c061d1502 update and fixes for new structur
Jens Kasten <jens@kasten-edv.de>
parents: 54
diff changeset
    17
class Action(Domain):
105
938d696a213e restructe:
Jens Kasten <jens@kasten-edv.de>
parents: 77
diff changeset
    18
53
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    19
    def __init__(self):
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    20
        Domain.__init__(self)
113
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
    21
        self.kvm_status_full = False
53
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    22
55
1d4c061d1502 update and fixes for new structur
Jens Kasten <jens@kasten-edv.de>
parents: 54
diff changeset
    23
    def kvm_error(self, error_message):
1d4c061d1502 update and fixes for new structur
Jens Kasten <jens@kasten-edv.de>
parents: 54
diff changeset
    24
        """Append a error message to error list."""
1d4c061d1502 update and fixes for new structur
Jens Kasten <jens@kasten-edv.de>
parents: 54
diff changeset
    25
        self.kvm_errors.append(error_message)
53
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    26
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    27
    def available_actions(self):
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    28
        """Return all methods which start with kvm_ and end with _action."""
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    29
        actions = []
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    30
        for action in dir(self):
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    31
            if action.startswith("kvm_") and action.endswith("_action"):
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    32
                methode = action.replace("kvm_", "").replace("_action", "")
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    33
                actions.append(methode)
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    34
        return actions
105
938d696a213e restructe:
Jens Kasten <jens@kasten-edv.de>
parents: 77
diff changeset
    35
53
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    36
    def kvm_show_action(self):
112
0ca5084026ff update README.txt
Jens Kasten <jens@kasten-edv.de>
parents: 105
diff changeset
    37
        """Show the qemu-kvm command as string."""
0ca5084026ff update README.txt
Jens Kasten <jens@kasten-edv.de>
parents: 105
diff changeset
    38
        doc = "teste a show"
0ca5084026ff update README.txt
Jens Kasten <jens@kasten-edv.de>
parents: 105
diff changeset
    39
        print "default show"
0ca5084026ff update README.txt
Jens Kasten <jens@kasten-edv.de>
parents: 105
diff changeset
    40
        #print self.command[1]
53
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    41
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    42
    def kvm_modify_action(self):
112
0ca5084026ff update README.txt
Jens Kasten <jens@kasten-edv.de>
parents: 105
diff changeset
    43
        """Modify a qemu-kvm domain configuration file."""
53
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    44
        self.modify()
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    45
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    46
    def kvm_create_action(self):
112
0ca5084026ff update README.txt
Jens Kasten <jens@kasten-edv.de>
parents: 105
diff changeset
    47
        """Create a basic qemu-kvm domain configuration file."""
53
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    48
        if os.path.isfile(self.kvm_domain_file):
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    49
            self.modify()
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    50
        else:
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    51
            self.create()
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    52
77
b8fe98927e41 uncomment migration method, no use at the moment
Jens Kasten <jens@kasten-edv.de>
parents: 61
diff changeset
    53
    #def kvm_migrate_action(self, command_monitor):
b8fe98927e41 uncomment migration method, no use at the moment
Jens Kasten <jens@kasten-edv.de>
parents: 61
diff changeset
    54
    #    self.kvm_monitor_action(command_monitor)
53
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    55
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    56
    def kvm_monitor_action(self, command_monitor):
112
0ca5084026ff update README.txt
Jens Kasten <jens@kasten-edv.de>
parents: 105
diff changeset
    57
        """Monitor a qemu-kvm domain."""
54
17b08e781dc6 update and fixes befor merging branch
Jens Kasten <jens@kasten-edv.de>
parents: 53
diff changeset
    58
        if not self.is_running():
53
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    59
            print ("Guest is not running.")
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    60
            return
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    61
        self.monitor_send(command_monitor)
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    62
        data = self.monitor_recieve()
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    63
        data = "\n".join([i for i in data])
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    64
        print data
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    65
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    66
    def kvm_boot_action(self):
112
0ca5084026ff update README.txt
Jens Kasten <jens@kasten-edv.de>
parents: 105
diff changeset
    67
        """Boot a qemu-kvm domain."""
54
17b08e781dc6 update and fixes befor merging branch
Jens Kasten <jens@kasten-edv.de>
parents: 53
diff changeset
    68
        if self.is_running():
53
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    69
            print ("Guest already running.")
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    70
            return True
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    71
        env = os.environ.copy()
54
17b08e781dc6 update and fixes befor merging branch
Jens Kasten <jens@kasten-edv.de>
parents: 53
diff changeset
    72
        # add the  to the enviroment
53
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    73
        if len(self.bridge) > 0:
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    74
            for key, value in self.bridge.iteritems():
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    75
                env[key] = value
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    76
        try:
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    77
            result = Popen(self.command[0], env=env, stdin=PIPE, stdout=PIPE)
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    78
            result.wait()
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    79
            return (True, "")
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    80
        except OSError, error_msg:
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    81
            return (False, error_msg)
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    82
        except IOError, error_msg:
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    83
            return (False, error_msg)
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    84
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    85
    def kvm_reboot_action(self):
112
0ca5084026ff update README.txt
Jens Kasten <jens@kasten-edv.de>
parents: 105
diff changeset
    86
        """Reboot a qemu-kvm domain."""
54
17b08e781dc6 update and fixes befor merging branch
Jens Kasten <jens@kasten-edv.de>
parents: 53
diff changeset
    87
        if not self.is_running():
53
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    88
            print ("Guest is not running.")
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    89
            return False
54
17b08e781dc6 update and fixes befor merging branch
Jens Kasten <jens@kasten-edv.de>
parents: 53
diff changeset
    90
        if not self.monitor_send(self.qemu_monitor["reboot"]):
53
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    91
            print ("Could not send signal reboot to guest.")
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    92
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    93
    def kvm_shutdown_action(self):
112
0ca5084026ff update README.txt
Jens Kasten <jens@kasten-edv.de>
parents: 105
diff changeset
    94
        """Shutdown a qemu-kvm domain.
53
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    95
        Its work for windows and linux guests, 
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    96
        but not on linux when the Xserver is looked.
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    97
        """
54
17b08e781dc6 update and fixes befor merging branch
Jens Kasten <jens@kasten-edv.de>
parents: 53
diff changeset
    98
        if not self.is_running():
53
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
    99
            print ("Guest is not running.")
60
70e7bfc80074 fix: missing return in kvmtools/kvm/action.py shutdown()
Jens Kasten <jens@kasten-edv.de>
parents: 55
diff changeset
   100
            return
53
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   101
        flag = 0
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   102
        if self.monitor_send(self.qemu_monitor["shutdown"]):
77
b8fe98927e41 uncomment migration method, no use at the moment
Jens Kasten <jens@kasten-edv.de>
parents: 61
diff changeset
   103
            # set a time  out to wait, that the shutdown dialog appears
b8fe98927e41 uncomment migration method, no use at the moment
Jens Kasten <jens@kasten-edv.de>
parents: 61
diff changeset
   104
            sleep(1.5)
53
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   105
            self.monitor_send(self.qemu_monitor["enter"])
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   106
            print ("Shutdown ...")
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   107
            while True:
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   108
                # some fancy ticker
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   109
                if flag == 0:
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   110
                    sign = "\\" 
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   111
                    flag = 1
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   112
                elif flag == 1:    
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   113
                    sign = "|"
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   114
                    flag = 2
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   115
                elif flag == 2:
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   116
                    sign = "/"
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   117
                    flag = 3
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   118
                elif flag == 3:
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   119
                    sign = "-"
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   120
                    flag = 0
54
17b08e781dc6 update and fixes befor merging branch
Jens Kasten <jens@kasten-edv.de>
parents: 53
diff changeset
   121
                if not self.is_running():
53
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   122
                    sys.stdout.write("Done.         \n")
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   123
                    sys.stdout.flush()
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   124
                    sys.exit(0) 
54
17b08e781dc6 update and fixes befor merging branch
Jens Kasten <jens@kasten-edv.de>
parents: 53
diff changeset
   125
                else:
17b08e781dc6 update and fixes befor merging branch
Jens Kasten <jens@kasten-edv.de>
parents: 53
diff changeset
   126
                    sys.stdout.write("waiting ... %s\r" % sign)
17b08e781dc6 update and fixes befor merging branch
Jens Kasten <jens@kasten-edv.de>
parents: 53
diff changeset
   127
                    sys.stdout.flush()
17b08e781dc6 update and fixes befor merging branch
Jens Kasten <jens@kasten-edv.de>
parents: 53
diff changeset
   128
                    sleep(0.05)
55
1d4c061d1502 update and fixes for new structur
Jens Kasten <jens@kasten-edv.de>
parents: 54
diff changeset
   129
        else:
1d4c061d1502 update and fixes for new structur
Jens Kasten <jens@kasten-edv.de>
parents: 54
diff changeset
   130
            print ("Could not send signal shutdown.")
53
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   131
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   132
    def kvm_kill_action(self):
112
0ca5084026ff update README.txt
Jens Kasten <jens@kasten-edv.de>
parents: 105
diff changeset
   133
        """Kill a qemu-kvm domain.
53
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   134
        Dangerous option, its simply like pull the power cable out.
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   135
        """
54
17b08e781dc6 update and fixes befor merging branch
Jens Kasten <jens@kasten-edv.de>
parents: 53
diff changeset
   136
        if not self.is_running():
53
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   137
            print ("Guest is not running.")
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   138
            return False
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   139
        try:    
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   140
            os.kill(self.kvm_pid, 9)
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   141
            sleep(0.8)
54
17b08e781dc6 update and fixes befor merging branch
Jens Kasten <jens@kasten-edv.de>
parents: 53
diff changeset
   142
            self.is_running()
53
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   143
            sys.exit(0)
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   144
        except OSError, error_msg:
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   145
            print error_msg
54
17b08e781dc6 update and fixes befor merging branch
Jens Kasten <jens@kasten-edv.de>
parents: 53
diff changeset
   146
            self.is_running()
53
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   147
            sys.exit(1)
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   148
113
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   149
    def _status_all(self):
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   150
        """Show status information form all running qemu-kvm domains."""
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   151
        domains = {}
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   152
        # list all files in run dir and get pidfile socketfile and domain name
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   153
        for i in os.listdir(self.kvm_run_dir):
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   154
            domain_name = i.rsplit(".", 1)[0]
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   155
            if not domain_name in domains:
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   156
                domains[domain_name] = {}
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   157
            if i.endswith(".pid"):
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   158
                domains[domain_name]["pidfile"] = os.path.join(self.kvm_run_dir, i)
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   159
            if i.endswith(".socket"):
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   160
                domains[domain_name]["socketfile"] = os.path.join(self.kvm_run_dir, i)
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   161
        # iter over the domains and set the necessary values on the fly
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   162
        counter = len(domains)
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   163
        for domain in domains.iterkeys():
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   164
            self.kvm_pidfile = domains[domain]["pidfile"]
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   165
            self.kvm_socketfile = domains[domain]["socketfile"]
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   166
            self.kvm_domain_name = domain
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   167
            self.monitor_open()
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   168
            self._get_uuid()
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   169
            self._get_status()
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   170
            self._get_process_info()
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   171
            print ("Domain name: %s :: Process name: %s" % \
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   172
                (domain, self.kvm_process_name))
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   173
            print ("Domain uuid: %s" % self.kvm_process_uuid)
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   174
            print ("%s :: Process state: %s" % \
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   175
                (self.kvm_process_status, self.kvm_process_state))
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   176
            if self.kvm_status_full:
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   177
                self._get_vnc()
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   178
                print "UID: %s" % self.kvm_process_uid
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   179
                print "GID: %s" % self.kvm_process_gid
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   180
                print "Groups: %s" % self.kvm_process_groups
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   181
                print "PID: %s :: PPID: %s" % \
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   182
                    (self.kvm_process_pid, self.kvm_process_ppid)
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   183
                print ("VNC information")
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   184
                print self.kvm_process_vnc
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   185
            self.monitor_close()
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   186
            # show only line for seperation if more than one domains
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   187
            if counter > 1:
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   188
                print "-" * 80
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   189
            counter -= 1
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   190
53
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   191
    def kvm_status_action(self):
112
0ca5084026ff update README.txt
Jens Kasten <jens@kasten-edv.de>
parents: 105
diff changeset
   192
        """Show information about qemu-kvm domain(s)."""
113
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   193
        if self.kvm_domain_name == "all":
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   194
            self._status_all()
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   195
            return True
54
17b08e781dc6 update and fixes befor merging branch
Jens Kasten <jens@kasten-edv.de>
parents: 53
diff changeset
   196
        if not self.is_running():
53
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   197
            print ("Guest is not running.")
9eb8be6341f3 new structur for file and class layout
Jens Kasten <jens@kasten-edv.de>
parents:
diff changeset
   198
            return False
54
17b08e781dc6 update and fixes befor merging branch
Jens Kasten <jens@kasten-edv.de>
parents: 53
diff changeset
   199
        self.get_process_information()
113
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   200
        print ("Domain name: %s :: Process name: %s" % \
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   201
            (self.kvm_domain_name, self.kvm_process_name))
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   202
        print ("Domain uuid: %s" % self.kvm_process_uuid)
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   203
        print ("%s :: Process state: %s" % \
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   204
            (self.kvm_process_status, self.kvm_process_state))
54
17b08e781dc6 update and fixes befor merging branch
Jens Kasten <jens@kasten-edv.de>
parents: 53
diff changeset
   205
        print "UID: %s" % self.kvm_process_uid
17b08e781dc6 update and fixes befor merging branch
Jens Kasten <jens@kasten-edv.de>
parents: 53
diff changeset
   206
        print "GID: %s" % self.kvm_process_gid
17b08e781dc6 update and fixes befor merging branch
Jens Kasten <jens@kasten-edv.de>
parents: 53
diff changeset
   207
        print "Groups: %s" % self.kvm_process_groups
113
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   208
        print "PID: %s :: PPID: %s" % \
d180b27d13a9 add 'status all --full' options, update README
Jens Kasten <jens@kasten-edv.de>
parents: 112
diff changeset
   209
            (self.kvm_process_pid, self.kvm_process_ppid)
61
abba9906ca66 updates and fixes
Jens Kasten <jens@kasten-edv.de>
parents: 60
diff changeset
   210
        print ("VNC information")
abba9906ca66 updates and fixes
Jens Kasten <jens@kasten-edv.de>
parents: 60
diff changeset
   211
        print self.kvm_process_vnc