コード例 #1
0
ファイル: maplinks.py プロジェクト: vigilo/turbogears
 def get_one(self, idmaplink):
     # pylint:disable-msg=C0111,R0201
     link = DBSession.query(tables.MapLink).get(idmaplink)
     check_map_access(link.map)
     baseurl = tg.url("/api/v%s" % self.apiver)
     result = {"id": link.idmaplink,
               "from": {
                   "id": link.idfrom_node,
                   "href": baseurl + "/mapnodes/%s" % link.idfrom_node,
                   },
               "to": {
                   "id": link.idto_node,
                   "href": baseurl + "/mapnodes/%s" % link.idto_node,
                   },
               "href": baseurl + "/maps/%s/links/%s" %
                                 (link.map.idmap, link.idmaplink),
               }
     # Spécifique MapServiceLink
     if isinstance(link, tables.MapServiceLink):
         if link.idgraph:
             result["graph"] = {
                     "id": link.idgraph,
                     "href": baseurl + "/graphs/%s" % link.idgraph
                     }
         datasources = {}
         if link.idds_out:
             datasources["out"] = {
                     "id": link.idds_out,
                     "href": baseurl + "/perfdatasources/%s"
                                       % link.idds_out,
                     }
         if link.idds_in:
             datasources["in"] = {
                     "id": link.idds_in,
                     "href": baseurl + "/perfdatasources/%s"
                                       % link.idds_in,
                     }
         result["perfdatasources"] = datasources
         result["supitem"] = {"id": link.idref}
         if isinstance(link, tables.MapLlsLink):
             result["supitem"]["type"] = "lls"
             result["supitem"]["href"] = baseurl + "/lls/%s" % link.idref
         elif isinstance(link, tables.MapHlsLink):
             result["supitem"]["type"] = "hls"
             result["supitem"]["href"] = baseurl + "/hls/%s" % link.idref
     # Spécifique MapSegment
     elif isinstance(link, tables.MapSegment):
         result["color"] = link.color,
         result["thickness"] = link.thickness
     return dict(link=result)
コード例 #2
0
ファイル: maps.py プロジェクト: vigilo/turbogears
 def get_one(self, idmap):
     # pylint:disable-msg=C0111,R0201
     m = DBSession.query(Map).get(idmap)
     if m is None:
         raise HTTPNotFound("Can't find map %s" % idmap)
     check_map_access(m)
     baseurl = tg.url("/api/v%s/maps/%s" % (self.apiver, m.idmap))
     result = {"id": m.idmap,
               "title": m.title,
               "mtime": m.mtime.isoformat(),
               "generated": m.generated,
               "background": {
                   "color": m.background_color,
                   "image": m.background_image,
                   "position": m.background_position,
                   "repeat": m.background_repeat,
                   },
               "href": baseurl,
               }
     # groups
     result["groups_href"] = baseurl+"/groups/"
     groups = []
     for group in m.groups:
         groups.append({
             "id": group.idgroup,
             "name": group.name,
             "href": tg.url("/api/v%s/mapgroups/%s" % (self.apiver, group.idgroup)),
             })
     result["groups"] = groups
     # nodes
     result["nodes_href"] = baseurl+"/nodes/"
     nodes = []
     for node in m.nodes:
         nodes.append({
             "id": node.idmapnode,
             "href": "%s/nodes/%s" % (baseurl, node.idmapnode)
             })
     result["nodes"] = nodes
     # links
     result["links_href"] = baseurl+"/links/"
     links = []
     for link in DBSession.query(MapLink).filter_by(
                                 idmap=idmap).all():
         links.append({
             "id": link.idmaplink,
             "href": "%s/links/%s" % (baseurl, link.idmaplink)
             })
     result["links"] = links
     return dict(map=result)
コード例 #3
0
ファイル: mapnodes.py プロジェクト: vigilo/turbogears
 def get_all(self):
     # pylint:disable-msg=C0111,R0201
     idmap = get_parent_id("maps")
     if idmap is not None:
         m = DBSession.query(tables.Map).get(idmap)
     else:
         raise HTTPNotFound("The URL seems invalid (no map found)")
     if m is None:
         raise HTTPNotFound("The map %s does not exist" % idmap)
     check_map_access(m)
     result = []
     for node in m.nodes:
         result.append({
             "id": node.idmapnode,
             "href": tg.url("/api/v%s/maps/%s/nodes/%s"
                            % (self.apiver, idmap, node.idmapnode)),
             })
     return dict(mapnodes=result)
コード例 #4
0
ファイル: maplinks.py プロジェクト: vigilo/turbogears
 def get_all(self):
     # pylint:disable-msg=C0111,R0201
     idmap = get_parent_id("maps")
     if idmap is not None:
         m = DBSession.query(tables.Map).get(idmap)
     else:
         raise HTTPNotFound("The URL seems invalid (no map found)")
     if m is None:
         raise HTTPNotFound("The map %s does not exist" % idmap)
     check_map_access(m)
     links = DBSession.query(tables.MapLink).filter_by(idmap=idmap).all()
     result = []
     for link in links:
         result.append({
             "id": link.idmaplink,
             "href": tg.url("/api/v%s/maps/%s/links/%s"
                            % (self.apiver, idmap, link.idmaplink)),
             })
     return dict(maplinks=result)
コード例 #5
0
ファイル: mapnodes.py プロジェクト: vigilo/turbogears
 def get_one(self, idmapnode):
     # pylint:disable-msg=C0111,R0201
     node = DBSession.query(tables.MapNode).get(idmapnode)
     check_map_access(node.map)
     baseurl = tg.url("/api/v%s" % self.apiver)
     result = {
             "id": node.idmapnode,
             "label": node.label,
             "x": node.x_pos,
             "y": node.y_pos,
             "widget": node.widget,
             "type": node.type_node,
             "icon": node.icon,
             "href": baseurl + "/maps/%s/nodes/%s"
                               % (node.map.idmap, node.idmapnode),
             }
     submaps = []
     for submap in node.submaps:
         submaps.append({
             "id": submap.idmap,
             "href": baseurl + "/maps/%s" % submap.idmap,
             "title": submap.title,
             })
     result["submaps"] = submaps
     if isinstance(node, tables.MapNodeHost):
         result["supitem"] = {
                 "id": node.idhost,
                 "href": baseurl + "/hosts/%s" % node.idhost,
                 }
     elif isinstance(node, tables.MapNodeLls):
         result["supitem"] = {
                 "id": node.idservice,
                 "href": baseurl + "/lls/%s" % node.idservice,
                 }
     elif isinstance(node, tables.MapNodeHls):
         result["supitem"] = {
                 "id": node.idservice,
                 "href": baseurl + "/hls/%s" % node.idservice,
                 }
     return dict(mapnode=result)