blob: df2121e2edf0023b6718fa9c693f7da1e8d7ecdf [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'
lanqinglongd0dda2e2015-08-25 11:02:48 +080014 self.admin_state_up = True
lanqinglong77124b02015-08-06 11:47:38 +080015 self.tenant_id = ''
lanqinglongd0dda2e2015-08-25 11:02:48 +080016 self.routerExternal = False
lanqinglong77124b02015-08-06 11:47:38 +080017 self.type ='LOCAL'
18 self.segmentationID = '6'
lanqinglongd0dda2e2015-08-25 11:02:48 +080019 self.shared = False
lanqinglong77124b02015-08-06 11:47:38 +080020
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
lanqinglonge675e922015-08-13 21:17:28 +080070 try:
71 Socom = SourceCompareDataDic[FirstPara][SecondPara]
72 Decom = DestiCompareDataDic[FirstPara][SecondPara]
73 except KeyError,error:
74 print "Key error ,This key is not found:%s"%error
lanqinglongd0dda2e2015-08-25 11:02:48 +080075 return False
lanqinglonge675e922015-08-13 21:17:28 +080076
77 if str(Socom).lower()== str(Decom).lower():
lanqinglong77124b02015-08-06 11:47:38 +080078 return True
79 else:
lanqinglonge675e922015-08-13 21:17:28 +080080 print "Source Compare data:"+FirstPara+"."+SecondPara+"="+str(Socom)
lanqinglong77124b02015-08-06 11:47:38 +080081 print "Dest Compare data: "+FirstPara+"."+SecondPara+"="+str(Decom)
82 return False
83
84class SubnetData(NetworkData):
85
86 def __init__(self):
87 self.id = ''
88 self.tenant_id = ''
89 self.network_id = ''
90 self.nexthop = '192.168.1.1'
91 self.destination = '192.168.1.1/24'
92 self.start = '192.168.2.2'
93 self.end = '192.168.2.254'
94 self.ipv6_address_mode = 'DHCPV6_STATELESS'
95 self.ipv6_ra_mode = 'DHCPV6_STATELESS'
96 self.cidr = '192.168.1.1/24'
lanqinglongd0dda2e2015-08-25 11:02:48 +080097 self.enable_dhcp = True
lanqinglong77124b02015-08-06 11:47:38 +080098 self.dns_nameservers = 'aaa'
99 self.gateway_ip = '192.168.2.1'
lanqinglongd0dda2e2015-08-25 11:02:48 +0800100 self.ip_version = '4'
101 self.shared = False
lanqinglong77124b02015-08-06 11:47:38 +0800102 self.name = 'demo-subnet'
103
104 def DictoJson(self):
105 if self.id =='' or self.tenant_id == '':
106 print 'Id and tenant id is necessary!'
107
108 Dicdata = {}
109 host_routesdata = []
110 host_routesdata.append({'nexthop': self.nexthop,'destination': self.destination})
111 allocation_pools = []
112 allocation_pools.append({'start': self.start,'end':self.end})
113
114 if self.id != '':
115 Dicdata['id'] = self.id
116 if self.network_id != '':
117 Dicdata['network_id'] = self.network_id
118 if self.name != '':
119 Dicdata['name'] = self.name
120 if self.nexthop != '':
121 Dicdata['host_routes'] = host_routesdata
122 if self.tenant_id != '':
123 Dicdata['tenant_id'] = self.tenant_id
124 if self.start != '':
125 Dicdata['allocation_pools'] = allocation_pools
126 if self.shared != '':
127 Dicdata['shared'] = self.shared
128 if self.ipv6_address_mode != '':
129 Dicdata['ipv6_address_mode'] = self.ipv6_address_mode
130 if self.ipv6_ra_mode != '':
131 Dicdata['ipv6_ra_mode'] = self.ipv6_ra_mode
132 if self.cidr != '':
133 Dicdata['cidr'] = self.cidr
134 if self.enable_dhcp != '':
135 Dicdata['enable_dhcp'] = self.enable_dhcp
136 if self.dns_nameservers != '':
137 Dicdata['dns_nameservers'] = self.dns_nameservers
138 if self.gateway_ip != '':
139 Dicdata['gateway_ip'] = self.gateway_ip
140 if self.ip_version != '':
141 Dicdata['ip_version'] = self.ip_version
142
143 Dicdata = {'subnet': Dicdata}
144
145 return json.dumps(Dicdata,indent=4)
146
lanqinglong77124b02015-08-06 11:47:38 +0800147class VirtualPortData(NetworkData):
148
149 def __init__(self):
150 self.id = ''
151 self.state = 'ACTIVE'
152 self.bindingHostId = 'fa:16:3e:76:8e:88'
lanqinglongd0dda2e2015-08-25 11:02:48 +0800153 self.allowedAddressPairs = [{'mac_address':'fa:16:3e:76:8e:88','ip_address':'192.168.1.1'}]
lanqinglong77124b02015-08-06 11:47:38 +0800154 self.deviceOwner = 'none'
155 self.fixedIp = []
156 self.securityGroups = [{'securityGroup':'asd'}]
lanqinglongd0dda2e2015-08-25 11:02:48 +0800157 self.adminStateUp = True
158 self.network_id = ''
159 self.tenant_id = ''
160 self.subnet_id = ''
lanqinglong77124b02015-08-06 11:47:38 +0800161 self.bindingvifDetails = 'port_filter'
162 self.bindingvnicType = 'normal'
163 self.bindingvifType = 'ovs'
164 self.macAddress = 'fa:16:3e:76:8e:88'
165 self.deviceId = 'a08aa'
166 self.name = 'u'
167
168 def DictoJson(self):
lanqinglongd0dda2e2015-08-25 11:02:48 +0800169 if self.id == '' or self.tenant_id == ' ' or \
170 self.network_id == '' or self.subnet_id == '':
lanqinglong77124b02015-08-06 11:47:38 +0800171 print 'Id/tenant id/networkid/subnetId is necessary!'
172
173 Dicdata = {}
174 fixedIp =[]
lanqinglongd0dda2e2015-08-25 11:02:48 +0800175 fixedIp.append({'subnet_id':self.subnet_id,'ip_address':'192.168.1.4'})
lanqinglong77124b02015-08-06 11:47:38 +0800176 allocation_pools = []
177
178 if self.id != '':
179 Dicdata['id'] = self.id
180 if self.state != '':
lanqinglongd0dda2e2015-08-25 11:02:48 +0800181 Dicdata['status'] = self.state
lanqinglong77124b02015-08-06 11:47:38 +0800182 if self.bindingHostId != '':
lanqinglongd0dda2e2015-08-25 11:02:48 +0800183 Dicdata['binding:host_id'] = self.bindingHostId
lanqinglong77124b02015-08-06 11:47:38 +0800184 if self.allowedAddressPairs != '':
lanqinglongd0dda2e2015-08-25 11:02:48 +0800185 Dicdata['allowed_address_pairs'] = self.allowedAddressPairs
lanqinglong77124b02015-08-06 11:47:38 +0800186 if self.deviceOwner != '':
lanqinglongd0dda2e2015-08-25 11:02:48 +0800187 Dicdata['device_owner'] = self.deviceOwner
lanqinglong77124b02015-08-06 11:47:38 +0800188 if self.securityGroups != '':
lanqinglongd0dda2e2015-08-25 11:02:48 +0800189 Dicdata['security_groups'] = self.securityGroups
lanqinglong77124b02015-08-06 11:47:38 +0800190 if self.adminStateUp != '':
lanqinglongd0dda2e2015-08-25 11:02:48 +0800191 Dicdata['admin_state_up'] = self.adminStateUp
192 if self.network_id != '':
193 Dicdata['network_id'] = self.network_id
194 if self.tenant_id != '':
195 Dicdata['tenant_id'] = self.tenant_id
lanqinglong77124b02015-08-06 11:47:38 +0800196 if self.bindingvifDetails != '':
lanqinglongd0dda2e2015-08-25 11:02:48 +0800197 Dicdata['binding:vif_details'] = self.bindingvifDetails
lanqinglong77124b02015-08-06 11:47:38 +0800198 if self.bindingvnicType != '':
lanqinglongd0dda2e2015-08-25 11:02:48 +0800199 Dicdata['binding:vnic_type'] = self.bindingvnicType
lanqinglong77124b02015-08-06 11:47:38 +0800200 if self.bindingvifType != '':
lanqinglongd0dda2e2015-08-25 11:02:48 +0800201 Dicdata['binding:vif_type'] = self.bindingvifType
lanqinglong77124b02015-08-06 11:47:38 +0800202 if self.macAddress != '':
lanqinglongd0dda2e2015-08-25 11:02:48 +0800203 Dicdata['mac_address'] = self.macAddress
lanqinglong77124b02015-08-06 11:47:38 +0800204 if self.deviceId != '':
lanqinglongd0dda2e2015-08-25 11:02:48 +0800205 Dicdata['device_id'] = self.deviceId
lanqinglong77124b02015-08-06 11:47:38 +0800206 if self.name != '':
207 Dicdata['name'] = self.name
208
lanqinglongd0dda2e2015-08-25 11:02:48 +0800209 Dicdata['fixed_ips'] = fixedIp
210 Dicdata = {'port': Dicdata}
lanqinglong77124b02015-08-06 11:47:38 +0800211
lanqinglongd0dda2e2015-08-25 11:02:48 +0800212 return json.dumps(Dicdata,indent=4)