-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation of hardware module
Incomplete
- Loading branch information
Soufiane Jounaid
committed
Jul 15, 2024
1 parent
4b00222
commit 9e3a946
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from dataclasses import dataclass | ||
from datetime import datetime | ||
from typing import List, Optional, Tuple | ||
|
||
|
||
from .clients import blazar | ||
from .context import get, RESOURCE_API_URL | ||
|
||
import requests | ||
import json | ||
import logging | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
@dataclass | ||
class Node: | ||
site_name: str | ||
node_name: str | ||
node_type: str | ||
# Other fields from the hardware API | ||
|
||
def next_free_timeslot(self) -> Tuple[datetime, datetime]: | ||
raise NotImplementedError() | ||
|
||
|
||
def get_nodes( | ||
all_sites: bool = False, | ||
filter_reserved: bool = False, | ||
gpu: Optional[bool] = None, | ||
number_cpu: Optional[int] = None, | ||
) -> List[Node]: | ||
site = get("region_name") # Get the site using the get method from the context module | ||
endpoint = f"sites/{site}/clusters/chameleon/nodes" # Build the endpoint URL | ||
api = G5K_API() | ||
data = api.call(endpoint) # Make the API call | ||
nodes = [] | ||
for node_data in data: | ||
node = Node( | ||
site_name=site, | ||
node_name=node_data["name"], | ||
node_type=node_data["type"], | ||
) | ||
nodes.append(node) | ||
return nodes | ||
|
||
class G5K_API: | ||
def call(self, endpoint): | ||
url = self.make_url(endpoint) | ||
LOG.info("Requesting %s from reference API ...", url) | ||
resp = requests.get(url) | ||
LOG.info("Response received. Parsing to json ...") | ||
data = resp.json() | ||
return data | ||
|
||
def make_url(self, endpoint): | ||
return "{0}/{1}.{2}".format(RESOURCE_API_URL, endpoint, "json") |