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

chore: Deprecate facility in the favor of metro #1971

Merged
merged 5 commits into from
Apr 18, 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
1 change: 1 addition & 0 deletions libcloud/compute/drivers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@
"vcloud",
"vpsnet",
"onapp",
"equinixmetal"
]
25 changes: 19 additions & 6 deletions libcloud/compute/drivers/equinixmetal.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def ex_list_nodes_for_project(self, ex_project_id, include="plan", page=1, per_p
return list(map(self._to_node, data))

def list_locations(self):
data = self.connection.request("/metal/v1/facilities").object["facilities"]
data = self.connection.request("/metal/v1/locations/metros").object["metros"]

return list(map(self._to_location, data))

Expand Down Expand Up @@ -303,12 +303,15 @@ def create_node(
if not ex_project_id:
raise Exception("ex_project_id needs to be specified")

facility = location.extra["code"]
location_code = location.extra["code"]
if not self._valid_location:
raise ValueError("Failed to create node: valid parameter metro [code] is required in the input")

params = {
"hostname": name,
"plan": size.id,
"operating_system": image.id,
"facility": facility,
"metro": location_code,
"include": "plan",
"billing_cycle": "hourly",
}
Expand Down Expand Up @@ -493,6 +496,8 @@ def _to_node(self, data):

if "facility" in data:
extra["facility"] = data["facility"]
if "metro" in data and data["metro"] is not None:
extra["metro"] = data["metro"]

for key in extra_keys:
if key in data:
Expand Down Expand Up @@ -534,8 +539,8 @@ def _to_size(self, data):
except KeyError:
cpus = None
regions = [
region.get("href").replace("/metal/v1/facilities/", "")
for region in data.get("available_in", [])
region.get("href").replace("/metal/v1/locations/metros", "")
for region in data.get("available_in_metros", [])
]
extra = {
"description": data["description"],
Expand Down Expand Up @@ -752,7 +757,7 @@ def ex_request_address_reservation(
}

if location_id:
params["facility"] = location_id
params["metro"] = location_id

if comments:
params["comments"] = comments
Expand Down Expand Up @@ -1055,6 +1060,14 @@ def ex_describe_attachment(self, attachment_id):

return data

def _valid_location(self, metro_code):
if metro_code == None or metro_code == "":
return False
metros = self.connection.request("/metal/v1/locations/metros").object["metros"]
for metro in metros:
if metro["code"] == metro_code:
return True
return False

class Project:
def __init__(self, project):
Expand Down
12 changes: 0 additions & 12 deletions libcloud/test/compute/fixtures/equinixmetal/facilities.json

This file was deleted.

10 changes: 10 additions & 0 deletions libcloud/test/compute/fixtures/equinixmetal/metros.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"metros": [
{
"id": "d3d6b29f-042d-43b7-b3ce-0bf53d5754ca",
"name": "Dallas",
"code": "da",
"country": "US"
}
]
}
5 changes: 2 additions & 3 deletions libcloud/test/compute/test_equinixmetal.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,8 @@ def test_destroy_volume(self):
class EquinixMetalMockHttp(MockHttp):
fixtures = ComputeFileFixtures("equinixmetal")

def _metal_v1_facilities(self, method, url, body, headers):
body = self.fixtures.load("facilities.json")

def _metal_v1_locations_metros(self, method, url, body, headers):
body = self.fixtures.load("metros.json")
return (httplib.OK, body, {}, httplib.responses[httplib.OK])

def _metal_v1_plans(self, method, url, body, headers):
Expand Down
Loading