Esempio n. 1
0
    def _modify_node_operation(self, ctx, current_entities):
        new_operation = utils.create_dict(ctx.modification_breadcrumbs,
                                          ctx.raw_entity_value)

        changes = {
            ctx.OPERATIONS: {
                ctx.operation_id: new_operation
            },
            ctx.PLUGINS: ctx.raw_node[ctx.PLUGINS]
        }
        self.sm.update_node(deployment_id=ctx.deployment_id,
                            node_id=ctx.raw_node_id,
                            **changes)
        current_node = current_entities[ctx.raw_node_id]
        if ctx.modification_breadcrumbs:
            operation_to_update = utils.traverse_object(
                current_node[ctx.OPERATIONS][ctx.operation_id],
                ctx.modification_breadcrumbs[:-1])
            operation_to_update[ctx.modification_breadcrumbs[-1]] = \
                ctx.raw_entity_value
        else:
            operation_to_update = current_node[ctx.OPERATIONS]
            operation_to_update[ctx.operation_id] = ctx.raw_entity_value

        current_node[ctx.PLUGINS] = ctx.raw_node[ctx.PLUGINS]

        return ctx.entity_id
Esempio n. 2
0
    def _modify_relationship_operation(self, ctx, current_entities):
        current_node = current_entities[ctx.raw_node_id]
        relationships = current_node[ctx.RELATIONSHIPS]
        operations = relationships[ctx.relationship_index][ctx.operations_key]

        if ctx.modification_breadcrumbs:
            operation_to_update = \
                utils.traverse_object(operations[ctx.operation_id],
                                      ctx.modification_breadcrumbs[:-1])
            operation_to_update[ctx.modification_breadcrumbs[-1]] = \
                ctx.raw_entity_value
        else:
            operations[ctx.operation_id] = ctx.raw_entity_value

        current_node[ctx.PLUGINS] = ctx.raw_node[ctx.PLUGINS]

        changes = {
            ctx.RELATIONSHIPS: relationships,
            ctx.PLUGINS: ctx.raw_node[ctx.PLUGINS]
        }

        self.sm.update_node(deployment_id=ctx.deployment_id,
                            node_id=ctx.raw_node_id,
                            **changes)

        return ctx.entity_id
Esempio n. 3
0
    def modify(self, ctx, current_entities):
        changes = {
            ctx.PROPERTIES: {
                ctx.property_id:
                utils.create_dict(ctx.modification_breadcrumbs,
                                  ctx.raw_entity_value)
            }
        }

        self.sm.update_node(deployment_id=ctx.deployment_id,
                            node_id=ctx.raw_node_id,
                            **changes)

        properties = current_entities[ctx.raw_node_id][ctx.PROPERTIES]

        if ctx.modification_breadcrumbs:
            property_to_update = \
                utils.traverse_object(properties[ctx.property_id],
                                      ctx.modification_breadcrumbs[:-1])
            property_to_update[ctx.modification_breadcrumbs[-1]] = \
                ctx.raw_entity_value
        else:
            properties[ctx.property_id] = ctx.raw_entity_value

        return ctx.entity_id
    def _add_node_operation(self, ctx, current_nodes):

        new_operations = utils.create_dict(ctx.modification_breadcrumbs,
                                           ctx.raw_entity_value)

        changes = {
            ctx.OPERATIONS: {ctx.operation_id: new_operations},
            ctx.PLUGINS: ctx.raw_node[ctx.PLUGINS]
        }

        self.sm.update_node(deployment_id=ctx.deployment_id,
                            node_id=ctx.raw_node_id,
                            changes=changes)
        current_node = current_nodes[ctx.raw_node_id]
        if ctx.modification_breadcrumbs:
            operation_to_update = utils.traverse_object(
                    current_node[ctx.OPERATIONS][ctx.operation_id],
                    ctx.modification_breadcrumbs[:-1]
            )
            operation_to_update[ctx.modification_breadcrumbs[-1]] = \
                ctx.raw_entity_value
        else:
            operation_to_update = current_node[ctx.OPERATIONS]
            operation_to_update[ctx.operation_id] = ctx.raw_entity_value

        current_node[ctx.PLUGINS] = ctx.raw_node[ctx.PLUGINS]

        return ctx.entity_id
    def _add_property(self, ctx, current_nodes):
        changes = {
            ctx.PROPERTIES: {
                ctx.property_id:
                    utils.create_dict(ctx.modification_breadcrumbs,
                                      ctx.raw_entity_value)
            }
        }

        self.sm.update_node(deployment_id=ctx.deployment_id,
                            node_id=ctx.raw_node_id,
                            changes=changes)

        properties = current_nodes[ctx.raw_node_id][ctx.PROPERTIES]
        current_node = current_nodes[ctx.raw_node_id]

        if ctx.modification_breadcrumbs:
            property_to_update = \
                utils.traverse_object(properties[ctx.property_id],
                                      ctx.modification_breadcrumbs[:-1])
            property_to_update[ctx.modification_breadcrumbs[-1]] = \
                ctx.raw_entity_value
        else:
            property_to_update = current_node[ctx.PROPERTIES]
            property_to_update[ctx.property_id] = ctx.raw_entity_value

        return ctx.entity_id
Esempio n. 6
0
    def _validate_property(self, dep_update, step):
        property_keys = utils.get_entity_keys(step.entity_id)

        if len(property_keys) < 2:
            return
        NODES, node_id, PROPERTIES = property_keys[:3]
        property_id = property_keys[3:]

        storage_node = self.sm.get_node(dep_update.deployment_id, node_id)
        raw_node = utils.get_raw_node(dep_update.blueprint, node_id)

        is_in_old = utils.traverse_object(storage_node.properties, property_id)
        is_in_new = utils.traverse_object(raw_node[PROPERTIES], property_id)

        if step.operation == OPERATION_TYPE.REMOVE:
            return is_in_old
        elif step.operation == OPERATION_TYPE.ADD:
            return is_in_new
        else:
            return is_in_old and is_in_new
    def _validate_property(self, dep_update, step):
        property_keys = utils.get_entity_keys(step.entity_id)

        if len(property_keys) < 2:
            return
        NODES, node_id, PROPERTIES = property_keys[:3]
        property_id = property_keys[3:]

        storage_node = self.sm.get_node(dep_update.deployment_id, node_id)
        raw_node = utils.get_raw_node(dep_update.blueprint, node_id)

        is_in_old = utils.traverse_object(storage_node.properties, property_id)
        is_in_new = utils.traverse_object(raw_node[PROPERTIES], property_id)

        if step.operation == OPERATION_TYPE.REMOVE:
            return is_in_old
        elif step.operation == OPERATION_TYPE.ADD:
            return is_in_new
        else:
            return is_in_old and is_in_new
Esempio n. 8
0
    def _validate_operation(self, dep_update, step):
        operation_keys = utils.get_entity_keys(step.entity_id)
        if len(operation_keys) < 2:
            return

        NODES, node_id, operation_host = operation_keys[:3]
        operation_id = operation_keys[3:]

        base_node = self.sm.get_node(dep_update.deployment_id, node_id)
        is_in_old = utils.traverse_object(getattr(base_node, operation_host),
                                          operation_id)

        modified_node = utils.get_raw_node(dep_update.blueprint, node_id)
        is_in_new = utils.traverse_object(modified_node[operation_host],
                                          operation_id)

        if step.operation == OPERATION_TYPE.REMOVE:
            return is_in_old
        elif step.operation == OPERATION_TYPE.ADD:
            return is_in_new
        else:
            return is_in_old and is_in_new
    def _validate_operation(self, dep_update, step):
        operation_keys = utils.get_entity_keys(step.entity_id)
        if len(operation_keys) < 2:
            return

        NODES, node_id, operation_host = operation_keys[:3]
        operation_id = operation_keys[3:]

        base_node = self.sm.get_node(dep_update.deployment_id, node_id)
        is_in_old = utils.traverse_object(getattr(base_node, operation_host),
                                          operation_id)

        modified_node = utils.get_raw_node(dep_update.blueprint, node_id)
        is_in_new = utils.traverse_object(modified_node[operation_host],
                                          operation_id)

        if step.operation == OPERATION_TYPE.REMOVE:
            return is_in_old
        elif step.operation == OPERATION_TYPE.ADD:
            return is_in_new
        else:
            return is_in_old and is_in_new
Esempio n. 10
0
    def modify(self, ctx, current_entities):
        node = get_node(ctx.deployment_id, ctx.raw_node_id)
        properties = deepcopy(node.properties)
        properties[ctx.property_id] = deployment_update_utils.create_dict(
            ctx.modification_breadcrumbs, ctx.raw_entity_value)
        node.properties = properties
        self.sm.update(node)

        properties = current_entities[ctx.raw_node_id][ctx.PROPERTIES]
        if ctx.modification_breadcrumbs:
            property_to_update = \
                deployment_update_utils.traverse_object(
                    properties[ctx.property_id],
                    ctx.modification_breadcrumbs[:-1])
            property_to_update[ctx.modification_breadcrumbs[-1]] = \
                ctx.raw_entity_value
        else:
            properties[ctx.property_id] = ctx.raw_entity_value
        return ctx.entity_id
Esempio n. 11
0
    def _modify_relationship_operation(self, ctx, current_entities):
        current_node = current_entities[ctx.raw_node_id]
        relationships = current_node[ctx.RELATIONSHIPS]
        operations = relationships[ctx.relationship_index][ctx.operations_key]

        if ctx.modification_breadcrumbs:
            operation_to_update = deployment_update_utils.traverse_object(
                operations[ctx.operation_id],
                ctx.modification_breadcrumbs[:-1])
            operation_to_update[ctx.modification_breadcrumbs[-1]] = \
                ctx.raw_entity_value
        else:
            operations[ctx.operation_id] = ctx.raw_entity_value

        current_node[ctx.PLUGINS] = ctx.raw_node[ctx.PLUGINS]
        node = get_node(ctx.deployment_id, ctx.raw_node_id)
        node.relationships = deepcopy(relationships)
        node.plugins = ctx.raw_node[ctx.PLUGINS]
        self.sm.update(node)
        return ctx.entity_id
    def _modify_relationship_operation(self, ctx, current_nodes):

        current_relationships = \
            current_nodes[ctx.raw_node_id][ctx.RELATIONSHIPS]
        current_relationship = current_relationships[ctx.relationship_index]
        operation_to_update = utils.traverse_object(
                current_relationship[ctx.operations_key][ctx.operation_id],
                ctx.modification_breadcrumbs[:-1]
        )

        # Update the changed onto the data model and the current nodes.
        operation_to_update[ctx.modification_breadcrumbs[-1]] = \
            ctx.raw_entity_value

        changes = {ctx.RELATIONSHIPS: current_relationships}
        self.sm.update_node(deployment_id=ctx.deployment_id,
                            node_id=ctx.raw_node_id,
                            changes=changes)

        return ctx.entity_id
Esempio n. 13
0
    def _modify_relationship_operation(self, ctx, current_entities):
        current_node = current_entities[ctx.raw_node_id]
        relationships = current_node[ctx.RELATIONSHIPS]
        operations = relationships[ctx.relationship_index][ctx.operations_key]

        if ctx.modification_breadcrumbs:
            operation_to_update = deployment_update_utils.traverse_object(
                operations[ctx.operation_id],
                ctx.modification_breadcrumbs[:-1]
            )
            operation_to_update[ctx.modification_breadcrumbs[-1]] = \
                ctx.raw_entity_value
        else:
            operations[ctx.operation_id] = ctx.raw_entity_value

        current_node[ctx.PLUGINS] = ctx.raw_node[ctx.PLUGINS]
        node = get_node(ctx.deployment_id, ctx.raw_node_id)
        node.relationships = deepcopy(relationships)
        node.plugins = ctx.raw_node[ctx.PLUGINS]
        self.sm.update(node)
        return ctx.entity_id
Esempio n. 14
0
    def modify(self, ctx, current_entities):
        node = get_node(ctx.deployment_id, ctx.raw_node_id)
        properties = deepcopy(node.properties)
        properties[ctx.property_id] = deployment_update_utils.create_dict(
            ctx.modification_breadcrumbs,
            ctx.raw_entity_value
        )
        node.properties = properties
        self.sm.update(node)

        properties = current_entities[ctx.raw_node_id][ctx.PROPERTIES]
        if ctx.modification_breadcrumbs:
            property_to_update = \
                deployment_update_utils.traverse_object(
                    properties[ctx.property_id],
                    ctx.modification_breadcrumbs[:-1])
            property_to_update[ctx.modification_breadcrumbs[-1]] = \
                ctx.raw_entity_value
        else:
            properties[ctx.property_id] = ctx.raw_entity_value
        return ctx.entity_id
Esempio n. 15
0
    def _modify_node_operation(self, ctx, current_entities):
        new_operation = deployment_update_utils.create_dict(
            ctx.modification_breadcrumbs, ctx.raw_entity_value)
        node = get_node(ctx.deployment_id, ctx.raw_node_id)
        operations = deepcopy(node.operations)
        operations.update({ctx.operation_id: new_operation})
        node.operations = operations
        node.plugins = ctx.raw_node[ctx.PLUGINS]
        self.sm.update(node)

        current_node = current_entities[ctx.raw_node_id]
        if ctx.modification_breadcrumbs:
            operation_to_update = deployment_update_utils.traverse_object(
                current_node[ctx.OPERATIONS][ctx.operation_id],
                ctx.modification_breadcrumbs[:-1])
            operation_to_update[ctx.modification_breadcrumbs[-1]] = \
                ctx.raw_entity_value
        else:
            operation_to_update = current_node[ctx.OPERATIONS]
            operation_to_update[ctx.operation_id] = ctx.raw_entity_value
        current_node[ctx.PLUGINS] = ctx.raw_node[ctx.PLUGINS]
        return ctx.entity_id
Esempio n. 16
0
    def _modify_node_operation(self, ctx, current_entities):
        new_operation = deployment_update_utils.create_dict(
            ctx.modification_breadcrumbs, ctx.raw_entity_value)
        node = get_node(ctx.deployment_id, ctx.raw_node_id)
        operations = deepcopy(node.operations)
        operations.update({ctx.operation_id: new_operation})
        node.operations = operations
        node.plugins = ctx.raw_node[ctx.PLUGINS]
        self.sm.update(node)

        current_node = current_entities[ctx.raw_node_id]
        if ctx.modification_breadcrumbs:
            operation_to_update = deployment_update_utils.traverse_object(
                    current_node[ctx.OPERATIONS][ctx.operation_id],
                    ctx.modification_breadcrumbs[:-1]
            )
            operation_to_update[ctx.modification_breadcrumbs[-1]] = \
                ctx.raw_entity_value
        else:
            operation_to_update = current_node[ctx.OPERATIONS]
            operation_to_update[ctx.operation_id] = ctx.raw_entity_value
        current_node[ctx.PLUGINS] = ctx.raw_node[ctx.PLUGINS]
        return ctx.entity_id
Esempio n. 17
0
 def storage_entity_value(self):
     return utils.traverse_object(self.storage_entity,
                                  self.modification_breadcrumbs)
Esempio n. 18
0
 def raw_entity_value(self):
     return utils.traverse_object(self.raw_entity,
                                  self._modification_breadcrumbs)
 def _get_entity_value(self, source_entity):
     if self._modification_breadcrumbs:
         return utils.traverse_object(source_entity,
                                      self.modification_breadcrumbs)
     else:
         return source_entity
Esempio n. 20
0
 def _get_entity_value(self, source_entity):
     if self._modification_breadcrumbs:
         return utils.traverse_object(source_entity,
                                      self.modification_breadcrumbs)
     else:
         return source_entity