Skip to content

Commit

Permalink
adds discovery image
Browse files Browse the repository at this point in the history
  • Loading branch information
jarededwards committed Apr 11, 2024
1 parent d46ad15 commit 1a99bb2
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
10 changes: 10 additions & 0 deletions discovery/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM ubuntu:latest

RUN apt -y update && apt -y install curl iproute2

ENV COLONY_API_URL=https://colony-api-development.mgmt-20.kubefirst.com
ENV COLONY_HARDWARE_ID=2de76518-16e2-45ec-b3ae-ee8db5f4de6f

COPY . .

CMD [ "./entrypoint.sh" ]
65 changes: 65 additions & 0 deletions discovery/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bash

# Function to get architecture info
get_architecture_info() {
architecture_info=$(lscpu | grep Architecture: | awk '{print $2}')
echo "$architecture_info"
}

# Function to get number of cpu
get_cpu_info() {
cpu_info=$(nproc)
echo "$cpu_info"
}

# Function to get memory info
get_mem_info() {
mem_info=$(free -m | grep Mem | awk '{print $2}')
echo "$mem_info"
}

# Function to get physical disk info
get_disk_info() {
disk_info=$(lsblk -o NAME,TYPE,SIZE | grep disk | awk 'NR>1{if (NR!=1) printf ","; printf "\"%s\"", $1}')
echo "["${disk_info#,}"]"
}


# Function to get physical interface info
get_interface_info() {
interface_info=$(ip -o link show | awk -F': ' 'NR>1{print ",\""$2"\""}')
echo "["${interface_info:1}"]"
}


# Main function to generate JSON output
generate_json() {
architecture_info=$(get_architecture_info)
cpu_info=$(get_cpu_info)
mem_info=$(get_mem_info)
disk_info=$(get_disk_info)
interface_info=$(get_interface_info)

json_output=$(cat <<EOF
{
"cpuArchitecture": "$architecture_info",
"cpuCores": "$cpu_info",
"memory": "$mem_info",
"blockDevices": $disk_info,
"interfaceInfo": $interface_info
}
EOF
)

echo "$json_output"

# curl --request PUT \
# --url "${COLONY_API_URL}/api/v1/mock/hardwares/${COLONY_HARDWARE_ID}" \
# --header 'Accept: application/json' \
# --header 'Content-Type: application/json' \
# --data "$json_output"

}

# Call the main function to generate JSON output
generate_json

0 comments on commit 1a99bb2

Please sign in to comment.