def get_redirect_url(self, *args, **kwargs): hostname = self.kwargs['hostname'] minion = self.kwargs['minion'] service = snippet_utils.load_snippet_with_name('delete_single_vm') jinja_context = dict() for v in service['variables']: if self.request.POST.get(v['name']): jinja_context[v['name']] = self.request.POST.get(v['name']) salt_util = salt_utils.SaltUtil() res = salt_util.deploy_service(service, jinja_context) print(res) print('deleting hostname %s' % hostname) return '/mssp/vms'
def form_valid(self, form): print('Here we go deploying') jinja_context = dict() service = snippet_utils.load_snippet_with_name('provision_firewall') for v in service['variables']: if self.request.POST.get(v['name']): jinja_context[v['name']] = self.request.POST.get(v['name']) salt_util = salt_utils.SaltUtil() res = salt_util.deploy_service(service, jinja_context) print(res) context = dict() context['results'] = res return render(self.request, 'mssp/results.html', context=context)
def form_valid(self, form): print('Here we go deploying') jinja_context = dict() service = snippet_utils.load_snippet_with_name(self.snippet) for v in service['variables']: if self.request.POST.get(v['name']): jinja_context[v['name']] = self.request.POST.get(v['name']) minion = self.request.POST.get('minion') salt_util = salt_utils.SaltUtil() res = salt_util.deploy_service(service, jinja_context) context = dict() try: response_obj = json.loads(res) # {"return": [{"compute-01.c.vistoq-demo.internal": {"shoaf1": "shutdown", "stuart1": "shutdown"}}]} fm = response_obj['return'][0] vms = list() if minion in fm: minion_dict = response_obj['return'][0][minion] for m in minion_dict: vm_detail = dict() vm_detail['hostname'] = m vm_detail['status'] = minion_dict[m] vms.append(vm_detail) context['vms'] = vms return render(self.request, 'mssp/deployed_vms.html', context=context) else: context['results'] = response_obj['return'][0] return render(self.request, 'mssp/results.html', context=context) except ValueError as ve: print('Could not parse json') print(ve) context['results'] = {'Error': 'Could not get deployed VMs list!'} return render(self.request, 'mssp/results.html', context=context)
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) salt_util = salt_utils.SaltUtil() minion_list = salt_util.get_minion_list() context['minion_list'] = minion_list return context