Skip to content

Commit

Permalink
Initial implementation of hardware module
Browse files Browse the repository at this point in the history
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.
56 changes: 56 additions & 0 deletions chi/hardware.py
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")

0 comments on commit 9e3a946

Please sign in to comment.