|
|
@@ -1,46 +1,46 @@ |
|
|
import requests, shlex, json |
|
|
import requests |
|
|
import json |
|
|
from subprocess import Popen, PIPE |
|
|
|
|
|
|
|
|
class MCollective: |
|
|
|
|
|
|
|
|
def list_hosts(self): |
|
|
process = Popen(shlex.split("mco rpc rpcutil ping -j"), stdout=PIPE) |
|
|
j = process.communicate()[0] |
|
|
process = Popen("mco rpc rpcutil ping -j".split(), stdout=PIPE) |
|
|
j = process.communicate()[0] |
|
|
|
|
|
process.wait() |
|
|
|
|
|
if j: |
|
|
return [ i['sender'].split('.')[0] for i in json.loads(j) ] |
|
|
return set(i['sender'].split('.')[0] for i in json.loads(j)) |
|
|
else: |
|
|
return None |
|
|
|
|
|
|
|
|
class Foreman: |
|
|
|
|
|
def __init__(self, hostname=None, username=None, password=None): |
|
|
self.username = username |
|
|
self.password = password |
|
|
self.hostname = hostname |
|
|
self.username = username |
|
|
self.password = password |
|
|
self.hostname = hostname |
|
|
|
|
|
self.perpage = 100 |
|
|
self.sslverify = False |
|
|
self.perpage = 100 |
|
|
self.sslverify = False |
|
|
|
|
|
def list_hosts(self): |
|
|
uri = "{0}/api/hosts?per_page={1}".format(self.hostname, self.perpage) |
|
|
uri = "{0}/api/hosts?per_page={1}".format(self.hostname, self.perpage) |
|
|
http = requests.get(uri, auth=(self.username, self.password), verify=self.sslverify) |
|
|
|
|
|
if http.status_code == 200: |
|
|
return [i['host']['name'].split('.')[0] for i in http.json()] |
|
|
return set(i['host']['name'].split('.')[0] for i in http.json()) |
|
|
else: |
|
|
return None |
|
|
|
|
|
if __name__ == '__main__': |
|
|
# Use whatever passwords you need to. |
|
|
foreman_hosts = Foreman('foreman', 'admin', 'chageme').list_hosts() |
|
|
mcollective_hosts = MCollective().list_hosts() |
|
|
foreman_hosts = Foreman('foreman', 'admin', 'chageme').list_hosts() |
|
|
mcollective_hosts = MCollective().list_hosts() |
|
|
|
|
|
diff = [i for i in foreman_hosts if i not in mcollective_hosts] |
|
|
diff = foreman_hosts - mcollective_hosts |
|
|
|
|
|
if len(diff) > 0: |
|
|
print diff |
|
|
else: |
|
|
print "All in sync." |
|
|
print diff or "All in sync." |