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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
#
# Copyright 2011, Infoblox, All Rights Reserved
#
# Open Source, see LICENSE
# Module with ID factories for creating IF-MAP Identifiers.
# Identifiers are used, for example, when publishing to an IF-MAP server, to represent an IP address.
# The XML for such the IP address identifier would be generated by ifmap.id.IPAddress
# example:
# >>> print ifmap.id.IPAdress('10.0.0.1')
from util import attr
class ifmapIDFactory:
pass
class IPAddress(ifmapIDFactory):
"""
XML Factory for an IP Address IF-MAP Identifier
"""
def __init__(self, ip_address, type=None, administrative_domain=None):
self.__ip_address = ip_address
self.__type = type
self.__administrative_domain = administrative_domain
def administrative_domain(self):
return self.__administrative_domain
def ip_address(self):
return self.__ip_address
def type(self):
return self.__type
def __str__(self):
_attr = attr({'value':self.__ip_address,'type':self.__type,'administrative-domain':self.__administrative_domain})
return '<ip-address %s' % _attr + '/>'
class MACAddress(ifmapIDFactory):
"""
XML Factory for a MAC Address IF-MAP Identifier
"""
def __init__(self, mac_address, administrative_domain=None):
self.__mac_address = mac_address
self.__administrative_domain = administrative_domain
return None;
def administrative_domain(self):
return self.__administrative_domain
def mac_address(self):
return self.__mac_address
def __str__(self):
_attr = attr({'value':self.__mac_address,'administrative-domain':self.__administrative_domain})
return '<mac-address %s' % _attr + '/>'
class Device(ifmapIDFactory):
"""
XML Factory for a Device IF-MAP Identifier
"""
def __init__(self, name, aik_name=None):
self.__name = name
self.__aik_name = aik_name
return None;
def aik_name(self):
return self.__aik_name
def name(self):
return self.__name
def __str__(self):
self.__XML = "<device>"
self.__XML += '<name>'+self.__name+'</name>'
# aik_name is optional
if self.__aik_name:
self.__XML += '<aik-name>'+self.__aik_name+'<aik-name>'
self.__XML += "</device>"
return self.__XML
class AccessRequest(ifmapIDFactory):
"""
XML Factory for an Access Request IF-MAP Identifier
"""
def __init__(self, name, administrative_domain=None):
self.__name = name
self.__administrative_domain = administrative_domain
return None;
def administrative_domain(self):
return self.__administrative_domain
def name(self):
return self.__name
def __str__(self):
self.__XML = "<access-request"
self.__XML += ' name="'+self.__name+'"'
# administrative_domain is optional
if self.__administrative_domain:
self.__XML += ' administrative-domain="'+self.__administrative_domain+'"'
self.__XML += " />"
return self.__XML
class Identity(ifmapIDFactory):
"""
XML Factory for an IF-MAP Identifier
"""
def __init__(self, name, type=None, other_type=None, administrative_domain=None):
self.__name = name # required
self.__type = type # "aik_name"|"distinguished_name"|"dns_name"|"email_address"|"kerberos_principal"|"username"|"sip_uri"|"tel_uri"|"hip_hit"|"other"
self.__other_type = other_type # vendor-specific type
self.__administrative_domain = administrative_domain
return None;
def administrative_domain(self):
return self.__administrative_domain
def name(self):
return self.__name
def type(self):
return self.__type
def other_type(self):
return self.__other_type
def __str__(self):
self.__XML = "<identity"
self.__XML += ' name="'+self.__name+'"'
# type and administrative_domain are optional
if self.__type:
self.__XML +=' type="'+self.__type+'"'
if self.__other_type:
self.__XML +=' other-type-definition="'+self.__other_type+'"'
if self.__administrative_domain:
self.__XML += ' administrative-domain="'+self.__administrative_domain+'"'
self.__XML += " />"
return self.__XML
class CustomIdentity(ifmapIDFactory):
"""
XML Factory for an Custom IF-MAP Identifier with namespace prefix or URL
"""
def __init__(self, name, ns_prefix="", namespace="", attributes=None):
self.__name = name # required
self.__ns_prefix = ns_prefix # see ifmap.namespaces
self.__namespace = namespace # a namespace IRI/URI
self.__attributes = attributes # additional attributes in a dictionary (eg. {key1: value1, key2: value2})
return None;
def attributes(self):
return self.__attributes
def name(self):
return self.__name
def ns_prefix(self):
return self.__ns_prefix
def namespace(self):
return self.__namespace
def __str__(self):
self.__XML = "<custom-identifier>"
if self.__ns_prefix:
self.__ns_prefix = self.__ns_prefix +':'
self.__XML += '<'+self.__ns_prefix+self.__name
if self.__namespace:
self.__namespace=' xlmns='+self.__ns_prefix+self.__namespace
self.__XML += self.__namespace
if self.__attributes and (type(self.__attributes) == type({})) and self.__attributes.items():
for key, attribute in self.__attributes.items():
self.__XML += ' '+key+'="'+attribute+'"'
self.__XML += " /></custom-identifier>"
return self.__XML
|