Created
November 18, 2021 10:08
-
-
Save LiamJolly/c0ec1f3798f816d0c8be7fc76fbcca0b to your computer and use it in GitHub Desktop.
03-volumes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_volume(self, name, driver="local", driver_opts=None, labels=None): | |
""" | |
Create a volume | |
:param name: The name of the volume | |
:param driver: The type of driver to use | |
:param driver_opts: Additional options | |
:param labels: Labels for the volume | |
:return: The created Volume | |
""" | |
if driver_opts is None: | |
driver_opts = {} | |
if labels is None: | |
labels = {} | |
return self.client.volumes.create(name=name, driver=driver, driver_opts=driver_opts, labels=labels) | |
def get_volume(self, volume_name) -> Volume: | |
""" | |
Get a volume by name | |
:param volume_name: The volume name to find | |
:return: An instance of the volume | |
""" | |
return self.client.volumes.get(volume_name) | |
def list_volumes(self) -> List[Volume]: | |
""" | |
List all available volumes | |
:return: a list of volumes | |
""" | |
return self.client.volumes.list() | |
def remove_volume(self, volume_name): | |
""" | |
Remove the volume with the given name | |
:param volume_name: The name of the volume to remove | |
""" | |
self.get_volume(volume_name).remove() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment