Skip to content

Commit

Permalink
agent add/remove variables + fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
solarw committed Jan 1, 2024
1 parent f5097b3 commit 7dd5925
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 22 deletions.
16 changes: 0 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,3 @@ security:
tox -p -e safety -e bandit
gitleaks detect --report-format json --report-path leak_report

.PHONY: common-checks-1
common-checks-1:
tox -p -e check-copyright -e check-hash -e check-packages


.PHONY: docs
docs:
mkdocs build --clean --strict

.PHONY: test
test:
pytest -rfE tests/ --cov=open_autonomy_client --cov-report=html --cov-report=xml --cov-report=term --cov-report=term-missing --cov-config=.coveragerc
find . -name ".coverage*" -not -name ".coveragerc" -exec rm -fr "{}" \;

.PHONY: all-checks
all-checks: clean formatters code-checks security common-checks-1
6 changes: 3 additions & 3 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
set -e
export BASE_URL=https://app.propel-dev1.autonolas.tech/
export BASE_URL=https://app.propel.staging.valory.xyz/
export CMD="propel -U $BASE_URL"
export AGENT_NAME=test_agent1_2
export KEY_ID=1
Expand All @@ -20,7 +20,7 @@ for i in "agent1 3" "agent2 4" "agent3 5" "agent4 6";
do
IFS=' ' read -r -a array <<< "$i"
AGENT_ID=${array[0]}
KEY_ID=${array[1]}
KEY_ID=${array[1]}

# check user has seats to perform agent creation
$CMD seats ensure
Expand All @@ -30,7 +30,7 @@ do
$CMD agents ensure-deleted $AGENT_NAME

# cerate agent. name has to be unique. will not allow create several agents with same name and/or key
$CMD agents create --name $AGENT_NAME --key $KEY_ID --service-ipfs-hash $IPFS_HASH --variables $VARIABLES
$CMD agents deploy --name --key $KEY_ID --service-ipfs-hash $IPFS_HASH --variables $VARIABLES

# wait for deployed. but it actually started. callr restart to have clean STARTED state
$CMD agents wait $AGENT_NAME DEPLOYED --timeout=120
Expand Down
36 changes: 36 additions & 0 deletions propel_client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,42 @@ def agents_stop(obj: ClickAPPObject, name_or_id: str) -> None:
print_json(agent)


@click.command(name="variables-add")
@click.pass_obj
@click.argument("name_or_id", type=str, required=True)
@click.argument("variables", type=str, required=False)
def agents_variables_add(obj: ClickAPPObject, name_or_id: str, variables: str) -> None:
"""
Add variables to agent.
:param name_or_id: str
:param variables: str
:param obj: ClickAPPObject
"""
variables_list = variables.split(",") or [] if variables else []
agent = obj.propel_client.agents_variables_add(name_or_id, variables_list)
print_json(agent)


@click.command(name="variables-remove")
@click.pass_obj
@click.argument("name_or_id", type=str, required=True)
@click.argument("variables", type=str, required=False)
def agents_variables_remove(
obj: ClickAPPObject, name_or_id: str, variables: str
) -> None:
"""
Remove variables from agent.
:param name_or_id: str
:param variables: str
:param obj: ClickAPPObject
"""
variables_list = variables.split(",") or [] if variables else []
agent = obj.propel_client.agents_variables_remove(name_or_id, variables_list)
print_json(agent)


@click.command(name="delete")
@click.pass_obj
@click.argument("name_or_id", type=str, required=True)
Expand Down
49 changes: 47 additions & 2 deletions propel_client/propel.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def agents_restart(self, agent_name_or_id: Union[int, str]) -> Dict:
:return: dict
"""
url = self._get_url(self.API_AGENTS_LIST) + f"/{agent_name_or_id}/restart"
url = self._get_url(self.API_AGENTS_LIST) + f"/{agent_name_or_id}/restart/"
response = requests.get(url, **self._get_credentials_params())
self._check_response(response)
return response.json()
Expand All @@ -254,11 +254,56 @@ def agents_stop(self, agent_name_or_id: Union[int, str]) -> Dict:
:return: dict
"""
url = self._get_url(self.API_AGENTS_LIST) + f"/{agent_name_or_id}/stop"
url = self._get_url(self.API_AGENTS_LIST) + f"/{agent_name_or_id}/stop/"
response = requests.get(url, **self._get_credentials_params())
self._check_response(response)
return response.json()

def agents_variables_add(
self, agent_name_or_id: Union[int, str], variables: List[str]
) -> Dict:
"""
Add variables to agent.
:param agent_name_or_id: str or int
:param variables: list of str
:return: dict
"""
url = (
self._get_url(self.API_AGENTS_LIST) + f"/{agent_name_or_id}/variables_add/"
)
response = requests.post(
url,
json={"variables": variables},
**self._get_credentials_params(),
allow_redirects=False,
)
self._check_response(response)
return response.json()

def agents_variables_remove(
self, agent_name_or_id: Union[int, str], variables: List[str]
) -> Dict:
"""
Remove variables from agent.
:param agent_name_or_id: str or int
:param variables: list of str
:return: dict
"""
url = (
self._get_url(self.API_AGENTS_LIST)
+ f"/{agent_name_or_id}/variables_remove/"
)

response = requests.post(
url, **self._get_credentials_params(), json={"variables": variables}
)
self._check_response(response)
return response.json()

def agents_delete(self, agent_name_or_id: Union[int, str]) -> Dict:
"""
Delete agent by name or id.
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ deps =
click==8.0.2
requests<3.0.0,>=2.28.2
pytest
poetry
pytest-coverage
types-requests

Expand Down Expand Up @@ -139,7 +140,7 @@ skip_install = True
deps =
tomte[flake8]==0.2.3
commands =
flake8 propel_client tests
flake8 --ignore=W503 propel_client tests

[testenv:mypy]
skipsdist = True
Expand Down

0 comments on commit 7dd5925

Please sign in to comment.