예제 #1
0
    def del_attr(self, state_data, api, node_id, **kwargs):
        """
        delete an existing node attribute

        required kwargs:
        key: key of attr to delete
        """

        if not 'key' in kwargs:
            return self._fail(msg='need either "key" kwarg')

        old_attr = None

        old_attr = api._model_query(
            'attrs', 'node_id=%d and key="%s"' % (int(node_id),
                                                  kwargs['key']))

        if old_attr is None:
            return self._ok()

        old_attr = old_attr[0]

        api._model_delete_by_id('attrs', old_attr['id'])

        reply_data = {
            'rollback': {
                'primitive': 'node.set_attr',
                'ns': {
                    'key': old_attr['key'],
                    'value': old_attr['value']}}}

        return self._ok(data=reply_data)
예제 #2
0
    def del_fact(self, state_data, api, node_id, **kwargs):
        """
        delete an existing fact.

        required kwargs:
        key: key of fact to delete
        """

        if not 'key' in kwargs:
            return self._fail(msg='need "key" kwarg')

        old_fact = None

        old_fact = api._model_query(
            'facts', 'node_id=%d and key="%s"' % (int(node_id),
                                                  kwargs['key']))

        if old_fact is None:
            return self._ok()  # no rollback necessary

        old_fact = old_fact[0]

        api._model_delete_by_id('facts', old_fact['id'])

        reply_data = {
            'rollback': {
                'primitive': 'node.set_fact',
                'ns': {
                    'key': old_fact['key'],
                    'value': old_fact['value']}}}

        return self._ok(data=reply_data)