zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 1 | """ |
| 2 | This file provide the data |
| 3 | lanqinglong@huawei.com |
| 4 | """ |
| 5 | import json |
| 6 | |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 7 | |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 8 | class NetworkData: |
| 9 | |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 10 | def __init__( self ): |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 11 | 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 Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 18 | self.type = 'LOCAL' |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 19 | self.segmentationID = '6' |
| 20 | self.shared = False |
| 21 | |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 22 | def DictoJson( self ): |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 23 | |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 24 | if self.id == '' or self.tenant_id == '': |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 25 | print 'Id and tenant id is necessary!' |
| 26 | |
| 27 | Dicdata = {} |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 28 | if self.id != '': |
| 29 | Dicdata[ 'id' ] = self.id |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 30 | if self.state != '': |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 31 | 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 |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 48 | |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 49 | Dicdata = { 'network': Dicdata } |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 50 | |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 51 | return json.dumps( Dicdata, indent=4 ) |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 52 | |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 53 | def Ordered( self, obj ): |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 54 | |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 55 | 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 ) |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 59 | else: |
| 60 | return obj |
| 61 | |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 62 | def JsonCompare( self, SourceData, DestiData, FirstPara, SecondPara ): |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 63 | |
| 64 | try: |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 65 | SourceCompareDataDic = json.loads( SourceData ) |
| 66 | DestiCompareDataDic = json.loads( DestiData ) |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 67 | except ValueError: |
| 68 | print "SourceData or DestData is not JSON Type!" |
| 69 | return False |
| 70 | |
| 71 | try: |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 72 | 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 |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 76 | return False |
| 77 | |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 78 | if str( Socom ).lower() == str( Decom ).lower(): |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 79 | return True |
| 80 | else: |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 81 | print "Source Compare data:" + FirstPara + "." + SecondPara + "=" + str( Socom ) |
| 82 | print "Dest Compare data: " + FirstPara + "." + SecondPara + "=" + str( Decom ) |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 83 | return False |
| 84 | |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 85 | |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 86 | class SubnetData( NetworkData ): |
| 87 | |
| 88 | def __init__( self ): |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 89 | 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 Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 106 | def DictoJson( self ): |
| 107 | if self.id == '' or self.tenant_id == '': |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 108 | print 'Id and tenant id is necessary!' |
| 109 | |
| 110 | Dicdata = {} |
| 111 | host_routesdata = [] |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 112 | host_routesdata.append( { 'nexthop': self.nexthop, 'destination': self.destination } ) |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 113 | allocation_pools = [] |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 114 | allocation_pools.append( { 'start': self.start, 'end': self.end } ) |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 115 | |
| 116 | if self.id != '': |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 117 | Dicdata[ 'id' ] = self.id |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 118 | if self.network_id != '': |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 119 | Dicdata[ 'network_id' ] = self.network_id |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 120 | if self.name != '': |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 121 | Dicdata[ 'name' ] = self.name |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 122 | if self.nexthop != '': |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 123 | Dicdata[ 'host_routes' ] = host_routesdata |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 124 | if self.tenant_id != '': |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 125 | Dicdata[ 'tenant_id' ] = self.tenant_id |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 126 | if self.start != '': |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 127 | Dicdata[ 'allocation_pools' ] = allocation_pools |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 128 | if self.shared != '': |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 129 | Dicdata[ 'shared' ] = self.shared |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 130 | if self.ipv6_address_mode != '': |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 131 | Dicdata[ 'ipv6_address_mode' ] = self.ipv6_address_mode |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 132 | if self.ipv6_ra_mode != '': |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 133 | Dicdata[ 'ipv6_ra_mode' ] = self.ipv6_ra_mode |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 134 | if self.cidr != '': |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 135 | Dicdata[ 'cidr' ] = self.cidr |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 136 | if self.enable_dhcp != '': |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 137 | Dicdata[ 'enable_dhcp' ] = self.enable_dhcp |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 138 | if self.dns_nameservers != '': |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 139 | Dicdata[ 'dns_nameservers' ] = self.dns_nameservers |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 140 | if self.gateway_ip != '': |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 141 | Dicdata[ 'gateway_ip' ] = self.gateway_ip |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 142 | if self.ip_version != '': |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 143 | Dicdata[ 'ip_version' ] = self.ip_version |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 144 | |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 145 | Dicdata = { 'subnet': Dicdata } |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 146 | |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 147 | return json.dumps( Dicdata, indent=4 ) |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 148 | |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 149 | |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 150 | class VirtualPortData( NetworkData ): |
| 151 | |
| 152 | def __init__( self ): |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 153 | self.id = '' |
| 154 | self.state = 'ACTIVE' |
| 155 | self.bindingHostId = 'fa:16:3e:76:8e:88' |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 156 | self.allowedAddressPairs = [ { 'mac_address': 'fa:16:3e:76:8e:88', 'ip_address': '192.168.1.1' } ] |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 157 | self.deviceOwner = 'none' |
| 158 | self.fixedIp = [] |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 159 | self.securityGroups = [ { 'securityGroup': 'asd' } ] |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 160 | 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 Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 171 | def DictoJson( self ): |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 172 | 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 Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 177 | fixedIp = [] |
| 178 | fixedIp.append( { 'subnet_id': self.subnet_id, 'ip_address': '192.168.1.4' } ) |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 179 | allocation_pools = [] |
| 180 | |
| 181 | if self.id != '': |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 182 | Dicdata[ 'id' ] = self.id |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 183 | if self.state != '': |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 184 | Dicdata[ 'status' ] = self.state |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 185 | if self.bindingHostId != '': |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 186 | Dicdata[ 'binding:host_id' ] = self.bindingHostId |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 187 | if self.allowedAddressPairs != '': |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 188 | Dicdata[ 'allowed_address_pairs' ] = self.allowedAddressPairs |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 189 | if self.deviceOwner != '': |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 190 | Dicdata[ 'device_owner' ] = self.deviceOwner |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 191 | if self.securityGroups != '': |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 192 | Dicdata[ 'security_groups' ] = self.securityGroups |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 193 | if self.adminStateUp != '': |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 194 | Dicdata[ 'admin_state_up' ] = self.adminStateUp |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 195 | if self.network_id != '': |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 196 | Dicdata[ 'network_id' ] = self.network_id |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 197 | if self.tenant_id != '': |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 198 | Dicdata[ 'tenant_id' ] = self.tenant_id |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 199 | if self.bindingvifDetails != '': |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 200 | Dicdata[ 'binding:vif_details' ] = self.bindingvifDetails |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 201 | if self.bindingvnicType != '': |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 202 | Dicdata[ 'binding:vnic_type' ] = self.bindingvnicType |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 203 | if self.bindingvifType != '': |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 204 | Dicdata[ 'binding:vif_type' ] = self.bindingvifType |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 205 | if self.macAddress != '': |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 206 | Dicdata[ 'mac_address' ] = self.macAddress |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 207 | if self.deviceId != '': |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 208 | Dicdata[ 'device_id' ] = self.deviceId |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 209 | if self.name != '': |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 210 | Dicdata[ 'name' ] = self.name |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 211 | |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 212 | Dicdata[ 'fixed_ips' ] = fixedIp |
| 213 | Dicdata = { 'port': Dicdata } |
zhanghaoyu7 | 474d8c6 | 2015-08-26 14:53:28 +0800 | [diff] [blame] | 214 | |
Jon Hall | 8638b56 | 2017-05-24 16:39:59 -0700 | [diff] [blame] | 215 | return json.dumps( Dicdata, indent=4 ) |