@@ -492,169 +492,6 @@ public Answer executeRequest(Command cmd) {
492492 return execute ((OvsCreateTunnelCommand )cmd );
493493 } else if (clazz == OvsSetupBridgeCommand .class ) {
494494 return execute ((OvsSetupBridgeCommand )cmd );
495- } else if (clazz == OvsDestroyBridgeCommand .class ) {
496- return execute ((OvsDestroyBridgeCommand )cmd );
497- } else if (clazz == OvsDestroyTunnelCommand .class ) {
498- return execute ((OvsDestroyTunnelCommand )cmd );
499- } else if (clazz == UpdateHostPasswordCommand .class ) {
500- return execute ((UpdateHostPasswordCommand )cmd );
501- } else if (cmd instanceof CheckRouterCommand ) {
502- return execute ((CheckRouterCommand )cmd );
503- } else if (cmd instanceof SetFirewallRulesCommand ) {
504- return execute ((SetFirewallRulesCommand )cmd );
505- } else if (cmd instanceof BumpUpPriorityCommand ) {
506- return execute ((BumpUpPriorityCommand )cmd );
507- } else if (cmd instanceof ClusterSyncCommand ) {
508- return execute ((ClusterSyncCommand )cmd );
509- } else if (cmd instanceof GetDomRVersionCmd ) {
510- return execute ((GetDomRVersionCmd )cmd );
511- } else if (clazz == CheckNetworkCommand .class ) {
512- return execute ((CheckNetworkCommand ) cmd );
513- } else {
514- return Answer .createUnsupportedCommandAnswer (cmd );
515- }
516- }
517-
518-
519- protected XsLocalNetwork getNativeNetworkForTraffic (Connection conn , TrafficType type , String name ) throws XenAPIException , XmlRpcException {
520- if (name != null ) {
521- if (s_logger .isDebugEnabled ()) {
522- s_logger .debug ("Looking for network named " + name );
523- }
524- return getNetworkByName (conn , name );
525- }
526-
527- if (type == TrafficType .Guest ) {
528- return new XsLocalNetwork (Network .getByUuid (conn , _host .guestNetwork ), null , PIF .getByUuid (conn , _host .guestPif ), null );
529- } else if (type == TrafficType .Control ) {
530- setupLinkLocalNetwork (conn );
531- return new XsLocalNetwork (Network .getByUuid (conn , _host .linkLocalNetwork ));
532- } else if (type == TrafficType .Management ) {
533- return new XsLocalNetwork (Network .getByUuid (conn , _host .privateNetwork ), null , PIF .getByUuid (conn , _host .privatePif ), null );
534- } else if (type == TrafficType .Public ) {
535- return new XsLocalNetwork (Network .getByUuid (conn , _host .publicNetwork ), null , PIF .getByUuid (conn , _host .publicPif ), null );
536- } else if (type == TrafficType .Storage ) {
537- return new XsLocalNetwork (Network .getByUuid (conn , _host .storageNetwork1 ), null , PIF .getByUuid (conn , _host .storagePif1 ), null );
538- }
539-
540- throw new CloudRuntimeException ("Unsupported network type: " + type );
541- }
542-
543- /**
544- * This is a tricky to create network in xenserver.
545- * if you create a network then create bridge by brctl or openvswitch yourself,
546- * then you will get an expection that is "REQUIRED_NETWROK" when you start a
547- * vm with this network. The soultion is, create a vif of dom0 and plug it in
548- * network, xenserver will create the bridge on behalf of you
549- * @throws XmlRpcException
550- * @throws XenAPIException
551- */
552- private void enableXenServerNetwork (Connection conn , Network nw ,
553- String vifNameLabel , String networkDesc ) throws XenAPIException , XmlRpcException {
554- /* Make sure there is a physical bridge on this network */
555- VIF dom0vif = null ;
556- Pair <VM , VM .Record > vm = getControlDomain (conn );
557- VM dom0 = vm .first ();
558- // Create a VIF unless there's not already another VIF
559- Set <VIF > dom0Vifs = dom0 .getVIFs (conn );
560- for (VIF vif :dom0Vifs ) {
561- vif .getRecord (conn );
562- if (vif .getNetwork (conn ).getUuid (conn ) == nw .getUuid (conn )) {
563- dom0vif = vif ;
564- s_logger .debug ("### A dom0 VIF has already been found - No need to create one" );
565- }
566- }
567- if (dom0vif == null ) {
568- s_logger .debug ("Create a vif on dom0 for " + networkDesc );
569- VIF .Record vifr = new VIF .Record ();
570- vifr .VM = dom0 ;
571- vifr .device = getLowestAvailableVIFDeviceNum (conn , dom0 );
572- if (vifr .device == null ) {
573- s_logger .debug ("Failed to create " + networkDesc + ", no vif available" );
574- return ;
575- }
576- Map <String , String > config = new HashMap <String , String >();
577- config .put ("nameLabel" , vifNameLabel );
578- vifr .otherConfig = config ;
579- vifr .MAC = "FE:FF:FF:FF:FF:FF" ;
580- vifr .network = nw ;
581-
582- dom0vif = VIF .create (conn , vifr );
583- }
584- // At this stage we surely have a VIF
585- dom0vif .plug (conn );
586- dom0vif .unplug (conn );
587- synchronized (_tmpDom0Vif ) {
588- _tmpDom0Vif .add (dom0vif );
589- }
590-
591- }
592-
593- private synchronized Network setupvSwitchNetwork (Connection conn ) {
594- try {
595- if (_host .vswitchNetwork == null ) {
596- Network vswitchNw = null ;
597- Network .Record rec = new Network .Record ();
598- String nwName = Networks .BroadcastScheme .VSwitch .toString ();
599- Set <Network > networks = Network .getByNameLabel (conn , nwName );
600-
601- if (networks .size () == 0 ) {
602- rec .nameDescription = "vswitch network for " + nwName ;
603- rec .nameLabel = nwName ;
604- vswitchNw = Network .create (conn , rec );
605- } else {
606- vswitchNw = networks .iterator ().next ();
607- }
608-
609- enableXenServerNetwork (conn , vswitchNw , "vswitch" , "vswicth network" );
610- _host .vswitchNetwork = vswitchNw ;
611- }
612- return _host .vswitchNetwork ;
613- } catch (Exception e ) {
614- e .printStackTrace ();
615- }
616-
617- return null ;
618- }
619-
620- /**
621- * This method just creates a XenServer network following the tunnel network naming convention
622- */
623- private synchronized Network findOrCreateTunnelNetwork (Connection conn , long vnetId ) {
624- try {
625- String nwName = "OVSTunnel" + vnetId ;
626- Network nw = null ;
627- Network .Record rec = new Network .Record ();
628- Set <Network > networks = Network .getByNameLabel (conn , nwName );
629-
630- if (networks .size () == 0 ) {
631- rec .nameDescription = "tunnel network id# " + vnetId ;
632- rec .nameLabel = nwName ;
633- //Initialize the ovs-host-setup to avoid error when doing get-param in plugin
634- Map <String ,String > otherConfig = new HashMap <String ,String >();
635- otherConfig .put ("ovs-host-setup" , "" );
636- rec .otherConfig = otherConfig ;
637- nw = Network .create (conn , rec );
638- s_logger .debug ("### Xen Server network for tunnels created:" + nwName );
639- } else {
640- nw = networks .iterator ().next ();
641- s_logger .debug ("### Xen Server network for tunnels found:" + nwName );
642- }
643- return nw ;
644- } catch (Exception e ) {
645- s_logger .warn ("createTunnelNetwork failed" , e );
646- return null ;
647- }
648- }
649-
650- /**
651- * This method creates a XenServer network and configures it for being used as a L2-in-L3 tunneled network
652- */
653- private synchronized Network configureTunnelNetwork (Connection conn , long networkId , long hostId , int key ) {
654- try {
655- // Note: the vnet (or gre key) is used to identify the XS network
656- Network nw = findOrCreateTunnelNetwork (conn , key );
657- String nwName = "OVSTunnel" + key ;
658495 //Invoke plugin to setup the bridge which will be used by this network
659496 String bridge = nw .getBridge (conn );
660497 Map <String ,String > nwOtherConfig = nw .getOtherConfig (conn );
@@ -4811,7 +4648,7 @@ private Answer execute(OvsDestroyTunnelCommand cmd) {
48114648 Connection conn = getConnection ();
48124649 s_logger .debug ("### About to destroy tunnel network" );
48134650 try {
4814- Network nw = findOrCreateTunnelNetwork (conn , cmd .getKey ());
4651+ Network nw = findTunnelNetwork (conn , cmd .getNetworkId ());
48154652 if (nw == null ) {
48164653 s_logger .warn ("### Unable to find tunnel network" );
48174654 return new Answer (cmd , false , "No network found" );
0 commit comments