'Import a key pair using an existing public key.'

@wrap_exception()
def import_key_pair(self, context, user_id, key_name, public_key, key_type=keypair_obj.KEYPAIR_TYPE_SSH):

    self._validate_new_key_pair(context, user_id, key_name, key_type)
    self._notify(context, 'import.start', key_name)
    fingerprint = self._generate_fingerprint(public_key, key_type)
    keypair = objects.KeyPair(context)
    keypair.user_id = user_id
    keypair.name = key_name
    keypair.type = key_type
    keypair.fingerprint = fingerprint
    keypair.public_key = public_key
    keypair.create()
    self._notify(context, 'import.end', key_name)
    return keypair
