Exemplo n.º 1
0
class ListArtifactsTest(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)
        self.repository = "node"

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

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

    async def run_async(self):
        async for _ in self.async_anon_client.list_manifest_properties(
                self.repository):
            pass
Exemplo n.º 2
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()