blob: 3f6d167ec5865fd91c1dacabf78671d058e94a9e [file] [log] [blame]
Matteo Scandolod2044a42017-08-07 16:08:28 -07001
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 Baker64c162f2015-05-11 16:56:01 -070017import os
18import sys
19sys.path.append("/opt/xos")
20os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xos.settings")
21import django
22from core.models import *
Scott Baker64c162f2015-05-11 16:56:01 -070023django.setup()
24
Scott Baker7b0eee42015-05-11 17:26:00 -070025for obj in ControllerNetwork.deleted_objects.all():
26 print "Purging deleted object", obj
27 obj.delete(purge=True)
Scott Baker64c162f2015-05-11 16:56:01 -070028
Scott Baker7b0eee42015-05-11 17:26:00 -070029for obj in ControllerSite.deleted_objects.all():
30 print "Purging deleted object", obj
31 obj.delete(purge=True)
32
Scott Baker8f922172015-05-11 17:49:28 -070033for obj in ControllerSlice.deleted_objects.all():
34 print "Purging deleted object", obj
35 obj.delete(purge=True)
36
Scott Baker7b0eee42015-05-11 17:26:00 -070037for obj in NetworkSlice.deleted_objects.all():
38 print "Purging deleted object", obj
39 obj.delete(purge=True)
40
Scott Baker8094b6a2015-08-28 11:55:19 -070041for obj in Port.deleted_objects.all():
Scott Baker7b0eee42015-05-11 17:26:00 -070042 print "Purging deleted object", obj
43 obj.delete(purge=True)
44
45for obj in DeploymentPrivilege.deleted_objects.all():
46 print "Purging deleted object", obj
47 obj.delete(purge=True)
48
49for obj in SiteDeployment.deleted_objects.all():
50 print "Purging deleted object", obj
51 obj.delete(purge=True)
52
53seen=[]
Scott Baker64c162f2015-05-11 16:56:01 -070054for obj in ControllerNetwork.objects.all():
Scott Baker7b0eee42015-05-11 17:26:00 -070055 seen.append(obj.id)
Scott Baker64c162f2015-05-11 16:56:01 -070056 conflicts = ControllerNetwork.objects.filter(network=obj.network, controller=obj.controller)
57 for conflict in conflicts:
Scott Baker7b0eee42015-05-11 17:26:00 -070058 if conflict.id not in seen:
59 print "Purging", conflict, conflict.id, "due to duplicate of", obj.id
Scott Baker64c162f2015-05-11 16:56:01 -070060 conflict.delete(purge=True)
61
Scott Baker7b0eee42015-05-11 17:26:00 -070062seen=[]
Scott Baker64c162f2015-05-11 16:56:01 -070063for obj in NetworkSlice.objects.all():
Scott Baker7b0eee42015-05-11 17:26:00 -070064 seen.append(obj.id)
Scott Baker64c162f2015-05-11 16:56:01 -070065 conflicts = NetworkSlice.objects.filter(network=obj.network, slice=obj.slice)
66 for conflict in conflicts:
Scott Baker7b0eee42015-05-11 17:26:00 -070067 if conflict.id not in seen:
68 print "Purging", conflict, conflict.id, "due to duplicate of", obj.id
Scott Baker64c162f2015-05-11 16:56:01 -070069 conflict.delete(purge=True)
70
Scott Baker7b0eee42015-05-11 17:26:00 -070071seen=[]
Scott Baker8094b6a2015-08-28 11:55:19 -070072for obj in Port.objects.all():
Scott Baker7b0eee42015-05-11 17:26:00 -070073 seen.append(obj.id)
Tony Mack8bc36b92015-09-01 16:06:52 +000074 conflicts = Port.objects.filter(network=obj.network, instance=obj.instanc)
Scott Baker64c162f2015-05-11 16:56:01 -070075 for conflict in conflicts:
Scott Baker7b0eee42015-05-11 17:26:00 -070076 if conflict.id not in seen:
77 print "Purging", conflict, conflict.id, "due to duplicate of", obj.id
Scott Baker64c162f2015-05-11 16:56:01 -070078 conflict.delete(purge=True)
79
Scott Baker7b0eee42015-05-11 17:26:00 -070080seen=[]
Scott Baker64c162f2015-05-11 16:56:01 -070081for obj in DeploymentPrivilege.objects.all():
Scott Baker7b0eee42015-05-11 17:26:00 -070082 seen.append(obj.id)
Scott Baker64c162f2015-05-11 16:56:01 -070083 conflicts = DeploymentPrivilege.objects.filter(user=obj.user, deployment=obj.deployment, role=obj.role)
84 for conflict in conflicts:
Scott Baker7b0eee42015-05-11 17:26:00 -070085 if conflict.id not in seen:
86 print "Purging", conflict, conflict.id, "due to duplicate of", obj.id
Scott Baker64c162f2015-05-11 16:56:01 -070087 conflict.delete(purge=True)
88
Scott Baker7b0eee42015-05-11 17:26:00 -070089seen=[]
Sapan Bhatia8918ac32017-07-09 00:43:27 -040090for 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
98seen=[]
Scott Baker64c162f2015-05-11 16:56:01 -070099for obj in SiteDeployment.objects.all():
Scott Baker7b0eee42015-05-11 17:26:00 -0700100 seen.append(obj.id)
Scott Baker64c162f2015-05-11 16:56:01 -0700101 conflicts = SiteDeployment.objects.filter(site=obj.site, deployment=obj.deployment, controller=obj.controller)
102 for conflict in conflicts:
Scott Baker7b0eee42015-05-11 17:26:00 -0700103 if conflict.id not in seen:
104 print "Purging", conflict, conflict.id, "due to duplicate of", obj.id
105 conflict.delete(purge=True)
106
107seen=[]
108for 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 Baker64c162f2015-05-11 16:56:01 -0700114 conflict.delete(purge=True)
Scott Baker8f922172015-05-11 17:49:28 -0700115
116seen=[]
117for 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