From 041ce106ec1167c02d3e6905df726846483668fc Mon Sep 17 00:00:00 2001 From: Brielle Bruns Date: Sun, 13 May 2018 19:50:23 -0600 Subject: [PATCH] no message --- meta-data | 3 --- network/legacy-eni | 17 ++++++++++++ virt-install-cloud.sh | 63 ++++++++++++++++++++++++++++++++----------- 3 files changed, 65 insertions(+), 18 deletions(-) create mode 100644 network/legacy-eni diff --git a/meta-data b/meta-data index 04b8e93..565430e 100644 --- a/meta-data +++ b/meta-data @@ -1,7 +1,4 @@ instance-id: iid-%GUEST_NAME%; -network-interfaces: | - allow-hotplug eth0 - iface eth0 inet dhcp hostname: %GUEST_NAME% local-hostname: %GUEST_NAME% manage_resolv_conf: false diff --git a/network/legacy-eni b/network/legacy-eni new file mode 100644 index 0000000..2c650c9 --- /dev/null +++ b/network/legacy-eni @@ -0,0 +1,17 @@ +## /network-config +--- +version: 1 +config: +- type: physical + name: eth0 + subnets: + - type: static + address: %%IP_ADDRESS%% + netmask: %%NETMASK%% + routes: + - network: 0.0.0.0 + netmask: 0.0.0.0 + gateway: %%GATEWAY%% +- type: nameserver + address: [%%NAME_SERVER%%] + search: [%%DOMAIN%%] \ No newline at end of file diff --git a/virt-install-cloud.sh b/virt-install-cloud.sh index 551c976..7222dd9 100755 --- a/virt-install-cloud.sh +++ b/virt-install-cloud.sh @@ -36,12 +36,13 @@ usage() { echo -e "\t-r ram size (in megabytes) *" echo -e "\t-c number of vcpus" echo -e "\t-b bridge to attach to *" - echo -e "\t-x network info (ip:netmask:gateway)" + echo -e "\t-x network info" + echo -e "(type:ip:netmask:gateway - type=eni/1, ip=dhcp or address, default eni dhcp)" echo -e "\t-i distribution to use (see script for supported options) - default is stretch" echo -e "\t-o OS type and variant (default: generic:generic - also set by distro option when available)" } -while getopts "c:r:s:n:d:i:o:b:h" opt; do +while getopts "c:r:s:n:d:i:o:b:x:h" opt; do case $opt in c) cpucount=$OPTARG;; r) ram=$OPTARG;; @@ -51,6 +52,7 @@ while getopts "c:r:s:n:d:i:o:b:h" opt; do i) distro=$OPTARG;; o) ostype=$OPTARG;; b) bridge=$OPTARG;; + x) netinfo=$OPTARG;; h) help="yes";; esac done @@ -62,6 +64,17 @@ if [[ -z $ram || -z $storage || -z $hostname || -z $domain || -z $bridge || $he exit 1 fi +if [[ -f ${WORKING_DIR}/config ]]; then + source ${WORKING_DIR}/config +else + echo "Error: Missing ${WORKING_DIR}/config !" + exit 1 +fi + +if [[ -f ${WORKING_DIR}/config.local ]]; then + source ${WORKING_DIR}/config.local +fi + if [[ -z $distro ]]; then distro="stretch" fi @@ -70,6 +83,22 @@ if [[ -z $cpucount ]]; then cpucount="2" fi +if [[ -z $netinfo ]]; then + netinfo="eni:dhcp" +fi + +if [[ ! -z $netinfo ]]; then + OIFS=${IFS} + IFS=: + read -ra $netinfo_config <<< "$netinfo" + virt_netinfo_type=${netinfo_config[0]} + virt_netinfo_address=${netinfo_config[1]} + virt_netinfo_netmask=${netinfo_config[2]} + virt_netinfo_gateway=${netinfo_config[3]} + IFS=${OIFS} +fi + + if [[ ! -z $ostype ]]; then OIFS=${IFS} IFS=: @@ -86,21 +115,25 @@ arch="amd64" source distros -if [[ -f ${WORKING_DIR}/config ]]; then - source ${WORKING_DIR}/config -else - echo "Error: Missing ${WORKING_DIR}/config !" - exit 1 +sed -e "s/%GUEST_NAME%/${hostname}/" ${WORKING_DIR}/meta-data > ${WORKING_DIR}/output/meta-data +sed -e "s/%FQDN%/${hostname}.${domain}/" ${WORKING_DIR}/user-data > ${WORKING_DIR}/output/user-data + +if [[ ${virt_netinfo_type} == "eni" ]]; then + cat ${WORK_DIR}/network/legacy-eni >> ${WORK_DIR}/output/meta-data + if [[ ${virt_netinfo_address} == "dhcp" ]]; then + echo " iface eth0 inet dhcp" >> ${WORK_DIR}/output/meta-data + else + echo " iface eth0 inet static" >> ${WORK_DIR}/output/meta-data + echo " address ${virt_netinfo_address}" >> ${WORK_DIR}/output/meta-data + echo " netmask ${virt_netinfo_netmask}" >> ${WORK_DIR}/output/meta-data + echo " gateway ${virt_netinfo_gateway}" >> ${WORK_DIR}/output/meta-data + fi +elif [[ $virt_netinfo_type == "1" ]]; then + echo "Not implemented yet!" +elif [[ $virt_netinfo_type == "2" ]]; then + echo "Not implemented yet!" fi -if [[ -f config.local ]]; then - source config.local -fi - -sed -e "s/%GUEST_NAME%/${hostname}/" meta-data > output/meta-data -sed -e "s/%FQDN%/${hostname}.${domain}/" user-data > output/user-data - - if [[ ! -f images/${IMG_NAME} ]]; then echo "Downloading image ${IMG_NAME}..." wget ${IMG_URL}/${IMG_NAME} -O images/${IMG_NAME}