# HG changeset patch # User Rob Hoes # Date 1278596871 -3600 # Node ID ac96f047a434dd212f15587dff046cd547d3e366 # Parent 678148a831694194bbb37f5b043d868187f1a5e0 Improve network recreation on pool join When joining a new host to a pool: * Networks of physical interfaces are copied to the pool's DB if they do not yet exists; matching is done based on the bridge name (xenbr0, xenbr1, ...). * All other networks are recreated on the pool. The bridge (xapi0, xapi1, ...) is renamed such that it is unique on the pool. All other network fields are copied from the host's network object. (related to CA-39461) Signed-off-by: Rob Hoes diff -r 678148a83169 -r ac96f047a434 ocaml/xapi/xapi_pool.ml --- a/ocaml/xapi/xapi_pool.ml Thu Jul 08 14:43:16 2010 +0100 +++ b/ocaml/xapi/xapi_pool.ml Thu Jul 08 14:47:51 2010 +0100 @@ -15,6 +15,7 @@ open Db_filter_types open Pervasiveext open Threadext +open Stringext module L = Debug.Debugger(struct let name="license" end) module D=Debug.Debugger(struct let name="xapi" end) @@ -387,18 +388,36 @@ new_vdi_ref let create_or_get_network_on_master __context rpc session_id (network_ref, network) : API.ref_network = - let my_name = network.API.network_name_label in + let my_bridge = network.API.network_bridge in let new_network_ref = - try List.hd (Client.Network.get_by_name_label ~rpc ~session_id ~label:my_name) - with _ -> - debug "Found no network with name_label = '%s' on the master, so creating one." my_name; - Client.Network.pool_introduce ~rpc ~session_id - ~name_label:my_name + if String.startswith "xenbr" my_bridge then + (* Physical network: try to join an existing one with the same bridge name, or create one. + * This relies on the convention that PIFs with the same label need to be connected. *) + try + let pool_networks = Client.Network.get_all_records ~rpc ~session_id in + let net_ref, _ = List.find (fun (_, net) -> net.API.network_bridge = my_bridge) pool_networks in + net_ref + with _ -> + debug "Found no network with bridge = '%s' on the master, so creating one." my_bridge; + Client.Network.pool_introduce ~rpc ~session_id + ~name_label:network.API.network_name_label + ~name_description:network.API.network_name_description + ~mTU:network.API.network_MTU + ~other_config:network.API.network_other_config + ~bridge:network.API.network_bridge + else begin + debug "Recreating network '%s' as internal network." network.API.network_name_label; + (* This call will generate a new 'xapi#' bridge name rather than keeping the + * current, possibly colliding one. *) + Client.Network.create ~rpc ~session_id + ~name_label:network.API.network_name_label ~name_description:network.API.network_name_description ~mTU:network.API.network_MTU ~other_config:network.API.network_other_config - ~bridge:network.API.network_bridge in + ~tags:network.API.network_tags + end + in new_network_ref