Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Soufianej server 1.0 #62

Merged
merged 20 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions chi/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,6 @@ def _is_ipynb() -> bool:
return False
return True


def _is_ipynb() -> bool:
try:
from IPython import get_ipython
if 'IPKernelApp' not in get_ipython().config:
return False
except ImportError:
return False
return True


def set(key, value):
"""Set a context parameter by name.

Expand Down
3 changes: 2 additions & 1 deletion chi/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class Node:
uid: str
version: str


def next_free_timeslot(self) -> Tuple[datetime, Optional[datetime]]:
"""
Finds the next available timeslot for the hardware using the Blazar client.
Expand Down Expand Up @@ -63,13 +62,15 @@ def next_free_timeslot(self) -> Tuple[datetime, Optional[datetime]]:
next_start = datetime.fromisoformat(allocations[i+1]['start_date'])



if current_end < next_start:
return (current_end, next_start)

# If no free slot found, return the end of the last allocation
last_end = datetime.fromisoformat(allocations[-1]['end_date'])
return (last_end, None)


def _call_api(endpoint):
url = "{0}/{1}.{2}".format(RESOURCE_API_URL, endpoint, "json")
LOG.info("Requesting %s from reference API ...", url)
Expand Down
46 changes: 44 additions & 2 deletions chi/lease.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,19 @@ def add_node_reservation(self,
node_type: str = None,
node_name: str = None,
nodes: List[Node] = None):
"""
Add a node reservation to the lease.

Parameters:
- amount (int): The number of nodes to reserve.
- node_type (str): The type of nodes to reserve.
- node_name (str): The name of the node to reserve.
- nodes (List[Node]): A list of Node objects to reserve.

Raises:
- CHIValueError: If nodes are specified, no other arguments should be included.

"""
if nodes:
if any([amount, node_type, node_name]):
raise CHIValueError("When specifying nodes, no other arguments should be included")
Expand All @@ -283,13 +295,30 @@ def add_node_reservation(self,
node_name=node_name)

def add_fip_reservation(self, amount: int):
"""
Add a reservation for a floating IP address to the list of FIP reservations.

Args:
amount (int): The number of reservations to add.

Returns:
None
"""
add_fip_reservation(reservation_list=self.fip_reservations,
count=amount)

def add_network_reservation(self,
network_name: str,
usage_type: str = None,
stitch_provider: str = None):
"""
Add a network reservation to the list of network reservations.

Args:
network_name (str): The name of the network to be reserved.
usage_type (str, optional): The type of usage for the network reservation. Defaults to None.
stitch_provider (str, optional): The stitch provider for the network reservation. Defaults to None.
"""
add_network_reservation(reservation_list=self.network_reservations,
network_name=network_name,
usage_type=usage_type,
Expand All @@ -300,6 +329,21 @@ def submit(self,
wait_timeout: int = 300,
show: List[str] = ["widget", "text"],
idempotent: bool = False):
"""
Submits the lease for creation.

Args:
wait_for_active (bool, optional): Whether to wait for the lease to become active. Defaults to True.
wait_timeout (int, optional): The maximum time to wait for the lease to become active, in seconds. Defaults to 300.
show (List[str], optional): The types of lease information to display. Defaults to ["widget", "text"].
idempotent (bool, optional): Whether to create the lease only if it doesn't already exist. Defaults to False.

Raises:
ResourceError: If unable to create the lease.

Returns:
None
"""
if idempotent:
existing_lease = self._get_existing_lease()
if existing_lease:
Expand Down Expand Up @@ -398,11 +442,9 @@ def _show_widget(self):
</ul>
"""


widget = HTML(html_content)
display(widget)


def _show_text(self):
print(f"Lease Details:")
print(f"Name: {self.name}")
Expand Down
Loading