<s> import json <EOL> import os <EOL> import requests <EOL> import sys <EOL> from operator import itemgetter , attrgetter <EOL> opencloud_auth = None <EOL> REST_API = "<STR_LIT>" <EOL> NODES_API = REST_API + "<STR_LIT>" <EOL> SITES_API = REST_API + "<STR_LIT>" <EOL> SLICES_API = REST_API + "<STR_LIT>" <EOL> SLIVERS_API = REST_API + "<STR_LIT>" <EOL> def get_nodes_by_site ( ) : <EOL> r = requests . get ( SITES_API + "<STR_LIT>" , auth = opencloud_auth ) <EOL> sites_list = r . json ( ) <EOL> sites = { } <EOL> for site in sites_list : <EOL> site [ "<STR_LIT>" ] = [ ] <EOL> sites [ str ( site [ "<STR_LIT:id>" ] ) ] = site <EOL> r = requests . get ( NODES_API + "<STR_LIT>" , auth = opencloud_auth ) <EOL> nodes = r . json ( ) <EOL> for node in nodes : <EOL> site_id = str ( node [ "<STR_LIT>" ] ) <EOL> if site_id in sites : <EOL> sites [ site_id ] [ "<STR_LIT>" ] . append ( node [ "<STR_LIT:name>" ] ) <EOL> return sites <EOL> """<STR_LIT>""" <EOL> def main ( ) : <EOL> global opencloud_auth <EOL> if len ( sys . argv ) != <NUM_LIT:3> : <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> sys . exit ( - <NUM_LIT:1> ) <EOL> username = sys . argv [ <NUM_LIT:1> ] <EOL> password = sys . argv [ <NUM_LIT:2> ] <EOL> opencloud_auth = ( username , password ) <EOL> sites = get_nodes_by_site ( ) <EOL> for site in sites . values ( ) : <EOL> if not site [ "<STR_LIT>" ] : <EOL> continue <EOL> print "<STR_LIT>" % site [ "<STR_LIT:name>" ] <EOL> for hostname in site [ "<STR_LIT>" ] : <EOL> print hostname <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> for site in sites . values ( ) : <EOL> if not site [ "<STR_LIT>" ] : <EOL> continue <EOL> print site [ "<STR_LIT:name>" ] <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
