[Qa-jenkins-scm] [Git][qa/jenkins.debian.net][master] bin/powercycle_x86_nodes: reformat using black, and use proper logging
Mattia Rizzolo
gitlab at salsa.debian.org
Wed Dec 11 16:23:08 GMT 2019
Mattia Rizzolo pushed to branch master at Debian QA / jenkins.debian.net
Commits:
325b9f57 by Mattia Rizzolo at 2019-12-11T16:21:47Z
bin/powercycle_x86_nodes: reformat using black, and use proper logging
Signed-off-by: Mattia Rizzolo <mattia at debian.org>
- - - - -
1 changed file:
- bin/powercycle_x86_nodes.py
Changes:
=====================================
bin/powercycle_x86_nodes.py
=====================================
@@ -3,45 +3,56 @@
# Copyright 2019 Holger Levsen <holger at layer-acht.org>
# released under the GPLv2
-from profitbricks.client import ProfitBricksService
-import json
import os
import sys
+import json
+import logging
+
+from profitbricks.client import ProfitBricksService
+
+
+log = logging.getLogger(__name__)
+_ch = logging.StreamHandler()
+_ch.setFormatter(logging.Formatter(("%(levelname)s: %(message)s")))
+log.addHandler(_ch)
+log.setLevel(logging.INFO)
+# log.setLevel(logging.DEBUG)
# expects node numbers or 'jenkins' as params...
-nodes=[]
-for argument in sys.argv:
+nodes = []
+for argument in sys.argv[1:]:
try:
- node=int(argument)
- name=('build'+str(node))
+ node = int(argument)
+ except ValueError:
+ # argument wasn't an integer
+ if argument == "jenkins":
+ nodes.append(argument)
+ else:
+ log.error("Unrecognized node: %s", argument)
+ sys.exit(1)
+ else:
+ name = "build" + str(node)
nodes.append(name)
- except:
- try:
- if argument=='jenkins':
- nodes.append(argument)
- except:
- pass
-#for node in nodes:
-# print (node)
+log.debug("Acting on nodes: %s", nodes)
client = ProfitBricksService(
- username=os.getenv('IONOS_USERNAME'),
- password=os.getenv('IONOS_PASSWORD'))
+ username=os.getenv("IONOS_USERNAME"), password=os.getenv("IONOS_PASSWORD")
+)
response = client.list_datacenters(0)
-#print (json.dumps(response, indent=4))
+log.debug(json.dumps(response, indent=4))
-for item in response['items']:
- datacenter=item['id']
- #print (datacenter)
+for item in response["items"]:
+ datacenter = item["id"]
+ log.debug(datacenter)
response = client.list_servers(datacenter_id=datacenter)
- #print (json.dumps(response, indent=4))
- for item in response['items']:
- #print (item['id'])
- #print (item['type'])
+ log.debug(json.dumps(response, indent=4))
+ for item in response["items"]:
+ log.debug(item['id'])
+ log.debug(item['type'])
for server in nodes:
- if item['type'] == 'server' and item['properties']['name'] == server:
- print ('Rebooting '+item['properties']['name']+' aka '+server)
- result = client.reboot_server(datacenter, item['id'])
- print (result)
+ if item["type"] == "server" and item["properties"]["name"] == server:
+ log.info("Rebooting " + item["properties"]["name"] + " aka " + server)
+ result = client.reboot_server(datacenter, item["id"])
+ log.info(result)
View it on GitLab: https://salsa.debian.org/qa/jenkins.debian.net/commit/325b9f57c95c5a66bd63b69cbae9546e76fe0928
--
View it on GitLab: https://salsa.debian.org/qa/jenkins.debian.net/commit/325b9f57c95c5a66bd63b69cbae9546e76fe0928
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/qa-jenkins-scm/attachments/20191211/8b7fdf0e/attachment-0001.html>
More information about the Qa-jenkins-scm
mailing list