redhat-nfvpe / base-infra-bootstrap

Generic node bootstrap for virtual KVM or baremetal
Apache License 2.0
3 stars 4 forks source link

[networking] allow for static IP assignment in spinup.sh #37

Open leifmadsen opened 6 years ago

leifmadsen commented 6 years ago

I have a lab situation where it would be really nice if I could just assign a static_ip value to the inventory items.

I've prototyped out some cloud-init stuff, and it seems to work. I need to add it all to Ansible and provide something that can be done dynamically.

leifmadsen commented 6 years ago

Raw POC (nothing dynamic here):

@@ -1,8 +1,8 @@
 #!/bin/bash

 # Take one argument from the commandline: VM name
-if [ $# -gt 3 ] || [ $# -lt 1 ]; then
-    echo "Usage: $0 <node-name> {memory-MB} {vCPUs}"
+if [ $# -gt 4 ] || [ $# -lt 1 ]; then
+    echo "Usage: $0 <node-name> {memory-MB} {vCPUs} {IP-address}"
     exit 1
 fi

@@ -94,7 +94,18 @@
   - {{ vm_ssh_key }}
 _EOF_

-    echo "instance-id: $1; local-hostname: $1" > $META_DATA
+    cat > $META_DATA << _EOF_
+instance-id: $1
+local-hostname: $1
+network-interfaces: |
+  auto eth0
+  iface eth0 inet static
+    address $4
+    network 192.168.3.0
+    netmask 255.255.255.0
+    broadcast 192.168.3.255
+    gateway 192.168.3.1
+_EOF_

     echo "$(date -R) Copying template image..."
     cp $IMAGE $DISK