~lamont/maas/bug-1599223-2.0

« back to all changes in this revision

Viewing changes to src/maasserver/api/machines.py

  • Committer: LaMont Jones
  • Date: 2016-05-12 19:07:37 UTC
  • mfrom: (5017 maas)
  • mto: This revision was merged to the branch mainline in revision 5021.
  • Revision ID: lamont@canonical.com-20160512190737-00g34satnuo0tk8v
mergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
    StorageLayoutForm,
78
78
    StorageLayoutMissingBootDiskError,
79
79
)
80
 
from maasserver.utils.orm import get_first
 
80
from maasserver.utils.orm import (
 
81
    get_first,
 
82
    reload_object,
 
83
)
81
84
import yaml
82
85
 
83
86
# Machine's fields exposed on the API.
420
423
        Note: This will clear the current storage layout and any extra
421
424
        configuration and replace it will the new layout.
422
425
 
423
 
        :param storage_layout: Storage layout for the machine. (flat, lvm
 
426
        :param storage_layout: Storage layout for the machine. (flat, lvm,
424
427
            and bcache)
425
428
 
426
429
        The following are optional for all layouts:
583
586
            content_type='text/plain')
584
587
 
585
588
    @operation(idempotent=False)
 
589
    def restore_networking_configuration(self, request, system_id):
 
590
        """Reset a machine's networking options to its initial state.
 
591
 
 
592
        Returns 404 if the machine is not found.
 
593
        Returns 403 if the user does not have permission to reset the machine.
 
594
        """
 
595
        machine = self.model.objects.get_node_or_404(
 
596
            system_id=system_id, user=request.user,
 
597
            perm=NODE_PERMISSION.ADMIN)
 
598
        if machine.status != NODE_STATUS.READY:
 
599
            raise NodeStateViolation(
 
600
                "Machine must be in a ready state to restore networking "
 
601
                "configuration")
 
602
        machine.set_initial_networking_configuration()
 
603
        return reload_object(machine)
 
604
 
 
605
    @operation(idempotent=False)
 
606
    def restore_storage_configuration(self, request, system_id):
 
607
        """Reset a machine's storage options to its initial state.
 
608
 
 
609
        Returns 404 if the machine is not found.
 
610
        Returns 403 if the user does not have permission to reset the machine.
 
611
        """
 
612
        machine = self.model.objects.get_node_or_404(
 
613
            system_id=system_id, user=request.user,
 
614
            perm=NODE_PERMISSION.ADMIN)
 
615
        if machine.status != NODE_STATUS.READY:
 
616
            raise NodeStateViolation(
 
617
                "Machine must be in a ready state to restore storage "
 
618
                "configuration.")
 
619
        machine.set_default_storage_layout()
 
620
        return reload_object(machine)
 
621
 
 
622
    @operation(idempotent=False)
 
623
    def restore_default_configuration(self, request, system_id):
 
624
        """Reset a machine's configuration to its initial state.
 
625
 
 
626
        Returns 404 if the machine is not found.
 
627
        Returns 403 if the user does not have permission to reset the machine.
 
628
        """
 
629
        machine = self.model.objects.get_node_or_404(
 
630
            system_id=system_id, user=request.user,
 
631
            perm=NODE_PERMISSION.ADMIN)
 
632
        if machine.status != NODE_STATUS.READY:
 
633
            raise NodeStateViolation(
 
634
                "Machine must be in a ready state to restore default "
 
635
                "networking and storage configuration.")
 
636
        machine.set_default_storage_layout()
 
637
        machine.set_initial_networking_configuration()
 
638
        return reload_object(machine)
 
639
 
 
640
    @operation(idempotent=False)
586
641
    def mark_broken(self, request, system_id):
587
642
        """Mark a node as 'broken'.
588
643