fix error in metadata redirect
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
f45ebbf1b6
commit
7d3db06f27
4 changed files with 8 additions and 13 deletions
1
agent.sh
1
agent.sh
|
|
@ -120,6 +120,7 @@ function main {
|
||||||
;;
|
;;
|
||||||
"Config")
|
"Config")
|
||||||
metadata_service
|
metadata_service
|
||||||
|
systemctl daemon-reload
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "action : ${fonction} not known !"
|
echo "action : ${fonction} not known !"
|
||||||
|
|
|
||||||
|
|
@ -33,11 +33,6 @@ function generate_dhcp_file {
|
||||||
subnet="$(echo "${cidr}" | cut -d\/ -f1)"
|
subnet="$(echo "${cidr}" | cut -d\/ -f1)"
|
||||||
output_file="/etc/dnsmasq.d/${2}.conf"
|
output_file="/etc/dnsmasq.d/${2}.conf"
|
||||||
|
|
||||||
if [ -z "$cidr" ]; then
|
|
||||||
echo "Veuillez fournir un CIDR en argument, par exemple '10.10.10.0/24'."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Extraire l'adresse de réseau et le masque
|
# Extraire l'adresse de réseau et le masque
|
||||||
IFS='/' read -r network mask <<< "$cidr"
|
IFS='/' read -r network mask <<< "$cidr"
|
||||||
network_int=$(ip_to_int "$network")
|
network_int=$(ip_to_int "$network")
|
||||||
|
|
@ -91,6 +86,4 @@ function generate_dhcp_file {
|
||||||
mac_incr=$((mac_incr + 1)) # Incrémenter l'adresse MAC
|
mac_incr=$((mac_incr + 1)) # Incrémenter l'adresse MAC
|
||||||
ip_incr=$((ip_incr + 1)) # Incrémenter l'adresse IP
|
ip_incr=$((ip_incr + 1)) # Incrémenter l'adresse IP
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Fichier de réservations DHCP généré à $output_file"
|
|
||||||
}
|
}
|
||||||
|
|
@ -15,6 +15,7 @@ function metadata_config() {
|
||||||
|
|
||||||
VENDOR_DATA=$(
|
VENDOR_DATA=$(
|
||||||
cat <<END | sed -e ':a;N;$!ba;s/\n/\\n/g' | sed -e 's/"/\\"/g'
|
cat <<END | sed -e ':a;N;$!ba;s/\n/\\n/g' | sed -e 's/"/\\"/g'
|
||||||
|
#cloud-config
|
||||||
users:
|
users:
|
||||||
- name: syonad
|
- name: syonad
|
||||||
lock_passwd: true
|
lock_passwd: true
|
||||||
|
|
@ -43,11 +44,11 @@ END
|
||||||
}
|
}
|
||||||
|
|
||||||
function metadata_start() {
|
function metadata_start() {
|
||||||
vpc="${1}"
|
local vpc="${1}"
|
||||||
ip="${2}"
|
local ip="${2}"
|
||||||
port="${3}"
|
local port="${3}"
|
||||||
vm_name="${4}"
|
local vm_name="${4}"
|
||||||
ssh_key="${5}"
|
local ssh_key="${5}"
|
||||||
|
|
||||||
|
|
||||||
metadata_config "${vm_name}" "${vpc}_${ip}-${port}" "${ssh_key}"
|
metadata_config "${vm_name}" "${vpc}_${ip}-${port}" "${ssh_key}"
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ function qemu_start_vm {
|
||||||
add_in_db "vm" "${vm_name}" "${subnet_name}" "${tap_id}" "${metadata_port}" "${ip}"
|
add_in_db "vm" "${vm_name}" "${subnet_name}" "${tap_id}" "${metadata_port}" "${ip}"
|
||||||
create_tap "${tap_id}" "br-${subnet_id}" "${vpc_name}"
|
create_tap "${tap_id}" "br-${subnet_id}" "${vpc_name}"
|
||||||
metadata_start "${vpc_name}" "${gateway_ip}" "${metadata_port}" "${vm_name}" "${ssh_key}"
|
metadata_start "${vpc_name}" "${gateway_ip}" "${metadata_port}" "${vm_name}" "${ssh_key}"
|
||||||
ip netns exec "${vpc_name}" iptables -t nat -A PREROUTING -s "${ip}/32" -d "169.254.169.254/32" -p tcp -m tcp --dport 80 -j DNAT --to-destination "${gateway_ip}:8080"
|
ip netns exec "${vpc_name}" iptables -t nat -A PREROUTING -s "${ip}/32" -d "169.254.169.254/32" -p tcp -m tcp --dport 80 -j DNAT --to-destination "${gateway_ip}:${metadata_port}"
|
||||||
|
|
||||||
print_in_color "${COLOR_GREEN}" "Start vm ${vm_name}"
|
print_in_color "${COLOR_GREEN}" "Start vm ${vm_name}"
|
||||||
ip netns exec "${vpc_name}" qemu-system-x86_64 \
|
ip netns exec "${vpc_name}" qemu-system-x86_64 \
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue