Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package yomi-formula for openSUSE:Factory checked in at 2021-08-19 12:49:16 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/yomi-formula (Old) and /work/SRC/openSUSE:Factory/.yomi-formula.new.1899 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "yomi-formula" Thu Aug 19 12:49:16 2021 rev:22 rq:912868 version:0.0.1+git.1629280900.fdbe9f0 Changes: -------- --- /work/SRC/openSUSE:Factory/yomi-formula/yomi-formula.changes 2021-05-02 18:35:18.745153267 +0200 +++ /work/SRC/openSUSE:Factory/.yomi-formula.new.1899/yomi-formula.changes 2021-08-19 12:49:18.913445425 +0200 @@ -1,0 +2,7 @@ +Wed Aug 18 10:03:43 UTC 2021 - Alberto Planas Dominguez <apla...@suse.com> + +- Update to version 0.0.1+git.1629280900.fdbe9f0: + * monitor: rename it to yomi-monitor + * suseconnect: make regcode parameter optional + +------------------------------------------------------------------- Old: ---- yomi-0.0.1+git.1619170188.fa52819.obscpio New: ---- yomi-0.0.1+git.1629280900.fdbe9f0.obscpio ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ yomi-formula.spec ++++++ --- /var/tmp/diff_new_pack.UKMGZO/_old 2021-08-19 12:49:19.581444470 +0200 +++ /var/tmp/diff_new_pack.UKMGZO/_new 2021-08-19 12:49:19.585444464 +0200 @@ -19,7 +19,7 @@ %define fname yomi %define fdir %{_datadir}/salt-formulas Name: yomi-formula -Version: 0.0.1+git.1619170188.fa52819 +Version: 0.0.1+git.1629280900.fdbe9f0 Release: 0 Summary: Yomi - Yet one more installer License: Apache-2.0 @@ -74,7 +74,7 @@ # Monitoring CLI mkdir -p %{buildroot}%{_bindir}/ -cp -a monitor %{buildroot}%{_bindir}/ +cp -a yomi-monitor %{buildroot}%{_bindir}/ # Pillars examples cat <<EOF > %{buildroot}%{_datadir}/%{fname}/pillar.conf @@ -164,7 +164,7 @@ %{fdir}/metadata/ %{_prefix}/lib/%{fname}/ %{_datadir}/%{fname} -%{_bindir}/monitor +%{_bindir}/yomi-monitor %config %{_sysconfdir}/salt/master.d/%{name}.conf %changelog ++++++ _servicedata ++++++ --- /var/tmp/diff_new_pack.UKMGZO/_old 2021-08-19 12:49:19.621444413 +0200 +++ /var/tmp/diff_new_pack.UKMGZO/_new 2021-08-19 12:49:19.625444407 +0200 @@ -1,4 +1,4 @@ <servicedata> <service name="tar_scm"> <param name="url">https://github.com/openSUSE/yomi.git</param> - <param name="changesrevision">fa52819b46b02afce44b47259238a49c382d5207</param></service></servicedata> \ No newline at end of file + <param name="changesrevision">fdbe9f0fe9fc1c58f722bf8b08c47128ba0aadb2</param></service></servicedata> \ No newline at end of file ++++++ yomi-0.0.1+git.1619170188.fa52819.obscpio -> yomi-0.0.1+git.1629280900.fdbe9f0.obscpio ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yomi-0.0.1+git.1619170188.fa52819/.gitignore new/yomi-0.0.1+git.1629280900.fdbe9f0/.gitignore --- old/yomi-0.0.1+git.1619170188.fa52819/.gitignore 1970-01-01 01:00:00.000000000 +0100 +++ new/yomi-0.0.1+git.1629280900.fdbe9f0/.gitignore 2021-08-18 12:01:40.000000000 +0200 @@ -0,0 +1,114 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# emacs +*~ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yomi-0.0.1+git.1619170188.fa52819/README.md new/yomi-0.0.1+git.1629280900.fdbe9f0/README.md --- old/yomi-0.0.1+git.1619170188.fa52819/README.md 2021-04-23 11:29:48.000000000 +0200 +++ new/yomi-0.0.1+git.1629280900.fdbe9f0/README.md 2021-08-18 12:01:40.000000000 +0200 @@ -317,7 +317,7 @@ events: yes ``` -We can launch the `monitor` tool. +We can launch the `yomi-monitor` tool. ```bash export SALTAPI_URL=http://localhost:8000 @@ -325,15 +325,16 @@ export SALTAPI_USER=salt export SALTAPI_PASS=linux -monitor -r -y +yomi-monitor -r -y ``` -The `monitor` tool store in a local cache the authentication tokens -generated by Salt API. This will accelerate the next connection to the -service, but sometimes can cause authentication errors (for example, -when the cache is in place but the salt-master get reinstalled). The -option `-r` makes sure that this cache is removed before -connection. Check the help option of the tool for more information. +The `yomi-monitor` tool store in a local cache the authentication +tokens generated by Salt API. This will accelerate the next connection +to the service, but sometimes can cause authentication errors (for +example, when the cache is in place but the salt-master get +reinstalled). The option `-r` makes sure that this cache is removed +before connection. Check the help option of the tool for more +information. # Booting a new machine @@ -717,8 +718,8 @@ internal states that Yomi use to drive the installation. Using the Salt API, WebSockets, or any other mechanism provided by Salt, we can listen the event bus and use this information to monitor the - installer. Yomi provides a basic tool, `monitor`, that shows real - time information about the installation process. + installer. Yomi provides a basic tool, `yomi-monitor`, that shows + real time information about the installation process. To disable the events, set this parameter to `no`. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yomi-0.0.1+git.1619170188.fa52819/monitor new/yomi-0.0.1+git.1629280900.fdbe9f0/monitor --- old/yomi-0.0.1+git.1619170188.fa52819/monitor 2021-04-23 11:29:48.000000000 +0200 +++ new/yomi-0.0.1+git.1629280900.fdbe9f0/monitor 1970-01-01 01:00:00.000000000 +0100 @@ -1,492 +0,0 @@ -#!/usr/bin/python3 - -# -*- coding: utf-8 -*- -# -# Author: Alberto Planas <apla...@suse.com> -# -# Copyright 2019 SUSE LLC. -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -import argparse -import getpass -import json -import logging -import os -from pathlib import Path -import pprint -import ssl -import sys -import time -import urllib.error -import urllib.parse -import urllib.request - -LOG = logging.getLogger(__name__) -TOKEN_FILE = "~/.salt-api-token" - -# ANSI color codes -BLACK = "\033[1;30m" -RED = "\033[1;31m" -GREEN = "\033[0;32m" -YELLOW = "\033[0;33m" -BLUE = "\033[1;34m" -MAGENTA = "\033[1;35m" -CYAN = "\033[1;36m" -WHITE = "\033[1;37m" -RESET = "\033[0;0m" - - -class SaltAPI: - def __init__( - self, - url, - username, - password, - eauth, - insecure, - token_file=TOKEN_FILE, - debug=False, - ): - self.url = url - self.username = username - self.password = password - self.eauth = eauth - self.insecure = insecure - self.token_file = token_file - self.debug = debug - - is_https = urllib.parse.urlparse(url).scheme == "https" - if debug or (is_https and insecure): - if insecure: - context = ssl._create_unverified_context() - handler = urllib.request.HTTPSHandler( - context=context, debuglevel=int(debug) - ) - else: - handler = urllib.request.HTTPHandler(debuglevel=int(debug)) - opener = urllib.request.build_opener(handler) - urllib.request.install_opener(opener) - - self.token = None - self.expire = 0.0 - - def login(self, remove=False): - """Login into the Salt API service.""" - if remove: - self._drop_token() - self.token, self.expire = self._read_token() - if self.expire < time.time() + 30: - self.token, self.expire = self._login() - self._write_token() - - def logout(self): - """Logout from the Salt API service.""" - self._drop_token() - self._post("/logout") - - def events(self): - """SSE event stream from Salt API service.""" - for line in api._req_sse("/events", None, "GET"): - line = line.decode("utf-8").strip() - if not line or line.startswith((":", "retry:")): - continue - key, value = line.split(":", 1) - if key == "tag": - tag = value.strip() - continue - if key == "data": - data = json.loads(value) - yield (tag, data) - - def minions(self, mid=None): - """Return the list of minions.""" - if mid: - action = "/minions/{}".format(mid) - else: - action = "/minions" - return self._get(action)["return"][0] - - def run_job(self, tgt, fun, **kwargs): - """Start an execution command and return jid.""" - data = { - "tgt": tgt, - "fun": fun, - } - data.update(kwargs) - return self._post("/minions", data)["return"][0] - - def jobs(self, jid=None): - """Return the list of jobs.""" - if jid: - action = "/jobs/{}".format(jid) - else: - action = "/jobs" - return self._get(action)["return"][0] - - def stats(self): - """Return a dump of statistics.""" - return self._get("/stats")["return"][0] - - def _login(self): - """Login into the Salt API service.""" - data = { - "username": self.username, - "password": self.password, - "eauth": self.eauth, - } - result = self._post("/login", data) - return result["return"][0]["token"], result["return"][0]["expire"] - - def _get(self, action, data=None): - return self._req(action, data, "GET") - - def _post(self, action, data=None): - return self._req(action, data, "POST") - - def _req(self, action, data, method): - """HTTP GET / POST to Salt API.""" - headers = { - "User-Agent": "salt-autoinstaller monitor", - "Accept": "application/json", - "Content-Type": "application/json", - "X-Requested-With": "XMLHttpRequest", - } - if self.token: - headers["X-Auth-Token"] = self.token - - url = urllib.parse.urljoin(self.url, action) - if method == "GET": - data = urllib.parse.urlencode(data).encode() if data else None - if data: - url = "{}?{}".format(url, data) - data = None - elif method == "POST": - data = json.dumps(data).encode() if data else {} - else: - raise ValueError("Method {} not valid".format(method)) - - result = {} - try: - request = urllib.request.Request(url, data, headers) - with urllib.request.urlopen(request) as response: - result = json.loads(response.read().decode("utf-8")) - except (urllib.error.HTTPError, urllib.error.URLError) as exc: - LOG.debug("Error with request", exc_info=True) - status = getattr(exc, "code", None) - - if status == 401: - print("Authentication denied") - - if status == 500: - print("Server error.") - exit(-1) - return result - - def _req_sse(self, action, data, method): - """HTTP SSE GET / POST to Salt API.""" - headers = { - "User-Agent": "salt-autoinstaller monitor", - "Accept": "text/event-stream", - "Content-Type": "application/json", - "Connection": "Keep-Alive", - "X-Requested-With": "XMLHttpRequest", - } - if self.token: - headers["X-Auth-Token"] = self.token - - url = urllib.parse.urljoin(self.url, action) - if method == "GET": - data = urllib.parse.urlencode(data).encode() if data else None - if data: - url = "{}?{}".format(url, data) - data = None - elif method == "POST": - data = json.dumps(data).encode() if data else {} - else: - raise ValueError("Method {} not valid".format(method)) - - try: - request = urllib.request.Request(url, data, headers) - with urllib.request.urlopen(request) as response: - yield from response - except (urllib.error.HTTPError, urllib.error.URLError) as e: - LOG.debug("Error with request", exc_info=True) - status = getattr(e, "code", None) - - if status == 401: - print("Authentication denied") - - if status == 500: - print("Server error.") - exit(-1) - - def _read_token(self): - """Return the token and expire time from the token file.""" - token, expire = None, 0.0 - - if self.token_file: - token_path = Path(self.token_file).expanduser() - if token_path.is_file(): - token, expire = token_path.read_text().split() - try: - expire = float(expire) - except ValueError: - expire = 0.0 - - return token, expire - - def _write_token(self): - """Save the token and expire time into the token file.""" - self._drop_token() - if self.token_file: - token_path = Path(self.token_file).expanduser() - token_path.touch(mode=0o600) - token_path.write_text("{} {}".format(self.token, self.expire)) - - def _drop_token(self): - """Remove the token file if present.""" - if self.token_file: - token_path = Path(self.token_file).expanduser() - if token_path.is_file(): - token_path.unlink() - - -def print_minions(minions): - """Print a list of minions.""" - print("Registered minions:") - for minion in minions: - print("- {}".format(minion)) - - -def print_minion(minion): - """Print detailed information of a minion.""" - pprint.pprint(minion) - - -def print_jobs(jobs): - """Print a list of jobs.""" - print("Registered jobs:") - for job, info in jobs.items(): - print("- {}".format(job)) - pprint.pprint(info) - - -def print_job(job): - """Print detailed information of a job.""" - pprint.pprint(job) - - -def print_raw_event(tag, data): - """Print raw event without format.""" - print("- {}".format(tag)) - pprint.pprint(data) - - -def print_yomi_event(tag, data): - """Print a Yomi event with format.""" - if tag.startswith("yomi/"): - id_ = data["data"]["id"] - stamp = data["data"]["_stamp"] - - # Decide the color to represent the node - if id_ in print_yomi_event.nodes: - color = print_yomi_event.nodes[id_] - else: - color = print_yomi_event.colors.pop() - print_yomi_event.colors.insert(0, color) - print_yomi_event.nodes[id_] = color - - tag = tag.split("/", 1)[1] - tag, section = tag.rsplit("/", 1) - if section == "enter": - print( - "[{}{}{}] {} -> [{}STARTING{}] {}".format( - color, id_, RESET, stamp, BLUE, RESET, tag - ) - ) - elif section == "success": - print( - "[{}{}{}] {} -> [{}SUCCESS{}] {}".format( - color, id_, RESET, stamp, GREEN, RESET, tag - ) - ) - elif section == "fail": - print( - "[{}{}{}] {} -> [{}FAIL{}] {}".format( - color, id_, RESET, stamp, RED, RESET, tag - ) - ) - - -# Static-a-like variables to track the rotating color -print_yomi_event.nodes = {} -print_yomi_event.colors = [RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN] - -if __name__ == "__main__": - parser = argparse.ArgumentParser( - description="salt-autoinstaller monitor tool via salt-api." - ) - parser.add_argument( - "-u", - "--saltapi-url", - default=os.environ.get("SALTAPI_URL", "https://localhost:8000"), - help="Specify the host url. Overwrite SALTAPI_URL.", - ) - parser.add_argument( - "-a", - "--auth", - "--eauth", - "--extended-auth", - default=os.environ.get("SALTAPI_EAUTH", "pam"), - help="Specify the external_auth backend to " - "authenticate against and interactively prompt " - "for credentials. Overwrite SALTAPI_EAUTH.", - ) - parser.add_argument( - "-n", - "--username", - default=os.environ.get("SALTAPI_USER"), - help="Optional, defaults to user name. will " - "be prompt if empty unless --non-interactive. " - "Overwrite SALTAPI_USER.", - ) - parser.add_argument( - "-p", - "--password", - default=os.environ.get("SALTAPI_PASS"), - help="Optional, but will be prompted unless " - "--non-interactive. Overwrite SALTAPI_PASS.", - ) - parser.add_argument( - "--non-interactive", - action="store_true", - default=False, - help="Optional, fail rather than waiting for input.", - ) - parser.add_argument( - "-r", - "--remove", - action="store_true", - default=False, - help="Remove the token cached in the system.", - ) - parser.add_argument( - "-i", - "--insecure", - action="store_true", - default=False, - help="Ignore any SSL certificate that may be " - "encountered. Note that it is recommended to resolve " - "certificate errors for production.", - ) - parser.add_argument( - "-H", - "--debug-http", - action="store_true", - default=False, - help=("Output the HTTP request/response headers on " "stderr."), - ) - parser.add_argument( - "-m", - "--minions", - action="store_true", - default=False, - help="List available minions.", - ) - parser.add_argument( - "--show-minion", - metavar="MID", - default=None, - help="Show the details of a minion.", - ) - parser.add_argument( - "-j", "--jobs", action="store_true", default=False, help="List available jobs." - ) - parser.add_argument( - "--show-job", metavar="JID", default=None, help="Show the details of a job." - ) - parser.add_argument( - "-e", - "--events", - action="store_true", - default=False, - help="Show events from salt-master.", - ) - parser.add_argument( - "-y", - "--yomi-events", - action="store_true", - default=False, - help="Show only Yomi events from salt-master.", - ) - parser.add_argument( - "target", nargs="?", help="Minion ID where to launch the installer." - ) - args = parser.parse_args() - - if not args.saltapi_url: - print("Please, provide a valid Salt API URL", file=sys.stderr) - exit(-1) - - if args.non_interactive: - if args.username is None: - print("Please, provide a valid user name", file=sys.stderr) - exit(-1) - - if args.password is None: - print("Please, provide a valid password", file=sys.stderr) - exit(-1) - else: - if args.username is None: - args.username = input("Username: ") - if args.password is None: - args.password = getpass.getpass(prompt="Password: ") - - api = SaltAPI( - url=args.saltapi_url, - username=args.username, - password=args.password, - eauth=args.auth, - insecure=args.insecure, - debug=args.debug_http, - ) - - api.login(args.remove) - - if args.minions: - print_minions(api.minions()) - - if args.show_minion: - print_minion(api.minions(args.show_minion)) - - if args.jobs: - print_jobs(api.jobs()) - - if args.show_job: - print_job(api.jobs(args.show_job)) - - if args.target: - print_job(api.run_job(args.target, "state.highstate")) - - if args.events or args.yomi_events: - for tag, data in api.events(): - if args.yomi_events: - print_yomi_event(tag, data) - else: - print_raw_event(tag, data) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yomi-0.0.1+git.1619170188.fa52819/salt/_modules/suseconnect.py new/yomi-0.0.1+git.1629280900.fdbe9f0/salt/_modules/suseconnect.py --- old/yomi-0.0.1+git.1619170188.fa52819/salt/_modules/suseconnect.py 2021-04-23 11:29:48.000000000 +0200 +++ new/yomi-0.0.1+git.1629280900.fdbe9f0/salt/_modules/suseconnect.py 2021-08-18 12:01:40.000000000 +0200 @@ -28,6 +28,7 @@ :platform: Linux """ from __future__ import absolute_import, print_function, unicode_literals + import json import logging import re @@ -65,7 +66,7 @@ return result["stdout"] -def register(regcode, product=None, email=None, url=None, root=None): +def register(regcode=None, product=None, email=None, url=None, root=None): """ .. versionadded:: TBD @@ -75,7 +76,7 @@ regcode Subscription registration code for the product to be registered. Relates that product to the specified subscription, - and enalbes software repositories for that product. + and enables software repositories for that product. product Specify a product for activation/deactivation. Only one product @@ -97,13 +98,19 @@ .. code-block:: bash - salt '*' suseconnect.register xxxx-yyy-zzzz - salt '*' suseconnect.register xxxx-yyy-zzzz product='sle-ha/15.2/x86_64' + salt '*' suseconnect.register regcode='xxxx-yyy-zzzz' + salt '*' suseconnect.register product='sle-ha/15.2/x86_64' """ - cmd = ["SUSEConnect", "--regcode", regcode] + cmd = ["SUSEConnect"] - parameters = [("product", product), ("email", email), ("url", url), ("root", root)] + parameters = [ + ("regcode", regcode), + ("product", product), + ("email", email), + ("url", url), + ("root", root), + ] for parameter, value in parameters: if value: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yomi-0.0.1+git.1619170188.fa52819/salt/_states/suseconnect.py new/yomi-0.0.1+git.1629280900.fdbe9f0/salt/_states/suseconnect.py --- old/yomi-0.0.1+git.1619170188.fa52819/salt/_states/suseconnect.py 2021-04-23 11:29:48.000000000 +0200 +++ new/yomi-0.0.1+git.1629280900.fdbe9f0/salt/_states/suseconnect.py 2021-08-18 12:01:40.000000000 +0200 @@ -28,6 +28,7 @@ :platform: Linux """ from __future__ import absolute_import, print_function, unicode_literals + import logging import re @@ -88,7 +89,7 @@ return False -def registered(name, regcode, product=None, email=None, url=None, root=None): +def registered(name, regcode=None, product=None, email=None, url=None, root=None): """ .. versionadded:: TBD @@ -102,7 +103,7 @@ regcode Subscription registration code for the product to be registered. Relates that product to the specified subscription, - and enalbes software repositories for that product. + and enables software repositories for that product. product Specify a product for activation/deactivation. Only one product @@ -139,9 +140,7 @@ if __opts__["test"]: ret["result"] = None - ret["comment"].append( - "Product or module {} would be registered".format(name) - ) + ret["comment"].append("Product or module {} would be registered".format(name)) ret["changes"][name] = True return ret @@ -204,16 +203,12 @@ if not _is_registered(product, root): ret["result"] = True - ret["comment"].append( - "Product or module {} already deregistered".format(name) - ) + ret["comment"].append("Product or module {} already deregistered".format(name)) return ret if __opts__["test"]: ret["result"] = None - ret["comment"].append( - "Product or module {} would be deregistered".format(name) - ) + ret["comment"].append("Product or module {} would be deregistered".format(name)) ret["changes"][name] = True return ret @@ -229,8 +224,6 @@ ret["result"] = True ret["comment"].append("Product or module {} deregistered".format(name)) else: - ret["comment"].append( - "Product or module {} failed to deregister".format(name) - ) + ret["comment"].append("Product or module {} failed to deregister".format(name)) return ret diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/yomi-0.0.1+git.1619170188.fa52819/yomi-monitor new/yomi-0.0.1+git.1629280900.fdbe9f0/yomi-monitor --- old/yomi-0.0.1+git.1619170188.fa52819/yomi-monitor 1970-01-01 01:00:00.000000000 +0100 +++ new/yomi-0.0.1+git.1629280900.fdbe9f0/yomi-monitor 2021-08-18 12:01:40.000000000 +0200 @@ -0,0 +1,492 @@ +#!/usr/bin/python3 + +# -*- coding: utf-8 -*- +# +# Author: Alberto Planas <apla...@suse.com> +# +# Copyright 2019 SUSE LLC. +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import argparse +import getpass +import json +import logging +import os +from pathlib import Path +import pprint +import ssl +import sys +import time +import urllib.error +import urllib.parse +import urllib.request + +LOG = logging.getLogger(__name__) +TOKEN_FILE = "~/.salt-api-token" + +# ANSI color codes +BLACK = "\033[1;30m" +RED = "\033[1;31m" +GREEN = "\033[0;32m" +YELLOW = "\033[0;33m" +BLUE = "\033[1;34m" +MAGENTA = "\033[1;35m" +CYAN = "\033[1;36m" +WHITE = "\033[1;37m" +RESET = "\033[0;0m" + + +class SaltAPI: + def __init__( + self, + url, + username, + password, + eauth, + insecure, + token_file=TOKEN_FILE, + debug=False, + ): + self.url = url + self.username = username + self.password = password + self.eauth = eauth + self.insecure = insecure + self.token_file = token_file + self.debug = debug + + is_https = urllib.parse.urlparse(url).scheme == "https" + if debug or (is_https and insecure): + if insecure: + context = ssl._create_unverified_context() + handler = urllib.request.HTTPSHandler( + context=context, debuglevel=int(debug) + ) + else: + handler = urllib.request.HTTPHandler(debuglevel=int(debug)) + opener = urllib.request.build_opener(handler) + urllib.request.install_opener(opener) + + self.token = None + self.expire = 0.0 + + def login(self, remove=False): + """Login into the Salt API service.""" + if remove: + self._drop_token() + self.token, self.expire = self._read_token() + if self.expire < time.time() + 30: + self.token, self.expire = self._login() + self._write_token() + + def logout(self): + """Logout from the Salt API service.""" + self._drop_token() + self._post("/logout") + + def events(self): + """SSE event stream from Salt API service.""" + for line in api._req_sse("/events", None, "GET"): + line = line.decode("utf-8").strip() + if not line or line.startswith((":", "retry:")): + continue + key, value = line.split(":", 1) + if key == "tag": + tag = value.strip() + continue + if key == "data": + data = json.loads(value) + yield (tag, data) + + def minions(self, mid=None): + """Return the list of minions.""" + if mid: + action = "/minions/{}".format(mid) + else: + action = "/minions" + return self._get(action)["return"][0] + + def run_job(self, tgt, fun, **kwargs): + """Start an execution command and return jid.""" + data = { + "tgt": tgt, + "fun": fun, + } + data.update(kwargs) + return self._post("/minions", data)["return"][0] + + def jobs(self, jid=None): + """Return the list of jobs.""" + if jid: + action = "/jobs/{}".format(jid) + else: + action = "/jobs" + return self._get(action)["return"][0] + + def stats(self): + """Return a dump of statistics.""" + return self._get("/stats")["return"][0] + + def _login(self): + """Login into the Salt API service.""" + data = { + "username": self.username, + "password": self.password, + "eauth": self.eauth, + } + result = self._post("/login", data) + return result["return"][0]["token"], result["return"][0]["expire"] + + def _get(self, action, data=None): + return self._req(action, data, "GET") + + def _post(self, action, data=None): + return self._req(action, data, "POST") + + def _req(self, action, data, method): + """HTTP GET / POST to Salt API.""" + headers = { + "User-Agent": "salt-autoinstaller monitor", + "Accept": "application/json", + "Content-Type": "application/json", + "X-Requested-With": "XMLHttpRequest", + } + if self.token: + headers["X-Auth-Token"] = self.token + + url = urllib.parse.urljoin(self.url, action) + if method == "GET": + data = urllib.parse.urlencode(data).encode() if data else None + if data: + url = "{}?{}".format(url, data) + data = None + elif method == "POST": + data = json.dumps(data).encode() if data else {} + else: + raise ValueError("Method {} not valid".format(method)) + + result = {} + try: + request = urllib.request.Request(url, data, headers) + with urllib.request.urlopen(request) as response: + result = json.loads(response.read().decode("utf-8")) + except (urllib.error.HTTPError, urllib.error.URLError) as exc: + LOG.debug("Error with request", exc_info=True) + status = getattr(exc, "code", None) + + if status == 401: + print("Authentication denied") + + if status == 500: + print("Server error.") + exit(-1) + return result + + def _req_sse(self, action, data, method): + """HTTP SSE GET / POST to Salt API.""" + headers = { + "User-Agent": "salt-autoinstaller monitor", + "Accept": "text/event-stream", + "Content-Type": "application/json", + "Connection": "Keep-Alive", + "X-Requested-With": "XMLHttpRequest", + } + if self.token: + headers["X-Auth-Token"] = self.token + + url = urllib.parse.urljoin(self.url, action) + if method == "GET": + data = urllib.parse.urlencode(data).encode() if data else None + if data: + url = "{}?{}".format(url, data) + data = None + elif method == "POST": + data = json.dumps(data).encode() if data else {} + else: + raise ValueError("Method {} not valid".format(method)) + + try: + request = urllib.request.Request(url, data, headers) + with urllib.request.urlopen(request) as response: + yield from response + except (urllib.error.HTTPError, urllib.error.URLError) as e: + LOG.debug("Error with request", exc_info=True) + status = getattr(e, "code", None) + + if status == 401: + print("Authentication denied") + + if status == 500: + print("Server error.") + exit(-1) + + def _read_token(self): + """Return the token and expire time from the token file.""" + token, expire = None, 0.0 + + if self.token_file: + token_path = Path(self.token_file).expanduser() + if token_path.is_file(): + token, expire = token_path.read_text().split() + try: + expire = float(expire) + except ValueError: + expire = 0.0 + + return token, expire + + def _write_token(self): + """Save the token and expire time into the token file.""" + self._drop_token() + if self.token_file: + token_path = Path(self.token_file).expanduser() + token_path.touch(mode=0o600) + token_path.write_text("{} {}".format(self.token, self.expire)) + + def _drop_token(self): + """Remove the token file if present.""" + if self.token_file: + token_path = Path(self.token_file).expanduser() + if token_path.is_file(): + token_path.unlink() + + +def print_minions(minions): + """Print a list of minions.""" + print("Registered minions:") + for minion in minions: + print("- {}".format(minion)) + + +def print_minion(minion): + """Print detailed information of a minion.""" + pprint.pprint(minion) + + +def print_jobs(jobs): + """Print a list of jobs.""" + print("Registered jobs:") + for job, info in jobs.items(): + print("- {}".format(job)) + pprint.pprint(info) + + +def print_job(job): + """Print detailed information of a job.""" + pprint.pprint(job) + + +def print_raw_event(tag, data): + """Print raw event without format.""" + print("- {}".format(tag)) + pprint.pprint(data) + + +def print_yomi_event(tag, data): + """Print a Yomi event with format.""" + if tag.startswith("yomi/"): + id_ = data["data"]["id"] + stamp = data["data"]["_stamp"] + + # Decide the color to represent the node + if id_ in print_yomi_event.nodes: + color = print_yomi_event.nodes[id_] + else: + color = print_yomi_event.colors.pop() + print_yomi_event.colors.insert(0, color) + print_yomi_event.nodes[id_] = color + + tag = tag.split("/", 1)[1] + tag, section = tag.rsplit("/", 1) + if section == "enter": + print( + "[{}{}{}] {} -> [{}STARTING{}] {}".format( + color, id_, RESET, stamp, BLUE, RESET, tag + ) + ) + elif section == "success": + print( + "[{}{}{}] {} -> [{}SUCCESS{}] {}".format( + color, id_, RESET, stamp, GREEN, RESET, tag + ) + ) + elif section == "fail": + print( + "[{}{}{}] {} -> [{}FAIL{}] {}".format( + color, id_, RESET, stamp, RED, RESET, tag + ) + ) + + +# Static-a-like variables to track the rotating color +print_yomi_event.nodes = {} +print_yomi_event.colors = [RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN] + +if __name__ == "__main__": + parser = argparse.ArgumentParser( + description="salt-autoinstaller monitor tool via salt-api." + ) + parser.add_argument( + "-u", + "--saltapi-url", + default=os.environ.get("SALTAPI_URL", "https://localhost:8000"), + help="Specify the host url. Overwrite SALTAPI_URL.", + ) + parser.add_argument( + "-a", + "--auth", + "--eauth", + "--extended-auth", + default=os.environ.get("SALTAPI_EAUTH", "pam"), + help="Specify the external_auth backend to " + "authenticate against and interactively prompt " + "for credentials. Overwrite SALTAPI_EAUTH.", + ) + parser.add_argument( + "-n", + "--username", + default=os.environ.get("SALTAPI_USER"), + help="Optional, defaults to user name. will " + "be prompt if empty unless --non-interactive. " + "Overwrite SALTAPI_USER.", + ) + parser.add_argument( + "-p", + "--password", + default=os.environ.get("SALTAPI_PASS"), + help="Optional, but will be prompted unless " + "--non-interactive. Overwrite SALTAPI_PASS.", + ) + parser.add_argument( + "--non-interactive", + action="store_true", + default=False, + help="Optional, fail rather than waiting for input.", + ) + parser.add_argument( + "-r", + "--remove", + action="store_true", + default=False, + help="Remove the token cached in the system.", + ) + parser.add_argument( + "-i", + "--insecure", + action="store_true", + default=False, + help="Ignore any SSL certificate that may be " + "encountered. Note that it is recommended to resolve " + "certificate errors for production.", + ) + parser.add_argument( + "-H", + "--debug-http", + action="store_true", + default=False, + help=("Output the HTTP request/response headers on " "stderr."), + ) + parser.add_argument( + "-m", + "--minions", + action="store_true", + default=False, + help="List available minions.", + ) + parser.add_argument( + "--show-minion", + metavar="MID", + default=None, + help="Show the details of a minion.", + ) + parser.add_argument( + "-j", "--jobs", action="store_true", default=False, help="List available jobs." + ) + parser.add_argument( + "--show-job", metavar="JID", default=None, help="Show the details of a job." + ) + parser.add_argument( + "-e", + "--events", + action="store_true", + default=False, + help="Show events from salt-master.", + ) + parser.add_argument( + "-y", + "--yomi-events", + action="store_true", + default=False, + help="Show only Yomi events from salt-master.", + ) + parser.add_argument( + "target", nargs="?", help="Minion ID where to launch the installer." + ) + args = parser.parse_args() + + if not args.saltapi_url: + print("Please, provide a valid Salt API URL", file=sys.stderr) + exit(-1) + + if args.non_interactive: + if args.username is None: + print("Please, provide a valid user name", file=sys.stderr) + exit(-1) + + if args.password is None: + print("Please, provide a valid password", file=sys.stderr) + exit(-1) + else: + if args.username is None: + args.username = input("Username: ") + if args.password is None: + args.password = getpass.getpass(prompt="Password: ") + + api = SaltAPI( + url=args.saltapi_url, + username=args.username, + password=args.password, + eauth=args.auth, + insecure=args.insecure, + debug=args.debug_http, + ) + + api.login(args.remove) + + if args.minions: + print_minions(api.minions()) + + if args.show_minion: + print_minion(api.minions(args.show_minion)) + + if args.jobs: + print_jobs(api.jobs()) + + if args.show_job: + print_job(api.jobs(args.show_job)) + + if args.target: + print_job(api.run_job(args.target, "state.highstate")) + + if args.events or args.yomi_events: + for tag, data in api.events(): + if args.yomi_events: + print_yomi_event(tag, data) + else: + print_raw_event(tag, data) ++++++ yomi.obsinfo ++++++ --- /var/tmp/diff_new_pack.UKMGZO/_old 2021-08-19 12:49:19.897444018 +0200 +++ /var/tmp/diff_new_pack.UKMGZO/_new 2021-08-19 12:49:19.897444018 +0200 @@ -1,5 +1,5 @@ name: yomi -version: 0.0.1+git.1619170188.fa52819 -mtime: 1619170188 -commit: fa52819b46b02afce44b47259238a49c382d5207 +version: 0.0.1+git.1629280900.fdbe9f0 +mtime: 1629280900 +commit: fdbe9f0fe9fc1c58f722bf8b08c47128ba0aadb2