Add openflow-port-mapping CLI command
[osm/openvim.git] / host_thread.py
index c29f79a..d8bca2e 100644 (file)
@@ -41,6 +41,7 @@ from vim_schema import localinfo_schema, hostinfo_schema
 import random
 import os
 
+#TODO: insert a logging system
 
 # from logging import Logger
 # import auxiliary_functions as af
@@ -48,9 +49,6 @@ import os
 # TODO: insert a logging system
 
 
-# global lvirt_module
-# lvirt_module=None  #libvirt module is charged only if not in test mode
-
 class host_thread(threading.Thread):
     lvirt_module = None
 
@@ -343,23 +341,20 @@ class host_thread(threading.Thread):
                 elif task[0] == 'new-ovsbridge':
                     print self.name, ": Creating compute OVS bridge"
                     self.create_ovs_bridge()
-                    break
                 elif task[0] == 'new-vxlan':
                     print self.name, ": Creating vxlan tunnel=" + task[1] + ", remote ip=" + task[2]
                     self.create_ovs_vxlan_tunnel(task[1], task[2])
-                    break
                 elif task[0] == 'del-ovsbridge':
                     print self.name, ": Deleting OVS bridge"
                     self.delete_ovs_bridge()
-                    break
                 elif task[0] == 'del-vxlan':
                     print self.name, ": Deleting vxlan " + task[1] + " tunnel"
                     self.delete_ovs_vxlan_tunnel(task[1])
-                    break
                 elif task[0] == 'create-ovs-bridge-port':
                     print self.name, ": Adding port ovim-" + task[1] + " to OVS bridge"
                     self.create_ovs_bridge_port(task[1])
                 elif task[0] == 'del-ovs-port':
+                    print self.name, ": Delete bridge attached to ovs port vlan {} net {}".format(task[1], task[2])
                     self.delete_bridge_port_attached_to_ovs(task[1], task[2])
                 else:
                     print self.name, ": unknown task", task
@@ -506,8 +501,12 @@ class host_thread(threading.Thread):
             self.tab()+'<apic/>' +\
             self.tab()+'<pae/>'+ \
             self.dec_tab() +'</features>'
-        if windows_os or topo=="oneSocket":
-            text += self.tab() + "<cpu mode='host-model'> <topology sockets='1' cores='%d' threads='1' /> </cpu>"% vcpus
+        if topo == "oneSocket:hyperthreading":
+            if vcpus % 2 != 0:
+                return -1, 'Cannot expose hyperthreading with an odd number of vcpus'
+            text += self.tab() + "<cpu mode='host-model'> <topology sockets='1' cores='%d' threads='2' /> </cpu>" % vcpus/2
+        elif windows_os or topo == "oneSocket":
+            text += self.tab() + "<cpu mode='host-model'> <topology sockets='1' cores='%d' threads='1' /> </cpu>" % vcpus
         else:
             text += self.tab() + "<cpu mode='host-model'></cpu>"
         text += self.tab() + "<clock offset='utc'/>" +\
@@ -1032,7 +1031,7 @@ class host_thread(threading.Thread):
         else:
             return False
 
-    def launch_dhcp_server(self, vlan, ip_range, netmask, dhcp_path):
+    def launch_dhcp_server(self, vlan, ip_range, netmask, dhcp_path, gateway):
         """
         Generate a linux bridge and attache the port to a OVS bridge
         :param self:
@@ -1040,6 +1039,7 @@ class host_thread(threading.Thread):
         :param ip_range: IP dhcp range
         :param netmask: network netmask
         :param dhcp_path: dhcp conf file path that live in namespace side
+        :param gateway: Gateway address for dhcp net
         :return: True if success
         """
 
@@ -1074,7 +1074,8 @@ class host_thread(threading.Thread):
         if not content:
             command = 'sudo  ip netns exec ' + net_namespace + ' /usr/sbin/dnsmasq --strict-order --except-interface=lo ' \
               '--interface=' + interface + ' --bind-interfaces --dhcp-hostsdir=' + dhcp_path + \
-              ' --dhcp-range ' + dhcp_range + ' --pid-file=' + pid_file + ' --dhcp-leasefile=' + leases_path + '  --listen-address ' + ip_range[0]
+              ' --dhcp-range ' + dhcp_range + ' --pid-file=' + pid_file + ' --dhcp-leasefile=' + leases_path + \
+              '  --listen-address ' + gateway
 
         print self.name, ': command:', command
         (_, stdout, _) = self.ssh_conn.exec_command(command)