Example #1
0
def onoff_machine(request, system_id):
    form = ConfirmForm(request.POST or None, initial={'system_id': system_id})
    if form.is_valid():
        try:
            cur_machine = maas.get_machines(system_id)
            m = MAAS()
            data = form.clean()
            if cur_machine['power_state'] == 'on':
                resp = m.post(f'machines/{system_id}/?op=power_off', data)
            else:
                resp = m.post(f'machines/{system_id}/?op=power_on', data)
            if resp.status_code in m.ok:
                return JsonResponse({
                    'status':
                    'success',
                    'message':
                    _('Machine Change Power Successfully')
                })

        except (MAASError, ConnectionError, TimeoutError) as e:
            return JsonResponse({'status': 'error', 'message': str(e)})
    context = {
        'form': form,
        'url': reverse('maas:machines:onoff_machine', args=[system_id])
    }
    html = render_to_string('partials/form_core.html', context, request)
    return JsonResponse({'html': html}, safe=False)
Example #2
0
def machine_commission(request, system_id=None):
    form = CommissionForm(request.POST or None,
                          initial={'system_id': system_id})
    if form.is_valid():
        data = form.clean()
        try:
            m = MAAS()
            resp = m.post(f'machines/{system_id}/?op=commission', data=data)
            if resp.status_code in m.ok:
                return JsonResponse({
                    'status': 'success',
                    'message': _('Commission Succesfully')
                })
        except (MAASError, ConnectionError, TimeoutError) as e:
            return JsonResponse({'status': 'error', 'message': str(e)})

    context = {
        'form': form,
        'url': reverse('maas:machines:machine_commission', args=[system_id])
    }

    html = render_to_string('partials/form_core.html',
                            request=request,
                            context=context)
    return JsonResponse({'html': html}, safe=False)
Example #3
0
def delete_machine(request, system_id):
    try:
        m = MAAS()
        resp = m.post(f'machines/{system_id}/', {'system_id': system_id})
        if resp.status_code in m.ok:
            return JsonResponse({
                'status': 'success',
                'message': _('Machine Delete Successfully')
            })
    except (MAASError, ConnectionError, TimeoutError) as e:
        return JsonResponse({'status': 'error', 'message': str(e)})
Example #4
0
def add(request):
    form = SubnetAddForm(request.POST or None)
    if request.method == 'POST' and form.is_valid():
        try:
            m = MAAS()
            data = form.clean()
            resp = m.post('subnets/', data=data)
            if resp.status_code in m.ok:
                sweetify.sweetalert(request, 'Success', text=_('Subnet Added Successfully'), icon='success', timer=2000)
                return redirect('maas:subnets:index')
            sweetify.sweetalert(request, 'Warning', text=_(resp.text), icon='warning', timer=5000)
        except (MAASError, ConnectionError, TimeoutError) as e:
            sweetify.sweetalert(request, 'Error', text=str(e), button='OK', icon='error', timer=5000)
    context = {
        'title': _('Form Add Subnet'),
        'form': form
    }
    return render(request, 'maas/subnets/add.html', context)
Example #5
0
def mark_disconnect(request, system_id, id):
    try:
        m = MAAS()
        resp = m.post(f'nodes/{system_id}/interfaces/{id}/?op=disconnect',
                      data={
                          'system_id': system_id,
                          'id': id
                      })
        if resp.status_code in m.ok:
            return JsonResponse({
                'status':
                'success',
                'message':
                _('Interfaces Disconnected Successfully'),
                'urlhref':
                reverse('maas:machines:index')
            })
        return JsonResponse({'status': 'error', 'message': _(resp.text)})
    except (MAASError, ConnectionError, TimeoutError) as e:
        return JsonResponse({'status': 'error', 'message': _(str(e))})
Example #6
0
def add(request):
    form = forms.SpacesForm(request.POST or None)
    if form.is_valid():
        try:
            data = form.clean()
            m = MAAS()
            resp = m.post('spaces/', data=data)
            if resp.status_code in m.ok:
                sweetify.success(request, _(
                    'Spaces Successfully Added'), timer=2000)
            sweetify.warning(request, _(resp.text), timer=5000)
            return redirect('index')
        except (MAASError, ConnectionError, TimeoutError) as e:
            context = None
            sweetify.sweetalert(request, 'Warning', icon='error', text=str(e), button='Ok', timer=5000)
    context = {
        'title': _('Form Space'),
        'form': form,
    }
    return render(request, 'maas/spaces/add.html', context)
Example #7
0
def add(request):
    form = VlanForm(request.POST or None)

    if form.is_valid():
        try:
            m = MAAS()
            data = form.clean()
            fabId = data['fabric_id']
            resp = m.post(f'fabrics/{fabId}/vlans/', data=data)
            if resp.status_code in m.ok:
                sweetify.success(request, _('Vlan Added Successful'), timer=3000)
                return redirect('maas:subnets:index')
            sweetify.warning(request, _(resp.text), timer=5000)
        except (MAASError, ConnectionError, TimeoutError) as e:
            sweetify.sweetalert(request, 'Warning', icon='error', text=str(e), button='Ok', timer=5000)

    context = {
        'title': _('Add Vlan'),
        'form': form
    }
    return render(request, 'maas/vlans/add.html', context)
Example #8
0
 def save(self):
     cleaned_data = super().clean()
     maas = MAAS()
     return maas.post("domains/", data=cleaned_data)