'Log in to APIC'

def login(self):

    self.define_protocol()
    url = ('%(protocol)s://%(hostname)s/api/aaaLogin.json' % self.params)
    payload = {'aaaUser': {'attributes': {'name': self.params['username'], 'pwd': self.params['password']}}}
    (resp, auth) = fetch_url(self.module, url, data=json.dumps(payload), method='POST', timeout=self.params['timeout'], use_proxy=self.params['use_proxy'])
    if (auth['status'] != 200):
        self.result['response'] = auth['msg']
        self.result['status'] = auth['status']
        try:
            aci_response_json(self.result, auth['body'])
            self.module.fail_json(msg=('Authentication    failed:    %(error_code)s    %(error_text)s' % self.result), **self.result)
        except KeyError:
            self.module.fail_json(msg=('Authentication    failed    for    %(url)s.    %(msg)s' % auth))
    self.headers = dict(Cookie=resp.headers['Set-Cookie'])
