Package: linkInventory
Inventory of all Widw Area Network links supplied by various Telecom Service Providers.For this project  it is assumed that  there was a leagacy monolithic application which used toserve the purpose of  these link inventory management  and the  inventory data is alrady available in apre exising  Microsoft SQL  database.This microservice will first establish connection with the pre-existing database instead of creating one andenable rest api to query the data.  In future it is expected to provide new features in link inventorymanagement  and will become independent with its own database.install pyodbc   - For configuring ubuntu16.04 to connect to MS SQL server you may follow a detial article herehttps://wordpress.com/post/bhujaykbhatta.wordpress.com/1339  or follow the section below for a summary===========================lsb_release -aNo LSB modules are available.Distributor ID: UbuntuDescription:    Ubuntu 16.04.4 LTSRelease:        16.04Codename:       xenial============================================sudo sucurl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.listsudo apt-get updatesudo ACCEPT_EULA=Y apt-get install msodbcsql17sudo ACCEPT_EULA=Y apt-get install mssql-toolssudo apt-get install unixodbc-dev  freetds-bin  freetds-dev tdsodbcexit#install pyodbc within virtual environmentpip install pyodbcpip install mssql-clisudo mv /etc/odbcinst.ini  /etc/odbcinst.ini.baksudo vi /etc/odbcinst.ini[FreeTDS]Description = v0.91 with protocol v7.2Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.soSetup=/usr/lib/i386-linux-gnu/odbc/libtdsS.soFileUsage = 1UsageCount = 1sudo vi /etc/freetds/freetds.conf[global]# TDS protocol version; tds version = 4.2# Whether to write a TDSDUMP file for diagnostic purposes# (setting this to /tmp is insecure on a multi-user system); dump file = /tmp/freetds.log; debug flags = 0xffff# Command and connection timeouts; timeout = 10; connect timeout = 10# If you get out-of-memory errors, it may mean that your client# is trying to allocate a huge buffer for a TEXT field.# Try setting 'text size' to a more reasonable limittext size = 64512# A typical Sybase server[egServer50]host = symachine.domain.comport = 5000tds version = 5.0# A typical Microsoft server[egServer70]host = ntmachine.domain.comport = 1433tds version = 7.0# A typical Microsoft server[MSSQL]host = dbserverport = 1433tds version = 7.0sudo vi /etc/odbc.ini[MSSQL]Driver = FreeTDSServerName = MSSQL  #  maps it to DSN name not the actual host namePort = 1433TDS_Version = 7.2Insttall a Microsoft Sql  docker container with persistent volumesudo docker pull mcr.microsoft.com/mssql/server:2017-latest#sudo docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=welcome@123'    -p 1433:1433 --name sql1    -d mcr.microsoft.com/mssql/server:2017-latestfor data persistance with volume  -sudo docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=welcome@123' --name sql1 -p 1433:1433 -v sqlvolume:/var/opt/mssql -d mcr.microsoft.com/mssql/server:2017-latestdocker volume lsthe volume is created at the host level by the docker, even if the container is deleted the volume is persistedand the next docker run command with -v sqlvolume will mount this existing volumeDRIVER              VOLUME NAMElocal               sqlvolumefor data persistence with host directorysudo docker run -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=welcome@123' -p 1433:1433 -v <host directory>:/var/opt/mssql -d mcr.microsoft.com/mssql/server:2017-latestsudo docker exec -it sql1 "bash"/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'welcome@123CREATE DATABASE infooperSELECT Name from sys.DatabasesCREATE LOGIN user1  WITH PASSWORD = 'user@1234';CREATE USER user1 FOR LOGIN user1;GOGRANT ALL PRIVILEGES ON infooper.* TO 'user1'@'localhost';GOFrom remote computer , pip install mssql-cli  or  https://github.com/dbcli/mssql-cli/blob/master/doc/installation/linux.md#ubuntu-1604and run the client commandstelnet dbserver 1433mssql-cli  -S 192.168.111.141 -U SA  -d infooper -P welcome@123CREATE TABLE vw_comm_links (serial_no INT  NOT NULL PRIMARY KEY, circuit_id NVARCHAR(50), division_name NVARCHAR(50), fa_end NVARCHAR(50), bandwidth NVARCHAR(50), link_type NVARCHAR(50), )INSERT INTO vw_comm_links VALUES (1, 'circuitid1', 'division1', 'faend1', '10MB', 'MPLS' );INSERT INTO vw_comm_links VALUES (2, 'circuitid2', 'division2', 'faend2', '5MB', 'PTP' );INSERT INTO vw_comm_links VALUES (3, 'circuitid3', 'division3', 'faend3', '20MB', 'MPLS' );GOSELECT * FROM vw_comm_linksGOQUITtest that  tds  is workingisql -v MSSQL SA welcome@123install the application  within a virtual environmentvirtualenv -p python3 venvsource venv/bin/activatepip install linkInventoryThe main configuration file nfor the application  is /etc/tokenleader/linvInventory_configs.ymlsudo vi /etc/tokenleader/linkInventory_configs.ymlhost_name: 0.0.0.0 # for docker this should 0.0.0.0host_port: 5004ssl: disabled # not required other than testing the flaks own ssl. ssl should be handled by apachessl_settings: adhocdatabase:DRIVER: '{FreeTDS}'TDS_Verson: 7.0Server: dbserverPort: 1433Database: infooperUID:  SAdb_pwd_key_map: db_pwdengine_connect_string: 'mssql+pyodbc:///odbc_connect={}'secrets:secrets_file_location: linkInventory/tests/test_data/secrets.yml # where you have write accessfernet_key_location: linkInventory/tests/test_data/fernetkeys # where you have write access and preferebly separated from secrets_file_locationdb_pwd_key_map: db_pwd # when using encrypt-pwd command use this value for --kemaptokenleader_pwd_key_map: tl_pwdgenerated an encrypted password for the dbencrypt-pwd -k db_pwd -p <your password here>start the servicelinv-start