From 26dd59fd415cf8744c323f261eefce0ed7407410 Mon Sep 17 00:00:00 2001
From: Csók Tamás <godhak@gmail.com>
Date: Thu, 2 Oct 2014 12:58:02 +0200
Subject: [PATCH] client: windows connect method logging added

---
 src/nsi/installer/cloud_connect_from_windows.py | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/nsi/installer/cloud_connect_from_windows.py b/src/nsi/installer/cloud_connect_from_windows.py
index b0008a6..c8f61be 100644
--- a/src/nsi/installer/cloud_connect_from_windows.py
+++ b/src/nsi/installer/cloud_connect_from_windows.py
@@ -14,6 +14,7 @@ import glob
 import win32crypt
 import binascii
 import nxkey
+import logging
 
 
 def connect(vm):
@@ -28,7 +29,10 @@ def connect(vm):
     vm.user     -- Username used for the connection
     vm.password -- Password used for the connection
     """
+    logger = logging.getLogger()
+    logger.info('Connect methods started')
     if vm.protocol == "SSH":
+        logger.debug('SSH protocol received')
         arguments = ("-ssh -P %(port)s -pw %(password)s"
                      " %(user)s@%(host)s" % {
                          'port': vm.port,
@@ -36,10 +40,13 @@ def connect(vm):
                          'user': vm.user,
                          'host': vm.host})
         directory = os.path.dirname(os.path.abspath(__file__))
+        logger.debug('Popen: %s\\putty.exe', directory)
+        logger.info('Determined arguments: %s', arguments)
         subprocess.Popen("%(path)s\\putty.exe %(arguments)s" % {
             'path': directory,
             'arguments': arguments}, shell=True)
     elif vm.protocol == "NX":
+        logger.debug('NX protocol received')
         listdir = os.path.expanduser("~\\.nx\\config\\*.nxs")
         found = False
         server = "\"Server host\" value=\"%s\"" % vm.host
@@ -49,8 +56,10 @@ def connect(vm):
                 file = f.read()
                 if server in file and port in file:
                     found = True
+                    logger.info('Config file found: %s', config_file)
                     break
         if not found:
+            logger.info('No config file found, creating new one')
             config_file = "%s%s%s" % (os.path.expanduser("~\\.nx\\config\\"),
                                       str(int(time.time() * 1000)), ".nxs")
             password = nxkey.NXKeyGen(vm.password).getEncrypted()
@@ -59,8 +68,11 @@ def connect(vm):
             f = open(config_file, 'w')
             f.write(config)
             f.close()
+            logger.info('Config file created: %s', config_file)
+        logger.debug('Popen the config file: %s', config_file)
         subprocess.Popen(config_file, shell=True)
     elif vm.protocol == "RDP":
+        logger.debug('NX protocol received')
         listdir = os.path.dirname(os.path.realpath(__file__)) + "\\.rdp\\*.rdp"
         found = False
         full_address = "full address:s:%s:%s" % (vm.host, vm.port)
@@ -70,8 +82,10 @@ def connect(vm):
                 file = f.read()
                 if full_address in file and user in file:
                     found = True
+                    logger.info('Config file found: %s', config_file)
                     break
         if not found:
+            logger.info('No config file found, creating new one')
             config_file = "%s%s%s" % ((os.path.dirname(
                 os.path.realpath(__file__)) + "\\.rdp\\"),
                 str(int(time.time() * 1000)), ".rdp")
@@ -82,8 +96,10 @@ def connect(vm):
             f = open(config_file, 'w')
             f.write(config)
             f.close()
+            logger.info('Config file created: %s', config_file)
+        logger.debug('Popen the config file: %s', config_file)
         subprocess.Popen(config_file, shell=True)
-
+    logger.info('Client finished working')
 
 NX_template = """<!DOCTYPE NXClientSettings>
 <NXClientSettings application="nxclient" version="1.3" >
--
libgit2 0.26.0