Exemplo n.º 1
0
    def _state_change_callback(self, prev_state, state, event):
        """
        Host state change callback
        """
        from nfv_vim import directors

        DLOG.info(
            "Host %s FSM State-Change: prev_state=%s, state=%s, event=%s." %
            (self.name, prev_state, state, event))

        self._elapsed_time_in_state = 0
        self._last_state_timestamp = timers.get_monotonic_timestamp_in_ms()

        if self.is_locking() and host_fsm.HOST_STATE.DISABLED == self.state:
            if nfvi.objects.v1.HOST_ADMIN_STATE.LOCKED \
                    == self.nfvi_host.admin_state:
                self._action = self._ACTION_NONE

        if self.is_unlocking():
            if nfvi.objects.v1.HOST_ADMIN_STATE.UNLOCKED \
                    == self.nfvi_host.admin_state:
                self._action = self._ACTION_NONE

        self._persist()

        host_director = directors.get_host_director()
        host_director.host_state_change_notify(self)
Exemplo n.º 2
0
    def complete(self, result, reason):
        """
        Disable Host Task Complete
        """
        if self.aborted():
            DLOG.debug("Task (%s) complete, but has been aborted." %
                       self._name)
        else:
            from nfv_vim import directors

            host_director = directors.get_host_director()
            host_director.host_disabled(self._host)

            DLOG.debug("Task (%s) complete." % self._name)

            event_data = dict()
            event_data['reason'] = reason

            if state_machine.STATE_TASK_RESULT.SUCCESS == result:
                self._host.fsm.handle_event(HOST_EVENT.TASK_COMPLETED,
                                            event_data)
            else:
                self._host.fsm.handle_event(HOST_EVENT.TASK_FAILED, event_data)
Exemplo n.º 3
0
    def nfvi_host_state_change(self,
                               nfvi_admin_state,
                               nfvi_oper_state,
                               nfvi_avail_status,
                               nfvi_data=None):
        """
        NFVI Host State Change
        """
        if nfvi_data is not None:
            self._nfvi_host.nfvi_data = nfvi_data
            self._persist()

        if nfvi.objects.v1.HOST_ADMIN_STATE.UNKNOWN == nfvi_admin_state:
            DLOG.info("Ignoring unknown administrative state change for %s." %
                      self._nfvi_host.name)
            return

        if nfvi.objects.v1.HOST_OPER_STATE.UNKNOWN == nfvi_oper_state:
            DLOG.info("Ignoring unknown operation state change for %s." %
                      self._nfvi_host.name)
            return

        if nfvi_admin_state != self._nfvi_host.admin_state \
                or nfvi_oper_state != self._nfvi_host.oper_state \
                or nfvi_avail_status != self._nfvi_host.avail_status:
            DLOG.debug("Host State-Change detected: nfvi_admin_state=%s "
                       "host_admin_state=%s, nfvi_oper_state=%s "
                       "host_oper_state=%s, nfvi_avail_state=%s "
                       "host_avail_status=%s, locking=%s unlocking=%s "
                       "fsm current_state=%s for %s." %
                       (nfvi_admin_state, self._nfvi_host.admin_state,
                        nfvi_oper_state, self._nfvi_host.oper_state,
                        nfvi_avail_status, self._nfvi_host.avail_status,
                        self.is_locking(), self.is_unlocking(),
                        self._fsm.current_state.name, self._nfvi_host.name))

            notify_offline = False
            if nfvi.objects.v1.HOST_AVAIL_STATUS.OFFLINE == nfvi_avail_status:
                if nfvi.objects.v1.HOST_AVAIL_STATUS.OFFLINE \
                        != self._nfvi_host.avail_status:
                    notify_offline = True

            self._nfvi_host.admin_state = nfvi_admin_state
            self._nfvi_host.oper_state = nfvi_oper_state
            self._nfvi_host.avail_status = nfvi_avail_status
            self._persist()
            self._nfvi_host_handle_state_change()

            if notify_offline:
                from nfv_vim import directors

                host_director = directors.get_host_director()
                host_director.host_offline(self)

        elif host_fsm.HOST_STATE.INITIAL == self._fsm.current_state.name:
            self._fsm.handle_event(host_fsm.HOST_EVENT.ADD)
            return

        elif host_fsm.HOST_STATE.CONFIGURE == self._fsm.current_state.name:
            self._fsm.handle_event(host_fsm.HOST_EVENT.ADD)
            return

        elif host_fsm.HOST_STATE.ENABLED == self._fsm.current_state.name \
                and nfvi.objects.v1.HOST_OPER_STATE.DISABLED == nfvi_oper_state:
            self._fsm.handle_event(host_fsm.HOST_EVENT.DISABLE)
            return

        elif host_fsm.HOST_STATE.DISABLED == self._fsm.current_state.name \
                and nfvi.objects.v1.HOST_OPER_STATE.ENABLED == nfvi_oper_state:
            self._fsm.handle_event(host_fsm.HOST_EVENT.ENABLE)
            return

        else:
            now_ms = timers.get_monotonic_timestamp_in_ms()
            secs_expired = (now_ms - self._last_state_timestamp) / 1000
            if 30 <= secs_expired:
                if 0 != self._last_state_timestamp:
                    self._elapsed_time_in_state += int(secs_expired)
                self._last_state_timestamp = now_ms
                self._persist()
                self._fsm.handle_event(host_fsm.HOST_EVENT.AUDIT)