NebraLtd / hm-watchdog

MIT License
0 stars 1 forks source link

Configure mDNS hostname #1

Closed shawaj closed 1 year ago

shawaj commented 3 years ago

Relates to https://github.com/NebraLtd/hm-diag/pull/115

@vpetersson suggested it would be better to have the balena supervisor access in this container instead of the diag

Would be good to pull this into NebraLtd/hm-config#61

shawaj commented 3 years ago

Here is the script for reference:

import os
import requests

from hw_diag.utilities.hardware import get_mac_addr

def set_hostname():
    """
    Sets the hostname of the miner to nebra-<last 6 of mac>
    via the balena supervisor api
    """
    path = "/sys/class/net/eth0/address"
    eth0 = get_mac_addr(path).replace(':','').lower()
    length = len(eth0)
    supervisor_addr = os.environ.get('BALENA_SUPERVISOR_ADDRESS')
    api_key = os.environ.get('BALENA_SUPERVISOR_API_KEY')

    headers = {
        'Content-Type': 'application/json',
    }
    params = (
        ('apikey', api_key),
    )
    data = '{{"network": {{"hostname": "nebra-{}"}}}}'.format(eth0[length - 6:])
    response = requests.patch(supervisor_addr + '/v1/device/host-config', headers=headers, params=params, data=data)

    return response
shawaj commented 3 years ago

@vpetersson had a thought about this.... We could perhaps put this code in the gwmfr container as it only runs once and then closes and doesn't need to interface with the outside world

shawaj commented 3 years ago

transferred from https://github.com/NebraLtd/hm-config

robputt commented 1 year ago

Completed in hm-diag.