grr/server/grr_response_server/hunt.py
def StartHuntFlowOnClient(client_id, hunt_id):
  """Starts a flow corresponding to a given hunt on a given client."""

  hunt_obj = data_store.REL_DB.ReadHuntObject(hunt_id)
  hunt_obj = CompleteHuntIfExpirationTimeReached(hunt_obj)
  # There may be a little race between foreman rules being removed and
  # foreman scheduling a client on an (already) paused hunt. Making sure
  # we don't lose clients in such a race by accepting clients for paused
  # hunts.
  if hunt_obj.hunt_state not in [
      rdf_hunt_objects.Hunt.HuntState.STARTED,
      rdf_hunt_objects.Hunt.HuntState.PAUSED
  ]:
    return

  if hunt_obj.args.hunt_type == hunt_obj.args.HuntType.STANDARD:
    hunt_args = hunt_obj.args.standard

    def UpdateFn(h):
      # h.num_clients > 0 check ensures that first client will be scheduled
      # immediately and not 60.0 / h.client_rate seconds after the hunt is
      # started.
      if h.client_rate > 0 and h.num_clients > 0:
        h.next_client_due = h.next_client_due + 60.0 / h.client_rate
      h.num_clients += 1
      return h

    hunt_obj = data_store.REL_DB.UpdateHuntObject(hunt_id, UpdateFn)
    start_at = hunt_obj.next_client_due if hunt_obj.client_rate > 0 else None

    flow_cls = registry.FlowRegistry.FlowClassByName(hunt_args.flow_name)
    flow_args = hunt_args.flow_args if hunt_args.HasField("flow_args") else None
    flow.StartFlow(
        client_id=client_id,
        creator=hunt_obj.creator,
        cpu_limit=hunt_obj.per_client_cpu_limit,
        network_bytes_limit=hunt_obj.per_client_network_bytes_limit,
        flow_cls=flow_cls,
        flow_args=flow_args,
        start_at=start_at,
        parent_hunt_id=hunt_id)

    if hunt_obj.client_limit and hunt_obj.num_clients >= hunt_obj.client_limit:
      PauseHunt(hunt_obj.hunt_id)

  elif hunt_obj.args.hunt_type == hunt_obj.args.HuntType.VARIABLE:
    raise NotImplementedError()
  else:
    raise UnknownHuntTypeError("Can't determine hunt type when starting "
                               "hunt %s on client %s." % (client_id, hunt_id))
Starts a flow corresponding to a given hunt on a given client.
Starts a flow corresponding to a given hunt on a given client.
Starts a flow corresponding to a given hunt on a given client .
def StartHuntFlowOnClient(client_id, hunt_id):
  hunt_obj = data_store.REL_DB.ReadHuntObject(hunt_id)
  hunt_obj = CompleteHuntIfExpirationTimeReached(hunt_obj)
  if hunt_obj.hunt_state not in [
      rdf_hunt_objects.Hunt.HuntState.STARTED,
      rdf_hunt_objects.Hunt.HuntState.PAUSED
  ]:
    return
  if hunt_obj.args.hunt_type == hunt_obj.args.HuntType.STANDARD:
    hunt_args = hunt_obj.args.standard
    def UpdateFn(h):
      if h.client_rate > 0 and h.num_clients > 0:
        h.next_client_due = h.next_client_due + 60.0 / h.client_rate
      h.num_clients += 1
      return h
    hunt_obj = data_store.REL_DB.UpdateHuntObject(hunt_id, UpdateFn)
    start_at = hunt_obj.next_client_due if hunt_obj.client_rate > 0 else None
    flow_cls = registry.FlowRegistry.FlowClassByName(hunt_args.flow_name)
    flow_args = hunt_args.flow_args if hunt_args.HasField("flow_args") else None
    flow.StartFlow(
        client_id=client_id,
        creator=hunt_obj.creator,
        cpu_limit=hunt_obj.per_client_cpu_limit,
        network_bytes_limit=hunt_obj.per_client_network_bytes_limit,
        flow_cls=flow_cls,
        flow_args=flow_args,
        start_at=start_at,
        parent_hunt_id=hunt_id)
    if hunt_obj.client_limit and hunt_obj.num_clients >= hunt_obj.client_limit:
      PauseHunt(hunt_obj.hunt_id)
  elif hunt_obj.args.hunt_type == hunt_obj.args.HuntType.VARIABLE:
    raise NotImplementedError()
  else:
    raise UnknownHuntTypeError("Can't determine hunt type when starting "
                               "hunt %s on client %s." % (client_id, hunt_id))
def StartHuntFlowOnClient ( client_id , hunt_id ) : hunt_obj = data_store . REL_DB . ReadHuntObject ( hunt_id ) hunt_obj = CompleteHuntIfExpirationTimeReached ( hunt_obj ) if hunt_obj . hunt_state not in [ rdf_hunt_objects . Hunt . HuntState . STARTED , rdf_hunt_objects . Hunt . HuntState . PAUSED ] : return if hunt_obj . args . hunt_type == hunt_obj . args . HuntType . STANDARD : hunt_args = hunt_obj . args . standard def UpdateFn ( h ) : if h . client_rate > 0 and h . num_clients > 0 : h . next_client_due = h . next_client_due + 60.0 / h . client_rate h . num_clients += 1 return h hunt_obj = data_store . REL_DB . UpdateHuntObject ( hunt_id , UpdateFn ) start_at = hunt_obj . next_client_due if hunt_obj . client_rate > 0 else None flow_cls = registry . FlowRegistry . FlowClassByName ( hunt_args . flow_name ) flow_args = hunt_args . flow_args if hunt_args . HasField ( "flow_args" ) else None flow . StartFlow ( client_id = client_id , creator = hunt_obj . creator , cpu_limit = hunt_obj . per_client_cpu_limit , network_bytes_limit = hunt_obj . per_client_network_bytes_limit , flow_cls = flow_cls , flow_args = flow_args , start_at = start_at , parent_hunt_id = hunt_id ) if hunt_obj . client_limit and hunt_obj . num_clients >= hunt_obj . client_limit : PauseHunt ( hunt_obj . hunt_id ) elif hunt_obj . args . hunt_type == hunt_obj . args . HuntType . VARIABLE : raise NotImplementedError ( ) else : raise UnknownHuntTypeError ( "Can't determine hunt type when starting " "hunt %s on client %s." % ( client_id , hunt_id ) )
Starts a flow corresponding to a given hunt on a given client.
Starts a flow corresponding to a given hunt on a given client .
"""Starts a flow corresponding to a given hunt on a given client.""" # There may be a little race between foreman rules being removed and # foreman scheduling a client on an (already) paused hunt. Making sure # we don't lose clients in such a race by accepting clients for paused # hunts. # h.num_clients > 0 check ensures that first client will be scheduled # immediately and not 60.0 / h.client_rate seconds after the hunt is # started.
client_id
hunt_id