def configure_host_by_mac(mac_addr): avl_private_ip = None ip_info = db.private_ip_pool(mac_addr=mac_addr) if ip_info: avl_private_ip = ip_info.private_ip else: avl_ip = db((~db.private_ip_pool.id.belongs(db()._select(db.host.host_ip))) & (db.private_ip_pool.vlan == HOST_VLAN_ID)).select(db.private_ip_pool.private_ip) if avl_ip.first(): ip_info = avl_ip.first() avl_private_ip = ip_info['private_ip'] if avl_private_ip: logger.debug('Available IP for mac address %s is %s'%(mac_addr, avl_private_ip)) host_name = 'host'+str(avl_private_ip.split('.')[3]) create_dhcp_entry(host_name, mac_addr, avl_private_ip) db.host[0] = dict(host_ip=ip_info['id'], host_name=host_name, mac_addr=mac_addr, status=HOST_STATUS_DOWN) return 'Host configured. Proceed for PXE boot.' else: logger.error('Available Private IPs for host are exhausted.') return 'Available Private IPs for host are exhausted.'
def add_private_ip(ip_pool_id): private_ip_pool = db.private_ip_pool[ip_pool_id] if private_ip_pool.vlan != HOST_VLAN_ID: mac_address = private_ip_pool.mac_addr if mac_address == None: while True: mac_address = generate_random_mac() if not (db.private_ip_pool(mac_addr=mac_address)):break #Update generated mac address in DB private_ip_pool.update_record(mac_addr=mac_address) create_dhcp_entry(None, mac_address, private_ip_pool.private_ip)