Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
reduce calls to containers.list() (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmc-msft authored Nov 11, 2020
1 parent 3e4b269 commit 7b34cf2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
7 changes: 2 additions & 5 deletions src/cli/onefuzz/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down
12 changes: 4 additions & 8 deletions src/cli/onefuzz/templates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 7b34cf2

Please sign in to comment.