utf8 hostnames fix

This commit is contained in:
deflax 2016-05-08 15:44:19 +03:00
parent d9701a2aa3
commit 1fdcca9882
4 changed files with 19 additions and 17 deletions

19
grid.py
View file

@ -193,14 +193,14 @@ def query_happiness(region_id):
for slaveid in all_slaves: for slaveid in all_slaves:
if str(grid_data[str(slaveid)]['alive']) == 'up': if str(grid_data[str(slaveid)]['alive']) == 'up':
alive_slaves.append(slaveid) alive_slaves.append(slaveid)
logger.info('grid> alive slaves ' + str(alive_slaves)) logger.info('region[{}]> alive slaves {}'.format(str(region_id), str(alive_slaves)))
#happy_slave = random.choice(alive_slaves) #happy_slave = random.choice(alive_slaves)
if len(alive_slaves) < 1: if len(alive_slaves) < 1:
logger.error('grid> grid is full. add more slaves') logger.error('region[{}]> grid is full. add more slaves'.format(str(region_id)))
else: else:
happy_slave = 1 #TODO: analyze slaves and make informed decision. happy_slave = 1 #TODO: analyze slaves and make informed decision.
logger.info('grid> ' + str(happy_slave) + ' selected') logger.info('region[{}]> {} selected'.format(str(region_id), str(happy_slave)))
return happy_slave return happy_slave
@ -223,7 +223,7 @@ def generate_ipv4(region_id, how_many=1):
counter = 0 counter = 0
while True: while True:
if counter == 50: if counter == 50:
logger.error('grid> ip range full') logger.error('region[{}]> ip range full'.format(str(region_id)))
return None return None
else: else:
counter += 1 counter += 1
@ -232,26 +232,26 @@ def generate_ipv4(region_id, how_many=1):
requested_ip = str(region_ips[requested_ip_index]) requested_ip = str(region_ips[requested_ip_index])
if requested_ip in tested_ips: if requested_ip in tested_ips:
logger.warning('grid> ip address ' + str(requested_ip) + ' already tested. cache: ' + str(tested_ips)) logger.warning('region[{}]> ip addres {} already tested. cache: {}'.format(str(region_id), str(requested_ip), str(tested_ips)))
continue continue
if requested_ip in requested_ips: if requested_ip in requested_ips:
logger.warning('grid> ip address ' + str(requested_ip) + ' already generated') logger.warning('region[{}]> ip address {} already generated.'.format(str(region_id), str(requested_ip)))
tested_ips.append(requested_ip) tested_ips.append(requested_ip)
continue continue
if requested_ip in all_ips: if requested_ip in all_ips:
position = used_ips.index(requested_ip) position = used_ips.index(requested_ip)
logger.warning('grid> ip address ' + str(requested_ip) + ' already exist. location:' + str(position)) logger.warning('region[{}]> ip address {} already exist. location: {}'.format(str(region_id), str(position)))
tested_ips.append(requested_ip) tested_ips.append(requested_ip)
continue continue
else: else:
tested_ips = [] #clear ip cache tested_ips = [] #clear ip cache
break break
logger.info('grid> ip address ' + requested_ip + ' selected') logger.info('region[{}]> ip address {} selected.'.format(str(region_id), str(requested_ip)))
requested_ips.append(requested_ip) requested_ips.append(requested_ip)
logger.info('grid> ip addresses ' + str(requested_ips) + ' selected') logger.info('region[{}]> ip addresses {} selected.'.format(str(region_id), str(requested_ips)))
return requested_ips return requested_ips
@ -397,6 +397,5 @@ if __name__ == '__main__':
#print(generate_ipv4(0,3)) #print(generate_ipv4(0,3))
#print(generate_vmid()) #print(generate_vmid())
#print(query_slave_data(0)) #print(query_slave_data(0))
print(query_vm(483039))
print(query_vm(147344)) print(query_vm(147344))

View file

@ -2,8 +2,6 @@
#makes jsons human (and machine) readable #makes jsons human (and machine) readable
#TODO: scan for all jsons and rewrite them.
echo "CACHE:" echo "CACHE:"
cat grid-cache.json | python3 -m json.tool cat grid-cache.json | python3 -m json.tool
echo " " echo " "
@ -12,4 +10,3 @@ cat grid-real.json | python3 -m json.tool
echo " " echo " "
echo "CLIENTS:" echo "CLIENTS:"
cat clients.json | python3 -m json.tool cat clients.json | python3 -m json.tool

View file

@ -9,6 +9,7 @@ import base64
import json import json
import time import time
import socket import socket
from unidecode import unidecode
#local #local
import grid import grid
@ -64,7 +65,10 @@ def vmcreate(req):
slave_id = str(grid.query_happiness(region_id)) slave_id = str(grid.query_happiness(region_id))
vm_id = str(grid.generate_vmid()) vm_id = str(grid.generate_vmid())
vm_ipv4 = grid.generate_ipv4(region_id, req['vps_ipv4']) vm_ipv4 = grid.generate_ipv4(region_id, req['vps_ipv4'])
vm_name = req['hostname']
vm_name_utf8 = req['hostname']
vm_name = unidecode(vm_name_utf8)
vm_pass = req['vmpass'] vm_pass = req['vmpass']
client_id = req['clientid'] client_id = req['clientid']
client_name = req['clientname'] client_name = req['clientname']
@ -74,7 +78,7 @@ def vmcreate(req):
ipv4_dict = {} ipv4_dict = {}
ipidx = 0 ipidx = 0
#ioconfig.logger.info('grid[' + slave_name + ']> recieved data: %s, %s, %s, %s, %s', region_id, slave_id, vm_id, vm_ipv4, req) ioconfig.logger.info('slave[' + slave_name + ']> recieved data: %s, %s, %s, %s, %s', region_id, slave_id, vm_id, vm_ipv4, req)
for ip in vm_ipv4: for ip in vm_ipv4:
ipv4_dict[str(ipidx)] = str(ip) ipv4_dict[str(ipidx)] = str(ip)
ipidx += 1 ipidx += 1
@ -134,7 +138,7 @@ def vmstatus(vm_id):
proxobject = auth(slave_id) proxobject = auth(slave_id)
vm_type = vm_type.lower() vm_type = vm_type.lower()
slave_name = proxobject.cluster.status.get()[0]['name'] slave_name = proxobject.cluster.status.get()[0]['name']
ioconfig.logger.info('grid[%s]> get status of %s %s' % (slave_name, vm_type, vm_id)) ioconfig.logger.info('slave[%s]> get status of %s %s' % (slave_name, vm_type, vm_id))
if vm_type == 'kvm': if vm_type == 'kvm':
result = proxobject.nodes(slave_name).qemu(vm_id).status.current.get() result = proxobject.nodes(slave_name).qemu(vm_id).status.current.get()
if vm_type == 'lxc': if vm_type == 'lxc':
@ -298,5 +302,6 @@ def getmyip():
if __name__ == '__main__': if __name__ == '__main__':
#internal module tests #internal module tests
time.sleep(30) time.sleep(1)
print(vmvnc(656758))

View file

@ -6,3 +6,4 @@ urllib
netaddr netaddr
proxmoxer proxmoxer
websockify websockify
unidecode