X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=VNFs%2FDPPD-PROX%2Fhelper-scripts%2Fopenstackrapid%2Fcreaterapid.py;h=867ce3240ed3ff7c666306a6663b1adc5f8c3ae1;hb=refs%2Fchanges%2F23%2F52423%2F1;hp=beca11c38f77cf60a52da9118660b450a485ab14;hpb=d29f8fa251540b48371f76e47ddba6315607d192;p=samplevnf.git diff --git a/VNFs/DPPD-PROX/helper-scripts/openstackrapid/createrapid.py b/VNFs/DPPD-PROX/helper-scripts/openstackrapid/createrapid.py index beca11c3..867ce324 100755 --- a/VNFs/DPPD-PROX/helper-scripts/openstackrapid/createrapid.py +++ b/VNFs/DPPD-PROX/helper-scripts/openstackrapid/createrapid.py @@ -31,7 +31,7 @@ from logging import handlers from prox_ctrl import prox_ctrl import ConfigParser -version="17.12.15" +version="18.2.12" stack = "rapid" #Default string for stack yaml = "rapid.yaml" #Default string for yaml file key = "prox" # This is also the default in the yaml file.... @@ -43,6 +43,9 @@ subnet = "dpdk-subnet" #subnet for dataplane subnet_cidr="10.10.10.0/24" # cidr for dataplane internal_network="admin_internal_net" floating_network="admin_floating_net" +vm1_availability_zone="nova" +vm2_availability_zone="nova" +vm3_availability_zone="nova" loglevel="DEBUG" # sets log level for writing to file runtime=10 # time in seconds for 1 test run @@ -59,6 +62,9 @@ def usage(): print(" [--subnet_cidr SUBNET_CIDR]") print(" [--internal_network ADMIN_NETWORK]") print(" [--floating_network ADMIN_NETWORK]") + print(" [--vm1_availability_zone ZONE_FOR_VM1]") + print(" [--vm2_availability_zone ZONE_FOR_VM2]") + print(" [--vm3_availability_zone ZONE_FOR_VM3]") print(" [--log DEBUG|INFO|WARNING|ERROR|CRITICAL") print(" [-h] [--help]") print("") @@ -76,7 +82,10 @@ def usage(): print(" --subnet DP_SUBNET Specify the subnet name to be used for the dataplane. Default is %s."%subnet) print(" --subnet_cidr SUBNET_CIDR Specify the subnet CIDR to be used for the dataplane. Default is %s."%subnet_cidr) print(" --internal_network NETWORK Specify the network name to be used for the control plane. Default is %s."%internal_network) - print(" --floating_network NETWORK Specify the external floating ip network name. Default is %s."%floating_network) + print(" --floating_network NETWORK Specify the external floating ip network name. Default is %s. NO if no floating ip used."%floating_network) + print(" --vm1_availability_zone ZONE Specify the availability zone for VM1. Default is %s."%vm1_availability_zone) + print(" --vm2_availability_zone ZONE Specify the availability zone for VM2. Default is %s."%vm2_availability_zone) + print(" --vm3_availability_zone ZONE Specify the availability zone for VM3. Default is %s."%vm3_availability_zone) print(" --log Specify logging level for log file output, screen output level is hard coded") print(" -h, --help Show help message and exit.") print("") @@ -85,7 +94,7 @@ def usage(): print("Note that %s is the default stack name. Replace with STACK_NAME if needed"%stack) try: - opts, args = getopt.getopt(sys.argv[1:], "vh", ["version","help", "yaml=","stack=","key=","flavor=","image=","image_file=","dataplane_network=","subnet=","subnet_cidr=","internal_network=","floating_network=","log="]) + opts, args = getopt.getopt(sys.argv[1:], "vh", ["version","help", "yaml=","stack=","key=","flavor=","image=","image_file=","dataplane_network=","subnet=","subnet_cidr=","internal_network=","floating_network=","vm1_availability_zone=","vm2_availability_zone=","vm3_availability_zone=","log="]) except getopt.GetoptError as err: print("===========================================") print(str(err)) @@ -135,6 +144,15 @@ for opt, arg in opts: elif opt in ("--floating_network"): floating_network = arg print ("Using floating ip network: "+ floating_network) + elif opt in ("--vm1_availability_zone"): + vm1_availability_zone = arg + print ("Using VM1 availability zone: "+ vm1_availability_zone) + elif opt in ("--vm2_availability_zone"): + vm2_availability_zone = arg + print ("Using VM2 availability zone: "+ vm2_availability_zone) + elif opt in ("--vm3_availability_zone"): + vm3_availability_zone = arg + print ("Using VM3 availability zone: "+ vm3_availability_zone) elif opt in ("--log"): loglevel = arg print ("Log level: "+ loglevel) @@ -205,16 +223,17 @@ else: raise Exception("Control plane network " + internal_network + " not existing") # Checking if the floating ip network already exists, if not, stop the script -log.debug("Checking floating ip network: "+floating_network) -cmd = 'openstack network show '+floating_network -log.debug (cmd) -cmd = cmd + ' |grep "status " | tr -s " " | cut -d" " -f 4' -NetworkExist = subprocess.check_output(cmd , shell=True).strip() -if NetworkExist == 'ACTIVE': - log.info("Floating ip network ("+floating_network+") already active") -else: - log.exception("Floating ip network " + floating_network + " not existing") - raise Exception("Floating ip network " + floating_network + " not existing") +if floating_network <>'NO': + log.debug("Checking floating ip network: "+floating_network) + cmd = 'openstack network show '+floating_network + log.debug (cmd) + cmd = cmd + ' |grep "status " | tr -s " " | cut -d" " -f 4' + NetworkExist = subprocess.check_output(cmd , shell=True).strip() + if NetworkExist == 'ACTIVE': + log.info("Floating ip network ("+floating_network+") already active") + else: + log.exception("Floating ip network " + floating_network + " not existing") + raise Exception("Floating ip network " + floating_network + " not existing") # Checking if the image already exists, if not create it log.debug("Checking image: "+image) @@ -278,7 +297,7 @@ else: cmd = cmd + ' |grep "name " | tr -s " " | cut -d" " -f 4' FlavorExist = subprocess.check_output(cmd , shell=True).strip() if FlavorExist == flavor: - cmd = 'openstack flavor set '+ flavor +' --property hw:mem_page_size="large" --property hw:cpu_policy="dedicated" --property hw:cpu_threads_policy="isolate"' + cmd = 'openstack flavor set '+ flavor +' --property hw:mem_page_size="large" --property hw:cpu_policy="dedicated" --property hw:cpu_thread_policy="isolate"' log.debug(cmd) subprocess.check_call(cmd , shell=True) log.info("Flavor created") @@ -334,7 +353,7 @@ cmd = cmd+' |grep "stack_status " | tr -s " " | cut -d"|" -f 3' StackRunning = subprocess.check_output(cmd , shell=True).strip() if StackRunning == '': log.info('Creating Stack ...') - cmd = 'openstack stack create -t '+ yaml + ' --parameter flavor="'+flavor +'" --parameter key="'+ key + '" --parameter image="'+image + '" --parameter dataplane_network="'+dataplane_network+ '" --parameter internal_network="'+internal_network+'" --parameter floating_network="'+floating_network+'" --wait '+stack + cmd = 'openstack stack create -t '+ yaml + ' --parameter flavor="'+flavor +'" --parameter key="'+ key + '" --parameter image="'+image + '" --parameter dataplane_network="'+dataplane_network+ '" --parameter internal_network="'+internal_network+'" --parameter floating_network="'+floating_network+'" --parameter vm1_availability_zone="'+vm1_availability_zone+'" --parameter vm2_availability_zone="'+vm2_availability_zone+'" --parameter vm3_availability_zone="'+vm3_availability_zone+'" --wait '+stack log.debug(cmd) cmd = cmd + ' |grep "stack_status " | tr -s " " | cut -d"|" -f 3' StackRunning = subprocess.check_output(cmd , shell=True).strip() @@ -357,9 +376,14 @@ for vm in range(1, int(total_number_of_VMs)+1): searchString = '.*vm%d_dataplane_ip.*?([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*)' % vm matchObj = re.search(searchString, output, re.DOTALL) vmDPIP.append(matchObj.group(1)) - searchString = '.*vm%d_public_ip.*?([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*)' % vm - matchObj = re.search(searchString, output, re.DOTALL) - vmAdminIP.append(matchObj.group(1)) + if floating_network <> 'NO': + searchString = '.*vm%d_public_ip.*?([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*)' % vm + matchObj = re.search(searchString, output, re.DOTALL) + vmAdminIP.append(matchObj.group(1)) + else: + 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))