diff --git a/grid.py b/grid.py index 32cb7a3..5f8d7fa 100644 --- a/grid.py +++ b/grid.py @@ -61,16 +61,15 @@ def delete(data): def phyidgen(slave_name, unit_type): """ scans all current db files and generate new id within a range between - 1000 - 1999 for bridges, - 2000 - 2999 for routers, - and 7000 - 7999 for application servers - Avoid any duplicates. """ + 101 - 150 for deployments and avoids any duplicates. + reserved ids: + 100 - FrankenROUTER instance """ if str(unit_type) == 'br': full_list = list(range(1000,2999)) if str(unit_type) == 'lxc': full_list = list(range(2000,2999)) if str(unit_type) == 'kvm': - full_list = list(range(7000,7999)) + full_list = list(range(100,150)) exclude_list = [] directory = 'db/' for dbfile in os.listdir(directory): @@ -91,7 +90,7 @@ def phyidgen(slave_name, unit_type): return choice else: logger.critical('{}> no free physical ids!'.format(slave_name)) - return none + return 99999 def analyze_happiness(region_id): """ analyzes grid data for the reuqested region and returns proposed slave_id, diff --git a/plugin.py b/plugin.py index c867f78..06022bb 100644 --- a/plugin.py +++ b/plugin.py @@ -41,14 +41,17 @@ def create(json): except Exception as e: ioconfig.logger.warning('grid> slave not predefined. I will query for a capable one.') #slave_name = str(grid.query_happiness(region_id, weight)) - #slave_name = 'lexx' - slave_name = 'warrior' + #slave_name = 'warrior' + slave_name = 'lexx' ioconfig.logger.info('{}> slave selected'.format(slave_name)) proxobject = auth(slave_name) real_slave_name = proxobject.cluster.status.get()[0]['name'] unit_id = int(time.time() * 10000 * 10000) #currently unit_id is just a timestamp phy_id = grid.phyidgen(slave_name, json['type']) + if phy_id == 99999: + response = { 'status': 'phy_id_alloc_failed' } + return response description = ' (' + str(unit_id) + ' - ' + str(phy_id) + ')\n' + 'owned by ' + json['clientemail'] + ' (' + json['clientid'] + ')\n' if json['type'] == 'kvm': @@ -72,7 +75,7 @@ def create(json): memory=json['mem'], scsihw='virtio-scsi-pci', scsi0='file=lvm:' + image_name + ',discard=on', - net0='virtio,bridge=' + json['net0if'], + net0='virtio,bridge=' + json['net0if'] + 'tag=' + str(phy_id), description=description) except Exception as e: print(e) @@ -84,12 +87,12 @@ def create(json): 'clientemail': json['clientemail'], 'hostname': vm_name, 'region': region_name, - 'slave': slave_name, + 'slave': real_slave_name, 'phy_id': phy_id, 'net0if': json['net0if'] } grid.create(data) - response = { 'status': 'kvm_created', 'unit_id': unit_id, 'hostname': vm_name, 'region': region_name, 'slave': real_slave_name } + response = { 'status': 'kvm_created', 'unit_id': unit_id, 'region': region_name, 'slave': real_slave_name, 'vlanid': phy_id} if json['type'] == 'lxc': vm_name_utf8 = json['hostname'] @@ -136,24 +139,24 @@ def create(json): grid.create(data) response = { 'status': 'lxc_created', 'unit_id': unit_id, 'hostname': vm_name, 'region': region_name, 'slave': real_slave_name } - if json['type'] == 'br': - try: - create_result = proxobject.nodes(real_slave_name).network.post(iface='vmbr' + str(phy_id), - type='bridge', - autostart=1) - except Exception as e: - print(e) - return { 'status': 'br_create_failed' } - data = { 'unit_id': int(unit_id), - 'type': 'br', - 'clientid': json['clientid'], - 'clientemail': json['clientemail'], - 'region': region_name, - 'slave': slave_name, - 'phy_id': phy_id - } - grid.create(data) - response = { 'status': 'bridge_created', 'unit_id': unit_id, 'region': region_name, 'slave': real_slave_name, 'phy_id': phy_id } + #if json['type'] == 'br': + # try: + # create_result = proxobject.nodes(real_slave_name).network.post(iface='vmbr' + str(phy_id), + # type='bridge', + # autostart=1) + # except Exception as e: + # print(e) + # return { 'status': 'br_create_failed' } + # data = { 'unit_id': int(unit_id), + # 'type': 'br', + # 'clientid': json['clientid'], + # 'clientemail': json['clientemail'], + # 'region': region_name, + # 'slave': slave_name, + # 'phy_id': phy_id + # } + # grid.create(data) + # response = { 'status': 'bridge_created', 'unit_id': unit_id, 'region': region_name, 'slave': real_slave_name, 'phy_id': phy_id } return response