def _get_cookie(self, mgmt_ip, config, refresh=False):
if mgmt_ip not in self.credentials:<EOL><INDENT>return None<EOL><DEDENT>security_data = self.credentials[mgmt_ip]<EOL>verify = security_data[const.HTTPS_CERT_TUPLE]<EOL>if not verify:<EOL><INDENT>verify = security_data[const.HTTPS_VERIFY_TUPLE]<EOL><DEDENT>if not refresh and security_data[const.COOKIE_TUPLE]:<EOL><INDENT>return security_data[const.COOKIE_TUPLE], verify<EOL><DEDENT>payload = {"<STR_LIT>": {"<STR_LIT>": {<EOL>"<STR_LIT:name>": security_data[const.UNAME_TUPLE],<EOL>"<STR_LIT>": security_data[const.PW_TUPLE]}}}<EOL>headers = {"<STR_LIT>": "<STR_LIT:application/json>", "<STR_LIT>": "<STR_LIT>"}<EOL>url = "<STR_LIT>".format(DEFAULT_SCHEME, mgmt_ip)<EOL>try:<EOL><INDENT>response = self.session.request('<STR_LIT:POST>',<EOL>url,<EOL>data=jsonutils.dumps(payload),<EOL>headers=headers,<EOL>verify=verify,<EOL>timeout=self.timeout * <NUM_LIT:2>)<EOL><DEDENT>except Exception as e:<EOL><INDENT>raise cexc.NexusConnectFailed(nexus_host=mgmt_ip,<EOL>exc=e)<EOL><DEDENT>self.status = response.status_code<EOL>if response.status_code == requests.codes.OK:<EOL><INDENT>cookie = response.headers.get('<STR_LIT>')<EOL>security_data = (<EOL>security_data[const.UNAME_TUPLE:const.COOKIE_TUPLE] +<EOL>(cookie,))<EOL>self.credentials[mgmt_ip] = security_data<EOL>return cookie, verify<EOL><DEDENT>else:<EOL><INDENT>e = "<STR_LIT>"<EOL>e += str(self.status)<EOL>raise cexc.NexusConnectFailed(nexus_host=mgmt_ip,<EOL>exc=e)<EOL><DEDENT>
Performs authentication and retries cookie.