]> xenbits.xensource.com Git - xcp/xen-api.git/commitdiff
Improve network recreation on pool join
authorRob Hoes <rob.hoes@citrix.com>
Thu, 8 Jul 2010 13:47:51 +0000 (14:47 +0100)
committerRob Hoes <rob.hoes@citrix.com>
Thu, 8 Jul 2010 13:47:51 +0000 (14:47 +0100)
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 <rob.hoes@citrix.com>
ocaml/xapi/xapi_pool.ml

index aa4d0f4857781dd024bbaa11967313853c7dac6f..af39b83f30a251e0564204b62b7a8e232c863708 100644 (file)
@@ -15,6 +15,7 @@ open Client
 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 @@ let create_or_get_vdi_on_master __context rpc session_id (vdi_ref, vdi) : API.re
        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