scripts to install openmano as a service on Xenial, and enhancements on installation
[osm/RO.git] / nfvo.py
diff --git a/nfvo.py b/nfvo.py
index 9c6dace..c33a44b 100644 (file)
--- a/nfvo.py
+++ b/nfvo.py
@@ -1318,6 +1318,7 @@ def start_scenario(mydb, tenant_id, scenario_id, instance_scenario_name, instanc
 
 def create_instance(mydb, tenant_id, instance_dict):
     #print "Checking that nfvo_tenant_id exists and getting the VIM URI and the VIM tenant_id"
+    logger.debug("Creating instance...")
     scenario = instance_dict["scenario"]
     datacenter_id = None
     datacenter_name=None
@@ -1771,23 +1772,39 @@ def instance_action(mydb,nfvo_tenant,instance_id, action_dict):
             try:
                 data = myvim.action_vminstance(vm['vim_vm_id'], action_dict)
                 if "console" in action_dict:
-                    if data["server"]=="127.0.0.1" or data["server"]=="localhost":
+                    if not global_config["http_console_proxy"]:
+                        vm_result[ vm['uuid'] ] = {"vim_result": 200,
+                                                   "description": "{protocol}//{ip}:{port}/{suffix}".format(
+                                                                                protocol=data["protocol"],
+                                                                                ip = data["server"],
+                                                                                port = data["port"],
+                                                                                suffix = data["suffix"]),
+                                                   "name":vm['name']
+                                                }
+                        vm_ok +=1
+                    elif data["server"]=="127.0.0.1" or data["server"]=="localhost":
                         vm_result[ vm['uuid'] ] = {"vim_result": -HTTP_Unauthorized,
                                                    "description": "this console is only reachable by local interface",
                                                    "name":vm['name']
                                                 }
                         vm_error+=1
-                        continue
+                    else:
                     #print "console data", data
-                    try: 
-                        console_thread = create_or_use_console_proxy_thread(data["server"], data["port"])
-                        vm_result[ vm['uuid'] ] = {"vim_result": 200,
-                                                   "description": "%s//%s:%d/%s" %(data["protocol"], console_thread.host, console_thread.port, data["suffix"]),
-                                                   "name":vm['name']
-                                                }
-                        vm_ok +=1
-                    except NfvoException as e:
-                        vm_result[ vm['uuid'] ] = {"vim_result": e.http_code, "name":vm['name'], "description": str(e)}
+                        try: 
+                            console_thread = create_or_use_console_proxy_thread(data["server"], data["port"])
+                            vm_result[ vm['uuid'] ] = {"vim_result": 200,
+                                                       "description": "{protocol}//{ip}:{port}/{suffix}".format(
+                                                                                    protocol=data["protocol"],
+                                                                                    ip = global_config["http_console_host"],
+                                                                                    port = console_thread.port,
+                                                                                    suffix = data["suffix"]),
+                                                       "name":vm['name']
+                                                    }
+                            vm_ok +=1
+                        except NfvoException as e:
+                            vm_result[ vm['uuid'] ] = {"vim_result": e.http_code, "name":vm['name'], "description": str(e)}
+                            vm_error+=1
+
                 else:
                     vm_result[ vm['uuid'] ] = {"vim_result": 200, "description": "ok", "name":vm['name']}
                     vm_ok +=1
@@ -1796,9 +1813,9 @@ def instance_action(mydb,nfvo_tenant,instance_id, action_dict):
                 vm_error+=1
 
     if vm_ok==0: #all goes wrong
-        return 1, vm_result
+        return vm_result
     else:
-        return 1, vm_result
+        return vm_result
     
 def create_or_use_console_proxy_thread(console_server, console_port):
     #look for a non-used port
@@ -1808,7 +1825,7 @@ def create_or_use_console_proxy_thread(console_server, console_port):
         return global_config["console_thread"][console_thread_key]
     
     for port in  global_config["console_port_iterator"]():
-        print "create_or_use_console_proxy_thread() port:", port
+        #print "create_or_use_console_proxy_thread() port:", port
         if port in global_config["console_ports"]:
             continue
         try: