From 845f2072c13ebc5cbced6f3643d768b53dae36de Mon Sep 17 00:00:00 2001 From: "jose.lausuch" Date: Sat, 9 Jul 2016 12:34:42 +0200 Subject: Add fixed_ip and files parameters in openstack_utils in create_instance This is needed i.e. for sdnvpn test case Change-Id: I235a6871a86b7a0c4a9ab27a3aef4bfd62ba4d43 Signed-off-by: jose.lausuch --- utils/openstack_utils.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'utils') diff --git a/utils/openstack_utils.py b/utils/openstack_utils.py index 8788fd1fc..2103c7fef 100644 --- a/utils/openstack_utils.py +++ b/utils/openstack_utils.py @@ -207,32 +207,40 @@ def create_instance(flavor_name, instance_name="functest-vm", confdrive=True, userdata=None, - av_zone=''): + av_zone='', + fixed_ip=None, + files=None): nova_client = get_nova_client() try: flavor = nova_client.flavors.find(name=flavor_name) except: print("Error: Flavor '%s' not found. Available flavors are:" % flavor_name) - print(nova_client.flavor.list()) + print(nova_client.flavors.list()) return -1 + if fixed_ip is not None: + nics = {"net-id": network_id, "v4-fixed-ip": fixed_ip} + else: + nics = {"net-id": network_id} if userdata is None: instance = nova_client.servers.create( name=instance_name, flavor=flavor, image=image_id, - nics=[{"net-id": network_id}], - availability_zone=av_zone + nics=[nics], + availability_zone=av_zone, + files=files ) else: instance = nova_client.servers.create( name=instance_name, flavor=flavor, image=image_id, - nics=[{"net-id": network_id}], + nics=[nics], config_drive=confdrive, userdata=userdata, - availability_zone=av_zone + availability_zone=av_zone, + files=files ) return instance @@ -243,7 +251,9 @@ def create_instance_and_wait_for_active(flavor_name, instance_name="", config_drive=False, userdata="", - av_zone=''): + av_zone='', + fixed_ip=None, + files=None): SLEEP = 3 VM_BOOT_TIMEOUT = 180 nova_client = get_nova_client() @@ -253,8 +263,9 @@ def create_instance_and_wait_for_active(flavor_name, instance_name, config_drive, userdata, - av_zone) - + av_zone=av_zone, + fixed_ip=fixed_ip, + files=files) count = VM_BOOT_TIMEOUT / SLEEP for n in range(count, -1, -1): status = get_instance_status(nova_client, instance) @@ -635,7 +646,6 @@ def update_bgpvpn(neutron_client, bgpvpn_id, **kwargs): def delete_bgpvpn(neutron_client, bgpvpn_id): return neutron_client.delete_bgpvpn(bgpvpn_id) - # ********************************************* # SEC GROUPS # ********************************************* -- cgit 1.2.3-korg