aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/common/openstack_utils.py
diff options
context:
space:
mode:
authorJing Lu <lvjing5@huawei.com>2017-08-21 01:44:25 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-08-21 01:44:25 +0000
commit36375f388880519336328406de1d1bbc408d4599 (patch)
tree03efc85f4f1d797c44586a21fe4c7f8e24c74ede /yardstick/common/openstack_utils.py
parent12bdd5ef73959b2ef9647410a3ba5a350228d896 (diff)
parentf01dea6918048d92984be69c6d96377dbd759d46 (diff)
Merge "Add common openstack opertation scenarios: network"
Diffstat (limited to 'yardstick/common/openstack_utils.py')
-rw-r--r--yardstick/common/openstack_utils.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/yardstick/common/openstack_utils.py b/yardstick/common/openstack_utils.py
index d86aee1cd..540d8d641 100644
--- a/yardstick/common/openstack_utils.py
+++ b/yardstick/common/openstack_utils.py
@@ -264,6 +264,15 @@ def create_aggregate_with_host(nova_client, aggregate_name, av_zone,
return True
+def create_keypair(nova_client, name, key_path=None): # pragma: no cover
+ try:
+ with open(key_path) as fpubkey:
+ keypair = get_nova_client().keypairs.create(name=name, public_key=fpubkey.read())
+ return keypair
+ except Exception:
+ log.exception("Error [create_keypair(nova_client)]")
+
+
def create_instance(json_body): # pragma: no cover
try:
return get_nova_client().servers.create(**json_body)
@@ -290,6 +299,17 @@ def create_instance_and_wait_for_active(json_body): # pragma: no cover
return None
+def attach_server_volume(server_id, volume_id, device=None): # pragma: no cover
+ try:
+ get_nova_client().volumes.create_server_volume(server_id, volume_id, device)
+ except Exception:
+ log.exception("Error [attach_server_volume(nova_client, '%s', '%s')]",
+ server_id, volume_id)
+ return False
+ else:
+ return True
+
+
def delete_instance(nova_client, instance_id): # pragma: no cover
try:
nova_client.servers.force_delete(instance_id)
@@ -417,6 +437,18 @@ def get_port_id_by_ip(neutron_client, ip_address): # pragma: no cover
'fixed_ips') if j['ip_address'] == ip_address), None)
+def create_floating_ip(neutron_client, extnet_id): # pragma: no cover
+ props = {'floating_network_id': extnet_id}
+ try:
+ ip_json = neutron_client.create_floatingip({'floatingip': props})
+ fip_addr = ip_json['floatingip']['floating_ip_address']
+ fip_id = ip_json['floatingip']['id']
+ except Exception:
+ log.error("Error [create_floating_ip(neutron_client)]")
+ return None
+ return {'fip_addr': fip_addr, 'fip_id': fip_id}
+
+
# *********************************************
# GLANCE
# *********************************************