aboutsummaryrefslogtreecommitdiffstats
path: root/Testcases/cfgm_common/ifmap/operations.py
blob: c4c2055a96aa2379f6cd4c473681e5887f7eb85f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Copyright 2011, Infoblox, All Rights Reserved
#
# Open Source, see LICENSE
#
from util import attr, link_ids

class OperationBase:
	""" foundation class for operation factory """
	pass

class PublishUpdateOperation(OperationBase):
    def __init__(self, id1, metadata, id2=None, lifetime=None):
        self.__id = link_ids(id1, id2)
        self.__metadata = metadata
        self.__lifetime = lifetime
    
    def __str__(self):
        if self.__lifetime:
            _attr = attr({'lifetime':self.__lifetime})
            return '<update %s>' % _attr + self.__id + self.__metadata + '</update>'
        else:
            return '<update>' + self.__id + self.__metadata + '</update>'
    
class PublishDeleteOperation(OperationBase):
    def __init__(self, id1, id2=None, filter=None):
        self.__id = link_ids(id1, id2)
        self.__filter = filter
    
    def __str__(self):
        if self.__filter:
            _attr = attr({'filter':self.__filter})
            return '<delete %s>' % _attr + self.__id + '</delete>'
        else:
            return '<delete>' + self.__id + '</delete>'

class PublishNotifyOperation(OperationBase):
    def __init__(self, id1, metadata, id2=None):
        self.__id = link_ids(id1, id2)
        self.__metadata = metadata
    
    def __str__(self):
        return '<notify>' + self.__id + self.__metadata + '</notify>'
        
class SubscribeUpdateOperation(OperationBase):
	"""
	SubscribeUpdate factory
	name
	identifier (single, or linked with link_ids())
	search_parameters - dictionary eg. {'max_depth':'3', 'max_size':'10000'}
		result_filter             => string, #Optional. Rules for extracting specific data from the results
		match_links               => string, #Optional. Filter to match links to be followed, unmatched links will not be followed in the search process
		max_depth                 => number, #Optional. Maximum distance of any included identifiers. Start depth is equal to 0
		max_size                  => number, #Optional. Maximum size in bytes of the results
		terminal_identifier_type  => string, #Optional. Terminal identifier type of the search request
	"""
	def __init__(self, name, identifier, search_parameters={}):
		self.__name = name
		self.__identifier = identifier
		self.__parameters = search_parameters
		
	def __str__(self):
		__attr = attr(self.__parameters)
		return '<update name="'+ self.__name + '" ' + __attr + '>' + self.__identifier +'</update>'
	
class SubscribeDeleteOperation(OperationBase):
	def __init__(self, name):
		self.__name = name
	
	def __str__(self):
		return '<delete name="'+ self.__name + '" />'