diff --git a/libcloud/compute/drivers/__init__.py b/libcloud/compute/drivers/__init__.py index 90dc411d5b..39aa15df7c 100644 --- a/libcloud/compute/drivers/__init__.py +++ b/libcloud/compute/drivers/__init__.py @@ -33,4 +33,5 @@ "vcloud", "vpsnet", "onapp", + "equinixmetal" ] diff --git a/libcloud/compute/drivers/equinixmetal.py b/libcloud/compute/drivers/equinixmetal.py index 9458d256cf..7ea78271b7 100644 --- a/libcloud/compute/drivers/equinixmetal.py +++ b/libcloud/compute/drivers/equinixmetal.py @@ -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)) @@ -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", } @@ -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: @@ -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"], @@ -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 @@ -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): diff --git a/libcloud/test/compute/fixtures/equinixmetal/facilities.json b/libcloud/test/compute/fixtures/equinixmetal/facilities.json deleted file mode 100644 index 4b0014c4eb..0000000000 --- a/libcloud/test/compute/fixtures/equinixmetal/facilities.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "facilities": [ - { - "id": "e1e9c52e-a0bc-4117-b996-0fc94843ea09", - "name": "Parsippany, NJ", - "code": "ewr1", - "features": ["baremetal"], - "address": null, - "href": "/facilities/e1e9c52e-a0bc-4117-b996-0fc94843ea09" - } - ] -} diff --git a/libcloud/test/compute/fixtures/equinixmetal/metros.json b/libcloud/test/compute/fixtures/equinixmetal/metros.json new file mode 100644 index 0000000000..a2fa6c804d --- /dev/null +++ b/libcloud/test/compute/fixtures/equinixmetal/metros.json @@ -0,0 +1,10 @@ +{ + "metros": [ + { + "id": "d3d6b29f-042d-43b7-b3ce-0bf53d5754ca", + "name": "Dallas", + "code": "da", + "country": "US" + } + ] +} diff --git a/libcloud/test/compute/test_equinixmetal.py b/libcloud/test/compute/test_equinixmetal.py index 9c7f3b9288..2ce0132e69 100644 --- a/libcloud/test/compute/test_equinixmetal.py +++ b/libcloud/test/compute/test_equinixmetal.py @@ -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):