Refactor generate_hostname

``generate_hostname`` take ``template_vars``
device_code would be better ;p