forked from nocproject/noc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathservice.py
34 lines (26 loc) · 1.12 KB
/
service.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# ----------------------------------------------------------------------
# Service command
# ----------------------------------------------------------------------
# Copyright (C) 2007-2020 The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------
# Python modules
import argparse
# NOC modules
from noc.core.management.base import BaseCommand
from noc.core.service.loader import get_service
from noc.core.text import format_table
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument("services", nargs=argparse.REMAINDER, help="Service names")
def handle(self, services=None, *args, **options):
service = get_service()
out = [["Service", "ID", "Address"]]
for sn in services:
service.dcs.resolve_sync(sn)
if sn in service.dcs.resolvers:
for svc_id, address in service.dcs.resolvers[sn].services.items():
out += [[sn, svc_id, address]]
self.stdout.write(format_table([0, 0, 0, 0, 0], out) + "\n")
if __name__ == "__main__":
Command().run()