def run(self): LOG.info('Starting') # Delay first compaction until system startup load has reduced last_compaction = time.time() - random.randint(1, 20*60) while True: # Update power state of all instances on this hypervisor LOG.info('Updating power states') self._update_power_states() # Cleanup soft deleted instances and networks delay = config.get('CLEANER_DELAY') for i in db.get_stale_instances(delay): LOG.withInstance(i['uuid']).info('Hard deleting instance') db.hard_delete_instance(i['uuid']) for n in db.get_stale_networks(delay): LOG.withNetwork(n['uuid']).info('Hard deleting network') db.hard_delete_network(n['uuid']) for ni in db.get_stale_network_interfaces(delay): LOG.withNetworkInterface( ni['uuid']).info('Hard deleting network interface') db.hard_delete_network_interface(ni['uuid']) # Perform etcd maintenance if time.time() - last_compaction > 1800: LOG.info('Compacting etcd') self._compact_etcd() last_compaction = time.time() time.sleep(60)
def run(self): last_compaction = 0 while True: # Cleanup soft deleted instances and networks delay = config.parsed.get('CLEANER_DELAY') for i in db.get_stale_instances(delay): LOG.info('Hard deleting instance %s' % i['uuid']) db.hard_delete_instance(i['uuid']) for n in db.get_stale_networks(delay): LOG.info('Hard deleting network %s' % n['uuid']) db.hard_delete_network(n['uuid']) for ni in db.get_stale_network_interfaces(delay): LOG.info('Hard deleting network interface %s' % ni['uuid']) db.hard_delete_network_interface(ni['uuid']) # Perform etcd maintenance if time.time() - last_compaction > 1800: # We need to determine what revision to compact to, so we keep a # key which stores when we last compacted and we use it's latest # revision number as the revision to compact to. c = etcd3.client() c.put('/sf/compact', json.dumps({'compacted_at': time.time()})) _, kv = c.get('/sf/compact') c.compact(kv.mod_revision, physical=True) c.defragment() last_compaction = time.time() time.sleep(60)
def delete(self, namespace): if not namespace: return error(400, 'no namespace specified') if namespace == 'system': return error(403, 'you cannot delete the system namespace') # The namespace must be empty instances = [] deleted_instances = [] for i in db.get_instances(all=True, namespace=namespace): if i['state'] == 'deleted': deleted_instances.append(i['uuid']) else: instances.append(i['uuid']) if len(instances) > 0: return error(400, 'you cannot delete a namespace with instances') networks = [] deleted_networks = [] for n in db.get_networks(all=True, namespace=namespace): if n['state'] == 'deleted': deleted_networks.append(n['uuid']) else: networks.append(n['uuid']) if len(networks) > 0: return error(400, 'you cannot delete a namespace with networks') for instance_uuid in deleted_instances: db.hard_delete_instance(instance_uuid) for network_uuid in deleted_networks: db.hard_delete_network(network_uuid) db.delete_namespace(namespace) db.delete_metadata('namespace', namespace)
def run(self): logutil.info(None, 'Starting') last_compaction = 0 while True: # Update power state of all instances on this hypervisor logutil.info(None, 'Updating power states') self._update_power_states() # Cleanup soft deleted instances and networks delay = config.parsed.get('CLEANER_DELAY') for i in db.get_stale_instances(delay): logutil.info([virt.ThinInstance(i['uuid'])], 'Hard deleting instance') db.hard_delete_instance(i['uuid']) for n in db.get_stale_networks(delay): logutil.info([net.ThinNetwork(n['uuid'])], 'Hard deleting network') db.hard_delete_network(n['uuid']) for ni in db.get_stale_network_interfaces(delay): logutil.info([net.ThinNetworkInterface(ni['uuid'])], 'Hard deleting network interface') db.hard_delete_network_interface(ni['uuid']) # Perform etcd maintenance if time.time() - last_compaction > 1800: logutil.info(None, 'Compacting etcd') self._compact_etcd() last_compaction = time.time() time.sleep(60)