コード例 #1
0
ファイル: forms.py プロジェクト: MingZhai/orthos2
 def clean(self):
     """Add the machine to cleaned data for further processing."""
     cleaned_data = super(SerialConsoleAPIForm, self).clean()
     cleaned_data['machine'] = self.machine
     serialconsole = SerialConsole(**cleaned_data)
     serialconsole.clean()
     return cleaned_data
コード例 #2
0
ファイル: add.py プロジェクト: MingZhai/orthos2
    def post(self, request, fqdn, *args, **kwargs):
        """Add serial console to machine."""
        if not request.user.is_superuser:
            return ErrorMessage(
                "Only superusers are allowed to perform this action!").as_json

        try:
            result = get_machine(fqdn,
                                 redirect_to='api:serialconsole_add',
                                 data=request.GET)
            if isinstance(result, Serializer):
                return result.as_json
            elif isinstance(result, HttpResponseRedirect):
                return result
            machine = result
        except Exception as e:
            return ErrorMessage(str(e)).as_json

        if machine.has_serialconsole():
            return InfoMessage("Machine has already a serial console.").as_json

        data = json.loads(request.body.decode('utf-8'))['form']
        form = SerialConsoleAPIForm(data, machine=machine)

        if form.is_valid():
            try:
                serialconsole = SerialConsole(**form.cleaned_data)
                serialconsole.save()
            except Exception as e:
                logger.exception(e)
                return ErrorMessage("Something went wrong!").as_json

            return Message('Ok.').as_json

        return ErrorMessage("\n{}".format(
            format_cli_form_errors(form))).as_json
コード例 #3
0
ファイル: virtualizationapi.py プロジェクト: MingZhai/orthos2
    def create(self, *args, **kwargs):
        """
        Create a virtual machine.

        Method returns a new `Machine` object and calls the subclass to actually create the virtual
        machine physically.
        """
        from orthos2.data.models import (Architecture, Machine, RemotePower,
                                         SerialConsole, SerialConsoleType,
                                         System)
        from django.contrib.auth.models import User

        vm = Machine()
        vm.unsaved_networkinterfaces = []

        vm.architecture = Architecture.objects.get(name=kwargs['architecture'])
        vm.system = System.objects.get(pk=kwargs['system'])

        self._create(vm, *args, **kwargs)

        vm.mac_address = vm.unsaved_networkinterfaces[0].mac_address
        vm.check_connectivity = Machine.Connectivity.ALL
        vm.collect_system_information = True
        vm.save()

        for networkinterface in vm.unsaved_networkinterfaces[1:]:
            networkinterface.machine = vm
            networkinterface.save()
        vm.remotepower = RemotePower(fence_name="virsh")
        vm.remotepower.save()

        if self.host.has_serialconsole():
            stype = SerialConsoleType.objects.get(name='libvirt/qemu')
            if not stype:
                raise Exception("Bug: SerialConsoleType not found")
            vm.serialconsole = SerialConsole(stype=stype, baud_rate=115200)
            vm.serialconsole.save()

        if vm.vnc['enabled']:
            vm.annotations.create(text='VNC enabled: {}:{}'.format(
                self.host.fqdn, vm.vnc['port']),
                                  reporter=User.objects.get(username='******'))

        return vm