'Login session for both real iscsi device and emulated iscsi. Include
env check and setup.'

def login(self):

    login_flag = False
    if self.portal_visible():
        login_flag = True
    elif self.initiator:
        logging.debug('Try    to    update    iscsi    initiatorname')
        cmd = 'mv    /etc/iscsi/initiatorname.iscsi    '
        cmd += ('/etc/iscsi/initiatorname.iscsi-%s' % self.id)
        utils.system(cmd)
        fd = open('/etc/iscsi/initiatorname.iscsi', 'w')
        fd.write(('InitiatorName=%s' % self.initiator))
        fd.close()
        utils.system('service    iscsid    restart')
        if self.portal_visible():
            login_flag = True
    elif self.emulated_image:
        self.export_target()
        utils.system('service    iscsid    restart')
        if self.portal_visible():
            login_flag = True
    if login_flag:
        iscsi_login(self.target)
