Sapan Bhatia | f68688d | 2013-09-03 11:45:46 -0400 | [diff] [blame] | 1 | import os |
| 2 | import base64 |
Tony Mack | a76b895 | 2013-10-05 23:36:30 -0400 | [diff] [blame] | 3 | import traceback |
| 4 | from collections import defaultdict |
Tony Mack | ae7f30c | 2013-09-25 12:46:50 -0400 | [diff] [blame] | 5 | from django.db.models import F, Q |
Sapan Bhatia | f68688d | 2013-09-03 11:45:46 -0400 | [diff] [blame] | 6 | from planetstack.config import Config |
Tony Mack | a76b895 | 2013-10-05 23:36:30 -0400 | [diff] [blame] | 7 | from util.logger import Logger, logging |
Tony Mack | 66646d5 | 2013-09-24 21:47:12 -0400 | [diff] [blame] | 8 | from observer.openstacksyncstep import OpenStackSyncStep |
Tony Mack | a76b895 | 2013-10-05 23:36:30 -0400 | [diff] [blame] | 9 | from core.models import * |
| 10 | |
Tony Mack | adb5d12 | 2014-04-21 21:46:45 -0400 | [diff] [blame] | 11 | logger = Logger(logfile='/var/log/observer.log', level=logging.INFO) |
Sapan Bhatia | f68688d | 2013-09-03 11:45:46 -0400 | [diff] [blame] | 12 | |
Tony Mack | 66646d5 | 2013-09-24 21:47:12 -0400 | [diff] [blame] | 13 | class GarbageCollector(OpenStackSyncStep): |
| 14 | requested_interval = 86400 |
| 15 | provides=[] |
Sapan Bhatia | f68688d | 2013-09-03 11:45:46 -0400 | [diff] [blame] | 16 | |
Tony Mack | b0e03bf | 2013-10-05 20:52:13 -0400 | [diff] [blame] | 17 | def call(self, **args): |
Tony Mack | 387a73f | 2013-09-18 07:59:14 -0400 | [diff] [blame] | 18 | try: |
Tony Mack | adb5d12 | 2014-04-21 21:46:45 -0400 | [diff] [blame] | 19 | self.gc_networks() |
| 20 | #self.gc_user_tenant_roles() |
Tony Mack | fccb9eb | 2014-04-14 22:16:42 -0400 | [diff] [blame] | 21 | #self.gc_tenants() |
| 22 | #self.gc_users() |
Tony Mack | b61c81c | 2014-04-21 17:08:12 -0400 | [diff] [blame] | 23 | self.gc_slivers() |
Tony Mack | fccb9eb | 2014-04-14 22:16:42 -0400 | [diff] [blame] | 24 | #self.gc_sliver_ips() |
Tony Mack | fccb9eb | 2014-04-14 22:16:42 -0400 | [diff] [blame] | 25 | pass |
Tony Mack | 387a73f | 2013-09-18 07:59:14 -0400 | [diff] [blame] | 26 | except: |
Tony Mack | adb5d12 | 2014-04-21 21:46:45 -0400 | [diff] [blame] | 27 | traceback.print_exc() |
Tony Mack | 387a73f | 2013-09-18 07:59:14 -0400 | [diff] [blame] | 28 | |
Tony Mack | adb5d12 | 2014-04-21 21:46:45 -0400 | [diff] [blame] | 29 | def gc_networks(self): |
Tony Mack | 387a73f | 2013-09-18 07:59:14 -0400 | [diff] [blame] | 30 | """ |
Tony Mack | adb5d12 | 2014-04-21 21:46:45 -0400 | [diff] [blame] | 31 | Remove all neutron networks that do not exist in the planetstack db. |
Tony Mack | 387a73f | 2013-09-18 07:59:14 -0400 | [diff] [blame] | 32 | """ |
Tony Mack | adb5d12 | 2014-04-21 21:46:45 -0400 | [diff] [blame] | 33 | # some networks cannot be deleted |
| 34 | system_networks = ['nat-net','private-admin'] |
| 35 | for network_template in NetworkTemplate.objects.all(): |
| 36 | if network_template.sharedNetworkName and \ |
| 37 | network_template.sharedNetworkName not in system_networks: |
| 38 | system_networks.append(network_template.sharedNetworkName) |
| 39 | |
| 40 | networks = Network.objects.filter(enacted__isnull=False) |
| 41 | networks_dict = {} |
| 42 | for network in networks: |
| 43 | networks_dict[network.name] = network |
| 44 | |
| 45 | # some deployments are at the same url. Keep track of the urls we've visited |
| 46 | # to make sure we aren't making redundant calls |
| 47 | completed_urls = [] |
Tony Mack | dd24095 | 2014-06-03 23:02:00 -0400 | [diff] [blame] | 48 | for deployment in Deployment.objects.all(): |
Tony Mack | adb5d12 | 2014-04-21 21:46:45 -0400 | [diff] [blame] | 49 | # skip deployments that we've already processed |
Tony Mack | dd24095 | 2014-06-03 23:02:00 -0400 | [diff] [blame] | 50 | if deployment.auth_url in completed_urls: |
Tony Mack | 387a73f | 2013-09-18 07:59:14 -0400 | [diff] [blame] | 51 | continue |
Tony Mack | adb5d12 | 2014-04-21 21:46:45 -0400 | [diff] [blame] | 52 | try: |
| 53 | driver = self.driver.admin_driver(deployment=deployment) |
| 54 | neutron_networks = driver.shell.quantum.list_networks()['networks'] |
| 55 | for neutron_network in neutron_networks: |
| 56 | # skip system networks |
| 57 | if neutron_network['name'] in system_networks: |
| 58 | continue |
| 59 | if neutron_network['name'] not in networks_dict: |
| 60 | try: |
| 61 | logger.info("GarbageCollector: deleting network %s" % neutron_network['name']) |
| 62 | for subnet_id in neutron_network['subnets']: |
| 63 | driver.delete_subnet(subnet_id) |
| 64 | driver.delete_network(neutron_network['id']) |
| 65 | except: |
| 66 | logger.log_exc("GarbageCollector: delete network %s failed" % neutron_network['name']) |
| 67 | except: |
| 68 | logger.log_exc("GarbageCollector: Error at deployment %s" % deployment) |
| 69 | |
Tony Mack | dd24095 | 2014-06-03 23:02:00 -0400 | [diff] [blame] | 70 | completed_urls.append(deployment.auth_url) |
Tony Mack | 387a73f | 2013-09-18 07:59:14 -0400 | [diff] [blame] | 71 | |
| 72 | def gc_tenants(self): |
| 73 | """ |
| 74 | Remove sites and slices that no don't exist in openstack db if they |
| 75 | have an enacted time (enacted != None). |
| 76 | """ |
Tony Mack | adb5d12 | 2014-04-21 21:46:45 -0400 | [diff] [blame] | 77 | # some tenants cannot be deleted |
| 78 | system_tenants = ['admin','service', 'invisible_to_admin'] |
Tony Mack | 387a73f | 2013-09-18 07:59:14 -0400 | [diff] [blame] | 79 | # get all sites that where enacted != null. We can assume these sites |
| 80 | # have previously been synced and need to be checed for deletion. |
| 81 | sites = Site.objects.filter(enacted__isnull=False) |
| 82 | site_dict = {} |
| 83 | for site in sites: |
| 84 | site_dict[site.login_base] = site |
| 85 | |
| 86 | # get all slices that where enacted != null. We can assume these slices |
| 87 | # have previously been synced and need to be checed for deletion. |
| 88 | slices = Slice.objects.filter(enacted__isnull=False) |
| 89 | slice_dict = {} |
| 90 | for slice in slices: |
| 91 | slice_dict[slice.name] = slice |
| 92 | |
| 93 | # delete keystone tenants that don't have a site record |
Tony Mack | adb5d12 | 2014-04-21 21:46:45 -0400 | [diff] [blame] | 94 | # some deployments are at the same url. Keep track of the urls we've visited |
| 95 | # to make sure we aren't making redundant calls |
| 96 | completed_urls = [] |
Tony Mack | dd24095 | 2014-06-03 23:02:00 -0400 | [diff] [blame] | 97 | for deployment in Deployment.objects.all(): |
Tony Mack | adb5d12 | 2014-04-21 21:46:45 -0400 | [diff] [blame] | 98 | # skip deployments that we've already processed |
Tony Mack | dd24095 | 2014-06-03 23:02:00 -0400 | [diff] [blame] | 99 | if deployment.auth_url in completed_urls: |
Tony Mack | adb5d12 | 2014-04-21 21:46:45 -0400 | [diff] [blame] | 100 | continue |
| 101 | |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 102 | driver = self.driver.admin_driver(deployment=deployment) |
| 103 | tenants = driver.shell.keystone.tenants.findall() |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 104 | for tenant in tenants: |
| 105 | if tenant.name in system_tenants: |
| 106 | continue |
| 107 | if tenant.name not in site_dict and tenant.name not in slice_dict: |
| 108 | try: |
Tony Mack | adb5d12 | 2014-04-21 21:46:45 -0400 | [diff] [blame] | 109 | logger.info("GarbageCollector: deleting tenant: %s" % (tenant)) |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 110 | driver.delete_tenant(tenant.id) |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 111 | except: |
Tony Mack | adb5d12 | 2014-04-21 21:46:45 -0400 | [diff] [blame] | 112 | logger.log_exc("GarbageCollector: delete tenant failed: %s" % tenant) |
Tony Mack | dd24095 | 2014-06-03 23:02:00 -0400 | [diff] [blame] | 113 | completed_urls.append(deployment.auth_url) |
Tony Mack | 387a73f | 2013-09-18 07:59:14 -0400 | [diff] [blame] | 114 | |
| 115 | def gc_users(self): |
| 116 | """ |
Tony Mack | f77f140 | 2014-04-02 07:06:53 -0400 | [diff] [blame] | 117 | Remove users that do not exist in openstack db if they have an |
Tony Mack | 387a73f | 2013-09-18 07:59:14 -0400 | [diff] [blame] | 118 | enacted time (enacted != None). |
| 119 | """ |
Tony Mack | adb5d12 | 2014-04-21 21:46:45 -0400 | [diff] [blame] | 120 | # some users cannot be deleted |
| 121 | system_users = ['admin', 'nova', 'quantum', 'neutron' 'glance', \ |
| 122 | 'cinder', 'swift', 'service', 'demo'] |
| 123 | |
Tony Mack | 387a73f | 2013-09-18 07:59:14 -0400 | [diff] [blame] | 124 | # get all users that where enacted != null. We can assume these users |
| 125 | # have previously been synced and need to be checed for deletion. |
| 126 | users = User.objects.filter(enacted__isnull=False) |
| 127 | user_dict = {} |
| 128 | for user in users: |
| 129 | user_dict[user.kuser_id] = user |
| 130 | |
| 131 | # delete keystone users that don't have a user record |
Tony Mack | adb5d12 | 2014-04-21 21:46:45 -0400 | [diff] [blame] | 132 | # some deployments are at the same url. Keep track of the urls we've visited |
| 133 | # to make sure we aren't making redundant calls |
| 134 | completed_urls = [] |
Tony Mack | dd24095 | 2014-06-03 23:02:00 -0400 | [diff] [blame] | 135 | for deployment in Deployment.objects.all(): |
Tony Mack | adb5d12 | 2014-04-21 21:46:45 -0400 | [diff] [blame] | 136 | # skip deployments that we've already processed |
Tony Mack | dd24095 | 2014-06-03 23:02:00 -0400 | [diff] [blame] | 137 | if deployment.auth_url in completed_urls: |
Tony Mack | adb5d12 | 2014-04-21 21:46:45 -0400 | [diff] [blame] | 138 | continue |
| 139 | |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 140 | driver = self.driver.admin_driver(deployment=deployment) |
| 141 | users = driver.shell.keystone.users.findall() |
| 142 | for user in users: |
| 143 | if user.name in system_users: |
| 144 | continue |
| 145 | if user.id not in user_dict: |
| 146 | try: |
Tony Mack | adb5d12 | 2014-04-21 21:46:45 -0400 | [diff] [blame] | 147 | logger.info("GarbageCollector: deleting user: %s" % user) |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 148 | self.driver.delete_user(user.id) |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 149 | except: |
Tony Mack | adb5d12 | 2014-04-21 21:46:45 -0400 | [diff] [blame] | 150 | logger.log_exc("GarbageCollector: delete user failed: %s" % user) |
Tony Mack | dd24095 | 2014-06-03 23:02:00 -0400 | [diff] [blame] | 151 | completed_urls.append(deployment.auth_url) |
Tony Mack | 387a73f | 2013-09-18 07:59:14 -0400 | [diff] [blame] | 152 | |
| 153 | def gc_user_tenant_roles(self): |
| 154 | """ |
| 155 | Remove roles that don't exist in openstack db if they have |
| 156 | an enacted time (enacted != None). |
| 157 | """ |
| 158 | # get all site privileges and slice memberships that have been enacted |
| 159 | user_tenant_roles = defaultdict(list) |
| 160 | for site_priv in SitePrivilege.objects.filter(enacted__isnull=False): |
| 161 | user_tenant_roles[(site_priv.user.kuser_id, site_priv.site.tenant_id)].append(site_priv.role.role) |
Tony Mack | a76b895 | 2013-10-05 23:36:30 -0400 | [diff] [blame] | 162 | for slice_memb in SlicePrivilege.objects.filter(enacted__isnull=False): |
Tony Mack | 387a73f | 2013-09-18 07:59:14 -0400 | [diff] [blame] | 163 | user_tenant_roles[(slice_memb.user.kuser_id, slice_memb.slice.tenant_id)].append(slice_memb.role.role) |
Tony Mack | adb5d12 | 2014-04-21 21:46:45 -0400 | [diff] [blame] | 164 | |
| 165 | # some deployments are at the same url. Keep track of the urls we've visited |
| 166 | # to make sure we aren't making redundant calls |
| 167 | completed_urls = [] |
Tony Mack | 387a73f | 2013-09-18 07:59:14 -0400 | [diff] [blame] | 168 | # Some user tenant role aren't stored in planetstack but they must be preserved. |
| 169 | # Role that fall in this category are |
| 170 | # 1. Never remove a user's role that their home site |
| 171 | # 2. Never remove a user's role at a slice they've created. |
| 172 | # Keep track of all roles that must be preserved. |
| 173 | users = User.objects.all() |
Tony Mack | dd24095 | 2014-06-03 23:02:00 -0400 | [diff] [blame] | 174 | for deployment in Deployment.objects.all(): |
Tony Mack | adb5d12 | 2014-04-21 21:46:45 -0400 | [diff] [blame] | 175 | # skip deployments that we've already processed |
Tony Mack | dd24095 | 2014-06-03 23:02:00 -0400 | [diff] [blame] | 176 | if deployment.auth_url in completed_urls: |
Tony Mack | adb5d12 | 2014-04-21 21:46:45 -0400 | [diff] [blame] | 177 | continue |
| 178 | |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 179 | driver = self.driver.admin_driver(deployment=deployment) |
| 180 | tenants = driver.shell.keystone.tenants.list() |
| 181 | for user in users: |
| 182 | # skip admin roles |
| 183 | if user.kuser_id == self.driver.admin_user.id: |
| 184 | continue |
| 185 | |
| 186 | ignore_tenant_ids = [] |
| 187 | k_user = driver.shell.keystone.users.find(id=user.kuser_id) |
| 188 | ignore_tenant_ids = [s['tenant_id'] for s in user.slices.values()] |
| 189 | if user.site: |
| 190 | ignore_tenant_ids.append(user.site.tenant_id) |
Tony Mack | 387a73f | 2013-09-18 07:59:14 -0400 | [diff] [blame] | 191 | |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 192 | # get user roles in keystone |
| 193 | for tenant in tenants: |
| 194 | # skip preserved tenant ids |
| 195 | if tenant.tenant_id in ignore_tenant_ids: |
| 196 | continue |
| 197 | # compare user tenant roles |
| 198 | user_tenant_role_ids = user_tenant_roles.get((user.kuser_id, tenant.id), []) |
Tony Mack | 387a73f | 2013-09-18 07:59:14 -0400 | [diff] [blame] | 199 | |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 200 | if user_tenant_role_ids: |
| 201 | # The user has roles at the tenant. Check if roles need to |
| 202 | # be updated. |
| 203 | k_user_roles = driver.shell.keystone.roles.roles_for_user(k_user, tenant) |
| 204 | for k_user_role in k_user_roles: |
| 205 | if k_user_role.role_id not in user_tenant_role_ids: |
Tony Mack | adb5d12 | 2014-04-21 21:46:45 -0400 | [diff] [blame] | 206 | logger.info("GarbageCollector: removing user role %s for %s at %s" % \ |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 207 | (k_user_role, k_user.username, tenant.name)) |
Tony Mack | adb5d12 | 2014-04-21 21:46:45 -0400 | [diff] [blame] | 208 | driver.shell.keyston.remove_user_role(k_user, k_user_role, tenant) |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 209 | else: |
| 210 | # remove all roles the user has at the tenant. |
| 211 | for k_user_role in k_user_roles: |
Tony Mack | adb5d12 | 2014-04-21 21:46:45 -0400 | [diff] [blame] | 212 | logger.info("GarbageCollector: removing user role %s for %s at %s" % \ |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 213 | (k_user_role, k_user.username, tenant.name)) |
Tony Mack | adb5d12 | 2014-04-21 21:46:45 -0400 | [diff] [blame] | 214 | driver.shell.keyston.remove_user_role(k_user, k_user_role, tenant) |
Tony Mack | dd24095 | 2014-06-03 23:02:00 -0400 | [diff] [blame] | 215 | completed_urls.append(deployment.auth_url) |
Tony Mack | 387a73f | 2013-09-18 07:59:14 -0400 | [diff] [blame] | 216 | |
| 217 | def gc_slivers(self): |
| 218 | """ |
| 219 | Remove slivers that no don't exist in openstack db if they have |
| 220 | an enacted time (enacted != None). |
| 221 | """ |
| 222 | # get all slivers where enacted != null. We can assume these users |
| 223 | # have previously been synced and need to be checed for deletion. |
| 224 | slivers = Sliver.objects.filter(enacted__isnull=False) |
| 225 | sliver_dict = {} |
| 226 | for sliver in slivers: |
| 227 | sliver_dict[sliver.instance_id] = sliver |
| 228 | |
Tony Mack | adb5d12 | 2014-04-21 21:46:45 -0400 | [diff] [blame] | 229 | |
| 230 | # some deployments are at the same url. Keep track of the urls we've visited |
| 231 | # to make sure we aren't making redundant calls |
| 232 | completed_urls = [] |
Tony Mack | dd24095 | 2014-06-03 23:02:00 -0400 | [diff] [blame] | 233 | for deployment in Deployment.objects.all(): |
Tony Mack | adb5d12 | 2014-04-21 21:46:45 -0400 | [diff] [blame] | 234 | # skip deployments that we've already processed |
Tony Mack | dd24095 | 2014-06-03 23:02:00 -0400 | [diff] [blame] | 235 | if deployment.auth_url in completed_urls: |
Tony Mack | b61c81c | 2014-04-21 17:08:12 -0400 | [diff] [blame] | 236 | continue |
Tony Mack | adb5d12 | 2014-04-21 21:46:45 -0400 | [diff] [blame] | 237 | |
| 238 | try: |
| 239 | driver = self.driver.admin_driver(deployment=deployment) |
| 240 | for tenant in driver.shell.keystone.tenants.list(): |
| 241 | if tenant.name in ['admin', 'services']: |
| 242 | continue |
| 243 | # delete sliver that don't have a sliver record |
| 244 | tenant_driver = self.driver.client_driver(tenant=tenant.name, deployment=deployment) |
| 245 | for instance in tenant_driver.shell.nova.servers.list(): |
| 246 | if instance.id not in sliver_dict: |
| 247 | try: |
| 248 | logger.info("GarbageCollector: destroying sliver: %s %s" % (instance, instance.id)) |
| 249 | tenant_driver.destroy_instance(instance.id) |
| 250 | except: |
| 251 | logger.log_exc("GarbageCollector: destroy sliver failed: %s" % instance) |
| 252 | except: |
| 253 | logger.log_exc("GarbageCollector: Error at deployment %s" % deployment) |
Tony Mack | dd24095 | 2014-06-03 23:02:00 -0400 | [diff] [blame] | 254 | completed_urls.append(deployment.auth_url) |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 255 | |
Tony Mack | 387a73f | 2013-09-18 07:59:14 -0400 | [diff] [blame] | 256 | |
| 257 | def gc_sliver_ips(self): |
| 258 | """ |
| 259 | Update ips that have changed. |
| 260 | """ |
| 261 | # fill in null ip addresses |
| 262 | slivers = Sliver.objects.filter(ip=None) |
| 263 | for sliver in slivers: |
| 264 | # update connection |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 265 | |
| 266 | driver = self.driver.client_driver(tenant=sliver.slice.name, deployment=sliver.node.deployment) |
Tony Mack | a76b895 | 2013-10-05 23:36:30 -0400 | [diff] [blame] | 267 | servers = driver.shell.nova.servers.findall(id=sliver.instance_id) |
Tony Mack | 387a73f | 2013-09-18 07:59:14 -0400 | [diff] [blame] | 268 | if not servers: |
| 269 | continue |
| 270 | server = servers[0] |
| 271 | ips = server.addresses.get(sliver.slice.name, []) |
| 272 | if ips and sliver.ip != ips[0]['addr']: |
| 273 | sliver.ip = ips[0]['addr'] |
| 274 | sliver.save() |
| 275 | logger.info("updated sliver ip: %s %s" % (sliver, ips[0])) |
| 276 | |
Tony Mack | e1509e8 | 2013-10-09 12:38:04 -0400 | [diff] [blame] | 277 | def gc_nodes(self): |
| 278 | # collect local nodes |
| 279 | nodes = Node.objects.all() |
| 280 | nodes_dict = {} |
| 281 | for node in nodes: |
| 282 | nodes_dict[node.name] = node |
| 283 | |
| 284 | # collect nova nodes: |
Tony Mack | e1509e8 | 2013-10-09 12:38:04 -0400 | [diff] [blame] | 285 | compute_nodes_dict = {} |
Tony Mack | dd24095 | 2014-06-03 23:02:00 -0400 | [diff] [blame] | 286 | for deployment in Deployment.objets.all(): |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 287 | driver = self.driver.admin_driver(deployment=deployment) |
| 288 | compute_nodes = driver.nova.hypervisors.list() |
| 289 | for compute_node in compute_nodes: |
| 290 | compute_nodes_dict[compute_node.hypervisor_hostname] = compute_node |
Tony Mack | e1509e8 | 2013-10-09 12:38:04 -0400 | [diff] [blame] | 291 | |
| 292 | # remove old nodes |
| 293 | old_node_names = set(nodes_dict.keys()).difference(compute_nodes_dict.keys()) |
| 294 | Node.objects.filter(name__in=old_node_names).delete() |
| 295 | |
| 296 | def gc_images(self): |
Tony Mack | 46c2d50 | 2013-10-09 13:04:28 -0400 | [diff] [blame] | 297 | # collect local images |
| 298 | images = Image.objects.all() |
| 299 | images_dict = {} |
| 300 | for image in images: |
| 301 | images_dict[image.name] = image |
| 302 | |
| 303 | # collect glance images |
Tony Mack | 46c2d50 | 2013-10-09 13:04:28 -0400 | [diff] [blame] | 304 | glance_images_dict = {} |
Tony Mack | dd24095 | 2014-06-03 23:02:00 -0400 | [diff] [blame] | 305 | for deployment in Deployment.objects.all(): |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 306 | driver = self.driver.admin_driver(deployment=deployment) |
| 307 | glance_images = driver.shell.glance.get_images() |
| 308 | for glance_image in glance_images: |
| 309 | glance_images_dict[glance_image['name']] = glance_image |
Tony Mack | 46c2d50 | 2013-10-09 13:04:28 -0400 | [diff] [blame] | 310 | |
| 311 | # remove old images |
| 312 | old_image_names = set(images_dict.keys()).difference(glance_images_dict.keys()) |
| 313 | Image.objects.filter(name__in=old_image_names).delete() |