lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 1 | """ |
| 2 | This file provide the data |
| 3 | lanqinglong@huawei.com |
| 4 | """ |
| 5 | import json |
| 6 | |
| 7 | class NetworkData: |
| 8 | |
| 9 | def __init__(self): |
| 10 | self.id = '' |
| 11 | self.state = 'ACTIVE' |
| 12 | self.name = 'onosfw-1' |
| 13 | self.physicalNetwork = 'none' |
lanqinglong | d0dda2e | 2015-08-25 11:02:48 +0800 | [diff] [blame^] | 14 | self.admin_state_up = True |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 15 | self.tenant_id = '' |
lanqinglong | d0dda2e | 2015-08-25 11:02:48 +0800 | [diff] [blame^] | 16 | self.routerExternal = False |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 17 | self.type ='LOCAL' |
| 18 | self.segmentationID = '6' |
lanqinglong | d0dda2e | 2015-08-25 11:02:48 +0800 | [diff] [blame^] | 19 | self.shared = False |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 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 | |
lanqinglong | e675e92 | 2015-08-13 21:17:28 +0800 | [diff] [blame] | 70 | 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 |
lanqinglong | d0dda2e | 2015-08-25 11:02:48 +0800 | [diff] [blame^] | 75 | return False |
lanqinglong | e675e92 | 2015-08-13 21:17:28 +0800 | [diff] [blame] | 76 | |
| 77 | if str(Socom).lower()== str(Decom).lower(): |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 78 | return True |
| 79 | else: |
lanqinglong | e675e92 | 2015-08-13 21:17:28 +0800 | [diff] [blame] | 80 | print "Source Compare data:"+FirstPara+"."+SecondPara+"="+str(Socom) |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 81 | print "Dest Compare data: "+FirstPara+"."+SecondPara+"="+str(Decom) |
| 82 | return False |
| 83 | |
| 84 | class 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' |
lanqinglong | d0dda2e | 2015-08-25 11:02:48 +0800 | [diff] [blame^] | 97 | self.enable_dhcp = True |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 98 | self.dns_nameservers = 'aaa' |
| 99 | self.gateway_ip = '192.168.2.1' |
lanqinglong | d0dda2e | 2015-08-25 11:02:48 +0800 | [diff] [blame^] | 100 | self.ip_version = '4' |
| 101 | self.shared = False |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 102 | 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 | |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 147 | class VirtualPortData(NetworkData): |
| 148 | |
| 149 | def __init__(self): |
| 150 | self.id = '' |
| 151 | self.state = 'ACTIVE' |
| 152 | self.bindingHostId = 'fa:16:3e:76:8e:88' |
lanqinglong | d0dda2e | 2015-08-25 11:02:48 +0800 | [diff] [blame^] | 153 | self.allowedAddressPairs = [{'mac_address':'fa:16:3e:76:8e:88','ip_address':'192.168.1.1'}] |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 154 | self.deviceOwner = 'none' |
| 155 | self.fixedIp = [] |
| 156 | self.securityGroups = [{'securityGroup':'asd'}] |
lanqinglong | d0dda2e | 2015-08-25 11:02:48 +0800 | [diff] [blame^] | 157 | self.adminStateUp = True |
| 158 | self.network_id = '' |
| 159 | self.tenant_id = '' |
| 160 | self.subnet_id = '' |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 161 | 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): |
lanqinglong | d0dda2e | 2015-08-25 11:02:48 +0800 | [diff] [blame^] | 169 | if self.id == '' or self.tenant_id == ' ' or \ |
| 170 | self.network_id == '' or self.subnet_id == '': |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 171 | print 'Id/tenant id/networkid/subnetId is necessary!' |
| 172 | |
| 173 | Dicdata = {} |
| 174 | fixedIp =[] |
lanqinglong | d0dda2e | 2015-08-25 11:02:48 +0800 | [diff] [blame^] | 175 | fixedIp.append({'subnet_id':self.subnet_id,'ip_address':'192.168.1.4'}) |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 176 | allocation_pools = [] |
| 177 | |
| 178 | if self.id != '': |
| 179 | Dicdata['id'] = self.id |
| 180 | if self.state != '': |
lanqinglong | d0dda2e | 2015-08-25 11:02:48 +0800 | [diff] [blame^] | 181 | Dicdata['status'] = self.state |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 182 | if self.bindingHostId != '': |
lanqinglong | d0dda2e | 2015-08-25 11:02:48 +0800 | [diff] [blame^] | 183 | Dicdata['binding:host_id'] = self.bindingHostId |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 184 | if self.allowedAddressPairs != '': |
lanqinglong | d0dda2e | 2015-08-25 11:02:48 +0800 | [diff] [blame^] | 185 | Dicdata['allowed_address_pairs'] = self.allowedAddressPairs |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 186 | if self.deviceOwner != '': |
lanqinglong | d0dda2e | 2015-08-25 11:02:48 +0800 | [diff] [blame^] | 187 | Dicdata['device_owner'] = self.deviceOwner |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 188 | if self.securityGroups != '': |
lanqinglong | d0dda2e | 2015-08-25 11:02:48 +0800 | [diff] [blame^] | 189 | Dicdata['security_groups'] = self.securityGroups |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 190 | if self.adminStateUp != '': |
lanqinglong | d0dda2e | 2015-08-25 11:02:48 +0800 | [diff] [blame^] | 191 | 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 |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 196 | if self.bindingvifDetails != '': |
lanqinglong | d0dda2e | 2015-08-25 11:02:48 +0800 | [diff] [blame^] | 197 | Dicdata['binding:vif_details'] = self.bindingvifDetails |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 198 | if self.bindingvnicType != '': |
lanqinglong | d0dda2e | 2015-08-25 11:02:48 +0800 | [diff] [blame^] | 199 | Dicdata['binding:vnic_type'] = self.bindingvnicType |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 200 | if self.bindingvifType != '': |
lanqinglong | d0dda2e | 2015-08-25 11:02:48 +0800 | [diff] [blame^] | 201 | Dicdata['binding:vif_type'] = self.bindingvifType |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 202 | if self.macAddress != '': |
lanqinglong | d0dda2e | 2015-08-25 11:02:48 +0800 | [diff] [blame^] | 203 | Dicdata['mac_address'] = self.macAddress |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 204 | if self.deviceId != '': |
lanqinglong | d0dda2e | 2015-08-25 11:02:48 +0800 | [diff] [blame^] | 205 | Dicdata['device_id'] = self.deviceId |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 206 | if self.name != '': |
| 207 | Dicdata['name'] = self.name |
| 208 | |
lanqinglong | d0dda2e | 2015-08-25 11:02:48 +0800 | [diff] [blame^] | 209 | Dicdata['fixed_ips'] = fixedIp |
| 210 | Dicdata = {'port': Dicdata} |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 211 | |
lanqinglong | d0dda2e | 2015-08-25 11:02:48 +0800 | [diff] [blame^] | 212 | return json.dumps(Dicdata,indent=4) |