Added tailscale support

This commit is contained in:
Prass, The Nomadic Coder 2024-02-21 12:13:59 +00:00
parent 39df1c1735
commit 39c5976a57
2 changed files with 33 additions and 0 deletions

View File

@ -562,6 +562,7 @@ def clone_task(state, project_id=None):
task_params["{}/vscode_version".format(section)] = state.get('vscode_version') or '' task_params["{}/vscode_version".format(section)] = state.get('vscode_version') or ''
task_params["{}/vscode_extensions".format(section)] = state.get('vscode_extensions') or '' task_params["{}/vscode_extensions".format(section)] = state.get('vscode_extensions') or ''
task_params["{}/force_dropbear".format(section)] = bool(state.get('force_dropbear')) task_params["{}/force_dropbear".format(section)] = bool(state.get('force_dropbear'))
task_params["{}/tailscale".format(section)] = bool(state.get('tailscale'))
if state.get('user_folder'): if state.get('user_folder'):
task_params['{}/user_base_directory'.format(section)] = state.get('user_folder') task_params['{}/user_base_directory'.format(section)] = state.get('user_folder')
docker = state.get('docker') or task.get_base_docker() docker = state.get('docker') or task.get_base_docker()
@ -1087,6 +1088,9 @@ def setup_parser(parser):
action='store_true', default=False, action='store_true', default=False,
help='Automatic yes to prompts; assume \"yes\" as answer ' help='Automatic yes to prompts; assume \"yes\" as answer '
'to all prompts and run non-interactively',) 'to all prompts and run non-interactively',)
parser.add_argument('--tailscale',
action='store_true', default=False,
help='Use tailscale to network (host and client need tailscale access)',)
def get_version(): def get_version():

View File

@ -1,4 +1,5 @@
import base64 import base64
import ipaddress
import json import json
import os import os
import socket import socket
@ -910,6 +911,33 @@ def setup_user_env(param, task):
def get_host_name(task, param): def get_host_name(task, param):
hostname = []
hostnames = []
if task.get_parameter(name='interactive_session/tailscale'):
def get_tailscale_interfaces():
interfaces = psutil.net_if_addrs()
tailscale_address = None
for interface_name, interface_addresses in interfaces.items():
for address in interface_addresses:
if "tailscale" in interface_name:
print(address)
try:
ipaddress.IPv4Address(address.address)
except ValueError:
pass
else:
tailscale_address = address.address
return tailscale_address
tl_addr = get_tailscale_interfaces()
if tl_addr:
hostname = tl_addr
hostnames = tl_addr
task.set_parameter(name='properties/external_address', value=str(tl_addr))
return hostname, hostnames
# noinspection PyBroadException # noinspection PyBroadException
try: try:
hostname = socket.gethostname() hostname = socket.gethostname()
@ -1014,6 +1042,7 @@ def main():
"public_ip": False, "public_ip": False,
"ssh_ports": None, "ssh_ports": None,
"force_dropbear": False, "force_dropbear": False,
"tailscale": False
} }
task = init_task(param, default_ssh_fingerprint) task = init_task(param, default_ssh_fingerprint)