def on_post(self, req, resp, tenant_id):
        body = json.loads(req.stream.read().decode())
        try:
            name = body['keypair']['name']
            key = body['keypair'].get('public_key', generate_random_key())
        except (__HOLE__, TypeError):
            return error_handling.bad_request(
                resp, 'Not all fields exist to create keypair.')

        validate_result = validate_keypair_name(resp, name)
        if not validate_result:
            return

        client = req.env['sl_client']
        mgr = SoftLayer.SshKeyManager(client)

        # Make sure the key with that label doesn't already exist
        existing_keys = mgr.list_keys(label=name)
        if existing_keys:
            return error_handling.duplicate(resp, 'Duplicate key by that name')

        try:
            keypair = mgr.add_key(key, name)
            resp.body = {'keypair': format_keypair(keypair)}
        except SoftLayer.SoftLayerAPIError as e:
            if 'Unable to generate a fingerprint' in e.faultString:
                return error_handling.bad_request(resp, e.faultString)
            if 'SSH key already exists' in e.faultString:
                return error_handling.duplicate(resp, e.faultString)
            raise
dataset/ETHPy150Open softlayer/jumpgate/jumpgate/compute/drivers/sl/keypairs.py/KeypairsV2.on_post