Skip to contentSkip to conversation

Change in xm interface

PATCH Anthony Liguori 3 participants 4 messages Feb 17, 2006

lore
Share & tools
lore
#0 lore raw

This is a great patch, I just want to make sure everyone who has written a tool against xm that is perhaps screen scrapping the output of xm block-list or xm network-list that the interface has changed.

You will now have to use --long to get the same S-Expression output.

Perhaps this sort of changes should be announced on xen-announce in the future? Is there such a list?

Regards,

Anthony Liguori

# HG changeset patch
# User [email protected]
# Node ID 34f6a1efe52d8c5c722a2d423a0b26b469540a3a
# Parent aeeeedc6c9b754dc9d26b4bc12ab9d025578da6e
This patch displays the network-list/block-list/vtpm-list using the 'xm' command. It supports the '--long' option.

tools/python/xen/xm/main.py +125 -21
diff -r aeeeedc6c9b7 -r 34f6a1efe52d tools/python/xen/xm/main.py
@@ -90,18 +90,18 @@
                                     where <DevId> may either be the device ID
                                     or the device name as mounted in the guest"""
 
-block_list_help = "block-list <DomId>               List virtual block devices for a domain"
+block_list_help = "block-list <DomId> [--long]      List virtual block devices for a domain"
 network_attach_help = """network-attach  <DomID> [script=<script>] [ip=<ip>] [mac=<mac>]
                            [bridge=<bridge>] [backend=<backDomID>]
                                     Create a new virtual network device """
 network_detach_help = """network-detach  <DomId> <DevId>  Destroy a domain's virtual network
                                     device, where <DevId> is the device ID."""
 
-network_list_help = "network-list <DomId>             List virtual network interfaces for a domain"
+network_list_help = "network-list <DomId> [--long]    List virtual network interfaces for a domain"
 vnet_list_help = "vnet-list [-l|--long]            list vnets"
 vnet_create_help = "vnet-create <config>             create a vnet from a config file"
 vnet_delete_help = "vnet-delete <vnetid>             delete a vnet"
-vtpm_list_help = "vtpm-list <DomId>                list virtual TPM devices"
+vtpm_list_help = "vtpm-list <DomId> [--long]       list virtual TPM devices"
 
 short_command_list = [
     "console",
@@ -684,29 +684,133 @@
     from xen.xend.XendClient import server
     print server.xend_node_log()
 
+def parse_dev_info(info):
+    def get_info(n, t, d):
+        i = 0
+        while i < len(info):
+            if (info[i][0] == n):
+                return t(info[i][1])
+            i = i + 1
+        return t(d)
+    return {
+        #common
+        'backend-id' : get_info('backend-id',   int,   -1),
+        'handle'     : get_info('handle',       int,    0),
+        'state'      : get_info('state',        int,   -1),
+        'be-path'    : get_info('backend',      str,   '??'),
+        'event-ch'   : get_info('event-channel',int,   -1),
+        #network specific
+        'virtual-device' : get_info('virtual-device', str, '??'),
+        'tx-ring-ref': get_info('tx-ring-ref',  int,   -1),
+        'rx-ring-ref': get_info('rx-ring-ref',  int,   -1),
+        'mac'        : get_info('mac',          str,   '??'),
+        #block-device specific
+        'ring-ref'   : get_info('ring-ref',     int,   -1),
+        }
+
+def has_long_option(args):
+    use_long = 0
+    try:
+        (options, params) = getopt.gnu_getopt(args, 'l', ['long'])
+    except getopt.GetoptError, opterr:
+        err(opterr)
+        sys.exit(1)
+
+    for (k, v) in options:
+        if k in ['-l', '--long']:
+            use_long = 1
+    return (use_long, params)
+
 def xm_network_list(args):
-    arg_check(args, "network-list", 1)
-    dom = args[0]
-    from xen.xend.XendClient import server
-    for x in server.xend_domain_devices(dom, 'vif'):
-        sxp.show(x)
-        print
+    arg_check(args, "network-list", 1, 2)
+
+    (use_long, params) = has_long_option(args)
+
+    if len(params) == 0:
+        print 'No domain parameter given'
+        sys.exit(1)
+    dom = params[0]
+    from xen.xend.XendClient import server
+    if use_long:
+        devs = server.xend_domain_devices(dom, 'vif')
+        map(PrettyPrint.prettyprint, devs)
+    else:
+        hdr = 0
+        for x in server.xend_domain_devices(dom, 'vif'):
+            if hdr == 0:
+                print 'Idx BE     MAC Addr.     handle state evt-ch tx-/rx-ring-ref BE-path'
+                hdr = 1
+            ni = parse_dev_info(x[1])
+            ni['idx'] = int(x[0])
+            print ("%(idx)-3d "
+                   "%(backend-id)-3d"
+                   "%(mac)-17s    "
+                   "%(handle)-3d   "
+                   "%(state)-3d    "
+                   "%(event-ch)-3d   "
+                   "%(tx-ring-ref)-5d/%(rx-ring-ref)-5d   "
+                   "%(be-path)-30s  "
+                   % ni)
 
 def xm_block_list(args):
-    arg_check(args, "block-list", 1)
-    dom = args[0]
-    from xen.xend.XendClient import server
-    for x in server.xend_domain_devices(dom, 'vbd'):
-        sxp.show(x)
-        print
+    arg_check(args, "block-list", 1, 2)
+
+    (use_long, params) = has_long_option(args)
+
+    if len(params) == 0:
+        print 'No domain parameter given'
+        sys.exit(1)
+    dom = params[0]
+    from xen.xend.XendClient import server
+    if use_long:
+        devs = server.xend_domain_devices(dom, 'vbd')
+        map(PrettyPrint.prettyprint, devs)
+    else:
+        hdr = 0
+        for x in server.xend_domain_devices(dom, 'vbd'):
+            if hdr == 0:
+                print 'Vdev  BE handle state evt-ch ring-ref BE-path'
+                hdr = 1
+            ni = parse_dev_info(x[1])
+            ni['idx'] = int(x[0])
+            print ("%(idx)-3d    "
+                   "%(backend-id)-3d  "
+                   "%(handle)-3d   "
+                   "%(state)-3d    "
+                   "%(event-ch)-3d    "
+                   "%(ring-ref)-5d "
+                   "%(be-path)-30s  "
+                   % ni)
 
 def xm_vtpm_list(args):
-    arg_check(args, "vtpm-list", 1)
-    dom = args[0]
-    from xen.xend.XendClient import server
-    for x in server.xend_domain_devices(dom, 'vtpm'):
-        sxp.show(x)
-        print
+    arg_check(args, "vtpm-list", 1, 2)
+
+    (use_long, params) = has_long_option(args)
+
+    if len(params) == 0:
+        print 'No domain parameter given'
+        sys.exit(1)
+    dom = params[0]
+    from xen.xend.XendClient import server
+    if use_long:
+        devs = server.xend_domain_devices(dom, 'vtpm')
+        map(PrettyPrint.prettyprint, devs)
+    else:
+        hdr = 0
+        for x in server.xend_domain_devices(dom, 'vtpm'):
+            if hdr == 0:
+                print 'Idx  BE handle state evt-ch ring-ref BE-path'
+                hdr = 1
+            ni = parse_dev_info(x[1])
+            ni['idx'] = int(x[0])
+            print ("%(idx)-3d   "
+                   "%(backend-id)-3d  "
+                   "%(handle)-3d   "
+                   "%(state)-3d    "
+                   "%(event-ch)-3d    "
+                   "%(ring-ref)-5d "
+                   "%(be-path)-30s  "
+                   % ni)
 
 def xm_block_attach(args):
     arg_check(args, 'block-attach', 4, 5)

_______________________________________________
Xen-changelog mailing list
[email protected]
http://lists.xensource.com/xen-changelog

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 5 lines · Anthony Liguori

This is a great patch, I just want to make sure everyone who has written a tool against xm that is perhaps screen scrapping the output of xm block-list or xm network-list that the interface has changed.

You will now have to use --long to get the same S-Expression output.

Your concern is perfectly reasonable. On that note though, could I emphasise

a) Screen-scraping xm is a bad idea. There is an interface straight into xend that one can use for integration (the same interface that xm uses). This will avoid such hackery, and make it an awful lot easier to maintain backwards compatibility. xm is for humans to use, not tools.

b) There is no guarantee that any interface inside domain 0, be it to the tools, or even to Xen, are fixed. The only interfaces that are fixed at the moment are the interfaces used by guests. Everything else is subject to change at any time. Of course, it's in everyone's interests that these interfaces become fixed in the future, but there's plenty of work that has to go into them yet before we could claim that they are supportable in the long term.

Quoted 2 lines

Perhaps this sort of changes should be announced on xen-announce in the future? Is there such a list?

That list is xen-devel, for the moment. I'm not sure there's any value in having a separate list -- anyone who's developing products that sit on top of Xen _really_ needs to be reading xen-devel anyway -- the project simply isn't mature enough for you to get away without doing that.

Ewan.

#2 lore raw
Quoted 9 lines · Ewan Mellor

Your concern is perfectly reasonable. On that note though, could I emphasise

a) Screen-scraping xm is a bad idea. There is an interface straight into xend that one can use for integration (the same interface that xm uses). This will avoid such hackery, and make it an awful lot easier to maintain backwards compatibility. xm is for humans to use, not tools.

I agree with you completely and will take the time to point out that libvirt uses the S-Expression/HTTP interface so you can just use that :-)

Quoted 8 lines

b) There is no guarantee that any interface inside domain 0, be it to the tools, or even to Xen, are fixed. The only interfaces that are fixed at the moment are the interfaces used by guests. Everything else is subject to change at any time. Of course, it's in everyone's interests that these interfaces become fixed in the future, but there's plenty of work that has to go into them yet before we could claim that they are supportable in the long term.

Yup.

Quoted 6 lines

That list is xen-devel, for the moment. I'm not sure there's any value in having a separate list -- anyone who's developing products that sit on top of Xen _really_ needs to be reading xen-devel anyway -- the project simply isn't mature enough for you to get away without doing that.

Ok. Always good to reiterate this occasionally :-)

Regards,

Anthony Liguori

Quoted 3 lines

Ewan.

#3 lore raw
In reply to Ewan Mellor
Quoted 8 lines · Ewan Mellor
Quoted 1 line

Perhaps this sort of changes should be announced on xen-announce in the future? Is there such a list?

That list is xen-devel, for the moment. I'm not sure there's any value in having a separate list -- anyone who's developing products that sit on top of Xen _really_ needs to be reading xen-devel anyway -- the project simply isn't mature enough for you to get away without doing that.

Heavily seconded. Please don't fork mailing lists - it really isn't warranted, and tends to exaggerate the problem we're trying to solve (people not seeing the information they need because it's hidden somewhere)...

thanks,
Nivedita