-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathcommon.sh
More file actions
executable file
·57 lines (50 loc) · 1.77 KB
/
Copy pathcommon.sh
File metadata and controls
executable file
·57 lines (50 loc) · 1.77 KB
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
#!/bin/bash
#
# Shared helper functions for cluster management scripts.
# Supports both AWS EC2 and bare metal deployments.
#
# Detect the instance type (aws or baremetal) by checking for marker files.
# Prints the type to stdout and returns 0, or prints an error and returns 1.
check_instance() {
local deploy_dir="$1"
if [[ -f "${deploy_dir}/aws-hypervisor/instance-data/aws-instance-id" ]]; then
echo "aws"
return 0
elif [[ -f "${deploy_dir}/aws-hypervisor/instance-data/bare-metal-host" ]]; then
echo "baremetal"
return 0
fi
echo "Error: No instance found. Run 'make deploy' (EC2) or 'make bm-init' (bare metal) first." >&2
return 1
}
# Get a display identifier for the current instance (instance ID or hostname).
get_instance_display() {
local deploy_dir="$1"
local instance_type="$2"
case "${instance_type}" in
aws)
cat "${deploy_dir}/aws-hypervisor/instance-data/aws-instance-id"
;;
baremetal)
cat "${deploy_dir}/aws-hypervisor/instance-data/bare-metal-host"
;;
esac
}
# Get the SSH user and host for connecting to the hypervisor.
get_ssh_target() {
local deploy_dir="$1"
local instance_type="$2"
case "${instance_type}" in
aws)
local ssh_user host_ip
ssh_user=$(cat "${deploy_dir}/aws-hypervisor/instance-data/ssh_user")
host_ip=$(cat "${deploy_dir}/aws-hypervisor/instance-data/public_address")
echo "${ssh_user}@${host_ip}"
;;
baremetal)
# Read the first metal_machine host from the inventory
grep -A1 '^\[metal_machine\]' "${deploy_dir}/openshift-clusters/inventory.ini" \
| tail -1 | awk '{print $1}'
;;
esac
}