populate the db with initial chocolately software during installation
This commit is contained in:
parent
dcf0f58c88
commit
7d2f0dd8a7
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,17 @@
|
|||
import json
|
||||
import os
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.conf import settings
|
||||
|
||||
from software.models import ChocoSoftware
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Populates database with initial software"
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
with open(os.path.join(settings.BASE_DIR, "software/chocos.json")) as f:
|
||||
chocos = json.load(f)
|
||||
|
||||
ChocoSoftware(chocos=chocos).save()
|
||||
self.stdout.write("Chocos saved to db")
|
|
@ -19,6 +19,26 @@ class ChocoSoftware(models.Model):
|
|||
]
|
||||
biggest = max(range(len(sizes)), key=lambda index: sizes[index]["size"])
|
||||
return int(sizes[biggest]["pk"])
|
||||
|
||||
@classmethod
|
||||
def combine_all(cls):
|
||||
from .serializers import ChocoSoftwareSerializer
|
||||
|
||||
chocos = cls.objects.all()
|
||||
combined = []
|
||||
for i in chocos:
|
||||
combined.extend(ChocoSoftwareSerializer(i).data["chocos"])
|
||||
|
||||
# remove duplicates
|
||||
return [dict(t) for t in {tuple(d.items()) for d in combined}]
|
||||
|
||||
def __str__(self):
|
||||
from .serializers import ChocoSoftwareSerializer
|
||||
|
||||
return str(len(ChocoSoftwareSerializer(self).data["chocos"])) + f" - {self.added}"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class ChocoLog(models.Model):
|
||||
|
|
|
@ -62,12 +62,7 @@ def update_chocos():
|
|||
continue
|
||||
else:
|
||||
if data:
|
||||
install = agent.salt_api_cmd(
|
||||
hostname=agent.salt_id,
|
||||
timeout=180,
|
||||
func="chocolatey.bootstrap",
|
||||
arg="force=True",
|
||||
)
|
||||
|
||||
resp = agent.salt_api_cmd(
|
||||
hostname=agent.salt_id, timeout=200, func="chocolatey.list"
|
||||
)
|
||||
|
|
|
@ -18,9 +18,7 @@ from .tasks import install_program
|
|||
|
||||
@api_view()
|
||||
def chocos(request):
|
||||
pk = ChocoSoftware.sort_by_highest()
|
||||
choco = ChocoSoftware.objects.get(pk=pk)
|
||||
return Response(ChocoSoftwareSerializer(choco).data)
|
||||
return Response(ChocoSoftware.combine_all())
|
||||
|
||||
|
||||
@api_view(["POST"])
|
||||
|
|
|
@ -225,6 +225,7 @@ pip install --upgrade pip
|
|||
pip install -r /home/${USER}/rmm/api/tacticalrmm/requirements.txt
|
||||
python manage.py migrate
|
||||
python manage.py collectstatic
|
||||
python manage.py load_chocos
|
||||
printf >&2 "${YELLOW}%0.s*${NC}" {1..80}
|
||||
printf >&2 "\n"
|
||||
printf >&2 "${YELLOW}Please create your login for the RMM website and django admin${NC}\n"
|
||||
|
|
|
@ -86,7 +86,7 @@ export default {
|
|||
methods: {
|
||||
getChocos() {
|
||||
axios.get("/software/chocos/").then(r => {
|
||||
this.chocos = r.data.chocos;
|
||||
this.chocos = r.data;
|
||||
});
|
||||
},
|
||||
showDescription(name) {
|
||||
|
|
Loading…
Reference in New Issue