ia64/xen-unstable

changeset 14937:5d2e5d05e828

[XM] Fix network-attach when a bridge is specified, add network-new command to create new XenAPI network

signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
author Tom Wilkie <tom.wilkie@gmail.com>
date Wed Apr 25 16:12:41 2007 +0100 (2007-04-25)
parents 1786112d2430
children 7317e701f3e7
files tools/python/xen/xm/main.py
line diff
     1.1 --- a/tools/python/xen/xm/main.py	Wed Apr 25 16:11:20 2007 +0100
     1.2 +++ b/tools/python/xen/xm/main.py	Wed Apr 25 16:12:41 2007 +0100
     1.3 @@ -510,6 +510,10 @@ def xenapi_unsupported():
     1.4      if serverType == SERVER_XEN_API:
     1.5          raise XenAPIUnsupportedException, "This function is not supported by Xen-API"
     1.6  
     1.7 +def xenapi_only():
     1.8 +    if serverType != SERVER_XEN_API:
     1.9 +        raise XenAPIUnsupportedException, "This function is only supported by Xen-API"
    1.10 +
    1.11  def map2sxp(m):
    1.12      return [[k, m[k]] for k in m.keys()]
    1.13  
    1.14 @@ -2070,8 +2074,14 @@ def xm_network_attach(args):
    1.15              record[keys[-1]] = val
    1.16  
    1.17          def get_net_from_bridge(bridge):
    1.18 -            raise "Not supported just yet"
    1.19 -         
    1.20 +            # In OSS, we just assert network.name_label == bridge name
    1.21 +            networks = dict([(record['name_label'], record['uuid'])
    1.22 +                             for record in server.xenapi.network
    1.23 +                             .get_all_records()])
    1.24 +            if bridge not in networks.keys():
    1.25 +                raise "Unknown bridge name!"
    1.26 +            return networks[bridge]
    1.27 +
    1.28          vif_conv = {
    1.29              'type':
    1.30                  lambda x: None,
    1.31 @@ -2102,7 +2112,6 @@ def xm_network_attach(args):
    1.32              else:
    1.33                  vif_conv[vif_param[0]](vif_param[1])
    1.34  
    1.35 -        print str(vif_record)
    1.36          server.xenapi.VIF.create(vif_record)
    1.37      else:
    1.38          for a in args[1:]:
    1.39 @@ -2222,6 +2231,21 @@ def xm_vnet_delete(args):
    1.40      vnet = args[0]
    1.41      server.xend_vnet_delete(vnet)
    1.42  
    1.43 +def xm_network_new(args):
    1.44 +    xenapi_only()
    1.45 +    arg_check(args, "xm_network_new", 1)
    1.46 +    network = args[0]
    1.47 +
    1.48 +    record = {
    1.49 +        "name_label":       network,
    1.50 +        "name_description": "",
    1.51 +        "other_config":     {},
    1.52 +        "default_gateway":  "",
    1.53 +        "default_netmask":  ""
    1.54 +        }
    1.55 +    
    1.56 +    server.xenapi.network.create(record)
    1.57 +
    1.58  commands = {
    1.59      "shell": xm_shell,
    1.60      "event-monitor": xm_event_monitor,
    1.61 @@ -2271,10 +2295,12 @@ commands = {
    1.62      "block-detach": xm_block_detach,
    1.63      "block-list": xm_block_list,
    1.64      "block-configure": xm_block_configure,
    1.65 -    # network
    1.66 +    # network (AKA vifs)
    1.67      "network-attach": xm_network_attach,
    1.68      "network-detach": xm_network_detach,
    1.69      "network-list": xm_network_list,
    1.70 +    # network (as in XenAPI)
    1.71 +    "network-new": xm_network_new,
    1.72      # vnet
    1.73      "vnet-list": xm_vnet_list,
    1.74      "vnet-create": xm_vnet_create,