Add support for FreeBSD
When loading the library on FreeBSD, the serial device should be /dev/ttyu1 and not /dev/ttyS1.
Let's add a simple OS check and load the properly loads the right serial device.
Turns out this was a bit more complicated than initially anticipated. Doing the actual OS detection is easy, but there's something else at play here with FreeBSD.
Here's a simple sample script that reads the meta data from the serial device:
import serial
import json
from sys import platform
if 'linux' in platform:
ser_dev = '/dev/ttyS1'
elif 'freebsd' in platform:
ser_dev = '/dev/ttyu1'
ser = serial.Serial(ser_dev, timeout=1)
ser.write('<\n\n>')
data = ser.readlines()
ser.close()
print data[0]
On Linux (Ubuntu), this runs fine:
$ python get_meta.py
{"uuid": "6cc039ad-d024-4ecf-b0de-83dbc297f9ba", "requirements": [], "name": "server0", "cpus_instead_of_cores": false, "tags": [], "mem": 536870912, "nics": [{"boot_order": null, "vlan": null, "ip_v4_conf": {"ip": {"uuid": "185.12.7.152", "tags": [], "nameservers": ["178.22.66.167", "178.22.71.56", "8.8.8.8"], "netmask": 24, "meta": {}, "gateway": "185.12.7.1"}, "conf": "dhcp"}, "mac": "22:bd:c4:fb:e4:da", "model": "virtio", "ip_v6_conf": null}], "enable_numa": false, "global_context": {"this-will-be-accessible": "from-all-servers"}, "drives": [{"device": "virtio", "dev_channel": "0:1", "drive": {"uuid": "e4d51782-a9d9-418c-992e-f2a550f1c3ba", "tags": [], "media": "disk", "name": "server0-1", "meta": {"description": ""}, "allow_multimount": false, "licenses": [], "affinities": [], "size": 42949672960}, "boot_order": 2}, {"device": "virtio", "dev_channel": "0:0", "drive": {"uuid": "19757a94-8173-46ba-8822-d9b7c6bdca82", "tags": [], "media": "disk", "name": "server0", "meta": {"description": ""}, "allow_multimount": false, "licenses": [], "affinities": [], "size": 21474836480}, "boot_order": 1}], "cpu_model": null, "hv_relaxed": false, "hv_tsc": false, "meta": {"description": ""}, "smp": 1, "cpu": 1000, "vnc_password": "abc123"}
On FreeBSD however, the result gets truncated for some strange reason:
$ python get_meta.py
{"uuid": "249e3f66-040e-4f58-99ca-0ce8a3d475fe", "requirements": [], "name": "fbsd10-test", "cpus_instead_of_cores": false, "tags": [], "mem": 2147483648, "nics": [{"boot_order": null, "vlan": null, "ip_v4_conf": {"ip": {"uuid": "31.171.245.187", "tags": [], "nameservers": ["178.22.66.167", "178.22.71.56", "8.8.8.8"], "netmask": 22, "meta": {}, "gateway": "31.171.244.1"}, "conf":
This, of course, results in invalid JSON, which throws an error when we try to process it. I did have some minor success by adjusting the baudrate, but the result was too inconsistent. This will simply require more research.
With cu on FreeBSD :
$ echo -e "<\n\n>" | cu -l /dev/ttyu1 -s 9600
Connected
{"uuid": "ced74d0a-51bf-4086-8c98-f7f2889a74f9", "requirements": [], "name": "FreeBSD Test2", "cpus_instead_of_cores": false, "tags": [], "mem": 1073741824, "nics": [{"boot_order": null, "vlan": null, "ip_v4_conf": {"ip": {"uuid": "31.171.246.217", "tags": [], "nameservers": ["178.22.66.167", "178.22.71.56", "8.8.8.8"], "netmask": 22, "meta": {}, "gateway": "31.171.244.1"}, "conf"
As it relates to an older library version, we're closing it as not planned.