Skip to content

Commit ea215b8

Browse files
Deprecate facility in the favor of metro
Signed-off-by: Ayush Rangwala <ayush.rangwala@gmail.com>
1 parent dfbb595 commit ea215b8

File tree

5 files changed

+33
-37
lines changed

5 files changed

+33
-37
lines changed

libcloud/compute/drivers/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@
3333
"vcloud",
3434
"vpsnet",
3535
"onapp",
36+
"equinixmetal"
3637
]

libcloud/compute/drivers/equinixmetal.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def ex_list_nodes_for_project(self, ex_project_id, include="plan", page=1, per_p
238238
return list(map(self._to_node, data))
239239

240240
def list_locations(self):
241-
data = self.connection.request("/metal/v1/facilities").object["facilities"]
241+
data = self.connection.request("/metal/v1/locations/metros").object["metros"]
242242
return list(map(self._to_location, data))
243243

244244
def list_images(self):
@@ -285,12 +285,15 @@ def create_node(
285285
if not ex_project_id:
286286
raise Exception("ex_project_id needs to be specified")
287287

288-
facility = location.extra["code"]
288+
location_code = location.extra["code"]
289+
if not self._valid_location:
290+
raise ValueError("Failed to create node: valid parameter metro [code] is required in the input")
291+
289292
params = {
290293
"hostname": name,
291294
"plan": size.id,
292295
"operating_system": image.id,
293-
"facility": facility,
296+
"metro": location_code,
294297
"include": "plan",
295298
"billing_cycle": "hourly",
296299
}
@@ -453,6 +456,8 @@ def _to_node(self, data):
453456
size = None
454457
if "facility" in data:
455458
extra["facility"] = data["facility"]
459+
if "metro" in data and data["metro"] is not None:
460+
extra["metro"] = data["metro"]
456461

457462
for key in extra_keys:
458463
if key in data:
@@ -491,8 +496,8 @@ def _to_size(self, data):
491496
except KeyError:
492497
cpus = None
493498
regions = [
494-
region.get("href").replace("/metal/v1/facilities/", "")
495-
for region in data.get("available_in", [])
499+
region.get("href").replace("/metal/v1/locations/metros", "")
500+
for region in data.get("available_in_metros", [])
496501
]
497502
extra = {
498503
"description": data["description"],
@@ -675,7 +680,7 @@ def ex_request_address_reservation(
675680
"quantity": quantity,
676681
}
677682
if location_id:
678-
params["facility"] = location_id
683+
params["metro"] = location_id
679684
if comments:
680685
params["comments"] = comments
681686
if customdata:
@@ -746,10 +751,8 @@ def create_volume(
746751
):
747752
"""
748753
Create a new volume.
749-
750754
:param size: Size of volume in gigabytes (required)
751755
:type size: ``int``
752-
753756
:param location: Which data center to create a volume in. If
754757
empty, undefined behavior will be selected.
755758
(optional)
@@ -778,10 +781,8 @@ def create_volume(
778781
def destroy_volume(self, volume):
779782
"""
780783
Destroys a storage volume.
781-
782784
:param volume: Volume to be destroyed
783785
:type volume: :class:`StorageVolume`
784-
785786
:rtype: ``bool``
786787
"""
787788
path = "/metal/v1/storage/%s" % volume.id
@@ -791,13 +792,10 @@ def destroy_volume(self, volume):
791792
def attach_volume(self, node, volume):
792793
"""
793794
Attaches volume to node.
794-
795795
:param node: Node to attach volume to.
796796
:type node: :class:`.Node`
797-
798797
:param volume: Volume to attach.
799798
:type volume: :class:`.StorageVolume`
800-
801799
:rytpe: ``bool``
802800
"""
803801
path = "/metal/v1/storage/%s/attachments" % volume.id
@@ -808,14 +806,11 @@ def attach_volume(self, node, volume):
808806
def detach_volume(self, volume, ex_node=None, ex_attachment_id=""):
809807
"""
810808
Detaches a volume from a node.
811-
812809
:param volume: Volume to be detached
813810
:type volume: :class:`.StorageVolume`
814-
815811
:param ex_attachment_id: Attachment id to be detached, if empty detach
816812
all attachments
817813
:type name: ``str``
818-
819814
:rtype: ``bool``
820815
"""
821816
path = "/metal/v1/storage/%s/attachments" % volume.id
@@ -841,10 +836,8 @@ def detach_volume(self, volume, ex_node=None, ex_attachment_id=""):
841836
def create_volume_snapshot(self, volume, name=""):
842837
"""
843838
Create a new volume snapshot.
844-
845839
:param volume: Volume to create a snapshot for
846840
:type volume: class:`StorageVolume`
847-
848841
:return: The newly created volume snapshot.
849842
:rtype: :class:`VolumeSnapshot`
850843
"""
@@ -856,10 +849,8 @@ def create_volume_snapshot(self, volume, name=""):
856849
def destroy_volume_snapshot(self, snapshot):
857850
"""
858851
Delete a volume snapshot
859-
860852
:param snapshot: volume snapshot to delete
861853
:type snapshot: class:`VolumeSnapshot`
862-
863854
:rtype: ``bool``
864855
"""
865856
volume_id = snapshot.extra["volume"]["href"].split("/")[-1]
@@ -870,10 +861,8 @@ def destroy_volume_snapshot(self, snapshot):
870861
def list_volume_snapshots(self, volume, include=""):
871862
"""
872863
List snapshots for a volume.
873-
874864
:param volume: Volume to list snapshots for
875865
:type volume: class:`StorageVolume`
876-
877866
:return: List of volume snapshots.
878867
:rtype: ``list`` of :class: `VolumeSnapshot`
879868
"""
@@ -885,7 +874,7 @@ def list_volume_snapshots(self, volume, include=""):
885874
return list(map(self._to_volume_snapshot, data))
886875

887876
def _to_volume_snapshot(self, data):
888-
created = datetime.datetime.strptime(data["created_at"], "%Y-%m-%dT%H:%M:%S")
877+
created = datetime.strptime(data["created_at"], "%Y-%m-%dT%H:%M:%S")
889878
return VolumeSnapshot(
890879
id=data["id"],
891880
name=data["id"],
@@ -941,6 +930,14 @@ def ex_describe_attachment(self, attachment_id):
941930
data = self.connection.request(path).object
942931
return data
943932

933+
def _valid_location(self, metro_code):
934+
if metro_code == None or metro_code == "":
935+
return False
936+
metros = self.connection.request("/metal/v1/locations/metros").object["metros"]
937+
for metro in metros:
938+
if metro["code"] == metro_code:
939+
return True
940+
return False
944941

945942
class Project:
946943
def __init__(self, project):

libcloud/test/compute/fixtures/equinixmetal/facilities.json

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"metros": [
3+
{
4+
"id": "d3d6b29f-042d-43b7-b3ce-0bf53d5754ca",
5+
"name": "Dallas",
6+
"code": "da",
7+
"country": "US"
8+
}
9+
]
10+
}

libcloud/test/compute/test_equinixmetal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ def test_destroy_volume(self):
303303
class EquinixMetalMockHttp(MockHttp):
304304
fixtures = ComputeFileFixtures("equinixmetal")
305305

306-
def _metal_v1_facilities(self, method, url, body, headers):
307-
body = self.fixtures.load("facilities.json")
306+
def _metal_v1_metros(self, method, url, body, headers):
307+
body = self.fixtures.load("metros.json")
308308
return (httplib.OK, body, {}, httplib.responses[httplib.OK])
309309

310310
def _metal_v1_plans(self, method, url, body, headers):

0 commit comments

Comments
 (0)