Merge pull request #1294 from Can-eh-dian11/develop
ability to bulk delete using client and site
This commit is contained in:
@@ -10,7 +10,7 @@ from tacticalrmm.utils import reload_nats
|
|||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
help = "Delete old agents"
|
help = "Delete multiple agents based on criteria"
|
||||||
|
|
||||||
def add_arguments(self, parser):
|
def add_arguments(self, parser):
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
@@ -23,6 +23,16 @@ class Command(BaseCommand):
|
|||||||
type=str,
|
type=str,
|
||||||
help="Delete agents that equal to or less than this version",
|
help="Delete agents that equal to or less than this version",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--site",
|
||||||
|
type=str,
|
||||||
|
help="Delete agents that belong to the specified site",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--client",
|
||||||
|
type=str,
|
||||||
|
help="Delete agents that belong to the specified client",
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--delete",
|
"--delete",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
@@ -32,11 +42,15 @@ class Command(BaseCommand):
|
|||||||
def handle(self, *args, **kwargs):
|
def handle(self, *args, **kwargs):
|
||||||
days = kwargs["days"]
|
days = kwargs["days"]
|
||||||
agentver = kwargs["agentver"]
|
agentver = kwargs["agentver"]
|
||||||
|
site = kwargs["site"]
|
||||||
|
client = kwargs["client"]
|
||||||
delete = kwargs["delete"]
|
delete = kwargs["delete"]
|
||||||
|
|
||||||
if not days and not agentver:
|
if not days and not agentver and not site and not client:
|
||||||
self.stdout.write(
|
self.stdout.write(
|
||||||
self.style.ERROR("Must have at least one parameter: days or agentver")
|
self.style.ERROR(
|
||||||
|
"Must have at least one parameter: days, agentver, site, or client"
|
||||||
|
)
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -50,6 +64,12 @@ class Command(BaseCommand):
|
|||||||
if agentver:
|
if agentver:
|
||||||
agents = [i for i in q if pyver.parse(i.version) <= pyver.parse(agentver)]
|
agents = [i for i in q if pyver.parse(i.version) <= pyver.parse(agentver)]
|
||||||
|
|
||||||
|
if site:
|
||||||
|
agents = [i for i in q if i.site.name == site]
|
||||||
|
|
||||||
|
if client:
|
||||||
|
agents = [i for i in q if i.client.name == client]
|
||||||
|
|
||||||
if not agents:
|
if not agents:
|
||||||
self.stdout.write(self.style.ERROR("No agents matched"))
|
self.stdout.write(self.style.ERROR("No agents matched"))
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user