~j-harbott/cirros/dev

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/sh

. ${CIRROS_LIB:=/lib/cirros/shlib_cirros} ||
	{ echo "failed to read ${CIRROS_LIB}" 1>&2; exit 1; }

Usage() {
	cat <<EOF
Usage: ${0##*/} [ options ]

   output status of the system.
   Normally this would be used for debugging, or to console
   to show user information.

   options:
   -v | --verbose  : be more verbose
EOF
}

cleanup() {
	[ -z "${TEMP_D}" -o ! -d "${TEMP_D}" ] || rm -Rf "${TEMP_D}"
}

cirros_status() {
	local short_opts="hv"
	local long_opts="help,verbose"
	local getopt_out=""
	getopt_out=$(getopt --name "${0##*/}" \
		--options "${short_opts}" --long "${long_opts}" -- "$@") &&
		eval set -- "${getopt_out}" ||
		{ bad_Usage; return; }

	local cur="" next="" mode="" VERBOSITY

	while [ $# -ne 0 ]; do
		cur=${1}; next=${2};
		case "$cur" in
			-h|--help) Usage ; exit 0;;
			-v|--verbose) VERBOSITY=$((${VERBOSITY}+1));;
			--) shift; break;;
		esac
		shift;
	done

	[ $# -eq 0 ] || { bad_Usage "no arguments expected"; return; }

	TEMP_D=$(mktemp -d "${TMPDIR:-/tmp}/${0##*/}.XXXXXX") ||
		{ error "failed to make tempdir"; return 1; }
	trap cleanup EXIT

	local container=""
	container=$(lxc-is-container -v) || container="none"
	echo "=== system information ==="
	# Example: Red Hat Inc. OpenStack Nova
	echo -n "Platform: "
	dmesg | grep DMI: | sed -n 's/.*[ ]\+DMI:[ ]*\(.\+\), BIOS.*/\1/p'
	echo "Container: ${container}"

	lscpu | awk '$1 == "Architecture:" { arch=$2 };
		$1 == "Socket(s):" { sockets=$2 };
		$0 ~ /^Core.*per socket:/ { cores=$4 };
		$0 ~ /^Thread.*core:/ { threads=$4 };
		$1 == "CPU(s):" { cpus=$2; } ;
		$1" "$2 == "CPU MHz:" { mhz=$3 };
		$1 == "Virtualization:" { virt=$2 };
		END {
			printf("Arch: %s\nCPU(s): %s @ %s MHz\nCores/Sockets/Threads: %s/%s/%s\n",
				arch, cpus, mhz, cores, sockets, threads); 
			printf("Virt-type: %s\n", virt);
		}' \
		arch="na" cpus="na" mhz="na" cores="na" sockets="na" threads="na"

	awk '$1 == "MemTotal:" { printf("RAM Size: %dMB\n", $2/1024)}' /proc/meminfo

	if [ "$container" = "none" ]; then
		echo "Disks:"
		asroot lsblk --ascii --list --bytes --output NAME,MAJ:MIN,SIZE,LABEL,MOUNTPOINT
	fi

	echo "=== sshd host keys ==="
	echo "-----BEGIN SSH HOST KEY KEYS-----"
	asroot dropbearkey -f /etc/dropbear/dropbear_rsa_host_key -y | grep ^ssh-rsa
	asroot dropbearkey -f /etc/dropbear/dropbear_dss_host_key -y | grep ^ssh-dss
	echo "-----END SSH HOST KEY KEYS-----"

	local oifs="$IFS" x="" val=""
	echo "=== network info ==="
	ip addr show > "$TEMP_D/ip-addr-show"
	ipinfo < "$TEMP_D/ip-addr-show"
	IFS="|"; set -- $_RET; IFS="$oifs"
	for x in "$@"; do
		echo "if-info: $x"
	done
	ip route | sed 's,^,ip-route:,'
	ip -6 route | sed 's,^,ip-route6:,'

	if assert_datasource; then
		echo "=== datasource: $_DATASOURCE_NAME $_DATASOURCE_MODE ==="
		for x in instance-id name availability-zone local-hostname \
		         launch-index; do
			ds_get_item "$x" && val="$_RET" || val="N/A"
			echo "$x: ${val}"
		done
	else
		echo "=== datasource: None None ==="
	fi

	local cur="" avail="" msg=""
	cirros_version_available && avail="$_RET"
	cirros_version && cur="$_RET"
	msg="current=$cur"
	[ "$avail" != "0.0" ] && msg="$msg latest=$avail"

	read_uptime && [ -n "$_RET" ] && msg="$msg uptime=$_RET"
	echo "=== cirros: $msg ==="

	if ! check_ping_gateway; then
		echo "=== pinging gateway failed, debugging connection ==="
 		debug_connection
	fi

	return 0
}

cirros_status "$@"

# vi: ts=4 noexpandtab