Skip to content

Commit

Permalink
make api consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
s-m-e committed Feb 8, 2022
1 parent d36f2b9 commit 9132c45
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/scherbelberg/_core/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
# IMPORT
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

import os
from typing import Any, Dict, List, Optional

from hcloud import Client
Expand All @@ -36,40 +37,45 @@
from hcloud.locations.client import LocationsClient
from hcloud.locations.domain import Location

from .const import TOKENVAR
from .debug import typechecked

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# ROUTINES
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

@typechecked
def get_locations(client: Client) -> List[Dict[str, Any]]:
async def get_locations(tokenvar: str = TOKENVAR) -> List[Dict[str, Any]]:
"""
Queries a list of data center locations.
Args:
client : A cloud-API client object.
tokenvar : Name of the environment variable holding the cloud API login token.
Returns:
Data center locations.
"""

client = Client(token=os.environ[tokenvar])

return [
_parse_location(location.data_model)
for location in LocationsClient(client).get_all()
]

@typechecked
def get_servertypes(client: Client, location: str = 'fsn1') -> List[Dict[str, Any]]:
async def get_servertypes(location: str = 'fsn1', tokenvar: str = TOKENVAR) -> List[Dict[str, Any]]:
"""
Queries a list of server types plus their specifications and prices.
Args:
client : A cloud-API client object.
location : Name of data center location.
tokenvar : Name of the environment variable holding the cloud API login token.
Returns:
Server types plus their specifications and prices.
"""

client = Client(token=os.environ[tokenvar])

servertypes = ServerTypesClient(client).get_all()

servertypes = [_parse_model(servertype.data_model) for servertype in servertypes]
Expand Down

0 comments on commit 9132c45

Please sign in to comment.