summaryrefslogtreecommitdiffstats
path: root/create_vm.sh
diff options
context:
space:
mode:
authorRihab Banday <rihab.banday@ericsson.com>2020-07-21 10:49:45 +0000
committerRihab Banday <rihab.banday@ericsson.com>2020-07-29 15:49:40 +0000
commitaf104f92b348c51e20f5fbf3be78f532864804ab (patch)
tree9cd3cac840ad665071fb6d80b6be058ff5f5bbfd /create_vm.sh
parentbef45268b994c845859f08b40f276dfeef33276f (diff)
Initial structure for e2e deployment scripting
This patch includes the initial skeleton of the e2e deployment tooling. This is expected to evolve as further development progresses. Change-Id: Ie1e334e672acb2213e8f6c2174506b685f826f98 Signed-off-by: Rihab Banday <rihab.banday@ericsson.com>
Diffstat (limited to 'create_vm.sh')
-rwxr-xr-xcreate_vm.sh40
1 files changed, 40 insertions, 0 deletions
diff --git a/create_vm.sh b/create_vm.sh
new file mode 100755
index 0000000..39bc38f
--- /dev/null
+++ b/create_vm.sh
@@ -0,0 +1,40 @@
+#!/bin/bash
+# SPDX-license-identifier: Apache-2.0
+##############################################################################
+# Copyright (c)
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+# TODO This will be merged in main functions.sh
+
+sudo mkdir -p /var/lib/libvirt/images/$1
+sudo qemu-img create -f qcow2 \
+ -o backing_file=/var/lib/libvirt/images/ubuntu-18.04.qcow2 \
+ /var/lib/libvirt/images/$1/"$1".qcow2 10G
+
+# Create cloud-init configuration files
+cat <<EOL > user-data
+#cloud-config
+users:
+ - name: ubuntu
+ ssh-authorized-keys:
+ - $(cat $HOME/.ssh/id_rsa.pub)
+ sudo: ['ALL=(ALL) NOPASSWD:ALL']
+ groups: sudo
+ shell: /bin/bash
+EOL
+cat <<EOL > meta-data
+local-hostname: $VM_NAME
+EOL
+
+sudo genisoimage -output /var/lib/libvirt/images/$1/"$1"-cidata.iso \
+ -volid cidata -joliet -rock user-data meta-data
+
+sudo virt-install --connect qemu:///system --name $VM_NAME \
+ --ram 4096 --vcpus=4 --os-type linux --os-variant ubuntu16.04 \
+ --disk path=/var/lib/libvirt/images/$1/"$1".qcow2,format=qcow2 \
+ --disk /var/lib/libvirt/images/$1/"$1"-cidata.iso,device=cdrom \
+ --import --network network=default --network bridge=$BRIDGE,model=rtl8139 --noautoconsole