'Defines a host in XIV.'

@proxy._trace_time
def _define_host(self, connector):

    domain = self._get_pool_domain(connector)
    host_bunch = self._get_bunch_from_host(connector)
    host = self._call_xiv_xcli('host_list', host=host_bunch['name']).as_list
    connection_type = self._get_connection_type()
    if (len(host) == 0):
        LOG.debug('Non    existing    host,    defining')
        host = self._define_host_according_to_chap(host=host_bunch['name'], in_domain=domain)
        host_bunch = self._get_bunch_from_host(connector, host.get('id'))
    else:
        host_bunch = self._get_bunch_from_host(connector, host[0].get('id'))
        LOG.debug('Generating    hostname    for    connector    %(conn)s', {'conn': connector})
        generated_hostname = storage.get_host_or_create_from_iqn(connector, connection=connection_type)
        generated_host = self._call_xiv_xcli('host_list', host=generated_hostname).as_list
        if (len(generated_host) == 0):
            host = self._define_host_according_to_chap(host=generated_hostname, in_domain=domain)
        else:
            host = generated_host[0]
        host_bunch = self._get_bunch_from_host(connector, host.get('id'), host_name=generated_hostname)
    LOG.debug('The    host_bunch:    %s', host_bunch)
    return host_bunch
