You are on page 1of 21

__author__ = 'victor.

grivtsov'
# -*- coding: utf-8 -*-

import os
import sys
import shutil
import xlrd
import datetime
from pytils import translit
from subprocess import Popen
from datetime import date
import time
from win32com import *
from xlwings import *
import telnetlib
from win32com.client import Dispatch
from formlayout import fedit
import socket
import hashlib
import subprocess
import re
from PyQt4 import QtCore, QtGui, uic
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import threading
import re

# ------Input Block---------
input_name = ['']
input_action = [0]
input_rus = [0]
input_ret = [0]
input_duw = [0]
input_tcu = [False]
input_pnr = [False]
input_action_lte = [0]

# ------Info Block---------
# ????????? ?????? ??? ????????,
# ? ??? ???????????? ???????? ?? ??
startname_arr = ['']
location_ru = ['']
duw_ip_arr = ['']
iub_ip_arr = ['']
tcu_ip_arr = ['']
scr1_arr = ['']
scr2_arr = ['']
scr3_arr = ['']
scr4_arr = ['']
scr5_arr = ['']
scr6_arr = ['']
rnc_arr = ['']
lac_arr = ['']
iub_id_arr = ['']
lte_oam_arr = ['']
lte_oam_gw_arr = ['']
lte_s1_arr = ['']
lte_s1_gw_arr = ['']
lte_vlan_oam_arr = ['']
lte_vlan_s1_arr = ['']
ura_arr = ['']

global values

def crypt(): # ??????? ?????????? ????????


truehostnames = []
keyword = 'jomolungma'
hostname = socket.gethostname()
crypted_word = keyword+hostname
hostname_ch = hashlib.sha256(crypted_word.encode()).hexdigest()
try:
lic = open("license.1", "r")
except:
print("???? ???????? ?? ??????, c???????? ? ???????: vgrivtsov@gmail.com")
time.sleep(15)
for i in lic:
truehostnames.append(i.strip())

if hostname_ch in truehostnames:
pass
else:
print("????????????? RBS Integrator ?? ?????? ?????????? ?????????!")
time.sleep(2)
print("?????? ????? ?????, ?????????? ?? ??????")
time.sleep(3)
quit()

def inp(): # input function


try:
global path
global startname

startname = input_name[-1]

path = ("cygwin/scripts/%s" % startname) #???? ????? ? ???????? ?????????


RBS

except NameError:

print("?? ?? ???????. ????????? ???????????? ???????? ??? ???????? ?? ?? ????")

try:
input("\n\n ??????? Enter, ????? ?????? ?????? ??? Ctrl+C ??? ??????.")
except KeyboardInterrupt:
print("?????? ????? ?????, ?????????? ?? ??????")
time.sleep(3)
sys.exit()

inp()

def new_dir(): #???????? ????? ????? ?? ?????????


global startname
global path
if os.path.exists(path):
for (p,d,f) in os.walk(path, False):
for file_name in f: # remove all files
os.remove(os.path.join(p, file_name))
for dir_name in d: # remove all dirs
os.rmdir(os.path.join(p,dir_name))
new_path = path
os.mkdir(new_path)

else:
new_path = path
os.mkdir(new_path)
#
-----------------------------------------------------------------------------------
-----------------------------------
#
-----------------------------------------------------------------------------------
-----------------------------------
# -----------------------------------????????? ?????? ??
Excel----------------------------------------------------------
#
-----------------------------------------------------------------------------------
-----------------------------------
#
-----------------------------------------------------------------------------------
-----------------------------------

def rnc_config(): # RNC configuration extract from rnc_conf.txt


global rnc_ip,rac,rnc_label,rnc_id_true
rnc_conf = open("rnc_conf.txt", "r")
for i in rnc_conf:
l = eval(i)
if rnc_id == l["_rnc_id"]:
rnc_ip = l["_rnc_ip"]
rac = l["_rac"]
rnc_label = l["_rnc_label"]
rnc_id_true = l["_rnc_id_true"]

def extdata(): #
-----------------------------------Extract_RNC_RBS_ID------------------------------
------

global startname
global rbs_id
global rnc_id, rnc_id_true
global rnc_ip
global lac
global rac
global cid1, cid2, cid3
global longitude
global latitude
global altitude
global location
global location_rus
global rnc_label
global usrlbl
global ura
global scramblingcode1, scramblingcode2, scramblingcode3, scramblingcode4,
scramblingcode5, scramblingcode6
usrlbl = ["%s_%s" % (startname, x) for x in range(1, 7)] # generator Cell name
new
workbook = xlrd.open_workbook('./DB/New_data_T2_v4.xlsx')
worksheet = workbook.sheet_by_name('Table')
for row in range(worksheet.nrows):
try:
data = (worksheet.cell_value(row, 8))
except:
print("??? ????? ??")
if str("%s_1" % startname) == str(data):
for col in range(worksheet.ncols):
rnc_id = str(worksheet.cell_value(row, 4))
rbs_id = str(int(worksheet.cell_value(row, 3)))
longitude = str(round(worksheet.cell_value(row, 5)*3600000)) #
Coordinates for OSS
latitude = str(round(worksheet.cell_value(row, 6)*3600000)) #
Coordinates for OSS
try:
altitude = str(int(worksheet.cell_value(row, 13)))
except:
altitude = "0"
lac = str(int(worksheet.cell_value(row, 7)))

for row in range(worksheet.nrows):


data2 = (worksheet.cell_value(row, 0))

if str(startname) == str(data2):
try:
location = str(translit.translify(worksheet.cell_value(row, 17)))
location_rus = str((worksheet.cell_value(row, 17)))
except:
print("????? ????????, ????????? ?? ? ??????")
location = "Mordor"
pass
try:
ura = str(int(worksheet.cell_value(row, 18)))
except:
print("Ura ?? ??????")
ura = "NO URA"
pass

for row in range(worksheet.nrows):


data1 = (worksheet.cell_value(row, 8))
if str(usrlbl[0]) == str(data1):
scramblingcode1 = str(int(worksheet.cell_value(row, 10)))
scramblingcode4 = scramblingcode1
cid1 = str(int(worksheet.cell_value(row, 9)))
if str(usrlbl[1]) == str(data1):
scramblingcode2 = str(int(worksheet.cell_value(row, 10)))
scramblingcode5 = scramblingcode2
cid2 = str(int(worksheet.cell_value(row, 9)))
if str(usrlbl[2]) == str(data1):
scramblingcode3 = str(int(worksheet.cell_value(row, 10)))
scramblingcode6 = scramblingcode3
cid3 = str(int(worksheet.cell_value(row, 9)))
rnc_config()
# ------------------------------------------------------

del workbook

def extip(): #
-----------------------------------Extract_IP--------------------------------------
-----
global startname
global duw_ip
global tcu_ip
global iub_ip
global row_true
global lte_oam, lte_oam_gw, lte_s1, lte_s1_gw, lte_vlan_oam, lte_vlan_s1
try:
workbook = xlrd.open_workbook('./DB/MOS_IP_PLAN_V5_.xlsx')
worksheet = workbook.sheet_by_name('IP ????')
for row in range(worksheet.nrows):
data = (worksheet.cell_value(row,0))
if str(startname) == str(data):
row_true = row+1
for col in range(worksheet.ncols):
duw_ip = (worksheet.cell_value(row, 7)) # IP startname
iub_ip = (worksheet.cell_value(row, 19))
tcu_ip = (worksheet.cell_value(row, 35))
lte_oam = (worksheet.cell_value(row, 12))
lte_oam_gw = (worksheet.cell_value(row, 13))
lte_s1 = (worksheet.cell_value(row, 24))
lte_s1_gw = (worksheet.cell_value(row, 25))
lte_vlan_oam = str(int(worksheet.cell_value(row, 10)))
lte_vlan_s1 = str(int(worksheet.cell_value(row, 22)))
del workbook
except (NameError, ValueError):
print("IP ?? ?????? ??? vlan ??????????")
pass

def ext_lte_data():
global PLCellIdGroup1, PLSubCellId1,PLCellIdGroup2,
PLSubCellId2,PLCellIdGroup3, PLSubCellId3
try:
workbook = xlrd.open_workbook('./DB/?????? ??? ???????? LTE2600
(PCI+RSI).xlsx')
worksheet = workbook.sheet_by_name('NewLTE')
for row in range(worksheet.nrows):
data = (worksheet.cell_value(row,2))
cid = (worksheet.cell_value(row,27))
if str(startname) == str(data) and str(cid) == '021':
for col in range(worksheet.ncols):
PLCellIdGroup1 = str(int(worksheet.cell_value(row, 31)))
PLSubCellId1 = str(int(worksheet.cell_value(row, 32)))
if str(startname) == str(data) and str(cid) == '022':
for col in range(worksheet.ncols):
PLCellIdGroup2 = str(int(worksheet.cell_value(row, 31)))
PLSubCellId2 = str(int(worksheet.cell_value(row, 32)))
if str(startname) == str(data) and str(cid) == '023':
for col in range(worksheet.ncols):
PLCellIdGroup3 = str(int(worksheet.cell_value(row, 31)))
PLSubCellId3 = str(int(worksheet.cell_value(row, 32)))
if str(startname) == str(data) and str(cid) == '024':
for col in range(worksheet.ncols):
PLCellIdGroup3 = str(int(worksheet.cell_value(row, 31)))
PLSubCellId3 = str(int(worksheet.cell_value(row, 32)))

del workbook
except (NameError, ValueError):
print("4G ?? ?? ???????, ????????? ??? LTE ?? ???????")
pass
#
-----------------------------------------------------------------------------------
-----------------------------------
#
-----------------------------------------------------------------------------------
-----------------------------------
#
-----------------------------------???????? ????????-------------------------------
-----------------------------------
#
-----------------------------------------------------------------------------------
-----------------------------------
#
-----------------------------------------------------------------------------------
-----------------------------------

def replace_tmpl(tmpl, var_list): # ??????? ???????????????? ?????? ? ????

lines = open(tmpl).readlines()
src = "%s"*len(lines) % tuple(lines)
for key, var in var_list.items():
src = str.replace(src, key, var)
return src
# ----------------------------------????????_???????_???
_????-----------------------------------------------------------

def NE_Site_create():

NE_Site = './template/NE_Site.txt'
body = replace_tmpl(NE_Site, {'$userLabel': startname,
'$altitude': altitude,
'$location': location,
'$longitude': longitude,
'$latitude': latitude
})

file = open("%s/01_OSS_Site_%s.xml" % (path, startname), "w")


file.write(body)
file.close()

def NE_RBS_create():
NE_RBS = './template/NE_RBS_create.txt'
body = replace_tmpl(NE_RBS, {'$RNC': rnc_label,
'$ManagedElementId': startname,
'$associatedSite': startname,
'$ipAddress': duw_ip_arr[-1]
})
file = open("%s/02_NE_RBS_%s.xml" % (path, startname), "w")
file.write(body)
file.close()

def NE_TCU_create():
NE_TCU = './template/NE_TCU_create.txt'
body = replace_tmpl(NE_TCU, {'$ManagedElementId': startname,
'$associatedSite' : startname,
'$ipAddress': tcu_ip_arr[-1],
'$RNC': rnc_label
})
file = open("%s/03_NE_TCU_%s.xml"% (path, startname), "w")
file.write(body)
file.close()

def NE_ERBS_create():
NE_RBS = './template/NE_ERBS_create.txt'
body = replace_tmpl(NE_RBS, { '$ManagedElementId': startname,
'$associatedSite': startname,
'$ipAddress': lte_oam_arr[-1]
})
file = open("%s/04_NE_ERBS_%s.xml" % (path, startname), "w")
file.write(body)
file.close()
# ---------------------CreateEricssonSite_v2.xlsm--
Generator----------------------------

def CreateEricssonSite():
global rus
print(scr2_arr[-1])
folder = os.getcwd()
#excel = Dispatch("Excel.Application")

wb = Workbook(r'%s\CreateEricssonSite_v65.xlsm' % folder, app_visible=False)

Range('Start', 'B3').value = True # checkbox choice 3G


Range('Data3G', 'AA6').value = duw # DUW
Range('Data3G', 'B6').value = startname[0:2] # Reg
Range('Data3G', 'F6').value = startname[2:6] # RBS ID
Range('Data3G', 'D6').value = rnc_arr[-1] # RNC ID
Range('Data3G', 'H6').value = lac_arr[-1]
Range('Data3G', 'I6').value = rac
Range('Data3G', 'K6').value = rus
Range('Data3G', 'K8').value = rus
Range('Data3G', 'K10').value = rus
Range('Data3G', 'W6').value = iub_ip_arr[-1]
Range('Data3G', 'N6').value = scr1_arr[-1]
Range('Data3G', 'N7').value = scr2_arr[-1]
Range('Data3G', 'N8').value = scr3_arr[-1]
Range('Data3G', 'N9').value = scr4_arr[-1]
Range('Data3G', 'N10').value = scr5_arr[-1]
Range('Data3G', 'N11').value = scr6_arr[-1]
Range('Data3G', 'G6').value = ura_arr[-1]

wb.application.xl_app.Run("Create3GW15") # generate configs


#wb.save()
wb.close()
#wb.application.quit()
#excel.Quit()

file1 = r'Create_3G_RBS_W15_Features_%s.mo' % startname


file2 = r'Create_3G_RBS_W15_%s.mo' % startname
file3 = r'Create_3G_RNC_W15_%s.mo' % startname
file4 = r'Comissioning_Cabinet_%s.xml' % startname
file5 = r'Comissioning_Site_Equipment_%s.xml' % startname
file6 = r'Comissioning_O&M_%s.xml' % startname

to_ = r'%s\%s' % (folder, path)


shutil.move(file1, to_)
shutil.move(file2, to_)
shutil.move(file3, to_)
shutil.move(file4, to_)
shutil.move(file5, to_)
shutil.move(file6, to_)

def CreateEricssonSite_LTE():

folder = os.getcwd()
#excel = Dispatch("Excel.Application")

wb = Workbook(r'%s\CreateEricssonSite_v65.xlsm' % folder, app_visible=False)


Range('Start', 'B4').value = True # checkbox choice 4G
Range('Data4G', 'B6').value = startname[0:2]
Range('Data4G', 'C6').value = startname
Range('Data4G', 'J6').value = lte_s1_arr[-1]
Range('Data4G', 'K6').value = lte_s1_gw_arr[-1]
Range('Data4G', 'M6').value = lte_vlan_s1_arr[-1]
Range('Data4G', 'N6').value = lte_oam_arr[-1]
Range('Data4G', 'O6').value = lte_oam_gw_arr[-1]
Range('Data4G', 'Q6').value = lte_vlan_oam_arr[-1]
Range('Data4G', 'AC6').value = lac_arr[-1]
try:
Range('Data4G', 'AI6').value = PLCellIdGroup1
Range('Data4G', 'AI7').value = PLCellIdGroup2
Range('Data4G', 'AI8').value = PLCellIdGroup3
Range('Data4G', 'AJ6').value = PLSubCellId1
Range('Data4G', 'AJ7').value = PLSubCellId2
Range('Data4G', 'AJ8').value = PLSubCellId3
except:
print("?? ??????? ????????? ??? 4G:PLCellIdGroup,PLSubCellId")

pass

wb.application.xl_app.Run("Create4G") # generate configs


wb.close() # close generator without save
#wb.application.quit()
#excel.Quit()

file1 = r'Create_4G_eNodeB_%s.mo' % startname

to_ = r'%s\%s' % (folder, path)


shutil.move(file1, to_)

#
-----------------------------------------------------------------------------------
-----------------------------------
#
-----------------------------------------------------------------------------------
-----------------------------------
#
-----------------------------------------------------------------------------------
-----------------------------------
#
-----------------------------------------------------------------------------------
-----------------------------------
def ftp_ses():
#-------------------------FTP-to-OSS-session---------------------------------

FTP_commands = open("commandsftp.txt", "w") # Create script for WinSCP


FTP_commands.write(
"""open ftp://%s:%s@%s:21
option batch on
option confirm off
cd scripts
put ".\cygwin\scripts\%s"
exit
""" % (user, password, HOST, startname))
FTP_commands.close()

# Start .com, for open new window use winscp.exe


cmd = 'winscp.com /console /script=commandsftp.txt'

p = subprocess.Popen(cmd, shell=False)
p.wait()

os.remove("commandsftp.txt")

def teln_ses(): # Telnet session for oss elements creating

global startname

tn = telnetlib.Telnet(HOST2)

tn.read_until(b"login: ")

tn.write(user.encode('ascii') + b"\n")

if password:
tn.read_until(b"Password: ")
tn.write(password.encode('ascii') + b"\n")
tn.read_until(("@%s>" % HOST2_name).encode('ascii'))
print(tn.read_eager().decode('ascii'))
tn.write(("/opt/ericsson/arne/bin/import.sh -f /home/%s/scripts/%s/01_OSS_Site_
%s.xml -import"
% (user, startname, startname)).encode('ascii') + b"\n")
print(tn.read_eager().decode('ascii'))
tn.read_until(("@%s>" % HOST2_name).encode('ascii'))
tn.write(("/opt/ericsson/arne/bin/import.sh -f /home/%s/scripts/%s/02_NE_RBS_
%s.xml -import"
% (user, startname, startname)).encode('ascii') + b"\n")
print(tn.read_eager().decode('ascii'))
tn.read_until(("@%s>" % HOST2_name).encode('ascii'))
if input_tcu[-1]:
tn.write(("/opt/ericsson/arne/bin/import.sh -f
/home/%s/scripts/%s/03_NE_TCU_%s.xml -import"
% (user, startname, startname)).encode('ascii') + b"\n")

tn.write(b"exit\n")
print(tn.read_all().decode('ascii'))

def teln_ses_lte(): # Telnet session for oss elements creating LTE

global startname

tn = telnetlib.Telnet(HOST_LTE)

tn.read_until(b"login: ")

tn.write(user.encode('ascii') + b"\n")

if password:
tn.read_until(b"Password: ")
tn.write(password.encode('ascii') + b"\n")

tn.write(("/opt/ericsson/arne/bin/import.sh -f /home/%s/scripts/%s/04_NE_ERBS_
%s.xml -import"
% (user, startname, startname)).encode('ascii') + b"\n")

tn.read_until(("@%s>" % HOST_LTE_NAME).encode('ascii'))
tn.write(b"exit\n")
print(tn.read_all().decode('ascii'))

def ipping():

os.system("ping %s" % duw_ip)


input("\n\n ??????? Enter, ????? ????? ? ????.")

def RBS_side_conf(): #???????? ??????? ? ????? ??? mobatch

import time

file = open("%s/commands.mos" % path, "w")

s = "%Y-%m-%d %H:%M:%S"
times = time.strftime(s, time.gmtime())
file.write("lt all\n")
file.write("confb+\n")
file.write("passwd ; rbs ; rbs\n")
file.write("rbs\n")
file.write("setclock %s\n" % times)
file.write("license iu activate\n")
file.write("l+ /scripts/%s/%s_RBS_log.txt\n" % (startname, startname))
file.write("truni /scripts/%s/Create_3G_RBS_W15_%s.mo\n" % (startname,
startname))
file.write("truni /scripts/%s/Create_3G_RBS_W15_Features_%s.mo\n" % (startname,
startname))

if retu == "ARETU":
file.write("set NodebFunction=1 featureStateStandardizedRet 1\n")
if retu == "CASCADE":
file.write("set NodebFunction=1 featureStateStandardizedRet 1\n")
file.write("set NodebFunction=1 featureStateRetCascading 1\n")

file.write("run /scripts/autoCreatedCV_pass_profile.mos\n")
file.write("confb-\n")
file.write("cvms RBS_FIN\n")
file.write("l- \n")

def RNC_side_conf():
file = open("%s/commandsRNC.mos" % path, "w")
file.write("lt all\n")
file.write("l+ /home/%s/scripts/%s/%s_RNC_log.txt\n" % (user, startname,
startname))
file.write("truni /home/%s/scripts/%s/Create_3G_RNC_W15_%s.mo\n" % (user,
startname, startname))
file.write("ldeb IubLink=Iub_%s\n" % rbs_id)
file.write("ldeb utrancell=%s\n" % startname)
file.write("l-\n")

def RbsOperations():

# global startname
#
# tn = telnetlib.Telnet(HOST)
#
# tn.read_until(b"login: ")
# tn.write(user.encode('ascii') + b"\n")
# if password:
# tn.read_until(b"Password: ")
# tn.write(password.encode('ascii') + b"\n")
# tn.write(("cd /home/%s/scripts/%s\r\n" % (user, startname)).encode('ascii'))
# tn.write(('amos %s "lt all; run commands.mos; q"\n' % duw_ip_arr[-
1]).encode('ascii'))
# #tn.write(b"exit\n")
# while True:
# line = tn.read_until(b"\n\r") # Check for new line
# print(line.decode('utf-8'))
# if (b"\nLog close:") in line: # If last read line is the prompt, end
loop
# break
#
# tn.close()

scripts_load_command = ('moshell %s "lt all; run /scripts/%s/commands.mos;


q"\n' %(duw_ip_arr[-1], startname )).encode('ascii')

print(scripts_load_command)
os.chdir('cygwin')
cmd = ['Cygwin.bat']
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
stdin=subprocess.PIPE, stderr=subprocess.PIPE)
p_stdout = p.communicate(input=scripts_load_command)[0]

print(p_stdout.decode())
os.chdir('..')

def RncOperations():
global startname

tn = telnetlib.Telnet(HOST)

tn.read_until(b"login: ")
tn.write(user.encode('ascii') + b"\n")
if password:
tn.read_until(b"Password: ")
tn.write(password.encode('ascii') + b"\n")
tn.write(("cd /home/%s/scripts/%s\r\n" % (user, startname)).encode('ascii'))
tn.write(('amos %s "lt all; run commandsRNC.mos; q"\n' %
rnc_ip).encode('ascii'))
while True:
line = tn.read_until(b"\n\r") # Check for new line and CR
print(line.decode('utf-8'))
if (b"\nLog close:") in line: # If last read line is the prompt, end loop
break

tn.close()

def LteOperations():
global startname

tn = telnetlib.Telnet(HOST_LTE_OSS)

tn.read_until(b"login: ")
tn.write(user.encode('ascii') + b"\n")
if password:
tn.read_until(b"Password: ")
tn.write(password.encode('ascii') + b"\n")

tn.write(('amos %s "lt all; secmode -a u; license iu activate;q"\n' %


lte_oam_arr[-1]).encode('ascii'))
tn.write(b"exit\n")
print(tn.read_all().decode('ascii'))

def LteLoadScript():
global startname

tn = telnetlib.Telnet(HOST_LTE_OSS)

tn.read_until(b"login: ")
tn.write(user.encode('ascii') + b"\n")
if password:
tn.read_until(b"Password: ")
tn.write(password.encode('ascii') + b"\n")

tn.write(('amos %s "lt all; truni /home/%s/scripts/%s/Create_4G_eNodeB_%s.mo


"\n'
% (lte_oam_arr[-1], user, startname, startname)).encode('ascii'))
tn.write(b"exit\n")
print(tn.read_all().decode('ascii'))

def LteCabinet():
global startname

tn = telnetlib.Telnet(HOST_LTE_OSS)

tn.read_until(b"login: ")
tn.write(user.encode('ascii') + b"\n")
if password:
tn.read_until(b"Password: ")
tn.write(password.encode('ascii') + b"\n")
try:
tn.write(('amos %s "lt all; truni /home/%s/scripts/Create_Cab_4G.mo; cvms
configure_ok"\n'
% (lte_oam_arr[-1], user)).encode('ascii'))
tn.write(b"exit\n")
print(tn.read_all().decode('ascii'))
except:
print("Cabinet file Create_Cab_4G.mo for lte no found! Cabinet no
created!")
pass

def EM_data(): # ??????????? ???????? ? ??? ?? ? ??????? ?????????


try:
file = open("%s" % EM_path, "a+", )
file.write("%s %s;\n" % (duw_ip_arr[-1], startname))
except FileNotFoundError:
print("?? ?????? visited.dat - ?????? ?? ????? ?????????? ? Element
Manager")
pass

try:
file = open("%s" % ipsites, "a+", )
file.write("%s %s rbs\n" % (startname, duw_ip_arr[-1]))
file.write("%s_LTE %s rbs\n" % (startname, lte_oam_arr[-1]))
except FileNotFoundError:
print("?? ?????? sitefiles ??? moshell")
pass

def em_start():

cmd_em = ['java', '-jar', 'bemcli.jar', duw_ip_arr[-1], 'em']

p = subprocess.Popen(cmd_em, stdout=subprocess.PIPE)
while True:
line = p.stdout.readline()
print(line)
if not line:
break

def inform():
global values
global startname
global location_rus, ura
global location
global duw_ip
global tcu_ip
global iub_ip
global lte_oam, lte_oam_gw, lte_s1, lte_s1_gw, lte_vlan_oam, lte_vlan_s1
global rnc_id, rnc_id_true
global rnc_ip
global rbs_id
global lac
global rac
global scramblingcode1
global scramblingcode2
global scramblingcode3
global scramblingcode4
global scramblingcode5
global scramblingcode6
global longitude
global latitude
global altitude
global rnc_label
global PLCellIdGroup1, PLSubCellId1,PLCellIdGroup2,
PLSubCellId2,PLCellIdGroup3, PLSubCellId3

inp(), extdata(), extip(), ext_lte_data()


try:
duw_ip_arr.append(duw_ip) # Add data from excel to work lists
iub_ip_arr.append(iub_ip)
tcu_ip_arr.append(tcu_ip)
location_ru.append(location_rus)
scr1_arr.append(scramblingcode1)
scr2_arr.append(scramblingcode2)
scr3_arr.append(scramblingcode3)
scr4_arr.append(scramblingcode4)
scr5_arr.append(scramblingcode5)
scr6_arr.append(scramblingcode6)
rnc_arr.append(rnc_id)
lac_arr.append(lac)
ura_arr.append(ura)
startname_arr.append(startname)
iub_id_arr.append(rbs_id)
lte_oam_arr.append(lte_oam)
lte_oam_gw_arr.append(lte_oam_gw)
lte_s1_arr.append(lte_s1)
lte_s1_gw_arr.append(lte_s1_gw)
lte_vlan_oam_arr.append(lte_vlan_oam)
lte_vlan_s1_arr.append(lte_vlan_s1)

rnc_config()

except:
print("Unexpected error:", sys.exc_info())
pass

def write_log():
try:
f = open("./logfile.txt", "a")
d = datetime.datetime.now()
f.write("%s %s %s \n" % (startname, startname, d))
f.close()
except:
print("logfile.txt ?? ??????")
pass
def write_PNR_LOG():
try:
today = date.today()
file = open("PNR_LOG.csv", "a", encoding='cp1251')
file.write("%s;%s;MS;%s;%s;250;20;%s;%s;%s;%s;%s\n" % (today, startname,
rnc_arr[-1], rnc_id_true, lac_arr[-1], cid1, usrlbl[0], cid1, rac ))
file.write("%s;%s;MS;%s;%s;250;20;%s;%s;%s;%s;%s\n" % (today, startname,
rnc_arr[-1], rnc_id_true, lac_arr[-1], cid2, usrlbl[1], cid2, rac ))
file.write("%s;%s;MS;%s;%s;250;20;%s;%s;%s;%s;%s\n" % (today, startname,
rnc_arr[-1], rnc_id_true, lac_arr[-1], cid3, usrlbl[2], cid3, rac ))

except:
print("??? ?????? PNR_LOG.csv ???????? ????? ?? ????????...")
file.write("log ?? ??????? ??? ?? %s" % startname)
pass
file.close()
# --------------------------------Main-
menu------------------------------------------------

def gui_menu():

settings = open("settings.txt") # OSS, DB login/pass


global HOST, user, password, EM_path, HOST2, ipsites, HOST2_name, HOST_LTE,
HOST_LTE_NAME, HOST_LTE_OSS
arr = []
for i in settings:
arr.append(i.rstrip().split())
HOST = arr[0][0]
user = arr[1][0]
password = arr[2][0]
EM_path = arr[3][0]
HOST2_name = arr[5][0].strip()
HOST_LTE_OSS = arr[7][0].strip()
HOST_LTE = arr[8][0].strip()
HOST_LTE_NAME = arr[9][0].strip()
try:
HOST2 = arr[4][0]
except:
print("IP for MOMAS server not found in settings(in 5th string) Exit...")
time.sleep(5)
sys.exit()
try:
ipsites = arr[6][0]
except:
print("Part to ipdabase file not found in settings(in 6th string). File
ipdatabase not to be writing")
time.sleep(5)

def create_datalist2():

return [('RBS name', '%s' % startname_arr[-1]),


('location', '%s' % location_ru[-1]),
('duw_ip', '%s' % duw_ip_arr[-1]),
('iub_ip', '%s' % iub_ip_arr[-1]),
('tcu_ip', '%s' % tcu_ip_arr[-1]),
('SC 1', '%s' % scr1_arr[-1]),
('SC 2', '%s' % scr2_arr[-1]),
('SC 3', '%s' % scr3_arr[-1]),
('SC 4', '%s' % scr4_arr[-1]),
('SC 5', '%s' % scr5_arr[-1]),
('SC 6', '%s' % scr6_arr[-1]),
('RNC', '%s' % rnc_arr[-1]),
('LAC', '%s' % lac_arr[-1]),
('RBS ID', '%s' % iub_id_arr[-1]),
('Ura', '%s' % ura_arr[-1]),
('LTE OAM ip', '%s' % lte_oam_arr[-1]),
('LTE OAM gw ip', '%s' % lte_oam_gw_arr[-1]),
('LTE S1 ip', '%s' % lte_s1_arr[-1]),
('LTE S1 GW ip', '%s' % lte_s1_gw_arr[-1]),
('LTE OAM vlan', '%s' % lte_vlan_oam_arr[-1]),
('LTE S1 vlan', '%s' % lte_vlan_s1_arr[-1]),
]

def chng_input(x):
global rnc_id
global rnc_label
global rnc_ip
global rac, ura
global rnc_id_true

startname_arr.append(x[0])
location_ru.append(x[1])
duw_ip_arr.append(x[2])
tcu_ip_arr.append(x[4])
iub_ip_arr.append(x[3])
scr1_arr.append(x[5])
scr2_arr.append(x[6])
scr3_arr.append(x[7])
scr4_arr.append(x[8])
scr5_arr.append(x[9])
scr6_arr.append(x[10])
rnc_arr.append(x[11])
lac_arr.append(x[12])
iub_id_arr.append(x[13])
ura_arr.append(x[14])
lte_oam_arr.append(x[15])
lte_oam_gw_arr.append(x[16])
lte_s1_arr.append(x[17])
lte_s1_gw_arr.append(x[18])
lte_vlan_oam_arr.append(x[19])
lte_vlan_s1_arr.append(x[20])

rnc_id = rnc_arr[-1] # at first equal rnc_id and new input rnc ID(lable)
rnc_config()

# ----------Action---------------------

print('??????????')
datalist2 = create_datalist2()
(fedit(datalist2, title="RBS Infromation",
comment="<b>???????? ?????? ??? ??????? ??????!</b>",
apply=chng_input))

if __name__ == '__main__':

global startname, duw, rus, retu, tcu


#crypt()

app = QtGui.QApplication(sys.argv)
window = uic.loadUi("CES_Window.ui") # type: <class 'PyQt4.QtGui.QWidget'>

duw = str(window.comboBox.currentText())
rus = str(window.comboBox_2.currentText())
retu = str(window.comboBox_3.currentText())

settings = open("settings.txt") # OSS, DB login/pass


global HOST, user, password, EM_path, HOST2, ipsites, HOST2_name, HOST_LTE,
HOST_LTE_NAME, HOST_LTE_OSS

arr = []
for i in settings:
arr.append(i.rstrip().split())
HOST = arr[0][0].strip()
user = arr[1][0].strip()
password = arr[2][0].strip()
EM_path = arr[3][0].strip()
HOST2_name = arr[5][0].strip()
HOST_LTE_OSS = arr[7][0].strip()
HOST_LTE = arr[8][0].strip()
HOST_LTE_NAME = arr[9][0].strip()
try:
HOST2 = arr[4][0].strip()
except:
print("IP for MOMAS server not found in settings(in 5th string) Exit...")
time.sleep(5)
sys.exit()
try:
ipsites = arr[6][0].strip()
except:
print("Part to ipdabase file not found in settings(in 6th string). File
ipdatabase not to be writing")
time.sleep(5)

def tcu_chk():

global duw, rus, retu


duw = str(window.comboBox.currentText())
rus = str(window.comboBox_2.currentText())
retu = str(window.comboBox_3.currentText())

if window.checkBox_7.isChecked():
global input_tcu, tcu
input_tcu = [True]
tcu = "TCU OK"
else:
input_tcu = [False]
tcu = "NO TCU"

def initial():
print("?????????? ? ??")
startname = (window.lineEdit.text()).upper()

window.plainTextEdit.appendPlainText(startname)
input_name.append(startname)

inform()

window.plainTextEdit.appendPlainText("?????????? ? ??...")
gui_menu()

def script_gen():

tcu_chk()
print("??????? ???????...")
print(rnc_label, duw_ip_arr[-1], duw, retu, rus, tcu)
window.plainTextEdit.appendPlainText("%s %s %s %s %s %s" %
(rnc_label, duw_ip_arr[-1], duw, retu,
rus, tcu))

inp(), new_dir(),
NE_Site_create(), NE_RBS_create(), NE_TCU_create(), NE_ERBS_create()
RBS_side_conf(), RNC_side_conf(),EM_data()
CreateEricssonSite()
if window.checkBox.isChecked():
CreateEricssonSite_LTE()
ftp_ses()
write_PNR_LOG()
print("??????? ???????")
window.plainTextEdit.appendPlainText("??????? ??????? ??? %s" % startname)

def full_conf():
tcu_chk()
global startname, duw, rus, retu, tcu

print("Full ?????????? ??")


print(rnc_label, duw_ip_arr[-1], duw, retu, rus, tcu)

inp(), new_dir(),
NE_Site_create(), NE_RBS_create(), NE_TCU_create(), NE_ERBS_create()
CreateEricssonSite(),
#CreateEricssonSite_LTE()
print("??????? ???????")
time.sleep(3)
RBS_side_conf(), RNC_side_conf(), EM_data(), write_log(), write_PNR_LOG(),
ftp_ses(),
print("??????? ??????????? ??")
RbsOperations(),
time.sleep(3)
print("?? ????????????????, ??????? ??????????? RNC")
RncOperations(),
time.sleep(3)
#em_start()
teln_ses()
print("?? ?????????")
window.plainTextEdit.appendPlainText("?? %s ?????????" % startname)

def rbs_conf():
print("?????????? ??...")
inp()
if window.checkBox.isChecked():
LteOperations(), LteCabinet()
print("LTE ?????????")
window.plainTextEdit.appendPlainText("LTE %s ?????????" % startname)
else:
RbsOperations()
print("RBS ?????????")
window.plainTextEdit.appendPlainText("RBS %s ?????????" % startname)

def rnc_conf():
print("?????????? RNC...")
inp(), RncOperations()
print("RNC ????????")
window.plainTextEdit.appendPlainText("?? %s ?? RNC %s ????????" %
(startname, rnc_label))

def oss_conf():
print("??????????? ?? OSS")
tcu_chk()
inp()
if window.checkBox.isChecked():
teln_ses_lte()
print("LTE ?? OSS ?????????")
window.plainTextEdit.appendPlainText("%s ?? OSS ?????????" % startname)
else:
teln_ses()
print("?? ?? OSS ?????????")
window.plainTextEdit.appendPlainText("%s ?? OSS ?????????" % startname)

def fing_get():

print("???????? fingerprint...")
tn = telnetlib.Telnet(HOST)

tn.read_until(b"login: ")

tn.write(user.encode('ascii') + b"\n")

if password:
tn.read_until(b"Password: ")
tn.write(password.encode('ascii') + b"\n")
tn.write(("amos %s 'lt all; get Licensing=1 fingerprint; al'"
% duw_ip_arr[-1]).encode('ascii') + b"\n")

tn.read_until(b"@rnduas1>")
tn.write(b"exit\n")
out_fing = tn.read_all().decode('ascii')
raw_fing = re.findall("fingerprint .*", out_fing)
true_fing = raw_fing[0].split()[1]

print(tn.read_all().decode('ascii'))
window.plainTextEdit.appendPlainText("%s" % true_fing)

def rdb():
global enter_value, rdb_bs_name
print("?????? RDB")
enter_value = '00'+startname[2:6]
rdb_bs_name = startname[0:2]+enter_value

def got_zapusk(): # Search for "?????????? ? ???????"


driver = webdriver.Chrome('.\chromedriver.exe')
driver.get("http://rdb.tele2.ru/")
assert "?????" in driver.title
elem = driver.find_element_by_id("p_body_ListSearch_listSearchBox")
elem.send_keys(enter_value)
elem.send_keys(Keys.RETURN)

link = driver.find_element_by_link_text(rdb_bs_name)
link.click()
link2 = driver.find_element_by_partial_link_text(rdb_bs_name)
link2.click()
link3 = driver.find_element_by_link_text("3g")
link3.click()
link_form = driver.current_url

link = re.sub("http://rdb.tele2.ru/p/form.aspx\?op=form&k=", "",


link_form)
link_edit = 'http://rdb.tele2.ru/p/edit.aspx?op=edit&k=%s&r=2' % link
print(link_edit)
driver.get(link_edit)
# driver.close()

def ustanovka(): # Search for "????????? ????????????"

driver = webdriver.Chrome('.\chromedriver.exe')
driver.get("http://rdb.tele2.ru/")
assert "?????" in driver.title
elem = driver.find_element_by_id("p_body_ListSearch_listSearchBox")
elem.send_keys(enter_value)
elem.send_keys(Keys.RETURN)

link = driver.find_element_by_link_text(rdb_bs_name)
link.click()
link2 = driver.find_element_by_partial_link_text(rdb_bs_name)
link2.click()
link_form = driver.current_url

link = re.sub("http://rdb.tele2.ru/p/form.aspx\?op=form&k=", "",


link_form)
link_edit = 'http://rdb.tele2.ru/p/edit.aspx?op=edit&k=%s&r=2' % link
print(link_edit)
driver.get(link_edit)
#driver.close()

t1 = threading.Thread(target=ustanovka)
t2 = threading.Thread(target=got_zapusk)

t1.start()
t2.start()

def chng_ip():
print("?????? IUB IP ?? ?????(%s) ?? RNC..." % iub_ip_arr[-1])
global startname

tn = telnetlib.Telnet(HOST)

tn.read_until(b"login: ")
tn.write(user.encode('ascii') + b"\n")
if password:
tn.read_until(b"Password: ")
tn.write(password.encode('ascii') + b"\n")

tn.write(('amos %s "lt all; confb+; set iub_%s remoteCpIpAddress1 %s; q"\n'


% (rnc_ip, iub_id_arr[-1], iub_ip_arr[-1])).encode('ascii'))
tn.write(b"exit\n")
print(tn.read_all().decode('ascii'))

QtCore.QObject.connect(window.pushButton_4, QtCore.SIGNAL("clicked()"),
initial)
QtCore.QObject.connect(window.pushButton_6, QtCore.SIGNAL("clicked()"),
script_gen)
QtCore.QObject.connect(window.pushButton_2, QtCore.SIGNAL("clicked()"),
rbs_conf)
QtCore.QObject.connect(window.pushButton, QtCore.SIGNAL("clicked()"), rnc_conf)
QtCore.QObject.connect(window.pushButton_5, QtCore.SIGNAL("clicked()"),
oss_conf)
QtCore.QObject.connect(window.pushButton_8, QtCore.SIGNAL("clicked()"),
fing_get)
QtCore.QObject.connect(window.pushButton_3, QtCore.SIGNAL("clicked()"),
full_conf)
QtCore.QObject.connect(window.pushButton_10, QtCore.SIGNAL("clicked()"),
em_start)
QtCore.QObject.connect(window.pushButton_11, QtCore.SIGNAL("clicked()"), rdb)
QtCore.QObject.connect(window.pushButton_12, QtCore.SIGNAL("clicked()"),
chng_ip)
QtCore.QObject.connect(window.pushButton_9, QtCore.SIGNAL("clicked()"),
QtGui.qApp.quit)

window.show()
sys.exit(app.exec_())

You might also like