Skip to content

Commit 1a398ef

Browse files
Make id a required part of BaseInstance (canonical#324)
BaseCloud has a required `get_instance()` method that can return an instance given an instance id, but BaseInstance had no consistent API to retrieve such an instance id. This adds it everywhere.
1 parent de8332a commit 1a398ef

File tree

6 files changed

+29
-1
lines changed

6 files changed

+29
-1
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1!5.6.2
1+
1!5.7.0

pycloudlib/instance.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ def __exit__(self, _type, _value, _traceback):
5252
if exceptions:
5353
raise CleanupError(exceptions)
5454

55+
@property
56+
@abstractmethod
57+
def id(self) -> str:
58+
"""Return instance id."""
59+
raise NotImplementedError
60+
5561
@property
5662
@abstractmethod
5763
def name(self):

pycloudlib/lxd/instance.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
)
1717

1818

19+
# pylint: disable=too-many-public-methods
1920
class LXDInstance(BaseInstance):
2021
"""LXD backed instance."""
2122

@@ -119,6 +120,11 @@ def is_vm(self):
119120

120121
return self._is_vm
121122

123+
@property
124+
def id(self) -> str:
125+
"""Return instance id."""
126+
return self.name
127+
122128
@property
123129
def name(self):
124130
"""Return instance name."""

pycloudlib/oci/instance.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ def __repr__(self):
5858
self.compartment_id,
5959
)
6060

61+
@property
62+
def id(self) -> str:
63+
"""Return instance id."""
64+
return self.instance_id
65+
6166
@property
6267
def name(self):
6368
"""Return the instance name."""

pycloudlib/openstack/instance.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def __init__(
3939
username: username to use when connecting via SSH
4040
"""
4141
super().__init__(key_pair, username=username)
42+
self.instance_id = instance_id
4243

4344
if not connection:
4445
connection = openstack.connect()
@@ -84,6 +85,11 @@ def __repr__(self):
8485
self.__class__.__name__, self.server.id
8586
)
8687

88+
@property
89+
def id(self) -> str:
90+
"""Return instance id."""
91+
return self.instance_id
92+
8793
@property
8894
def name(self):
8995
"""Return instance name."""

pycloudlib/vmware/instance.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ def __init__(self, key_pair: KeyPair, vm_id: str, env: Mapping):
2525
self._ip: Optional[str] = None
2626
self.env = env
2727

28+
@property
29+
def id(self) -> str:
30+
"""Return instance id."""
31+
return self.vm_id
32+
2833
@property
2934
def name(self) -> str:
3035
"""Return VM name."""

0 commit comments

Comments
 (0)