示例#1
0
def _create_external_keypair():
    """If use_external_resource is True, this will set the runtime_properties,
    and then exit.

    :param ctx: The Cloudify context.
    :return False: Cloudify resource. Continue operation.
    :return True: External resource. Set runtime_properties. Ignore operation.
    :raises NonRecoverableError: If unable to locate the existing key file.
    """

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

    key_pair_name = ctx.node.properties['resource_id']
    key_pair_in_account = _get_key_pair_by_id(key_pair_name)
    key_path_in_filesystem = _get_path_to_key_file()
    ctx.logger.debug('Path to key file: {0}.'.format(key_path_in_filesystem))
    if not key_pair_in_account:
        raise NonRecoverableError(
            'External resource, but the key pair is not in the account.')
    if not _search_for_key_file(key_path_in_filesystem):
        raise NonRecoverableError(
            'External resource, but the key file does not exist.')
    utils.set_external_resource_id(key_pair_name, ctx.instance)
    return True
def _create_external_keypair():
    """If use_external_resource is True, this will set the runtime_properties,
    and then exit.

    :param ctx: The Cloudify context.
    :return False: Cloudify resource. Continue operation.
    :return True: External resource. Set runtime_properties. Ignore operation.
    :raises NonRecoverableError: If unable to locate the existing key file.
    """

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

    key_pair_name = ctx.node.properties['resource_id']
    key_pair_in_account = _get_key_pair_by_id(key_pair_name)
    key_path_in_filesystem = _get_path_to_key_file()
    ctx.logger.debug(
        'Path to key file: {0}.'.format(key_path_in_filesystem))
    if not key_pair_in_account:
        raise NonRecoverableError(
            'External resource, but the key pair is not in the account.')
    if not _search_for_key_file(key_path_in_filesystem):
        raise NonRecoverableError(
            'External resource, but the key file does not exist.')
    utils.set_external_resource_id(key_pair_name, ctx.instance)
    return True
def _start_external_instance(instance_id):

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

    ctx.logger.info("Not starting instance {0}, because it is an external resource.".format(instance_id))
    _instance_started_assign_runtime_properties(instance_id)
    return True
def _terminate_external_instance(instance_id):

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

    ctx.logger.info("External resource. Not terminating instance {0}.".format(instance_id))
    utils.unassign_runtime_property_from_resource(constants.EXTERNAL_RESOURCE_ID, ctx.instance)
    return True
def _stop_external_instance(instance_id):

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

    ctx.logger.info("External resource. Not stopping instance {0}.".format(instance_id))
    _unassign_runtime_properties(runtime_properties=constants.INSTANCE_INTERNAL_ATTRIBUTES, ctx_instance=ctx.instance)
    return True
def _disassociate_external_elasticip_or_instance():
    """Pretends to disassociate an Elastic IP with an EC2 instance but if one
    was not created by Cloudify, it just deletes runtime_properties
    and exits the operation.

    :return False: At least one is a Cloudify resource. Continue operation.
    :return True: Both are External resources. Set runtime_properties.
        Ignore operation.
    """

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

    ctx.logger.info("Either instance or elasticip is an external resource so not " "performing disassociate operation.")
    utils.unassign_runtime_property_from_resource("public_ip_address", ctx.source.instance)
    return True
示例#7
0
    def test_utils_use_external_resource_not_external(self):

        ctx = self.mock_ctx(
            'test_utils_use_external_resource_not_external')
        current_ctx.set(ctx=ctx)

        self.assertEquals(
            False,
            utils.use_external_resource(ctx.node.properties))
示例#8
0
def _start_external_instance(instance_id):

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

    ctx.logger.info(
        'Not starting instance {0}, because it is an external resource.'.
        format(instance_id))
    _instance_started_assign_runtime_properties_and_tag(instance_id)
    return True
示例#9
0
def _terminate_external_instance(instance_id):

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

    ctx.logger.info(
        'External resource. Not terminating instance {0}.'.format(instance_id))
    utils.unassign_runtime_property_from_resource(
        constants.EXTERNAL_RESOURCE_ID, ctx.instance)
    return True
示例#10
0
def _stop_external_instance(instance_id):

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

    ctx.logger.info(
        'External resource. Not stopping instance {0}.'.format(instance_id))
    _unassign_runtime_properties(
        runtime_properties=constants.INSTANCE_INTERNAL_ATTRIBUTES,
        ctx_instance=ctx.instance)
    return True
示例#11
0
def _attach_external_volume_or_instance(instance_id):
    """Pretends to attach an external EBC volume with an EC2 instance
    but if one was not created by Cloudify, it just sets runtime_properties
    and exits the operation.

    :return False: At least one is a Cloudify resource. Continue operation.
    :return True: Both are External resources. Set runtime_properties.
        Ignore operation.
    """

    if not utils.use_external_resource(ctx.source.node.properties) \
            or not utils.use_external_resource(
                ctx.target.node.properties):
        return False

    ctx.source.instance.runtime_properties['instance_id'] = \
        instance_id
    ctx.logger.info('Either instance or volume is an external resource so not '
                    'performing attach operation.')
    return True
示例#12
0
def _detach_external_volume_or_instance():
    """Pretends to detach an external EBC volume with an EC2 instance
    but if one was not created by Cloudify, it just sets runtime_properties
    and exits the operation.

    :return False: At least one is a Cloudify resource. Continue operation.
    :return True: Both are External resources. Set runtime_properties.
        Ignore operation.
    """

    if not utils.use_external_resource(ctx.source.node.properties) \
            or not utils.use_external_resource(
                ctx.target.node.properties):
        return False

    utils.unassign_runtime_property_from_resource(
        'instance_id', ctx.source.instance)
    ctx.logger.info(
        'Either instance or EBS volume is an external resource so not '
        'performing detach operation.')
    return True
def _associate_external_elasticip_or_instance(elasticip):
    """Pretends to associate an Elastic IP with an EC2 instance but if one
    was not created by Cloudify, it just sets runtime_properties
    and exits the operation.

    :return False: At least one is a Cloudify resource. Continue operation.
    :return True: Both are External resources. Set runtime_properties.
        Ignore operation.
    """

    if not utils.use_external_resource(ctx.source.node.properties) \
            or not utils.use_external_resource(
                ctx.target.node.properties):
        return False

    ctx.logger.info(
        'Either instance or elasticip is an external resource so not '
        'performing associate operation.')
    ctx.source.instance.runtime_properties['public_ip_address'] = \
        elasticip
    return True
def _disassociate_external_elasticip_or_instance():
    """Pretends to disassociate an Elastic IP with an EC2 instance but if one
    was not created by Cloudify, it just deletes runtime_properties
    and exits the operation.

    :return False: At least one is a Cloudify resource. Continue operation.
    :return True: Both are External resources. Set runtime_properties.
        Ignore operation.
    """

    if not utils.use_external_resource(ctx.source.node.properties) \
            or not utils.use_external_resource(
                ctx.target.node.properties):
        return False

    ctx.logger.info(
        'Either instance or elasticip is an external resource so not '
        'performing disassociate operation.')
    utils.unassign_runtime_property_from_resource('public_ip_address',
                                                  ctx.source.instance)
    return True
示例#15
0
    def test_utils_use_external_resource_external(self):

        ctx = self.mock_ctx(
            'test_utils_use_external_resource_external')
        current_ctx.set(ctx=ctx)

        ctx.node.properties['use_external_resource'] = True
        ctx.node.properties['resource_id'] = \
            'test_utils_use_external_resource_external'

        self.assertEquals(
            True,
            utils.use_external_resource(ctx.node.properties))
def _create_external_instance():

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

    instance_id = ctx.node.properties["resource_id"]
    instance = _get_instance_from_id(instance_id)
    if instance is None:
        raise NonRecoverableError(
            "Cannot use_external_resource because instance_id {0} " "is not in this account.".format(instance_id)
        )
    utils.set_external_resource_id(instance.id, ctx.instance)
    return True
示例#17
0
def _create_external_instance():

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

    instance_id = ctx.node.properties['resource_id']
    instance = _get_instance_from_id(instance_id)
    if instance is None:
        raise NonRecoverableError(
            'Cannot use_external_resource because instance_id {0} '
            'is not in this account.'.format(instance_id))
    utils.set_external_resource_id(instance.id, ctx.instance)
    return True
def _release_external_elasticip():
    """Pretends to release an Elastic IP but if it was
    not created by Cloudify, it just deletes runtime_properties
    and exits the operation.

    :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

    utils.unassign_runtime_property_from_resource(constants.EXTERNAL_RESOURCE_ID, ctx.instance)
    return True
def _release_external_elasticip():
    """Pretends to release an Elastic IP but if it was
    not created by Cloudify, it just deletes runtime_properties
    and exits the operation.

    :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

    utils.unassign_runtime_property_from_resource(
        constants.EXTERNAL_RESOURCE_ID, ctx.instance)
    return True
示例#20
0
def _delete_external_volume():
    """If use_external_resource is True, this will delete the runtime_properties,
    and then exit.

    :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 EBS volume from account.')
    utils.unassign_runtime_property_from_resource(
        constants.EXTERNAL_RESOURCE_ID, ctx.instance)
    return True
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_property_from_resource(
        constants.EXTERNAL_RESOURCE_ID, ctx.instance)
    return True
示例#22
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 _create_external_securitygroup(name):
    """If use_external_resource is True, this will set the runtime_properties,
    and then exit.

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

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

    group = _get_security_group_from_id(name)
    if not group:
        raise NonRecoverableError(
            'External security group was indicated, but the given '
            'security group does not exist.')
    utils.set_external_resource_id(group.id, ctx.instance)
    return True
示例#24
0
def _create_external_volume():
    """If use_external_resource is True, this will set the runtime_properties,
    and then exit.

    :return False: Cloudify resource. Continue operation.
    :return True: External resource. Set runtime_properties. Ignore operation.
    """

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

    volume_id = ctx.node.properties['resource_id']

    volume = _get_volumes_from_id(volume_id)
    if not volume:
        raise NonRecoverableError('External EBS volume was indicated, but the '
                                  'volume id does not exist.')
    utils.set_external_resource_id(volume.id, ctx.instance)
    return True
def _allocate_external_elasticip():
    """Pretends to allocate an Elastic IP but if it was
    not created by Cloudify, it just sets runtime_properties
    and exits the operation.

    :return False: Cloudify resource. Continue operation.
    :return True: External resource. Set runtime_properties. Ignore operation.
    """

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

    address_ip = _get_address_by_id(ctx.node.properties['resource_id'])
    if not address_ip:
        raise NonRecoverableError(
            'External elasticip was indicated, but the given '
            'elasticip does not exist in the account.')
    utils.set_external_resource_id(address_ip, ctx.instance)
    return True
def _allocate_external_elasticip():
    """Pretends to allocate an Elastic IP but if it was
    not created by Cloudify, it just sets runtime_properties
    and exits the operation.

    :return False: Cloudify resource. Continue operation.
    :return True: External resource. Set runtime_properties. Ignore operation.
    """

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

    address_ip = _get_address_by_id(ctx.node.properties["resource_id"])
    if not address_ip:
        raise NonRecoverableError(
            "External elasticip was indicated, but the given " "elasticip does not exist in the account."
        )
    utils.set_external_resource_id(address_ip, ctx.instance)
    return True
示例#27
0
def _create_external_volume():
    """If use_external_resource is True, this will set the runtime_properties,
    and then exit.

    :return False: Cloudify resource. Continue operation.
    :return True: External resource. Set runtime_properties. Ignore operation.
    """

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

    volume_id = ctx.node.properties['resource_id']

    volume = _get_volumes_from_id(volume_id)
    if not volume:
        raise NonRecoverableError(
            'External EBS volume was indicated, but the '
            'volume id does not exist.')
    utils.set_external_resource_id(volume.id, ctx.instance)
    return True
def use_external_elb(**_):

    utils.use_external_resource(ctx.node.properties)
def use_external_elb(**_):

    utils.use_external_resource(ctx.node.properties)