The cirros image was rebuilt against the 3.13.0-83 kernel, drivers e1000e, igbvf...
[packages/trusty/cirros-testvm.git] / cirros-testvm / src-cirros / src / sbin / cirros-status
1 #!/bin/sh
2
3 . ${CIRROS_LIB:=/lib/cirros/shlib_cirros} ||
4         { echo "failed to read ${CIRROS_LIB}" 1>&2; exit 1; }
5
6 Usage() {
7         cat <<EOF
8 Usage: ${0##*/} [ options ]
9
10    output status of the system.
11    Normally this would be used for debugging, or to console
12    to show user information.
13
14    options:
15    -v | --verbose  : be more verbose
16 EOF
17 }
18
19 cleanup() {
20         [ -z "${TEMP_D}" -o ! -d "${TEMP_D}" ] || rm -Rf "${TEMP_D}"
21 }
22
23 cirros_status() {
24         local short_opts="hv"
25         local long_opts="help,verbose"
26         local getopt_out=""
27         getopt_out=$(getopt --name "${0##*/}" \
28                 --options "${short_opts}" --long "${long_opts}" -- "$@") &&
29                 eval set -- "${getopt_out}" ||
30                 { bad_Usage; return; }
31
32         local cur="" next="" mode="" VERBOSITY
33
34         while [ $# -ne 0 ]; do
35                 cur=${1}; next=${2};
36                 case "$cur" in
37                         -h|--help) Usage ; exit 0;;
38                         -v|--verbose) VERBOSITY=$((${VERBOSITY}+1));;
39                         --) shift; break;;
40                 esac
41                 shift;
42         done
43
44         [ $# -eq 0 ] || { bad_Usage "no arguments expected"; return; }
45
46         TEMP_D=$(mktemp -d "${TMPDIR:-/tmp}/${0##*/}.XXXXXX") ||
47                 { error "failed to make tempdir"; return 1; }
48         trap cleanup EXIT
49
50         local container=""
51         container=$(lxc-is-container -v) || container="none"
52         echo "=== system information ==="
53         # Example: Red Hat Inc. OpenStack Nova
54         echo -n "Platform: "
55         dmesg | grep DMI: | sed -n 's/.*[ ]\+DMI:[ ]*\(.\+\), BIOS.*/\1/p'
56         echo "Container: ${container}"
57
58         lscpu | awk '$1 == "Architecture:" { arch=$2 };
59                 $1 == "Socket(s):" { sockets=$2 };
60                 $0 ~ /^Core.*per socket:/ { cores=$4 };
61                 $0 ~ /^Thread.*core:/ { threads=$4 };
62                 $1 == "CPU(s):" { cpus=$2; } ;
63                 $1" "$2 == "CPU MHz:" { mhz=$3 };
64                 $1 == "Virtualization:" { virt=$2 };
65                 END {
66                         printf("Arch: %s\nCPU(s): %s @ %s MHz\nCores/Sockets/Threads: %s/%s/%s\n",
67                                 arch, cpus, mhz, cores, sockets, threads); 
68                         printf("Virt-type: %s\n", virt);
69                 }' \
70                 arch="na" cpus="na" mhz="na" cores="na" sockets="na" threads="na"
71
72         awk '$1 == "MemTotal:" { printf("RAM Size: %dMB\n", $2/1024)}' /proc/meminfo
73
74         if [ "$container" = "none" ]; then
75                 echo "Disks:"
76                 asroot lsblk --ascii --list --bytes --output NAME,MAJ:MIN,SIZE,LABEL,MOUNTPOINT
77         fi
78
79         echo "=== sshd host keys ==="
80         echo "-----BEGIN SSH HOST KEY KEYS-----"
81         asroot dropbearkey -f /etc/dropbear/dropbear_rsa_host_key -y | grep ^ssh-rsa
82         asroot dropbearkey -f /etc/dropbear/dropbear_dss_host_key -y | grep ^ssh-dss
83         echo "-----END SSH HOST KEY KEYS-----"
84
85         local oifs="$IFS" x="" val=""
86         echo "=== network info ==="
87         ip addr show > "$TEMP_D/ip-addr-show"
88         ipinfo < "$TEMP_D/ip-addr-show"
89         IFS="|"; set -- $_RET; IFS="$oifs"
90         for x in "$@"; do
91                 echo "if-info: $x"
92         done
93         ip route | sed 's,^,ip-route:,'
94
95         if assert_datasource; then
96                 echo "=== datasource: $_DATASOURCE_NAME $_DATASOURCE_MODE ==="
97                 for x in instance-id name availability-zone local-hostname \
98                          launch-index; do
99                         ds_get_item "$x" && val="$_RET" || val="N/A"
100                         echo "$x: ${val}"
101                 done
102         else
103                 echo "=== datasource: None None ==="
104         fi
105
106         local cur="" avail="" msg=""
107         cirros_version_available && avail="$_RET"
108         cirros_version && cur="$_RET"
109         msg="current=$cur"
110         [ "$avail" != "0.0" ] && msg="$msg latest=$avail"
111
112         read_uptime && [ -n "$_RET" ] && msg="$msg uptime=$_RET"
113         echo "=== cirros: $msg ==="
114
115         if ! check_ping_gateway; then
116                 echo "=== pinging gateway failed, debugging connection ==="
117                 debug_connection
118         fi
119
120         return 0
121 }
122
123 cirros_status "$@"
124
125 # vi: ts=4 noexpandtab