Skip to content

Commit

Permalink
[MOD] Small changes based on Pylint output
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Whitwell committed Apr 20, 2017
1 parent 2a97436 commit 79e3b06
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions memset
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
'''
"""
Replace your /etc/ansible/hosts (/usr/local/etc/ansible/hosts) file with this,
to automatically import all your Memset servers into the Ansible inventory.
Expand All @@ -18,7 +18,8 @@ ansible memset-reading -l memset-linux -m ping
API key must have access to at least:
method:server.list, method:server.info & method:service.info
'''
"""

from jsonrpclib import Server
import os
import sys
Expand All @@ -40,18 +41,23 @@ uri = "https://%s:@api.memset.com/v1/jsonrpc/" % memkey

s = Server(uri)


def _get_servers():
return s.server.list()


def _get_service(name):
return s.service.info(name=name)


def _simple_os(server):
return 'windows' if server["os"].startswith("win") else 'linux'


def _get_zone(service):
return service['network_zones'][0]


def _build_vars(server):
var = {}
service = _get_service(server["name"])
Expand Down Expand Up @@ -81,6 +87,7 @@ def _build_vars(server):

return var


def get_single(hostname):
servers = _get_servers()
server = filter(lambda s: s["host_name"] == hostname, servers)
Expand All @@ -89,16 +96,17 @@ def get_single(hostname):
output = _build_vars(server[0])
return output


def get_all():
osses = {}
osses["windows"] = []
osses["linux"] = []
output = {
'memset-windows' : {'hosts' : [], 'vars': {}},
'memset-linux' : {'hosts' : [], 'vars': {}},
'memset-reading' : {'hosts' : [], 'vars': {}},
'memset-dunsfold' : {'hosts' : [], 'vars': {}},
'_meta' : {'hostvars': {}}
'memset-windows': {'hosts': [], 'vars': {}},
'memset-linux': {'hosts': [], 'vars': {}},
'memset-reading': {'hosts': [], 'vars': {}},
'memset-dunsfold': {'hosts': [], 'vars': {}},
'_meta': {'hostvars': {}}
}
for server in _get_servers():
os_group = 'memset-%s' % _simple_os(server)
Expand All @@ -111,6 +119,7 @@ def get_all():
output['memset-linux']['vars']["ansible_ssh_user"] = 'root'
return output


def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "", ["list", "host="])
Expand All @@ -125,5 +134,6 @@ def main():
output = get_single(a)
print json.dumps(output, sort_keys=True, indent=4, separators=(',', ': '))


if __name__ == '__main__':
main()

0 comments on commit 79e3b06

Please sign in to comment.