def _start_tgtd(iqn, portal_port, device):
    """Start a ISCSI target for the device."""
    # Start ISCSI Target daemon
    _execute(['tgtd'], "Unable to start the ISCSI daemon")

    _wait_for_tgtd()

    # tgt service will create default portal on default port 3260.
    # so no need to create again if input portal_port == 3260.
    if portal_port != DEFAULT_ISCSI_PORTAL_PORT:
        cmd = ['tgtadm', '--lld', 'iscsi', '--mode', 'portal', '--op',
               'new', '--param', 'portal=0.0.0.0:' + str(portal_port)]
        _execute(cmd, "Error when adding a new portal with portal_port %d"
                 % portal_port)

    cmd = ['tgtadm', '--lld', 'iscsi', '--mode', 'target', '--op',
           'new', '--tid', '1', '--targetname', iqn]
    _execute(cmd, "Error when adding a new target for iqn %s" % iqn)

    cmd = ['tgtadm', '--lld', 'iscsi', '--mode', 'logicalunit', '--op',
           'new', '--tid', '1', '--lun', '1', '--backing-store', device]
    _execute(cmd, "Error when adding a new logical unit for iqn %s" % iqn)

    cmd = ['tgtadm', '--lld', 'iscsi', '--mode', 'target', '--op',
           'bind', '--tid', '1', '--initiator-address', 'ALL']
    _execute(cmd, "Error when enabling the target to accept the specific "
                  "initiators for iqn %s" % iqn)
dataset/ETHPy150Open openstack/ironic-python-agent/ironic_python_agent/extensions/iscsi.py/_start_tgtd/original