Exemplo n.º 1
0
    def provision(self, server_uuid, target):
        """Asynchronous trigger the provisioning of the server.

        This will set the target provision state of the server, and
        a background task will begin which actually applies the state
        change. This call will return a 202 (Accepted) indicating the
        request was accepted and is in progress; the client should
        continue to GET the status of this server to observe the
        status of the requested action.

        :param server_uuid: UUID of a server.
        :param target: The desired provision state of the server or verb.
        """

        # Currently we only support rebuild target
        if target not in (states.REBUILD, ):
            raise exception.InvalidActionParameterValue(value=target,
                                                        action="provision",
                                                        server=server_uuid)

        db_server = self._resource or self._get_resource(server_uuid)
        if target == states.REBUILD:
            pecan.request.engine_api.rebuild(pecan.request.context, db_server)

        # Set the HTTP Location Header
        url_args = '/'.join([server_uuid, 'states'])
        pecan.response.location = link.build_url('servers', url_args)
Exemplo n.º 2
0
    def power(self, server_uuid, target):
        """Set the power state of the server.

        :param server_uuid: the UUID of a server.
        :param target: the desired target to change power state,
                       on, off or reboot.
        :raises Conflict (HTTP 409): if a power operation is
                 already in progress.
        :raises BadRequest (HTTP 400): if the requested target
                 state is not valid or if the server is in CLEANING state.

        """
        if target not in ["on", "off", "reboot", "soft_off", "soft_reboot"]:
            # ironic will throw InvalidStateRequested
            raise exception.InvalidActionParameterValue(value=target,
                                                        action="power",
                                                        server=server_uuid)

        db_server = self._resource or self._get_resource(server_uuid)
        pecan.request.engine_api.power(pecan.request.context, db_server,
                                       target)
        # At present we do not catch the Exception from ironicclient.
        # Such as Conflict and BadRequest.
        # varify provision_state, if server is being cleaned,
        # don't change power state?

        # Set the HTTP Location Header, user can get the power_state
        # by locaton.
        url_args = '/'.join([server_uuid, 'states'])
        pecan.response.location = link.build_url('servers', url_args)