コード例 #1
0
ファイル: node_action.py プロジェクト: kcns008/maas
    def execute(self, osystem=None, distro_series=None, hwe_kernel=None):
        """See `NodeAction.execute`."""
        if self.node.owner is None:
            with locks.node_acquire:
                self.node.acquire(self.user, token=None)

        if osystem and distro_series:
            try:
                self.node.osystem, self.node.distro_series = (
                    validate_osystem_and_distro_series(osystem, distro_series))
                self.node.save()
            except ValidationError as e:
                raise NodeActionError(e)

        try:
            self.node.hwe_kernel = validate_hwe_kernel(
                hwe_kernel, self.node.min_hwe_kernel, self.node.architecture,
                self.node.osystem, self.node.distro_series)
            self.node.save()
        except ValidationError as e:
            raise NodeActionError(e)

        try:
            get_curtin_config(self.node)
        except Exception as e:
            raise NodeActionError("Failed to retrieve curtin config: %s" % e)

        try:
            self.node.start(self.user)
        except StaticIPAddressExhaustion:
            raise NodeActionError(
                "%s: Failed to start, static IP addresses are exhausted." %
                self.node.hostname)
        except RPC_EXCEPTIONS + (ExternalProcessError, ) as exception:
            raise NodeActionError(exception)
コード例 #2
0
 def test__returns_osystem_and_release_with_license_key_stripped(self):
     factory.make_Node()
     osystem = make_usable_osystem(self)
     release = osystem['default_release']
     self.assertEqual(
         (osystem['name'], release),
         validate_osystem_and_distro_series(osystem['name'], release + '*'))
コード例 #3
0
ファイル: node_action.py プロジェクト: zeronewb/maas
    def execute(self, osystem=None, distro_series=None, hwe_kernel=None):
        """See `NodeAction.execute`."""
        if self.node.owner is None:
            with locks.node_acquire:
                try:
                    self.node.acquire(self.user, token=None)
                except ValidationError as e:
                    raise NodeActionError(e)

        if osystem and distro_series:
            try:
                self.node.osystem, self.node.distro_series = (
                    validate_osystem_and_distro_series(osystem, distro_series))
                self.node.save()
            except ValidationError as e:
                raise NodeActionError(e)

        try:
            self.node.hwe_kernel = validate_hwe_kernel(
                hwe_kernel, self.node.min_hwe_kernel, self.node.architecture,
                self.node.osystem, self.node.distro_series)
            self.node.save()
        except ValidationError as e:
            raise NodeActionError(e)

        request = self.request
        if request is None:
            # Being called from the websocket, just to ensure that the curtin
            # configuration is valid. The request object does not need to be
            # an actual request. 'SERVER_NAME' and 'SERVER_PORT' are required
            # so `build_absolure_uri` can create an actual absolute URI.
            request = HttpRequest()
            request.META['SERVER_NAME'] = 'localhost'
            request.META['SERVER_PORT'] = 5248
        try:
            get_curtin_config(request, self.node)
        except Exception as e:
            raise NodeActionError("Failed to retrieve curtin config: %s" % e)

        try:
            self.node.start(self.user)
        except StaticIPAddressExhaustion:
            raise NodeActionError(
                "%s: Failed to start, static IP addresses are exhausted." %
                self.node.hostname)
        except RPC_EXCEPTIONS + (ExternalProcessError, ) as exception:
            raise NodeActionError(exception)
コード例 #4
0
    def _execute(self,
                 osystem=None,
                 distro_series=None,
                 hwe_kernel=None,
                 install_kvm=False):
        """See `NodeAction.execute`."""
        if install_kvm:
            if not self.user.is_superuser:
                raise NodeActionError(
                    "You must be a MAAS administrator to deploy a machine "
                    "as a MAAS-managed KVM Pod.")
        if self.node.owner is None:
            with locks.node_acquire:
                try:
                    bridge_all = True if install_kvm else False
                    self.node.acquire(self.user,
                                      token=None,
                                      bridge_all=bridge_all)
                except ValidationError as e:
                    raise NodeActionError(e)
        if install_kvm:
            try:
                # KVM Pod installation should default to ubuntu/bionic, since
                # that was the release it was tested on.
                if osystem is None:
                    osystem = 'ubuntu'
                if distro_series is None:
                    distro_series = 'bionic'
                self.node.osystem, self.node.distro_series = (
                    validate_osystem_and_distro_series(osystem, distro_series))
                self.node.install_kvm = True
                self.node.save()
            except ValidationError as e:
                raise NodeActionError(e)
        elif osystem and distro_series:
            try:
                self.node.osystem, self.node.distro_series = (
                    validate_osystem_and_distro_series(osystem, distro_series))
                self.node.save()
            except ValidationError as e:
                raise NodeActionError(e)
        try:
            self.node.hwe_kernel = validate_hwe_kernel(
                hwe_kernel, self.node.min_hwe_kernel, self.node.architecture,
                self.node.osystem, self.node.distro_series)
            self.node.save()
        except ValidationError as e:
            raise NodeActionError(e)

        request = self.request
        if request is None:
            # `compile_node_actions` is the path by which the node
            # actions are instantiated.  There are other places within the
            # code that call compile_node_actions without a request object.
            # In this event, and for future uses of these node actions without
            # a request being passed in, we need to create one here.
            # 'SERVER_NAME' and 'SERVER_PORT' are required so
            # `build_absolure_uri` can create an actual absolute URI so that
            # the curtin configuration is valid.
            request = HttpRequest()
            request.META['SERVER_NAME'] = 'localhost'
            request.META['SERVER_PORT'] = 5248
        try:
            get_curtin_config(request, self.node)
        except Exception as e:
            raise NodeActionError("Failed to retrieve curtin config: %s" % e)

        try:
            self.node.start(self.user)
        except StaticIPAddressExhaustion:
            raise NodeActionError(
                "%s: Failed to start, static IP addresses are exhausted." %
                self.node.hostname)
        except RPC_EXCEPTIONS + (ExternalProcessError, ) as exception:
            raise NodeActionError(exception)
コード例 #5
0
    def _execute(
        self,
        osystem=None,
        distro_series=None,
        hwe_kernel=None,
        install_kvm=False,
        user_data=None,
    ):
        """See `NodeAction.execute`."""
        if install_kvm:
            if not self.user.is_superuser:
                raise NodeActionError(
                    "You must be a MAAS administrator to deploy a machine "
                    "as a MAAS-managed KVM Pod.")
        if self.node.owner is None:
            with locks.node_acquire:
                try:
                    self.node.acquire(self.user)
                except ValidationError as e:
                    raise NodeActionError(e)
        if osystem and distro_series:
            try:
                (
                    self.node.osystem,
                    self.node.distro_series,
                ) = validate_osystem_and_distro_series(osystem, distro_series)
                self.node.save()
            except ValidationError as e:
                raise NodeActionError(e)
        else:
            configs = Config.objects.get_configs(
                ["default_osystem", "default_distro_series"])
            self.node.osystem = configs["default_osystem"]
            self.node.distro_series = configs["default_distro_series"]
            self.node.save()
        try:
            self.node.hwe_kernel = validate_hwe_kernel(
                hwe_kernel,
                self.node.min_hwe_kernel,
                self.node.architecture,
                self.node.osystem,
                self.node.distro_series,
            )
            self.node.save()
        except ValidationError as e:
            raise NodeActionError(e)
        user_data = user_data.encode() if user_data else None
        request = self.request
        if request is None:
            # `compile_node_actions` is the path by which the node
            # actions are instantiated.  There are other places within the
            # code that call compile_node_actions without a request object.
            # In this event, and for future uses of these node actions without
            # a request being passed in, we need to create one here.
            # 'SERVER_NAME' and 'SERVER_PORT' are required so
            # `build_absolure_uri` can create an actual absolute URI so that
            # the curtin configuration is valid.
            request = HttpRequest()
            request.META["SERVER_NAME"] = "localhost"
            request.META["SERVER_PORT"] = 5248
        try:
            get_curtin_config(request, self.node)
        except Exception as e:
            raise NodeActionError("Failed to retrieve curtin config: %s" % e)

        try:
            self.node.start(self.user,
                            user_data=user_data,
                            install_kvm=install_kvm)
        except StaticIPAddressExhaustion:
            raise NodeActionError(
                "%s: Failed to start, static IP addresses are exhausted." %
                self.node.hostname)
        except IPAddressCheckFailed:
            raise NodeActionError(
                f"{self.node.hostname}: Failed to start, IP addresses check failed."
            )
        except RPC_EXCEPTIONS + (ExternalProcessError, ) as exception:
            raise NodeActionError(exception)