Add fixed_ip and files parameters in openstack_utils in create_instance 37/16637/7
authorjose.lausuch <jose.lausuch@ericsson.com>
Sat, 9 Jul 2016 10:34:42 +0000 (12:34 +0200)
committerJose Lausuch <jose.lausuch@ericsson.com>
Mon, 11 Jul 2016 14:27:46 +0000 (14:27 +0000)
This is needed i.e. for sdnvpn test case

Change-Id: I235a6871a86b7a0c4a9ab27a3aef4bfd62ba4d43
Signed-off-by: jose.lausuch <jose.lausuch@ericsson.com>
utils/openstack_utils.py

index 8788fd1..2103c7f 100644 (file)
@@ -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
 # *********************************************