Ejemplo n.º 1
0
 def addipconf(self,updatetc=False):
     ipaddress = self.properties['IPAddress'];
     
     name = self.properties['Name'];
     domainname = proxieddomain(name);
     
     fulladdress = self.properties['ConnectionPath'];
     filepath = "/etc/nginx/conf.d/default.conf";
     testpath = "./test/test.conf" 
     nginx_server = get_nginx_server_address()
     cmd ="cat " + filepath;
     out1=remote_machine.execute_remote_cmd(nginx_server[0],nginx_server[1],cmd,nginx_server[2])
     print(out1);
     reverser = manageproxy(out1);
     
     reverser.add(reverser.render({'x' : domainname , 'y' : fulladdress}),fulladdress);
     
     
     reverser.filedit = reverser.filedit.replace('$' ,'\$');
     cmd = 'echo -e "' + reverser.filedit  + '" > '+ filepath;
     out2 = remote_machine.execute_remote_cmd(nginx_server[0],nginx_server[1],cmd,nginx_server[2])
     
     cmd = '/etc/init.d/nginx reload';
     output = remote_machine.execute_remote_cmd(nginx_server[0],nginx_server[1],cmd,nginx_server[2])
     
     if(updatetc):
         hostadd = self.properties['ConnectionPath'].split(':')[0] + ' '  + domainname ; 
         cmd ='echo " ' + hostadd + ' " >> /etc/hosts'; 
         output = remote_machine.execute_remote_cmd(nginx_server[0],nginx_server[1],cmd,nginx_server[2])
Ejemplo n.º 2
0
    def addipbyconf(self, updatetc=False):
        ipaddress = self.properties['IPAddress']

        name = self.properties['Name']
        domainname = proxieddomain(name)
        nginx_server = get_nginx_server_address()
        fulladdress = self.properties.get('ConnectionPath')
        if (not fulladdress):
            return
        logger.debug(fulladdress)
        filepath = "/etc/nginx/conf.d/" + self.properties['Name'] + ".conf"
        reverser = manageproxy('')
        reverser.add(reverser.render({
            'x': domainname,
            'y': fulladdress
        }))
        print(reverser.filedit)
        reverser.filedit = reverser.filedit.replace('$', '\$')
        cmd = 'echo -e "' + reverser.filedit + '" > ' + filepath
        out2 = remote_machine.execute_remote_cmd(nginx_server[0],
                                                 nginx_server[1], cmd,
                                                 nginx_server[2])
        print("Output : " + out2)
        cmd = '/etc/init.d/nginx reload'
        output = remote_machine.execute_remote_cmd(nginx_server[0],
                                                   nginx_server[1], cmd,
                                                   nginx_server[2])
        print(output)
Ejemplo n.º 3
0
 def addipbyconf(self,updatetc=False):
     ipaddress = self.properties['IPAddress'];
     
     name = self.properties['Name'];
     domainname = proxieddomain(name);
     nginx_server = get_nginx_server_address()
     fulladdress = self.properties['ConnectionPath'];
     logger.debug(fulladdress);
     filepath = "/etc/nginx/conf.d/" + self.properties['Name'] +".conf";
     reverser = manageproxy('');
     reverser.add(reverser.render({'x' : domainname , 'y' : fulladdress}),fulladdress);
     print(reverser.filedit);
     reverser.filedit = reverser.filedit.replace('$' ,'\$');
     cmd = 'echo -e "' + reverser.filedit  + '" > '+ filepath;
     out2 = remote_machine.execute_remote_cmd(nginx_server[0],nginx_server[1],cmd,nginx_server[2])
     print("Output : " +out2);
     cmd = '/etc/init.d/nginx reload';
     output = remote_machine.execute_remote_cmd(nginx_server[0],nginx_server[1],cmd,nginx_server[2])
     print(output)
     if(updatetc):
         hostadd = self.properties['ConnectionPath'].split(':')[0] + ' '  + domainname ; 
         cmd ='echo " ' + hostadd + ' " >> /etc/hosts'; 
         logger.debug('Command=> '+cmd)
         logger.debug('Host IP=> ' +hostadd)
         output = remote_machine.execute_remote_cmd(nginx_server[0],nginx_server[1],cmd,nginx_server[2])
         logger.debug(output)
Ejemplo n.º 4
0
def garbage_collector():
    
    #Delete volumes no longer necessary
    nginx_server = get_nginx_server_address()
    vollist = client.volumes(filters = { 'dangling' : True});
    volarray =  vollist.get('Volumes');
    print (vollist['Volumes']);
    if volarray:
        for volume in vollist['Volumes']:
            try:
                client.remove_volume(name = volume['Name']);
            except Exception as e:
                print (e); 
                
    #Delete remaining nginx conf
    
    conlist = client.containers(all = True);
    namelist = ['default'];
    for container in conlist:
        namelist.append(container['Names'][0].split("/")[2]);
        #~ namelist.append(container['Names'][0].split("/")[1]);
    print(namelist)    
    cmd = "ls /etc/nginx/conf.d/";    
    output = remote_machine.execute_remote_cmd(nginx_server[0],nginx_server[1],cmd,nginx_server[2])
    strlist = output.split("\n");
    print(strlist)
    
    todellist =[];
    for i in range(0,len(strlist)-1):
        name = strlist[i].split(".")[0];
        if not name in namelist:
            todellist.append(name);
    print(todellist)        
    for name in todellist:
        cmd = "rm -f /etc/nginx/conf.d/"+name+".conf" ;    
        output = remote_machine.execute_remote_cmd(nginx_server[0],nginx_server[1],cmd,nginx_server[2])
    
    #Delete any mysql database whose app is missing
    datalist= ['information_schema','sys','mysql','performance_schema']
    datalist.append(namelist);
    cmd = """bash -c "mypassword='******' /var/lib/mysql/mysql.sh -l" """ ;
    container = Container('f966820cf4a0')
    output = container.execcmd(cmd);
    strlist = output.split("\n");
    print(strlist)
    for i in range(3,len(strlist)-1):
        name = strlist[i].split(".")[0];
        if not name in datalist:
            todellist.append(name);    
    print(todellist);
    
    for name in todellist:
        cmd = """bash -c "mypassword='******' /var/lib/mysql/mysql.sh -r """ + name + ' "  ';    
        print(cmd);
        container.execcmd(cmd);
    container = 'None';
    
    #Delete any containers not in database
    print('not implemented')
Ejemplo n.º 5
0
 def deleteipbyconf(self):
     filepath = "/etc/nginx/conf.d/" + self.properties['Name'] +".conf";
     cmd = 'rm -f ' + filepath;
     nginx_server = get_nginx_server_address()
     output = remote_machine.execute_remote_cmd(nginx_server[0],nginx_server[1],cmd,nginx_server[2])
     print(output)
     cmd = '/etc/init.d/nginx reload';
     output = remote_machine.execute_remote_cmd(nginx_server[0],nginx_server[1],cmd,nginx_server[2])
     print(output)
Ejemplo n.º 6
0
 def deleteipbyconf(self):
     filepath = "/etc/nginx/conf.d/" + self.properties['Name'] + ".conf"
     cmd = 'rm -f ' + filepath
     nginx_server = get_nginx_server_address()
     output = remote_machine.execute_remote_cmd(nginx_server[0],
                                                nginx_server[1], cmd,
                                                nginx_server[2])
     print(output)
     cmd = '/etc/init.d/nginx reload'
     output = remote_machine.execute_remote_cmd(nginx_server[0],
                                                nginx_server[1], cmd,
                                                nginx_server[2])
     print(output)
Ejemplo n.º 7
0
def addip(name,uuids):
    filepath = "/etc/nginx/conf.d/" + name +".conf";
    addresses=[];
    nginx_server = get_nginx_server_address()
    for uuid in uuids:
        container = Container(uuid);
        addresses.append(container.properties.get('ConnectionPath'));	
    reverser = manageproxy('');
    domainname = proxieddomain("/"+name);
    reverser.addmultiple(domainname,addresses);
    reverser.filedit = reverser.filedit.replace('$' ,'\$');
    cmd = 'echo -e "' + reverser.filedit  + '" > '+ filepath;
    out2 = remote_machine.execute_remote_cmd(nginx_server[0],nginx_server[1],cmd,nginx_server[2])  # @UnusedVariable
    cmd = '/etc/init.d/nginx reload';
    output = remote_machine.execute_remote_cmd(nginx_server[0],nginx_server[1],cmd,nginx_server[2])  # @UnusedVariable
Ejemplo n.º 8
0
    def addipbyconf(self, updatetc=False):
        #         ipaddress = self.properties['IPAddress'];

        name = self.properties['Name']
        envvars = self.properties['Environment']
        domainname = None
        for x in envvars:
            sstrings = x.split("=")
            if (sstrings[0] == "HostName"):
                domainname = sstrings[1]
        if not domainname:
            domainname = proxieddomain(name)
        nginx_server = get_nginx_server_address()
        fulladdress = self.properties.get('ConnectionPath')
        logger.debug("check true")
        logger.debug(fulladdress)
        if (not fulladdress):
            return

        filepath = "/etc/nginx/conf.d/" + self.properties['Name'] + ".conf"
        reverser = manageproxy('')
        reverser.add(reverser.render({
            'x': domainname,
            'y': fulladdress
        }))
        print(reverser.filedit)
        reverser.filedit = reverser.filedit.replace('$', '\$')
        cmd = 'echo -e "' + reverser.filedit + '" > ' + filepath
        out2 = remote_machine.execute_remote_cmd(nginx_server[0],
                                                 nginx_server[1], cmd,
                                                 nginx_server[2])
        print("Output : " + out2)
        cmd = '/etc/init.d/nginx reload'
        output = remote_machine.execute_remote_cmd(nginx_server[0],
                                                   nginx_server[1], cmd,
                                                   nginx_server[2])
        print(output)
        if (updatetc):
            hostadd = self.properties['ConnectionPath'].split(
                ':')[0] + ' ' + domainname
            cmd = 'echo " ' + hostadd + ' " >> /etc/hosts'
            logger.debug('Command=> ' + cmd)
            #logger.debug('Host IP=> ' +hostadd)
            output = remote_machine.execute_remote_cmd(nginx_server[0],
                                                       nginx_server[1], cmd,
                                                       nginx_server[2])
Ejemplo n.º 9
0
def addip(name, uuids):
    filepath = "/etc/nginx/conf.d/" + name + ".conf"
    addresses = []
    nginx_server = get_nginx_server_address()
    for uuid in uuids:
        container = Container(uuid)
        addresses.append(container.properties.get('ConnectionPath'))
    reverser = manageproxy('')
    domainname = proxieddomain("/" + name)
    reverser.addmultiple(domainname, addresses)
    reverser.filedit = reverser.filedit.replace('$', '\$')
    cmd = 'echo -e "' + reverser.filedit + '" > ' + filepath
    out2 = remote_machine.execute_remote_cmd(nginx_server[0], nginx_server[1],
                                             cmd, nginx_server[2])
    cmd = '/etc/init.d/nginx reload'
    output = remote_machine.execute_remote_cmd(nginx_server[0],
                                               nginx_server[1], cmd,
                                               nginx_server[2])
Ejemplo n.º 10
0
 def deleteipconf(self):    
     name = self.properties['Name'];
     domainname = proxieddomain(name);
     filepath = "/etc/nginx/conf.d/default.conf";
     testpath = "./test/test.conf" 
     nginx_server = get_nginx_server_address()
     cmd ="cat " + filepath;
     out1=remote_machine.execute_remote_cmd(nginx_server[0],nginx_server[1],cmd,nginx_server[2])
     reverser = manageproxy(out1);
     reverser.removebyip(domainname);
     
     reverser.filedit = reverser.filedit.replace('$' ,'\$');
     cmd = 'echo -e "' + reverser.filedit  + '" > '+ filepath;
     out2 = remote_machine.execute_remote_cmd(nginx_server[0],nginx_server[1],cmd,nginx_server[2])
     
    
     cmd = '/etc/init.d/nginx reload';
     output =remote_machine.execute_remote_cmd(nginx_server[0],nginx_server[1],cmd,nginx_server[2])
     print(output)
Ejemplo n.º 11
0
def garbage_collector():
    
    #Delete volumes no longer necessary
    nginx_server = get_nginx_server_address()
    vollist = client.volumes(filters = { 'dangling' : True})
    volarray =  vollist.get('Volumes')
    print (vollist['Volumes'])
    if volarray:
        for volume in vollist['Volumes']:
            try:
                client.remove_volume(name = volume['Name'])
            except Exception as e:
                print (e) 
                
    #Delete remaining nginx conf
    
    conlist = client.containers(all = True)
    namelist = ['default']
    for container in conlist:
        namelist.append(container['Names'][0].split("/")[2])
        #~ namelist.append(container['Names'][0].split("/")[1])
    print(namelist)    
    cmd = "ls /etc/nginx/conf.d/"    
    output = remote_machine.execute_remote_cmd(nginx_server[0],nginx_server[1],cmd,nginx_server[2])
    strlist = output.split("\n")
    print(strlist)
    
    todellist =[]
    for i in range(0,len(strlist)-1):
        name = strlist[i].split(".")[0]
        if not name in namelist:
            todellist.append(name)
    print(todellist)        
    for name in todellist:
        cmd = "rm -f /etc/nginx/conf.d/"+name+".conf"     
        output = remote_machine.execute_remote_cmd(nginx_server[0],nginx_server[1],cmd,nginx_server[2])
    
    #Delete any mysql database whose app is missing
    '''datalist= ['information_schema','sys','mysql','performance_schema']
Ejemplo n.º 12
0
    def addipbyconf(self,updatetc=False):
#         ipaddress = self.properties['IPAddress'];
        
        name = self.properties['Name'];
        envvars = self.properties['Environment'];
        domainname=None;
        for x in envvars:
            sstrings = x.split("=");
            if (sstrings[0] == "HostName") :
                domainname=sstrings[1];
        if not domainname :
            domainname = proxieddomain(name);
        nginx_server = get_nginx_server_address()
        fulladdress = self.properties.get('ConnectionPath');
        logger.debug("check true");
        logger.debug(fulladdress);
        if (not fulladdress):
            return;
        
        filepath = "/etc/nginx/conf.d/" + self.properties['Name'] +".conf";
        reverser = manageproxy('');
        reverser.add(reverser.render({'x' : domainname , 'y' : fulladdress}));
        print(reverser.filedit);
        reverser.filedit = reverser.filedit.replace('$' ,'\$');
        cmd = 'echo -e "' + reverser.filedit  + '" > '+ filepath;
        out2 = remote_machine.execute_remote_cmd(nginx_server[0],nginx_server[1],cmd,nginx_server[2])
        print("Output : " +out2);
        cmd = '/etc/init.d/nginx reload';
        output = remote_machine.execute_remote_cmd(nginx_server[0],nginx_server[1],cmd,nginx_server[2])
        print(output)
        if(updatetc):
            hostadd = self.properties['ConnectionPath'].split(':')[0] + ' '  + domainname ; 
            cmd ='echo " ' + hostadd + ' " >> /etc/hosts'; 
            logger.debug('Command=> '+cmd)
            #logger.debug('Host IP=> ' +hostadd)
            output = remote_machine.execute_remote_cmd(nginx_server[0],nginx_server[1],cmd,nginx_server[2])
Ejemplo n.º 13
0
from gluon import DAL, Field
import remote_vm_task as remote_machine
from helper import get_mysqldb_machine_address , get_mysqldb_configuration

def create_account(user_id,new_password):
	mysql_server = get_mysqldb_machine_address()
	mysql_db = get_mysqldb_configuration()
	cmd = bash -c "mypassword='******'/root/mysqlconf/mysql.sh -u"+ user_id" "+ new_password;
    out2 = remote_machine.execute_remote_cmd(mysql_server[0],mysql_server[1],cmd,mysql_server[2])
	return;
	
def change_password(user_id,new_password):
	'''check if user exists
	
	SELECT User FROM mysql.user WHERE User = '******'
	if exists then change_password else
	create_account(user_id,new_password)
	return;
	
	'''
	mysql_server = get_mysqldb_machine_address()
	mysql_db = get_mysqldb_configuration()
	cmd = bash -c "mypassword='******'/root/mysqlconf/mysql.sh -cp "+ user_id" "+ new_password;
    out2 = remote_machine.execute_remote_cmd(mysql_server[0],mysql_server[1],cmd,mysql_server[2])
	return;
	
def create_databse(user_id,database_name):
	'''check if db_exists
	
	SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = 'DBName'
	if exists return False else 
Ejemplo n.º 14
0
def garbage_collector():

    #Delete volumes no longer necessary
    nginx_server = get_nginx_server_address()
    vollist = client.volumes(filters={'dangling': True})
    volarray = vollist.get('Volumes')
    print(vollist['Volumes'])
    if volarray:
        for volume in vollist['Volumes']:
            try:
                client.remove_volume(name=volume['Name'])
            except Exception as e:
                print(e)

    #Delete remaining nginx conf

    conlist = client.containers(all=True)
    namelist = ['default']
    for container in conlist:
        namelist.append(container['Names'][0].split("/")[2])
        #~ namelist.append(container['Names'][0].split("/")[1]);
    print(namelist)
    cmd = "ls /etc/nginx/conf.d/"
    output = remote_machine.execute_remote_cmd(nginx_server[0],
                                               nginx_server[1], cmd,
                                               nginx_server[2])
    strlist = output.split("\n")
    print(strlist)

    todellist = []
    for i in range(0, len(strlist) - 1):
        name = strlist[i].split(".")[0]
        if not name in namelist:
            todellist.append(name)
    print(todellist)
    for name in todellist:
        cmd = "rm -f /etc/nginx/conf.d/" + name + ".conf"
        output = remote_machine.execute_remote_cmd(nginx_server[0],
                                                   nginx_server[1], cmd,
                                                   nginx_server[2])

    #Delete any mysql database whose app is missing
    datalist = ['information_schema', 'sys', 'mysql', 'performance_schema']
    datalist.append(namelist)
    cmd = """bash -c "mypassword='******' /var/lib/mysql/mysql.sh -l" """
    container = Container('f966820cf4a0')
    output = container.execcmd(cmd)
    strlist = output.split("\n")
    print(strlist)
    for i in range(3, len(strlist) - 1):
        name = strlist[i].split(".")[0]
        if not name in datalist:
            todellist.append(name)
    print(todellist)

    for name in todellist:
        cmd = """bash -c "mypassword='******' /var/lib/mysql/mysql.sh -r """ + name + ' "  '
        print(cmd)
        container.execcmd(cmd)
    container = 'None'

    #Delete any containers not in database
    print('not implemented')