Use Proper Locking for allocate

Rebase of https://github.com/crowbar/barclamp-crowbar/pull/1028 against master.