Skip to content

Instantly share code, notes, and snippets.

@ekohl
Forked from mrcrilly/mcollective-to-foreman.py
Last active January 3, 2016 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ekohl/8506890 to your computer and use it in GitHub Desktop.
Save ekohl/8506890 to your computer and use it in GitHub Desktop.
import requests
import json
from subprocess import Popen, PIPE
class MCollective:
def list_hosts(self):
process = Popen("mco rpc rpcutil ping -j".split(), stdout=PIPE)
j = process.communicate()[0]
process.wait()
if 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.perpage = 100
self.sslverify = False
def list_hosts(self):
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 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()
diff = foreman_hosts - mcollective_hosts
print diff or "All in sync."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment