def on_end(self, resource_id): """Remove the hosts from the pool.""" reservations = db_api.reservation_get_all_by_values( resource_id=resource_id) for reservation in reservations: if reservation['status'] not in ['completed', 'deleted']: allocations = db_api.host_allocation_get_all_by_values( reservation_id=reservation['id']) pool = rp.ReservationPool() for allocation in allocations: db_api.host_allocation_destroy(allocation['id']) hyp = self.nova.hypervisors.get( self._get_hypervisor_from_name_or_id( allocation['compute_host_id']) ) if hyp.__dict__['running_vms'] > 0: hyp = self.nova.hypervisors.search(hyp.__dict__['hypervisor_hostname'], servers=True) for server in hyp[0].__dict__['servers']: s = self.nova.servers.get(server['uuid']) s.delete() pool.delete(reservation['resource_id']) db_api.reservation_update(reservation['id'], {'status': 'completed'}) host_reservation = db_api.host_reservation_get_by_reservation_id( reservation['id']) db_api.host_reservation_update(host_reservation['id'], {'status': 'completed'})
def on_start(self, resource_id): """Add the hosts in the pool.""" reservations = db_api.reservation_get_all_by_values( resource_id=resource_id) for reservation in reservations: pool = rp.ReservationPool() for allocation in db_api.host_allocation_get_all_by_values( reservation_id=reservation['id']): host = db_api.host_get(allocation['compute_host_id']) pool.add_computehost(reservation['resource_id'], host['service_name'])
def on_end(self, resource_id): """Remove the hosts from the pool.""" reservations = db_api.reservation_get_all_by_values( resource_id=resource_id) for reservation in reservations: db_api.reservation_update(reservation['id'], {'status': 'completed'}) host_reservation = db_api.host_reservation_get_by_reservation_id( reservation['id']) db_api.host_reservation_update(host_reservation['id'], {'status': 'completed'}) allocations = db_api.host_allocation_get_all_by_values( reservation_id=reservation['id']) pool = rp.ReservationPool() for allocation in allocations: db_api.host_allocation_destroy(allocation['id']) if self.nova.hypervisors.get( self._get_hypervisor_from_name_or_id( allocation['compute_host_id']) ).__dict__['running_vms'] == 0: pool.delete(reservation['resource_id'])