def _delete_external_keypair():
    """If use_external_resource is True, this will delete the runtime_properties,
    and then exit.

    :param ctx: The Cloudify context.
    :return False: Cloudify resource. Continue operation.
    :return True: External resource. Unset runtime_properties.
        Ignore operation.
    """

    if not utils.use_external_resource(ctx.node.properties):
        return False

    ctx.logger.info('External resource. Not deleting keypair.')

    utils.unassign_runtime_properties_from_resource(RUNTIME_PROPERTIES,
                                                    ctx.instance)
    return True
Example #2
0
def _delete_external_keypair():
    """If use_external_resource is True, this will delete the runtime_properties,
    and then exit.

    :param ctx: The Cloudify context.
    :return False: Cloudify resource. Continue operation.
    :return True: External resource. Unset runtime_properties.
        Ignore operation.
    """

    if not utils.use_external_resource(ctx.node.properties):
        return False

    ctx.logger.info('External resource. Not deleting keypair.')

    utils.unassign_runtime_properties_from_resource(RUNTIME_PROPERTIES,
                                                    ctx.instance)
    return True
def delete(**kwargs):
    """Deletes a keypair."""

    ec2_client = connection.EC2ConnectionClient().client()

    key_pair_name = utils.get_external_resource_id_or_raise(
        'delete key pair', ctx.instance)

    if _delete_external_keypair():
        return

    ctx.logger.debug('Attempting to delete key pair from account.')

    try:
        ec2_client.delete_key_pair(key_pair_name)
    except (boto.exception.EC2ResponseError,
            boto.exception.BotoServerError) as e:
        raise NonRecoverableError('{0}'.format(str(e)))

    utils.unassign_runtime_properties_from_resource(RUNTIME_PROPERTIES,
                                                    ctx.instance)
    _delete_key_file()
    ctx.logger.info('Deleted key pair: {0}.'.format(key_pair_name))
Example #4
0
def delete(**kwargs):
    """Deletes a keypair."""

    ec2_client = connection.EC2ConnectionClient().client()

    key_pair_name = utils.get_external_resource_id_or_raise(
        'delete key pair', ctx.instance)

    if _delete_external_keypair():
        return

    ctx.logger.debug('Attempting to delete key pair from account.')

    try:
        ec2_client.delete_key_pair(key_pair_name)
    except (boto.exception.EC2ResponseError,
            boto.exception.BotoServerError) as e:
        raise NonRecoverableError('{0}'.format(str(e)))

    utils.unassign_runtime_properties_from_resource(RUNTIME_PROPERTIES,
                                                    ctx.instance)
    _delete_key_file()
    ctx.logger.info('Deleted key pair: {0}.'.format(key_pair_name))