Use Vagrantfile to build virtual site
[icn.git] / tools / vagrant / create_nodes_json_sample.sh
1 #!/bin/bash
2 set -eu -o pipefail
3
4 num_machines=$1
5 site=$2
6 name_prefix=$3
7
8 nodes_json_path="deploy/metal3/scripts/nodes.json.sample"
9 ipmi_host=$(virsh -c qemu:///system net-dumpxml ${site}-baremetal | xmlstarlet sel -t -v "//network/ip/@address")
10
11 cat <<EOF >${nodes_json_path}
12 {
13   "nodes": [
14 EOF
15 for ((i=1;i<=num_machines;++i)); do
16     name="${name_prefix}${i}"
17     ipmi_port=$((6230+i-1))
18     baremetal_mac=$(virsh -c qemu:///system dumpxml "${site}-${name}" | xmlstarlet sel -t -v "//interface[source/@network='${site}-baremetal']/mac/@address")
19     provisioning_mac=$(virsh -c qemu:///system dumpxml "${site}-${name}" | xmlstarlet sel -t -v "//interface[source/@network='${site}-provisioning']/mac/@address")
20     if ((i<num_machines)); then comma=","; else comma=""; fi
21     cat <<EOF >>${nodes_json_path}
22     {
23       "name": "${name}",
24       "ipmi_driver_info": {
25         "username": "admin",
26         "password": "password",
27         "address": "${ipmi_host}:${ipmi_port}"
28       },
29       "os": {
30         "image_name": "bionic-server-cloudimg-amd64.img",
31         "username": "ubuntu",
32         "password": "mypasswd"
33       },
34       "net": {
35         "links": [
36           {
37             "id": "baremetal_nic",
38             "ethernet_mac_address": "${baremetal_mac}",
39             "type": "phy"
40           },
41           {
42             "id": "provisioning_nic",
43             "ethernet_mac_address": "${provisioning_mac}",
44             "type": "phy"
45           }
46         ],
47         "networks": [
48           {
49             "id": "baremetal",
50             "link": "baremetal_nic",
51             "type": "ipv4_dhcp"
52           },
53           {
54             "id": "provisioning",
55             "link": "provisioning_nic",
56             "type": "ipv4_dhcp"
57           }
58         ],
59         "services": []
60       }
61     }${comma}
62 EOF
63 done
64 cat <<EOF >>${nodes_json_path}
65   ]
66 }
67 EOF