-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcloud-init_functions.fish
74 lines (63 loc) · 2.37 KB
/
cloud-init_functions.fish
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
#!/usr/bin/env fish
#
# Copyright (C) 2020 Cisco Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
# @author Lori Jakab <[email protected]>
set ci_script_dir (realpath (dirname (status -f)))
function ci_get_local_ssh_pubkey
if test -r $HOME/.ssh/id_rsa.pub
set -g local_ssh_pubkey (awk '{ print $2; }' $HOME/.ssh/id_rsa.pub)
end
end
function ci_create_user_data_sdwan
set role $argv[1]
set conf sdwan.$argv[1]
set vbond (yq e ".sdwan.vbond.ctrl_static_ip" $cna_config_file)
if test "$vbond" = "null"
set vbond $argv[8]
end
if test "$argv[1]" = "vbond"
set vbond "$vbond local"
end
string match -qie vedge $role
if test $status -eq 0
set role vedge
end
set sdwan_pubkey_entry "!"
ci_get_local_ssh_pubkey
if test -n "$local_ssh_pubkey"
set sdwan_pubkey_entry "pubkey-chain automation key-string $local_ssh_pubkey"
end
set vm_name (yq e ".$conf.vm_name" $cna_config_file)
set vm_name "$sdwan_naming_prefix-$vm_name"
set site_id (yq e ".$conf.site_id" $cna_config_file)
if test "$site_id" = "null"
set site_id $sdwan_ctrl_site_id
end
env VM_NAME=$vm_name \
SDWAN_SYSTEM_IP=(yq e ".$conf.system_ip" $cna_config_file) \
SDWAN_SITE_ID=$site_id \
SDWAN_ORG=$sdwan_org_name \
SDWAN_VBOND_IP=$vbond \
SDWAN_GEO_LAT=(yq e ".sdwan.geolocation.latitude" $cna_config_file) \
SDWAN_GEO_LON=(yq e ".sdwan.geolocation.longitude" $cna_config_file) \
SDWAN_PASSWORD=$sdwan_password \
SDWAN_PUBKEY=$sdwan_pubkey_entry \
NTP_SERVER=$argv[2] \
envsubst < $ci_script_dir/cloud-init_templates/user-data-sdwan-common.tpl > $local_tempdir/user-data
env VM_GATEWAY_MGMT=$argv[3] \
VM_GATEWAY_CTRL=$argv[4] \
VM_GATEWAY_PUB=$argv[5] \
VM_GATEWAY_BIZ=$argv[6] \
IP_PREFLEN_SERVICE=$argv[7] \
envsubst < $ci_script_dir/cloud-init_templates/user-data-sdwan-$role.tpl >> $local_tempdir/user-data
end
function ci_create_user_data_linux_host
cat $ci_script_dir/cloud-init_templates/user-data-linux-common > $local_tempdir/user-data
end
function ci_create_user_data_linux_router
cat $ci_script_dir/cloud-init_templates/user-data-linux-common > $local_tempdir/user-data
cat $ci_script_dir/cloud-init_templates/user-data-linux-extra-router >> $local_tempdir/user-data
end