Exemple #1
0
    def stop_lpar(self, instance_name, timeout=30):
        """Stop a running LPAR.

        :param instance_name: LPAR instance name
        :param timeout: value in seconds for specifying
                        how long to wait for the LPAR to stop
        """
        cmd = self.command.chsysstate('-r lpar -o shutdown --immed -n %s' %
                                      instance_name)
        self.run_vios_command(cmd)

        # poll instance until stopped or raise exception
        lpar_obj = self.get_lpar(instance_name)
        wait_inc = 1  # seconds to wait between status polling
        start_time = time.time()
        while lpar_obj['state'] != 'Not Activated':
            curr_time = time.time()
            # wait up to (timeout) seconds for shutdown
            if (curr_time - start_time) > timeout:
                raise exception.PowerVMLPAROperationTimeout(
                        operation='stop_lpar',
                        instance_name=instance_name)

            time.sleep(wait_inc)
            lpar_obj = self.get_lpar(instance_name)
Exemple #2
0
    def _poll_for_lpar_status(self, instance_name, status, operation,
                            timeout=constants.POWERVM_LPAR_OPERATION_TIMEOUT):
        """Polls until the LPAR with the given name reaches the given status.

        :param instance_name: LPAR instance name
        :param status: Poll until the given LPAR status is reached
        :param operation: The operation being performed, e.g. 'stop_lpar'
        :param timeout: The number of seconds to wait.
        :raises: PowerVMLPARInstanceNotFound
        :raises: PowerVMLPAROperationTimeout
        :raises: InvalidParameterValue
        """
        # make sure it's a valid status
        if (status == constants.POWERVM_NOSTATE or
                not status in constants.POWERVM_POWER_STATE):
            msg = _("Invalid LPAR state: %s") % status
            raise n_exc.InvalidParameterValue(err=msg)

        # raise the given timeout exception if the loop call doesn't complete
        # in the specified timeout
        timeout_exception = exception.PowerVMLPAROperationTimeout(
                                                operation=operation,
                                                instance_name=instance_name)
        with eventlet_timeout.Timeout(timeout, timeout_exception):
            def _wait_for_lpar_status(instance_name, status):
                """Called at an interval until the status is reached."""
                lpar_obj = self.get_lpar(instance_name)
                if lpar_obj['state'] == status:
                    raise loopingcall.LoopingCallDone()

            timer = loopingcall.FixedIntervalLoopingCall(_wait_for_lpar_status,
                                                         instance_name, status)
            timer.start(interval=1).wait()