fixes issues with ovs type using bridge netwoks
[osm/openvim.git] / vim_db.py
index 93f2f45..386f29f 100644 (file)
--- a/vim_db.py
+++ b/vim_db.py
@@ -3,7 +3,7 @@
 
 ##
 # Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
-# This file is part of openmano
+# This file is part of openvim
 # All Rights Reserved.
 #
 # Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -34,7 +34,7 @@ __date__ ="$10-jul-2014 12:07:15$"
 
 import MySQLdb as mdb
 import uuid as myUuid
-from utils import auxiliary_functions as af
+import auxiliary_functions as af
 import json
 import logging
 
@@ -173,7 +173,7 @@ class vim_db():
     def __get_used_net_vlan(self):
         #get used from database if needed
         try:
-            cmd = "SELECT vlan FROM nets WHERE vlan>='%s' and (type='ptp' or type='data') ORDER BY vlan LIMIT 25" % self.net_vlan_lastused
+            cmd = "SELECT vlan FROM nets WHERE vlan>='%s' ORDER BY vlan LIMIT 25" % self.net_vlan_lastused
             with self.con:
                 self.cur = self.con.cursor()
                 self.logger.debug(cmd)
@@ -1495,7 +1495,7 @@ class vim_db():
                 r,c = self.format_error(e, "new_instance", cmd)
                 if r!=-HTTP_Request_Timeout or retry_==1: return r,c
 
-    def delete_instance(self, instance_id, tenant_id, net_list, ports_to_free, logcause="requested by http"):
+    def delete_instance(self, instance_id, tenant_id, net_dataplane_list, ports_to_free, net_ovs_list, logcause="requested by http"):
         for retry_ in range(0,2):
             cmd=""
             try:
@@ -1515,7 +1515,16 @@ class vim_db():
                     self.cur.execute(cmd)
                     net_list__ = self.cur.fetchall()
                     for net in net_list__:
-                        net_list.append(net[0])
+                        net_dataplane_list.append(net[0])
+
+                    # get ovs manangement nets
+                    cmd = "SELECT DISTINCT net_id from ports WHERE instance_id = " \
+                          "'%s' AND net_id is not Null AND type='instance:bridge'" % instance_id
+                    self.logger.debug(cmd)
+                    self.cur.execute(cmd)
+                    net_list__ = self.cur.fetchall()
+                    for net in net_list__:
+                        net_ovs_list.append(net[0])
 
                     #get dataplane interfaces releases by this VM; both PF and VF with no other VF 
                     cmd="SELECT source_name, mac FROM (SELECT root_id, count(instance_id) as used FROM resources_port WHERE instance_id='%s' GROUP BY root_id ) AS A" % instance_id \