Move code from brickd here

This code will be reused in the RED Brick API Daemon.