Merge "Fix minor bug when iface is not connected to net"
diff --git a/osm_openvim/host_thread.py b/osm_openvim/host_thread.py
index 1f8fdb4..80d9986 100644
--- a/osm_openvim/host_thread.py
+++ b/osm_openvim/host_thread.py
@@ -1901,7 +1901,8 @@
             #TODO.Revise  self.server_forceoff(True)
 
             iface = conn.interfaceLookupByMACString(mac)
-            iface.destroy()
+            if iface.isActive():
+                iface.destroy()
             iface.create()
             self.logger.debug("restore_iface '%s' %s", name, mac)
         except host_thread.lvirt_module.libvirtError as e:
diff --git a/osm_openvim/ovim.py b/osm_openvim/ovim.py
index b0fa78f..3131e8a 100755
--- a/osm_openvim/ovim.py
+++ b/osm_openvim/ovim.py
@@ -42,7 +42,7 @@
 
 __author__ = "Alfonso Tierno, Leonardo Mirabal"
 __date__ = "$06-Feb-2017 12:07:15$"
-__version__ = "0.5.13-r529"
+__version__ = "0.5.14-r530"
 version_date = "May 2017"
 database_version = 18      #needed database schema version
 
@@ -564,7 +564,7 @@
                 bridge_net_name = net_provider[7:]
                 for brnet in self.config['bridge_nets']:
                     if brnet[0] == bridge_net_name:  # free
-                        if not brnet[3]:
+                        if brnet[3]:
                             raise ovimException("invalid 'provider:physical', "
                                                 "bridge '%s' is already used" % bridge_net_name, HTTP_Conflict)
                         bridge_net = brnet
@@ -627,7 +627,7 @@
                 if network["name"] in self.config["dhcp_server"].get("nets", ()):
                     self.config["dhcp_nets"].append(content)
                     self.logger.debug("dhcp_server: add new net", content)
-                elif not bridge_net and bridge_net[0] in self.config["dhcp_server"].get("bridge_ifaces", ()):
+                elif bridge_net and bridge_net[0] in self.config["dhcp_server"].get("bridge_ifaces", ()):
                     self.config["dhcp_nets"].append(content)
                     self.logger.debug("dhcp_server: add new net", content, content)
             return content
@@ -747,7 +747,7 @@
                 self.config["dhcp_nets"].remove(network_id)
             return content
         else:
-            raise ovimException("Error deleting  network %s" % network_id, HTTP_Internal_Server_Error)
+            raise ovimException("Error deleting network '{}': {}".format(network_id, content), -result)
 
     def get_openflow_rules(self, network_id=None):
         """
@@ -836,7 +836,7 @@
             else:
                 raise ovimException("Default Openflow controller not not running", HTTP_Not_Found)
 
-        if ofc_id in self.config['ofcs_thread']:
+        elif ofc_id in self.config['ofcs_thread']:
             conn = self.config['ofcs_thread'][ofc_id].OF_connector
         else:
             raise ovimException("Openflow controller not found with ofc_id={}".format(ofc_id), HTTP_Not_Found)
diff --git a/osm_openvim/vim_db.py b/osm_openvim/vim_db.py
index f69c305..b034342 100644
--- a/osm_openvim/vim_db.py
+++ b/osm_openvim/vim_db.py
@@ -1126,7 +1126,7 @@
 
                         #get dedicated ports and SRIOV
                         cmd = "SELECT port_id as iface_id, p.vlan as vlan, p.mac as mac_address, net_id, if(model='PF',\
-                            'yes',if(model='VF','no','yes:sriov')) as dedicated, rp.Mbps as bandwidth, name, vpci, \
+                            'yes',if(model='VF','no','yes:sriov')) as dedicated, p.Mbps as bandwidth, name, vpci, \
                             pci as source \
                             FROM resources_port as rp join ports as p on port_id=uuid  WHERE p.instance_id = '%s' AND numa_id = '%s' and p.type='instance:data'" % (instance_id, numa_id) 
                         self.logger.debug(cmd)