From 763cff971e95466f07f24592523e19377964257a Mon Sep 17 00:00:00 2001 From: doteast Date: Thu, 25 Feb 2016 22:13:36 +0000 Subject: [PATCH] no going back --- scripts/fetch-ssh-keys.v2 | 114 ----------------------------------- scripts/list-vms-per-host.v2 | 48 --------------- 2 files changed, 162 deletions(-) delete mode 100755 scripts/fetch-ssh-keys.v2 delete mode 100755 scripts/list-vms-per-host.v2 diff --git a/scripts/fetch-ssh-keys.v2 b/scripts/fetch-ssh-keys.v2 deleted file mode 100755 index 4b8280af4d..0000000000 --- a/scripts/fetch-ssh-keys.v2 +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/python -tt -# vim: fileencoding=utf8 foldmethod=marker -#{{{ License header: MIT -"""Copyright (c) 2013 Till Maas - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE.""" -#}}} -""" :author: Till Maas - :contact: opensource@till.name - :license: MIT -""" -""" :changes: Ali AlKhalidi - :contact: doteast@fedoraproject.org -""" - -import os -import sys -import copy -import itertools - -from ansible import plugins -from ansible.errors import AnsibleOptionsError -from ansible.plugins.callback import CallbackBase -from ansible.plugins.callback import default -from ansible.cli.adhoc import AdHocCLI -ALIAS_PATH = '/srv/web/infra/hosts/{hostname}/host_aliases' - - -class ResultAccumulator(CallbackBase): - def __init__(self, *args, **kwargs): - super(ResultAccumulator, self).__init__(*args, **kwargs) - self.unreachable = set() - self.host_status = {} - self.sshhostkeys = {} - - def v2_runner_on_unreachable(self, result): - self.unreachable.add(result._host.get_name()) - - def v2_runner_on_ok(self, result, *args, **kwargs): - facts = result._result['ansible_facts'] - key = "ssh-rsa {0}".format(facts['ansible_ssh_host_key_rsa_public']) - - names = [result._host.get_name()] - ansible_fqdn = facts['ansible_fqdn'] - if ansible_fqdn not in names: - names.append(ansible_fqdn) - - ansible_hostname = facts['ansible_hostname'] - if ansible_hostname not in names: - if ansible_fqdn.find('.stg.') != -1 or result._host.get_name().find('.stg.') != -1: - names.append(ansible_hostname+".stg") - else: - names.append(ansible_hostname) - - try: - with open(ALIAS_PATH.format(hostname=result._host.get_name()), - "rb") as alias_file: - aliases = [a.strip() for a in alias_file.readlines()] - for alias in aliases: - if alias not in names: - names.append(alias) - except IOError: - pass - - ipv4_addresses = facts["ansible_default_ipv4"] - if ipv4_addresses: - names.append(ipv4_addresses["address"]) - - # ignore link local addresses - non_link_local = facts["ansible_default_ipv6"] - if non_link_local: - names.append(non_link_local["address"]) - - #get tunnel addresses; hardcoded to tun0 - if facts.has_key('ansible_tun0'): - tunnel_addresses=facts["ansible_tun0"] - names.append(tunnel_addresses['ipv4']['address']) - - self.sshhostkeys[result._host.get_name()] = {"key": key, - "names": ",".join(names)} - -if __name__ == '__main__': - args = copy.copy(sys.argv) - args.extend(['-m', 'setup']) - cb = ResultAccumulator() - cli = AdHocCLI(copy.copy(args), callback=cb) - try: - cli.parse() - except AnsibleOptionsError: - if len(cli.args) != 1: - cli.args = copy.copy(args) - cli.args.append('all') - cli.parse() - - cli.run() - - for host in sorted(cb.sshhostkeys.items()): - print "{names} {key} {comment}".format(comment=host[0],**host[1]) diff --git a/scripts/list-vms-per-host.v2 b/scripts/list-vms-per-host.v2 deleted file mode 100755 index a689a2bed7..0000000000 --- a/scripts/list-vms-per-host.v2 +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/python -tt -# Author: Toshio Kuratomi -# Copyright: December, 2015 -# License: LGPLv3+ -import sys -import copy -import itertools - -from ansible import plugins -from ansible.errors import AnsibleOptionsError -from ansible.plugins.callback import CallbackBase -from ansible.plugins.callback import default -from ansible.cli.adhoc import AdHocCLI - - -class ResultAccumulator(CallbackBase): - def __init__(self, *args, **kwargs): - super(ResultAccumulator, self).__init__(*args, **kwargs) - self.unreachable = set() - self.host_status = {} - - def v2_runner_on_unreachable(self, result): - self.unreachable.add(result._host.get_name()) - - def v2_runner_on_ok(self, result, *args, **kwargs): - for vm in (vm for vm in result._result.keys() if vm not in ('invocation', 'changed', '_ansible_no_log')): - self.host_status[(result._host.get_name(), vm)] = (result._result[vm]['state'], str(result._result[vm]['autostart'])) - - -if __name__ == '__main__': - args = copy.copy(sys.argv) - args.extend(['-m', 'virt', '-a', 'command=info']) - cb = ResultAccumulator() - cli = AdHocCLI(copy.copy(args), callback=cb) - try: - cli.parse() - except AnsibleOptionsError: - if len(cli.args) != 1: - cli.args = copy.copy(args) - cli.args.append('virtservers') - cli.parse() - - cli.run() - - for host in cb.unreachable: - sys.stderr.write('unreachable: %s\n' % host) - for host, status in sorted(cb.host_status.items()): - print(':'.join(itertools.chain(host, status)))