From 5ece0f5d1a550c9c90b6860215fe9b3a1e46a812 Mon Sep 17 00:00:00 2001 From: Yutaro Date: Thu, 5 Apr 2018 19:04:03 +0200 Subject: [PATCH 1/2] script to dump link commands --- scripts/linklist.py | 75 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 scripts/linklist.py diff --git a/scripts/linklist.py b/scripts/linklist.py new file mode 100644 index 0000000..891ea19 --- /dev/null +++ b/scripts/linklist.py @@ -0,0 +1,75 @@ +import os +import sys +import urllib +import urllib2 +import httplib +import json + +# Sites to have links to/from disabled completely +disabled_nodes = ['T2_BR_UERJ', 'T2_PK_NCP', 'T2_RU_PNPI', 'T2_RU_SINP', 'T2_TH_CUNSTDA', 'T2_RU_ITEP'] # [node] +# Specific links to disable +disabled_links = [] # [(to, from)] +# Sites to not touch (e.g. being commissioned) - T3s are also skipped +skipped_nodes = ['T2_PK_NCP'] + +x509_proxy = '/tmp/x509up_u%d' % os.getuid() + +def httpsconnection(host, timeout = 0): + return httplib.HTTPSConnection(host, key_file = x509_proxy, cert_file = x509_proxy) + +class X509Handler(urllib2.HTTPSHandler): + def https_open(self, request): + return self.do_open(httpsconnection, request) + +def datasvc(command, args = []): + url = 'https://cmsweb.cern.ch/phedex/datasvc/json/prod/' + command + if len(args): + url += '?' + '&'.join(args) + + request = urllib2.Request(url) + + opener = urllib2.build_opener(X509Handler()) + opener.addheaders.append(('Accept', 'application/json')) + response = opener.open(request) + + return json.loads(response.read())['phedex'] + +if __name__ == '__main__': + from argparse import ArgumentParser + + argParser = ArgumentParser(description = 'Dump the link commands.') + argParser.add_argument('--current', '-c', action = 'store_true', dest = 'current', help = 'Dump current state.') + + args = argParser.parse_args() + sys.argv = [] + + result = datasvc('nodes') + nodes = sorted(n['name'] for n in result['node'] if not n['name'].startswith('T3') and n['name'] not in skipped_nodes) + + result = datasvc('links') + links = {} + for link in result['link']: + links[(link['from'], link['to'])] = link['status'] + + for from_node in list(nodes): + for to_node in list(nodes): + try: + current = links[(from_node, to_node)] + except KeyError: + continue + + # Will not touch links that are not in ok or deactivated states + if current not in ['ok', 'deactivated']: + continue + + if args.current: + if current == 'ok': + print from_node, to_node, 'enable' + else: + print from_node, to_node, 'disable' + + else: + if from_node in disabled_nodes or to_node in disabled_nodes or (from_node, to_node) in disabled_links: + print from_node, to_node, 'disable' + else: + print from_node, to_node, 'enable' From 6cd06039b89d0120c1bce4ca7722f21bb7f035d5 Mon Sep 17 00:00:00 2001 From: Yutaro Date: Tue, 10 Apr 2018 16:42:51 +0200 Subject: [PATCH 2/2] updated site list --- scripts/linklist.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/linklist.py b/scripts/linklist.py index 891ea19..5f5694f 100644 --- a/scripts/linklist.py +++ b/scripts/linklist.py @@ -6,7 +6,7 @@ import json # Sites to have links to/from disabled completely -disabled_nodes = ['T2_BR_UERJ', 'T2_PK_NCP', 'T2_RU_PNPI', 'T2_RU_SINP', 'T2_TH_CUNSTDA', 'T2_RU_ITEP'] # [node] +disabled_nodes = ['T2_BR_UERJ', 'T2_RU_PNPI', 'T2_RU_SINP', 'T2_TH_CUNSTDA'] # [node] # Specific links to disable disabled_links = [] # [(to, from)] # Sites to not touch (e.g. being commissioned) - T3s are also skipped @@ -52,12 +52,15 @@ def datasvc(command, args = []): links[(link['from'], link['to'])] = link['status'] for from_node in list(nodes): + if from_node != 'T2_PK_NCP': + continue + for to_node in list(nodes): try: current = links[(from_node, to_node)] except KeyError: continue - + # Will not touch links that are not in ok or deactivated states if current not in ['ok', 'deactivated']: continue