示例#1
0
 public static void ValidateIpv4Addresses(IAmCluster cluster, IPAddress[] ipv4Addresses)
 {
     for (int i = 0; i < ipv4Addresses.Length - 1; i++)
     {
         for (int j = i + 1; j < ipv4Addresses.Length; j++)
         {
             if (object.Equals(ipv4Addresses[i], ipv4Addresses[j]))
             {
                 throw new IPv4AddressesHasDuplicateEntries(ipv4Addresses[i].ToString());
             }
         }
     }
     if (cluster != null)
     {
         IDictionary <IPAddress, AmClusterNetwork> dictionary = null;
         try
         {
             dictionary = AmClusterResourceHelper.GetIpv4StaticNetworkMap(cluster, ipv4Addresses);
         }
         finally
         {
             if (dictionary != null)
             {
                 SharedHelper.DisposeObjectList <AmClusterNetwork>(dictionary.Values);
             }
         }
     }
 }
示例#2
0
        public static void ValidateIpv6Networks(IAmCluster cluster, string[] ipv6Networks)
        {
            for (int i = 0; i < ipv6Networks.Length - 1; i++)
            {
                for (int j = i + 1; j < ipv6Networks.Length; j++)
                {
                    if (SharedHelper.StringIEquals(ipv6Networks[i], ipv6Networks[j]))
                    {
                        throw new IPv6NetworksHasDuplicateEntries(ipv6Networks[i]);
                    }
                }
            }
            Dictionary <string, AmClusterNetwork> ipv6AutoCfgNetworkMap = AmClusterResourceHelper.GetIpv6AutoCfgNetworkMap(cluster, ipv6Networks);

            if (ipv6AutoCfgNetworkMap != null)
            {
                SharedHelper.DisposeObjectList <AmClusterNetwork>(ipv6AutoCfgNetworkMap.Values);
            }
        }
示例#3
0
        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);
        }
示例#4
0
        public static List <AmClusterResource> ConfigureIPv6AutoCfgResources(ILogTraceHelper logger, AmClusterGroup group, string[] ipv6Networks)
        {
            bool flag = false;
            Dictionary <string, AmClusterResource> dictionary  = new Dictionary <string, AmClusterResource>(8);
            Dictionary <string, AmClusterNetwork>  dictionary2 = null;

            AmClusterResource[]      array = null;
            List <AmClusterResource> list  = new List <AmClusterResource>(10);
            List <AmClusterResource> list2 = null;

            try
            {
                logger      = (logger ?? NullLogTraceHelper.GetNullLogger());
                dictionary2 = AmClusterResourceHelper.GetIpv6AutoCfgNetworkMap(group.OwningCluster, ipv6Networks);
                IEnumerable <AmClusterResource> source = group.EnumerateResourcesOfType("IPv6 Address");
                if (source.Count <AmClusterResource>() > 0)
                {
                    array = source.ToArray <AmClusterResource>();
                }
                if (array != null)
                {
                    foreach (string key in ipv6Networks)
                    {
                        for (int j = 0; j < array.Length; j++)
                        {
                            AmClusterResource amClusterResource = array[j];
                            string            privateProperty   = amClusterResource.GetPrivateProperty <string>("Network");
                            AmClusterNetwork  amClusterNetwork  = dictionary2[key];
                            if (SharedHelper.StringIEquals(amClusterNetwork.Name, privateProperty))
                            {
                                logger.AppendLogMessage("Reusing ipv6 resource because its network is matching. (resource:{0}, network:{1}/{2}", new object[]
                                {
                                    amClusterResource.Name,
                                    privateProperty,
                                    amClusterNetwork.Name
                                });
                                dictionary[key] = amClusterResource;
                                array[j]        = null;
                                break;
                            }
                        }
                    }
                }
                if (dictionary.Count < ipv6Networks.Length)
                {
                    int num = 1;
                    foreach (string text in ipv6Networks)
                    {
                        if (!dictionary.ContainsKey(text))
                        {
                            AmClusterResource amClusterResource = (AmClusterResource)group.CreateUniqueResource(logger, "IPv6 Auto Config Address", "IPv6 Address", ref num);
                            list.Add(amClusterResource);
                            logger.AppendLogMessage("Created new ipv6 resource. (resource:{0}, network:{1})", new object[]
                            {
                                amClusterResource.Name,
                                text
                            });
                            dictionary[text] = amClusterResource;
                        }
                    }
                }
                list2 = new List <AmClusterResource>(ipv6Networks.Length);
                foreach (string key2 in ipv6Networks)
                {
                    AmClusterResource amClusterResource = dictionary[key2];
                    AmClusterNetwork  amClusterNetwork  = dictionary2[key2];
                    logger.AppendLogMessage("ConfigureIPv6AutoCfgResources: Setting resource '{0}' to be on network '{1}' (role={2}).", new object[]
                    {
                        amClusterResource.Name,
                        amClusterNetwork.Name,
                        amClusterNetwork.GetNativeRole()
                    });
                    amClusterResource.SetPrivateProperty <string>("Network", amClusterNetwork.Name);
                    AmClusterResourceHelper.SetPossibleOwnersForIpResource(logger, amClusterResource);
                    list2.Add(amClusterResource);
                }
                flag = true;
            }
            finally
            {
                if (!flag)
                {
                    SharedHelper.DisposeObjectList <AmClusterResource>(list);
                }
                SharedHelper.DisposeObjectList <AmClusterResource>(array);
                if (dictionary2 != null)
                {
                    SharedHelper.DisposeObjectList <AmClusterNetwork>(dictionary2.Values);
                }
            }
            return(list2);
        }
示例#5
0
        public static List <AmClusterResource> ConfigureIPv4DhcpResources(ILogTraceHelper logger, AmClusterGroup group, string[] ipv4Networks)
        {
            bool flag = false;
            Dictionary <string, AmClusterResource> dictionary  = new Dictionary <string, AmClusterResource>(8);
            Dictionary <string, AmClusterNetwork>  dictionary2 = null;

            AmClusterResource[]      array = null;
            List <AmClusterResource> list  = new List <AmClusterResource>(10);
            List <AmClusterResource> list2 = new List <AmClusterResource>(10);
            List <AmClusterResource> list3 = null;

            try
            {
                logger      = (logger ?? NullLogTraceHelper.GetNullLogger());
                dictionary2 = AmClusterResourceHelper.GetIpv4DhcpNetworkMap(group.OwningCluster, ipv4Networks);
                IEnumerable <AmClusterResource> enumerable = group.EnumerateResourcesOfType("IP Address");
                if (enumerable != null)
                {
                    array = enumerable.ToArray <AmClusterResource>();
                    for (int i = 0; i < array.Length; i++)
                    {
                        AmClusterResource amClusterResource = array[i];
                        if (amClusterResource.GetPrivateProperty <int>("EnableDhcp") != 0)
                        {
                            list.Add(amClusterResource);
                            array[i] = null;
                        }
                    }
                }
                foreach (string key in ipv4Networks)
                {
                    for (int k = 0; k < list.Count; k++)
                    {
                        AmClusterResource amClusterResource2 = list[k];
                        string            privateProperty    = amClusterResource2.GetPrivateProperty <string>("Network");
                        AmClusterNetwork  amClusterNetwork   = dictionary2[key];
                        if (SharedHelper.StringIEquals(amClusterNetwork.Name, privateProperty))
                        {
                            logger.AppendLogMessage("Reusing ipv4 dhcp resource because its network is matching. (resource:{0}, network:{1}/{2}", new object[]
                            {
                                amClusterResource2.Name,
                                privateProperty,
                                amClusterNetwork.Name
                            });
                            dictionary[key] = amClusterResource2;
                            list[k]         = null;
                            break;
                        }
                    }
                }
                if (dictionary.Count < ipv4Networks.Length)
                {
                    int num = 1;
                    foreach (string text in ipv4Networks)
                    {
                        if (!dictionary.ContainsKey(text))
                        {
                            AmClusterResource amClusterResource2 = (AmClusterResource)group.CreateUniqueResource(logger, "IPv4 DHCP Address", "IP Address", ref num);
                            list2.Add(amClusterResource2);
                            logger.AppendLogMessage("Created new ipv4 dhcp resource. (resource:{0}, network:{1})", new object[]
                            {
                                amClusterResource2.Name,
                                text
                            });
                            dictionary[text] = amClusterResource2;
                        }
                    }
                }
                list3 = new List <AmClusterResource>(ipv4Networks.Length);
                foreach (string key2 in ipv4Networks)
                {
                    AmClusterResource amClusterResource2 = dictionary[key2];
                    AmClusterNetwork  amClusterNetwork   = dictionary2[key2];
                    int num2;
                    using (AmClusterPropListDisposable amClusterPropListDisposable = AmClusPropListMaker.CreatePropListInt("EnableDhcp", 1, out num2))
                    {
                        using (AmClusterPropListDisposable amClusterPropListDisposable2 = AmClusPropListMaker.DupeAndAppendPropListString(amClusterPropListDisposable.RawBuffer, (int)amClusterPropListDisposable.BufferSize, "Network", amClusterNetwork.Name, out num2))
                        {
                            logger.AppendLogMessage("ConfigureIPv4DhcpResources: Setting resource '{0}' to be DHCP-enabled on network '{1}' (role={2}).", new object[]
                            {
                                amClusterResource2.Name,
                                amClusterNetwork.Name,
                                amClusterNetwork.GetNativeRole()
                            });
                            amClusterResource2.SetPrivatePropertyList(amClusterPropListDisposable2);
                        }
                    }
                    AmClusterResourceHelper.SetPossibleOwnersForIpResource(logger, amClusterResource2);
                    list3.Add(amClusterResource2);
                }
                flag = true;
            }
            finally
            {
                if (!flag)
                {
                    SharedHelper.DisposeObjectList <AmClusterResource>(list2);
                }
                SharedHelper.DisposeObjectList <AmClusterResource>(array);
                SharedHelper.DisposeObjectList <AmClusterResource>(list);
                if (dictionary2 != null)
                {
                    SharedHelper.DisposeObjectList <AmClusterNetwork>(dictionary2.Values);
                }
            }
            return(list3);
        }