public void Execute(Network network) { IList<NetworkRoute> routes = new List<NetworkRoute>(); _logger.Log("Routes Found: " + routes.Count); DeleteExistingPersistentRoutesRoutes(); foreach (var networkInterface in network.Interfaces.Values) { var publicGateway = networkInterface.gateway; if (!string.IsNullOrEmpty(publicGateway)) _executableProcessQueue.Enqueue("route", String.Format("-p add 0.0.0.0 mask 0.0.0.0 {0} metric 2", publicGateway)); if (networkInterface.routes == null || networkInterface.routes.Length < 1) continue; foreach (var route in networkInterface.routes) { if (routes.Contains(route)) continue; routes.Add(route); } } foreach (var route in routes) { _executableProcessQueue.Enqueue("route", String.Format("-p add {0} mask {1} {2} metric 10", route.route, route.netmask, route.gateway)); } _executableProcessQueue.Go(); }
public void Setup() { xenNetworkInformation = MockRepository.GenerateMock<IXenNetworkInformation>(); setNetworkInterface = MockRepository.GenerateMock<ISetNetworkInterface>(); setNetworkRoutes = MockRepository.GenerateMock<ISetNetworkRoutes>(); networkInterface = new NetworkInterface(); network = new Network(); network.Interfaces.Add("fakemac", networkInterface); command = new ResetNetwork(setNetworkInterface, xenNetworkInformation, setNetworkRoutes); xenNetworkInformation.Stub(x => x.Get()).Return(network); result = command.Execute(null); }
public void Setup() { xenNetworkInformation = MockRepository.GenerateMock<IXenNetworkInformation>(); setNetworkInterface = MockRepository.GenerateMock<ISetNetworkInterface>(); setNetworkRoutes = MockRepository.GenerateMock<ISetNetworkRoutes>(); xenProviderDataInformation = MockRepository.GenerateMock<IXenProviderDataInformation>(); setProviderData = MockRepository.GenerateMock<ISetProviderData>(); setHostname = MockRepository.GenerateMock<ISetHostnameAction>(); _xenStore = MockRepository.GenerateMock<IXenStore>(); networkInterface = new NetworkInterface(); network = new Network(); network.Interfaces.Add("fakemac", networkInterface); providerData = new ProviderData(); command = new ResetNetwork(setNetworkInterface, xenNetworkInformation, setNetworkRoutes, setProviderData, xenProviderDataInformation, setHostname, _xenStore); }
public void Setup() { _network = new Network(); Setup("fakemac"); SetupRoutesOnInterface(new[] { new NetworkRoute { gateway = "10.1.10.20", netmask = "255.255.255.0", route = "10.1.10.1" }, new NetworkRoute { gateway = "10.1.10.20", netmask = "255.255.255.0", route = "10.1.10.2" } }); _networkInterface1 = NetworkInterface; _networkInterface1.label = "public"; _network.Interfaces.Add("fakemac", _networkInterface1); Setup("fakemac1"); SetupRoutesOnInterface(new[] { new NetworkRoute { gateway = "10.1.10.20", netmask = "255.255.255.0", route = "10.1.10.1" }, new NetworkRoute { gateway = "10.1.10.20", netmask = "255.255.255.0", route = "10.1.10.3" } }); _networkInterface2 = NetworkInterface; _networkInterface2.gateway = "10.1.1.1"; _network.Interfaces.Add("fakemac1", _networkInterface2); _executableProcessQueue = MockRepository.GenerateMock<IExecutableProcessQueue>(); _executableProcessQueue.Expect(x => x.Go()).Repeat.Once(); _registryReader = MockRepository.GenerateMock<IRegistryReader>(); _registryReader.Stub(x => x.GetValuesFrom(Arg<string>.Is.Anything)) .Return(new List<string> { "0.0.0.0,0.0.0.0,172.16.251.2,2", "1.2.3.4,5.6.7.8,9.10.11.12.13,10" }); _logger = MockRepository.GenerateMock<ILogger>(); ExecutableProcessQueue.Replay(); _setNetworkRoutes = new SetNetworkRoutes(_executableProcessQueue, _registryReader, _logger); _setNetworkRoutes.Execute(_network); }