mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-12 10:08:09 +00:00
Add Onefuzz.container.reset to the SDK (#198)
This commit is contained in:
@ -274,6 +274,29 @@ class Containers(Endpoint):
|
|||||||
self.logger.debug("list containers")
|
self.logger.debug("list containers")
|
||||||
return self._req_model_list("GET", responses.ContainerInfoBase)
|
return self._req_model_list("GET", responses.ContainerInfoBase)
|
||||||
|
|
||||||
|
def reset(
|
||||||
|
self, container_types: Optional[List[enums.ContainerType]] = None
|
||||||
|
) -> None:
|
||||||
|
"""Reset containers unless specified.
|
||||||
|
[Caution]: It can lead to unexpected results.
|
||||||
|
The default conatiners are listed ContainerType.reset_defaults
|
||||||
|
"""
|
||||||
|
if not container_types:
|
||||||
|
container_types = enums.ContainerType.reset_defaults()
|
||||||
|
|
||||||
|
if not container_types:
|
||||||
|
raise Exception("Container type is None")
|
||||||
|
|
||||||
|
for container in self.list():
|
||||||
|
if (
|
||||||
|
container.metadata
|
||||||
|
and "container_type" in container.metadata
|
||||||
|
and enums.ContainerType(container.metadata["container_type"])
|
||||||
|
in container_types
|
||||||
|
):
|
||||||
|
self.logger.info("removing container: %s", container.name)
|
||||||
|
self.delete(container.name)
|
||||||
|
|
||||||
|
|
||||||
class Repro(Endpoint):
|
class Repro(Endpoint):
|
||||||
""" Interact with Reproduction VMs """
|
""" Interact with Reproduction VMs """
|
||||||
@ -1364,25 +1387,7 @@ class Onefuzz:
|
|||||||
self.scalesets.shutdown(scaleset.scaleset_id, now=True)
|
self.scalesets.shutdown(scaleset.scaleset_id, now=True)
|
||||||
|
|
||||||
if containers:
|
if containers:
|
||||||
for container in self.containers.list():
|
self.containers.reset()
|
||||||
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)
|
|
||||||
|
|
||||||
def reset(
|
def reset(
|
||||||
self,
|
self,
|
||||||
|
@ -189,17 +189,31 @@ class Compare(Enum):
|
|||||||
|
|
||||||
|
|
||||||
class ContainerType(Enum):
|
class ContainerType(Enum):
|
||||||
setup = "setup"
|
analysis = "analysis"
|
||||||
|
coverage = "coverage"
|
||||||
crashes = "crashes"
|
crashes = "crashes"
|
||||||
inputs = "inputs"
|
inputs = "inputs"
|
||||||
readonly_inputs = "readonly_inputs"
|
|
||||||
unique_inputs = "unique_inputs"
|
|
||||||
coverage = "coverage"
|
|
||||||
reports = "reports"
|
|
||||||
unique_reports = "unique_reports"
|
|
||||||
no_repro = "no_repro"
|
no_repro = "no_repro"
|
||||||
|
readonly_inputs = "readonly_inputs"
|
||||||
|
reports = "reports"
|
||||||
|
setup = "setup"
|
||||||
tools = "tools"
|
tools = "tools"
|
||||||
analysis = "analysis"
|
unique_inputs = "unique_inputs"
|
||||||
|
unique_reports = "unique_reports"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def reset_defaults(cls) -> List["ContainerType"]:
|
||||||
|
return [
|
||||||
|
cls.analysis,
|
||||||
|
cls.coverage,
|
||||||
|
cls.crashes,
|
||||||
|
cls.inputs,
|
||||||
|
cls.no_repro,
|
||||||
|
cls.readonly_inputs,
|
||||||
|
cls.reports,
|
||||||
|
cls.setup,
|
||||||
|
cls.unique_reports,
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class StatsFormat(Enum):
|
class StatsFormat(Enum):
|
||||||
|
Reference in New Issue
Block a user