Skip to content

Commit 8a4fec9

Browse files
committed
provisioning: Add a "make status" target
If you've walked away from the keyboard and forgotten whether there are target nodes running or waiting for the next step, it's easy to "make mrproper" and wipe out the ssh keys and other state that Ansible and terraform use to access those nodes. With guestfs, it's as easy as "virsh list" to see what's running. But with terraform, the nodes are running in another geographic location entirely. Add a make target that can probe to see if we've left something cooking on the back burner. Before "make bringup" or after "make destroy": $ make status make: Nothing to be done for 'status'. $ After a "make bringup with guestfs: $ make status Id Name State ------------------------- 2 test-nfsd running $ After a "make bringup" with terraform: $ make status There are 4 active terraform resources on 'gce'. { "gce-nfsd" = "35.243.237.209" } $ Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent e18cdf0 commit 8a4fec9

File tree

6 files changed

+40
-0
lines changed

6 files changed

+40
-0
lines changed

scripts/bringup.Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@ endif
2222

2323
bringup: $(KDEVOPS_BRING_UP_DEPS)
2424

25+
status: $(KDEVOPS_STATUS_DEPS)
26+
2527
destroy: $(KDEVOPS_DESTROY_DEPS)
2628

2729
bringup-help-menu:
2830
@echo "Bringup targets:"
2931
@echo "bringup - Brings up target hosts"
32+
@echo "status - Reports the status of target hosts"
3033
@echo "destroy - Destroy all target hosts"
3134
@echo "cleancache - Remove all cached images"
3235
@echo ""

scripts/guestfs.Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ GUESTFS_BRINGUP_DEPS += $(LIBVIRT_PCIE_PASSTHROUGH)
5050
GUESTFS_BRINGUP_DEPS += install_libguestfs
5151

5252
KDEVOPS_PROVISION_METHOD := bringup_guestfs
53+
KDEVOPS_PROVISION_STATUS_METHOD := status_guestfs
5354
KDEVOPS_PROVISION_DESTROY_METHOD := destroy_guestfs
5455

5556
9p_linux_clone:
@@ -97,6 +98,10 @@ bringup_guestfs: $(GUESTFS_BRINGUP_DEPS)
9798
--tags console-permissions
9899
PHONY += bringup_guestfs
99100

101+
status_guestfs:
102+
$(Q)scripts/status_guestfs.sh
103+
PHONY += status_guestfs
104+
100105
destroy_guestfs:
101106
$(Q)$(TOPDIR)/scripts/destroy_guestfs.sh
102107
$(Q)rm -f $(KDEVOPS_PROVISIONED_SSH) $(KDEVOPS_PROVISIONED_DEVCONFIG)

scripts/provision.Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
# systems will be up after this.
55
KDEVOPS_PROVISION_METHOD :=
66

7+
# Provisioning methods should set this to their target which will report
8+
# the status of target nodes
9+
KDEVOPS_PROVISION_STATUS_METHOD :=
10+
711
# Provisioning methods should set this to their target which will ensure
812
# the systems will be removed after this
913
KDEVOPS_PROVISION_DESTROY_METHOD :=
@@ -86,4 +90,6 @@ $(KDEVOPS_PROVISIONED_DEVCONFIG):
8690
KDEVOPS_BRING_UP_DEPS += $(KDEVOPS_PROVISION_METHOD)
8791
KDEVOPS_BRING_UP_DEPS += $(KDEVOPS_PROVISIONED_SSH)
8892

93+
KDEVOPS_STATUS_DEPS += $(KDEVOPS_PROVISION_STATUS_METHOD)
94+
8995
KDEVOPS_DESTROY_DEPS += $(KDEVOPS_PROVISION_DESTROY_METHOD)

scripts/status_guestfs.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: copyleft-next-0.3.1
3+
4+
virsh list
5+
exit 0

scripts/status_terraform.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: copyleft-next-0.3.1
3+
4+
[ -z "${TOPDIR}" ] && TOPDIR='.'
5+
source ${TOPDIR}/.config
6+
source ${TOPDIR}/scripts/lib.sh
7+
8+
cd ${TOPDIR}/terraform/$1
9+
terraform refresh > /dev/null
10+
COUNT=`terraform state list | wc -l`
11+
if [[ ${COUNT} -eq 1 ]]; then
12+
echo "There is 1 active terraform resource on '$1'."
13+
else
14+
echo "There are ${COUNT} active terraform resources on '$1'."
15+
fi
16+
terraform output public_ip_map
17+
exit 0

scripts/terraform.Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
TERRAFORM_EXTRA_VARS :=
44

55
KDEVOPS_PROVISION_METHOD := bringup_terraform
6+
KDEVOPS_PROVISION_STATUS_METHOD := status_terraform
67
KDEVOPS_PROVISION_DESTROY_METHOD := destroy_terraform
78

89
export KDEVOPS_CLOUD_PROVIDER=aws
@@ -192,6 +193,9 @@ $(KDEVOPS_PROVISIONED_SSH):
192193
-e 'ansible_python_interpreter=/usr/bin/python3'
193194
$(Q)touch $(KDEVOPS_PROVISIONED_SSH)
194195

196+
status_terraform:
197+
$(Q)scripts/status_terraform.sh $(KDEVOPS_CLOUD_PROVIDER)
198+
195199
destroy_terraform:
196200
$(Q)ansible-playbook $(ANSIBLE_VERBOSE) \
197201
--connection=local -i $(KDEVOPS_HOSTFILE) \

0 commit comments

Comments
 (0)