diff --git a/grid.py b/grid.py index f6074c1..32cb7a3 100644 --- a/grid.py +++ b/grid.py @@ -60,8 +60,17 @@ def delete(data): return None def phyidgen(slave_name, unit_type): - """ scans all current db files and generate new id within a range between 1000 and 9999, and avoid any duplicates """ - full_list = list(range(1000,10000)) + """ 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. """ + 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)) exclude_list = [] directory = 'db/' for dbfile in os.listdir(directory): @@ -76,7 +85,9 @@ def phyidgen(slave_name, unit_type): valid_list = list(set(full_list) - set(exclude_list)) if len(valid_list) > 1: choice = random.choice(valid_list) - logger.info('{}> physical id generated: {}'.format(slave_name, choice)) + #logger.info('{}[{}]> unit type: {} physical id: {}'.format(str(json['clientemail']), str(slave_name), str(unit_type), str(choice))) + logger.info('[{}]> unit type: {} physical id: {}'.format(str(slave_name), str(unit_type), str(choice))) + print(str(exclude_list)) return choice else: logger.critical('{}> no free physical ids!'.format(slave_name)) diff --git a/plugin.py b/plugin.py index d7ea50e..c867f78 100644 --- a/plugin.py +++ b/plugin.py @@ -72,8 +72,10 @@ def create(json): memory=json['mem'], scsihw='virtio-scsi-pci', scsi0='file=lvm:' + image_name + ',discard=on', + net0='virtio,bridge=' + json['net0if'], description=description) - except: + except Exception as e: + print(e) response = { 'status': 'kvm_create_failed' } return response data = { 'unit_id': int(unit_id), @@ -93,14 +95,14 @@ def create(json): vm_name_utf8 = json['hostname'] vm_name = unidecode(vm_name_utf8) image_name = 'vm-' + str(phy_id) + '-disk-1' - try: - local_storage = proxobject.nodes(real_slave_name).storage('lvm') - storage_create_result = local_storage.content.post(vmid=phy_id, filename=image_name, size=json['hdd'] + 'G') - ioconfig.logger.info('%s[%s]> allocated %s as %s' % (json['clientemail'], slave_name, json['hdd'], image_name)) - except: - ioconfig.logger.info('%s[%s]> unable to allocate %s' % (json['clientemail'], slave_name, image_name)) - response = { 'status':'vol_alloc_failed' } - return response + #try: + # local_storage = proxobject.nodes(real_slave_name).storage('lvm') + # storage_create_result = local_storage.content.post(vmid=phy_id, filename=image_name, size=json['hdd'] + 'G') + # ioconfig.logger.info('%s[%s]> allocated %s as %s' % (json['clientemail'], slave_name, json['hdd'], image_name)) + #except: + # ioconfig.logger.info('%s[%s]> unable to allocate %s' % (json['clientemail'], slave_name, image_name)) + # response = { 'status':'vol_alloc_failed' } + # return response try: vm_pass = json['rootpass'] except: @@ -113,9 +115,10 @@ def create(json): password=vm_pass, cores=json['cpu'], memory=json['mem'], - net0='name=eth0,bridge=' + json['net0if'] + ',gw=' + json['region_gw'] + ',hwaddr=' + json['macaddr'] + ',ip=' + json['ipv4addr'] + '/' + json['region_netmask'], + net0='name=eth0,bridge=' + json['net0if'] + ',ip=' + json['net0ip'] + '/' + json['net0mask'], + net1='name=eth1,bridge=' + json['net1if'] + ',ip=' + json['net1ip'] + '/' + json['net1mask'] + ',gw=' + json['net1gw'], ostemplate='backup:vztmpl/debian-9.0-standard_9.0-2_amd64.tar.gz', - rootfs='volume=lvm:' + image_name, + rootfs='volume=lvm:' + str(json['hdd']), swap=32, description=description) except: