add new host to hosts file.

@param string The $host to be added to the hosts file
@param string The $ip   to be added along with host to hosts file

@throws RuntimeException if already exists or cant write to file

@return bool
180625
public function add($host, $ip)
    {
        $this->validHost($host);
        $this->validIp($ip);

        if ($this->check($host)) {
            throw new \RuntimeException('Host already exists in the file');
        }

        $this->backup();

        $record = "\n$ip $host";
        $file = new \SplFileObject($this->filepath, 'a');
        $ok = $file->fwrite($record);

        if (!$ok) {
            throw new \RuntimeException('Could not write to file');
        }

        return true;
    }
340659
public function removeHost(string $host)
	{
		$host = Host::filter($host);
		if( $this->offsetExists($host) ) unset( $this->hosts[$host] );
		return $this;
	}
1195019
def add_ip_to_net(networks, host):
    
    for network in networks:
        if host['ipaddr'] in network['network']:
            network['hosts'].append(host)
            return
15948
def add_new_host(self, hostname, ipv4addr, comment=None):
        
        host = Host(self.session, name=hostname)
        if host.ipv4addrs:
            host.ipv4addrs = []
        host.add_ipv4addr(ipv4addr)
        host.comment = comment
        return host.save()
8030
protected function setHost($host)
    {
        $host = strtolower($host);
        
        if ($host !== '' && !$this->isValidDomain($host) && !$this->isValidIpv4($host) && !$this->isValidIpv6($host)) {
            throw new \InvalidArgumentException("Invalid hostname '$host'");
        }
        
        $this->host = $host;
    }
615966
def hosts_append(hostsfile='/etc/hosts', ip_addr=None, entries=None):
    '''
    
    '''
    host_list = entries.split(',')
    hosts = parse_hosts(hostsfile=hostsfile)
    if ip_addr in hosts:
        for host in host_list:
            if host in hosts[ip_addr]:
                host_list.remove(host)

    if not host_list:
        return 'No additional hosts were added to {0}'.format(hostsfile)

    append_line = '\n{0} {1}'.format(ip_addr, ' '.join(host_list))
    with salt.utils.files.fopen(hostsfile, 'a') as fp_:
        fp_.write(salt.utils.stringutils.to_str(append_line))

    return 'The following line was added to {0}:{1}'.format(hostsfile,
                                                            append_line)
673025
@Override
    public final synchronized boolean addHost(Host host, boolean refresh) {
        // Already exists
        if (hosts.containsKey(host)) {
            // Check to see if we are adding token ranges or if the token ranges changed
            // which will force a rebuild of the token topology
            Host existingHost = hosts.get(host).getHost();
            if (existingHost.getTokenRanges().size() != host.getTokenRanges().size()) {
                existingHost.setTokenRanges(host.getTokenRanges());
                return true;
            }
            
            ArrayList<TokenRange> currentTokens = Lists.newArrayList(existingHost.getTokenRanges());
            ArrayList<TokenRange> newTokens     = Lists.newArrayList(host.getTokenRanges());
            Collections.sort(currentTokens, compareByStartToken);
            Collections.sort(newTokens,     compareByStartToken);
            for (int i = 0; i < currentTokens.size(); i++) {
                if (!currentTokens.get(i).getStartToken().equals(newTokens.get(i).getStartToken()) ||
                    !currentTokens.get(i).getEndToken().equals(newTokens.get(i).getEndToken())) {
                    return false;
                }
            }
            
            existingHost.setTokenRanges(host.getTokenRanges());
            return true;
        }
        else {
            HostConnectionPool<CL> pool = newHostConnectionPool(host, factory, config);
            if (null == hosts.putIfAbsent(host, pool)) {
                try {
                    monitor.onHostAdded(host, pool);
                    if (refresh) {
                        topology.addPool(pool);
                        rebuildPartitions();
                    }
                    pool.primeConnections(config.getInitConnsPerHost());
                }
                catch (Exception e) {
                    // Ignore, pool will have been marked down internally
                }
                return true;
            }
            else {
                return false;
            }
        }
    }
447611
public function setHost($host) {
        $this->host = (string) $host;
        if (empty($this->host)) {
            throw new InvalidArgumentException('empty host');
        }
        return $this;
    }
28564
public function setHost(Host $host)
    {
        $this->host = $host;

        if ($this->status != self::STATUS_NEW) {
            throw new \RuntimeException('Cannot set worker host after worker has started working');
        }
    }
1039417
public static function serializeHost($host)
    {
        if (is_int($host) || is_float($host)) {
            $string = self::serializeIPv4($host);
        } elseif (is_array($host)) {
            $string = '[' . self::serializeIPv6($host) . ']';
        } else {
            $string = (string)$host;
        }
        return $string;
    }
75589
def add_host(self, ip, mac):
		
		msg = OmapiMessage.open(b"host")
		msg.message.append((b"create", struct.pack("!I", 1)))
		msg.message.append((b"exclusive", struct.pack("!I", 1)))
		msg.obj.append((b"hardware-address", pack_mac(mac)))
		msg.obj.append((b"hardware-type", struct.pack("!I", 1)))
		msg.obj.append((b"ip-address", pack_ip(ip)))
		response = self.query_server(msg)
		if response.opcode != OMAPI_OP_UPDATE:
			raise OmapiError("add failed")
1035310
public static function tryParse(string $host): ?HostInterface
    {
        if (!self::myParse($host, $hostname, $ipAddress)) {
            return null;
        }

        return new self($hostname, $ipAddress);
    }
1123214
public function withHost(string $host): UriInterface
    {
        $instance = clone $this;
        $instance->host = $this->marshalHost($host);

        return $instance;
    }
1194065
public function execute(InputInterface $input, OutputInterface $output)
    {
        $host = $input->getArgument('host');

        $remove = $this->hostFile->remove($host);

        $output->writeLn("$host was removed from file.");
    }
880028
function SetServer ( $host, $port = 0 )
    {
        assert ( is_string($host) );
        if ( $host[0] == '/')
        {
            $this->_path = 'unix://' . $host;
            return;
        }
        if ( substr ( $host, 0, 7 )=="unix://" )
        {
            $this->_path = $host;
            return;
        }

        $this->_host = $host;
        $port = intval($port);
        assert ( 0<=$port && $port<65536 );
        $this->_port = ( $port==0 ) ? 9312 : $port;
        $this->_path = '';
    }
713831
public function setHost($host)
    {
        $this->host = trim(strtolower($host));

        if ('' === $this->host) {
            $this->merge();

            return;
        }

        if (!isset($this->cache['hosts-configuration'])) {
            $this->merge();

            return;
        }

        foreach ($this->cache['hosts-configuration'] as $hostConf) {
            if (!isset($hostConf['servername'])) {
                continue;
            }
            if ($this->match($this->host, $hostConf['servername'])) {
                $this->merge($hostConf);
                break;
            }
            if (!isset($hostConf['hosts'])) {
                continue;
            }
            foreach ((array) $hostConf['hosts'] as $hostname) {
                if ($this->match($this->host, $hostname)) {
                    $this->merge($hostConf);
                    break 2;
                }
            }
        }
    }
1020200
public function addExtension(ExtensionInterface $extension)
    {
        if ($this->initialized) {
            throw new RuntimeException(sprintf('Unable to add extension "%s" as they have already been initialized.', $extension->getName()));
        }

        $this->extensions[$extension->getName()] = $extension;
    }