From 312bba313681f408461832a8e4fe43b4de56ede0 Mon Sep 17 00:00:00 2001 From: Venkata Harshavardhan Reddy Allu Date: Thu, 21 Mar 2019 20:56:23 +0530 Subject: Add new methods to openstack_utils When we use OSM as MANO_COMPONENT, we don't have methods to retrieve the object instances of ports and VMs. So, we need these methods to gather details of a : - VM using the 'id' get_instance(id) - port using their 'ip_address' get_port_by_ip(ip_address) Change-Id: Ica45bf49dddb38a3811b049d67c363ac606fde7a Signed-off-by: Venkata Harshavardhan Reddy Allu --- sfc/lib/openstack_utils.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'sfc/lib') diff --git a/sfc/lib/openstack_utils.py b/sfc/lib/openstack_utils.py index 59ccdaca..c46ff123 100644 --- a/sfc/lib/openstack_utils.py +++ b/sfc/lib/openstack_utils.py @@ -188,6 +188,12 @@ class OpenStackSFC: return instance, port_list + def get_instance(self, instance_id): + """ + Return a dictionary of metadata for a server instance + """ + return self.conn.compute.get_server_metadata(instance_id) + def get_av_zones(self): ''' Return the availability zone each host belongs to @@ -237,6 +243,17 @@ class OpenStackSFC: raise Exception("There is no VM with name '{}'!!".format(vm_name)) + def get_port_by_ip(self, ip_address): + """ + Return a dictionary of metadata for a port instance + by its ip_address + """ + + ports = self.conn.network.ports() + for port in ports: + if port.fixed_ips[0]['ip_address'] == ip_address: + return self.conn.network.get_port(port.id) + def assign_floating_ip(self, vm, vm_port): ''' Assign floating ips to all the VMs -- cgit 1.2.3-korg