bitkeeper revision 1.1108.7.1 (40fd3300BIfHRgHP5-DpQTLgUmNmEQ)
Merge http://xen.bkbits.net:8080/xeno-unstable.bk into gandalf.hpl.hp.com:/var/bk/xeno-unstable.bk
No files matched your search
@@ -41,6 +41,7 @@ setup(name = 'xen',
|
||||
'xen.util',
|
||||
'xen.xend',
|
||||
'xen.xend.server',
|
||||
'xen.xend.sv',
|
||||
'xen.xm',
|
||||
],
|
||||
ext_package = "xen.lowlevel",
|
||||
|
||||
@@ -100,7 +100,7 @@ def lookup_raw_partn(name):
|
||||
if line:
|
||||
return [ { 'device' : blkdev_name_to_number(p),
|
||||
'start_sector' : long(0),
|
||||
'nr_sectors' : long(line) * 2,
|
||||
'nr_sectors' : long(1L<<63),
|
||||
'type' : 'Disk' } ]
|
||||
else:
|
||||
# see if this is a hex device number
|
||||
|
||||
@@ -25,8 +25,8 @@
|
||||
# todo Support security settings etc. in the config file.
|
||||
# todo Support command-line args.
|
||||
|
||||
from twisted.web import server
|
||||
from twisted.web import resource
|
||||
from twisted.web import server, static
|
||||
from twisted.web import resource, script
|
||||
from twisted.internet import reactor
|
||||
|
||||
from xen.xend import XendRoot
|
||||
@@ -44,8 +44,12 @@ def create(port=None, interface=None, bridge=0):
|
||||
if bridge or xroot.rebooted:
|
||||
Vifctl.network('start')
|
||||
root = resource.Resource()
|
||||
sv = static.File( "/usr/lib/python2.2/site-packages/xen/xend/sv/" )
|
||||
sv.indexNames=['Main.rpy']
|
||||
sv.processors={'.rpy':script.ResourceScript}
|
||||
xend = SrvRoot()
|
||||
root.putChild('xend', xend)
|
||||
root.putChild('sv', sv)
|
||||
site = server.Site(root)
|
||||
reactor.listenTCP(port, site, interface=interface)
|
||||
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
from HTMLBase import HTMLBase
|
||||
from XendClientDeferred import server
|
||||
from xen.xend import PrettyPrint
|
||||
|
||||
from xen.xend.sv.util import *
|
||||
from xen.xend.sv.GenTabbed import *
|
||||
|
||||
class DomInfo( GenTabbed ):
|
||||
|
||||
def __init__( self, urlWriter, callback ):
|
||||
|
||||
self.dom = 0;
|
||||
|
||||
def tabUrlWriter( tab ):
|
||||
return urlWriter( "mod=info&dom=%s%s" % ( self.dom, tab ) )
|
||||
|
||||
GenTabbed.__init__( self, tabUrlWriter, [ 'General', 'SXP', 'Devices' ], [ DomGenTab, DomSXPTab, NullTab ], callback )
|
||||
|
||||
def write_BODY( self, request ):
|
||||
dom = request.args.get('dom')
|
||||
|
||||
if dom is None or len(dom) != 1:
|
||||
request.write( "<p>Please Select a Domain</p>" )
|
||||
return None
|
||||
else:
|
||||
self.dom = dom[0]
|
||||
|
||||
GenTabbed.write_BODY( self, request )
|
||||
|
||||
class DomGenTab( GeneralTab ):
|
||||
|
||||
def __init__( self ):
|
||||
|
||||
titles = {}
|
||||
|
||||
titles[ 'ID' ] = 'dom'
|
||||
titles[ 'Name' ] = 'name'
|
||||
titles[ 'CPU' ] = 'cpu'
|
||||
titles[ 'Memory' ] = ( 'mem', memoryFormatter )
|
||||
titles[ 'State' ] = ( 'state', stateFormatter )
|
||||
titles[ 'Total CPU' ] = ( 'cpu_time', smallTimeFormatter )
|
||||
titles[ 'Up Time' ] = ( 'up_time', bigTimeFormatter )
|
||||
|
||||
GeneralTab.__init__( self, "General Domain Info", {}, titles )
|
||||
|
||||
def write_BODY( self, request, callback ):
|
||||
dom = request.args.get('dom')
|
||||
|
||||
if dom is None or len(dom) != 1:
|
||||
request.write( "<p>Please Select a Domain</p>" )
|
||||
return None
|
||||
else:
|
||||
self.dom = dom[0]
|
||||
|
||||
deferred = getDomInfoHash( self.dom )
|
||||
deferred.addCallback( self.continue_BODY, request, callback )
|
||||
|
||||
def continue_BODY( self, dict, request, callback ):
|
||||
|
||||
self.dict = dict
|
||||
|
||||
GeneralTab.write_BODY( self, request, callback )
|
||||
|
||||
class DomSXPTab( PreTab ):
|
||||
|
||||
def __init__( self ):
|
||||
self.dom = 0
|
||||
PreTab.__init__( self, "" )
|
||||
|
||||
def fn( self, x, request ):
|
||||
class tmp:
|
||||
def __init__( self ):
|
||||
self.str = ""
|
||||
def write( self, str ):
|
||||
self.str = self.str + str
|
||||
temp = tmp()
|
||||
PrettyPrint.prettyprint( x, out=temp )
|
||||
self.source = temp.str
|
||||
return request
|
||||
|
||||
def fn2( self, request, callback ):
|
||||
PreTab.write_BODY( self, request, callback )
|
||||
|
||||
def write_BODY( self, request, callback ):
|
||||
dom = request.args.get('dom')
|
||||
|
||||
if dom is None or len(dom) != 1:
|
||||
request.write( "<p>Please Select a Domain</p>" )
|
||||
return None
|
||||
else:
|
||||
self.dom = dom[0]
|
||||
|
||||
deferred = server.xend_domain( self.dom )
|
||||
|
||||
deferred.addCallback( self.fn, request )
|
||||
deferred.addCallback( self.fn2, callback )
|
||||
def errback( x ):
|
||||
print ">err ", x
|
||||
deferred.addErrback( errback )
|
||||
@@ -0,0 +1,101 @@
|
||||
from twisted.web import resource
|
||||
from twisted.web.server import NOT_DONE_YET
|
||||
|
||||
from XendClientDeferred import server as XendServer
|
||||
from xen.xend import sxp
|
||||
|
||||
from xen.xend.sv.HTMLBase import HTMLBase
|
||||
from xen.xend.sv.util import *
|
||||
|
||||
from twisted.internet import reactor
|
||||
|
||||
class DomList( HTMLBase ):
|
||||
|
||||
isLeaf = True
|
||||
|
||||
def __init__( self, urlWriter, callback ):
|
||||
HTMLBase.__init__(self)
|
||||
self.urlWriter = urlWriter
|
||||
self.head = None
|
||||
self.long = None
|
||||
self.rendered_domains = {}
|
||||
self.domCount = 0
|
||||
self.callback = callback
|
||||
|
||||
def write_BODY( self, request, head=True, long=True ):
|
||||
deferred = XendServer.xend_domains()
|
||||
deferred.addCallback( self.get_domain_info, request )
|
||||
deferred.addErrback( self.errback )
|
||||
|
||||
self.head = head
|
||||
self.long = long
|
||||
|
||||
def errback( self, err ):
|
||||
print 'errback>', err
|
||||
|
||||
def get_domain_info( self, domains, request ):
|
||||
|
||||
self.domCount = len( domains )
|
||||
|
||||
for domain in domains:
|
||||
deferred = getDomInfoHash( domain )
|
||||
deferred.addCallback( self.render_domain, request )
|
||||
deferred.addErrback( self.errback )
|
||||
|
||||
def render_domain( self, domInfoHash, request ):
|
||||
|
||||
domStr = "<td class='domainInfo' align='center'>%(dom)-4d</td>\n" % domInfoHash
|
||||
|
||||
url = self.urlWriter( "mod=info&dom=%(dom)-4d" % domInfoHash )
|
||||
|
||||
domStr += "<td class='domainInfo' align='center'><a href='%s'>%s</a></td>\n" % ( url, domInfoHash['name'] )
|
||||
|
||||
if self.long:
|
||||
domStr += "<td class='domainInfo' align='center'>%(mem)7d</td>\n" % domInfoHash
|
||||
domStr += "<td class='domainInfo' align='center'>%(cpu)3d</td>\n" % domInfoHash
|
||||
|
||||
domStr += "<td class='domainInfo' align='center'>%(state)5s</td>\n" % domInfoHash
|
||||
|
||||
if self.long:
|
||||
domStr += "<td class='domainInfo' align='center'>%(cpu_time)7.1f</td>\n" % domInfoHash
|
||||
|
||||
self.rendered_domains[ domInfoHash[ 'dom' ] ] = domStr
|
||||
self.domCount -= 1
|
||||
|
||||
if self.domCount == 0:
|
||||
self.finish_write_BODY( request )
|
||||
|
||||
def finish_write_BODY( self, request ):
|
||||
|
||||
request.write( "\n<table style='border:0px solid white' cellspacing='0' cellpadding='0' border='0' width='100%'>\n" )
|
||||
|
||||
if self.head:
|
||||
request.write( "<tr class='domainInfoHead'>" )
|
||||
self.write_DOMAIN_HEAD( request, self.long )
|
||||
request.write( "</tr>" )
|
||||
|
||||
odd = True
|
||||
for domain in self.rendered_domains.values():
|
||||
if odd:
|
||||
request.write( "<tr class='domainInfoOdd'>\n" )
|
||||
odd = False
|
||||
else:
|
||||
request.write( "<tr class='domainInfoEven'>\n" )
|
||||
odd = True
|
||||
request.write( domain )
|
||||
request.write( "</tr>\n" )
|
||||
|
||||
request.write( "</table>\n" )
|
||||
|
||||
self.callback( request )
|
||||
|
||||
def write_DOMAIN_HEAD( self, request, long=True ):
|
||||
request.write( "<td class='domainInfoHead' align='center'>Domain</td>\n" )
|
||||
request.write( "<td class='domainInfoHead' align='center'>Name</td>\n" )
|
||||
if long:
|
||||
request.write( "<td class='domainInfoHead' align='center'>Memory / Mb</td>\n" )
|
||||
request.write( "<td class='domainInfoHead' align='center'>CPU</td>\n" )
|
||||
request.write( "<td class='domainInfoHead' align='center'>State</td>\n" )
|
||||
if long:
|
||||
request.write( "<td class='domainInfoHead' align='center'>CPU time / s</td>\n" )
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
import types
|
||||
|
||||
from HTMLBase import HTMLBase
|
||||
from TabView import TabView
|
||||
|
||||
class GenTabbed( HTMLBase ):
|
||||
|
||||
def __init__( self, urlWriter, tabStrings, tabObjects, callback ):
|
||||
HTMLBase.__init__(self)
|
||||
self.tab = 0;
|
||||
self.tabStrings = tabStrings
|
||||
self.tabObjects = tabObjects
|
||||
self.urlWriter = urlWriter
|
||||
self.callback = callback
|
||||
|
||||
def write_BODY( self, request, urlWriter = None ):
|
||||
tab = request.args.get('tab')
|
||||
|
||||
if tab is None or len( tab) != 1:
|
||||
self.tab = 0
|
||||
else:
|
||||
self.tab = int( tab[0] )
|
||||
|
||||
request.write( "<table style='' width='100%' border='0' cellspacing='0' cellpadding='0'>" )
|
||||
request.write( "<tr><td>" )
|
||||
|
||||
TabView( self.tab, self.tabStrings, self.urlWriter ).write_BODY( request )
|
||||
|
||||
request.write( "</td></tr><tr><td>" )
|
||||
|
||||
render_tab = self.tabObjects[ self.tab ]()
|
||||
|
||||
if render_tab is None:
|
||||
request.write( "<p>Bad Tab</p>" )
|
||||
self.finish_BODY( request )
|
||||
else:
|
||||
render_tab.write_BODY( request, self.finish_BODY )
|
||||
|
||||
def finish_BODY( self, request ):
|
||||
|
||||
request.write( "</td></tr></table>" )
|
||||
|
||||
self.callback( request )
|
||||
|
||||
class PreTab( HTMLBase ):
|
||||
|
||||
def __init__( self, source ):
|
||||
HTMLBase.__init__( self )
|
||||
self.source = source
|
||||
|
||||
def write_BODY( self, request, callback ):
|
||||
|
||||
request.write( "<div style='display: block; overflow: auto; border: 0px solid black; height: 400px; width: 540px; padding: 5px; z-index:0; align: center'><pre>" )
|
||||
|
||||
request.write( self.source )
|
||||
|
||||
request.write( "</pre></div>" )
|
||||
|
||||
callback( request )
|
||||
|
||||
class GeneralTab( HTMLBase ):
|
||||
|
||||
def __init__( self, title, dict, titles ):
|
||||
HTMLBase.__init__( self )
|
||||
self.title = title
|
||||
self.dict = dict
|
||||
self.titles = titles
|
||||
|
||||
def write_BODY( self, request, callback ):
|
||||
|
||||
request.write( "<p><u>%s</u></p>" % self.title )
|
||||
|
||||
request.write( "<table width='100%' cellspacing='0' cellpadding='0' border='0'>" )
|
||||
|
||||
def writeAttr( niceName, attr, formatter=None ):
|
||||
if type( attr ) is types.TupleType:
|
||||
( attr, formatter ) = attr
|
||||
|
||||
if attr in self.dict:
|
||||
if formatter:
|
||||
temp = formatter( self.dict[ attr ] )
|
||||
else:
|
||||
temp = str( self.dict[ attr ] )
|
||||
request.write( "<tr><td width='50%%'><p>%s:</p></td><td width='50%%'><p>%s</p></td></tr>" % ( niceName, temp ) )
|
||||
|
||||
for niceName, attr in self.titles.items():
|
||||
writeAttr( niceName, attr )
|
||||
|
||||
request.write( "</table>" )
|
||||
|
||||
callback( request )
|
||||
|
||||
class NullTab( HTMLBase ):
|
||||
|
||||
def __init__( self ):
|
||||
HTMLBase.__init__( self )
|
||||
self.title = "Null Tab"
|
||||
|
||||
def write_BODY( self, request, callback ):
|
||||
request.write( "<p>%s</p>" % self.title )
|
||||
callback( request )
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
from twisted.web import server, resource
|
||||
from twisted.internet import reactor
|
||||
|
||||
class HTMLBase( resource.Resource ):
|
||||
|
||||
isLeaf = True
|
||||
|
||||
def __init__( self ):
|
||||
resource.Resource.__init__(self)
|
||||
|
||||
def render_GET( self, request ):
|
||||
self.write_TOP( request )
|
||||
return self.write_BODY( request, self.finish_render_GET )
|
||||
|
||||
def finish_render_GET( self, request ):
|
||||
self.write_BOTTOM( request )
|
||||
request.finish()
|
||||
|
||||
def write_BODY( self, request ):
|
||||
request.write( "BODY" )
|
||||
|
||||
def write_TOP( self, request ):
|
||||
request.write( '<html><head><title>Xen</title><link rel="stylesheet" type="text/css" href="inc/style.css" />' )
|
||||
request.write( '</head><body>' )
|
||||
|
||||
def write_BOTTOM( self, request ):
|
||||
request.write( "</body></html>" )
|
||||
@@ -0,0 +1,81 @@
|
||||
from twisted.web import resource
|
||||
from twisted.web.server import NOT_DONE_YET
|
||||
|
||||
from xen.xend.XendClient import server as XendServer
|
||||
from xen.xend import sxp
|
||||
|
||||
from HTMLBase import HTMLBase
|
||||
|
||||
from xen.xend.sv import DomList, NodeInfo, DomInfo
|
||||
|
||||
class Main( HTMLBase ):
|
||||
|
||||
isLeaf = True
|
||||
|
||||
def __init__( self ):
|
||||
HTMLBase.__init__(self)
|
||||
|
||||
def render_POST( self, request ):
|
||||
return self.render_GET( request )
|
||||
|
||||
def mainUrlWriter( self, s ):
|
||||
return "Main.rpy?%s" % s
|
||||
|
||||
def write_BODY( self, request, callback ):
|
||||
|
||||
self.callback = callback
|
||||
|
||||
request.write( "\n<table style='border:0px solid black; background: url(images/orb_01.jpg) no-repeat' cellspacing='0' cellpadding='0' border='0' width='780px' height='536px'>\n" )
|
||||
request.write( "<tr>\n" )
|
||||
request.write( " <td width='15px'> </td>" )
|
||||
request.write( " <td width='175px' align='center' valign'center'>" )
|
||||
request.write( " <table cellspacing='0' cellpadding='0' border='0' width='100%' height='100%'>" )
|
||||
request.write( " <tr><td height='200px' align='center' valign='center'><a href='http://www.cl.cam.ac.uk/Research/SRG/netos/xen/'>" )
|
||||
request.write( " <img src='images/xen.png' width='150' height='75' border='0'/></a></td></tr>" )
|
||||
request.write( " <tr><td align='center' valign='top'>" )
|
||||
|
||||
request.write( " <p class='small'><a href='Main.rpy?mod=node'>Node details</a></p>" )
|
||||
request.write( " <p class='small'><a href='Main.rpy?mod=list'>Domains summary</a></p>" )
|
||||
|
||||
DomList.DomList( self.mainUrlWriter, self.continue_BODY ).write_BODY( request, True, False )
|
||||
|
||||
return NOT_DONE_YET
|
||||
|
||||
def continue_BODY( self, request ):
|
||||
request.write( " </td></tr>" )
|
||||
request.write( " </table>" )
|
||||
request.write( " " )
|
||||
request.write( " </td>\n" )
|
||||
request.write( " <td width='15px'> </td>" )
|
||||
request.write( " <td width='558px' align='left' valign='top'>" )
|
||||
request.write( " <table cellspacing='0' cellpadding='0' border='0' width='100%' height='100%'>" )
|
||||
request.write( " <tr><td height='20px'></td></tr>" )
|
||||
request.write( " <tr><td align='center' valign='top'>" )
|
||||
|
||||
mod = request.args.get('mod')
|
||||
|
||||
if mod is None or len(mod) != 1:
|
||||
request.write( '<p>Please select a module</p>' )
|
||||
self.finish_BODY( request )
|
||||
elif mod[0] == 'info':
|
||||
DomInfo.DomInfo( self.mainUrlWriter, self.finish_BODY ).write_BODY( request )
|
||||
elif mod[0] == 'list':
|
||||
DomList.DomList( self.mainUrlWriter, self.finish_BODY ).write_BODY( request )
|
||||
elif mod[0] == 'node':
|
||||
NodeInfo.NodeInfo( self.mainUrlWriter, self.finish_BODY ).write_BODY( request )
|
||||
else:
|
||||
request.write( '<p>Invalid module. Please select another</p>' )
|
||||
self.finish_BODY( request )
|
||||
|
||||
def finish_BODY( self, request ):
|
||||
|
||||
request.write( " </td></tr>" )
|
||||
request.write( " </table>" )
|
||||
request.write( " </td>\n" )
|
||||
request.write( " <td width='17px'> </td>" )
|
||||
request.write( "</tr>\n" )
|
||||
|
||||
request.write( "</table>\n" )
|
||||
|
||||
self.callback( request )
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
from xen.xend.sv.Main import *
|
||||
|
||||
resource = Main()
|
||||
@@ -0,0 +1,47 @@
|
||||
from xen.xend import XendDmesg
|
||||
from xen.xend import XendNode
|
||||
|
||||
from xen.xend.sv.util import *
|
||||
from xen.xend.sv.GenTabbed import *
|
||||
from xen.xend.sv.HTMLBase import HTMLBase
|
||||
|
||||
class NodeInfo( GenTabbed ):
|
||||
|
||||
def __init__( self, urlWriter, callback ):
|
||||
|
||||
def newUrlWriter( url ):
|
||||
return urlWriter( "mod=node%s" % url )
|
||||
|
||||
GenTabbed.__init__( self, newUrlWriter, [ 'General', 'Dmesg' ], [ NodeGeneralTab, NodeDmesgTab ], callback )
|
||||
|
||||
class NodeGeneralTab( GeneralTab ):
|
||||
|
||||
def __init__( self ):
|
||||
|
||||
nodeInfo = XendNode.instance().info()
|
||||
|
||||
dictNodeInfo = {}
|
||||
|
||||
for l in nodeInfo:
|
||||
dictNodeInfo[ l[0] ] = l[1]
|
||||
|
||||
dictTitles = {}
|
||||
dictTitles[ 'System' ] = 'system'
|
||||
dictTitles[ 'Hostname' ] = 'host'
|
||||
dictTitles[ 'Release' ] = 'release'
|
||||
dictTitles[ 'Version' ] ='version'
|
||||
dictTitles[ 'Machine' ] = 'machine'
|
||||
dictTitles[ 'Cores' ] = 'cores'
|
||||
dictTitles[ 'Hyperthreading' ] = ( 'hyperthreads_per_core', hyperthreadFormatter )
|
||||
dictTitles[ 'CPU Speed' ] = ( 'cpu_mhz', cpuFormatter )
|
||||
dictTitles[ 'Memory' ] = ( 'memory', memoryFormatter )
|
||||
dictTitles[ 'Free Memory' ] = ( 'free_memory', memoryFormatter )
|
||||
|
||||
GeneralTab.__init__( self, title="General Node Info", dict=dictNodeInfo, titles=dictTitles )
|
||||
|
||||
class NodeDmesgTab( PreTab ):
|
||||
|
||||
def __init__( self ):
|
||||
self.xd = XendDmesg.instance()
|
||||
PreTab.__init__( self, self.xd.info()[0] )
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
from xen.xend.sv.HTMLBase import HTMLBase
|
||||
|
||||
class TabView( HTMLBase ):
|
||||
|
||||
def __init__( self, tab, tabs, urlWriter ):
|
||||
HTMLBase.__init__(self)
|
||||
self.tab = tab # interger - tab id
|
||||
self.tabs = tabs
|
||||
self.urlWriter = urlWriter
|
||||
|
||||
def write_BODY( self, request ):
|
||||
request.write( "<table style='' border='0' cellspacing='0' cellpadding='0' align='center'>" )
|
||||
request.write( "<tr height='22'>" )
|
||||
|
||||
if self.tab == 0:
|
||||
image = "left-end-highlight.jpg"
|
||||
else:
|
||||
image = "left-end-no-highlight.jpg"
|
||||
|
||||
request.write( "<td height='22' width='14'><image src='images/%s' width='14' height='22'></td>" % image )
|
||||
|
||||
count = len( self.tabs )
|
||||
|
||||
for i in range( count ):
|
||||
|
||||
if i == self.tab:
|
||||
image = "middle-highlight.jpg"
|
||||
else:
|
||||
image = "middle-no-highlight.jpg"
|
||||
|
||||
request.write( "<td style='background: url(images/%s)'><p align='center'><a href='%s'>%s</a></p></td>" % ( image, self.urlWriter( "&tab=%s" % i ), self.tabs[ i ] ) )
|
||||
|
||||
if i < count-1:
|
||||
if i == self.tab:
|
||||
image = "seperator-left-highlight.jpg"
|
||||
elif self.tab == i+1:
|
||||
image = "seperator-right-highlight.jpg"
|
||||
else:
|
||||
image = "seperator.jpg"
|
||||
|
||||
request.write( "<td height='22' width='23'><image src='images/%s' width='23' height='22'></td>" % image )
|
||||
|
||||
if self.tab == count - 1:
|
||||
image = "right-end-highlight.jpg"
|
||||
else:
|
||||
image = "right-end-no-highlight.jpg"
|
||||
|
||||
request.write( "<td height='22' width='14'><image src='images/%s' width='14' height='22'></td>" % image )
|
||||
request.write( "</tr></table>" )
|
||||
@@ -0,0 +1,363 @@
|
||||
# Copyright (C) 2004 Tom Wilkie <tw275@cam.ac.uk>
|
||||
# Copyright (C) 2004 Mike Wray
|
||||
"""Client API for the HTTP interface on xend.
|
||||
Callable as a script - see main().
|
||||
|
||||
This API is the 'control-plane' for xend.
|
||||
The 'data-plane' is done separately. For example, consoles
|
||||
are accessed via sockets on xend, but the list of consoles
|
||||
is accessible via this API.
|
||||
|
||||
This one is similar to mikes, but works in an async fashion
|
||||
"""
|
||||
import sys
|
||||
import httplib
|
||||
import types
|
||||
from StringIO import StringIO
|
||||
import urlparse
|
||||
|
||||
from xen.xend.encode import *
|
||||
from xen.xend.sxp import *
|
||||
from xen.xend.PrettyPrint import prettyprint
|
||||
|
||||
from twisted.protocols.http import HTTPClient
|
||||
from twisted.internet.protocol import ClientCreator
|
||||
from twisted.internet.defer import Deferred
|
||||
from twisted.internet import reactor
|
||||
|
||||
DEBUG = 0
|
||||
|
||||
class XendRequest( HTTPClient ):
|
||||
def __init__(self, deferred, urls):
|
||||
self.urls = urls
|
||||
self.deferred = deferred
|
||||
|
||||
def connectionMade(self):
|
||||
self.sendCommand('GET', self.urls[2])
|
||||
self.sendHeader('Host', '%s:%d' % (self.urls[0], self.urls[1]) )
|
||||
self.endHeaders()
|
||||
|
||||
def handleResponse(self, data):
|
||||
self.deferred.callback( data )
|
||||
|
||||
def process_SXP( sexp ):
|
||||
pin = Parser()
|
||||
pin.input(sexp)
|
||||
pin.input_eof()
|
||||
return pin.get_val()
|
||||
|
||||
def xend_request(url, method, data=None):
|
||||
"""Make a request to xend.
|
||||
|
||||
url xend request url
|
||||
method http method: POST or GET
|
||||
data request argument data (dict)
|
||||
"""
|
||||
urlinfo = urlparse.urlparse(url)
|
||||
(uproto, ulocation, upath, uparam, uquery, ufrag) = urlinfo
|
||||
(hdr, args) = encode_data(data)
|
||||
if data and method == 'GET':
|
||||
upath += '?' + args
|
||||
args = None
|
||||
if method == "POST" and upath.endswith('/'):
|
||||
upath = upath[:-1]
|
||||
|
||||
deferred = Deferred()
|
||||
|
||||
clientCreator = ClientCreator( reactor, XendRequest, deferred, (ulocation, 8000, upath) )
|
||||
clientCreator.connectTCP( ulocation, 8000 )
|
||||
|
||||
deferred.addCallback( process_SXP )
|
||||
|
||||
return deferred
|
||||
|
||||
class XendError(RuntimeError):
|
||||
pass
|
||||
|
||||
class Foo(httplib.HTTPResponse):
|
||||
|
||||
def begin(self):
|
||||
fin = self.fp
|
||||
while(1):
|
||||
buf = fin.readline()
|
||||
print "***", buf
|
||||
if buf == '':
|
||||
print
|
||||
sys.exit()
|
||||
|
||||
|
||||
def sxprio(sxpr):
|
||||
"""Convert an sxpr to a string.
|
||||
"""
|
||||
io = StringIO()
|
||||
sxp.show(sxpr, out=io)
|
||||
print >> io
|
||||
io.seek(0)
|
||||
return io
|
||||
|
||||
def fileof(val):
|
||||
"""Converter for passing configs.
|
||||
Handles lists, files directly.
|
||||
Assumes a string is a file name and passes its contents.
|
||||
"""
|
||||
if isinstance(val, types.ListType):
|
||||
return sxprio(val)
|
||||
if isinstance(val, types.StringType):
|
||||
return file(val)
|
||||
if hasattr(val, 'readlines'):
|
||||
return val
|
||||
|
||||
# todo: need to sort of what urls/paths are using for objects.
|
||||
# e.g. for domains at the moment return '0'.
|
||||
# should probably return abs path w.r.t. server, e.g. /xend/domain/0.
|
||||
# As an arg, assume abs path is obj uri, otherwise just id.
|
||||
|
||||
# Function to convert to full url: Xend.uri(path), e.g.
|
||||
# maps /xend/domain/0 to http://wray-m-3.hpl.hp.com:8000/xend/domain/0
|
||||
# And should accept urls for ids?
|
||||
|
||||
def urljoin(location, root, prefix='', rest=''):
|
||||
prefix = str(prefix)
|
||||
rest = str(rest)
|
||||
base = 'http://' + location + root + prefix
|
||||
url = urlparse.urljoin(base, rest)
|
||||
return url
|
||||
|
||||
def nodeurl(location, root, id=''):
|
||||
return urljoin(location, root, 'node/', id)
|
||||
|
||||
def domainurl(location, root, id=''):
|
||||
return urljoin(location, root, 'domain/', id)
|
||||
|
||||
def consoleurl(location, root, id=''):
|
||||
return urljoin(location, root, 'console/', id)
|
||||
|
||||
def deviceurl(location, root, id=''):
|
||||
return urljoin(location, root, 'device/', id)
|
||||
|
||||
def vneturl(location, root, id=''):
|
||||
return urljoin(location, root, 'vnet/', id)
|
||||
|
||||
def eventurl(location, root, id=''):
|
||||
return urljoin(location, root, 'event/', id)
|
||||
|
||||
def xend_get(url, args=None):
|
||||
"""Make a xend request using GET.
|
||||
Requests using GET are 'safe' and may be repeated without
|
||||
nasty side-effects.
|
||||
"""
|
||||
return xend_request(url, "GET", args)
|
||||
|
||||
def xend_call(url, data):
|
||||
"""Make xend request using POST.
|
||||
Requests using POST potentially cause side-effects and should
|
||||
not be repeated unless it really is wanted to do the side
|
||||
effect again.
|
||||
"""
|
||||
return xend_request(url, "POST", data)
|
||||
|
||||
class Xend:
|
||||
|
||||
"""Default location of the xend server."""
|
||||
SRV_DEFAULT = "localhost"
|
||||
|
||||
"""Default path to the xend root on the server."""
|
||||
ROOT_DEFAULT = "/xend/"
|
||||
|
||||
def __init__(self, srv=None, root=None):
|
||||
self.bind(srv, root)
|
||||
|
||||
def bind(self, srv=None, root=None):
|
||||
"""Bind to a given server.
|
||||
|
||||
srv server location (host:port)
|
||||
root server xend root path
|
||||
"""
|
||||
if srv is None: srv = self.SRV_DEFAULT
|
||||
if root is None: root = self.ROOT_DEFAULT
|
||||
if not root.endswith('/'): root += '/'
|
||||
self.location = srv
|
||||
self.root = root
|
||||
|
||||
def nodeurl(self, id=''):
|
||||
return nodeurl(self.location, self.root, id)
|
||||
|
||||
def domainurl(self, id=''):
|
||||
return domainurl(self.location, self.root, id)
|
||||
|
||||
def consoleurl(self, id=''):
|
||||
return consoleurl(self.location, self.root, id)
|
||||
|
||||
def deviceurl(self, id=''):
|
||||
return deviceurl(self.location, self.root, id)
|
||||
|
||||
def vneturl(self, id=''):
|
||||
return vneturl(self.location, self.root, id)
|
||||
|
||||
def eventurl(self, id=''):
|
||||
return eventurl(self.location, self.root, id)
|
||||
|
||||
def xend(self):
|
||||
return xend_get(urljoin(self.location, self.root))
|
||||
|
||||
def xend_node(self):
|
||||
return xend_get(self.nodeurl())
|
||||
|
||||
def xend_node_cpu_rrobin_slice_set(self, slice):
|
||||
return xend_call(self.nodeurl(),
|
||||
{'op' : 'cpu_rrobin_slice_set',
|
||||
'slice' : slice })
|
||||
|
||||
def xend_node_cpu_bvt_slice_set(self, ctx_allow):
|
||||
return xend_call(self.nodeurl(),
|
||||
{'op' : 'cpu_bvt_slice_set',
|
||||
'ctx_allow' : ctx_allow })
|
||||
|
||||
def xend_node_cpu_fbvt_slice_set(self, ctx_allow):
|
||||
return xend_call(self.nodeurl(),
|
||||
{'op' : 'cpu_fbvt_slice_set',
|
||||
'ctx_allow' : ctx_allow })
|
||||
|
||||
def xend_domains(self):
|
||||
return xend_get(self.domainurl())
|
||||
|
||||
def xend_domain_create(self, conf):
|
||||
return xend_call(self.domainurl(),
|
||||
{'op' : 'create',
|
||||
'config' : fileof(conf) })
|
||||
|
||||
def xend_domain(self, id):
|
||||
return xend_get(self.domainurl(id))
|
||||
|
||||
def xend_domain_unpause(self, id):
|
||||
return xend_call(self.domainurl(id),
|
||||
{'op' : 'unpause'})
|
||||
|
||||
def xend_domain_pause(self, id):
|
||||
return xend_call(self.domainurl(id),
|
||||
{'op' : 'pause'})
|
||||
|
||||
def xend_domain_shutdown(self, id, reason):
|
||||
return xend_call(self.domainurl(id),
|
||||
{'op' : 'shutdown',
|
||||
'reason' : reason })
|
||||
|
||||
def xend_domain_destroy(self, id):
|
||||
return xend_call(self.domainurl(id),
|
||||
{'op' : 'destroy'})
|
||||
|
||||
def xend_domain_save(self, id, filename):
|
||||
return xend_call(self.domainurl(id),
|
||||
{'op' : 'save',
|
||||
'file' : filename})
|
||||
|
||||
def xend_domain_restore(self, id, filename):
|
||||
return xend_call(self.domainurl(id),
|
||||
{'op' : 'restore',
|
||||
'file' : filename })
|
||||
|
||||
def xend_domain_migrate(self, id, dst):
|
||||
return xend_call(self.domainurl(id),
|
||||
{'op' : 'migrate',
|
||||
'destination': dst})
|
||||
|
||||
def xend_domain_pincpu(self, id, cpu):
|
||||
return xend_call(self.domainurl(id),
|
||||
{'op' : 'pincpu',
|
||||
'cpu' : cpu})
|
||||
|
||||
def xend_domain_cpu_bvt_set(self, id, mcuadv, warp, warpl, warpu):
|
||||
return xend_call(self.domainurl(id),
|
||||
{'op' : 'cpu_bvt_set',
|
||||
'mcuadv' : mcuadv,
|
||||
'warp' : warp,
|
||||
'warpl' : warpl,
|
||||
'warpu' : warpu })
|
||||
|
||||
def xend_domain_cpu_fbvt_set(self, id, mcuadv, warp, warpl, warpu):
|
||||
return xend_call(self.domainurl(id),
|
||||
{'op' : 'cpu_fbvt_set',
|
||||
'mcuadv' : mcuadv,
|
||||
'warp' : warp,
|
||||
'warpl' : warpl,
|
||||
'warpu' : warpu })
|
||||
|
||||
|
||||
def xend_domain_cpu_atropos_set(self, id, period, slice, latency, xtratime):
|
||||
return xend_call(self.domainurl(id),
|
||||
{'op' : 'cpu_atropos_set',
|
||||
'period' : period,
|
||||
'slice' : slice,
|
||||
'latency' : latency,
|
||||
'xtratime': xtratime })
|
||||
|
||||
def xend_domain_vifs(self, id):
|
||||
return xend_get(self.domainurl(id),
|
||||
{ 'op' : 'vifs' })
|
||||
|
||||
def xend_domain_vif_ip_add(self, id, vif, ipaddr):
|
||||
return xend_call(self.domainurl(id),
|
||||
{'op' : 'vif_ip_add',
|
||||
'vif' : vif,
|
||||
'ip' : ipaddr })
|
||||
|
||||
def xend_domain_vbds(self, id):
|
||||
return xend_get(self.domainurl(id),
|
||||
{'op' : 'vbds'})
|
||||
|
||||
def xend_domain_vbd(self, id, vbd):
|
||||
return xend_get(self.domainurl(id),
|
||||
{'op' : 'vbd',
|
||||
'vbd' : vbd})
|
||||
|
||||
def xend_consoles(self):
|
||||
return xend_get(self.consoleurl())
|
||||
|
||||
def xend_console(self, id):
|
||||
return xend_get(self.consoleurl(id))
|
||||
|
||||
def xend_vnets(self):
|
||||
return xend_get(self.vneturl())
|
||||
|
||||
def xend_vnet_create(self, conf):
|
||||
return xend_call(self.vneturl(),
|
||||
{'op': 'create', 'config': fileof(conf) })
|
||||
|
||||
def xend_vnet(self, id):
|
||||
return xend_get(self.vneturl(id))
|
||||
|
||||
def xend_vnet_delete(self, id):
|
||||
return xend_call(self.vneturl(id),
|
||||
{'op': 'delete'})
|
||||
|
||||
def xend_event_inject(self, sxpr):
|
||||
val = xend_call(self.eventurl(),
|
||||
{'op': 'inject', 'event': fileof(sxpr) })
|
||||
|
||||
def main(argv):
|
||||
"""Call an API function:
|
||||
|
||||
python XendClient.py fn args...
|
||||
|
||||
The leading 'xend_' on the function can be omitted.
|
||||
Example:
|
||||
|
||||
> python XendClient.py domains
|
||||
(domain 0 8)
|
||||
> python XendClient.py domain 0
|
||||
(domain (id 0) (name Domain-0) (memory 128))
|
||||
"""
|
||||
server = Xend()
|
||||
fn = argv[1]
|
||||
if not fn.startswith('xend'):
|
||||
fn = 'xend_' + fn
|
||||
args = argv[2:]
|
||||
deferred = getattr(server, fn)(*args)
|
||||
deferred.addCallback( prettyprint )
|
||||
reactor.run()
|
||||
print
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv)
|
||||
else:
|
||||
server = Xend()
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
|
After Width: | Height: | Size: 66 KiB |
|
After Width: | Height: | Size: 37 KiB |
|
After Width: | Height: | Size: 535 B |
|
After Width: | Height: | Size: 440 B |
|
After Width: | Height: | Size: 376 B |
|
After Width: | Height: | Size: 344 B |
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 507 B |
|
After Width: | Height: | Size: 535 B |
|
After Width: | Height: | Size: 447 B |
|
After Width: | Height: | Size: 552 B |
|
After Width: | Height: | Size: 560 B |
|
After Width: | Height: | Size: 443 B |
|
After Width: | Height: | Size: 10 KiB |
@@ -0,0 +1,30 @@
|
||||
|
||||
P {font-family: verdana, arial; font-size: 12px; color: black}
|
||||
.small {font-size: 10px}
|
||||
|
||||
TD.domainInfo {font-family: verdana, arial; font-size: 10px; color: black}
|
||||
TD.domainInfoHead {font-family: verdana, arial; font-size: 10px; color: white; font-face: bold}
|
||||
|
||||
TD.domainInfoHead {background-color: black}
|
||||
TR.domainInfoOdd {background-color: white}
|
||||
TR.domainInfoEven {background-color: lightgrey}
|
||||
|
||||
body {
|
||||
width: 670px;
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
background-color: #fff;
|
||||
background-image: url(../images/orb_02.jpg);
|
||||
background-repeat: repeat-y;
|
||||
background-position: left top;
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
font-weight: bold;
|
||||
color: #333333;
|
||||
letter-spacing: 0px;
|
||||
scrollbar-base-color: #333333;
|
||||
scrollbar-track-color: #666666;
|
||||
scrollbar-face-color: #fff;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
from xen.xend.sv.XendClientDeferred import server
|
||||
from xen.xend import sxp
|
||||
|
||||
def getDomInfoHash( domain ):
|
||||
deferred = server.xend_domain( int( domain ) )
|
||||
deferred.addCallback( procDomInfo, domain )
|
||||
return deferred
|
||||
|
||||
def procDomInfo( domInfo, domain ):
|
||||
d = {}
|
||||
d['dom'] = int( domain )
|
||||
d['name'] = sxp.child_value( domInfo, 'name' )
|
||||
d['mem'] = int( sxp.child_value( domInfo, 'memory' ) )
|
||||
d['cpu'] = int( sxp.child_value( domInfo, 'cpu' ) )
|
||||
d['state'] = sxp.child_value( domInfo, 'state' )
|
||||
d['cpu_time'] = float( sxp.child_value( domInfo, 'cpu_time' ) )
|
||||
if( sxp.child_value( domInfo, 'up_time' ) ):
|
||||
d['up_time'] = float( sxp.child_value( domInfo, 'up_time' ) )
|
||||
if( sxp.child_value( domInfo, 'start_time' ) ):
|
||||
d['start_time'] = float( sxp.child_value( domInfo, 'start_time' ) )
|
||||
return d
|
||||
|
||||
def bigTimeFormatter( time ):
|
||||
weeks = time // 604800
|
||||
remainder = time % 604800
|
||||
days = remainder // 86400
|
||||
|
||||
remainder = remainder % 86400
|
||||
|
||||
hms = smallTimeFormatter( remainder )
|
||||
|
||||
return "%d weeks, %d days, %s" % ( weeks, days, hms )
|
||||
|
||||
def smallTimeFormatter( time ):
|
||||
hours = time // 3600
|
||||
remainder = time % 3600
|
||||
mins = remainder // 60
|
||||
secs = time % 60
|
||||
return "%02d:%02d:%04.1f (hh:mm:ss.s)" % ( hours, mins, secs )
|
||||
|
||||
def stateFormatter( state ):
|
||||
states = [ 'Running', 'Blocked', 'Paused', 'Shutdown', 'Crashed' ]
|
||||
|
||||
for i in range( len( state ) ):
|
||||
if state[i] != "-":
|
||||
return states[ i ] + " (%s)" % state
|
||||
|
||||
return state
|
||||
|
||||
def memoryFormatter( mem ):
|
||||
return "%7dMb" % mem
|
||||
|
||||
def cpuFormatter( mhz ):
|
||||
if mhz > 1000:
|
||||
ghz = float( mhz ) / 1000.0
|
||||
return "%4.2fGHz" % ghz
|
||||
else:
|
||||
return "%4dMHz" % mhz
|
||||
|
||||
def hyperthreadFormatter( threads ):
|
||||
if int( threads ) > 1:
|
||||
return "Yes (%d)" % threads
|
||||
else:
|
||||
return "No"
|
||||
@@ -105,8 +105,23 @@ class Xm:
|
||||
|
||||
def getprog(self, name, val=None):
|
||||
"""Get a sub-program.
|
||||
name Name of the sub-program (or optionally, an unambiguous
|
||||
prefix of its name)
|
||||
val Default return value if no (unique) match is found
|
||||
"""
|
||||
return self.progs.get(name, val)
|
||||
|
||||
match = None
|
||||
for progname in self.progs.keys():
|
||||
if progname == name:
|
||||
match = progname
|
||||
break
|
||||
if progname.startswith(name):
|
||||
if not match:
|
||||
match = progname
|
||||
else:
|
||||
return val # name is ambiguous - bail out
|
||||
|
||||
return self.progs.get(match, val)
|
||||
|
||||
def proglist(self):
|
||||
"""Get a list of sub-programs, ordered by group.
|
||||
|
||||