From 7b34cf23f271b949e50908bb6f7a359c445d1275 Mon Sep 17 00:00:00 2001 From: bmc-msft <41130664+bmc-msft@users.noreply.github.com> Date: Wed, 11 Nov 2020 12:18:14 -0500 Subject: [PATCH] reduce calls to containers.list() (#289) --- src/cli/onefuzz/template.py | 7 ++----- src/cli/onefuzz/templates/__init__.py | 12 ++++-------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/cli/onefuzz/template.py b/src/cli/onefuzz/template.py index 95f651ea62..d35aef4547 100644 --- a/src/cli/onefuzz/template.py +++ b/src/cli/onefuzz/template.py @@ -51,7 +51,6 @@ def stop( msg.append("build:%s" % build) self.logger.info("stopping %s" % " ".join(msg)) - containers = [x.name for x in self.onefuzz.containers.list()] jobs = self.onefuzz.jobs.list() for job in jobs: if job.config.project != project: @@ -81,10 +80,8 @@ def stop( continue to_remove.append(container.name) for container_name in to_remove: - if container_name in containers: - self.logger.info("removing container: %s", container_name) - self.onefuzz.containers.delete(container_name) - containers.remove(container_name) + if self.onefuzz.containers.delete(container_name).result: + self.logger.info("removed container: %s", container_name) if stop_notifications: notifications = self.onefuzz.notifications.list() diff --git a/src/cli/onefuzz/templates/__init__.py b/src/cli/onefuzz/templates/__init__.py index 3107aa1f8a..257c71be7f 100644 --- a/src/cli/onefuzz/templates/__init__.py +++ b/src/cli/onefuzz/templates/__init__.py @@ -99,15 +99,11 @@ def define_containers(self, *types: ContainerType) -> None: ) def create_containers(self) -> None: - all_containers = [x.name for x in self.onefuzz.containers.list()] for (container_type, container_name) in self.containers.items(): - if container_name in all_containers: - self.logger.info("using container: %s", container_name) - else: - self.logger.info("creating container: %s", container_name) - self.onefuzz.containers.create( - container_name, metadata={"container_type": container_type.name} - ) + self.logger.info("using container: %s", container_name) + self.onefuzz.containers.create( + container_name, metadata={"container_type": container_type.name} + ) def setup_notifications(self, config: Optional[NotificationConfig]) -> None: if not config: