This repository was archived by the owner on Nov 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-vpn-ip-new
executable file
·76 lines (60 loc) · 2.77 KB
/
get-vpn-ip-new
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
import os
from typing import List
from pathlib import Path
import json
import vv_configargparse
from vv_edge_info.edge_info import get_edge_info
def write_list_to_files(input_list: List[str]):
if os.path.isfile('.tailscale-ip'):
os.remove('.tailscale-ip')
for i in input_list:
with open(".tailscale-ip", "a") as f:
f.write(i + "\n")
def split_string_into_list(string: str):
if len(string):
string = string.replace(',', " ").split()
else:
string = None
return string
def get_vpn_ip(include_api_live_inventory: bool,
allow_devices: str,
exclude_devices: str,
exclude_inventory_id: List,
stdout_json: bool = False):
allow_devices = split_string_into_list(allow_devices)
exclude_devices = split_string_into_list(exclude_devices)
edge_info = get_edge_info(include_api_live_inventory=include_api_live_inventory,
allow_devices=allow_devices,
exclude_devices=exclude_devices,
exclude_inventory_id=exclude_inventory_id).to_df()
deploy_vpn_ips = []
deploy_vpn_ips.extend(edge_info.vpn_ip.values)
if not deploy_vpn_ips:
raise Exception('배포 대상 장비가 없습니다. vpn-config.ini의 설정을 확인하세요.')
if stdout_json:
vpn_json = json.dumps(deploy_vpn_ips)
print(vpn_json)
else:
write_list_to_files(deploy_vpn_ips)
if __name__ == '__main__':
parser = vv_configargparse.get_argument_parser()
parser.add_argument('--include-api-live-inventory', action='store_true',
help='live inventory를 결과에 포함시킬지 여부.')
parser.add_argument('--allow-devices', type=str, default='',
help='결과에 포함할 디바이스 정보. comma separated list.')
parser.add_argument('--exclude-devices', type=str, default='',
help='결과에서 제외할 디바이스 정보. allow-list보다 나중에 적용됨.')
parser.add_argument('--exclude-inventory-id', action='append', default=[],
help='결과에서 제외할 인벤토리 정보. allow-list보다 나중에 적용됨.')
parser.add_argument('--stdout-json', action="store_true",
help='결과를 stdout 으로 보여준다')
args = parser.parse_args()
try:
get_vpn_ip(include_api_live_inventory=args.include_api_live_inventory,
allow_devices=args.allow_devices,
exclude_devices=args.exclude_devices,
exclude_inventory_id=args.exclude_inventory_id,
stdout_json=args.stdout_json)
except Exception as e:
raise e