blob: c002c4aeb744f20761f9ad72eb7a04bf3022fc0a [file] [log] [blame]
lanqinglong77124b02015-08-06 11:47:38 +08001"""
2This file provide the data
3lanqinglong@huawei.com
4"""
5import json
6
7class NetworkData:
8
9 def __init__(self):
10 self.id = ''
11 self.state = 'ACTIVE'
12 self.name = 'onosfw-1'
13 self.physicalNetwork = 'none'
14 self.admin_state_up = 'true'
15 self.tenant_id = ''
16 self.routerExternal = 'false'
17 self.type ='LOCAL'
18 self.segmentationID = '6'
19 self.shared = 'false'
20
21 def DictoJson(self):
22
23 if self.id =='' or self.tenant_id == '':
24 print 'Id and tenant id is necessary!'
25
26 Dicdata = {}
27 if self.id !='':
28 Dicdata['id'] = self.id
29 if self.state != '':
30 Dicdata['status'] = self.state
31 if self.name !='':
32 Dicdata['name'] = self.name
33 if self.physicalNetwork !='':
34 Dicdata['provider:physical_network'] = self.physicalNetwork
35 if self.admin_state_up !='':
36 Dicdata['admin_state_up'] = self.admin_state_up
37 if self.tenant_id !='':
38 Dicdata['tenant_id'] = self.tenant_id
39 if self.routerExternal !='':
40 Dicdata['router:external'] = self.routerExternal
41 if self.type !='':
42 Dicdata['provider:network_type'] = self.type
43 if self.segmentationID !='':
44 Dicdata['provider:segmentation_id'] = self.segmentationID
45 if self.shared !='':
46 Dicdata['shared'] = self.shared
47
48 Dicdata = {'network': Dicdata}
49
50 return json.dumps(Dicdata,indent=4)
51
52 def Ordered(self,obj):
53
54 if isinstance(obj, dict):
55 return sorted((k,self.Ordered(v)) for k, v in obj.items())
56 if isinstance(obj, list):
57 return sorted(self.Ordered(x) for x in obj )
58 else:
59 return obj
60
61 def JsonCompare(self,SourceData,DestiData,FirstPara,SecondPara):
62
63 try:
64 SourceCompareDataDic = json.loads(SourceData)
65 DestiCompareDataDic = json.loads(DestiData)
66 except ValueError:
67 print "SourceData or DestData is not JSON Type!"
68 return False
69
70 Socom = SourceCompareDataDic[FirstPara][SecondPara]
71 Decom = DestiCompareDataDic[FirstPara][SecondPara]
72 if Socom == Decom:
73 return True
74 else:
75 print "Source Compare data:"+FirstPara+"."+SecondPara+"="+Socom
76 print "Dest Compare data: "+FirstPara+"."+SecondPara+"="+str(Decom)
77 return False
78
79class SubnetData(NetworkData):
80
81 def __init__(self):
82 self.id = ''
83 self.tenant_id = ''
84 self.network_id = ''
85 self.nexthop = '192.168.1.1'
86 self.destination = '192.168.1.1/24'
87 self.start = '192.168.2.2'
88 self.end = '192.168.2.254'
89 self.ipv6_address_mode = 'DHCPV6_STATELESS'
90 self.ipv6_ra_mode = 'DHCPV6_STATELESS'
91 self.cidr = '192.168.1.1/24'
92 self.enable_dhcp = 'true'
93 self.dns_nameservers = 'aaa'
94 self.gateway_ip = '192.168.2.1'
95 self.ip_version = 'INET'
96 self.shared = 'false'
97 self.name = 'demo-subnet'
98
99 def DictoJson(self):
100 if self.id =='' or self.tenant_id == '':
101 print 'Id and tenant id is necessary!'
102
103 Dicdata = {}
104 host_routesdata = []
105 host_routesdata.append({'nexthop': self.nexthop,'destination': self.destination})
106 allocation_pools = []
107 allocation_pools.append({'start': self.start,'end':self.end})
108
109 if self.id != '':
110 Dicdata['id'] = self.id
111 if self.network_id != '':
112 Dicdata['network_id'] = self.network_id
113 if self.name != '':
114 Dicdata['name'] = self.name
115 if self.nexthop != '':
116 Dicdata['host_routes'] = host_routesdata
117 if self.tenant_id != '':
118 Dicdata['tenant_id'] = self.tenant_id
119 if self.start != '':
120 Dicdata['allocation_pools'] = allocation_pools
121 if self.shared != '':
122 Dicdata['shared'] = self.shared
123 if self.ipv6_address_mode != '':
124 Dicdata['ipv6_address_mode'] = self.ipv6_address_mode
125 if self.ipv6_ra_mode != '':
126 Dicdata['ipv6_ra_mode'] = self.ipv6_ra_mode
127 if self.cidr != '':
128 Dicdata['cidr'] = self.cidr
129 if self.enable_dhcp != '':
130 Dicdata['enable_dhcp'] = self.enable_dhcp
131 if self.dns_nameservers != '':
132 Dicdata['dns_nameservers'] = self.dns_nameservers
133 if self.gateway_ip != '':
134 Dicdata['gateway_ip'] = self.gateway_ip
135 if self.ip_version != '':
136 Dicdata['ip_version'] = self.ip_version
137
138 Dicdata = {'subnet': Dicdata}
139
140 return json.dumps(Dicdata,indent=4)
141
142 def Ordered(self,obj):
143 super(NetworkData,self).Ordered(obj)
144
145 def JsonCompare(self,SourceData,DestiData,FirstPara,SecondPara):
146 super(NetworkData,self).JsonCompare(SourceData,DestiData,FirstPara,SecondPara)
147
148class VirtualPortData(NetworkData):
149
150 def __init__(self):
151 self.id = ''
152 self.state = 'ACTIVE'
153 self.bindingHostId = 'fa:16:3e:76:8e:88'
154 self.allowedAddressPairs = [{'macAddress':'fa:16:3e:76:8e:88','ipAddress':'192.168.1.1'}]
155 self.deviceOwner = 'none'
156 self.fixedIp = []
157 self.securityGroups = [{'securityGroup':'asd'}]
158 self.adminStateUp = 'true'
159 self.networkId = ''
160 self.tenantId = ''
161 self.subnetId = ''
162 self.bindingvifDetails = 'port_filter'
163 self.bindingvnicType = 'normal'
164 self.bindingvifType = 'ovs'
165 self.macAddress = 'fa:16:3e:76:8e:88'
166 self.deviceId = 'a08aa'
167 self.name = 'u'
168
169 def DictoJson(self):
170 if self.id == '' or self.tenant_id == ' ' or self.networkId == '':
171 print 'Id/tenant id/networkid/subnetId is necessary!'
172
173 Dicdata = {}
174 fixedIp =[]
175 fixedIp.append({'subnetId':self.subnetId,'ipAddress':'192.168.1.4'})
176 allocation_pools = []
177
178 if self.id != '':
179 Dicdata['id'] = self.id
180 if self.state != '':
181 Dicdata['state'] = self.state
182 if self.bindingHostId != '':
183 Dicdata['bindingHostId'] = self.bindingHostId
184 if self.allowedAddressPairs != '':
185 Dicdata['allowedAddressPairs'] = self.allowedAddressPairs
186 if self.deviceOwner != '':
187 Dicdata['deviceOwner'] = self.deviceOwner
188 if self.fixedIp != []:
189 Dicdata['fixedIp'] = fixedIp
190 if self.securityGroups != '':
191 Dicdata['securityGroups'] = self.securityGroups
192 if self.adminStateUp != '':
193 Dicdata['adminStateUp'] = self.adminStateUp
194 if self.networkId != '':
195 Dicdata['networkId'] = self.networkId
196 if self.tenantId != '':
197 Dicdata['tenantId'] = self.tenantId
198 if self.subnetId != '':
199 Dicdata['subnetId'] = self.subnetId
200 if self.bindingvifDetails != '':
201 Dicdata['bindingvifDetails'] = self.bindingvifDetails
202 if self.bindingvnicType != '':
203 Dicdata['bindingvnicType'] = self.bindingvnicType
204 if self.bindingvifType != '':
205 Dicdata['bindingvifType'] = self.bindingvifType
206 if self.macAddress != '':
207 Dicdata['macAddress'] = self.macAddress
208 if self.deviceId != '':
209 Dicdata['deviceId'] = self.deviceId
210 if self.name != '':
211 Dicdata['name'] = self.name
212
213 Dicdata = {'virtualport': Dicdata}
214
215 return json.dumps(Dicdata,indent=4)
216
217 def Ordered(self,obj):
218 super(NetworkData,self).Ordered(obj)
219
220 def JsonCompare(self,SourceData,DestiData,FirstPara,SecondPara):
221 super(NetworkData,self).JsonCompare(SourceData,DestiData,FirstPara,SecondPara)