コード例 #1
0
    def patch(args: argparse.Namespace) -> None:
        path = "agents/{}/slots/{}".format(args.agent_id, args.slot_id)
        headers = {"Content-Type": "application/merge-patch+json"}
        payload = {"enabled": enabled}

        api.patch(args.master, path, json=payload, headers=headers)
        status = "Disabled" if not enabled else "Enabled"
        print("{} slot {} of agent {}".format(status, args.slot_id,
                                              args.agent_id))
コード例 #2
0
    def remove_metadata(self, keys: List[str]) -> None:
        """
        Removes user-defined metadata from the model. Any top-level keys that
        appear in the ``keys`` list are removed from the model.

        Arguments:
            keys (List[string]): Top-level keys to remove from the model metadata.
        """
        for key in keys:
            if key in self.metadata:
                del self.metadata[key]

        api.patch(
            self._master,
            "/api/v1/models/{}".format(self.name),
            body={"model": {"metadata": self.metadata, "description": self.description}},
        )
コード例 #3
0
    def add_metadata(self, metadata: Dict[str, Any]) -> None:
        """
        Adds user-defined metadata to the model. The ``metadata`` argument must be a
        JSON-serializable dictionary. If any keys from this dictionary already appear in
        the model's metadata, the previous dictionary entries are replaced.

        Arguments:
            metadata (dict): Dictionary of metadata to add to the model.
        """
        for key, val in metadata.items():
            self.metadata[key] = val

        api.patch(
            self._master,
            "/api/v1/models/{}".format(self.name),
            body={"model": {"metadata": self.metadata, "description": self.description}},
        )
コード例 #4
0
def change_experiment_state(experiment_id: int, new_state: str) -> None:
    auth.initialize_session(conf.make_master_url(), try_reauth=True)
    r = api.patch(
        conf.make_master_url(),
        "experiments/{}".format(experiment_id),
        headers={"Content-Type": "application/merge-patch+json"},
        body={"state": new_state},
    )
    assert r.status_code == requests.codes.no_content, r.text
コード例 #5
0
def change_experiment_state(experiment_id: int, new_state: str) -> None:
    # TODO(DET-5678): refactor tests to not use cli singleton auth.
    certs.cli_cert = certs.default_load(conf.make_master_url())
    authentication.cli_auth = authentication.Authentication(
        conf.make_master_url(), try_reauth=True)
    r = api.patch(
        conf.make_master_url(),
        "experiments/{}".format(experiment_id),
        headers={"Content-Type": "application/merge-patch+json"},
        body={"state": new_state},
    )
    assert r.status_code == requests.codes.no_content, r.text
コード例 #6
0
ファイル: agent.py プロジェクト: shiyuann/determined
    def patch(args: argparse.Namespace) -> None:
        check_false(args.all and args.agent_id)

        if not (args.all or args.agent_id):
            print("Error: must specify exactly one of `--all` or agent_id")
            sys.exit(1)

        if args.agent_id:
            agent_ids = [args.agent_id]
        else:
            r = api.get(args.master, "agents")
            agent_ids = sorted(local_id(a) for a in r.json().keys())

        for agent_id in agent_ids:
            path = "agents/{}/slots".format(agent_id)
            headers = {"Content-Type": "application/merge-patch+json"}
            payload = {"enabled": enabled}

            api.patch(args.master, path, body=payload, headers=headers)
            status = "Disabled" if not enabled else "Enabled"
            print("{} agent {}".format(status, agent_id))
コード例 #7
0
def update_user(
    username: str,
    master_address: str,
    active: Optional[bool] = None,
    password: Optional[str] = None,
    agent_user_group: Optional[Dict[str, Any]] = None,
) -> Response:
    if active is None and password is None and agent_user_group is None:
        raise Exception(
            "Internal error (must supply at least one kwarg to update_user).")

    request = {}  # type: Dict[str, Any]
    if active is not None:
        request["active"] = active

    if password is not None:
        request["password"] = password

    if agent_user_group is not None:
        request["agent_user_group"] = agent_user_group

    return api.patch(master_address, "users/{}".format(username), body=request)
コード例 #8
0
def update_username(current_username: str, master_address: str,
                    new_username: str) -> Response:
    request = {"username": new_username}
    return api.patch(master_address,
                     "users/{}/username".format(current_username),
                     body=request)