aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--utils/openstack_utils.py30
1 files changed, 20 insertions, 10 deletions
diff --git a/utils/openstack_utils.py b/utils/openstack_utils.py
index 8788fd1f..2103c7fe 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
# *********************************************