add public_ip
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
27f91f80a3
commit
e22f3d4e67
2 changed files with 10 additions and 2 deletions
|
|
@ -25,6 +25,7 @@ function start_vm {
|
||||||
DEFINE_string 'subnet_name' '-' 'SUBNET NAME' 's'
|
DEFINE_string 'subnet_name' '-' 'SUBNET NAME' 's'
|
||||||
DEFINE_string 'vm_name' '-' 'VM NAME' 'm'
|
DEFINE_string 'vm_name' '-' 'VM NAME' 'm'
|
||||||
DEFINE_string 'vm_ip' '-' 'VM CIDR' 'p'
|
DEFINE_string 'vm_ip' '-' 'VM CIDR' 'p'
|
||||||
|
DEFINE_string 'public_ip' '-' 'VM Public ip' 'u'
|
||||||
DEFINE_string 'volume_id' '-' 'Volume backend file' 'o'
|
DEFINE_string 'volume_id' '-' 'Volume backend file' 'o'
|
||||||
DEFINE_string 'ssh_key' '-' 'pub ssh Key' 'k'
|
DEFINE_string 'ssh_key' '-' 'pub ssh Key' 'k'
|
||||||
DEFINE_boolean 'dryrun' false 'Enable dry-run mode' 'd'
|
DEFINE_boolean 'dryrun' false 'Enable dry-run mode' 'd'
|
||||||
|
|
@ -54,13 +55,14 @@ function start_vm {
|
||||||
print_in_color "${COLOR_SYAN}" " ip: ${vm_ip}"
|
print_in_color "${COLOR_SYAN}" " ip: ${vm_ip}"
|
||||||
print_in_color "${COLOR_SYAN}" " volume backing file: ${FLAGS_volume_id}"
|
print_in_color "${COLOR_SYAN}" " volume backing file: ${FLAGS_volume_id}"
|
||||||
print_in_color "${COLOR_SYAN}" " sshkey: ${FLAGS_ssh_key}"
|
print_in_color "${COLOR_SYAN}" " sshkey: ${FLAGS_ssh_key}"
|
||||||
|
print_in_color "${COLOR_SYAN}" " public_ip: ${FLAGS_public_ip}"
|
||||||
print_in_color "${COLOR_SYAN}" "#############################################"
|
print_in_color "${COLOR_SYAN}" "#############################################"
|
||||||
echo
|
echo
|
||||||
echo
|
echo
|
||||||
|
|
||||||
create_vpc "${FLAGS_vpc_name}"
|
create_vpc "${FLAGS_vpc_name}"
|
||||||
create_subnet "${FLAGS_vpc_name}" "${FLAGS_subnet_name}" "${FLAGS_vxlan_id}" "${local_ip}" "${gateway_ip}" "${subnet}"
|
create_subnet "${FLAGS_vpc_name}" "${FLAGS_subnet_name}" "${FLAGS_vxlan_id}" "${local_ip}" "${gateway_ip}" "${subnet}"
|
||||||
qemu_start_vm "${FLAGS_vm_ip}" "${FLAGS_subnet_name}" "${FLAGS_vpc_name}" "${FLAGS_vm_name}" "${FLAGS_volume_id}" "${FLAGS_ssh_key}" "${FLAGS_gateway_ip}"
|
qemu_start_vm "${FLAGS_vm_ip}" "${FLAGS_subnet_name}" "${FLAGS_vpc_name}" "${FLAGS_vm_name}" "${FLAGS_volume_id}" "${FLAGS_ssh_key}" "${FLAGS_gateway_ip}" "${local_ip}" "${FLAGS_public_ip}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function stop_vm {
|
function stop_vm {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
. ./lib/colors.sh
|
. ./lib/colors.sh
|
||||||
. ./lib/db.sh
|
. ./lib/db.sh
|
||||||
. ./lib/metadata.sh
|
. ./lib/metadata.sh
|
||||||
|
. ./lib/public_ip.sh
|
||||||
|
|
||||||
function check_qemu_exist {
|
function check_qemu_exist {
|
||||||
local vm_name="${1}"
|
local vm_name="${1}"
|
||||||
|
|
@ -34,6 +35,8 @@ function qemu_start_vm {
|
||||||
local volume_path="${5}"
|
local volume_path="${5}"
|
||||||
local ssh_key="${6}"
|
local ssh_key="${6}"
|
||||||
local gateway_ip="${7}"
|
local gateway_ip="${7}"
|
||||||
|
local local_ip="${8}"
|
||||||
|
local public_ip="${9}"
|
||||||
local tap_id="$(generate_random_id 10)"
|
local tap_id="$(generate_random_id 10)"
|
||||||
local metadata_port="$(generate_random_number)"
|
local metadata_port="$(generate_random_number)"
|
||||||
local subnet_id="$(echo "${subnet_name}" | cut -d\- -f2)"
|
local subnet_id="$(echo "${subnet_name}" | cut -d\- -f2)"
|
||||||
|
|
@ -46,7 +49,7 @@ function qemu_start_vm {
|
||||||
} || \
|
} || \
|
||||||
{
|
{
|
||||||
print_in_color "${COLOR_GREEN}" "Create tap tap${tap_id}"
|
print_in_color "${COLOR_GREEN}" "Create tap tap${tap_id}"
|
||||||
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}" "${public_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}:${metadata_port}"
|
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}"
|
||||||
|
|
@ -65,6 +68,7 @@ function qemu_start_vm {
|
||||||
-netdev "tap,id=net0,ifname=tap${tap_id},script=no,downscript=no" \
|
-netdev "tap,id=net0,ifname=tap${tap_id},script=no,downscript=no" \
|
||||||
-device "virtio-net-pci,netdev=net0,mac=${mac}" \
|
-device "virtio-net-pci,netdev=net0,mac=${mac}" \
|
||||||
-daemonize
|
-daemonize
|
||||||
|
add_public_ip "${vpc_name}" "${public_ip}" "${ip}" "${local_ip}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -75,6 +79,7 @@ function qemu_stop_vm {
|
||||||
local tap_id="$(echo "${vm_def}" | cut -d\; -f 3)"
|
local tap_id="$(echo "${vm_def}" | cut -d\; -f 3)"
|
||||||
local metadata_port="$(echo "${vm_def}" | cut -d\; -f 4)"
|
local metadata_port="$(echo "${vm_def}" | cut -d\; -f 4)"
|
||||||
local ip="$(echo "${vm_def}" | cut -d\; -f 5)"
|
local ip="$(echo "${vm_def}" | cut -d\; -f 5)"
|
||||||
|
local public_ip="$(echo "${vm_def}" | cut -d\; -f 6)"
|
||||||
local subnet_def=$(get_from_db "subnet" "${subnet_name}")
|
local subnet_def=$(get_from_db "subnet" "${subnet_name}")
|
||||||
local vpc_name="$(echo "${subnet_def}" | cut -d\; -f 2)"
|
local vpc_name="$(echo "${subnet_def}" | cut -d\; -f 2)"
|
||||||
local gateway_ip="$(echo "${subnet_def}" | cut -d\; -f 5 | cut -d\/ -f 1)"
|
local gateway_ip="$(echo "${subnet_def}" | cut -d\; -f 5 | cut -d\/ -f 1)"
|
||||||
|
|
@ -90,6 +95,7 @@ function qemu_stop_vm {
|
||||||
ip -n "${vpc_name}" link del dev "tap${tap_id}"
|
ip -n "${vpc_name}" link del dev "tap${tap_id}"
|
||||||
|
|
||||||
metadata_stop "${vpc_name}" "${gateway_ip}" "${metadata_port}"
|
metadata_stop "${vpc_name}" "${gateway_ip}" "${metadata_port}"
|
||||||
|
delete_public_ip "${vpc_name}" "${public_ip}" "${ip}"
|
||||||
delete_in_db "vm" "${vm_name}"
|
delete_in_db "vm" "${vm_name}"
|
||||||
|
|
||||||
print_in_color "${COLOR_GREY}" "Try to delete ${subnet_name}"
|
print_in_color "${COLOR_GREY}" "Try to delete ${subnet_name}"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue