New xm uptime command.

From Alex Brett <alex.brett@xensource.com>

Signed-off-by: Ewan Mellor <ewan@xensource.com>
This commit is contained in:
emellor@leeni.uk.xensource.com committed 2006-08-12 12:25:42 +01:00
1 parent 4db258f902
commit 7857edbe76
2 files changed
+62

No files matched your search

+59
View File
@@ -31,6 +31,7 @@ import warnings
warnings.filterwarnings('ignore', category=FutureWarning)
import xmlrpclib
import traceback
import datetime
import xen.xend.XendProtocol
@@ -70,6 +71,7 @@ save_help = "save <DomId> <File> Save domain state (and config)
shutdown_help ="shutdown <DomId> [-w][-a][-R|-H] Shutdown a domain"
top_help = "top Monitor system and domains in real-time"
unpause_help = "unpause <DomId> Unpause a paused domain"
uptime_help = "uptime [-s|--short] [DomId, ...] List uptime for domains"
help_spacer = """
"""
@@ -149,6 +151,7 @@ short_command_list = [
"shutdown",
"top",
"unpause",
"uptime",
"vcpu-set",
]
@@ -172,6 +175,7 @@ domain_commands = [
"sysrq",
"top",
"unpause",
"uptime",
"vcpu-list",
"vcpu-pin",
"vcpu-set",
@@ -412,6 +416,7 @@ def parse_doms_info(info):
'vcpus' : get_info('online_vcpus', int, 0),
'state' : get_info('state', str, '??'),
'cpu_time' : get_info('cpu_time', float, 0),
'up_time' : get_info('up_time', float, -1),
'seclabel' : security.get_security_printlabel(info),
}
@@ -818,6 +823,59 @@ def xm_console(args):
domid = int(sxp.child_value(info, 'domid', '-1'))
console.execConsole(domid)
def xm_uptime(args):
short_mode = 0
try:
(options, params) = getopt.gnu_getopt(args, 's', ['short'])
except getopt.GetoptError, opterr:
err(opterr)
sys.exit(1)
for (k, v) in options:
if k in ['-s', '--short']:
short_mode = 1
doms = getDomains(params)
if short_mode == 0:
print 'Name ID Uptime'
for dom in doms:
d = parse_doms_info(dom)
if d['dom'] > 0:
uptime = int(round(d['up_time']))
else:
f=open('/proc/uptime', 'r')
upfile = f.read()
uptime = int(round(float(upfile.split(' ')[0])))
f.close()
days = int(uptime / 86400)
uptime -= (days * 86400)
hours = int(uptime / 3600)
uptime -= (hours * 3600)
minutes = int(uptime / 60)
uptime -= (minutes * 60)
seconds = uptime
upstring = ""
if days > 0:
upstring += str(days) + " day"
if days > 1:
upstring += "s"
upstring += ", "
upstring += '%(hours)2d:%(minutes)02d' % vars()
if short_mode:
now = datetime.datetime.now()
upstring = now.strftime(" %H:%M:%S") + " up " + upstring
upstring += ", " + d['name'] + " (" + str(d['dom']) + ")"
else:
upstring += ':%(seconds)02d' % vars()
upstring = ("%(name)-32s %(dom)3d " % d) + upstring
print upstring
def xm_top(args):
arg_check(args, "top", 0)
@@ -1117,6 +1175,7 @@ commands = {
"save": xm_save,
"reboot": xm_reboot,
"shutdown": xm_shutdown,
"uptime": xm_uptime,
"list": xm_list,
# memory commands
"mem-max": xm_mem_max,
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.