- searchString = '.*vm%d_private_ip.*?([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*)' % vm
- matchObj = re.search(searchString, output, re.DOTALL)
- vmAdminIP.append(matchObj.group(1))
- searchString = '.*vm%d_dataplane_mac.*?([a-fA-F0-9:]{17})' % vm
- matchObj = re.search(searchString, output, re.DOTALL)
- vmDPmac.append(matchObj.group(1))
- log.info('VM%d: (admin IP: %s), (dataplane IP: %s), (dataplane MAC: %s)' % (vm,vmAdminIP[-1],vmDPIP[-1],vmDPmac[-1]))
- config.add_section('VM%d'%vm)
- config.set('VM%d'%vm, 'admin_ip', vmAdminIP[-1])
- config.set('VM%d'%vm, 'dp_ip', vmDPIP[-1])
- config.set('VM%d'%vm, 'dp_mac', vmDPmac[-1])
+ ServerToBeCreated.append("yes")
+ # Checking if the flavor already exists, if not create it
+ log.debug("Checking flavor: "+flavor_name)
+ cmd = 'openstack flavor show '+flavor_name
+ log.debug (cmd)
+ cmd = cmd + ' |grep "\sname\s" | tr -s " " | cut -d" " -f 4'
+ FlavorExist = subprocess.check_output(cmd , shell=True).strip()
+ if FlavorExist == flavor_name:
+ log.info("Flavor ("+flavor_name+") already installed")
+ else:
+ log.info('Creating flavor ...')
+ cmd = 'openstack flavor create %s %s'%(flavor_name,flavor_info)
+ log.debug(cmd)
+ cmd = cmd + ' |grep "\sname\s" | tr -s " " | cut -d" " -f 4'
+ FlavorExist = subprocess.check_output(cmd , shell=True).strip()
+ if FlavorExist == flavor_name:
+ cmd = 'openstack flavor set %s %s'%(flavor_name, flavor_meta_data)
+ log.debug(cmd)
+ subprocess.check_call(cmd , shell=True)
+ log.info("Flavor created")
+ else :
+ log.exception("Failed to create flavor: " + flavor_name)
+ raise Exception("Failed to create flavor: " + flavor_name)
+ if SRIOV_port == 'NO':
+ nic_info = '--nic net-id=%s --nic net-id=%s'%(internal_network,dataplane_network)
+ else:
+ nic_info = '--nic net-id=%s'%(internal_network)
+ for port in SRIOV_port.split(','):
+ nic_info = nic_info + ' --nic port-id=%s'%(port)
+ if vm==int(total_number_of_VMs):
+ # For the last server, we want to wait for the server creation to complete, so the next operations will succeeed (e.g. IP allocation)
+ # Note that this waiting is not bullet proof. Imagine, we loop through all the VMs, and the last VM was already running, while the previous
+ # VMs still needed to be created. Or the previous server creations take much longer than the last one.
+ # In that case, we might be to fast when we query for the IP & MAC addresses.
+ wait = ' --wait '
+ else:
+ wait = ' '
+ log.info("Creating server...")
+ cmd = 'openstack server create --flavor %s --key-name %s --image %s %s %s%s%s'%(flavor_name,key,image,nic_info,boot_info,wait,ServerName[-1])
+ log.debug(cmd)
+ cmd = cmd + ' |grep "\sname\s" | tr -s " " | cut -d" " -f 4'
+ ServerExist = subprocess.check_output(cmd , shell=True).strip()
+if floating_network <> 'NO':
+ for vm in range(0, int(total_number_of_VMs)):
+ if ServerToBeCreated[vm] =="yes":
+ log.info('Creating floating IP ...')
+ cmd = 'openstack floating ip create ' + floating_network
+ log.debug(cmd)
+ cmd = cmd + ' |grep "floating_ip_address " | tr -s " " | cut -d"|" -f 3'
+ vmAdminIP = subprocess.check_output(cmd , shell=True).strip()
+ log.info('Associating floating IP ...')
+ cmd = 'openstack server add floating ip %s %s'%(ServerName[vm],vmAdminIP)
+ log.debug(cmd)
+ output = subprocess.check_output(cmd , shell=True).strip()
+
+for vm in range(1, int(total_number_of_VMs)+1):
+ cmd = 'openstack server show %s'%(ServerName[vm-1])
+ log.debug(cmd)
+ output = subprocess.check_output(cmd , shell=True).strip()
+ searchString = '.*%s.*?([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*)' %(dataplane_network)
+ matchObj = re.search(searchString, output, re.DOTALL)
+ vmDPIP = matchObj.group(1)
+ searchString = '.*%s=([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+),*\s*([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)*' %(internal_network)
+ matchObj = re.search(searchString, output, re.DOTALL)
+ vmAdminIP = matchObj.group(2)
+ if vmAdminIP == None:
+ vmAdminIP = matchObj.group(1)
+ cmd = 'openstack port list |egrep "\\b%s\\b" | tr -s " " | cut -d"|" -f 4'%(vmDPIP)
+ log.debug(cmd)
+ vmDPmac = subprocess.check_output(cmd , shell=True).strip()
+ config.add_section('M%d'%vm)
+ config.set('M%d'%vm, 'name', ServerName[vm-1])
+ config.set('M%d'%vm, 'admin_ip', vmAdminIP)
+ config.set('M%d'%vm, 'dp_ip', vmDPIP)
+ config.set('M%d'%vm, 'dp_mac', vmDPmac)
+ log.info('%s: (admin IP: %s), (dataplane IP: %s), (dataplane MAC: %s)' % (ServerName[vm-1],vmAdminIP,vmDPIP,vmDPmac))
+