Ejemplo n.º 1
0
        private bool SetHostEntry(ITaskItem hostEntry, IHostsFile hostsFile)
        {
            var ipAddress = hostEntry.GetMetadata("IPAddress");
            var hostName  = hostEntry.ItemSpec;
            var comment   = hostEntry.GetMetadata("Comment");

            if (string.IsNullOrEmpty(hostName))
            {
                this.Log.LogError("HostName is null or empty.");
                return(false);
            }

            if (string.IsNullOrEmpty(ipAddress))
            {
                this.Log.LogError("IPAddress is null or empty for hostname '{0}.", hostName);
                return(false);
            }

            IPAddress parsedIPAddress;

            if (!System.Net.IPAddress.TryParse(ipAddress, out parsedIPAddress))
            {
                this.Log.LogError("Invalid IP address ({0}) for hostname '{1}'.", ipAddress, hostName);
                return(false);
            }

            this.LogTaskMessage(MessageImportance.Normal, string.Format(CultureInfo.InvariantCulture, "Updating hosts entry for host {0} to IP address {1}.", hostName, ipAddress));
            hostsFile.SetHostEntry(hostName, ipAddress, comment);
            return(true);
        }
 public UpdateHostsForIngressCmdLet(IHostsFile hosts, IKubernetesCluster cluster)
 {
     Guard.IsNotNull(hosts, nameof(hosts));
     Guard.IsNotNull(cluster, nameof(cluster));
     Hosts   = hosts;
     Cluster = cluster;
 }
 public void Write(string path, IHostsFile hostsFile)
 {
     using (StreamWriter sw = new StreamWriter(path))
     {
         hostsFile.Save(sw);
     }
 }
Ejemplo n.º 4
0
 public void Write(string path, IHostsFile hostsFile)
 {
     using (StreamWriter sw = new StreamWriter(path))
     {
         hostsFile.Save(sw);
     }
 }
Ejemplo n.º 5
0
        private bool SetHostEntry(ITaskItem hostEntry, IHostsFile hostsFile)
        {
            var ipAddress = hostEntry.GetMetadata("IPAddress");
            var hostName = hostEntry.ItemSpec;
            var comment = hostEntry.GetMetadata("Comment");

            if (string.IsNullOrEmpty(hostName))
            {
                this.Log.LogError("HostName is null or empty.");
                return false;
            }

            if (string.IsNullOrEmpty(ipAddress))
            {
                this.Log.LogError("IPAddress is null or empty for hostname '{0}.", hostName);
                return false;
            }

            IPAddress parsedIPAddress;
            if (!System.Net.IPAddress.TryParse(ipAddress, out parsedIPAddress))
            {
                this.Log.LogError("Invalid IP address ({0}) for hostname '{1}'.", ipAddress, hostName);
                return false;
            }

            this.LogTaskMessage(MessageImportance.Normal, string.Format(CultureInfo.InvariantCulture, "Updating hosts entry for host {0} to IP address {1}.", hostName, ipAddress));
            hostsFile.SetHostEntry(hostName, ipAddress, comment);
            return true;
        }