Beispiel #1
0
                    'target': obj.id,
                }
                self.append_node(obj.id, ret_dict, recursive_cnt - 1)

    def get(self):
        t_start = datetime.datetime.now()
        work_dict = {'nodes': {}, 'links': {}}
        param_id = request.args.get('id')
        if param_id is None:
            work_dict = {'nodes': [{'id': "_"}], 'links': []}
            return work_dict, 200
        self.append_node(param_id, work_dict, recursive_cnt=3)
        ret_dict = {
            'nodes': list(work_dict['nodes'].values()),
            'links': list(work_dict['links'].values())
        }
        t_delta = int(
            (datetime.datetime.now() - t_start).total_seconds() * 1000)
        return ret_dict, 200, {
            'Access-Control-Expose-Headers': 'X-Total-Count',
            'X-Perf-MSec': t_delta,
        }


@blueprint.before_app_first_request
def register_views():
    apispec.spec.path(view=GraphData, app=current_app)


api.add_resource(GraphData, '/graph_data')
Beispiel #2
0
        return ret_list, 200, {
            'Access-Control-Expose-Headers': 'X-Total-Count',
            'X-Total-Count': total_cnt,
            'Cache-Control': 'max-age=300'
        }

    @ttl_cache(120.0)  # noqa
    def post(self):
        return self.get()

    @ttl_cache(120.0)  # noqa
    def options(self):
        query = db.session.query(Node)
        query = self.filter_id(query)
        query = self.filter_aspect(query)
        query = self.filter_search(query)
        total_cnt = query.count()
        return None, 204, {
            'Access-Control-Expose-Headers': 'X-Total-Count',
            'X-Total-Count': total_cnt,
            'Cache-Control': 'max-age=300'
        }


@blueprint.before_app_first_request
def register_views():
    apispec.spec.path(view=NodeList, app=current_app)


api.add_resource(NodeList, '/nodes')
Beispiel #3
0
            enum:
              - asc
              - desc
          description: asc/desc
      responses:
        '204':
          description: get options was successfully.
          headers:
            Access-Control-Expose-Headers:
              schema:
                type: string
                example: X-Total-Count
            X-Total-Count:
              schema:
                type: integer
              description: Number of results.
    """
    FILTER_CONTEXT = Config.D3URI_CONTEXT + "/function.jsonld"

    def filter_my_aspect(self, query):
        query = query.filter(Node.aspect == 'function')
        return query


@blueprint.before_app_first_request
def register_views():
    apispec.spec.path(view=FunctionList, app=current_app)


api.add_resource(FunctionList, '/functions')
Beispiel #4
0
        query = query.order_by(asc(Node.json['d3_type'].astext))
        total_cnt = query.count()
        json_list = [{
            '@id': i[0],
            'search_d3_type': i[0],
            'name': i[0]
        } for i in query.all()]
        return json_list, 200, {
            'Access-Control-Expose-Headers': 'X-Total-Count',
            'X-Total-Count': total_cnt,
            'Cache-Control': 'max-age=300'
        }

    @staticmethod
    def options():
        query = db.session.query(Node)
        total_cnt = query.count()
        return None, 204, {
            'Access-Control-Expose-Headers': 'X-Total-Count',
            'X-Total-Count': total_cnt,
            'Cache-Control': 'max-age=300'
        }


@blueprint.before_app_first_request
def register_views():
    apispec.spec.path(view=D3TypeList, app=current_app)


api.add_resource(D3TypeList, '/d3_types')
Beispiel #5
0
                'X-Perf-3-MSec': t_delta3,
                'X-Perf-4-MSec': t_delta4,
            }
        else:
            return_list = []
            jsonld_proc = jsonld.JsonLdProcessor()
            for expanded_node in expanded_list:
                compacted_node = jsonld_proc.compact(expanded_node,
                                                     compact,
                                                     options=None)
                return_list.append(compacted_node)
            t_delta5 = int(
                (datetime.datetime.now() - t_start).total_seconds() * 1000)
            return return_list, 200, {
                'Access-Control-Expose-Headers': 'X-Total-Count',
                'X-Total-Count': len(return_list),
                'X-Perf-1-MSec': t_delta1,
                'X-Perf-2-MSec': t_delta2,
                'X-Perf-3-MSec': t_delta3,
                'X-Perf-4-MSec': t_delta4,
                'X-Perf-5-MSec': t_delta5,
            }


@blueprint.before_app_first_request
def register_views():
    apispec.spec.path(view=NodeExport, app=current_app)


api.add_resource(NodeExport, '/export')
Beispiel #6
0
      responses:
        200:
          content:
            application/json:
              schema: AspectListSchema
    """
    @ttl_cache(60.0)  # noqa
    def get(self):
        query = db.session.query(Node.json['guest_os'].astext)
        query = self.filter_aspect(query)
        query = query.filter(
            or_(Node.context == Config.D3URI_CONTEXT + "/vmware_vm.jsonld",
                Node.context == Config.D3URI_CONTEXT + "/cps_linux.jsonld"))
        query = query.group_by(Node.json['guest_os'].astext)
        query = query.order_by(asc(Node.json['guest_os'].astext))
        total_cnt = query.count()
        json_list = [{'@id': i[0], 'name': i[0]} for i in query.all()]
        return json_list, 200, {
            'Access-Control-Expose-Headers': 'X-Total-Count',
            'X-Total-Count': total_cnt,
            'Cache-Control': 'max-age=300'
        }


@blueprint.before_app_first_request
def register_views():
    apispec.spec.path(view=ReportVmOS, app=current_app)


api.add_resource(ReportVmOS, '/report_vm_os')
Beispiel #7
0
            for tag in tags:
                if type(tag) is list:
                    for subtag in tag:
                        tag_set.add(subtag)
                else:
                    tag_set.add(tag)
        return tag_set

    def get(self):
        param_ids = self.get_requested_ids()
        tag_set = self.get_all_tags()
        if param_ids:
            tag_set = tag_set.intersection(set(param_ids))
        json_list = [{'@id': i, 'name': i} for i in tag_set]
        return json_list, 200, {
            'Access-Control-Expose-Headers': 'X-Total-Count',
            'X-Total-Count': len(json_list),
            'Cache-Control': 'max-age=300'
        }

    def post(self):
        return self.get()


@blueprint.before_app_first_request
def register_views():
    apispec.spec.path(view=TagList, app=current_app)


api.add_resource(TagList, '/tags')
Beispiel #8
0
      tags:
      - locations
      summary: aspect by its uuid
      parameters:
        - in: path
          schema: UuidInputSchema
        - in: path2
          schema: UuidInputSchema
      responses:
        200:
          content:
            application/json:
              schema: LocationSchema
        404:
          content:
            application/json:
              schema: ErrorSchema
    """
    # ToDo: update apidoc strings


@blueprint.before_app_first_request
def register_views():
    apispec.spec.path(view=LocationById, app=current_app)
    apispec.spec.path(view=LocationByIdAndContext, app=current_app)


api.add_resource(LocationByIdAndContext,
                 '/locations/<uuid:query_id>/<path:context>')
api.add_resource(LocationById, '/locations/<uuid:query_id>')
Beispiel #9
0
            enum:
              - asc
              - desc
          description: asc/desc
      responses:
        '204':
          description: get options was successfully.
          headers:
            Access-Control-Expose-Headers:
              schema:
                type: string
                example: X-Total-Count
            X-Total-Count:
              schema:
                type: integer
              description: Number of results.
    """
    FILTER_CONTEXT = Config.D3URI_CONTEXT + "/location.jsonld"

    def filter_my_aspect(self, query):
        query = query.filter(Node.aspect == 'location')
        return query


@blueprint.before_app_first_request
def register_views():
    apispec.spec.path(view=LocationList, app=current_app)


api.add_resource(LocationList, '/locations')
Beispiel #10
0
    get:
      tags:
      - products
      summary: aspect by its uuid
      parameters:
        - in: path
          schema: UuidInputSchema
        - in: path2
          schema: UuidInputSchema
      responses:
        200:
          content:
            application/json:
              schema: ProductSchema
        404:
          content:
            application/json:
              schema: ErrorSchema
    """
    # ToDo: update apidoc strings


@blueprint.before_app_first_request
def register_views():
    apispec.spec.path(view=ProductById, app=current_app)


api.add_resource(ProductByIdAndContext,
                 '/products/<uuid:query_id>/<path:context>')
api.add_resource(ProductById, '/products/<uuid:query_id>')
Beispiel #11
0
      summary: all aspects
      responses:
        200:
          content:
            application/json:
              schema: AspectListSchema
    """

    @ttl_cache(120.0)  # noqa
    def get(self):
        query = db.session.query(Node.json['scope'].astext)
        query = self.filter_aspect(query)
        query = query.filter(Node.context == Config.D3URI_CONTEXT + "/base.jsonld")
        query = query.group_by(Node.json['scope'].astext)
        query = query.order_by(asc(Node.json['scope'].astext))
        total_cnt = query.count()
        json_list = [{'@id': i[0],
                      'name': i[0]} for i in query.all()]
        return json_list, 200, {'Access-Control-Expose-Headers': 'X-Total-Count',
                                'X-Total-Count': total_cnt,
                                'Cache-Control': 'max-age=300'
                                }


@blueprint.before_app_first_request
def register_views():
    apispec.spec.path(view=ScopeList, app=current_app)


api.add_resource(ScopeList, '/scopes')
Beispiel #12
0
        - in: query
          name: order
          schema:
            type: string
            enum:
              - asc
              - desc
          description: asc/desc
      responses:
        '204':
          description: get options was successfully.
          headers:
            Access-Control-Expose-Headers:
              schema:
                type: string
                example: X-Total-Count
            X-Total-Count:
              schema:
                type: integer
              description: Number of results.
    """
    FILTER_CONTEXT = Config.D3URI_CONTEXT + "/product.jsonld"


@blueprint.before_app_first_request
def register_views():
    apispec.spec.path(view=ProductList, app=current_app)


api.add_resource(ProductList, '/products')
Beispiel #13
0
    get:
      tags:
      - nodes
      summary: aspect by its uuid
      parameters:
        - in: path
          schema: UuidInputSchema
        - in: path2
          schema: UuidInputSchema
      responses:
        200:
          content:
            application/json:
              schema: NodeSchema
        404:
          content:
            application/json:
              schema: ErrorSchema
    """
    FILTER_ASPECT = 'node'


@blueprint.before_app_first_request
def register_views():
    apispec.spec.path(view=NodeById, app=current_app)
    apispec.spec.path(view=NodeByIdAndContext, app=current_app)


api.add_resource(NodeByIdAndContext, '/nodes/<uuid:query_id>/<path:context>')
api.add_resource(NodeById, '/nodes/<uuid:query_id>')
Beispiel #14
0
    ---
    get:
      tags:
      - aspects
      summary: all aspects
      responses:
        200:
          content:
            application/json:
              schema: AspectListSchema
    """
    @staticmethod
    def get():
        return ASPECTS, 200, {
            'Access-Control-Expose-Headers': 'X-Total-Count',
            'X-Total-Count': len(ASPECTS),
            'Cache-Control': 'max-age=300'
        }


@blueprint.before_app_first_request
def register_views():
    apispec.spec.path(view=AspectById, app=current_app)
    apispec.spec.path(view=AspectByName, app=current_app)
    apispec.spec.path(view=AspectList, app=current_app)


api.add_resource(AspectList, '/aspects')
api.add_resource(AspectById, '/aspects/uuid/<uuid:obj_id>')
api.add_resource(AspectByName, '/aspects/name/<string:name>')
Beispiel #15
0
      summary: all vm guest operating systems
      responses:
        200:
          content:
            application/json:
              schema: AspectListSchema
    """

    @ttl_cache(60.0)  # noqa
    def get(self):
        query = db.session.query(Node.json['power_state'].astext)
        query = self.filter_aspect(query)
        query = query.filter(Node.context == Config.D3URI_CONTEXT + "/vmware_vm.jsonld")
        query = query.group_by(Node.json['power_state'].astext)
        query = query.order_by(asc(Node.json['power_state'].astext))
        total_cnt = query.count()
        json_list = [{'@id': i[0],
                      'name': i[0]} for i in query.all()]
        return json_list, 200, {'Access-Control-Expose-Headers': 'X-Total-Count',
                                'X-Total-Count': total_cnt,
                                'Cache-Control': 'max-age=300'
                                }


@blueprint.before_app_first_request
def register_views():
    apispec.spec.path(view=ReportPowerState, app=current_app)


api.add_resource(ReportPowerState, '/report_power_state')
Beispiel #16
0
    get:
      tags:
      - functions
      summary: aspect by its uuid
      parameters:
        - in: path
          schema: UuidInputSchema
        - in: path2
          schema: UuidInputSchema
      responses:
        200:
          content:
            application/json:
              schema: FunctionSchema
        404:
          content:
            application/json:
              schema: ErrorSchema
    """
    # ToDo: update apidoc strings


@blueprint.before_app_first_request
def register_views():
    apispec.spec.path(view=FunctionById, app=current_app)
    apispec.spec.path(view=FunctionByIdAndContext, app=current_app)


api.add_resource(FunctionByIdAndContext, '/functions/<uuid:query_id>/<path:context>')
api.add_resource(FunctionById, '/functions/<uuid:query_id>')