Skip to content
Open
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
192 changes: 33 additions & 159 deletions datacrunch/instance_types/instance_types.py
Original file line number Diff line number Diff line change
@@ -1,164 +1,38 @@
INSTANCE_TYPES_ENDPOINT = '/instance-types'


class InstanceType:
"""Instance type."""

def __init__(
self,
id: str,
instance_type: str,
price_per_hour: float,
spot_price_per_hour: float,
description: str,
cpu: dict,
gpu: dict,
memory: dict,
gpu_memory: dict,
storage: dict,
) -> None:
"""Initialize an instance type object.

:param id: instance type id
:type id: str
:param instance_type: instance type. e.g. '8V100.48M'
:type instance_type: str
:param price_per_hour: price per hour
:type price_per_hour: float
:param spot_price_per_hour: spot price per hour
:type spot_price_per_hour: float
:param description: instance type description
:type description: str
:param cpu: cpu details
:type cpu: dict
:param gpu: gpu details
:type gpu: dict
:param memory: memory details
:type memory: dict
:param gpu_memory: gpu memory details
:type gpu_memory: dict
:param storage: storage details
:type storage: dict
"""
self._id = id
self._instance_type = instance_type
self._price_per_hour = float(price_per_hour)
self._spot_price_per_hour = float(spot_price_per_hour)
self._description = description
self._cpu = cpu
self._gpu = gpu
self._memory = memory
self._gpu_memory = gpu_memory
self._storage = storage

@property
def id(self) -> str:
"""Get the instance type id.

:return: instance type id
:rtype: str
"""
return self._id

@property
def instance_type(self) -> str:
"""Get the instance type.

:return: instance type. e.g. '8V100.48M'
:rtype: str
"""
return self._instance_type

@property
def price_per_hour(self) -> float:
"""Get the instance type price per hour.

:return: price per hour
:rtype: float
"""
return self._price_per_hour

@property
def spot_price_per_hour(self) -> float:
"""Get the instance spot price per hour.

:return: spot price per hour
:rtype: float
"""
return self._spot_price_per_hour
from dataclasses import dataclass

@property
def description(self) -> str:
"""Get the instance type description.
from dataclasses_json import dataclass_json

:return: instance type description
:rtype: str
"""
return self._description

@property
def cpu(self) -> dict:
"""Get the instance type cpu details.

:return: cpu details
:rtype: dict
"""
return self._cpu

@property
def gpu(self) -> dict:
"""Get the instance type gpu details.

:return: gpu details
:rtype: dict
"""
return self._gpu

@property
def memory(self) -> dict:
"""Get the instance type memory details.

:return: memory details
:rtype: dict
"""
return self._memory

@property
def gpu_memory(self) -> dict:
"""Get the instance type gpu_memory details.

:return: gpu_memory details
:rtype: dict
"""
return self._gpu_memory

@property
def storage(self) -> dict:
"""Get the instance type storage details.

:return: storage details
:rtype: dict
"""
return self._storage
INSTANCE_TYPES_ENDPOINT = '/instance-types'

def __str__(self) -> str:
"""Prints the instance type.

:return: instance type string representation
:rtype: str
"""
return (
f'id: {self._id}\n'
f'instance type: {self._instance_type}\n'
f'price_per_hour: ${self._price_per_hour}\n'
f'spot_price_per_hour: ${self._spot_price_per_hour}\n'
f'description: {self._description}\n'
f'cpu: {self._cpu}\n'
f'gpu: {self._gpu}\n'
f'memory :{self._memory}\n'
f'gpu_memory :{self._gpu_memory}\n'
f'storage :{self._storage}\n'
)
@dataclass_json
@dataclass
class InstanceType:
"""Instance type.

Attributes:
id: instance type id.
instance_type: instance type, e.g. '8V100.48M'.
price_per_hour: instance type price per hour.
spot_price_per_hour: instance type spot price per hour.
description: instance type description.
cpu: instance type cpu details.
gpu: instance type gpu details.
memory: instance type memory details.
gpu_memory: instance type gpu memory details.
storage: instance type storage details.
"""

id: str
instance_type: str
price_per_hour: float
spot_price_per_hour: float
description: str
cpu: dict
gpu: dict
memory: dict
gpu_memory: dict
storage: dict


class InstanceTypesService:
Expand All @@ -178,8 +52,8 @@ def get(self) -> list[InstanceType]:
InstanceType(
id=instance_type['id'],
instance_type=instance_type['instance_type'],
price_per_hour=instance_type['price_per_hour'],
spot_price_per_hour=instance_type['spot_price'],
price_per_hour=float(instance_type['price_per_hour']),
spot_price_per_hour=float(instance_type['spot_price']),
description=instance_type['description'],
cpu=instance_type['cpu'],
gpu=instance_type['gpu'],
Expand Down