def put(self, id, sublease): """Update an existing lease. :param id: UUID of a lease. :param lease: a subset of a Lease containing values to update. """ sublease_dct = sublease.as_dict() new_name = sublease_dct.pop('name', None) end_date = sublease_dct.pop('end_date', None) start_date = sublease_dct.pop('start_date', None) before_end_date = sublease_dct.pop('before_end_date', None) if sublease_dct != {}: raise exceptions.BlazarException('Only name changing, ' 'dates and before end ' 'notifications may be ' 'proceeded.') if new_name: sublease_dct['name'] = new_name if end_date: sublease_dct['end_date'] = end_date if start_date: sublease_dct['start_date'] = start_date if before_end_date: sublease_dct['before_end_date'] = before_end_date lease = pecan.request.rpcapi.update_lease(id, sublease_dct) if lease is None: raise exceptions.NotFound(object={'lease_id': id}) return Lease.convert(lease)
def get_one(self, id): """Returns the lease having this specific uuid :param id: ID of lease """ lease = pecan.request.rpcapi.get_lease(id) if lease is None: raise exceptions.NotFound(object={'lease_id': id}) return Lease.convert(lease)
def get_one(self, id): """Returns the host having this specific uuid :param id: ID of host """ host_dct = pecan.request.hosts_rpcapi.get_computehost(id) if host_dct is None: raise exceptions.NotFound(object={'host_id': id}) return Host.convert(host_dct)
def delete(self, id): """Delete an existing lease. :param id: UUID of a lease. """ try: pecan.request.rpcapi.delete_lease(id) except TypeError: # The lease was not existing when asking to delete it raise exceptions.NotFound(object={'lease_id': id})
def delete(self, id): """Delete an existing host. :param id: UUID of a host. """ try: pecan.request.hosts_rpcapi.delete_computehost(id) except TypeError: # The host was not existing when asking to delete it raise exceptions.NotFound(object={'host_id': id})
def put(self, id, host): """Update an existing host. :param id: ID of a host. :param host: a subset of a Host containing values to update. """ host_dct = host.as_dict() host = pecan.request.hosts_rpcapi.update_computehost(id, host_dct) if host is None: raise exceptions.NotFound(object={'host_id': id}) return Host.convert(host)
def handler(*args, **kwargs): """Decorator handler.""" get_kwargs = {} for k, v in get_args.items(): get_kwargs[k] = kwargs[v] try: obj = get_function(**get_kwargs) except exceptions.NotFound: obj = None if obj is None: e = exceptions.NotFound(object=get_kwargs) return api_utils.not_found(e) return func(*args, **kwargs)