Skip to content

Commit 8230a5e

Browse files
authored
Implement Suspend() command for instances (#524)
1 parent f01cb67 commit 8230a5e

File tree

1 file changed

+20
-0
lines changed
  • libcloudforensics/providers/gcp/internal

1 file changed

+20
-0
lines changed

libcloudforensics/providers/gcp/internal/compute.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,6 +1794,26 @@ def GetPowerState(self) -> str:
17941794
"""
17951795
return str(self.GetOperation()['status'])
17961796

1797+
def Suspend(self) -> None:
1798+
"""
1799+
Suspends the instance.
1800+
1801+
Raises:
1802+
errors.InstanceStateChangeError: If the Suspend operation is unsuccessful
1803+
"""
1804+
1805+
logger.info('Suspending instance "{0:s}"'.format(self.name))
1806+
try:
1807+
gce_instance_client = self.GceApi().instances() # pylint: disable=no-member
1808+
request = gce_instance_client.suspend(
1809+
project=self.project_id, instance=self.name, zone=self.zone)
1810+
response = request.execute()
1811+
self.BlockOperation(response, zone=self.zone)
1812+
except HttpError as exception:
1813+
raise errors.InstanceStateChangeError(
1814+
'Could not suspend instance: {0:s}'.format(str(exception)), __name__)
1815+
1816+
17971817
def Stop(self) -> None:
17981818
"""
17991819
Stops the instance.

0 commit comments

Comments
 (0)