def test_get(): client = ResourceManagerClient() resource = 'test_machine' response_body = '{"_id": "my_id"}' httpretty.register_uri(httpretty.GET, client.endpoint + "/" + resource, body=response_body) assert client.get_resource(resource) == json.loads(response_body)
'interfaces': [{'ratembps': 1000}, {'ratembps': 1000}]}, 'h-xx': {'regex': r'h-\d\d.qa1.eucalyptus-systems.com', 'mem': 68719476736, 'cpucores': 8, 'cpumhz': 2400}, 'a-xx-x': {'regex': r'a-\d\d-\w.qa1.eucalyptus-systems.com', 'mem': 137438953472, 'cpucores': 8, 'cpumhz': 2600, 'interfaces': [{'ratembps': 10000}]} } with open(newhosts, "r") as file: collected = json.loads(file.read()) # client = ResourceManagerClient(endpoint="http://10.111.4.100:5000") # PRODUCTION client = ResourceManagerClient(endpoint="http://127.0.0.1:5000") # USE "http://10.111.4.100:5000" for production ourlist = client.get_all_resources() for item in ourlist: machine = client.get_resource(item['hostname']) # PRODUCTION for mtype in memtable: match = re.search(memtable[mtype]['regex'], item['hostname']) if match: if 'tags' not in machine.keys(): machine[u'tags'] = {} if item['hostname'] in collected['hosts'].keys(): print "{}: updating to {} (collected) (vs {} table)".format( item['hostname'], int(collected['hosts'][item['hostname']])*1024, memtable[mtype]['mem']) machine[u'tags'][u'memory'] = int(collected['hosts'][item['hostname']])*1024 # PRODUCTION else: print "{}: updating to {} (table)".format(item['hostname'], memtable[mtype]['mem']) machine[u'tags'][u'memory'] = memtable[mtype]['mem'] # PRODUCTION
'interfaces': [{ 'ratembps': 10000 }] } } with open(newhosts, "r") as file: collected = json.loads(file.read()) # client = ResourceManagerClient(endpoint="http://10.111.4.100:5000") # PRODUCTION client = ResourceManagerClient( endpoint="http://127.0.0.1:5000" ) # USE "http://10.111.4.100:5000" for production ourlist = client.get_all_resources() for item in ourlist: machine = client.get_resource(item['hostname']) # PRODUCTION for mtype in memtable: match = re.search(memtable[mtype]['regex'], item['hostname']) if match: if 'tags' not in machine.keys(): machine[u'tags'] = {} if item['hostname'] in collected['hosts'].keys(): print "{}: updating to {} (collected) (vs {} table)".format( item['hostname'], int(collected['hosts'][item['hostname']]) * 1024, memtable[mtype]['mem']) machine[u'tags'][u'memory'] = int(collected['hosts'][ item['hostname']]) * 1024 # PRODUCTION else: print "{}: updating to {} (table)".format( item['hostname'], memtable[mtype]['mem'])