Closed shawaj closed 1 year 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
@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
transferred from https://github.com/NebraLtd/hm-config
Completed in hm-diag.
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