- conn = http.client.HTTPConnection(o.netloc)
- headers = {'Content-type': 'application/json'}
- conn.request('POST', o.path, callback_data, headers)
- resp = conn.getresponse()
- data = resp.read().decode('utf-8')
- # json_data = json.loads(data)
- if resp.status == 202 or resp.status == 200:
- logger.info('Registrer to SMO successed, response code {} {}, data {}'.
- format(resp.status, resp.reason, data))
- return True
- logger.error('Response code is: {}'.format(resp.status))
- return False
+ if o.scheme == 'https':
+ conn = get_https_conn_default(o.netloc)
+ else:
+ conn = get_http_conn(o.netloc)
+
+ try:
+ return post_data(conn, o.path, callback_data)
+ except ssl.SSLCertVerificationError as e:
+ logger.debug('Try to register to smo with \
+ trusted ca failed: {}'.format(e))
+ if 'self signed' in str(e):
+ conn = get_https_conn_selfsigned(o.netloc)
+ try:
+ return post_data(conn, o.path, callback_data)
+ except Exception as e:
+ logger.info(
+ 'Register to smo with self-signed ca failed: {}'.format(e))
+ # TODO: write the status to extension db table.
+ return False, None
+ return False, None
+ except Exception as e:
+ logger.critical('Register to smo except: {}'.format(e))
+ return False, None