blob: 6c8725e92d152b987c3ee509892f86a4c09f9458 [file] [log] [blame]
zhanghaoyu7474d8c62015-08-26 14:53:28 +08001"""
2This file provide the data
3lanqinglong@huawei.com
4"""
5import json
6
Jon Hall8638b562017-05-24 16:39:59 -07007
zhanghaoyu7474d8c62015-08-26 14:53:28 +08008class NetworkData:
9
Jon Hall8638b562017-05-24 16:39:59 -070010 def __init__( self ):
zhanghaoyu7474d8c62015-08-26 14:53:28 +080011 self.id = ''
12 self.state = 'ACTIVE'
13 self.name = 'onosfw-1'
14 self.physicalNetwork = 'none'
15 self.admin_state_up = True
16 self.tenant_id = ''
17 self.routerExternal = False
Jon Hall8638b562017-05-24 16:39:59 -070018 self.type = 'LOCAL'
zhanghaoyu7474d8c62015-08-26 14:53:28 +080019 self.segmentationID = '6'
20 self.shared = False
21
Jon Hall8638b562017-05-24 16:39:59 -070022 def DictoJson( self ):
zhanghaoyu7474d8c62015-08-26 14:53:28 +080023
Jon Hall8638b562017-05-24 16:39:59 -070024 if self.id == '' or self.tenant_id == '':
zhanghaoyu7474d8c62015-08-26 14:53:28 +080025 print 'Id and tenant id is necessary!'
26
27 Dicdata = {}
Jon Hall8638b562017-05-24 16:39:59 -070028 if self.id != '':
29 Dicdata[ 'id' ] = self.id
zhanghaoyu7474d8c62015-08-26 14:53:28 +080030 if self.state != '':
Jon Hall8638b562017-05-24 16:39:59 -070031 Dicdata[ 'status' ] = self.state
32 if self.name != '':
33 Dicdata[ 'name' ] = self.name
34 if self.physicalNetwork != '':
35 Dicdata[ 'provider:physical_network' ] = self.physicalNetwork
36 if self.admin_state_up != '':
37 Dicdata[ 'admin_state_up' ] = self.admin_state_up
38 if self.tenant_id != '':
39 Dicdata[ 'tenant_id' ] = self.tenant_id
40 if self.routerExternal != '':
41 Dicdata[ 'router:external' ] = self.routerExternal
42 if self.type != '':
43 Dicdata[ 'provider:network_type' ] = self.type
44 if self.segmentationID != '':
45 Dicdata[ 'provider:segmentation_id' ] = self.segmentationID
46 if self.shared != '':
47 Dicdata[ 'shared' ] = self.shared
zhanghaoyu7474d8c62015-08-26 14:53:28 +080048
Jon Hall8638b562017-05-24 16:39:59 -070049 Dicdata = { 'network': Dicdata }
zhanghaoyu7474d8c62015-08-26 14:53:28 +080050
Jon Hall8638b562017-05-24 16:39:59 -070051 return json.dumps( Dicdata, indent=4 )
zhanghaoyu7474d8c62015-08-26 14:53:28 +080052
Jon Hall8638b562017-05-24 16:39:59 -070053 def Ordered( self, obj ):
zhanghaoyu7474d8c62015-08-26 14:53:28 +080054
Jon Hall8638b562017-05-24 16:39:59 -070055 if isinstance( obj, dict ):
56 return sorted( ( k, self.Ordered( v ) ) for k, v in obj.items() )
57 if isinstance( obj, list ):
58 return sorted( self.Ordered( x ) for x in obj )
zhanghaoyu7474d8c62015-08-26 14:53:28 +080059 else:
60 return obj
61
Jon Hall8638b562017-05-24 16:39:59 -070062 def JsonCompare( self, SourceData, DestiData, FirstPara, SecondPara ):
zhanghaoyu7474d8c62015-08-26 14:53:28 +080063
64 try:
Jon Hall8638b562017-05-24 16:39:59 -070065 SourceCompareDataDic = json.loads( SourceData )
66 DestiCompareDataDic = json.loads( DestiData )
zhanghaoyu7474d8c62015-08-26 14:53:28 +080067 except ValueError:
68 print "SourceData or DestData is not JSON Type!"
69 return False
70
71 try:
Jon Hall8638b562017-05-24 16:39:59 -070072 Socom = SourceCompareDataDic[ FirstPara ][ SecondPara ]
73 Decom = DestiCompareDataDic[ FirstPara ][ SecondPara ]
74 except KeyError as error:
75 print "Key error ,This key is not found:%s" % error
zhanghaoyu7474d8c62015-08-26 14:53:28 +080076 return False
77
Jon Hall8638b562017-05-24 16:39:59 -070078 if str( Socom ).lower() == str( Decom ).lower():
zhanghaoyu7474d8c62015-08-26 14:53:28 +080079 return True
80 else:
Jon Hall8638b562017-05-24 16:39:59 -070081 print "Source Compare data:" + FirstPara + "." + SecondPara + "=" + str( Socom )
82 print "Dest Compare data: " + FirstPara + "." + SecondPara + "=" + str( Decom )
zhanghaoyu7474d8c62015-08-26 14:53:28 +080083 return False
84
zhanghaoyu7474d8c62015-08-26 14:53:28 +080085
Jon Hall8638b562017-05-24 16:39:59 -070086class SubnetData( NetworkData ):
87
88 def __init__( self ):
zhanghaoyu7474d8c62015-08-26 14:53:28 +080089 self.id = ''
90 self.tenant_id = ''
91 self.network_id = ''
92 self.nexthop = '192.168.1.1'
93 self.destination = '192.168.1.1/24'
94 self.start = '192.168.2.2'
95 self.end = '192.168.2.254'
96 self.ipv6_address_mode = 'DHCPV6_STATELESS'
97 self.ipv6_ra_mode = 'DHCPV6_STATELESS'
98 self.cidr = '192.168.1.1/24'
99 self.enable_dhcp = True
100 self.dns_nameservers = 'aaa'
101 self.gateway_ip = '192.168.2.1'
102 self.ip_version = '4'
103 self.shared = False
104 self.name = 'demo-subnet'
105
Jon Hall8638b562017-05-24 16:39:59 -0700106 def DictoJson( self ):
107 if self.id == '' or self.tenant_id == '':
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800108 print 'Id and tenant id is necessary!'
109
110 Dicdata = {}
111 host_routesdata = []
Jon Hall8638b562017-05-24 16:39:59 -0700112 host_routesdata.append( { 'nexthop': self.nexthop, 'destination': self.destination } )
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800113 allocation_pools = []
Jon Hall8638b562017-05-24 16:39:59 -0700114 allocation_pools.append( { 'start': self.start, 'end': self.end } )
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800115
116 if self.id != '':
Jon Hall8638b562017-05-24 16:39:59 -0700117 Dicdata[ 'id' ] = self.id
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800118 if self.network_id != '':
Jon Hall8638b562017-05-24 16:39:59 -0700119 Dicdata[ 'network_id' ] = self.network_id
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800120 if self.name != '':
Jon Hall8638b562017-05-24 16:39:59 -0700121 Dicdata[ 'name' ] = self.name
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800122 if self.nexthop != '':
Jon Hall8638b562017-05-24 16:39:59 -0700123 Dicdata[ 'host_routes' ] = host_routesdata
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800124 if self.tenant_id != '':
Jon Hall8638b562017-05-24 16:39:59 -0700125 Dicdata[ 'tenant_id' ] = self.tenant_id
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800126 if self.start != '':
Jon Hall8638b562017-05-24 16:39:59 -0700127 Dicdata[ 'allocation_pools' ] = allocation_pools
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800128 if self.shared != '':
Jon Hall8638b562017-05-24 16:39:59 -0700129 Dicdata[ 'shared' ] = self.shared
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800130 if self.ipv6_address_mode != '':
Jon Hall8638b562017-05-24 16:39:59 -0700131 Dicdata[ 'ipv6_address_mode' ] = self.ipv6_address_mode
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800132 if self.ipv6_ra_mode != '':
Jon Hall8638b562017-05-24 16:39:59 -0700133 Dicdata[ 'ipv6_ra_mode' ] = self.ipv6_ra_mode
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800134 if self.cidr != '':
Jon Hall8638b562017-05-24 16:39:59 -0700135 Dicdata[ 'cidr' ] = self.cidr
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800136 if self.enable_dhcp != '':
Jon Hall8638b562017-05-24 16:39:59 -0700137 Dicdata[ 'enable_dhcp' ] = self.enable_dhcp
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800138 if self.dns_nameservers != '':
Jon Hall8638b562017-05-24 16:39:59 -0700139 Dicdata[ 'dns_nameservers' ] = self.dns_nameservers
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800140 if self.gateway_ip != '':
Jon Hall8638b562017-05-24 16:39:59 -0700141 Dicdata[ 'gateway_ip' ] = self.gateway_ip
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800142 if self.ip_version != '':
Jon Hall8638b562017-05-24 16:39:59 -0700143 Dicdata[ 'ip_version' ] = self.ip_version
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800144
Jon Hall8638b562017-05-24 16:39:59 -0700145 Dicdata = { 'subnet': Dicdata }
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800146
Jon Hall8638b562017-05-24 16:39:59 -0700147 return json.dumps( Dicdata, indent=4 )
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800148
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800149
Jon Hall8638b562017-05-24 16:39:59 -0700150class VirtualPortData( NetworkData ):
151
152 def __init__( self ):
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800153 self.id = ''
154 self.state = 'ACTIVE'
155 self.bindingHostId = 'fa:16:3e:76:8e:88'
Jon Hall8638b562017-05-24 16:39:59 -0700156 self.allowedAddressPairs = [ { 'mac_address': 'fa:16:3e:76:8e:88', 'ip_address': '192.168.1.1' } ]
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800157 self.deviceOwner = 'none'
158 self.fixedIp = []
Jon Hall8638b562017-05-24 16:39:59 -0700159 self.securityGroups = [ { 'securityGroup': 'asd' } ]
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800160 self.adminStateUp = True
161 self.network_id = ''
162 self.tenant_id = ''
163 self.subnet_id = ''
164 self.bindingvifDetails = 'port_filter'
165 self.bindingvnicType = 'normal'
166 self.bindingvifType = 'ovs'
167 self.macAddress = 'fa:16:3e:76:8e:88'
168 self.deviceId = 'a08aa'
169 self.name = 'u'
170
Jon Hall8638b562017-05-24 16:39:59 -0700171 def DictoJson( self ):
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800172 if self.id == '' or self.tenant_id == ' ' or \
173 self.network_id == '' or self.subnet_id == '':
174 print 'Id/tenant id/networkid/subnetId is necessary!'
175
176 Dicdata = {}
Jon Hall8638b562017-05-24 16:39:59 -0700177 fixedIp = []
178 fixedIp.append( { 'subnet_id': self.subnet_id, 'ip_address': '192.168.1.4' } )
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800179 allocation_pools = []
180
181 if self.id != '':
Jon Hall8638b562017-05-24 16:39:59 -0700182 Dicdata[ 'id' ] = self.id
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800183 if self.state != '':
Jon Hall8638b562017-05-24 16:39:59 -0700184 Dicdata[ 'status' ] = self.state
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800185 if self.bindingHostId != '':
Jon Hall8638b562017-05-24 16:39:59 -0700186 Dicdata[ 'binding:host_id' ] = self.bindingHostId
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800187 if self.allowedAddressPairs != '':
Jon Hall8638b562017-05-24 16:39:59 -0700188 Dicdata[ 'allowed_address_pairs' ] = self.allowedAddressPairs
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800189 if self.deviceOwner != '':
Jon Hall8638b562017-05-24 16:39:59 -0700190 Dicdata[ 'device_owner' ] = self.deviceOwner
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800191 if self.securityGroups != '':
Jon Hall8638b562017-05-24 16:39:59 -0700192 Dicdata[ 'security_groups' ] = self.securityGroups
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800193 if self.adminStateUp != '':
Jon Hall8638b562017-05-24 16:39:59 -0700194 Dicdata[ 'admin_state_up' ] = self.adminStateUp
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800195 if self.network_id != '':
Jon Hall8638b562017-05-24 16:39:59 -0700196 Dicdata[ 'network_id' ] = self.network_id
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800197 if self.tenant_id != '':
Jon Hall8638b562017-05-24 16:39:59 -0700198 Dicdata[ 'tenant_id' ] = self.tenant_id
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800199 if self.bindingvifDetails != '':
Jon Hall8638b562017-05-24 16:39:59 -0700200 Dicdata[ 'binding:vif_details' ] = self.bindingvifDetails
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800201 if self.bindingvnicType != '':
Jon Hall8638b562017-05-24 16:39:59 -0700202 Dicdata[ 'binding:vnic_type' ] = self.bindingvnicType
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800203 if self.bindingvifType != '':
Jon Hall8638b562017-05-24 16:39:59 -0700204 Dicdata[ 'binding:vif_type' ] = self.bindingvifType
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800205 if self.macAddress != '':
Jon Hall8638b562017-05-24 16:39:59 -0700206 Dicdata[ 'mac_address' ] = self.macAddress
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800207 if self.deviceId != '':
Jon Hall8638b562017-05-24 16:39:59 -0700208 Dicdata[ 'device_id' ] = self.deviceId
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800209 if self.name != '':
Jon Hall8638b562017-05-24 16:39:59 -0700210 Dicdata[ 'name' ] = self.name
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800211
Jon Hall8638b562017-05-24 16:39:59 -0700212 Dicdata[ 'fixed_ips' ] = fixedIp
213 Dicdata = { 'port': Dicdata }
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800214
Jon Hall8638b562017-05-24 16:39:59 -0700215 return json.dumps( Dicdata, indent=4 )