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
  • Select an option

  • Save ekohl/8506890 to your computer and use it in GitHub Desktop.

Select an option

Save ekohl/8506890 to your computer and use it in GitHub Desktop.

Revisions

  1. ekohl revised this gist Jan 19, 2014. 1 changed file with 19 additions and 19 deletions.
    38 changes: 19 additions & 19 deletions mcollective-to-foreman.py
    Original file line number Diff line number Diff line change
    @@ -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."
  2. @mrcrilly mrcrilly created this gist Jan 19, 2014.
    46 changes: 46 additions & 0 deletions mcollective-to-foreman.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    import requests, shlex, 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.wait()

    if j:
    return [ 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 [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 = [i for i in foreman_hosts if i not in mcollective_hosts]

    if len(diff) > 0:
    print diff
    else:
    print "All in sync."