Example #1
0
        private void ParseInterfaces(XElement configNode)
        {
            var physicalInterfaces = configNode.XPathSelectElements("./interfaces/interface");

            foreach (var physicalInterface in physicalInterfaces)
            {
                // For a valid interface there should be at least one IP address node...
                if (physicalInterface.XPathSelectElement("./unit/family/inet/address/name") == null)
                {
                    continue;
                }

                // Use a temporary object to parse a name from the parent physical interface node.
                var tempObject = new JuniperObject();
                tempObject.Parse(physicalInterface, null);

                var logicalInterfaces = physicalInterface.Elements("unit");
                foreach (var logicalInterface in logicalInterfaces)
                {
                    JuniperObject juniperInterface = new Juniper_Interface();
                    juniperInterface.Parse(logicalInterface, null);
                    juniperInterface.Name = string.Format("{0}.{1}", tempObject.Name, juniperInterface.Name);
                    _juniperObjects.Add(juniperInterface);
                }
            }
        }
Example #2
0
        private void ParseAddresses(IEnumerable <XElement> addresses, string zoneName)
        {
            foreach (var address in addresses)
            {
                var dnsName      = address.Element("dns-name");
                var ipPrefix     = address.Element("ip-prefix");
                var rengeAddress = address.Element("range-address");

                JuniperObject juniperObject = null;

                if (dnsName != null)
                {
                    juniperObject = new Juniper_Fqdn();
                }
                else if (ipPrefix != null)
                {
                    if (IsHostObject(ipPrefix.Value))
                    {
                        juniperObject = new Juniper_Host();
                    }
                    else
                    {
                        juniperObject = new Juniper_Network();
                    }
                }
                else if (rengeAddress != null)
                {
                    juniperObject = new Juniper_Range();
                }

                if (juniperObject != null)
                {
                    juniperObject.Parse(address, zoneName);
                    _juniperObjects.Add(juniperObject);

                    HandleDuplicatedAddressName(juniperObject.Name, zoneName);
                }
            }
        }
Example #3
0
        private void ParseApplication(XElement application)
        {
            JuniperObject juniperObject;

            var terms = application.Elements("term").ToList();

            if (terms.Count > 0)
            {
                // Use a temporary object to parse name and description from the parent application node.
                var termApplicationObject = new JuniperObject();
                termApplicationObject.Parse(application, null);

                if (terms.Count > 1)
                {
                    // Create a group only for multiple terms!!!
                    var members = new List <string>();

                    foreach (var term in terms)
                    {
                        juniperObject = new Juniper_Application {
                            LineNumber = ((IXmlLineInfo)term).LineNumber
                        };
                        ((Juniper_Application)juniperObject).IsJunosDefault = termApplicationObject.Name.StartsWith("junos-");   // must come before parsing!!!
                        ((Juniper_Application)juniperObject).ParseFromTerm(term, true);
                        _juniperObjects.Add(juniperObject);

                        members.Add(juniperObject.Name);
                    }

                    juniperObject = new Juniper_ApplicationGroup
                    {
                        Name        = termApplicationObject.Name,
                        Description = termApplicationObject.Description,
                        LineNumber  = termApplicationObject.LineNumber,
                    };

                    ((Juniper_ApplicationGroup)juniperObject).IsJunosDefault = termApplicationObject.Name.StartsWith("junos-");
                    ((Juniper_ApplicationGroup)juniperObject).Members.AddRange(members);   // add the members manually
                    _juniperObjects.Add(juniperObject);
                }
                else
                {
                    juniperObject = new Juniper_Application
                    {
                        Name        = termApplicationObject.Name,
                        Description = termApplicationObject.Description,
                        LineNumber  = termApplicationObject.LineNumber
                    };

                    ((Juniper_Application)juniperObject).IsJunosDefault = termApplicationObject.Name.StartsWith("junos-");   // must come before parsing!!!
                    ((Juniper_Application)juniperObject).ParseFromTerm(terms[0], false);
                    _juniperObjects.Add(juniperObject);
                }
            }
            else
            {
                juniperObject = new Juniper_Application();
                juniperObject.Parse(application, null);
                _juniperObjects.Add(juniperObject);
            }
        }