Ejemplo n.º 1
0
        public async Task <string> RemoveDnsHostRecordIPAddresses(string reference, string[] ipAddresses)
        {
            if (!String.IsNullOrEmpty(reference))
            {
                if (ipAddresses != null && ipAddresses.Length > 0)
                {
                    List <string> IPs = new List <string>();

                    foreach (string Address in ipAddresses)
                    {
                        IPAddress IP;

                        if (NetworkAddressTest.IsIPv4Address(Address, out IP, false, true))
                        {
                            IPs.Add($"{{\"ipv4addr\":\"{IP.ToString()}\"}}");
                        }
                    }

                    string Data = $"{{\"ipv4addrs-\":[{String.Join(",", IPs)}]}}";

                    return(await base.UpdateIbxObject <host>(reference, Data));
                }
                else
                {
                    throw new ArgumentException("The IP Addresses cannot be null or empty.", "ipAddresses");
                }
            }
            else
            {
                throw new ArgumentNullException("reference", "The reference to remove an IP address from cannot be null or empty.");
            }
        }
Ejemplo n.º 2
0
        public async Task <string> SetDnsHostRecordIP(string reference, string ipAddress, bool enableDhcp = false, bool setHostName = false, string mac = "")
        {
            if (!String.IsNullOrEmpty(reference))
            {
                if (!String.IsNullOrEmpty(ipAddress))
                {
                    IPAddress IP;
                    string    MACAddress = String.Empty;

                    if (NetworkAddressTest.IsIPv4Address(ipAddress, out IP, false, true) && NetworkAddressTest.IsMAC(mac, out MACAddress, true, true))
                    {
                        string HostName = String.Empty;

                        if (setHostName)
                        {
                            host Host = await GetIbxObject <host>(reference, new string[] { "ALL" });

                            HostName = Host.name;
                        }

                        string Data = "{\"ipv4addrs\":[{\"ipv4addr\":\"" + IP.ToString() + "\"" +
                                      ",\"configure_for_dhcp\":" + ((enableDhcp) ? "true" : "false") +
                                      ((!String.IsNullOrEmpty(mac)) ? ",\"mac\":\"" + mac + "\"" : "") +
                                      ((setHostName) ? ",\"options\":[{\"name\":\"host-name\",\"num\":12,\"value\":\"" + HostName + "\"}]" : "") +
                                      "}]}";

                        return(await base.UpdateIbxObject <host>(reference, Data));
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    throw new ArgumentNullException("ipAddress", "The DNS host record IP address cannot be null or empty.");
                }
            }
            else
            {
                throw new ArgumentNullException("reference", "Reference data cannot be null or empty.");
            }
        }
Ejemplo n.º 3
0
        public async Task <string> NewDnsHostRecord(string hostName, string ipAddress, bool addToDns = true, bool enableDhcp = false, bool setHostName = false, string mac = "")
        {
            IPAddress IP;
            string    FQDN       = String.Empty;
            string    MACAddress = String.Empty;

            if (NetworkAddressTest.IsIPv4Address(ipAddress, out IP, false, true) && NetworkAddressTest.IsMAC(mac, out MACAddress, true, true) &&
                NetworkAddressTest.IsFqdn(hostName, "hostname", out FQDN, false, true))
            {
                string Data = "{\"name\":\"" + hostName + "\",\"ipv4addrs\":[{\"ipv4addr\":\"" + IP.ToString() + "\"" +
                              ((!String.IsNullOrEmpty(MACAddress)) ? ",\"mac\":\"" + MACAddress + "\"" : "") +
                              ",\"configure_for_dhcp\":" + ((enableDhcp) ? "true" : "false") +
                              ((setHostName) ? ",\"options\":[{\"name\":\"host-name\",\"num\":12,\"value\":\"" + FQDN + "\"}]" : "") +
                              "}],\"configure_for_dns\":" + addToDns.ToString().ToLower() + "}";

                return(await base.NewIbxObject(typeof(host), Data));
            }
            else
            {
                return(null);
            }
        }