mac address string generator
This commit is contained in:
parent
1c648824f2
commit
4cb5d21bad
2 changed files with 28 additions and 6 deletions
27
grid.py
27
grid.py
|
@ -33,15 +33,14 @@ def querydb(cubeid):
|
||||||
dbf = open(dbfile, 'r')
|
dbf = open(dbfile, 'r')
|
||||||
data = json.load(dbf)
|
data = json.load(dbf)
|
||||||
dbf.close()
|
dbf.close()
|
||||||
logger.info('grid> {} --> {}'.format(dbfile, data))
|
logger.info('{}> <-- {}'.format(dbfile, data))
|
||||||
return data
|
return data
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.critical('grid> {}'.format(e))
|
logger.critical('{}> '.format(e))
|
||||||
pass
|
pass
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def writedb(src_data):
|
def writedb(src_data):
|
||||||
""" create new metadata file """
|
""" create new metadata file """
|
||||||
try:
|
try:
|
||||||
|
@ -139,6 +138,26 @@ def generate_ipv4(region_name, how_many=1):
|
||||||
return requested_ips
|
return requested_ips
|
||||||
|
|
||||||
|
|
||||||
|
def genmac(int_value):
|
||||||
|
""" convert kinda long enough int to MAC string """
|
||||||
|
prefix_sum = sum(int(digit) for digit in str(int_value))
|
||||||
|
if (prefix_sum > 255):
|
||||||
|
prefix_hex = 'ff'
|
||||||
|
else:
|
||||||
|
prefix_hex = format(prefix_sum, 'x')
|
||||||
|
|
||||||
|
suffix = int(str(int_value)[-12:])
|
||||||
|
suffix_hex = format(suffix, 'x')
|
||||||
|
length = len(suffix_hex)
|
||||||
|
suffix_hex = suffix_hex.zfill(length+length%2)
|
||||||
|
|
||||||
|
addr = prefix_hex + suffix_hex
|
||||||
|
#logger.info('grid> mac-string {} genrated from: {} ({}->{}) ({}->{}) '.format(addr, int_value, prefix, prefix_hex, suffix, suffix_hex))
|
||||||
|
print('grid> mac-string {} genrated from: {} (sum {}->{}) ({}->{}) '.format(addr, int_value, prefix_sum, prefix_hex, suffix, suffix_hex))
|
||||||
|
|
||||||
|
return ':'.join(addr[i:i+2] for i in range(0,len(addr),2))
|
||||||
|
|
||||||
|
|
||||||
def generate_vmid():
|
def generate_vmid():
|
||||||
""" analyzes cached grid data and return proposed vmid for new machines """
|
""" analyzes cached grid data and return proposed vmid for new machines """
|
||||||
grid_data = readcache()
|
grid_data = readcache()
|
||||||
|
@ -192,6 +211,8 @@ def findDiff(d1, d2, path=""):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### DEPRECATED
|
||||||
def readreal():
|
def readreal():
|
||||||
""" read the current state and return its contents """
|
""" read the current state and return its contents """
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -82,8 +82,8 @@ def vmcreate(req):
|
||||||
for ip in ipv4_list:
|
for ip in ipv4_list:
|
||||||
ipv4_dict[str(ipidx)] = str(ip)
|
ipv4_dict[str(ipidx)] = str(ip)
|
||||||
ipidx += 1
|
ipidx += 1
|
||||||
#TODO: aa:aa:aa <- generate from slave name to hex bb:bb:bb <- generate from cubeid to hex
|
|
||||||
macaddr = 'E2:C6:DE:BE:98:F2'
|
macaddr = grid.genmac(cubeid)
|
||||||
|
|
||||||
#metadata
|
#metadata
|
||||||
deploy = { 'cube': int(cubeid),
|
deploy = { 'cube': int(cubeid),
|
||||||
|
@ -262,7 +262,7 @@ def vmrrd(cubeid):
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
def vmvnc(vm_id):
|
def vmvnc(cubeid):
|
||||||
""" invoke vnc ticket """
|
""" invoke vnc ticket """
|
||||||
slave_name, vm_type, vm_id = grid.query_vm(cubeid)
|
slave_name, vm_type, vm_id = grid.query_vm(cubeid)
|
||||||
proxobject = auth(slave_name)
|
proxobject = auth(slave_name)
|
||||||
|
@ -281,6 +281,7 @@ def vmvnc(vm_id):
|
||||||
slaveip = ioconfig.parser.get(str(slave_name), 'ipv4')
|
slaveip = ioconfig.parser.get(str(slave_name), 'ipv4')
|
||||||
#slaveport = socket['port']
|
#slaveport = socket['port']
|
||||||
slaveport = ticket['port']
|
slaveport = ticket['port']
|
||||||
|
slave_id = 1 #TODO: fix this
|
||||||
listenport = str(int(slaveport) + 1000 + (int(slave_id) * 100)) #TODO: max 100 parallel connections/slave.
|
listenport = str(int(slaveport) + 1000 + (int(slave_id) * 100)) #TODO: max 100 parallel connections/slave.
|
||||||
myip = getmyip()
|
myip = getmyip()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue