internal static LocalizedString FixUpIpAddressesForNetName(ITaskOutputHelper logger, IAmCluster cluster, AmClusterGroup group, AmClusterResource netname, IEnumerable <IPAddress> staticIpAddresses) { logger = (logger ?? NullTaskOutputHelper.GetNullLogger()); LocalizedString localizedString = Strings.FixUpIpAddressStatusUnchanged; if (staticIpAddresses != null && staticIpAddresses.Count <IPAddress>() == 1 && IPAddress.Any.Equals(staticIpAddresses.ElementAt(0))) { logger.AppendLogMessage("DAG IP Address was specified in AD, but it's the sentinel value for forcing DHCP ({0}).", new object[] { IPAddress.Any }); staticIpAddresses = new IPAddress[0]; } bool flag = staticIpAddresses != null && staticIpAddresses.Count <IPAddress>() > 0; bool flag2 = staticIpAddresses != null && staticIpAddresses.Count <IPAddress>() == 0; logger.AppendLogMessage("FixUpIpAddressesForNetName: goingToStaticIps: {0}, goingToDynamicIps = {1}.", new object[] { flag, flag2 }); if (flag) { logger.AppendLogMessage("FixUpIpAddressesForNetName: The static IPs specified are:", new object[0]); foreach (IPAddress ipaddress in staticIpAddresses) { logger.AppendLogMessage(" -> {0}", new object[] { ipaddress }); } } IEnumerable <AmClusterNetwork> enumerable = null; IEnumerable <AmClusterResource> enumerable2 = null; IEnumerable <AmClusterResource> enumerable3 = null; IEnumerable <AmClusterResource> enumerable4 = null; try { enumerable = cluster.EnumerateNetworks(); IEnumerable <AmClusterNetwork> enumerable5 = AmClusterResourceHelper.FilterPublicNetworksFromAllNetworks(enumerable); enumerable2 = group.EnumerateResourcesOfType("IP Address"); enumerable3 = group.EnumerateResourcesOfType("IPv6 Address"); IEnumerable <AmClusterResource> enumerable6 = enumerable2.Concat(enumerable3); IList <string> networksWithResources; int num = AmClusterResourceHelper.DeleteOrphanedIpAddresses(logger, group, netname, enumerable6, staticIpAddresses, enumerable5, out networksWithResources); if (num > 0) { SharedHelper.DisposeObjectList <AmClusterResource>(enumerable6); enumerable2 = group.EnumerateResourcesOfType("IP Address"); enumerable3 = group.EnumerateResourcesOfType("IPv6 Address"); } if (flag) { enumerable4 = AmClusterResourceHelper.AddStaticIpAddressesToStrandedNetworks(logger, group, netname, enumerable5, networksWithResources, staticIpAddresses); } else { enumerable4 = AmClusterResourceHelper.AddIpAddressesToStrandedNetworks(logger, group, netname, enumerable5, networksWithResources); } int num2 = enumerable4.Count <AmClusterResource>(); if (num2 > 0) { HashSet <string> hashSet = new HashSet <string>(); foreach (AmClusterResource amClusterResource in enumerable2) { hashSet.Add(amClusterResource.Name); } foreach (AmClusterResource amClusterResource2 in enumerable3) { hashSet.Add(amClusterResource2.Name); } foreach (AmClusterResource amClusterResource3 in enumerable4) { hashSet.Add(amClusterResource3.Name); } string text = string.Format("[{0}]", string.Join("] OR [", hashSet.ToArray <string>())); logger.AppendLogMessage("Setting the dependency on netname '{0}' to '{1}'", new object[] { netname.Name, text }); netname.OfflineResource(); uint num3 = netname.SetDependencyExpression(text); logger.AppendLogMessage("SetDependencyExpression returned {0}.", new object[] { num3 }); } localizedString = Strings.FixUpIpAddressStatusUpdated(num, num2); } finally { SharedHelper.DisposeObjectList <AmClusterNetwork>(enumerable); SharedHelper.DisposeObjectList <AmClusterResource>(enumerable2); SharedHelper.DisposeObjectList <AmClusterResource>(enumerable3); SharedHelper.DisposeObjectList <AmClusterResource>(enumerable4); netname.OnlineResource(); } logger.AppendLogMessage("Successfully completed fixing up the IP addresses for netname '{0}'. Changes made: {1}", new object[] { netname.Name, localizedString }); return(localizedString); }
private static IEnumerable <AmClusterResource> AddStaticIpAddressesToStrandedNetworks(ITaskOutputHelper logger, AmClusterGroup group, AmClusterResource netname, IEnumerable <AmClusterNetwork> publicNetworks, IEnumerable <string> networksWithResources, IEnumerable <IPAddress> staticIpAddresses) { logger = (logger ?? NullTaskOutputHelper.GetNullLogger()); if (publicNetworks.Count <AmClusterNetwork>() <= networksWithResources.Count <string>()) { logger.AppendLogMessage("AddStaticIpAddressesToStrandedNetworks: publicNetworks.Count({0}) <= networksWithResources.Count({1}). So we're doing nothing.", new object[] { publicNetworks.Count <AmClusterNetwork>(), networksWithResources.Count <string>() }); return(new List <AmClusterResource>(0)); } List <AmClusterResource> list = new List <AmClusterResource>(publicNetworks.Count <AmClusterNetwork>() - networksWithResources.Count <string>()); IEnumerable <AmClusterNetwork> enumerable = from publicNet in publicNetworks where !networksWithResources.Contains(publicNet.Name) select publicNet; bool flag = false; using (IEnumerator <AmClusterNetwork> enumerator = enumerable.GetEnumerator()) { while (enumerator.MoveNext()) { AmClusterNetwork publicNetwork = enumerator.Current; logger.AppendLogMessage("AddStaticIpAddressesToStrandedNetworks() There doesn't appear to be an IP resource on network '{0}'.", new object[] { publicNetwork.Name }); IEnumerable <IPAddress> enumerable2 = from staticIp in staticIpAddresses where publicNetwork.IsIPInNetwork(staticIp) select staticIp; if (enumerable2.Count <IPAddress>() > 0) { flag = true; } foreach (IPAddress ipaddress in enumerable2) { logger.AppendLogMessage("AddStaticIpAddressesToStrandedNetworks() Adding IP {0} to network '{1}'.", new object[] { ipaddress, publicNetwork.Name }); int num = 1; bool flag2 = false; AmClusterResource amClusterResource = null; try { amClusterResource = (AmClusterResource)group.CreateUniqueResource(logger, "IPv4 Static Address", "IP Address", ref num); logger.AppendLogMessage("Created new ipv4 static resource. (resource:{0}, address:{1})", new object[] { amClusterResource.Name, ipaddress.ToString() }); int num2; using (AmClusterPropListDisposable amClusterPropListDisposable = AmClusPropListMaker.CreatePropListString("Address", ipaddress.ToString(), out num2)) { using (AmClusterPropListDisposable amClusterPropListDisposable2 = AmClusPropListMaker.DupeAndAppendPropListString(amClusterPropListDisposable.RawBuffer, (int)amClusterPropListDisposable.BufferSize, "Network", publicNetwork.Name, out num2)) { using (AmClusterPropListDisposable amClusterPropListDisposable3 = AmClusPropListMaker.DupeAndAppendPropListString(amClusterPropListDisposable2.RawBuffer, (int)amClusterPropListDisposable2.BufferSize, "SubnetMask", publicNetwork.GetAddressMask(), out num2)) { logger.AppendLogMessage("Created new ipv4 resource: name '{0}' to be {1} on network named '{2}' with mask={3}.", new object[] { amClusterResource.Name, ipaddress.ToString(), publicNetwork.Name, publicNetwork.GetAddressMask() }); amClusterResource.SetPrivatePropertyList(amClusterPropListDisposable3); } } } list.Add(amClusterResource); flag2 = true; } finally { if (!flag2 && amClusterResource != null) { logger.AppendLogMessage("There was some error creating and configuring the IP address resource {0}. Making a best-effort attempt to delete it.", new object[] { ipaddress }); try { amClusterResource.OfflineResource(); amClusterResource.DeleteResource(); } catch (ClusterApiException ex) { logger.AppendLogMessage("There was an error deleting the incomplete IP address. Ignoring the error and continuing. The error was {0}", new object[] { ex }); } if (amClusterResource != null) { amClusterResource.Dispose(); amClusterResource = null; } } } } } } if (!flag) { string[] value = (from network in enumerable select network.Name).ToArray <string>(); string[] value2 = (from staticIp in staticIpAddresses select staticIp.ToString()).ToArray <string>(); logger.WriteWarning(Strings.DagTaskNotEnoughStaticIPAddresses(string.Join(",", value), string.Join(",", value2))); } return(list); }
// Token: 0x060008AC RID: 2220 RVA: 0x00029304 File Offset: 0x00027504 internal static void CreateFileShareWitnessQuorum(ITaskOutputHelper output, IAmCluster cluster, string fswShare) { output = (output ?? NullTaskOutputHelper.GetNullLogger()); IAmClusterGroup amClusterGroup = cluster.FindCoreClusterGroup(); if (amClusterGroup == null) { Thread.Sleep(10000); amClusterGroup = cluster.FindCoreClusterGroup(); if (amClusterGroup == null) { throw new FailedToGetClusterCoreGroupException(); } } using (amClusterGroup) { IEnumerable <AmClusterResource> source = amClusterGroup.EnumerateResourcesOfType("File Share Witness"); IAmClusterResource amClusterResource = source.ElementAtOrDefault(0); try { bool flag = false; if (amClusterResource == null) { output.AppendLogMessage("CreateFileShareWitnessQuorum: Could not find an existing FSW resource. A new one will be created.", new object[0]); flag = true; } else if (amClusterResource.GetState() == AmResourceState.Failed) { output.AppendLogMessage("CreateFileShareWitnessQuorum: The existing FSW resource is in a Failed state. It should be deleted and recreated.", new object[0]); flag = true; } else { string privateProperty = amClusterResource.GetPrivateProperty <string>("SharePath"); if (!SharedHelper.StringIEquals(privateProperty, fswShare)) { output.AppendLogMessage("CreateFileShareWitnessQuorum: There is already a FSW, but the current share path ({0}) is not what's desired ({1}). Will try to fix it.", new object[] { privateProperty, fswShare }); List <string> list = new List <string>(4); foreach (IAmClusterNode amClusterNode in cluster.EnumerateNodes()) { using (amClusterNode) { if (!AmClusterNode.IsNodeUp(amClusterNode.State)) { list.Add(amClusterNode.Name.NetbiosName); } } } if (list.Count > 0) { output.WriteErrorSimple(new DagTaskSetDagNeedsAllNodesUpToChangeQuorumException(string.Join(",", list.ToArray()))); } DagHelper.SetFswSharePath(output, cluster, amClusterResource, fswShare); } } AmResourceState state; if (!flag && amClusterResource != null) { try { state = amClusterResource.GetState(); if (state != AmResourceState.Online) { output.AppendLogMessage("The FSW is not online (it is {0}). Attempting to bring online.", new object[] { state }); amClusterResource.OnlineResource(); } state = amClusterResource.GetState(); output.AppendLogMessage("The fsw resource is now in state {0}.", new object[] { state }); if (state != AmResourceState.Online) { flag = true; } } catch (ClusterException ex) { output.AppendLogMessage("Bringing the FSW resource online failed, so it will be deleted and recreated. For the record, the error was {0}", new object[] { ex }); flag = true; } } if (flag) { if (amClusterResource != null) { amClusterResource.Dispose(); amClusterResource = null; } output.AppendLogMessage("CreateFileShareWitnessQuorum: Calling RevertToMnsQuorum to clean everything up first.", new object[0]); DagHelper.RevertToMnsQuorum(output, cluster); string text = string.Format("File Share Witness ({0})", fswShare); output.AppendLogMessage("Creating a new file share witness resource named '{0}'.", new object[] { text }); amClusterResource = amClusterGroup.CreateResource(text, "File Share Witness"); DagHelper.SetFswSharePath(output, cluster, amClusterResource, fswShare); } output.AppendLogMessage("The FSW resource is now in state {0}.", new object[] { amClusterResource.GetState() }); string text2; uint maxLogSize; string quorumResourceInformation = cluster.GetQuorumResourceInformation(out text2, out maxLogSize); output.AppendLogMessage("The current quorum resource is '{0}'. About to set it to the FSW.", new object[] { quorumResourceInformation }); state = amClusterResource.GetState(); if (state != AmResourceState.Online) { output.WriteErrorSimple(new DagTaskFileShareWitnessResourceIsStillNotOnlineException(fswShare, state.ToString())); } cluster.SetQuorumResource(amClusterResource, null, maxLogSize); quorumResourceInformation = cluster.GetQuorumResourceInformation(out text2, out maxLogSize); output.AppendLogMessage("The quorum resource is now '{0}'.", new object[] { quorumResourceInformation }); output.AppendLogMessage("Bringing the quorum resource online...", new object[0]); amClusterResource.OnlineResource(); } finally { if (amClusterResource != null) { amClusterResource.Dispose(); amClusterResource = null; } } } }