From 53e6316692037ccdb893446f3a61caedad20b2eb Mon Sep 17 00:00:00 2001 From: Robert Volkmann Date: Mon, 22 Jul 2024 09:28:23 +0200 Subject: [PATCH 1/4] Add target for second machine and introduce different naming convention * vm0X are the VMs running inside of vms * machine0X are provisioned machines * firewall is a provisioned firewall --- Makefile | 132 ++++++++++++++++++++++++------------------ README.md | 2 +- scripts/manage_vms.py | 18 +++--- test/integration.sh | 4 +- 4 files changed, 89 insertions(+), 67 deletions(-) diff --git a/Makefile b/Makefile index 8432bfa4..d2bb1e52 100644 --- a/Makefile +++ b/Makefile @@ -23,11 +23,9 @@ MAX_RETRIES := 30 # Machine flavors ifeq ($(MINI_LAB_FLAVOR),cumulus) -LAB_MACHINES=machine01,machine02 LAB_TOPOLOGY=mini-lab.cumulus.yaml VRF=vrf20 else ifeq ($(MINI_LAB_FLAVOR),sonic) -LAB_MACHINES=machine01,machine02 LAB_TOPOLOGY=mini-lab.sonic.yaml VRF=Vrf20 else @@ -49,7 +47,8 @@ endif up: env control-plane-bake partition-bake @chmod 600 files/ssh/id_rsa docker compose up --remove-orphans --force-recreate control-plane partition - @$(MAKE) --no-print-directory start-machines + @$(MAKE) --no-print-directory start-vm01 + @$(MAKE) --no-print-directory start-vm02 # for some reason an allocated machine will not be able to phone home # without restarting the metal-core # TODO: should be investigated and fixed if possible @@ -126,18 +125,20 @@ cleanup-partition: _privatenet: env docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network list --name user-private-network | grep user-private-network || docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network allocate --partition mini-lab --project 00000000-0000-0000-0000-000000000001 --name user-private-network -.PHONY: _public_ips -_public_ips: env +.PHONY: firewall +firewall: _privatenet docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network ip list --name firewall | grep firewall || docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network ip create --network internet-mini-lab --project 00000000-0000-0000-0000-000000000001 --ipaddress 203.0.113.129 --name firewall - docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network ip list --name machine | grep machine || docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network ip create --network internet-mini-lab --project 00000000-0000-0000-0000-000000000001 --ipaddress 203.0.113.130 --name machine + docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl firewall create --description firewall --name firewall --hostname firewall --project 00000000-0000-0000-0000-000000000001 --partition mini-lab --image firewall-ubuntu-3.0 --size v1-small-x86 --userdata "@/tmp/ignition.json" --ips 203.0.113.129 --firewall-rules-file=/tmp/rules.yaml --networks internet-mini-lab,$(shell docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network list --name user-private-network -o template --template '{{ .id }}') -.PHONY: machine -machine: _privatenet _public_ips - docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl machine create --description test --name test --hostname test --project 00000000-0000-0000-0000-000000000001 --partition mini-lab --image $(MACHINE_OS) --size v1-small-x86 --userdata "@/tmp/ignition.json" --ips 203.0.113.130 --networks internet-mini-lab,$(shell docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network list --name user-private-network -o template --template '{{ .id }}') +.PHONY: machine01 +machine01: _privatenet + docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network ip list --name machine01 | grep machine01 || docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network ip create --network internet-mini-lab --project 00000000-0000-0000-0000-000000000001 --ipaddress 203.0.113.130 --name machine01 + docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl machine create --description machine01 --name machine01 --hostname machine01 --project 00000000-0000-0000-0000-000000000001 --partition mini-lab --image $(MACHINE_OS) --size v1-small-x86 --userdata "@/tmp/ignition.json" --ips 203.0.113.130 --networks internet-mini-lab,$(shell docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network list --name user-private-network -o template --template '{{ .id }}') -.PHONY: firewall -firewall: _privatenet _public_ips - docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl firewall create --description fw --name fw --hostname fw --project 00000000-0000-0000-0000-000000000001 --partition mini-lab --image firewall-ubuntu-3.0 --size v1-small-x86 --userdata "@/tmp/ignition.json" --ips 203.0.113.129 --firewall-rules-file=/tmp/rules.yaml --networks internet-mini-lab,$(shell docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network list --name user-private-network -o template --template '{{ .id }}') +.PHONY: machine02 +machine02: _privatenet + docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network ip list --name machine02 | grep machine02 || docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network ip create --network internet-mini-lab --project 00000000-0000-0000-0000-000000000001 --ipaddress 203.0.113.131 --name machine02 + docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl machine create --description machine02 --name machine02 --hostname machine02 --project 00000000-0000-0000-0000-000000000001 --partition mini-lab --image $(MACHINE_OS) --size v1-small-x86 --userdata "@/tmp/ignition.json" --ips 203.0.113.131 --networks internet-mini-lab,$(shell docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network list --name user-private-network -o template --template '{{ .id }}') .PHONY: ls ls: env @@ -166,75 +167,96 @@ ssh-leaf01: ssh-leaf02: ssh -o StrictHostKeyChecking=no -o "PubkeyAcceptedKeyTypes +ssh-rsa" -i files/ssh/id_rsa root@leaf02 -## MACHINE MANAGEMENT ## +## MACHINE VM MANAGEMENT ## + +.PHONY: start-vm01 +start-vm01: + docker exec vms /mini-lab/manage_vms.py --names vm01 create -.PHONY: start-machines -start-machines: - docker exec vms /mini-lab/manage_vms.py --names $(LAB_MACHINES) create +.PHONY: start-vm02 +start-vm02: + docker exec vms /mini-lab/manage_vms.py --names vm02 create + +.PHONY: start-vm03 +start-vm03: + docker exec vms /mini-lab/manage_vms.py --names vm03 create .PHONY: _password _password: env docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl machine consolepassword $(MACHINE_UUID) -.PHONY: password-machine01 -password-machine01: - @$(MAKE) --no-print-directory _password MACHINE_UUID=e0ab02d2-27cd-5a5e-8efc-080ba80cf258 +.PHONY: password-vm01 +password-vm01: + @$(MAKE) --no-print-directory _password MACHINE_UUID=e0ab02d2-27cd-5a5e-8efc-080ba80cf258 -.PHONY: password-machine02 -password-machine02: - @$(MAKE) --no-print-directory _password MACHINE_UUID=2294c949-88f6-5390-8154-fa53d93a3313 +.PHONY: password-vm02 +password-vm02: + @$(MAKE) --no-print-directory _password MACHINE_UUID=2294c949-88f6-5390-8154-fa53d93a3313 -.PHONY: password-machine03 -password-machine03: - @$(MAKE) --no-print-directory _password MACHINE_UUID=2a92f14d-d3b1-4d46-b813-5d058103743e +.PHONY: password-vm03 +password-vm03: + @$(MAKE) --no-print-directory _password MACHINE_UUID=2a92f14d-d3b1-4d46-b813-5d058103743e -.PHONY: _free-machine -_free-machine: env +.PHONY: _free_vm +_free_vm: env docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl machine rm $(MACHINE_UUID) - docker exec vms /mini-lab/manage_vms.py --names $(MACHINE_NAME) kill --with-disks - docker exec vms /mini-lab/manage_vms.py --names $(MACHINE_NAME) create + docker exec vms /mini-lab/manage_vms.py --names $(VM_NAME) kill --with-disks + docker exec vms /mini-lab/manage_vms.py --names $(VM_NAME) create -.PHONY: free-machine01 -free-machine01: - @$(MAKE) --no-print-directory _free-machine MACHINE_NAME=machine01 MACHINE_UUID=e0ab02d2-27cd-5a5e-8efc-080ba80cf258 +.PHONY: free-vm01 +free-vm01: + @$(MAKE) --no-print-directory _free_vm VM_NAME=vm01 MACHINE_UUID=e0ab02d2-27cd-5a5e-8efc-080ba80cf258 -.PHONY: free-machine02 -free-machine02: - @$(MAKE) --no-print-directory _free-machine MACHINE_NAME=machine02 MACHINE_UUID=2294c949-88f6-5390-8154-fa53d93a3313 +.PHONY: free-vm02 +free-vm02: + @$(MAKE) --no-print-directory _free_vm VM_NAME=vm02 MACHINE_UUID=2294c949-88f6-5390-8154-fa53d93a3313 -.PHONY: free-machine03 -free-machine03: - @$(MAKE) --no-print-directory _free-machine MACHINE_NAME=machine03 MACHINE_UUID=2a92f14d-d3b1-4d46-b813-5d058103743e +.PHONY: free-vm03 +free-vm03: + @$(MAKE) --no-print-directory _free_vm VM_NAME=vm03 MACHINE_UUID=2a92f14d-d3b1-4d46-b813-5d058103743e -.PHONY: _console-machine -_console-machine: +.PHONY: _console-vm +_console-vm: @echo "exit console with CTRL+5 and then quit telnet through q + ENTER" @docker exec -it vms telnet 127.0.0.1 $(CONSOLE_PORT) -.PHONY: console-machine01 -console-machine01: - @$(MAKE) --no-print-directory _console-machine CONSOLE_PORT=4000 +.PHONY: console-vm01 +console-vm01: + @$(MAKE) --no-print-directory _console-vm CONSOLE_PORT=4000 -.PHONY: console-machine02 -console-machine02: - @$(MAKE) --no-print-directory _console-machine CONSOLE_PORT=4001 +.PHONY: console-vm02 +console-vm02: + @$(MAKE) --no-print-directory _console-vm CONSOLE_PORT=4001 -.PHONY: console-machine03 -console-machine03: - @$(MAKE) --no-print-directory _console-machine CONSOLE_PORT=4002 +.PHONY: console-vm03 +console-vm03: + @$(MAKE) --no-print-directory _console-vm CONSOLE_PORT=4002 ## SSH TARGETS FOR MACHINES ## # Python code could be replaced by jq, but it is not preinstalled on Cumulus +define get-ipv6-link-local-address + $(shell ssh -F files/ssh/config leaf01 "vtysh -c 'show bgp $(if $(2),vrf $(2) )neighbors $(1) json' | \ + python3 -c 'import sys, json; data = json.load(sys.stdin); key = next(iter(data)); print(data[key][\"bgpNeighborAddr\"] + \"%\" + key)'" \ + ) +endef + .PHONY: ssh-firewall ssh-firewall: - $(eval fw = $(shell ssh -F files/ssh/config leaf01 "vtysh -c 'show bgp neighbors fw json' | \ + $(eval firewall = $(shell ssh -F files/ssh/config leaf01 "vtysh -c 'show bgp neighbors firewall json' | \ python3 -c 'import sys, json; data = json.load(sys.stdin); key = next(iter(data)); print(data[key][\"bgpNeighborAddr\"] + \"%\" + key)'" \ )) - ssh -F files/ssh/config $(fw) $(COMMAND) + ssh -F files/ssh/config $(firewall) $(COMMAND) + +.PHONY: ssh-machine01 +ssh-machine01: + $(eval machine = $(shell ssh -F files/ssh/config leaf01 "vtysh -c 'show bgp vrf $(VRF) neighbors machine01 json' | \ + python3 -c 'import sys, json; data = json.load(sys.stdin); key = next(iter(data)); print(data[key][\"bgpNeighborAddr\"] + \"%\" + key)'" \ + )) + ssh -F files/ssh/config $(machine) $(COMMAND) -.PHONY: ssh-machine -ssh-machine: - $(eval machine = $(shell ssh -F files/ssh/config leaf01 "vtysh -c 'show bgp vrf $(VRF) neighbors test json' | \ +.PHONY: ssh-machine02 +ssh-machine02: + $(eval machine = $(shell ssh -F files/ssh/config leaf01 "vtysh -c 'show bgp vrf $(VRF) neighbors machine02 json' | \ python3 -c 'import sys, json; data = json.load(sys.stdin); key = next(iter(data)); print(data[key][\"bgpNeighborAddr\"] + \"%\" + key)'" \ )) ssh -F files/ssh/config $(machine) $(COMMAND) @@ -243,7 +265,7 @@ ssh-machine: connect-to-cloudflare: @echo "Attempting to connect to Cloudflare..." @for i in $$(seq 1 $(MAX_RETRIES)); do \ - if $(MAKE) ssh-machine COMMAND="sudo curl --connect-timeout 1 --fail --silent https://1.1.1.1" > /dev/null 2>&1; then \ + if $(MAKE) ssh-machine01 COMMAND="sudo curl --connect-timeout 1 --fail --silent https://1.1.1.1" > /dev/null 2>&1; then \ echo "Connected successfully"; \ exit 0; \ else \ diff --git a/README.md b/README.md index c18c448e..f2abd931 100644 --- a/README.md +++ b/README.md @@ -185,7 +185,7 @@ docker compose run --rm metalctl machine reinstall \ ### Free machine -Free a machine with `make free-machine01` or +Free a machine with `make free-vm01` or ```bash docker compose run --rm metalctl machine rm e0ab02d2-27cd-5a5e-8efc-080ba80cf258 diff --git a/scripts/manage_vms.py b/scripts/manage_vms.py index a3b86d3a..83a09037 100755 --- a/scripts/manage_vms.py +++ b/scripts/manage_vms.py @@ -7,28 +7,28 @@ import sys VMS = { - "machine01": { - "name": "machine01", + "vm01": { + "name": "vm01", "uuid": "e0ab02d2-27cd-5a5e-8efc-080ba80cf258", - "disk-path": "/machine01.img", + "disk-path": "/vm01.img", "disk-size": "5G", "memory": "2G", "tap-index-fd": [(0, 30), (1, 40)], "serial-port": 4000, }, - "machine02": { - "name": "machine02", + "vm02": { + "name": "vm02", "uuid": "2294c949-88f6-5390-8154-fa53d93a3313", - "disk-path": "/machine02.img", + "disk-path": "/vm02.img", "disk-size": "5G", "memory": "2G", "tap-index-fd": [(2, 50), (3, 60)], "serial-port": 4001, }, - "machine03": { - "name": "machine03", + "vm03": { + "name": "vm03", "uuid": "2a92f14d-d3b1-4d46-b813-5d058103743e", - "disk-path": "/machine03.img", + "disk-path": "/vm03.img", "disk-size": "5G", "memory": "2G", "tap-index-fd": [(4, 70), (5, 80)], diff --git a/test/integration.sh b/test/integration.sh index bb6fae07..7423647e 100755 --- a/test/integration.sh +++ b/test/integration.sh @@ -21,9 +21,9 @@ do done echo "$waiting/$minWaiting machines are waiting" -echo "Create firewall and machine" +echo "Create firewall and machine01" make firewall -make machine +make machine01 echo "Waiting for machines to get to Phoned Home state" phoned=$(docker compose run -T metalctl machine ls | grep Phoned | wc -l) From f173701f7dbc69008e9f8fa2693a2c64826e5695 Mon Sep 17 00:00:00 2001 From: Robert Volkmann Date: Mon, 22 Jul 2024 17:26:15 +0200 Subject: [PATCH 2/4] Reduce code duplication --- Makefile | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index d2bb1e52..48057a2a 100644 --- a/Makefile +++ b/Makefile @@ -125,20 +125,35 @@ cleanup-partition: _privatenet: env docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network list --name user-private-network | grep user-private-network || docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network allocate --partition mini-lab --project 00000000-0000-0000-0000-000000000001 --name user-private-network +define create_public_ip + docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network ip list --name $(1) | grep $(1) || docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network ip create --network internet-mini-lab --project 00000000-0000-0000-0000-000000000001 --ipaddress $(2) --name $(1) +endef + +define private_net_id + docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network list --name user-private-network -o template --template '{{ .id }}' +endef + +define create_common_args + --description $(1) --name $(1) --hostname $(1) --project 00000000-0000-0000-0000-000000000001 --partition mini-lab --size v1-small-x86 --userdata "@/tmp/ignition.json" +endef + .PHONY: firewall firewall: _privatenet - docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network ip list --name firewall | grep firewall || docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network ip create --network internet-mini-lab --project 00000000-0000-0000-0000-000000000001 --ipaddress 203.0.113.129 --name firewall - docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl firewall create --description firewall --name firewall --hostname firewall --project 00000000-0000-0000-0000-000000000001 --partition mini-lab --image firewall-ubuntu-3.0 --size v1-small-x86 --userdata "@/tmp/ignition.json" --ips 203.0.113.129 --firewall-rules-file=/tmp/rules.yaml --networks internet-mini-lab,$(shell docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network list --name user-private-network -o template --template '{{ .id }}') + $(call create_public_ip,firewall,203.0.113.129) + docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl firewall create $(create_common_args,firewall) \ + --firewall-rules-file=/tmp/rules.yaml --image firewall-ubuntu-3.0 --ips 203.0.113.129 --networks internet-mini-lab,$(call private_net_id) .PHONY: machine01 machine01: _privatenet - docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network ip list --name machine01 | grep machine01 || docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network ip create --network internet-mini-lab --project 00000000-0000-0000-0000-000000000001 --ipaddress 203.0.113.130 --name machine01 - docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl machine create --description machine01 --name machine01 --hostname machine01 --project 00000000-0000-0000-0000-000000000001 --partition mini-lab --image $(MACHINE_OS) --size v1-small-x86 --userdata "@/tmp/ignition.json" --ips 203.0.113.130 --networks internet-mini-lab,$(shell docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network list --name user-private-network -o template --template '{{ .id }}') + $(call create_public_ip,machine01,203.0.113.130) + docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl machine create $(create_common_args,machine01) \ + --image $(MACHINE_OS) --ips 203.0.113.130 --networks internet-mini-lab,$(call private_net_id) .PHONY: machine02 machine02: _privatenet - docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network ip list --name machine02 | grep machine02 || docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network ip create --network internet-mini-lab --project 00000000-0000-0000-0000-000000000001 --ipaddress 203.0.113.131 --name machine02 - docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl machine create --description machine02 --name machine02 --hostname machine02 --project 00000000-0000-0000-0000-000000000001 --partition mini-lab --image $(MACHINE_OS) --size v1-small-x86 --userdata "@/tmp/ignition.json" --ips 203.0.113.131 --networks internet-mini-lab,$(shell docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network list --name user-private-network -o template --template '{{ .id }}') + $(call create_public_ip,machine02,203.0.113.131) + docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl machine create $(create_common_args,machine02,203.0.113.131) \ + --image $(MACHINE_OS) --ips 203.0.113.131 --networks internet-mini-lab,$(call private_net_id) .PHONY: ls ls: env @@ -242,24 +257,18 @@ endef .PHONY: ssh-firewall ssh-firewall: - $(eval firewall = $(shell ssh -F files/ssh/config leaf01 "vtysh -c 'show bgp neighbors firewall json' | \ - python3 -c 'import sys, json; data = json.load(sys.stdin); key = next(iter(data)); print(data[key][\"bgpNeighborAddr\"] + \"%\" + key)'" \ - )) - ssh -F files/ssh/config $(firewall) $(COMMAND) + $(eval address = $(call get-ipv6-link-local-address,firewall)) + ssh -F files/ssh/config $(address) $(COMMAND) .PHONY: ssh-machine01 ssh-machine01: - $(eval machine = $(shell ssh -F files/ssh/config leaf01 "vtysh -c 'show bgp vrf $(VRF) neighbors machine01 json' | \ - python3 -c 'import sys, json; data = json.load(sys.stdin); key = next(iter(data)); print(data[key][\"bgpNeighborAddr\"] + \"%\" + key)'" \ - )) - ssh -F files/ssh/config $(machine) $(COMMAND) + $(eval address = $(call get-ipv6-link-local-address,machine01,$(VRF))) + ssh -F files/ssh/config $(address) $(COMMAND) .PHONY: ssh-machine02 ssh-machine02: - $(eval machine = $(shell ssh -F files/ssh/config leaf01 "vtysh -c 'show bgp vrf $(VRF) neighbors machine02 json' | \ - python3 -c 'import sys, json; data = json.load(sys.stdin); key = next(iter(data)); print(data[key][\"bgpNeighborAddr\"] + \"%\" + key)'" \ - )) - ssh -F files/ssh/config $(machine) $(COMMAND) + $(eval address = $(call get-ipv6-link-local-address,machine02,$(VRF))) + ssh -F files/ssh/config $(address) $(COMMAND) .PHONY: connect-to-cloudflare connect-to-cloudflare: From fbd340ea8f84da5857100d77de8936364acc9442 Mon Sep 17 00:00:00 2001 From: Robert Volkmann Date: Mon, 22 Jul 2024 18:44:27 +0200 Subject: [PATCH 3/4] Reduce code duplication, second try --- Makefile | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 48057a2a..93639ba0 100644 --- a/Makefile +++ b/Makefile @@ -38,9 +38,9 @@ KIND_ARGS=--image kindest/node:v$(K8S_VERSION) endif ifeq ($(CI),true) - DOCKER_COMPOSE_TTY_ARG=-T + METALCTL=docker compose run --no-TTY metalctl else - DOCKER_COMPOSE_TTY_ARG= + METALCTL=docker compose run --no-TTY metalctl endif .PHONY: up @@ -123,14 +123,10 @@ cleanup-partition: .PHONY: _privatenet _privatenet: env - docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network list --name user-private-network | grep user-private-network || docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network allocate --partition mini-lab --project 00000000-0000-0000-0000-000000000001 --name user-private-network + $(METALCTL) network list --name user-private-network | grep user-private-network || $(METALCTL) network allocate --partition mini-lab --project 00000000-0000-0000-0000-000000000001 --name user-private-network define create_public_ip - docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network ip list --name $(1) | grep $(1) || docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network ip create --network internet-mini-lab --project 00000000-0000-0000-0000-000000000001 --ipaddress $(2) --name $(1) -endef - -define private_net_id - docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl network list --name user-private-network -o template --template '{{ .id }}' + $(METALCTL) network ip list --name $(1) | grep $(1) || $(METALCTL) network ip create --network internet-mini-lab --project 00000000-0000-0000-0000-000000000001 --ipaddress $(2) --name $(1) endef define create_common_args @@ -140,24 +136,24 @@ endef .PHONY: firewall firewall: _privatenet $(call create_public_ip,firewall,203.0.113.129) - docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl firewall create $(create_common_args,firewall) \ - --firewall-rules-file=/tmp/rules.yaml --image firewall-ubuntu-3.0 --ips 203.0.113.129 --networks internet-mini-lab,$(call private_net_id) + $(METALCTL) firewall create $(call create_common_args,firewall) --firewall-rules-file=/tmp/rules.yaml --image firewall-ubuntu-3.0 --ips 203.0.113.129 \ + --networks internet-mini-lab,$(shell $(METALCTL) network list --name user-private-network -o template --template '{{ .id }}') .PHONY: machine01 machine01: _privatenet $(call create_public_ip,machine01,203.0.113.130) - docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl machine create $(create_common_args,machine01) \ - --image $(MACHINE_OS) --ips 203.0.113.130 --networks internet-mini-lab,$(call private_net_id) + $(METALCTL) machine create $(call create_common_args,machine01) --image $(MACHINE_OS) --ips 203.0.113.130 \ + --networks internet-mini-lab,$(shell $(METALCTL) network list --name user-private-network -o template --template '{{ .id }}') .PHONY: machine02 machine02: _privatenet $(call create_public_ip,machine02,203.0.113.131) - docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl machine create $(create_common_args,machine02,203.0.113.131) \ - --image $(MACHINE_OS) --ips 203.0.113.131 --networks internet-mini-lab,$(call private_net_id) + $(METALCTL) machine create $(call create_common_args,machine02) --image $(MACHINE_OS) --ips 203.0.113.131 \ + --networks internet-mini-lab,$(shell $(METALCTL) network list --name user-private-network -o template --template '{{ .id }}') .PHONY: ls ls: env - docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl machine ls + $(METALCTL) machine ls ## SWITCH MANAGEMENT ## @@ -198,7 +194,7 @@ start-vm03: .PHONY: _password _password: env - docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl machine consolepassword $(MACHINE_UUID) + $(METALCTL) machine consolepassword $(MACHINE_UUID) .PHONY: password-vm01 password-vm01: @@ -214,7 +210,7 @@ password-vm03: .PHONY: _free_vm _free_vm: env - docker compose run $(DOCKER_COMPOSE_TTY_ARG) metalctl machine rm $(MACHINE_UUID) + $(METALCTL) machine rm $(MACHINE_UUID) docker exec vms /mini-lab/manage_vms.py --names $(VM_NAME) kill --with-disks docker exec vms /mini-lab/manage_vms.py --names $(VM_NAME) create From 4958a34bb74fab9735dc2250aee9a7606720dd22 Mon Sep 17 00:00:00 2001 From: Robert Volkmann Date: Tue, 23 Jul 2024 08:18:01 +0200 Subject: [PATCH 4/4] Automatically remove metalctl container locally --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 93639ba0..96138357 100644 --- a/Makefile +++ b/Makefile @@ -40,7 +40,7 @@ endif ifeq ($(CI),true) METALCTL=docker compose run --no-TTY metalctl else - METALCTL=docker compose run --no-TTY metalctl + METALCTL=docker compose run --rm metalctl endif .PHONY: up