def _update(self, context, host, binary, payload): """Do the actual update""" svc = objects.ZunService.get_by_host_and_binary(context, host, binary) if svc is None: raise exception.ZunServiceNotFound(binary=binary, host=host) else: return svc.update(context, payload)
def destroy_zun_service(self, host, binary): session = get_session() with session.begin(): query = model_query(models.ZunService, session=session) query = query.filter_by(host=host, binary=binary) count = query.delete() if count != 1: raise exception.ZunServiceNotFound(host=host, binary=binary)
def destroy_zun_service(self, host, binary): try: self.client.delete('/zun_services/' + host + '_' + binary) except etcd.EtcdKeyNotFound: raise exception.ZunServiceNotFound(host=host, binary=binary) except Exception as e: LOG.error('Error occurred while destroying zun service: %s', six.text_type(e)) raise
def get_zun_service(self, host, binary): try: service = None res = self.client.read('/zun_services/' + host + '_' + binary) service = translate_etcd_result(res, 'zun_service') except etcd.EtcdKeyNotFound: raise exception.ZunServiceNotFound(host=host, binary=binary) except Exception as e: LOG.error('Error occurred while retrieving zun service: %s', six.text_type(e)) raise finally: return service
def update_zun_service(self, host, binary, values): try: target = self.client.read('/zun_services/' + host + '_' + binary) target_value = json.loads(target.value) values['updated_at'] = datetime.isoformat(timeutils.utcnow()) target_value.update(values) target.value = json.dump_as_bytes(target_value) self.client.update(target) except etcd.EtcdKeyNotFound: raise exception.ZunServiceNotFound(host=host, binary=binary) except Exception as e: LOG.error('Error occurred while updating service: %s', six.text_type(e)) raise
def delete(self, host, binary): """Delete the specified service. :param host: The host on which the binary is running. :param binary: The name of the binary. """ context = pecan.request.context policy.enforce(context, "zun-service:delete", action="zun-service:delete") svc = objects.ZunService.get_by_host_and_binary(context, host, binary) if svc is None: raise exception.ZunServiceNotFound(binary=binary, host=host) else: svc.destroy(context)
def update_zun_service(self, host, binary, values): session = get_session() with session.begin(): query = model_query(models.ZunService, session=session) query = query.filter_by(host=host, binary=binary) try: ref = query.with_lockmode('update').one() except NoResultFound: raise exception.ZunServiceNotFound(host=host, binary=binary) if 'report_count' in values: if values['report_count'] > ref.report_count: ref.last_seen_up = timeutils.utcnow() ref.update(values) return ref