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

Add Onefuzz.container.reset to the SDK #198

Merged
merged 6 commits into from
Oct 23, 2020
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 56 additions & 19 deletions src/cli/onefuzz/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,61 @@ def list(self) -> List[responses.ContainerInfoBase]:
self.logger.debug("list containers")
return self._req_model_list("GET", responses.ContainerInfoBase)

def reset(
anshuman-goel marked this conversation as resolved.
Show resolved Hide resolved
self,
analysis: bool = False,
coverage: bool = False,
crashes: bool = False,
inputs: bool = False,
no_repro: bool = False,
readonly_inputs: bool = False,
reports: bool = False,
setup: bool = False,
unique_reports: bool = False,
) -> None:
"""Reset all Conatiners unless specified.
[Caution]: It can lead to unexpected results.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bmc-msft The cli is not able to read the lines after first one. Some bug exists over there.


:param bool analysis: Delete only analysis containers.
:param bool coverage: Delete only coverage containers.
:param bool crashes: Delete only crashes containers.
:param bool inputs: Delete only inputs containers.
:param bool no_repro: Delete only no_repro containers.
:param bool readonly_inputs: Delete only readonly_inputs containers.
:param bool reports: Delete only reports containers.
:param bool setup: Delete only setup containers.
:param bool unique_reports: Delete only unique_reports containers.
"""
container_types = {
"analysis": False,
"coverage": False,
"crashes": False,
"inputs": False,
"no_repro": False,
"readonly_inputs": False,
"reports": False,
"setup": False,
"unique_reports": False,
}
for k, v in locals().items():
if k in container_types and v:
container_types[k] = v
if not any(list(container_types.values())):
for k, _ in container_types.items():
container_types[k] = True

container_types = dict(filter(lambda x: x[1], container_types.items()))
delete_container_types = container_types.keys()

for container in self.list():
if (
container.metadata
and "container_type" in container.metadata
and container.metadata["container_type"] in delete_container_types
):
self.logger.info("removing container: %s", container.name)
self.delete(container.name)


class Repro(Endpoint):
""" Interact with Reproduction VMs """
Expand Down Expand Up @@ -1364,25 +1419,7 @@ def _delete_components(
self.scalesets.shutdown(scaleset.scaleset_id, now=True)

if containers:
for container in self.containers.list():
if (
container.metadata
and "container_type" in container.metadata
and container.metadata["container_type"]
in [
"analysis",
"coverage",
"crashes",
"inputs",
"no_repro",
"readonly_inputs",
"reports",
"setup",
"unique_reports",
]
):
self.logger.info("removing container: %s", container.name)
self.containers.delete(container.name)
self.containers.reset()

def reset(
self,
Expand Down