Matteo Scandolo | d2044a4 | 2017-08-07 16:08:28 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
Scott Baker | 64c162f | 2015-05-11 16:56:01 -0700 | [diff] [blame] | 17 | import os |
| 18 | import sys |
| 19 | sys.path.append("/opt/xos") |
| 20 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xos.settings") |
| 21 | import django |
| 22 | from core.models import * |
Scott Baker | 64c162f | 2015-05-11 16:56:01 -0700 | [diff] [blame] | 23 | django.setup() |
| 24 | |
Scott Baker | 7b0eee4 | 2015-05-11 17:26:00 -0700 | [diff] [blame] | 25 | for obj in ControllerNetwork.deleted_objects.all(): |
| 26 | print "Purging deleted object", obj |
| 27 | obj.delete(purge=True) |
Scott Baker | 64c162f | 2015-05-11 16:56:01 -0700 | [diff] [blame] | 28 | |
Scott Baker | 7b0eee4 | 2015-05-11 17:26:00 -0700 | [diff] [blame] | 29 | for obj in ControllerSite.deleted_objects.all(): |
| 30 | print "Purging deleted object", obj |
| 31 | obj.delete(purge=True) |
| 32 | |
Scott Baker | 8f92217 | 2015-05-11 17:49:28 -0700 | [diff] [blame] | 33 | for obj in ControllerSlice.deleted_objects.all(): |
| 34 | print "Purging deleted object", obj |
| 35 | obj.delete(purge=True) |
| 36 | |
Scott Baker | 7b0eee4 | 2015-05-11 17:26:00 -0700 | [diff] [blame] | 37 | for obj in NetworkSlice.deleted_objects.all(): |
| 38 | print "Purging deleted object", obj |
| 39 | obj.delete(purge=True) |
| 40 | |
Scott Baker | 8094b6a | 2015-08-28 11:55:19 -0700 | [diff] [blame] | 41 | for obj in Port.deleted_objects.all(): |
Scott Baker | 7b0eee4 | 2015-05-11 17:26:00 -0700 | [diff] [blame] | 42 | print "Purging deleted object", obj |
| 43 | obj.delete(purge=True) |
| 44 | |
| 45 | for obj in DeploymentPrivilege.deleted_objects.all(): |
| 46 | print "Purging deleted object", obj |
| 47 | obj.delete(purge=True) |
| 48 | |
| 49 | for obj in SiteDeployment.deleted_objects.all(): |
| 50 | print "Purging deleted object", obj |
| 51 | obj.delete(purge=True) |
| 52 | |
| 53 | seen=[] |
Scott Baker | 64c162f | 2015-05-11 16:56:01 -0700 | [diff] [blame] | 54 | for obj in ControllerNetwork.objects.all(): |
Scott Baker | 7b0eee4 | 2015-05-11 17:26:00 -0700 | [diff] [blame] | 55 | seen.append(obj.id) |
Scott Baker | 64c162f | 2015-05-11 16:56:01 -0700 | [diff] [blame] | 56 | conflicts = ControllerNetwork.objects.filter(network=obj.network, controller=obj.controller) |
| 57 | for conflict in conflicts: |
Scott Baker | 7b0eee4 | 2015-05-11 17:26:00 -0700 | [diff] [blame] | 58 | if conflict.id not in seen: |
| 59 | print "Purging", conflict, conflict.id, "due to duplicate of", obj.id |
Scott Baker | 64c162f | 2015-05-11 16:56:01 -0700 | [diff] [blame] | 60 | conflict.delete(purge=True) |
| 61 | |
Scott Baker | 7b0eee4 | 2015-05-11 17:26:00 -0700 | [diff] [blame] | 62 | seen=[] |
Scott Baker | 64c162f | 2015-05-11 16:56:01 -0700 | [diff] [blame] | 63 | for obj in NetworkSlice.objects.all(): |
Scott Baker | 7b0eee4 | 2015-05-11 17:26:00 -0700 | [diff] [blame] | 64 | seen.append(obj.id) |
Scott Baker | 64c162f | 2015-05-11 16:56:01 -0700 | [diff] [blame] | 65 | conflicts = NetworkSlice.objects.filter(network=obj.network, slice=obj.slice) |
| 66 | for conflict in conflicts: |
Scott Baker | 7b0eee4 | 2015-05-11 17:26:00 -0700 | [diff] [blame] | 67 | if conflict.id not in seen: |
| 68 | print "Purging", conflict, conflict.id, "due to duplicate of", obj.id |
Scott Baker | 64c162f | 2015-05-11 16:56:01 -0700 | [diff] [blame] | 69 | conflict.delete(purge=True) |
| 70 | |
Scott Baker | 7b0eee4 | 2015-05-11 17:26:00 -0700 | [diff] [blame] | 71 | seen=[] |
Scott Baker | 8094b6a | 2015-08-28 11:55:19 -0700 | [diff] [blame] | 72 | for obj in Port.objects.all(): |
Scott Baker | 7b0eee4 | 2015-05-11 17:26:00 -0700 | [diff] [blame] | 73 | seen.append(obj.id) |
Tony Mack | 8bc36b9 | 2015-09-01 16:06:52 +0000 | [diff] [blame] | 74 | conflicts = Port.objects.filter(network=obj.network, instance=obj.instanc) |
Scott Baker | 64c162f | 2015-05-11 16:56:01 -0700 | [diff] [blame] | 75 | for conflict in conflicts: |
Scott Baker | 7b0eee4 | 2015-05-11 17:26:00 -0700 | [diff] [blame] | 76 | if conflict.id not in seen: |
| 77 | print "Purging", conflict, conflict.id, "due to duplicate of", obj.id |
Scott Baker | 64c162f | 2015-05-11 16:56:01 -0700 | [diff] [blame] | 78 | conflict.delete(purge=True) |
| 79 | |
Scott Baker | 7b0eee4 | 2015-05-11 17:26:00 -0700 | [diff] [blame] | 80 | seen=[] |
Scott Baker | 64c162f | 2015-05-11 16:56:01 -0700 | [diff] [blame] | 81 | for obj in DeploymentPrivilege.objects.all(): |
Scott Baker | 7b0eee4 | 2015-05-11 17:26:00 -0700 | [diff] [blame] | 82 | seen.append(obj.id) |
Scott Baker | 64c162f | 2015-05-11 16:56:01 -0700 | [diff] [blame] | 83 | conflicts = DeploymentPrivilege.objects.filter(user=obj.user, deployment=obj.deployment, role=obj.role) |
| 84 | for conflict in conflicts: |
Scott Baker | 7b0eee4 | 2015-05-11 17:26:00 -0700 | [diff] [blame] | 85 | if conflict.id not in seen: |
| 86 | print "Purging", conflict, conflict.id, "due to duplicate of", obj.id |
Scott Baker | 64c162f | 2015-05-11 16:56:01 -0700 | [diff] [blame] | 87 | conflict.delete(purge=True) |
| 88 | |
Scott Baker | 7b0eee4 | 2015-05-11 17:26:00 -0700 | [diff] [blame] | 89 | seen=[] |
Sapan Bhatia | 8918ac3 | 2017-07-09 00:43:27 -0400 | [diff] [blame] | 90 | for obj in Privilege.objects.all(): |
| 91 | seen.append(obj.id) |
| 92 | conflicts = Privilege.objects.filter(accessor_id=obj.accessor_id, object_id=obj.object_id, permission=obj.permission, accessor_type=obj.accessor_type, object_type=obj.object_type) |
| 93 | for conflict in conflicts: |
| 94 | if conflict.id not in seen: |
| 95 | print "Purging", conflict, conflict.id, "due to duplicate of", obj.id |
| 96 | conflict.delete(purge=True) |
| 97 | |
| 98 | seen=[] |
Scott Baker | 64c162f | 2015-05-11 16:56:01 -0700 | [diff] [blame] | 99 | for obj in SiteDeployment.objects.all(): |
Scott Baker | 7b0eee4 | 2015-05-11 17:26:00 -0700 | [diff] [blame] | 100 | seen.append(obj.id) |
Scott Baker | 64c162f | 2015-05-11 16:56:01 -0700 | [diff] [blame] | 101 | conflicts = SiteDeployment.objects.filter(site=obj.site, deployment=obj.deployment, controller=obj.controller) |
| 102 | for conflict in conflicts: |
Scott Baker | 7b0eee4 | 2015-05-11 17:26:00 -0700 | [diff] [blame] | 103 | if conflict.id not in seen: |
| 104 | print "Purging", conflict, conflict.id, "due to duplicate of", obj.id |
| 105 | conflict.delete(purge=True) |
| 106 | |
| 107 | seen=[] |
| 108 | for obj in ControllerSite.objects.all(): |
| 109 | seen.append(obj.id) |
| 110 | conflicts = ControllerSite.objects.filter(site=obj.site, controller=obj.controller) |
| 111 | for conflict in conflicts: |
| 112 | if conflict.id not in seen: |
| 113 | print "Purging", conflict, conflict.id, "due to duplicate of", obj.id |
Scott Baker | 64c162f | 2015-05-11 16:56:01 -0700 | [diff] [blame] | 114 | conflict.delete(purge=True) |
Scott Baker | 8f92217 | 2015-05-11 17:49:28 -0700 | [diff] [blame] | 115 | |
| 116 | seen=[] |
| 117 | for obj in ControllerSlice.objects.all(): |
| 118 | seen.append(obj.id) |
| 119 | conflicts = ControllerSlice.objects.filter(slice=obj.slice, controller=obj.controller) |
| 120 | for conflict in conflicts: |
| 121 | if conflict.id not in seen: |
| 122 | print "Purging", conflict, conflict.id, "due to duplicate of", obj.id |
| 123 | conflict.delete(purge=True) |
| 124 | |