in libcloud/compute/drivers/equinixmetal.py [0:0]
def _to_size(self, data):
try:
cpus = data["specs"]["cpus"][0].get("count")
except KeyError:
cpus = None
regions = [
region.get("href").replace("/metal/v1/locations/metros", "")
for region in data.get("available_in_metros", [])
]
extra = {
"description": data["description"],
"line": data["line"],
"cpus": cpus,
"regions": regions,
}
try:
factor = 1
ram_txt = data["specs"]["memory"]["total"]
if "GB" in ram_txt:
factor = 1024
ram_txt = ram_txt.replace("GB", "")
elif "TB" in ram_txt:
factor = 1024 * 1024
ram_txt = ram_txt.replace("TB", "")
ram = int(ram_txt) * factor
except Exception:
ram = None
disk = None
if data["specs"].get("drives", ""):
disk = 0
for disks in data["specs"]["drives"]:
disk_size = disks["size"].replace("GB", "")
if "TB" in disk_size:
disk_size = float(disks["size"].replace("TB", "")) * 1000
disk += disks["count"] * int(disk_size)
name = "{} - {} RAM".format(data.get("name"), ram)
price = data["pricing"].get("hour")
return NodeSize(
id=data["slug"],
name=name,
ram=ram,
disk=disk,
bandwidth=0,
price=price,
extra=extra,
driver=self,
)