'Create a mapping between a vdisk to a host.'

@utils.synchronized('flashsystem-map', external=True)
def _map_vdisk_to_host(self, vdisk_name, connector):

    LOG.debug('enter:    _map_vdisk_to_host:    vdisk    %(vdisk_name)s    to    host    %(host)s.', {'vdisk_name': vdisk_name, 'host': connector})
    host_name = self._get_host_from_connector(connector)
    if (host_name is None):
        host_name = self._create_host(connector)
        self._driver_assert((host_name is not None), _('_create_host    failed    to    return    the    host    name.'))
    (map_flag, result_lun) = self._is_vdisk_map(vdisk_name, connector)
    if (not map_flag):
        ssh_cmd = ['svctask', 'mkvdiskhostmap', '-host', host_name, '-scsi', six.text_type(result_lun), vdisk_name]
        (out, err) = self._ssh(ssh_cmd, check_exit_code=False)
        if (err and err.startswith('CMMVC6071E')):
            if (not self.configuration.flashsystem_multihostmap_enabled):
                msg = _('flashsystem_multihostmap_enabled    is    set    to    False,    not    allow    multi    host    mapping.    CMMVC6071E    The    VDisk-to-host    mapping    was    not    created    because    the    VDisk    is    already    mapped    to    a    host.')
                LOG.error(msg)
                raise exception.VolumeBackendAPIException(data=msg)
            for i in range(len(ssh_cmd)):
                if (ssh_cmd[i] == 'mkvdiskhostmap'):
                    ssh_cmd.insert((i + 1), '-force')
            (out, err) = self._ssh(ssh_cmd)
            LOG.info('Volume    %s    is    mapping    to    multiple    hosts.', vdisk_name)
            self._assert_ssh_return(('successfully    created' in out), '_map_vdisk_to_host', ssh_cmd, out, err)
        else:
            self._assert_ssh_return(('successfully    created' in out), '_map_vdisk_to_host', ssh_cmd, out, err)
    LOG.debug('leave:    _map_vdisk_to_host:    LUN    %(result_lun)s,    vdisk    %(vdisk_name)s,    host    %(host_name)s.', {'result_lun': result_lun, 'vdisk_name': vdisk_name, 'host_name': host_name})
    return int(result_lun)
