Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import logging
- from salt.utils.decorators import depends
- import salt.ext.six as six
- log = logging.getLogger(__name__)
- '''
- PYHDB IMPORT
- '''
- HAS_PYHDB = False
- try:
- import pyhdb
- HAS_PYHDB = True
- except ImportError:
- pass
- __virtualname__ = 'hanacon'
- def __virtual__():
- if HAS_PYHDB:
- return __virtualname__
- return (False, 'no PYHDB')
- def check():
- return __virtual__()
- '''
- GRAINS CHECK
- '''
- def grains():
- return __grains__['hhost'],__grains__['hport'], __grains__['hinst'], __grains__['hsid'],__grains__['huser'], __grains__['hpass']
- '''
- BACKUP CONTROLS
- '''
- def backup():
- connection = pyhdb.connect (host=__grains__['hhost'], port=__grains__['hport'], user="SYSTEM", password="Welc0me@1")
- cursor = connection.cursor()
- cursor.execute("BACKUP DATA USING FILE ('BACKUP_LATEST')")
- return "Completed Successfully"
- connection.close()
- '''
- USER CONTROLS
- '''
- def users():
- connection = pyhdb.connect (host=__grains__['hhost'], port=__grains__['hport'], user="SYSTEM", password="Welc0me@1")
- cursor = connection.cursor()
- cursor.execute("Select * FROM SYS.users")
- return cursor.fetchall()
- connection.close()
- '''
- stp = __salt__['cmd.run']("/usr/sap/hostctrl/exe/sapcontrol -nr "+ __grains__['hinst'] +" -function StopSystem")
- def sysreset():
- da = __salt__['cmd.run']("/usr/sap/"+__grains__['hsid']"/HDB"+ __grains__['hinst'] +"/exe/hdbnameserver")
- return da;
- sthcomp = __salt__['cmd.run']("/usr/sap/"+__grains__['hsid']"/HDB"+ __grains__['hinst'] +"/exe/hdbcompileserver &"
- sthindx = __salt__['cmd.run']("/usr/sap/"+__grains__['hsid']"/HDB"+ __grains__['hinst'] +"/exe/hdbindexserver")
- def tryy():
- 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'")
- '''
- def tryyy():
- lowhsid = __grains__['hsid'].lower()
- 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'")
- '''
- HDB CONTROLS
- '''
- def any():
- return __grains__['hinst']
- def info():
- return __salt__['cmd.run']("/usr/sap/hostctrl/exe/sapcontrol -nr "+ __grains__['hinst'] +" -function GetProcessList")
- def stop():
- return __salt__['cmd.run']("/usr/sap/hostctrl/exe/sapcontrol -nr "+ __grains__['hinst'] +" -function StopSystem")
- def start():
- return __salt__['cmd.run']("/usr/sap/hostctrl/exe/sapcontrol -nr "+ __grains__['hinst'] +" -function StartSystem")
- '''
- HDB Cleanup
- '''
- def hsid():
- return __grains__['hsid']
- def logs():
- success = "LOGS CLEARED!"
- clearscript = __salt__['cmd.run']("find /hana/shared/"+__grains__['hsid'] +"/HDB"+__grains__['hinst'] + "/backup/log/ -maxdepth 1 -type f -name \"*log_backup*\" -exec rm {} \;")
- return clearscript+success;
- def comp():
- connection = pyhdb.connect (host=__grains__['hhost'], port=__grains__['hport'], user="SYSTEM", password="Welc0me@1")
- cursor = connection.cursor()
- cursor.execute("ALTER SYSTEM RECLAIM LOG")
- return "Completed Successfully"
- connection.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement