Advertisement
Guest User

32111

a guest
Jul 20th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1.  
  2. import logging
  3. from salt.utils.decorators import depends
  4. import salt.ext.six as six
  5.  
  6. log = logging.getLogger(__name__)
  7.  
  8. '''
  9. PYHDB IMPORT
  10. '''
  11.  
  12. HAS_PYHDB = False
  13. try:
  14. import pyhdb
  15. HAS_PYHDB = True
  16. except ImportError:
  17. pass
  18.  
  19. __virtualname__ = 'hanacon'
  20.  
  21. def __virtual__():
  22. if HAS_PYHDB:
  23. return __virtualname__
  24. return (False, 'no PYHDB')
  25. def check():
  26. return __virtual__()
  27.  
  28.  
  29. '''
  30. GRAINS CHECK
  31. '''
  32. def grains():
  33. return __grains__['hhost'],__grains__['hport'], __grains__['hinst'], __grains__['hsid'],__grains__['huser'], __grains__['hpass']
  34.  
  35.  
  36.  
  37. '''
  38. BACKUP CONTROLS
  39. '''
  40.  
  41. def backup():
  42. connection = pyhdb.connect (host=__grains__['hhost'], port=__grains__['hport'], user="SYSTEM", password="Welc0me@1")
  43. cursor = connection.cursor()
  44. cursor.execute("BACKUP DATA USING FILE ('BACKUP_LATEST')")
  45. return "Completed Successfully"
  46. connection.close()
  47.  
  48. '''
  49. USER CONTROLS
  50. '''
  51. def users():
  52. connection = pyhdb.connect (host=__grains__['hhost'], port=__grains__['hport'], user="SYSTEM", password="Welc0me@1")
  53. cursor = connection.cursor()
  54. cursor.execute("Select * FROM SYS.users")
  55. return cursor.fetchall()
  56. connection.close()
  57.  
  58. '''
  59. stp = __salt__['cmd.run']("/usr/sap/hostctrl/exe/sapcontrol -nr "+ __grains__['hinst'] +" -function StopSystem")
  60.  
  61.  
  62.  
  63. def sysreset():
  64. da = __salt__['cmd.run']("/usr/sap/"+__grains__['hsid']"/HDB"+ __grains__['hinst'] +"/exe/hdbnameserver")
  65. return da;
  66.  
  67. sthcomp = __salt__['cmd.run']("/usr/sap/"+__grains__['hsid']"/HDB"+ __grains__['hinst'] +"/exe/hdbcompileserver &"
  68. sthindx = __salt__['cmd.run']("/usr/sap/"+__grains__['hsid']"/HDB"+ __grains__['hinst'] +"/exe/hdbindexserver")
  69.  
  70.  
  71. def tryy():
  72. return __salt__['cmd.run']("runuser -l "+__grains__['hsid']"adm -c 'HDB stop && sleep 30s && hdbnameserver && hdbcompileserver && hdbindexserver -console && sleep 30s && ALTER USER SYSTEM PASSWORD test123'")
  73.  
  74. '''
  75.  
  76. def tryyy():
  77. lowhsid = __grains__['hsid'].lower()
  78. return __salt__['cmd.run']("runuser -l "+lowhsid+"adm -c 'HDB stop && sleep 30s && hdbnameserver && hdbcompileserver && hdbindexserver && sleep 30s && hdbsql -n localhost -i "+__grains__['hinst']+" -u SYSTEM -p Hithana4us ALTER USER SYSTEM PASSWORD test123'")
  79.  
  80. '''
  81. HDB CONTROLS
  82. '''
  83.  
  84. def any():
  85. return __grains__['hinst']
  86. def info():
  87. return __salt__['cmd.run']("/usr/sap/hostctrl/exe/sapcontrol -nr "+ __grains__['hinst'] +" -function GetProcessList")
  88. def stop():
  89. return __salt__['cmd.run']("/usr/sap/hostctrl/exe/sapcontrol -nr "+ __grains__['hinst'] +" -function StopSystem")
  90. def start():
  91. return __salt__['cmd.run']("/usr/sap/hostctrl/exe/sapcontrol -nr "+ __grains__['hinst'] +" -function StartSystem")
  92.  
  93. '''
  94. HDB Cleanup
  95. '''
  96. def hsid():
  97. return __grains__['hsid']
  98.  
  99.  
  100. def logs():
  101. success = "LOGS CLEARED!"
  102. clearscript = __salt__['cmd.run']("find /hana/shared/"+__grains__['hsid'] +"/HDB"+__grains__['hinst'] + "/backup/log/ -maxdepth 1 -type f -name \"*log_backup*\" -exec rm {} \;")
  103. return clearscript+success;
  104.  
  105. def comp():
  106. connection = pyhdb.connect (host=__grains__['hhost'], port=__grains__['hport'], user="SYSTEM", password="Welc0me@1")
  107. cursor = connection.cursor()
  108. cursor.execute("ALTER SYSTEM RECLAIM LOG")
  109. return "Completed Successfully"
  110. connection.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement