'Check if host exists on the array, or create it.'

def create_hostgroup_with_check(self, hostgroup_name):

    hostgroup_id = self.find_hostgroup(hostgroup_name)
    if hostgroup_id:
        LOG.info('create_hostgroup_with_check.    hostgroup    name:    %(name)s,    hostgroup    id:    %(id)s', {'name': hostgroup_name, 'id': hostgroup_id})
        return hostgroup_id
    try:
        hostgroup_id = self._create_hostgroup(hostgroup_name)
    except Exception:
        LOG.info('Failed    to    create    hostgroup:    %(name)s.    Please    check    if    it    exists    on    the    array.', {'name': hostgroup_name})
        hostgroup_id = self.find_hostgroup(hostgroup_name)
        if (hostgroup_id is None):
            err_msg = (_('Failed    to    create    hostgroup:    %(name)s.    Check    if    it    exists    on    the    array.') % {'name': hostgroup_name})
            LOG.error(err_msg)
            raise exception.VolumeBackendAPIException(data=err_msg)
    LOG.info('create_hostgroup_with_check.    Create    hostgroup    success.    hostgroup    name:    %(name)s,    hostgroup    id:    %(id)s', {'name': hostgroup_name, 'id': hostgroup_id})
    return hostgroup_id
