예제 #1
0
def exec_command(request):
    ret = ''
    if request.method == 'POST':
        action = request.get_full_path().split('=')[1]
        if action == 'exec':
            target = request.POST.get('target')
            command = request.POST.get('command')
            tgtcheck = Host.objects.filter(name=target)
            argcheck = command not in DANGER_COMMAND
            if tgtcheck and argcheck:
                results = Runner(pattern=target,
                                 forks=10,
                                 module_name='command',
                                 module_args=command).run()
                if results.get('dark'):
                    ret = 'Failed. Please run again.'
                else:
                    ret = results.get('contacted')

            elif not tgtcheck:
                ret = 'No specific host.'
            elif not argcheck:
                ret = 'Please contact admistrator.'

    return render(request, 'exec_command.html', locals())
예제 #2
0
 databases = ['scm', 'amon', 'rman', 'metastore']
 for db in databases:
     owner = db
     if db == 'metastore':
         owner = 'hive'
     log.debug("Creating database {0} with owner {1}".format(db, owner))
     try:
         r = Runner(inventory=Inventory(['localhost']),
                    transport='local',
                    sudo=True,
                    sudo_user='******',
                    module_name="postgresql_db",
                    module_args=("name={0} owner={1} encoding='UTF-8'"
                             .format(db, owner))
                    ).run()
         if r.get('contacted', {}).get('localhost', {}).get('failed'):
             msg = r.get('contacted', {}).get('localhost', {}).get('msg', 'N/A')
             log.error("Creating the database filed: {0}".format(msg))
     except Exception, e:
         log.error("Exception creating database {0}: {1}".format(db, e))
 # Alter one of the DBs
 sql_cmds = [
     "ALTER DATABASE metastore SET standard_conforming_strings = off"
 ]
 for sql_cmd in sql_cmds:
     misc.run_psql_command(sql_cmd, 'postgres', self.app.path_resolver.psql_cmd, 5432)
 # Prepare the scm database
 cmd = ("/usr/share/cmf/schema/scm_prepare_database.sh -h localhost postgresql scm scm {0}"
        .format(self.db_pwd))
 misc.run(cmd)
 # Make sure we have a clean DB env
예제 #3
0
 databases = ['scm', 'amon', 'rman', 'metastore']
 for db in databases:
     owner = db
     if db == 'metastore':
         owner = 'hive'
     log.debug("Creating database {0} with owner {1}".format(db, owner))
     try:
         r = Runner(inventory=Inventory(['localhost']),
                    transport='local',
                    become=True,
                    become_user='******',
                    module_name="postgresql_db",
                    module_args=("name={0} owner={1} encoding='UTF-8'"
                                 .format(db, owner))
                    ).run()
         if r.get('contacted', {}).get('localhost', {}).get('failed'):
             msg = r.get('contacted', {}).get('localhost', {}).get('msg', 'N/A')
             log.error("Creating the database filed: {0}".format(msg))
     except Exception, e:
         log.error("Exception creating database {0}: {1}".format(db, e))
 # Alter one of the DBs
 sql_cmds = [
     "ALTER DATABASE metastore SET standard_conforming_strings = off"
 ]
 for sql_cmd in sql_cmds:
     misc.run_psql_command(sql_cmd, 'postgres', self.app.path_resolver.psql_cmd, 5432)
 # Prepare the scm database
 cmd = ("/usr/share/cmf/schema/scm_prepare_database.sh -h localhost postgresql scm scm {0}"
        .format(self.db_pwd))
 misc.run(cmd)
 # Make sure we have a clean DB env