Skip to content
Snippets Groups Projects
Commit cff8ed09 authored by Mohammad Torkashvand's avatar Mohammad Torkashvand
Browse files

add aig_ prefix to all env vars

parent 45713c72
No related branches found
No related tags found
No related merge requests found
Pipeline #88723 passed
......@@ -7,7 +7,7 @@ run-tox-pipeline:
stage: tox
tags:
- docker-executor
image: python:3.10
image: python:3.12
# Change pip's cache directory to be inside the project directory since we can
# only cache local items.
......
......@@ -28,11 +28,11 @@ Fill in environment variables and run the command to generate the Ansible invent
```bash
# Rewritting environment variables
## URL of the WFO API (change IP only)
export api_url=http://127.0.0.1:8080/api/v1/subscriptions/routers
export aig_api_url=http://127.0.0.1:8080/api/v1/subscriptions/routers
## Token provided by each GSO instance admin (varies per environment)
export gso_api_key=<fill_with_gso_token>
export aig_gso_api_key=<fill_with_gso_token>
## Full paths where AIG will save host_vars
export host_vars_dir=/path/to/base/host_vars/dir
export aig_host_vars_dir=/path/to/base/host_vars/dir
# Execution of the command to generate the Ansible inventory files
ansible_inventory_generator
......@@ -60,4 +60,4 @@ pip install -U pip setuptools wheel
### 403 error when running the `ansible_inventory_generator` command
This tool cannot reach the GSO API because it is authenticated. Use a correct gso_api_key environment variable.
This tool cannot reach the GSO API because it is authenticated. Use a correct aig_gso_api_key environment variable.
......@@ -26,10 +26,10 @@ def represent_none(self: BaseRepresenter, _: Any) -> ScalarNode:
yaml.add_representer(type(None), represent_none)
def write_host_vars(host_name: str, router_data: dict, host_vars_dir: Path) -> None:
def write_host_vars(host_name: str, router_data: dict, aig_host_vars_dir: Path) -> None:
"""Write host variables to a file."""
settings = load_settings()
host_dir = host_vars_dir / host_name
host_dir = aig_host_vars_dir / host_name
host_dir.mkdir(exist_ok=True)
vars_file_path = host_dir / settings.vars_file_name
......@@ -56,8 +56,8 @@ def write_hosts_file(groups: dict, hosts_file: Path) -> None:
def generate_host_vars_and_hosts_file(router_subscriptions: list, temp_dir: Path) -> None:
"""Process router subscriptions data."""
groups: dict[str, list[str]] = {}
host_vars_dir = temp_dir / "host_vars"
host_vars_dir.mkdir()
aig_host_vars_dir = temp_dir / "host_vars"
aig_host_vars_dir.mkdir()
for router_subscription in router_subscriptions:
router = router_subscription.get("router", {})
......@@ -65,7 +65,7 @@ def generate_host_vars_and_hosts_file(router_subscriptions: list, temp_dir: Path
if not host_name:
continue
write_host_vars(host_name, router, host_vars_dir)
write_host_vars(host_name, router, aig_host_vars_dir)
vendor_group = router.get("vendor", "").lower()
role_group = f"{router.get('router_role', '')}_routers"
......@@ -101,7 +101,7 @@ def generate_inventory_from_api() -> None:
settings = load_settings()
"""Generate Ansible inventory from API."""
response = requests.get(
settings.api_url, timeout=API_TIMEOUT_SEC, headers={"Authorization": f"Bearer {settings.gso_api_key}"}
settings.aig_api_url, timeout=API_TIMEOUT_SEC, headers={"Authorization": f"Bearer {settings.aig_gso_api_key}"}
)
response.raise_for_status()
try:
......@@ -111,7 +111,7 @@ def generate_inventory_from_api() -> None:
sys.exit(1)
temp_dir = Path(tempfile.mkdtemp())
old_host_vars_dir = Path(settings.host_vars_dir)
old_host_vars_dir = Path(settings.aig_host_vars_dir)
with safe_write(temp_dir, old_host_vars_dir) as temp_dir:
generate_host_vars_and_hosts_file(router_subscriptions, temp_dir)
......
......@@ -2,9 +2,9 @@ from pydantic.v1 import BaseSettings
class Settings(BaseSettings):
api_url: str
gso_api_key: str
host_vars_dir: str
aig_api_url: str
aig_gso_api_key: str
aig_host_vars_dir: str
vars_file_name: str = "gso.yaml"
class Config:
......
api_url=http://127.0.0.1:8080/api/v1/subscriptions/routers
host_vars_dir=/path/to/base/hostvars/dir
aig_api_url=http://127.0.0.1:8080/api/v1/subscriptions/routers
aig_host_vars_dir=/path/to/base/hostvars/dir
vars_file_name=wfo_vars.yaml
hosts_file_dir=/path/to/base/hosts/dir
gso_api_key=askjdhaskhdaksjhdkajshdkashd
aig_gso_api_key=askjdhaskhdaksjhdkajshdkashd
......@@ -154,10 +154,10 @@ def setup_test(tmp_dir, mocked_subscription_api_data):
patch("requests.get") as mock_get,
):
mock_load_settings.return_value = Settings(
api_url="http://test",
host_vars_dir=str(tmp_dir),
aig_api_url="http://test",
aig_host_vars_dir=str(tmp_dir),
vars_file_name="wfo_vars.yaml",
gso_api_key="random_gso_api_key",
aig_gso_api_key="random_gso_api_key",
)
mock_get.return_value.json.return_value = mocked_subscription_api_data
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment