Exemple #1
0
def prueba_local():
	prompts = []
	prompts += expect('is your.*','Jaime')
	prompts += expect('you at stack.*','si')			
	
	with expecting(prompts):
		run("python /root/prueba_local.py")
Exemple #2
0
def webres_release(tags,datacenter):
    if datacenter == "av":
        print("RELEASEING WITH PRODUCTION AV")

        #Making mysql backup by sending request to mysql server
        execute(mysql_backup_dump, tags='tags', db='bacula', host='192.168.44.2')


        #Running the release
        run('ls -l')
        #Putting new installation file on server
        #put('localfile','remotefile')
        #Running sudo command
        sudo("cat /etc/passwd")

        #Adding release tag to config file
        writeconfig('Release','Webres',tags)


    elif datacenter == "tc":
        print("RELEASEING WITH PRODUCTION TC")
        #Adding release tag to config file
        writeconfig('Release','Webres',tags)
        #Running the release
        run('ls -l')
        #Putting new installation file on server
        #put('localfile','remotefile')
        #Running sudo command
        sudo("cat /etc/passwd")
    else:
        print ("ERROR IN DATACENTER")
Exemple #3
0
def archive_setup_real_data():
    """Set up cnxarchive database with real data
    """
    if not _postgres_user_exists('cnxarchive'):
        prompts = []
        prompts += fexpect.expect('Enter password for new role:', 'cnxarchive')
        prompts += fexpect.expect('Enter it again:', 'cnxarchive')
        with fexpect.expecting(prompts):
            fexpect.sudo(
                'createuser --no-createdb --no-createrole --superuser --pwprompt cnxarchive',
                user='******')

    if _postgres_db_exists('cnxarchive'):
        sudo('dropdb cnxarchive', user='******')
    sudo('createdb -O cnxarchive cnxarchive', user='******')
    sudo('createlang plpythonu cnxarchive', user='******')

    run('zcat cnx-archive/repo_test_data.sql.gz >cnx-archive/repo_test_data.sql'
        )

    prompts = fexpect.expect('Password for user cnxarchive:', 'cnxarchive')
    with fexpect.expecting(prompts):
        fexpect.run(
            'psql -U cnxarchive cnxarchive -f cnx-archive/repo_test_data.sql')

    run('rm -rf cnx-archive/repo_test_data.sql')
    run('cnx-upgrade v1')
Exemple #4
0
def python_ss():
    prompts = []
    prompts += expect('>>>', 'print \"Hello World\"')
    prompts += expect('>>>', 'exit()')

    with expecting(prompts):
        run('python:')
Exemple #5
0
def python_ss():
    prompts = []
    prompts += expect('>>>', 'print \"Hello World\"')
    prompts += expect('>>>', 'exit()')

    with expecting(prompts):
        run('python:')
def prueba_local():
    prompts = []
    prompts += expect('is your.*', 'Jaime')
    prompts += expect('you at stack.*', 'si')

    with expecting(prompts):
        run("python /root/prueba_local.py")
Exemple #7
0
def deploy(reboot=True):
    with cd(env.stage_root):
        run('git pull')

    # Reboots gunicorn
    if reboot:
        restart('gunicorn')
        restart('celery')
Exemple #8
0
def deploy(reboot=True):
    with cd(env.stage_root):
        run('git pull')

    # Reboots gunicorn
    if reboot:
        restart('gunicorn')
        restart('celery')
Exemple #9
0
def ossec_update():
    put("/var/ossec-hids-2.7.1.tar.gz","/var/", use_sudo=True)
    sudo("tar zxf /var/ossec-hids-2.7.1.tar.gz -C /var/")
    run("ls -l")
    put ("/var/ossec-hids-2.7.1/etc/preloaded-vars.conf","/tmp/preloaded-vars.conf")
    sudo("mv -f /tmp/preloaded-vars.conf /var/ossec-hids-2.7.1/etc/preloaded-vars.conf")
    sudo("/var/ossec-hids-2.7.1/install.sh")
    sudo("/var/ossec/bin/ossec-control restart")
    sudo ("rm -rf /var/ossec-hids-2.7.1")
    sudo ("rm -rf /var/ossec-hids-2.7.1.tar.gz")
def display_task(): #部署
    
    print yellow("Start display packega ...")
    env.deploy_full_path=env.deploy_project_root+env.deploy_release_dir+"/"+env.deploy_version
    run('sh /home/www/tomcat-8.0.36/bin/shutdown.sh')
    run('rm -rf /home/www/tomcat-8.0.36/webapps/*')
    run('cp %s/jsh_mode_api.war /home/www/tomcat-8.0.36/webapps/ROOT.war' % env.deploy_full_path)
    run('chown www:www /home/www/tomcat-8.0.36/webapps/ROOT.war')
    run('set -m ;/home/www/tomcat-8.0.36/bin/startup.sh start')   #set -m; 不加启动不了
    print green("display success!!")
def put_task():#上传文件
    print yellow("Start pull packega ...")
    with settings(warn_only=True):
        with cd(env.deploy_project_root+env.deploy_release_dir):
                run("mkdir -p %s" % (env.deploy_version)) #创建版本目录
    
    env.deploy_full_path=env.deploy_project_root+env.deploy_release_dir+"/"+env.deploy_version
    
    with settings(warn_only=True):
            result = put(env.project_dev_source+"/"+env.project_dev_tar_source,env.deploy_full_path)    
    
    if result.failed and not confirm("put file failed, Continue[Y/N]?"):
            abort("Aborthing file put task!")    
            
    print green("Put package success!")
Exemple #12
0
 def test_one_expectation(self):
     cmd = 'echo "Hello" && read NAME && echo "Hi $NAME."'
     from ilogue.fexpect import expect, expecting, run
     expectation =  expect('Hello','answer')
     with expecting(expectation):
         output = run(cmd)
     self.assertIn('answer',output)
Exemple #13
0
 def test_one_expectation(self):
     cmd = 'echo "Hello" && read NAME && echo "Hi $NAME."'
     from ilogue.fexpect import expect, expecting, run
     expectation =  expect('Hello','answer')
     with expecting(expectation):
         output = run(cmd)
     self.assertIn('answer',output)
Exemple #14
0
    def test_mixed_case(self):
        cmd1 = "expr 5 + 5"
        cmd2 = "read -p Name: NAME && echo Hi $NAME."
        cmd3 = "expr 18 / 3"

        from ilogue.fexpect import expect, expecting, run
        import fabric

        output1 = run(cmd1)
        expectation = expect("Name:", "Bill")
        with expecting(expectation):
            output2 = run(cmd2)
        output3 = run(cmd3)

        self.assertIn("10", output1)
        self.assertIn("Hi Bill.", output2)
        self.assertIn("6", output3)
Exemple #15
0
    def test_mixed_case(self):
        cmd1 = 'expr 5 + 5'
        cmd2 = 'read -p Name: NAME && echo Hi $NAME.'
        cmd3 = 'expr 18 / 3'

        from ilogue.fexpect import expect, expecting, run
        import fabric

        output1 = run(cmd1)
        expectation =  expect('Name:','Bill')
        with expecting(expectation):
            output2 = run(cmd2)
        output3 = run(cmd3)

        self.assertIn('10',output1)
        self.assertIn('Hi Bill.',output2)
        self.assertIn('6',output3)
Exemple #16
0
    def test_mixed_case(self):
        cmd1 = 'expr 5 + 5'
        cmd2 = 'read -p Name: NAME && echo Hi $NAME.'
        cmd3 = 'expr 18 / 3'

        from ilogue.fexpect import expect, expecting, run
        import fabric

        output1 = run(cmd1)
        expectation =  expect('Name:','Bill')
        with expecting(expectation):
            output2 = run(cmd2)
        output3 = run(cmd3)

        self.assertIn('10',output1)
        self.assertIn('Hi Bill.',output2)
        self.assertIn('6',output3)
Exemple #17
0
 def test_two_expectations(self):
     cmd = 'echo "Hello" && read ONE && echo "bladiebla" && read TWO && echo "First $ONE than $TWO."'
     from ilogue.fexpect import expect, expecting, run
     exp1 =  expect('Hello','111')
     exp2 =  expect('bladiebla','222')
     with expecting(exp1+exp2):
         output = run(cmd)
     self.assertIn('111',output)
     self.assertIn('222',output)
Exemple #18
0
 def test_two_expectations(self):
     cmd = 'echo "Hello" && read ONE && echo "bladiebla" && read TWO && echo "First $ONE than $TWO."'
     from ilogue.fexpect import expect, expecting, run
     exp1 =  expect('Hello','111')
     exp2 =  expect('bladiebla','222')
     with expecting(exp1+exp2):
         output = run(cmd)
     self.assertIn('111',output)
     self.assertIn('222',output)
Exemple #19
0
 def test_order_inconsequential(self):
     #sequence shouldn't matter
     cmd = 'echo "Hello" && read ONE && echo "bladiebla" && read TWO && echo "First $ONE than $TWO."'
     from ilogue.fexpect import expect, expecting, run
     exp1 =  expect('Hello','111')
     exp2 =  expect('bladiebla','222')
     with expecting(exp2+exp1):
         output = run(cmd)
     self.assertIn('111',output)
     self.assertIn('222',output)
Exemple #20
0
    def test_two_expectations(self):
        cmd = 'echo "Hello" && read ONE && echo "bladiebla" && read TWO && echo "First $ONE than $TWO."'
        from ilogue.fexpect import expect, expecting, run

        exp1 = expect("Hello", "111")
        exp2 = expect("bladiebla", "222")
        with expecting(exp1 + exp2):
            output = run(cmd)
        self.assertIn("111", output)
        self.assertIn("222", output)
Exemple #21
0
 def test_order_inconsequential(self):
     #sequence shouldn't matter
     cmd = 'echo "Hello" && read ONE && echo "bladiebla" && read TWO && echo "First $ONE than $TWO."'
     from ilogue.fexpect import expect, expecting, run
     exp1 =  expect('Hello','111')
     exp2 =  expect('bladiebla','222')
     with expecting(exp2+exp1):
         output = run(cmd)
     self.assertIn('111',output)
     self.assertIn('222',output)
Exemple #22
0
 def test_can_change_shell(self):
     cmd = 'ps c && echo "Hello" && read NAME && echo "Hi $NAME."'
     from ilogue.fexpect import expect, expecting, run
     import fabric
     expectation =  expect('Hello','answer')
     backupenv = dict(fabric.state.env)
     fabric.state.env.shell = 'sh -c'
     with expecting(expectation):
         output = run(cmd)
     fabric.state.env.update(backupenv)
     self.assertIn('00 sh',output)
def run_bg(cmd, before=None, sockname="dtach", use_sudo=False):
    if not exists("/usr/bin/screen"):
        sudo("apt-get install screen")
    if before:
        cmd = "{}; dtach -n `mktemp -u /tmp/{}.XXXX` {}".format(before, sockname, cmd)
    else:
        cmd = "dtach -n `mktemp -u /tmp/{}.XXXX` {}".format(sockname, cmd)
    if use_sudo:
        return sudo(cmd)
    else:
        return run(cmd)
Exemple #24
0
 def test_can_change_shell(self):
     cmd = 'ps c && echo "Hello" && read NAME && echo "Hi $NAME."'
     from ilogue.fexpect import expect, expecting, run
     import fabric
     expectation =  expect('Hello','answer')
     backupenv = dict(fabric.state.env)
     fabric.state.env.shell = 'sh -c'
     with expecting(expectation):
         output = run(cmd)
     fabric.state.env.update(backupenv)
     self.assertIn('00 sh',output)
Exemple #25
0
    def test_quotes(self):
        cmd1 = 'read -p "Prompt1:" RESP1 && echo Received $RESP1.'
        cmd2 = "read -p 'Prompt2:' RESP2 && echo Received $RESP2."
        cmd3 = """read -p 'Prompt3:' -n "20" RESP3 && echo Received $RESP3."""

        from ilogue.fexpect import expect, expecting, run
        import fabric

        expectation =  []
        expectation += expect('Prompt1:','Foo')
        expectation += expect('Prompt2:','Bar')
        expectation += expect('Prompt3:','Baz')

        with expecting(expectation):
            output1 = run(cmd1)
            output2 = run(cmd2)
            output3 = run(cmd3)

        self.assertIn('Received Foo',output1)
        self.assertIn('Received Bar',output2)
        self.assertIn('Received Baz',output3)
Exemple #26
0
    def test_quotes(self):
        cmd1 = 'read -p "Prompt1:" RESP1 && echo Received $RESP1.'
        cmd2 = "read -p 'Prompt2:' RESP2 && echo Received $RESP2."
        cmd3 = """read -p 'Prompt3:' -n "20" RESP3 && echo Received $RESP3."""

        from ilogue.fexpect import expect, expecting, run
        import fabric

        expectation =  []
        expectation += expect('Prompt1:','Foo')
        expectation += expect('Prompt2:','Bar')
        expectation += expect('Prompt3:','Baz')

        with expecting(expectation):
            output1 = run(cmd1)
            output2 = run(cmd2)
            output3 = run(cmd3)

        self.assertIn('Received Foo',output1)
        self.assertIn('Received Bar',output2)
        self.assertIn('Received Baz',output3)
Exemple #27
0
    def test_can_change_shell(self):
        cmd = 'ps && echo "Hello" && read NAME && echo "Hi $NAME."'
        from ilogue.fexpect import expect, expecting, run
        import fabric

        expectation = expect("Hello", "answer")
        backupenv = fabric.state.env
        fabric.state.env.shell = "sh -c"
        with expecting(expectation):
            output = run(cmd)
        fabric.state.env = backupenv
        self.assertIn("00 sh", output)
Exemple #28
0
def run_bg(cmd, before=None, sockname="dtach", use_sudo=False):
    if not exists("/usr/bin/screen"):
        sudo("apt-get install screen")
    if before:
        cmd = "{}; dtach -n `mktemp -u /tmp/{}.XXXX` {}".format(
            before, sockname, cmd)
    else:
        cmd = "dtach -n `mktemp -u /tmp/{}.XXXX` {}".format(sockname, cmd)
    if use_sudo:
        return sudo(cmd)
    else:
        return run(cmd)
Exemple #29
0
    def test_controlchar(self):
        cmd = "python"
        from ilogue.fexpect import controlchar, expect, expecting, run
        import fabric

        expectation = []
        expectation += expect(">>>", controlchar("C"))
        expectation += expect("KeyboardInterrupt", controlchar("D"))

        with expecting(expectation):
            output = run(cmd)

        self.assertIn("KeyboardInterrupt", output)
Exemple #30
0
    def test_controlchar(self):
        cmd = 'python'
        from ilogue.fexpect import controlchar, expect, expecting, run
        import fabric

        expectation =  []
        expectation += expect(">>>", controlchar('C'))
        expectation += expect('KeyboardInterrupt', controlchar('D'))

        with expecting(expectation):
            output = run(cmd)

        self.assertIn('KeyboardInterrupt',output)
Exemple #31
0
    def test_controlchar(self):
        cmd = 'python'
        from ilogue.fexpect import controlchar, expect, expecting, run
        import fabric

        expectation =  []
        expectation += expect(">>>", controlchar('C'))
        expectation += expect('KeyboardInterrupt', controlchar('D'))

        with expecting(expectation):
            output = run(cmd)

        self.assertIn('KeyboardInterrupt',output)
Exemple #32
0
def archive_setup_real_data():
    """Set up cnxarchive database with real data
    """
    if not _postgres_user_exists('cnxarchive'):
        prompts = []
        prompts += fexpect.expect('Enter password for new role:', 'cnxarchive')
        prompts += fexpect.expect('Enter it again:', 'cnxarchive')
        with fexpect.expecting(prompts):
            fexpect.sudo('createuser --no-createdb --no-createrole --superuser --pwprompt cnxarchive', user='******')

    if _postgres_db_exists('cnxarchive'):
        sudo('dropdb cnxarchive', user='******')
    sudo('createdb -O cnxarchive cnxarchive', user='******')
    sudo('createlang plpythonu cnxarchive', user='******')

    run('zcat cnx-archive/repo_test_data.sql.gz >cnx-archive/repo_test_data.sql')

    prompts = fexpect.expect('Password for user cnxarchive:', 'cnxarchive')
    with fexpect.expecting(prompts):
        fexpect.run('psql -U cnxarchive cnxarchive -f cnx-archive/repo_test_data.sql')

    run('rm -rf cnx-archive/repo_test_data.sql')
    run('cnx-upgrade v1')
Exemple #33
0
def generate_client_credentials(cluster_name, public_key, verify_code):
    """Generate the client credentials"""

    prompts = []
    prompts += expect('Enter a name for this cluster:', cluster_name)
    prompts += expect("Input the server's public key:", public_key)
    prompts += expect("Input the server verify code: ", verify_code)

    with expecting(prompts):
        output = run('cstar_perf_client --get-credentials')

    lines = output.split('\n')
    client_public_key = [line for line in lines if line.startswith("Your public key is")][0]
    fab.run("echo '{}' > ~/credentials.txt".format(client_public_key))
Exemple #34
0
 def test_exit_after_expectation(self):
     import time
     from StringIO import StringIO
     #sequence shouldn't matter
     script = "#!/usr/bin/python\nimport time\nfor i in range(1,8):\n\tprint(i)\n\ttime.sleep(1)"
     cmd = 'python /tmp/test.py'
     put(StringIO(script),'/tmp/test.py')
     from ilogue.fexpect import expect, expecting, run
     exp1 =  expect('Hello','111')
     exp2 =  expect('3','expected',exitAfter=0)
     t = time.time()
     with expecting(exp1+exp2):
         output = run(cmd)
     elapsed = time.time() - t
     self.assertGreater(elapsed,2)
     self.assertLess(elapsed,4)
Exemple #35
0
def generate_client_credentials(cluster_name, public_key, verify_code):
    """Generate the client credentials"""

    prompts = []
    prompts += expect('Enter a name for this cluster:', cluster_name)
    prompts += expect("Input the server's public key:", public_key)
    prompts += expect("Input the server verify code: ", verify_code)

    with expecting(prompts):
        output = run('cstar_perf_client --get-credentials')

    lines = output.split('\n')
    client_public_key = [
        line for line in lines if line.startswith("Your public key is")
    ][0]
    fab.run("echo '{}' > ~/credentials.txt".format(client_public_key))
Exemple #36
0
 def test_exit_after_expectation(self):
     import time
     from StringIO import StringIO
     #sequence shouldn't matter
     script = "#!/usr/bin/python\nimport time\nfor i in range(1,8):\n\tprint(i)\n\ttime.sleep(1)"
     cmd = 'python /tmp/test.py'
     put(StringIO(script),'/tmp/test.py')
     from ilogue.fexpect import expect, expecting, run
     exp1 =  expect('Hello','111')
     exp2 =  expect('3','expected',exitAfter=0)
     t = time.time()
     with expecting(exp1+exp2):
         output = run(cmd)
     elapsed = time.time() - t
     self.assertGreater(elapsed,2)
     self.assertLess(elapsed,4)
Exemple #37
0
    def test_multimatch(self):
        """ Match same prompt but with different responses """

        cmd =  'echo "name" && read NAME1 && echo "name is $NAME1" && echo "name" && read NAME2 && echo "name is $NAME2"'

        from ilogue.fexpect import expecting, expect, run

        expectation = []
        expectation += expect('name', 'Ford')
        expectation += expect('name', 'Arthur')

        with expecting(expectation):
            output = run(cmd)

        self.assertIn('Ford', output)
        self.assertIn('Arthur', output)
Exemple #38
0
    def test_multimatch(self):
        """ Match same prompt but with different responses """

        cmd = 'echo "name" && read NAME1 && echo "name is $NAME1" && echo "name" && read NAME2 && echo "name is $NAME2"'

        from ilogue.fexpect import expecting, expect, run

        expectation = []
        expectation += expect('name', 'Ford')
        expectation += expect('name', 'Arthur')

        with expecting(expectation):
            output = run(cmd)

        self.assertIn('Ford', output)
        self.assertIn('Arthur', output)
Exemple #39
0
def uptime():
    run('uptime')
Exemple #40
0
def supervisor(command, *args):
    with prefix('workon research'):
        with cd(env.stage_root):
            for a in args:
                run(' supervisorctl -c supervisor.conf %s %s' %
                    (command, a[0]))
Exemple #41
0
def migrate_schema(app='graph'):
    with prefix('workon research'):
        with cd(env.stage_root):
            run(env.stage_root + '/manage.py makemigrations %s ' % app)
Exemple #42
0
def check():
    run("ls")
Exemple #43
0
def start_client():
    with cd(code_dir):
        run("make clean")
        run("make all")
        sudo('screen -d python client_2.py ' + ipaddress + '; sleep 1')
Exemple #44
0
def instalar_pxp():

	question = raw_input("La conexion se realizara por un proxy? (s/n) : ")
	if question == 's' :
		question = raw_input("Ingrese la cadena de conexion del servidor proxy  (proxyuser:proxypwd@server:port o server:port) : ")
		proxy = question
	else :
		proxy = ""
			
	run("yum -y install wget")
		
	version = run("grep -o release.. /etc/redhat-release")
	
	if(version == 'release 7'):
		# postgres de  rpm de postgres 9.5# 
		run("wget http://yum.postgresql.org/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-2.noarch.rpm")
	else:
		# postgres de  rpm de postgres 9.5# 
		run("wget http://yum.postgresql.org/9.5/redhat/rhel-6-x86_64/pgdg-redhat95-9.5-2.noarch.rpm")

# configuraicon de archivos de centos-base.repo agregando una linea #
	s = open("/etc/yum.repos.d/CentOS-Base.repo",'a')
	s.write("exclude=postgresql*\n\n")
	s.close()

	if(version == 'release 7'):
		run("rpm -Uvh --replacepkgs pgdg-centos95-9.5-2.noarch.rpm")
	else:
		run("rpm -Uvh --replacepkgs pgdg-redhat95-9.5-2.noarch.rpm")
	
# instalacion de postgres y la primera corrida #
	S_pgsql="service postgresql-9.5"
	I_pgsql="postgresql95"
	sudo("yum -y install postgresql95-server postgresql95-docs postgresql95-contrib postgresql95-plperl postgresql95-plpython postgresql95-pltcl postgresql95-test rhdb-utils gcc-objc postgresql95-devel ")
	if(version == 'release 7'):
		
		run("/usr/pgsql-9.5/bin/postgresql95-setup initdb")
		run("systemctl start postgresql-9.5")
		run("systemctl enable postgresql-9.5")
	else:
		
		run("service postgresql-9.5 initdb")
		run("service postgresql-9.5 start")
		run("chkconfig postgresql-9.5 on")

# instalacion del php y apache mas la primera corrida #


	sudo("yum -y install httpd php  mod_ssl mod_auth_pgsql  php-pear php-bcmath  php-mbstring php-cli php-ldap php-pdo php-pgsql php-gd")
	
	if(version == 'release 7'):
		run("systemctl start httpd")
		run("systemctl enable httpd")
	else:
		run("service httpd start")
		run("chkconfig httpd on")

#Creacion de archivos para bitacoras
	archi = open("/usr/local/lib/phx.c",'w')
	archi.write('#include "postgres.h"\n')
	archi.write('#include <string.h>\n')
	archi.write('#include "fmgr.h"\n')
	archi.write('#include "utils/geo_decls.h"\n')
	archi.write('#include <stdio.h>\n')
	
	archi.write('#ifdef PG_MODULE_MAGIC\n')
	archi.write('PG_MODULE_MAGIC;\n')
	archi.write('#endif\n')
	archi.write('/* by value */\n')
	archi.write('PG_FUNCTION_INFO_V1(monitor_phx);\n')
	
	archi.write('Datum\n')
	archi.write('monitor_phx(PG_FUNCTION_ARGS)\n')
	archi.write('{\n')
	archi.write('    int32   arg = PG_GETARG_INT32(0);\n')
	archi.write('    system("sudo /usr/local/lib/./phxbd.sh");\n')
	archi.write('        PG_RETURN_INT32(arg);\n')
	archi.write('}')
	archi.close()
	
	run("gcc -I /usr/local/include -I /usr/pgsql-9.5/include/server/ -fpic -c /usr/local/lib/phx.c")
	run("gcc -I /usr/local/include -I /usr/pgsql-9.5/include/server/ -shared -o /usr/local/lib/phx.so phx.o")
	

	run("chown root.postgres /usr/local/lib/phx.so")
	run("chmod 750 /usr/local/lib/phx.so")
	
	archi = open("/usr/local/lib/phxbd.sh",'w')
	archi.write('!/bin/bash\n')
	archi.write('top -b -n 1 | grep -e postgres -e httpd | awk \'{print $1","$12","$2","$9","$10","$5""""}\' > /tmp/procesos.csv\n')
	archi.write('chown root.postgres /tmp/procesos.csv\n')
	archi.write('chmod 740 /tmp/procesos.csv')
	
	sudo("chown root.postgres /usr/local/lib/phxbd.sh")
	sudo("sudo chmod 700 /usr/local/lib/phxbd.sh")
	
	f = open("/etc/sudoers",'r')
	chain = f.read()
	chain = chain.replace("Defaults    requiretty","#Defaults    requiretty")
	chain = chain.replace("root    ALL=(ALL)       ALL","root    ALL=(ALL)       ALL\n postgres        ALL=NOPASSWD: /usr/local/lib/phxbd.sh")
	f.close()
	
	f = open("/etc/sudoers",'w')
	f.write(chain)
	f.close()
	
	
	
#Instalacion de mcrypt para servicios rest
	if(version == 'release 7'):
		run("wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-8.noarch.rpm")
		run("wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm")
		run("rpm -Uvh remi-release-7*.rpm epel-release-7*.rpm")
	else:
		run("wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm")
		run("wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm")
		sudo("rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm")
	
	
	run("yum -y update")
	run("yum -y install php-mcrypt*")

# cambio de los archivos pg_hba y postgres.config#
	
	archi=open("/var/lib/pgsql/9.5/data/pg_hba.conf",'w')
		
	archi.write("# TYPE  DATABASE        USER            ADDRESS                 METHOD\n\n")
	archi.write("# 'local' is for Unix domain socket connections only\n")
	archi.write("local   all		postgres,dbkerp_conexion                  trust\n")
	archi.write("local   all             all                                     md5\n")
	archi.write("# IPv4 local connections:\n")
	archi.write("host    all             all             127.0.0.1/32            md5\n")
	archi.write("host    all             all             192.168.0.0/16          md5\n")
	archi.write("# IPv6 local connections:\n")
	archi.write("host    all             all             ::1/128                 md5\n")
	archi.close()

	
	f = open("/var/lib/pgsql/9.5/data/postgresql.conf",'r')
	
	chain = f.read()
	chain = chain.replace("pg_catalog.english","pg_catalog.spanish")
	chain = chain.replace("log_destination = 'stderr'","log_destination = 'csvlog'")
	chain = chain.replace("log_filename = 'postgresql-%a.log'","log_filename = 'postgresql-%Y-%m-%d.log'")
	chain = chain.replace("log_truncate_on_rotation = on","log_truncate_on_rotation = off")
	chain = chain.replace("#log_error_verbosity = default","log_error_verbosity = verbose")
	chain = chain.replace("#log_statement = 'none'","log_statement = 'mod'")
	chain = chain.replace("iso, mdy","iso, dmy")
	f.close()
	
	
	otro = open("/var/lib/pgsql/9.5/data/postgresql.conf",'w')
	
		
	otro.write(chain)
	otro.close()
	
	s = open("/var/lib/pgsql/9.5/data/postgresql.conf",'a')
	
	s.write("listen_addresses = '*'\n")
	s.write("bytea_output = 'escape'\n")
	s.close()
	
	
	db_pass = "******"
	sudo('psql -c "ALTER USER postgres WITH ENCRYPTED PASSWORD E\'%s\'"' % (db_pass), user='******')
	sudo('psql -c "CREATE DATABASE dbkerp WITH ENCODING=\'UTF-8\';"', user='******')
	sudo('psql -c "CREATE USER dbkerp_conexion WITH PASSWORD \'dbkerp_conexion\';"', user='******')
	sudo('psql -c "ALTER ROLE dbkerp_conexion SUPERUSER;"', user='******')
	sudo('psql -c "CREATE USER dbkerp_admin WITH PASSWORD \'a1a69c4e834c5aa6cce8c6eceee84295\';"', user='******')
	sudo('psql -c "ALTER ROLE dbkerp_admin SUPERUSER;"', user='******')
	
	if(version == 'release 7'):
		run('systemctl restart postgresql-9.5')
	else:
		run('service postgresql-9.5 restart')

# instalacion de git para poder bajar el repositoriio pxp y moviendo a la carpeta /var/www/html/kerp/#
	sudo("yum -y install git-core")
	run("mkdir /var/www/html/kerp")
	run("mkdir /var/www/html/kerp/pxp")
		
	#Si existe proxy se configura github para el proxy
	if (proxy != ""):
		run("git config --global http.proxy http://" + proxy)
		run("git config --global https.proxy https://" + proxy)
		
	run("git clone https://github.com/kplian/pxp.git /var/www/html/kerp/pxp")
	run("chown -R apache.apache /var/www/html/kerp/")
	run("chmod 700 -R /var/www/html/kerp/")

# haciendo una copia de datosgenerales.samples.php y modificando archivo#
	f = open("/var/www/html/kerp/pxp/lib/DatosGenerales.sample.php")
	g = open("/var/www/html/kerp/pxp/lib/DatosGenerales.php","w")
	linea = f.readline()
	while linea != "":
		g.write(linea)
		linea = f.readline()

	g.close()
	f.close()
    #TODO    VOLVER VARIABLE LA CARPETA PRINCIPAL KERP
	f = open("/var/www/html/kerp/pxp/lib/DatosGenerales.php",'r')
	chain = f.read()
	chain = chain.replace("/web/lib/lib_control/","/kerp/pxp/lib/lib_control/")
	chain = chain.replace("/kerp-boa/","/kerp/")
	
	
	chain = chain.replace("/var/lib/pgsql/9.1/data/pg_log/","/var/lib/pgsql/9.5/data/pg_log/")
	

	f.close()
	otro = open("/var/www/html/kerp/pxp/lib/DatosGenerales.php",'w')
	otro.write(chain)
	otro.close()


	run("ln -s /var/www/html/kerp/pxp/lib /var/www/html/kerp/lib")
	run("ln -s /var/www/html/kerp/pxp/index.php /var/www/html/kerp/index.php")
	run("ln -s /var/www/html/kerp/pxp/sis_generador /var/www/html/kerp/sis_generador")
	run("ln -s /var/www/html/kerp/pxp/sis_organigrama /var/www/html/kerp/sis_organigrama")
	run("ln -s /var/www/html/kerp/pxp/sis_parametros /var/www/html/kerp/sis_parametros")
	run("ln -s /var/www/html/kerp/pxp/sis_seguridad /var/www/html/kerp/sis_seguridad")
	run("ln -s /var/www/html/kerp/pxp/sis_workflow /var/www/html/kerp/sis_workflow")
	

	
	archi=open('/var/www/html/kerp/sistemas.txt','w')
	archi.close()
	
	
	run("mkdir /var/www/html/kerp/reportes_generados")
	
	sudo("setfacl -R -m u:apache:wrx /var/www/html/kerp/reportes_generados")
	
# 	sudo("yum -y install rpm-build")
	
	sudo("setfacl -R -m u:postgres:wrx /var/www/html")
	
	sudo("chcon -Rv --type=httpd_sys_rw_content_t /var/www/html/kerp/")
	sudo("setsebool -P httpd_can_network_connect_db=1")

# iptables
	if(version == 'release 6'):
		run("iptables --flush")	
		run("iptables -P INPUT ACCEPT")
		run("iptables -P OUTPUT ACCEPT")
		run("iptables -P FORWARD ACCEPT")
		#Interfaz local aceptar
		run("iptables -A INPUT -i lo -j ACCEPT")
		#Comunicaciones establecidas aceptar
		run("iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT")
		#Ping Aceptar
		run("iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT")
		#Ssh Aceptar
		run("iptables -A INPUT -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT")
		#http y https aceptar
		run("iptables -A INPUT -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT")
		run("iptables -A INPUT -p tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT")
		#postgres  aceptar
		run("iptables -A INPUT -p tcp --dport 5432 -m state --state NEW,ESTABLISHED -j ACCEPT")
		run("iptables -P INPUT DROP")
		run("service iptables save")
		run("service iptables restart")
	else:
		run("firewall-cmd --permanent --add-port=22/tcp")
        	run("firewall-cmd --permanent --add-port=80/tcp")
        	run("firewall-cmd --permanent --add-port=5432/tcp")
		run("firewall-cmd --reload")
				
	prompts = []
	prompts += expect('Ingrese una opcion.*','1')
	prompts += expect('Ingrese el nombre de la BD.*','dbkerp')	
	prompts += expect('Desea obtener un backup de la BD.*','NO')
	prompts += expect('los datos de prueba.*','n')	
	
	with expecting(prompts):
		sudo("/var/www/html/kerp/pxp/utilidades/restaurar_bd/./restaurar_todo.py" , user="******")
def start_client():
    with cd(code_dir):
        run("make clean")
        run("make all")
        sudo("screen -d python client_2.py " + ipaddress + "; sleep 1")
Exemple #46
0
def migrate(app='graph'):
    with prefix('workon research'):
        with cd(env.stage_root):
            run(env.stage_root + '/manage.py migrate %s' % app)
Exemple #47
0
def uptime():
    run('uptime')
Exemple #48
0
def migrate_schema(app='graph'):
    with prefix('workon research'):
        with cd(env.stage_root):
            run(env.stage_root + '/manage.py makemigrations %s ' % app)
Exemple #49
0
def mysql_backup_dump(tags, db):
    print(Making mysql_backup_dump)
    date = time.strftime("%Y-%m-%d")

    run('mysqldump '+db+' > /var/backup/mysqldumpt_'+db+'_'+tags+'_'+date+'.sql')
    run('tar czf /var/backup/mysqldumpt_'+db+'_'+tags+'_'+date+'.tar.gz /var/backup/mysqldumpt_'+db+'_'+tags+'_'+date+'.sql')
Exemple #50
0
def supervisor(command, *args):
    with prefix('workon research'):
        with cd(env.stage_root):
            for a in args:
                run(' supervisorctl -c supervisor.conf %s %s' % (command, a[0]))
Exemple #51
0
def migrate(app='graph'):
    with prefix('workon research'):
        with cd(env.stage_root):
            run(env.stage_root + '/manage.py migrate %s' % app)
def instalar_pxp():

    question = raw_input("La conexion se realizara por un proxy? (s/n) : ")
    if question == 's':
        question = raw_input(
            "Ingrese la cadena de conexion del servidor proxy  (proxyuser:proxypwd@server:port o server:port) : "
        )
        proxy = question
    else:
        proxy = ""

    run("yum -y install wget")

    version = run("grep -o release.. /etc/redhat-release")

    if (version == 'release 7'):
        # postgres de  rpm de postgres 9.5#
        run("wget http://yum.postgresql.org/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-2.noarch.rpm"
            )
    else:
        # postgres de  rpm de postgres 9.5#
        run("wget http://yum.postgresql.org/9.5/redhat/rhel-6-x86_64/pgdg-redhat95-9.5-2.noarch.rpm"
            )

# configuraicon de archivos de centos-base.repo agregando una linea #
    s = open("/etc/yum.repos.d/CentOS-Base.repo", 'a')
    s.write("exclude=postgresql*\n\n")
    s.close()

    if (version == 'release 7'):
        run("rpm -Uvh --replacepkgs pgdg-centos95-9.5-2.noarch.rpm")
    else:
        run("rpm -Uvh --replacepkgs pgdg-redhat95-9.5-2.noarch.rpm")

# instalacion de postgres y la primera corrida #
    S_pgsql = "service postgresql-9.5"
    I_pgsql = "postgresql95"
    sudo(
        "yum -y install postgresql95-server postgresql95-docs postgresql95-contrib postgresql95-plperl postgresql95-plpython postgresql95-pltcl postgresql95-test rhdb-utils gcc-objc postgresql95-devel "
    )
    if (version == 'release 7'):

        run("/usr/pgsql-9.5/bin/postgresql95-setup initdb")
        run("systemctl start postgresql-9.5")
        run("systemctl enable postgresql-9.5")
    else:

        run("service postgresql-9.5 initdb")
        run("service postgresql-9.5 start")
        run("chkconfig postgresql-9.5 on")

# instalacion del php y apache mas la primera corrida #

    sudo(
        "yum -y install httpd php  mod_ssl mod_auth_pgsql  php-pear php-bcmath  php-mbstring php-cli php-ldap php-pdo php-pgsql php-gd"
    )

    if (version == 'release 7'):
        run("systemctl start httpd")
        run("systemctl enable httpd")
    else:
        run("service httpd start")
        run("chkconfig httpd on")

#Creacion de archivos para bitacoras
    archi = open("/usr/local/lib/phx.c", 'w')
    archi.write('#include "postgres.h"\n')
    archi.write('#include <string.h>\n')
    archi.write('#include "fmgr.h"\n')
    archi.write('#include "utils/geo_decls.h"\n')
    archi.write('#include <stdio.h>\n')

    archi.write('#ifdef PG_MODULE_MAGIC\n')
    archi.write('PG_MODULE_MAGIC;\n')
    archi.write('#endif\n')
    archi.write('/* by value */\n')
    archi.write('PG_FUNCTION_INFO_V1(monitor_phx);\n')

    archi.write('Datum\n')
    archi.write('monitor_phx(PG_FUNCTION_ARGS)\n')
    archi.write('{\n')
    archi.write('    int32   arg = PG_GETARG_INT32(0);\n')
    archi.write('    system("sudo /usr/local/lib/./phxbd.sh");\n')
    archi.write('        PG_RETURN_INT32(arg);\n')
    archi.write('}')
    archi.close()

    run("gcc -I /usr/local/include -I /usr/pgsql-9.5/include/server/ -fpic -c /usr/local/lib/phx.c"
        )
    run("gcc -I /usr/local/include -I /usr/pgsql-9.5/include/server/ -shared -o /usr/local/lib/phx.so phx.o"
        )

    run("chown root.postgres /usr/local/lib/phx.so")
    run("chmod 750 /usr/local/lib/phx.so")

    archi = open("/usr/local/lib/phxbd.sh", 'w')
    archi.write('!/bin/bash\n')
    archi.write(
        'top -b -n 1 | grep -e postgres -e httpd | awk \'{print $1","$12","$2","$9","$10","$5""""}\' > /tmp/procesos.csv\n'
    )
    archi.write('chown root.postgres /tmp/procesos.csv\n')
    archi.write('chmod 740 /tmp/procesos.csv')

    sudo("chown root.postgres /usr/local/lib/phxbd.sh")
    sudo("sudo chmod 700 /usr/local/lib/phxbd.sh")

    f = open("/etc/sudoers", 'r')
    chain = f.read()
    chain = chain.replace("Defaults    requiretty", "#Defaults    requiretty")
    chain = chain.replace(
        "root    ALL=(ALL)       ALL",
        "root    ALL=(ALL)       ALL\n postgres        ALL=NOPASSWD: /usr/local/lib/phxbd.sh"
    )
    f.close()

    f = open("/etc/sudoers", 'w')
    f.write(chain)
    f.close()

    #Instalacion de mcrypt para servicios rest
    if (version == 'release 7'):
        run("wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-9.noarch.rpm"
            )
        run("wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm")
        run("rpm -Uvh remi-release-7*.rpm epel-release-7*.rpm")
    else:
        run("wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm"
            )
        run("wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm")
        sudo("rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm")

    run("yum -y update")
    run("yum -y install php-mcrypt*")

    # cambio de los archivos pg_hba y postgres.config#

    archi = open("/var/lib/pgsql/9.5/data/pg_hba.conf", 'w')

    archi.write(
        "# TYPE  DATABASE        USER            ADDRESS                 METHOD\n\n"
    )
    archi.write("# 'local' is for Unix domain socket connections only\n")
    archi.write(
        "local   all		postgres,dbkerp_conexion                  trust\n")
    archi.write(
        "local   all             all                                     md5\n"
    )
    archi.write("# IPv4 local connections:\n")
    archi.write(
        "host    all             all             127.0.0.1/32            md5\n"
    )
    archi.write(
        "host    all             all             192.168.0.0/16          md5\n"
    )
    archi.write("# IPv6 local connections:\n")
    archi.write(
        "host    all             all             ::1/128                 md5\n"
    )
    archi.close()

    f = open("/var/lib/pgsql/9.5/data/postgresql.conf", 'r')

    chain = f.read()
    chain = chain.replace("pg_catalog.english", "pg_catalog.spanish")
    chain = chain.replace("log_destination = 'stderr'",
                          "log_destination = 'csvlog'")
    chain = chain.replace("log_filename = 'postgresql-%a.log'",
                          "log_filename = 'postgresql-%Y-%m-%d.log'")
    chain = chain.replace("log_truncate_on_rotation = on",
                          "log_truncate_on_rotation = off")
    chain = chain.replace("#log_error_verbosity = default",
                          "log_error_verbosity = verbose")
    chain = chain.replace("#log_statement = 'none'", "log_statement = 'mod'")
    chain = chain.replace("iso, mdy", "iso, dmy")
    f.close()

    otro = open("/var/lib/pgsql/9.5/data/postgresql.conf", 'w')

    otro.write(chain)
    otro.close()

    s = open("/var/lib/pgsql/9.5/data/postgresql.conf", 'a')

    s.write("listen_addresses = '*'\n")
    s.write("bytea_output = 'escape'\n")
    s.close()

    db_pass = "******"
    sudo('psql -c "ALTER USER postgres WITH ENCRYPTED PASSWORD E\'%s\'"' %
         (db_pass),
         user='******')
    sudo('psql -c "CREATE DATABASE dbkerp WITH ENCODING=\'UTF-8\';"',
         user='******')
    sudo(
        'psql -c "CREATE USER dbkerp_conexion WITH PASSWORD \'dbkerp_conexion\';"',
        user='******')
    sudo('psql -c "ALTER ROLE dbkerp_conexion SUPERUSER;"', user='******')
    sudo(
        'psql -c "CREATE USER dbkerp_admin WITH PASSWORD \'a1a69c4e834c5aa6cce8c6eceee84295\';"',
        user='******')
    sudo('psql -c "ALTER ROLE dbkerp_admin SUPERUSER;"', user='******')

    if (version == 'release 7'):
        run('systemctl restart postgresql-9.5')
    else:
        run('service postgresql-9.5 restart')


# instalacion de git para poder bajar el repositoriio pxp y moviendo a la carpeta /var/www/html/kerp/#
    sudo("yum -y install git-core")
    run("mkdir /var/www/html/kerp")
    run("mkdir /var/www/html/kerp/pxp")

    #Si existe proxy se configura github para el proxy
    if (proxy != ""):
        run("git config --global http.proxy http://" + proxy)
        run("git config --global https.proxy https://" + proxy)

    run("git clone https://github.com/kplian/pxp.git /var/www/html/kerp/pxp")
    run("chown -R apache.apache /var/www/html/kerp/")
    run("chmod 700 -R /var/www/html/kerp/")

    # haciendo una copia de datosgenerales.samples.php y modificando archivo#
    f = open("/var/www/html/kerp/pxp/lib/DatosGenerales.sample.php")
    g = open("/var/www/html/kerp/pxp/lib/DatosGenerales.php", "w")
    linea = f.readline()
    while linea != "":
        g.write(linea)
        linea = f.readline()

    g.close()
    f.close()
    #TODO    VOLVER VARIABLE LA CARPETA PRINCIPAL KERP
    f = open("/var/www/html/kerp/pxp/lib/DatosGenerales.php", 'r')
    chain = f.read()
    chain = chain.replace("/web/lib/lib_control/",
                          "/kerp/pxp/lib/lib_control/")
    chain = chain.replace("/kerp-boa/", "/kerp/")

    chain = chain.replace("/var/lib/pgsql/9.1/data/pg_log/",
                          "/var/lib/pgsql/9.5/data/pg_log/")

    f.close()
    otro = open("/var/www/html/kerp/pxp/lib/DatosGenerales.php", 'w')
    otro.write(chain)
    otro.close()

    run("ln -s /var/www/html/kerp/pxp/lib /var/www/html/kerp/lib")
    run("ln -s /var/www/html/kerp/pxp/index.php /var/www/html/kerp/index.php")
    run("ln -s /var/www/html/kerp/pxp/sis_generador /var/www/html/kerp/sis_generador"
        )
    run("ln -s /var/www/html/kerp/pxp/sis_organigrama /var/www/html/kerp/sis_organigrama"
        )
    run("ln -s /var/www/html/kerp/pxp/sis_parametros /var/www/html/kerp/sis_parametros"
        )
    run("ln -s /var/www/html/kerp/pxp/sis_seguridad /var/www/html/kerp/sis_seguridad"
        )
    run("ln -s /var/www/html/kerp/pxp/sis_workflow /var/www/html/kerp/sis_workflow"
        )

    archi = open('/var/www/html/kerp/sistemas.txt', 'w')
    archi.close()

    run("mkdir /var/www/html/kerp/reportes_generados")

    sudo("setfacl -R -m u:apache:wrx /var/www/html/kerp/reportes_generados")

    # 	sudo("yum -y install rpm-build")

    sudo("setfacl -R -m u:postgres:wrx /var/www/html")

    sudo("chcon -Rv --type=httpd_sys_rw_content_t /var/www/html/kerp/")
    sudo("setsebool -P httpd_can_network_connect_db=1")

    # iptables
    if (version == 'release 6'):
        run("iptables --flush")
        run("iptables -P INPUT ACCEPT")
        run("iptables -P OUTPUT ACCEPT")
        run("iptables -P FORWARD ACCEPT")
        #Interfaz local aceptar
        run("iptables -A INPUT -i lo -j ACCEPT")
        #Comunicaciones establecidas aceptar
        run("iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT")
        #Ping Aceptar
        run("iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT")
        #Ssh Aceptar
        run("iptables -A INPUT -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT"
            )
        #http y https aceptar
        run("iptables -A INPUT -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT"
            )
        run("iptables -A INPUT -p tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT"
            )
        #postgres  aceptar
        run("iptables -A INPUT -p tcp --dport 5432 -m state --state NEW,ESTABLISHED -j ACCEPT"
            )
        run("iptables -P INPUT DROP")
        run("service iptables save")
        run("service iptables restart")
    else:
        run("firewall-cmd --permanent --add-port=22/tcp")
        run("firewall-cmd --permanent --add-port=80/tcp")
        run("firewall-cmd --permanent --add-port=5432/tcp")
        run("firewall-cmd --reload")

    prompts = []
    prompts += expect('Ingrese una opcion.*', '1')
    prompts += expect('Ingrese el nombre de la BD.*', 'dbkerp')
    prompts += expect('Desea obtener un backup de la BD.*', 'NO')
    prompts += expect('los datos de prueba.*', 'n')

    with expecting(prompts):
        sudo(
            "/var/www/html/kerp/pxp/utilidades/restaurar_bd/./restaurar_todo.py",
            user="******")
def check():
    run("ls")