@@ -897,76 +897,6 @@ protected XsLocalNetwork getNativeNetworkForTraffic(Connection conn, TrafficType
897897 throw new CloudRuntimeException ("Unsupported network type: " + type );
898898 }
899899
900- /**
901- * This is a tricky to create network in xenserver.
902- * if you create a network then create bridge by brctl or openvswitch yourself,
903- * then you will get an expection that is "REQUIRED_NETWROK" when you start a
904- * vm with this network. The soultion is, create a vif of dom0 and plug it in
905- * network, xenserver will create the bridge on behalf of you. But we can not keep the dom0 vif for the entire
906- * existence of network, as we will seen reach max VIF (8) that can be conencted to a domain. So as soon as we have
907- * one more VIF for any of the VM, delete dom0 VIF so that we can scale beyond 8 networks on a host.
908- * @throws XmlRpcException
909- * @throws XenAPIException
910- */
911- private void enableXenServerNetwork (Connection conn , Network nw , String vifNameLabel , String networkDesc ) throws XenAPIException , XmlRpcException {
912- /* Make sure there is a physical bridge on this network */
913- VIF dom0vif = null ;
914- Pair <VM , VM .Record > vm = getControlDomain (conn );
915- VM dom0 = vm .first ();
916- // Create a VIF unless there's not already another VIF
917- Set <VIF > dom0Vifs = dom0 .getVIFs (conn );
918- for (VIF vif : dom0Vifs ) {
919- vif .getRecord (conn );
920- if (vif .getNetwork (conn ).getUuid (conn ).equals (nw .getUuid (conn ))) {
921- dom0vif = vif ;
922- s_logger .debug ("A VIF for dom0 has already been found - No need to create one" );
923- }
924- }
925-
926- int domuVifCount =0 ;
927- Set <VIF > domUVifs = nw .getVIFs (conn );
928- Host host = Host .getByUuid (conn , _host .uuid );
929- for (VIF vif : domUVifs ) {
930- vif .getRecord (conn );
931- if (vif .getVM (conn ).getResidentOn (conn ).equals (host )) {
932- domuVifCount ++;
933- }
934- }
935-
936- if (dom0vif == null && domuVifCount == 0 ) {
937- s_logger .debug ("Create a vif on dom0 for " + networkDesc );
938- VIF .Record vifr = new VIF .Record ();
939- vifr .VM = dom0 ;
940- vifr .device = getLowestAvailableVIFDeviceNum (conn , dom0 );
941- if (vifr .device == null ) {
942- s_logger .debug ("Failed to create " + networkDesc + ", no vif available" );
943- return ;
944- }
945- Map <String , String > config = new HashMap <String , String >();
946- config .put ("nameLabel" , vifNameLabel );
947- vifr .otherConfig = config ;
948- vifr .MAC = "FE:FF:FF:FF:FF:FF" ;
949- vifr .network = nw ;
950-
951- vifr .lockingMode = Types .VifLockingMode .NETWORK_DEFAULT ;
952- dom0vif = VIF .create (conn , vifr );
953- synchronized (_tmpDom0Vif ) {
954- _tmpDom0Vif .add (dom0vif );
955- }
956- try {
957- dom0vif .plug (conn );
958- } catch (Exception e ) {
959- // though an exception is thrown here, VIF actually gets plugged-in to dom0, so just ignore the exception
960- }
961- dom0vif .unplug (conn );
962- }
963-
964- if (dom0vif != null && domuVifCount > 1 ) {
965- // now that there is at least one more VIF (other than dom0 vif) destroy dom0 VIF
966- dom0vif .destroy (conn );
967- }
968- }
969-
970900 private synchronized Network setupvSwitchNetwork (Connection conn ) {
971901 try {
972902 if (_host .vswitchNetwork == null ) {
@@ -982,8 +912,6 @@ private synchronized Network setupvSwitchNetwork(Connection conn) {
982912 } else {
983913 vswitchNw = networks .iterator ().next ();
984914 }
985- if (!is_xcp ())
986- enableXenServerNetwork (conn , vswitchNw , "vswitch" , "vswitch network" );
987915 _host .vswitchNetwork = vswitchNw ;
988916 }
989917 return _host .vswitchNetwork ;
@@ -1007,21 +935,20 @@ private synchronized Network findOrCreateTunnelNetwork(Connection conn, String n
1007935 Network .Record rec = new Network .Record ();
1008936 Set <Network > networks = Network .getByNameLabel (conn , nwName );
1009937
1010-
1011938 if (networks .size () == 0 ) {
1012939 rec .nameDescription = "tunnel network id# " + nwName ;
1013940 rec .nameLabel = nwName ;
1014941 //Initialize the ovs-host-setup to avoid error when doing get-param in plugin
1015942 Map <String , String > otherConfig = new HashMap <String , String >();
1016943 otherConfig .put ("ovs-host-setup" , "" );
944+ // Mark 'internal network' as shared so bridge gets automatically created on each host in the cluster
945+ // when VM with vif connected to this internal network is started
946+ otherConfig .put ("assume_network_is_shared" , "true" );
1017947 rec .otherConfig = otherConfig ;
1018948 nw = Network .create (conn , rec );
1019- // Plug dom0 vif only when creating network
1020- enableXenServerNetwork (conn , nw , nwName , "tunnel network for account " + nwName );
1021949 s_logger .debug ("### Xen Server network for tunnels created:" + nwName );
1022950 } else {
1023951 nw = networks .iterator ().next ();
1024- enableXenServerNetwork (conn , nw , nwName , "tunnel network for account " + nwName );
1025952 s_logger .debug ("Xen Server network for tunnels found:" + nwName );
1026953 }
1027954 return nw ;
@@ -1052,9 +979,8 @@ private synchronized Network configureTunnelNetwork(Connection conn, Long networ
1052979 }
1053980 }
1054981 }
982+
1055983 if (!configured ) {
1056- // Plug dom0 vif only if not done before for network and host
1057- enableXenServerNetwork (conn , nw , nwName , "tunnel network for account " + bridgeName );
1058984 String result ;
1059985 if (bridgeName .startsWith ("OVS-DR-VPC-Bridge" )) {
1060986 result = callHostPlugin (conn , "ovstunnel" , "setup_ovs_bridge_for_distributed_routing" , "bridge" , bridge ,
0 commit comments