ia64/xen-unstable

changeset 14956:a9b9847d97bb

Add network-del and network-show commands to xm

signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
author Tom Wilkie <tom.wilkie@gmail.com>
date Thu Apr 26 15:40:35 2007 +0100 (2007-04-26)
parents 16e38247dee8
children aeb1931eab36
files tools/python/xen/xm/main.py
line diff
     1.1 --- a/tools/python/xen/xm/main.py	Thu Apr 26 15:39:30 2007 +0100
     1.2 +++ b/tools/python/xen/xm/main.py	Thu Apr 26 15:40:35 2007 +0100
     1.3 @@ -2233,7 +2233,7 @@ def xm_vnet_delete(args):
     1.4  
     1.5  def xm_network_new(args):
     1.6      xenapi_only()
     1.7 -    arg_check(args, "xm_network_new", 1)
     1.8 +    arg_check(args, "network-new", 1)
     1.9      network = args[0]
    1.10  
    1.11      record = {
    1.12 @@ -2245,7 +2245,71 @@ def xm_network_new(args):
    1.13          }
    1.14      
    1.15      server.xenapi.network.create(record)
    1.16 +    
    1.17 +def xm_network_del(args):
    1.18 +    xenapi_only()
    1.19 +    arg_check(args, "network-del", 1)
    1.20 +    network = args[0]
    1.21  
    1.22 +    networks = dict([(record['name_label'], record['uuid'])
    1.23 +                     for record in
    1.24 +                     server.xenapi.network.get_all_records()])
    1.25 +
    1.26 +    if network not in networks.keys():
    1.27 +        raise ValueError("'%s' is not a valid network name" % network)
    1.28 +    
    1.29 +    server.xenapi.network.destroy(networks[network])
    1.30 +
    1.31 +def uuid_dict_trans(records):
    1.32 +    return dict([(record['uuid'], record)
    1.33 +                 for record in records])
    1.34 +
    1.35 +def xm_network_show(args):
    1.36 +    xenapi_only()
    1.37 +    arg_check(args, "network-show", 0)
    1.38 +
    1.39 +    networks = server.xenapi.network.get_all_records()
    1.40 +    pifs     = uuid_dict_trans(
    1.41 +        server.xenapi.PIF.get_all_records())
    1.42 +    vifs     = uuid_dict_trans(
    1.43 +        server.xenapi.VIF.get_all_records())
    1.44 +
    1.45 +    print '%-20s %-40s %-10s' % \
    1.46 +          ('Name', 'VIFs', 'PIFs')
    1.47 +    
    1.48 +    format2 = "%(name_label)-20s %(vif)-40s %(pif)-10s"
    1.49 +
    1.50 +    for network in networks:
    1.51 +        for i in range(max(len(network['PIFs']),
    1.52 +                           len(network['VIFs']), 1)):
    1.53 +            if i < len(network['PIFs']):
    1.54 +                pif_uuid = network['PIFs'][i]
    1.55 +            else:
    1.56 +                pif_uuid = None
    1.57 +                
    1.58 +            if i < len(network['VIFs']):
    1.59 +                vif_uuid = network['VIFs'][i]
    1.60 +            else:
    1.61 +                vif_uuid = None
    1.62 +                
    1.63 +            pif = pifs.get(pif_uuid, {'device':''}) 
    1.64 +            vif = vifs.get(vif_uuid, None)
    1.65 +
    1.66 +            if vif:
    1.67 +                dom_name = server.xenapi.VM.get_name_label(vif['VM'])
    1.68 +                vif = "%s.%s" % (dom_name, vif['device'])
    1.69 +            else:
    1.70 +                vif = '' 
    1.71 +
    1.72 +            if i == 0:
    1.73 +                r = {'name_label':network['name_label'],
    1.74 +                     'vif':vif, 'pif':pif['device']}
    1.75 +            else:
    1.76 +                r = {'name_label':'','vif':vif,'pif':pif['device']}
    1.77 +
    1.78 +            print format2 % r
    1.79 +
    1.80 +            
    1.81  commands = {
    1.82      "shell": xm_shell,
    1.83      "event-monitor": xm_event_monitor,
    1.84 @@ -2301,6 +2365,8 @@ commands = {
    1.85      "network-list": xm_network_list,
    1.86      # network (as in XenAPI)
    1.87      "network-new": xm_network_new,
    1.88 +    "network-del": xm_network_del,
    1.89 +    "network-show": xm_network_show,
    1.90      # vnet
    1.91      "vnet-list": xm_vnet_list,
    1.92      "vnet-create": xm_vnet_create,