Skip to content

Commit

Permalink
Server 1.0
Browse files Browse the repository at this point in the history
Implemented a redesign of the server module's OOP interfaces

class Server
Fields
reservation_id: str
addresses: {network: [ip,]}
@Property which if an id is set, fetches the latest addresses
created_at: datetime
flavor: str
host_id: str
host_status: str
name: str
hypervisor_hostname: str
id: str
image: Image
is_locked: bool
keypair: Keypair
status
@Property which if an id is set, fetches the latest status
__init__(
	name: str,
	reservation_id: str,
	image_name=”CC-Ubuntu-22.04” : str,
	image: Image,
	flavor_name=”baremetal” : str,
	key_name=”$USER-jupyterhub”,
	keypair: Keypair,
	network_name=”sharednet1”,
)
Args
name - the name of the instance
reservation_id - the uuid of the host reservation to draw this instance on. Can be obtained via my_lease.node_reservations[0][“id”]
image_name the name of the image to boot
image - Image object optionally given instead of image_name.
flavor_name - the name of the flavor
key_name - the keypair to use for this instance
keypair - Keypair object optionally given instead of key_name
network_name - the network to launch this server on.

submit(
	count=1,
	wait_for_active: bool = True, #
	wait_timeout: seconds,
	show=[”widget”, “text”].
	idempotent=False,
) -> [Server]
Args:
count - The number of servers to create with these details.
wait_for_active - If true, this method will block until the lease is in an active state.
wait_timeout - how many seconds to wait until a timeout.
idempotent - If true, first try to get a server with the same name. If one does not exist, run submit as normal.
Submits this server object to be created.  If count is greater than 1, several servers will be created, and the list of Server objects will be returned, instead of self being modified in place.
Implementation: This should cache the details for the server in the fields.
delete() -> None
wait(status=”active” : str) -> None
Waits until the server is a given status
show(
	type=[“text”, “widget”] : str,
	wait_for_active : bool,
) -> None
Displays this server in the format specified by the user. Either a textual representation printed to stdout or as a widget table. If wait_for_active and type=widget, then the widget representation will display immediately, and update once the server status changes. If wait_for_active and type=text, displays once server is active.
check_connectivity(
	wait=True : bool,
	port=22 : int,
	timeout=500 : int,
	type=[“widget”, “text”]: str
) -> bool
Args
wait - Whether to wait for connectivity, or check once
port - the port to check on
timeout - how many seconds to wait for
type - The type of output to display. Will output a timer showing how long this function has waited for. If set to None, displays nothing.
Periodically checks that the given port is open, and returns true if a TCP connection can be made to it.
associate_floating_ip(fip=None : str)
args:
fip the fip to associate to this instance, which must be allocated to the project. If none, will allocate a new IP to the project, and associate that. Can be gotten from a lease via my_lease.fip_reservations[0][“address”]
Associates a fip to the server.
detach_floating_ip(fip : str)
args
fip the fip to detach from this server.
ssh_connection()
Returns a Fabric Connection object that may be used to run SSH commands.
upload(
	file : str,
	remote_path=”” : str,
)
Uploads the file or directory specified to the remote path
execute(command: str)
Runs a command over SSH on the node.
list_servers() -> [Server]
Returns all servers in the current project
get_server(name) -> Server
Gets the a server with the given name.
class Flavor
Fields
disk: int
ram: int
vcpus: int
name: str
get_flavors() -> [Flavor]
Gets a list of all flavors
  • Loading branch information
JOUNAIDSoufiane committed Aug 1, 2024
1 parent c259d02 commit ccc71f0
Show file tree
Hide file tree
Showing 2 changed files with 485 additions and 194 deletions.
44 changes: 44 additions & 0 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
Loading

0 comments on commit ccc71f0

Please sign in to comment.