Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions cf_remote/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import argparse
import os
import sys
import re
import socket

from cf_remote import log
from cf_remote import version
Expand Down Expand Up @@ -504,7 +506,7 @@ def validate_command(command, args):
if command in ["sudo", "run"]:
if len(args.remote_command) != 1:
raise CFRExitError(
"cf-remote sude/run requires exactly 1 command (use quotes)"
"cf-remote sudo/run requires exactly 1 command (use quotes)"
)
args.remote_command = args.remote_command[0]

Expand Down Expand Up @@ -613,6 +615,13 @@ def get_cloud_hosts(name, bootstrap_ips=False):
return ret


def dns_lookup(name):
try:
return bool(socket.getaddrinfo(name, 22))
except socket.gaierror as e:
raise CFRUserError("DNS lookup failed for '{}': {}".format(name, e))


def resolve_hosts(string, single=False, bootstrap_ips=False):
log.debug("resolving hosts from '{}'".format(string))
if is_file_string(string):
Expand All @@ -627,8 +636,12 @@ def resolve_hosts(string, single=False, bootstrap_ips=False):
hosts = get_cloud_hosts(name, bootstrap_ips)
ret.extend(hosts)
log.debug("found in cloud, adding '{}'".format(hosts))
else:
elif name.startswith("@"):
raise CFRUserError("'{}' does not exist.".format(name))
elif re.search(r"[@:.]", name) or dns_lookup(name):
ret.append(name)
else:
raise CFRUserError("'{}' does not exist.".format(name))

if single:
if len(ret) != 1:
Expand Down
Loading