'Map vdisk to host.
If vdisk already mapped and multihostmap is True, use the force flag.'

def mkvdiskhostmap(self, host, vdisk, lun, multihostmap):

    ssh_cmd = ['svctask', 'mkvdiskhostmap', '-host', ('"%s"' % host), vdisk]
    if lun:
        ssh_cmd.insert(ssh_cmd.index(vdisk), '-scsi')
        ssh_cmd.insert(ssh_cmd.index(vdisk), lun)
    if multihostmap:
        ssh_cmd.insert((ssh_cmd.index('mkvdiskhostmap') + 1), '-force')
    try:
        self.run_ssh_check_created(ssh_cmd)
        result_lun = self.get_vdiskhostmapid(vdisk, host)
        if ((result_lun is None) or (lun and (lun != result_lun))):
            msg = (_('mkvdiskhostmap    error:\n    command:    %(cmd)s\n    lun:    %(lun)s\n    result_lun:    %(result_lun)s') % {'cmd': ssh_cmd, 'lun': lun, 'result_lun': result_lun})
            LOG.error(msg)
            raise exception.VolumeDriverException(message=msg)
        return result_lun
    except Exception as ex:
        if ((not multihostmap) and hasattr(ex, 'message') and ('CMMVC6071E' in ex.message)):
            LOG.error('storwize_svc_multihostmap_enabled    is    set    to    False,    not    allowing    multi    host    mapping.')
            raise exception.VolumeDriverException(message=_('CMMVC6071E    The    VDisk-to-host    mapping    was    not    created    because    the    VDisk    is    already    mapped    to    a    host.\n"'))
        with excutils.save_and_reraise_exception():
            LOG.error('Error    mapping    VDisk-to-host')
