Esempio n. 1
0
        public static void ValidateIpv4Networks(IAmCluster cluster, string[] ipv4Networks)
        {
            for (int i = 0; i < ipv4Networks.Length - 1; i++)
            {
                for (int j = i + 1; j < ipv4Networks.Length; j++)
                {
                    if (SharedHelper.StringIEquals(ipv4Networks[i], ipv4Networks[j]))
                    {
                        throw new IPv4NetworksHasDuplicateEntries(ipv4Networks[i]);
                    }
                }
            }
            Dictionary <string, AmClusterNetwork> ipv4DhcpNetworkMap = AmClusterResourceHelper.GetIpv4DhcpNetworkMap(cluster, ipv4Networks);

            if (ipv4DhcpNetworkMap != null)
            {
                SharedHelper.DisposeObjectList <AmClusterNetwork>(ipv4DhcpNetworkMap.Values);
            }
        }
Esempio n. 2
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);
        }