Exemple #1
0
    def put(self, Injection):
        """inject a plugin into a board.

        :param plugin_ident: UUID or logical name of a plugin.
        :param board_ident: UUID or logical name of a board.
        """

        if not Injection.plugin:
            raise exception.MissingParameterValue(
                ("Plugin is not specified."))

        if not Injection.onboot:
            Injection.onboot = False

        rpc_board = api_utils.get_rpc_board(self.board_ident)
        rpc_plugin = api_utils.get_rpc_plugin(Injection.plugin)

        try:
            cdict = pecan.request.context.to_policy_values()
            cdict['owner'] = rpc_board.owner
            policy.authorize('iot:plugin_inject:put', cdict, cdict)

            if not rpc_plugin.public:
                cdict = pecan.request.context.to_policy_values()
                cdict['owner'] = rpc_plugin.owner
                policy.authorize('iot:plugin_inject:put', cdict, cdict)
        except exception:
            return exception

        rpc_board.check_if_online()
        result = pecan.request.rpcapi.inject_plugin(pecan.request.context,
                                                    rpc_plugin.uuid,
                                                    rpc_board.uuid,
                                                    Injection.onboot)
        return result
Exemple #2
0
    def post(self, Board):
        """Create a new Board.

        :param Board: a Board within the request body.
        """
        context = pecan.request.context
        cdict = context.to_policy_values()
        policy.authorize('iot:board:create', cdict, cdict)

        if not Board.name:
            raise exception.MissingParameterValue(("Name is not specified."))
        if not Board.code:
            raise exception.MissingParameterValue(("Code is not specified."))
        if not Board.location:
            raise exception.MissingParameterValue(
                ("Location is not specified."))

        if Board.name:
            if not api_utils.is_valid_board_name(Board.name):
                msg = ("Cannot create board with invalid name %(name)s")
                raise wsme.exc.ClientSideError(msg % {'name': Board.name},
                                               status_code=400)

        new_Board = objects.Board(pecan.request.context, **Board.as_dict())

        new_Board.owner = pecan.request.context.user_id
        new_Board.project = pecan.request.context.project_id

        new_Location = objects.Location(pecan.request.context,
                                        **Board.location[0].as_dict())

        new_Board = pecan.request.rpcapi.create_board(pecan.request.context,
                                                      new_Board, new_Location)

        return Board.convert_with_links(new_Board)
    def get_all(self, marker=None,
                limit=None, sort_key='id', sort_dir='asc',
                fields=None):
        """Retrieve a list of EnabledWebservices.

        :param marker: pagination marker for large data sets.
        :param limit: maximum number of resources to return in a single result.
                      This value cannot be larger than the value of max_limit
                      in the [api] section of the ironic configuration, or only
                      max_limit resources will be returned.
        :param sort_key: column to sort results by. Default: id.
        :param sort_dir: direction to sort. "asc" or "desc". Default: asc.
        :param fields: Optional, a list with a specified set of fields
                       of the resource to be returned.
        """
        cdict = pecan.request.context.to_policy_values()
        policy.authorize('iot:enabledwebservice:get', cdict, cdict)
        project_id = pecan.request.context.project_id

        if fields is None:
            fields = _DEFAULT_RETURN_FIELDS
        return self._get_EnabledWebservices_collection(marker,
                                                       limit,
                                                       sort_key, sort_dir,
                                                       project_id=project_id,
                                                       fields=fields)
Exemple #4
0
    def put(self, Webservice):
        """Create a new Webservice.

        :param Webservice: a Webservice within the request body.
        """
        context = pecan.request.context
        cdict = context.to_policy_values()
        policy.authorize('iot:webservice:create', cdict, cdict)

        if not Webservice.name:
            raise exception.MissingParameterValue(
                ("Name is not specified."))

        if Webservice.name:
            if not api_utils.is_valid_name(Webservice.name):
                msg = ("Cannot create webservice with invalid name %(name)s")
                raise wsme.exc.ClientSideError(msg % {'name': Webservice.name},
                                               status_code=400)

        rpc_board = api_utils.get_rpc_board(self.board_ident)

        new_Webservice = objects.Webservice(pecan.request.context,
                                            **Webservice.as_dict())

        new_Webservice.board_uuid = rpc_board.uuid
        new_Webservice = pecan.request.rpcapi.create_webservice(
            pecan.request.context,
            new_Webservice)

        return Webservice.convert_with_links(new_Webservice)
Exemple #5
0
    def detail(self, marker=None,
               limit=None, sort_key='id', sort_dir='asc',
               fields=None, with_public=False, all_fleets=False):
        """Retrieve a list of fleets.

        :param marker: pagination marker for large data sets.
        :param limit: maximum number of resources to return in a single result.
                      This value cannot be larger than the value of max_limit
                      in the [api] section of the ironic configuration, or only
                      max_limit resources will be returned.
        :param sort_key: column to sort results by. Default: id.
        :param sort_dir: direction to sort. "asc" or "desc". Default: asc.
        :param with_public: Optional boolean to get also public fleet.
        :param all_fleets: Optional boolean to get all the fleets.
                            Only for the admin
        :param fields: Optional, a list with a specified set of fields
                       of the resource to be returned.
        """

        cdict = pecan.request.context.to_policy_values()
        policy.authorize('iot:fleet:get', cdict, cdict)

        # /detail should only work against collections
        parent = pecan.request.path.split('/')[:-1][-1]
        if parent != "fleets":
            raise exception.HTTPNotFound()

        return self._get_fleets_collection(marker,
                                           limit, sort_key, sort_dir,
                                           with_public=with_public,
                                           all_fleets=all_fleets,
                                           fields=fields)
Exemple #6
0
    def post(self, Fleet):
        """Create a new Fleet.

        :param Fleet: a Fleet within the request body.
        """
        context = pecan.request.context
        cdict = context.to_policy_values()
        policy.authorize('iot:fleet:create', cdict, cdict)

        if not Fleet.name:
            raise exception.MissingParameterValue(
                ("Name is not specified."))

        if Fleet.name:
            if not api_utils.is_valid_name(Fleet.name):
                msg = ("Cannot create fleet with invalid name %(name)s")
                raise wsme.exc.ClientSideError(msg % {'name': Fleet.name},
                                               status_code=400)

        new_Fleet = objects.Fleet(pecan.request.context,
                                  **Fleet.as_dict())

        new_Fleet.project = cdict['project_id']
        new_Fleet = pecan.request.rpcapi.create_fleet(
            pecan.request.context,
            new_Fleet)

        return Fleet.convert_with_links(new_Fleet)
Exemple #7
0
    def post(self, Service):
        """Create a new Service.

        :param Service: a Service within the request body.
        """
        context = pecan.request.context
        cdict = context.to_policy_values()
        policy.authorize('iot:service:create', cdict, cdict)

        if not Service.name:
            raise exception.MissingParameterValue(
                ("Name is not specified."))

        if Service.name:
            if not api_utils.is_valid_name(Service.name):
                msg = ("Cannot create service with invalid name %(name)s")
                raise wsme.exc.ClientSideError(msg % {'name': Service.name},
                                               status_code=400)

        new_Service = objects.Service(pecan.request.context,
                                      **Service.as_dict())

        new_Service.project = cdict['project_id']
        new_Service = pecan.request.rpcapi.create_service(
            pecan.request.context,
            new_Service)

        return Service.convert_with_links(new_Service)
Exemple #8
0
    def put(self, Injection):
        """inject a plugin into a board.

        :param plugin_ident: UUID or logical name of a plugin.
        :param board_ident: UUID or logical name of a board.
        """

        if not Injection.plugin:
            raise exception.MissingParameterValue(("Plugin is not specified."))

        if not Injection.onboot:
            Injection.onboot = False

        rpc_board = api_utils.get_rpc_board(self.board_ident)
        rpc_plugin = api_utils.get_rpc_plugin(Injection.plugin)

        try:
            cdict = pecan.request.context.to_policy_values()
            cdict['owner'] = rpc_board.owner
            policy.authorize('iot:plugin_inject:put', cdict, cdict)

            if not rpc_plugin.public:
                cdict = pecan.request.context.to_policy_values()
                cdict['owner'] = rpc_plugin.owner
                policy.authorize('iot:plugin_inject:put', cdict, cdict)
        except exception:
            return exception

        rpc_board.check_if_online()
        result = pecan.request.rpcapi.inject_plugin(pecan.request.context,
                                                    rpc_plugin.uuid,
                                                    rpc_board.uuid,
                                                    Injection.onboot)
        return result
Exemple #9
0
    def get_all(self,
                status=None,
                marker=None,
                limit=None,
                sort_key='id',
                sort_dir='asc',
                fields=None,
                project=None):
        """Retrieve a list of boards.

        :param status: Optional string value to get only board in
                                that status.
        :param marker: pagination marker for large data sets.
        :param limit: maximum number of resources to return in a single result.
                      This value cannot be larger than the value of max_limit
                      in the [api] section of the ironic configuration, or only
                      max_limit resources will be returned.
        :param sort_key: column to sort results by. Default: id.
        :param sort_dir: direction to sort. "asc" or "desc". Default: asc.
        :param fields: Optional, a list with a specified set of fields
                       of the resource to be returned.
        """
        cdict = pecan.request.context.to_policy_values()
        policy.authorize('iot:board:get', cdict, cdict)

        if fields is None:
            fields = _DEFAULT_RETURN_FIELDS
        return self._get_boards_collection(status,
                                           marker,
                                           limit,
                                           sort_key,
                                           sort_dir,
                                           fields=fields,
                                           project=project)
Exemple #10
0
    def get_all(self, marker=None,
                limit=None, sort_key='id', sort_dir='asc',
                fields=None):
        """Retrieve a list of boards.

        :param marker: pagination marker for large data sets.
        :param limit: maximum number of resources to return in a single result.
                      This value cannot be larger than the value of max_limit
                      in the [api] section of the ironic configuration, or only
                      max_limit resources will be returned.
        :param sort_key: column to sort results by. Default: id.
        :param sort_dir: direction to sort. "asc" or "desc". Default: asc.
        :param fields: Optional, a list with a specified set of fields
                       of the resource to be returned.
        """
        cdict = pecan.request.context.to_policy_values()
        policy.authorize('iot:board:get', cdict, cdict)

        if fields is None:
            fields = _DEFAULT_BOARDS_RETURN_FIELDS

        filters = {}
        filters['fleet'] = self.fleet_ident

        boards = objects.Board.list(pecan.request.context, limit, marker,
                                    sort_key=sort_key, sort_dir=sort_dir,
                                    filters=filters)

        parameters = {'sort_key': sort_key, 'sort_dir': sort_dir}

        return BoardCollection.convert_with_links(boards, limit,
                                                  fields=fields,
                                                  **parameters)
Exemple #11
0
    def post(self, Plugin):
        """Create a new Plugin.

        :param Plugin: a Plugin within the request body.
        """
        context = pecan.request.context
        cdict = context.to_policy_values()
        policy.authorize('iot:plugin:create', cdict, cdict)

        if not Plugin.name:
            raise exception.MissingParameterValue(("Name is not specified."))

        if Plugin.name:
            if not api_utils.is_valid_name(Plugin.name):
                msg = ("Cannot create plugin with invalid name %(name)s")
                raise wsme.exc.ClientSideError(msg % {'name': Plugin.name},
                                               status_code=400)

        new_Plugin = objects.Plugin(pecan.request.context, **Plugin.as_dict())

        new_Plugin.owner = cdict['user']
        new_Plugin = pecan.request.rpcapi.create_plugin(
            pecan.request.context, new_Plugin)

        return Plugin.convert_with_links(new_Plugin)
Exemple #12
0
    def post(self, Plugin):
        """Create a new Plugin.

        :param Plugin: a Plugin within the request body.
        """
        context = pecan.request.context
        cdict = context.to_policy_values()
        policy.authorize('iot:plugin:create', cdict, cdict)

        if not Plugin.name:
            raise exception.MissingParameterValue(
                ("Name is not specified."))

        if Plugin.name:
            if not api_utils.is_valid_name(Plugin.name):
                msg = ("Cannot create plugin with invalid name %(name)s")
                raise wsme.exc.ClientSideError(msg % {'name': Plugin.name},
                                               status_code=400)

        new_Plugin = objects.Plugin(pecan.request.context,
                                    **Plugin.as_dict())

        new_Plugin.owner = cdict['user']
        new_Plugin = pecan.request.rpcapi.create_plugin(pecan.request.context,
                                                        new_Plugin)

        return Plugin.convert_with_links(new_Plugin)
Exemple #13
0
    def get_all(self, marker=None,
                limit=None, sort_key='id', sort_dir='asc',
                fields=None, with_public=False, all_services=False):
        """Retrieve a list of services.

        :param marker: pagination marker for large data sets.
        :param limit: maximum number of resources to return in a single result.
                      This value cannot be larger than the value of max_limit
                      in the [api] section of the ironic configuration, or only
                      max_limit resources will be returned.
        :param sort_key: column to sort results by. Default: id.
        :param sort_dir: direction to sort. "asc" or "desc". Default: asc.
        :param with_public: Optional boolean to get also public pluings.
        :param all_services: Optional boolean to get all the pluings.
                            Only for the admin
        :param fields: Optional, a list with a specified set of fields
                       of the resource to be returned.
        """
        cdict = pecan.request.context.to_policy_values()
        policy.authorize('iot:service:get', cdict, cdict)

        if fields is None:
            fields = _DEFAULT_RETURN_FIELDS
        return self._get_services_collection(marker,
                                             limit, sort_key, sort_dir,
                                             with_public=with_public,
                                             all_services=all_services,
                                             fields=fields)
Exemple #14
0
    def detail(self, status=None, marker=None,
               limit=None, sort_key='id', sort_dir='asc',
               fields=None, project=None):
        """Retrieve a list of boards.

        :param status: Optional string value to get only board in
                                that status.
        :param marker: pagination marker for large data sets.
        :param limit: maximum number of resources to return in a single result.
                      This value cannot be larger than the value of max_limit
                      in the [api] section of the ironic configuration, or only
                      max_limit resources will be returned.
        :param sort_key: column to sort results by. Default: id.
        :param sort_dir: direction to sort. "asc" or "desc". Default: asc.
        :param project: Optional string value to get only boards
                        of the project.
        :param fields: Optional, a list with a specified set of fields
                       of the resource to be returned.
        """

        cdict = pecan.request.context.to_policy_values()
        policy.authorize('iot:board:get', cdict, cdict)

        # /detail should only work against collections
        parent = pecan.request.path.split('/')[:-1][-1]
        if parent != "boards":
            raise exception.HTTPNotFound()

        return self._get_boards_collection(status, marker,
                                           limit, sort_key, sort_dir,
                                           project=project, fields=fields)
Exemple #15
0
    def get_all(self,
                marker=None,
                limit=None,
                sort_key='id',
                sort_dir='asc',
                fields=None,
                with_public=False,
                all_plugins=False):
        """Retrieve a list of plugins.

        :param marker: pagination marker for large data sets.
        :param limit: maximum number of resources to return in a single result.
                      This value cannot be larger than the value of max_limit
                      in the [api] section of the ironic configuration, or only
                      max_limit resources will be returned.
        :param sort_key: column to sort results by. Default: id.
        :param sort_dir: direction to sort. "asc" or "desc". Default: asc.
        :param with_public: Optional boolean to get also public pluings.
        :param all_plugins: Optional boolean to get all the pluings.
                            Only for the admin
        :param fields: Optional, a list with a specified set of fields
                       of the resource to be returned.
        """
        cdict = pecan.request.context.to_policy_values()
        policy.authorize('iot:plugin:get', cdict, cdict)

        if fields is None:
            fields = _DEFAULT_RETURN_FIELDS
        return self._get_plugins_collection(marker,
                                            limit,
                                            sort_key,
                                            sort_dir,
                                            with_public=with_public,
                                            all_plugins=all_plugins,
                                            fields=fields)
Exemple #16
0
    def post(self, Fleet):
        """Create a new Fleet.

        :param Fleet: a Fleet within the request body.
        """
        context = pecan.request.context
        cdict = context.to_policy_values()
        policy.authorize('iot:fleet:create', cdict, cdict)

        if not Fleet.name:
            raise exception.MissingParameterValue(("Name is not specified."))

        if Fleet.name:
            if not api_utils.is_valid_name(Fleet.name):
                msg = ("Cannot create fleet with invalid name %(name)s")
                raise wsme.exc.ClientSideError(msg % {'name': Fleet.name},
                                               status_code=400)

        new_Fleet = objects.Fleet(pecan.request.context, **Fleet.as_dict())

        new_Fleet.project = cdict['project_id']
        new_Fleet = pecan.request.rpcapi.create_fleet(pecan.request.context,
                                                      new_Fleet)

        return Fleet.convert_with_links(new_Fleet)
Exemple #17
0
    def post(self, Service):
        """Create a new Service.

        :param Service: a Service within the request body.
        """
        context = pecan.request.context
        cdict = context.to_policy_values()
        policy.authorize('iot:service:create', cdict, cdict)

        if not Service.name:
            raise exception.MissingParameterValue(("Name is not specified."))

        if Service.name:
            if not api_utils.is_valid_name(Service.name):
                msg = ("Cannot create service with invalid name %(name)s")
                raise wsme.exc.ClientSideError(msg % {'name': Service.name},
                                               status_code=400)

        new_Service = objects.Service(pecan.request.context,
                                      **Service.as_dict())

        new_Service.project = cdict['project_id']
        new_Service = pecan.request.rpcapi.create_service(
            pecan.request.context, new_Service)

        return Service.convert_with_links(new_Service)
Exemple #18
0
    def get_one(self, port_ident):
        rpc_board = api_utils.get_rpc_board(self.board_ident)

        cdict = pecan.request.context.to_policy_values()
        cdict['owner'] = rpc_board.owner
        policy.authorize('iot:port_on_board:get', cdict, cdict)

        return self.get_port_detail(rpc_board, port_ident)
Exemple #19
0
    def get_one(self, port_ident):
        rpc_board = api_utils.get_rpc_board(self.board_ident)

        cdict = pecan.request.context.to_policy_values()
        cdict['owner'] = rpc_board.owner
        policy.authorize('iot:port_on_board:get', cdict, cdict)

        return self.get_port_detail(rpc_board, port_ident)
Exemple #20
0
    def get_all(self):

        rpc_board = api_utils.get_rpc_board(self.board_ident)

        cdict = pecan.request.context.to_policy_values()
        cdict['owner'] = rpc_board.owner
        policy.authorize('iot:port_on_board:get', cdict, cdict)

        return self._get_ports_on_board_collection(rpc_board.uuid)
Exemple #21
0
    def get_all(self):

        rpc_board = api_utils.get_rpc_board(self.board_ident)

        cdict = pecan.request.context.to_policy_values()
        cdict['owner'] = rpc_board.owner
        policy.authorize('iot:port_on_board:get', cdict, cdict)

        return self._get_ports_on_board_collection(rpc_board.uuid)
Exemple #22
0
    def get_all(self):
        """Retrieve a list of plugins of a board.

        """
        rpc_board = api_utils.get_rpc_board(self.board_ident)

        cdict = pecan.request.context.to_policy_values()
        cdict['owner'] = rpc_board.owner
        policy.authorize('iot:plugin_on_board:get', cdict, cdict)

        return self._get_plugins_on_board_collection(rpc_board.uuid)
Exemple #23
0
    def get_all(self):
        """Retrieve a list of services of a board.

        """
        rpc_board = api_utils.get_rpc_board(self.board_ident)

        cdict = pecan.request.context.to_policy_values()
        cdict['project_id'] = rpc_board.project
        policy.authorize('iot:service_on_board:get', cdict, cdict)

        return self._get_services_on_board_collection(rpc_board.uuid)
Exemple #24
0
    def get_all(self):
        """Retrieve a list of services of a board.

        """
        rpc_board = api_utils.get_rpc_board(self.board_ident)

        cdict = pecan.request.context.to_policy_values()
        cdict['project_id'] = rpc_board.project
        policy.authorize('iot:service_on_board:get', cdict, cdict)

        return self._get_services_on_board_collection(rpc_board.uuid)
Exemple #25
0
    def get_all(self):
        """Retrieve a list of plugins of a board.

        """
        rpc_board = api_utils.get_rpc_board(self.board_ident)

        cdict = pecan.request.context.to_policy_values()
        cdict['owner'] = rpc_board.owner
        policy.authorize('iot:plugin_on_board:get', cdict, cdict)

        return self._get_plugins_on_board_collection(rpc_board.uuid)
Exemple #26
0
    def delete(self, board_ident):
        """Delete a board.

        :param board_ident: UUID or logical name of a board.
        """
        context = pecan.request.context
        cdict = context.to_policy_values()
        policy.authorize('iot:board:delete', cdict, cdict)

        rpc_board = api_utils.get_rpc_board(board_ident)
        pecan.request.rpcapi.destroy_board(pecan.request.context,
                                           rpc_board.uuid)
Exemple #27
0
    def delete(self, plugin_ident):
        """Delete a plugin.

        :param plugin_ident: UUID or logical name of a plugin.
        """
        context = pecan.request.context
        cdict = context.to_policy_values()
        policy.authorize('iot:plugin:delete', cdict, cdict)

        rpc_plugin = api_utils.get_rpc_plugin(plugin_ident)
        pecan.request.rpcapi.destroy_plugin(pecan.request.context,
                                            rpc_plugin.uuid)
Exemple #28
0
    def delete(self, service_ident):
        """Delete a service.

        :param service_ident: UUID or logical name of a service.
        """
        context = pecan.request.context
        cdict = context.to_policy_values()
        policy.authorize('iot:service:delete', cdict, cdict)

        rpc_service = api_utils.get_rpc_service(service_ident)
        pecan.request.rpcapi.destroy_service(pecan.request.context,
                                             rpc_service.uuid)
Exemple #29
0
    def delete(self, service_ident):
        """Delete a service.

        :param service_ident: UUID or logical name of a service.
        """
        context = pecan.request.context
        cdict = context.to_policy_values()
        policy.authorize('iot:service:delete', cdict, cdict)

        rpc_service = api_utils.get_rpc_service(service_ident)
        pecan.request.rpcapi.destroy_service(pecan.request.context,
                                             rpc_service.uuid)
Exemple #30
0
    def delete(self, fleet_ident):
        """Delete a fleet.

        :param fleet_ident: UUID or logical name of a fleet.
        """
        context = pecan.request.context
        cdict = context.to_policy_values()
        policy.authorize('iot:fleet:delete', cdict, cdict)

        rpc_fleet = api_utils.get_rpc_fleet(fleet_ident)
        pecan.request.rpcapi.destroy_fleet(pecan.request.context,
                                           rpc_fleet.uuid)
Exemple #31
0
    def delete(self, fleet_ident):
        """Delete a fleet.

        :param fleet_ident: UUID or logical name of a fleet.
        """
        context = pecan.request.context
        cdict = context.to_policy_values()
        policy.authorize('iot:fleet:delete', cdict, cdict)

        rpc_fleet = api_utils.get_rpc_fleet(fleet_ident)
        pecan.request.rpcapi.destroy_fleet(pecan.request.context,
                                           rpc_fleet.uuid)
Exemple #32
0
    def delete(self, board_ident):
        """Delete a board.

        :param board_ident: UUID or logical name of a board.
        """
        context = pecan.request.context
        cdict = context.to_policy_values()
        policy.authorize('iot:board:delete', cdict, cdict)

        rpc_board = api_utils.get_rpc_board(board_ident)
        pecan.request.rpcapi.destroy_board(pecan.request.context,
                                           rpc_board.uuid)
Exemple #33
0
    def delete(self, plugin_ident):
        """Delete a plugin.

        :param plugin_ident: UUID or logical name of a plugin.
        """
        context = pecan.request.context
        cdict = context.to_policy_values()
        policy.authorize('iot:plugin:delete', cdict, cdict)

        rpc_plugin = api_utils.get_rpc_plugin(plugin_ident)
        pecan.request.rpcapi.destroy_plugin(pecan.request.context,
                                            rpc_plugin.uuid)
Exemple #34
0
    def get_one(self, webservice_ident, fields=None):
        """Retrieve information about the given webservice.

        :param webservice_ident: UUID or logical name of a webservice.
        :param fields: Optional, a list with a specified set of fields
            of the resource to be returned.
        """

        rpc_webservice = api_utils.get_rpc_webservice(webservice_ident)
        cdict = pecan.request.context.to_policy_values()
        policy.authorize('iot:webservice:get_one', cdict, cdict)

        return Webservice.convert_with_links(rpc_webservice, fields=fields)
Exemple #35
0
    def get_one(self, board_ident, fields=None):
        """Retrieve information about the given board.

        :param board_ident: UUID or logical name of a board.
        :param fields: Optional, a list with a specified set of fields
            of the resource to be returned.
        """

        cdict = pecan.request.context.to_policy_values()
        policy.authorize('iot:board:get', cdict, cdict)

        rpc_board = api_utils.get_rpc_board(board_ident)

        return Board.convert_with_links(rpc_board, fields=fields)
Exemple #36
0
    def get_one(self, service_ident, fields=None):
        """Retrieve information about the given service.

        :param service_ident: UUID or logical name of a service.
        :param fields: Optional, a list with a specified set of fields
            of the resource to be returned.
        """

        rpc_service = api_utils.get_rpc_service(service_ident)
        cdict = pecan.request.context.to_policy_values()
        cdict['project'] = rpc_service.project
        policy.authorize('iot:service:get_one', cdict, cdict)

        return Service.convert_with_links(rpc_service, fields=fields)
Exemple #37
0
    def get_one(self, board_ident, fields=None):
        """Retrieve information about the given board.

        :param board_ident: UUID or logical name of a board.
        :param fields: Optional, a list with a specified set of fields
            of the resource to be returned.
        """

        cdict = pecan.request.context.to_policy_values()
        policy.authorize('iot:board:get', cdict, cdict)

        rpc_board = api_utils.get_rpc_board(board_ident)

        return Board.convert_with_links(rpc_board, fields=fields)
Exemple #38
0
    def get_one(self, fleet_ident, fields=None):
        """Retrieve information about the given fleet.

        :param fleet_ident: UUID or logical name of a fleet.
        :param fields: Optional, a list with a specified set of fields
            of the resource to be returned.
        """

        rpc_fleet = api_utils.get_rpc_fleet(fleet_ident)
        cdict = pecan.request.context.to_policy_values()
        cdict['project'] = rpc_fleet.project
        policy.authorize('iot:fleet:get_one', cdict, cdict)

        return Fleet.convert_with_links(rpc_fleet, fields=fields)
Exemple #39
0
    def get_one(self, plugin_ident, fields=None):
        """Retrieve information about the given plugin.

        :param plugin_ident: UUID or logical name of a plugin.
        :param fields: Optional, a list with a specified set of fields
            of the resource to be returned.
        """

        rpc_plugin = api_utils.get_rpc_plugin(plugin_ident)
        if not rpc_plugin.public:
            cdict = pecan.request.context.to_policy_values()
            cdict['owner'] = rpc_plugin.owner
            policy.authorize('iot:plugin:get_one', cdict, cdict)

        return Plugin.convert_with_links(rpc_plugin, fields=fields)
Exemple #40
0
    def get_one(self, plugin_ident, fields=None):
        """Retrieve information about the given plugin.

        :param plugin_ident: UUID or logical name of a plugin.
        :param fields: Optional, a list with a specified set of fields
            of the resource to be returned.
        """

        rpc_plugin = api_utils.get_rpc_plugin(plugin_ident)
        if not rpc_plugin.public:
            cdict = pecan.request.context.to_policy_values()
            cdict['owner'] = rpc_plugin.owner
            policy.authorize('iot:plugin:get_one', cdict, cdict)

        return Plugin.convert_with_links(rpc_plugin, fields=fields)
Exemple #41
0
    def restore(self):
        rpc_board = api_utils.get_rpc_board(self.board_ident)

        try:
            cdict = pecan.request.context.to_policy_values()
            cdict['owner'] = rpc_board.owner
            policy.authorize('iot:service_action:post', cdict, cdict)

        except exception:
            return exception

        rpc_board.check_if_online()

        pecan.request.rpcapi.restore_services_on_board(pecan.request.context,
                                                       rpc_board.uuid)

        return self._get_services_on_board_collection(rpc_board.uuid)
Exemple #42
0
    def delete(self, plugin_uuid):
        """Remove a plugin from a board.

        :param plugin_ident: UUID or logical name of a plugin.
        :param board_ident: UUID or logical name of a board.
        """
        rpc_board = api_utils.get_rpc_board(self.board_ident)
        cdict = pecan.request.context.to_policy_values()
        cdict['owner'] = rpc_board.owner

        policy.authorize('iot:plugin_remove:delete', cdict, cdict)

        rpc_board.check_if_online()
        rpc_plugin = api_utils.get_rpc_plugin(plugin_uuid)
        return pecan.request.rpcapi.remove_plugin(pecan.request.context,
                                                  rpc_plugin.uuid,
                                                  rpc_board.uuid)
Exemple #43
0
    def delete(self, plugin_uuid):
        """Remove a plugin from a board.

        :param plugin_ident: UUID or logical name of a plugin.
        :param board_ident: UUID or logical name of a board.
        """
        rpc_board = api_utils.get_rpc_board(self.board_ident)
        cdict = pecan.request.context.to_policy_values()
        cdict['owner'] = rpc_board.owner

        policy.authorize('iot:plugin_remove:delete', cdict, cdict)

        rpc_board.check_if_online()
        rpc_plugin = api_utils.get_rpc_plugin(plugin_uuid)
        return pecan.request.rpcapi.remove_plugin(pecan.request.context,
                                                  rpc_plugin.uuid,
                                                  rpc_board.uuid)
Exemple #44
0
    def restore(self):
        rpc_board = api_utils.get_rpc_board(self.board_ident)

        try:
            cdict = pecan.request.context.to_policy_values()
            cdict['owner'] = rpc_board.owner
            policy.authorize('iot:service_action:post', cdict, cdict)

        except exception:
            return exception

        rpc_board.check_if_online()

        pecan.request.rpcapi.restore_services_on_board(
            pecan.request.context,
            rpc_board.uuid)

        return self._get_services_on_board_collection(rpc_board.uuid)
Exemple #45
0
    def detail(self,
               status=None,
               marker=None,
               limit=None,
               sort_key='id',
               sort_dir='asc',
               fields=None,
               project=None):
        """Retrieve a list of boards.

        :param status: Optional string value to get only board in
                                that status.
        :param marker: pagination marker for large data sets.
        :param limit: maximum number of resources to return in a single result.
                      This value cannot be larger than the value of max_limit
                      in the [api] section of the ironic configuration, or only
                      max_limit resources will be returned.
        :param sort_key: column to sort results by. Default: id.
        :param sort_dir: direction to sort. "asc" or "desc". Default: asc.
        :param project: Optional string value to get only boards
                        of the project.
        :param fields: Optional, a list with a specified set of fields
                       of the resource to be returned.
        """

        cdict = pecan.request.context.to_policy_values()
        policy.authorize('iot:board:get', cdict, cdict)

        # /detail should only work against collections
        parent = pecan.request.path.split('/')[:-1][-1]
        if parent != "boards":
            raise exception.HTTPNotFound()

        return self._get_boards_collection(status,
                                           marker,
                                           limit,
                                           sort_key,
                                           sort_dir,
                                           project=project,
                                           fields=fields)
Exemple #46
0
    def get_all(self,
                marker=None,
                limit=None,
                sort_key='id',
                sort_dir='asc',
                fields=None):
        """Retrieve a list of boards.

        :param marker: pagination marker for large data sets.
        :param limit: maximum number of resources to return in a single result.
                      This value cannot be larger than the value of max_limit
                      in the [api] section of the ironic configuration, or only
                      max_limit resources will be returned.
        :param sort_key: column to sort results by. Default: id.
        :param sort_dir: direction to sort. "asc" or "desc". Default: asc.
        :param fields: Optional, a list with a specified set of fields
                       of the resource to be returned.
        """
        cdict = pecan.request.context.to_policy_values()
        policy.authorize('iot:board:get', cdict, cdict)

        if fields is None:
            fields = _DEFAULT_BOARDS_RETURN_FIELDS

        filters = {}
        filters['fleet'] = self.fleet_ident

        boards = objects.Board.list(pecan.request.context,
                                    limit,
                                    marker,
                                    sort_key=sort_key,
                                    sort_dir=sort_dir,
                                    filters=filters)

        parameters = {'sort_key': sort_key, 'sort_dir': sort_dir}

        return BoardCollection.convert_with_links(boards,
                                                  limit,
                                                  fields=fields,
                                                  **parameters)
Exemple #47
0
    def detail(self,
               marker=None,
               limit=None,
               sort_key='id',
               sort_dir='asc',
               fields=None,
               with_public=False,
               all_plugins=False):
        """Retrieve a list of plugins.

        :param marker: pagination marker for large data sets.
        :param limit: maximum number of resources to return in a single result.
                      This value cannot be larger than the value of max_limit
                      in the [api] section of the ironic configuration, or only
                      max_limit resources will be returned.
        :param sort_key: column to sort results by. Default: id.
        :param sort_dir: direction to sort. "asc" or "desc". Default: asc.
        :param with_public: Optional boolean to get also public pluings.
        :param all_plugins: Optional boolean to get all the pluings.
                            Only for the admin
        :param fields: Optional, a list with a specified set of fields
                       of the resource to be returned.
        """

        cdict = pecan.request.context.to_policy_values()
        policy.authorize('iot:plugin:get', cdict, cdict)

        # /detail should only work against collections
        parent = pecan.request.path.split('/')[:-1][-1]
        if parent != "plugins":
            raise exception.HTTPNotFound()

        return self._get_plugins_collection(marker,
                                            limit,
                                            sort_key,
                                            sort_dir,
                                            with_public=with_public,
                                            all_plugins=all_plugins,
                                            fields=fields)
Exemple #48
0
    def post(self, Board):
        """Create a new Board.

        :param Board: a Board within the request body.
        """
        context = pecan.request.context
        cdict = context.to_policy_values()
        policy.authorize('iot:board:create', cdict, cdict)

        if not Board.name:
            raise exception.MissingParameterValue(
                ("Name is not specified."))
        if not Board.code:
            raise exception.MissingParameterValue(
                ("Code is not specified."))
        if not Board.location:
            raise exception.MissingParameterValue(
                ("Location is not specified."))

        if Board.name:
            if not api_utils.is_valid_board_name(Board.name):
                msg = ("Cannot create board with invalid name %(name)s")
                raise wsme.exc.ClientSideError(msg % {'name': Board.name},
                                               status_code=400)

        new_Board = objects.Board(pecan.request.context,
                                  **Board.as_dict())

        new_Board.owner = pecan.request.context.user_id
        new_Board.project = pecan.request.context.project_id

        new_Location = objects.Location(pecan.request.context,
                                        **Board.location[0].as_dict())

        new_Board = pecan.request.rpcapi.create_board(pecan.request.context,
                                                      new_Board, new_Location)

        return Board.convert_with_links(new_Board)
Exemple #49
0
    def post(self, plugin_ident, PluginAction):

        if not PluginAction.action:
            raise exception.MissingParameterValue(
                ("Action is not specified."))

        if not PluginAction.parameters:
            PluginAction.parameters = {}

        rpc_board = api_utils.get_rpc_board(self.board_ident)
        rpc_plugin = api_utils.get_rpc_plugin(plugin_ident)

        try:
            cdict = pecan.request.context.to_policy_values()
            cdict['owner'] = rpc_board.owner
            policy.authorize('iot:plugin_action:post', cdict, cdict)

            if not rpc_plugin.public:
                cdict = pecan.request.context.to_policy_values()
                cdict['owner'] = rpc_plugin.owner
                policy.authorize('iot:plugin_action:post', cdict, cdict)
        except exception:
            return exception

        rpc_board.check_if_online()

        if objects.plugin.want_customs_params(PluginAction.action):
            valid_keys = list(rpc_plugin.parameters.keys())
            if not all(k in PluginAction.parameters for k in valid_keys):
                raise exception.InvalidParameterValue(
                    "Parameters are different from the valid ones")

        result = pecan.request.rpcapi.action_plugin(pecan.request.context,
                                                    rpc_plugin.uuid,
                                                    rpc_board.uuid,
                                                    PluginAction.action,
                                                    PluginAction.parameters)
        return result
Exemple #50
0
    def patch(self, board_ident, val_Board):
        """Update a board.

        :param board_ident: UUID or logical name of a board.
        :param Board: values to be changed
        :return updated_board: updated_board
        """

        context = pecan.request.context
        cdict = context.to_policy_values()
        policy.authorize('iot:board:update', cdict, cdict)

        board = api_utils.get_rpc_board(board_ident)
        val_Board = val_Board.as_dict()
        for key in val_Board:
            try:
                board[key] = val_Board[key]
            except Exception:
                pass

        updated_board = pecan.request.rpcapi.update_board(
            pecan.request.context, board)
        return Board.convert_with_links(updated_board)
Exemple #51
0
    def patch(self, fleet_ident, val_Fleet):
        """Update a fleet.

        :param fleet_ident: UUID or logical name of a fleet.
        :param Fleet: values to be changed
        :return updated_fleet: updated_fleet
        """

        rpc_fleet = api_utils.get_rpc_fleet(fleet_ident)
        cdict = pecan.request.context.to_policy_values()
        cdict['project'] = rpc_fleet.project
        policy.authorize('iot:fleet:update', cdict, cdict)

        val_Fleet = val_Fleet.as_dict()
        for key in val_Fleet:
            try:
                rpc_fleet[key] = val_Fleet[key]
            except Exception:
                pass

        updated_fleet = pecan.request.rpcapi.update_fleet(
            pecan.request.context, rpc_fleet)
        return Fleet.convert_with_links(updated_fleet)
Exemple #52
0
    def patch(self, plugin_ident, val_Plugin):
        """Update a plugin.

        :param plugin_ident: UUID or logical name of a plugin.
        :param Plugin: values to be changed
        :return updated_plugin: updated_plugin
        """

        rpc_plugin = api_utils.get_rpc_plugin(plugin_ident)
        cdict = pecan.request.context.to_policy_values()
        cdict['owner'] = rpc_plugin.owner
        policy.authorize('iot:plugin:update', cdict, cdict)

        val_Plugin = val_Plugin.as_dict()
        for key in val_Plugin:
            try:
                rpc_plugin[key] = val_Plugin[key]
            except Exception:
                pass

        updated_plugin = pecan.request.rpcapi.update_plugin(
            pecan.request.context, rpc_plugin)
        return Plugin.convert_with_links(updated_plugin)
Exemple #53
0
    def patch(self, plugin_ident, val_Plugin):
        """Update a plugin.

        :param plugin_ident: UUID or logical name of a plugin.
        :param Plugin: values to be changed
        :return updated_plugin: updated_plugin
        """

        rpc_plugin = api_utils.get_rpc_plugin(plugin_ident)
        cdict = pecan.request.context.to_policy_values()
        cdict['owner'] = rpc_plugin.owner
        policy.authorize('iot:plugin:update', cdict, cdict)

        val_Plugin = val_Plugin.as_dict()
        for key in val_Plugin:
            try:
                rpc_plugin[key] = val_Plugin[key]
            except Exception:
                pass

        updated_plugin = pecan.request.rpcapi.update_plugin(
            pecan.request.context, rpc_plugin)
        return Plugin.convert_with_links(updated_plugin)
Exemple #54
0
    def action(self, service_ident, ServiceAction):

        if not ServiceAction.action:
            raise exception.MissingParameterValue(("Action is not specified."))

        rpc_board = api_utils.get_rpc_board(self.board_ident)
        rpc_service = api_utils.get_rpc_service(service_ident)

        try:
            cdict = pecan.request.context.to_policy_values()
            cdict['owner'] = rpc_board.owner
            policy.authorize('iot:service_action:post', cdict, cdict)

        except exception:
            return exception

        rpc_board.check_if_online()

        result = pecan.request.rpcapi.action_service(pecan.request.context,
                                                     rpc_service.uuid,
                                                     rpc_board.uuid,
                                                     ServiceAction.action)
        return result
Exemple #55
0
    def patch(self, service_ident, val_Service):
        """Update a service.

        :param service_ident: UUID or logical name of a service.
        :param Service: values to be changed
        :return updated_service: updated_service
        """

        rpc_service = api_utils.get_rpc_service(service_ident)
        cdict = pecan.request.context.to_policy_values()
        cdict['project'] = rpc_service.project
        policy.authorize('iot:service:update', cdict, cdict)

        val_Service = val_Service.as_dict()
        for key in val_Service:
            try:
                rpc_service[key] = val_Service[key]
            except Exception:
                pass

        updated_service = pecan.request.rpcapi.update_service(
            pecan.request.context, rpc_service)
        return Service.convert_with_links(updated_service)
Exemple #56
0
    def patch(self, fleet_ident, val_Fleet):
        """Update a fleet.

        :param fleet_ident: UUID or logical name of a fleet.
        :param Fleet: values to be changed
        :return updated_fleet: updated_fleet
        """

        rpc_fleet = api_utils.get_rpc_fleet(fleet_ident)
        cdict = pecan.request.context.to_policy_values()
        cdict['project'] = rpc_fleet.project
        policy.authorize('iot:fleet:update', cdict, cdict)

        val_Fleet = val_Fleet.as_dict()
        for key in val_Fleet:
            try:
                rpc_fleet[key] = val_Fleet[key]
            except Exception:
                pass

        updated_fleet = pecan.request.rpcapi.update_fleet(
            pecan.request.context, rpc_fleet)
        return Fleet.convert_with_links(updated_fleet)
Exemple #57
0
    def patch(self, service_ident, val_Service):
        """Update a service.

        :param service_ident: UUID or logical name of a service.
        :param Service: values to be changed
        :return updated_service: updated_service
        """

        rpc_service = api_utils.get_rpc_service(service_ident)
        cdict = pecan.request.context.to_policy_values()
        cdict['project'] = rpc_service.project
        policy.authorize('iot:service:update', cdict, cdict)

        val_Service = val_Service.as_dict()
        for key in val_Service:
            try:
                rpc_service[key] = val_Service[key]
            except Exception:
                pass

        updated_service = pecan.request.rpcapi.update_service(
            pecan.request.context, rpc_service)
        return Service.convert_with_links(updated_service)
Exemple #58
0
    def post(self, plugin_ident, PluginAction):

        if not PluginAction.action:
            raise exception.MissingParameterValue(("Action is not specified."))

        if not PluginAction.parameters:
            PluginAction.parameters = {}

        rpc_board = api_utils.get_rpc_board(self.board_ident)
        rpc_plugin = api_utils.get_rpc_plugin(plugin_ident)

        try:
            cdict = pecan.request.context.to_policy_values()
            cdict['owner'] = rpc_board.owner
            policy.authorize('iot:plugin_action:post', cdict, cdict)

            if not rpc_plugin.public:
                cdict = pecan.request.context.to_policy_values()
                cdict['owner'] = rpc_plugin.owner
                policy.authorize('iot:plugin_action:post', cdict, cdict)
        except exception:
            return exception

        rpc_board.check_if_online()

        if objects.plugin.want_customs_params(PluginAction.action):
            valid_keys = list(rpc_plugin.parameters.keys())
            if not all(k in PluginAction.parameters for k in valid_keys):
                raise exception.InvalidParameterValue(
                    "Parameters are different from the valid ones")

        result = pecan.request.rpcapi.action_plugin(pecan.request.context,
                                                    rpc_plugin.uuid,
                                                    rpc_board.uuid,
                                                    PluginAction.action,
                                                    PluginAction.parameters)
        return result
Exemple #59
0
    def patch(self, board_ident, val_Board):
        """Update a board.

        :param board_ident: UUID or logical name of a board.
        :param Board: values to be changed
        :return updated_board: updated_board
        """

        context = pecan.request.context
        cdict = context.to_policy_values()
        policy.authorize('iot:board:update', cdict, cdict)

        board = api_utils.get_rpc_board(board_ident)
        val_Board = val_Board.as_dict()
        for key in val_Board:
            try:
                board[key] = val_Board[key]
            except Exception:
                pass

        updated_board = pecan.request.rpcapi.update_board(
            pecan.request.context,
            board)
        return Board.convert_with_links(updated_board)