

def set_lifecycle_state(self, resource_id='', target_lcstate=''):
    'Sets the lifecycle state (if possible) to the target state. Supports compound states'
    if (not target_lcstate):
        raise BadRequest(('Bad life-cycle state %s' % target_lcstate))
    if target_lcstate.startswith(LCS.DELETED):
        self.lcs_delete(resource_id)
    if target_lcstate.startswith(LCS.RETIRED):
        self.execute_lifecycle_transition(resource_id, LCE.RETIRE)
    res_obj = self.read(resource_id)
    old_lcstate = res_obj.lcstate
    old_availability = res_obj.availability
    restype = res_obj.type_
    restype_workflow = get_restype_lcsm(restype)
    if (not restype_workflow):
        raise BadRequest(('Resource id=%s type=%s has no lifecycle' % (resource_id, restype)))
    if ('_' in target_lcstate):
        (target_lcs, target_av) = lcsplit(target_lcstate)
        if (target_lcs not in LCS):
            raise BadRequest(('Unknown life-cycle state %s' % target_lcs))
        if (target_av and (target_av not in AS)):
            raise BadRequest(('Unknown life-cycle availability %s' % target_av))
    elif (target_lcstate in LCS):
        (target_lcs, target_av) = (target_lcstate, res_obj.availability)
    elif (target_lcstate in AS):
        (target_lcs, target_av) = (res_obj.lcstate, target_lcstate)
    else:
        raise BadRequest(('Unknown life-cycle state %s' % target_lcstate))
    lcs_successors = restype_workflow.get_lcstate_successors(old_lcstate)
    av_successors = restype_workflow.get_availability_successors(old_availability)
    (found_lcs, found_av) = ((target_lcs in lcs_successors.values()), (target_av in av_successors.values()))
    if ((not found_lcs) and (not found_av)):
        raise BadRequest(('Target state %s not reachable for resource in state %s_%s' % (target_lcstate, old_lcstate, old_availability)))
    res_obj.lcstate = target_lcs
    res_obj.availability = target_av
    res_obj.ts_updated = get_ion_ts()
    updres = target_av.rr_store.update(res_obj)
    log.debug('set_lifecycle_state(res_id=%s, target=%s). Change %s_%s to %s_%s', resource_id, target_lcstate, old_lcstate, old_availability, res_obj.lcstate, res_obj.availability)
    if self.container.has_capability(self.container.CCAP.EVENT_PUBLISHER):
        self.event_pub.publish_event(event_type='ResourceLifecycleEvent', origin=res_obj._id, origin_type=res_obj.type_, sub_type=('%s.%s' % (res_obj.lcstate, res_obj.availability)), lcstate=res_obj.lcstate, availability=res_obj.availability, lcstate_before=old_lcstate, availability_before=old_availability)

dataset/ETHPy150Open ooici/pyon/pyon/ion/resregistry.py ResourceRegistry.set_lifecycle_state/VarMisuse@370/702 `self`->`target_av`