Пример #1
0
    def delete_images(self):
        # [START list_repository_names]
        audience = "https://management.azure.com"
        account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]
        credential = DefaultAzureCredential()
        client = ContainerRegistryClient(account_url,
                                         credential,
                                         audience=audience)

        for repository in client.list_repository_names():
            print(repository)
            # [END list_repository_names]

            # [START list_manifest_properties]
            # Keep the three most recent images, delete everything else
            manifest_count = 0
            for manifest in client.list_manifest_properties(
                    repository,
                    order_by=ManifestOrder.LAST_UPDATE_TIME_DESCENDING):
                manifest_count += 1
                if manifest_count > 3:
                    client.delete_manifest(repository, manifest.digest)
            # [END list_manifest_properties]

        client.close()
Пример #2
0
    def delete_old_tags(self):
        from azure.containerregistry import (
            ContainerRegistryClient,
            ContainerRepositoryClient,
            TagOrder
        )
        from azure.identity import DefaultAzureCredential

        # [START list_repository_names]
        account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]
        credential = DefaultAzureCredential()
        client = ContainerRegistryClient(account_url, credential)

        for repository in client.list_repository_names():
            repository_client = ContainerRepositoryClient(account_url, repository, credential)
            # [END list_repository_names]

            # [START list_tags]
            tag_count = 0
            for tag in repository_client.list_tags(order_by=TagOrder.LAST_UPDATE_TIME_DESCENDING):
                tag_count += 1
                if tag_count > 3:
                    repository_client.delete_tag(tag.name)
            # [END list_tags]

        client.close()
Пример #3
0
    def basic_sample(self):
        # Instantiate the client
        account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]
        audience = "https://management.azure.com"
        client = ContainerRegistryClient(account_url,
                                         DefaultAzureCredential(),
                                         audience=audience)
        with client:
            # Iterate through all the repositories
            for repository_name in client.list_repository_names():
                if repository_name == "hello-world":
                    for tag in client.list_tag_properties(repository_name):
                        print(tag.digest)

                    # [START delete_repository]
                    client.delete_repository(repository_name, tag.name)
Пример #4
0
    def basic_sample(self):

        from azure.containerregistry import ContainerRegistryClient
        from azure.identity import DefaultAzureCredential

        account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]

        # Instantiate the client
        client = ContainerRegistryClient(account_url, DefaultAzureCredential())
        with client:
            # Iterate through all the repositories
            for repository_name in client.list_repository_names():
                if repository_name == "hello-world":
                    for tag in client.list_tag_properties(repository_name):
                        print(tag.digest)

                    # [START delete_repository]
                    client.delete_repository(repository_name, tag.name)
Пример #5
0
class ListRepositoriesTest(PerfStressTest):

    def __init__(self, arguments):
        super().__init__(arguments)

        account_url = self.get_from_env("CONTAINERREGISTRY_ANONREGISTRY_ENDPOINT")
        audience = "https://management.azure.com"
        self.anon_client = ContainerRegistryClient(endpoint=account_url, credential=None, audience=audience)
        self.async_anon_client = AsyncContainerRegistryClient(endpoint=account_url, credential=None, audience=audience)

    async def close(self):
        await self.async_anon_client.close()
        await super().close()

    def run_sync(self):
        for _ in self.anon_client.list_repository_names():
            pass

    async def run_async(self):
        async for _ in self.async_anon_client.list_repository_names():
            pass
    def basic_sample(self):

        from azure.containerregistry import ContainerRegistryClient
        from azure.identity import DefaultAzureCredential

        # Instantiate the client
        client = ContainerRegistryClient(self.account_url, DefaultAzureCredential())
        with client:
            # Iterate through all the repositories
            for repository_name in client.list_repository_names():
                if repository_name == "hello-world":
                    # Create a repository client from the registry client
                    repository_client = client.get_repository(repository_name)

                    with repository_client:
                        # Show all tags
                        for tag in repository_client.list_tags():
                            print(tag.digest)

                    # [START delete_repository]
                    client.delete_repository("hello-world")
    def basic_sample(self):

        from azure.containerregistry import ContainerRegistryClient
        from azure.identity import DefaultAzureCredential
        account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]

        # Instantiate the client
        client = ContainerRegistryClient(account_url, DefaultAzureCredential())
        with client:
            # Iterate through all the repositories
            for repository_name in client.list_repository_names():
                if repository_name == "hello-world":
                    # Create a repository object from the registry client
                    container_repository = client.get_repository(
                        repository_name)

                    with container_repository:
                        # Show all tags
                        for manifest in container_repository.list_manifests():
                            print(manifest.tags)

                    # [START delete_repository]
                    client.delete_repository("hello-world")
    def delete_old_tags(self):
        from azure.containerregistry import ContainerRegistryClient, TagOrder
        from azure.identity import DefaultAzureCredential

        # [START list_repository_names]
        account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]
        credential = DefaultAzureCredential()
        client = ContainerRegistryClient(account_url, credential)

        for repository in client.list_repository_names():
            print(repository)
            # [END list_repository_names]

            # [START list_tag_properties]
            # Keep the three most recent tags, delete everything else
            tag_count = 0
            tags = client.list_tag_properties(
                repository, order_by=TagOrder.LAST_UPDATE_TIME_DESCENDING)
            for tag in tags[3:]:
                client.delete_tag(repository, tag.name)
            # [END list_tag_properties]

        client.close()