def purge(self, cr, uid, vals, context={}): context.update({'saas-self': self, 'saas-cr': cr, 'saas-uid': uid}) ssh, sftp = execute.connect(vals['backup_fullname'], context=context) execute.execute(ssh, ['rm', '-rf', '/opt/backup/simple/' + vals['saverepo_name'] + '/'+ vals['save_name']], context) ssh.close() sftp.close() return
def wpa_run(self): dump_cmd = ['airodump-ng', '-c', self.channel, '--bssid', self.bssid, '-w', './log/' + self.bssid, self.iface] airodump_proc = Popen(dump_cmd, stdout=DN, stderr=DN) self.proc_list.append(airodump_proc) self.send_deauths() while self.key == '': output = Popen('tshark -r ./log/' + self.bssid + '-01.cap 2>/dev/null| grep "Message 4 of 4"',shell=True, stdout=PIPE).communicate()[0] if output.find('Message 4 of 4') != -1: execute('rm ./log/'+self.bssid+'.key') airodump_proc.kill() airodump_proc.communicate() crack_cmd = ['aircrack-ng', '-w', self.password_list, '-b', self.bssid, './log/' + self.bssid + '-01.cap','-l', './log/' + self.bssid + '.key'] crack_proc = Popen(crack_cmd, stdout=DN) self.proc_list.append(crack_proc) crack_proc.wait() try: f = open('./log/' + self.bssid + '.key') key = f.read() f.close() self.key = key self.crack_success = True self.stop() except: pass else: self.send_deauths() time.sleep(5) return self.key
def stop_monitor(): ''' @brief Delete wlan device. ''' for dev in _dev_name_list: execute('iw dev '+ dev +' del > /dev/null 2>&1') w_interface_up()
def deploy_post(self, cr, uid, vals, context): super(saas_container, self).deploy_post(cr, uid, vals, context) context.update({'saas-self': self, 'saas-cr': cr, 'saas-uid': uid}) if vals['apptype_name'] == 'docker': ssh, sftp = execute.connect(vals['container_fullname'], context=context) execute.execute(ssh, ['echo "host all all ' + vals['container_options']['network']['value'] + ' md5" >> /etc/postgresql/' + vals['app_current_version'] + '/main/pg_hba.conf'], context) execute.execute(ssh, ['echo "listen_addresses=\'' + vals['container_options']['listen']['value'] + '\'" >> /etc/postgresql/' + vals['app_current_version'] + '/main/postgresql.conf'], context)
def purge_files(self, cr, uid, vals, context={}): context.update({'saas-self': self, 'saas-cr': cr, 'saas-uid': uid}) ssh, sftp = execute.connect(vals['container_fullname'], username=vals['apptype_system_user'], context=context) execute.execute(ssh, ['rm', '-rf', vals['service_full_localpath_files']], context) ssh.close() sftp.close() self.check_files(cr, uid, vals, context=context)
def start(self, cr, uid, vals, context={}): context.update({'saas-self': self, 'saas-cr': cr, 'saas-uid': uid}) self.stop(cr, uid, vals, context=context) ssh, sftp = execute.connect(vals['server_domain'], vals['server_ssh_port'], 'root', context) execute.execute(ssh, ['docker', 'start', vals['container_name']], context) ssh.close() sftp.close() time.sleep(3)
def purge(self, cr, uid, vals, context={}): context.update({'saas-self': self, 'saas-cr': cr, 'saas-uid': uid}) if 'shinken_server_domain' in vals: ssh, sftp = execute.connect(vals['shinken_fullname'], context=context) execute.execute(ssh, ['rm', vals['server_shinken_configfile']], context) execute.execute(ssh, ['/etc/init.d/shinken', 'reload'], context) ssh.close() sftp.close()
def purge(self, cr, uid, vals, context={}): context.update({'saas-self': self, 'saas-cr': cr, 'saas-uid': uid}) #TODO we need to launch a direct command, without ssh ssh, sftp = execute.connect('localhost', 22, 'saas-conductor', context) execute.execute(ssh, ['sed', '-i', "'/Host " + vals['server_domain'] + "/,/END " + vals['server_domain'] + "/d'", vals['config_home_directory'] + '/.ssh/config'], context) ssh.close() sftp.close() execute.execute_local(['rm', '-rf', vals['config_home_directory'] + '/.ssh/keys/' + vals['server_domain']], context)
def run(self): ''' Start airodump-ng and dump ''' # Clean first self.stop() remove_command = 'rm -rf ' + self.air_scan_result + '*' execute(remove_command) dump_command = ['airodump-ng', self.iface, '-w', self.air_scan_result, '--output-format', 'csv'] self.dump_proc, unused_ret, unused_out, unused_err = execute(dump_command, wait=False) self.isRunning = True
def w_interface_up(): p, retval, out, err = execute('iw dev |grep Interface') intf_list = out.replace('\tInterface','').split() for interface in intf_list: execute('ifconfig ' + interface + ' up') #print get_interfaces()
def main (): logging.basicConfig(stream=sys.stdout, level=logging.INFO) for locale in CONFIGURATION.locales: merge(locale) # Dummy text is not required. Don't raise exception if files are missing. merge(CONFIGURATION.dummy_locale, fail_if_missing=False) compile_cmd = 'django-admin.py compilemessages' execute(compile_cmd, working_directory=BASE_DIR)
def check_files(self, cr, uid, vals, context={}): context.update({'saas-self': self, 'saas-cr': cr, 'saas-uid': uid}) service_ids = self.search(cr, uid, [('application_version_id', '=', vals['app_version_id']),('container_id.server_id','=',vals['server_id'])], context=context) if vals['service_id'] in service_ids: service_ids.remove(vals['service_id']) if not service_ids: ssh, sftp = execute.connect(vals['server_domain'], vals['server_ssh_port'], 'root', context) execute.execute(ssh, ['rm', '-rf', vals['app_version_full_hostpath']], context) ssh.close() sftp.close()
def deploy(self, cr, uid, vals, context={}): context.update({'saas-self': self, 'saas-cr': cr, 'saas-uid': uid}) _logger.info('test %s', vals['shinken_server_domain']) if 'shinken_server_domain' in vals: ssh, sftp = execute.connect(vals['shinken_fullname'], context=context) sftp.put(vals['config_conductor_path'] + '/saas/saas_shinken/res/server-shinken.config', vals['server_shinken_configfile']) execute.execute(ssh, ['sed', '-i', '"s/NAME/' + vals['server_domain'] + '/g"', vals['server_shinken_configfile']], context) execute.execute(ssh, ['/etc/init.d/shinken', 'reload'], context) ssh.close() sftp.close()
def set_monitor_mode(): ''' @brief Set wlan device to monitor mode. @return: * success - True * fail - False ''' for dev in _mon_dev_list: execute('iwconfig '+ dev +' mode monitor') time.sleep(1) p, retval, out, err = execute('iwconfig '+ dev) retry = 0 while out.find('Mode:Monitor') == -1: # If the mode is not changed properly, enter the loop and retry 60. execute('ifconfig '+dev+' down') execute('iwconfig '+ dev +' mode monitor') time.sleep(0.5) p, retval, out, err = execute('iwconfig '+ dev) retry = retry + 1 if retry == 150: break time.sleep(2) for dev in _mon_dev_list: # Reaffirm p, retval, out, err = execute('iwconfig '+ dev) if out.find('Mode:Monitor') == -1: return False return True
def purge_key(self, cr, uid, vals, context={}): ssh, sftp = execute.connect('localhost', 22, 'saas-conductor', context) execute.execute(ssh, ['sed', '-i', "'/Host " + vals['container_fullname'] + "/,/END " + vals['container_fullname'] + "/d'", vals['config_home_directory'] + '/.ssh/config'], context) ssh.close() sftp.close() execute.execute_local(['rm', '-rf', vals['config_home_directory'] + '/.ssh/keys/' + vals['container_fullname']], context) execute.execute_local(['rm', '-rf', vals['config_home_directory'] + '/.ssh/keys/' + vals['container_fullname'] + '.pub'], context) ssh, sftp = execute.connect(vals['server_domain'], vals['server_ssh_port'], 'root', context) execute.execute(ssh, ['rm', '-rf', '/opt/keys/' + vals['container_fullname'] + '/authorized_keys'], context) ssh.close() sftp.close()
def deploy(self, cr, uid, vals, context=None): context.update({'saas-self': self, 'saas-cr': cr, 'saas-uid': uid}) self.purge(cr, uid, vals, context=context) if 'base_restoration' in context: return res = self.deploy_create_database(cr, uid, vals, context) if not res: for key, database in vals['base_databases'].iteritems(): if vals['database_type'] != 'mysql': ssh, sftp = execute.connect(vals['container_fullname'], username=vals['apptype_system_user'], context=context) execute.execute(ssh, ['createdb', '-h', vals['database_server'], '-U', vals['service_db_user'], database], context) ssh.close() sftp.close() else: ssh, sftp = execute.connect(vals['database_fullname'], context=context) execute.execute(ssh, ["mysql -u root -p'" + vals['database_root_password'] + "' -se \"create database " + database + ";\""], context) execute.execute(ssh, ["mysql -u root -p'" + vals['database_root_password'] + "' -se \"grant all on " + database + ".* to '" + vals['service_db_user'] + "';\""], context) ssh.close() sftp.close() execute.log('Database created', context) if vals['base_build'] == 'build': self.deploy_build(cr, uid, vals, context) elif vals['base_build'] == 'restore': if vals['database_type'] != 'mysql': ssh, sftp = execute.connect(vals['container_fullname'], username=vals['apptype_system_user'], context=context) execute.execute(ssh, ['pg_restore', '-h', vals['bdd_server_domain'], '-U', vals['service_db_user'], '--no-owner', '-Fc', '-d', vals['base_unique_name_'], vals['app_version_full_localpath'] + '/' + vals['app_bdd'] + '/build.sql'], context) ssh.close() sftp.close() else: ssh, sftp = execute.connect(vals['container_fullname'], username=vals['apptype_system_user'], context=context) execute.execute(ssh, ['mysql', '-h', vals['bdd_server_domain'], '-u', vals['service_db_user'], '-p' + vals['bdd_server_mysql_passwd'], vals['base_unique_name_'], '<', vals['app_version_full_localpath'] + '/' + vals['app_bdd'] + '/build.sql'], context) ssh.close() sftp.close() self.deploy_post_restore(cr, uid, vals, context) if vals['base_build'] != 'none': if vals['base_poweruser_name'] and vals['base_poweruser_email'] and vals['apptype_admin_name'] != vals['base_poweruser_name']: self.deploy_create_poweruser(cr, uid, vals, context) if vals['base_test']: self.deploy_test(cr, uid, vals, context) self.deploy_post(cr, uid, vals, context) #For shinken self.save(cr, uid, [vals['base_id']], context=context)
def purge(self, cr, uid, vals, context={}): context.update({'saas-self': self, 'saas-cr': cr, 'saas-uid': uid}) self.purge_files(cr, uid, vals, context=context) self.purge_pre_service(cr, uid, vals, context) ssh, sftp = execute.connect(vals['container_fullname'], username=vals['apptype_system_user'], context=context) execute.execute(ssh, ['rm', '-rf', vals['service_full_localpath']], context) ssh.close() sftp.close() if vals['database_type'] != 'mysql': ssh, sftp = execute.connect(vals['database_fullname'], username='******', context=context) execute.execute(ssh, ['psql', '-c', '"DROP USER ' + vals['service_db_user'] + ';"'], context) ssh.close() sftp.close() ssh, sftp = execute.connect(vals['container_fullname'], username=vals['apptype_system_user'], context=context) execute.execute(ssh, ['sed', '-i', '"/:*:' + vals['service_db_user'] + ':/d" ~/.pgpass'], context) ssh.close() sftp.close() else: ssh, sftp = execute.connect(vals['database_fullname'], context=context) execute.execute(ssh, ["mysql -u root -p'" + vals['database_root_password'] + "' -se \"drop user " + vals['service_db_user'] + ";\""], context) ssh.close() sftp.close() return
def auto_monitor(): ''' @brief Check monitor mode support. and set. ''' print "Check Monitor mode...." p, r, out, err = execute('iw dev| grep phy') interface_list = out.split('\n') interface_list.pop() ap_support = [] monitor_support = [] for interface in interface_list: interface = interface.replace('#', '') p, r, out, err = execute('iw phy '+interface+' info') sup = out[out.find('Supported interface modes:')+28:] support_list = sup[:sup.find(':')].replace('\t', '').replace(' ', '').replace('*', '').split('\n')[:-1] for support in support_list: if support == 'AP': ap_support.append(interface) elif support == 'monitor': monitor_support.append(interface) if len(ap_support) == 0 or len(monitor_support) == 0: print '\n' print '[!!] I did not find the device to support the required mode.' print '[!!] Please check that the WLAN device that supports monitor mode on your system.' return False print "Set Monitor mode...." if ap_support: w_interface_down() for dev in _dev_name_list: execute('iw phy ' + ap_support[0] + ' interface add '+ dev +' type monitor') w_interface_down() ret = set_monitor_mode() if ret == False: print '[!!] It failed to change the mode of the wireless LAN device.' print '[!!] Please try again later.' return False w_interface_down() elif monitor_support: w_interface_down() for dev in _dev_name_list: if dev == "atear_ap": continue execute('iw phy ' + ap_support[0] + ' interface add '+ dev +' type monitor') w_interface_down() ret = set_monitor_mode() if ret == False: print '[!!] It failed to change the mode of the wireless LAN device.' print '[!!] Please try again later.' return False w_interface_down() execute('rfkill unblock wlan') return True
def run(self): dns_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) dns_sock.settimeout(3) # Set timeout on socket-operations. execute('fuser -k -n udp 53') time.sleep(0.5) dns_sock.bind(('', 53)) while self.START_SIGNAL: try: data, addr = dns_sock.recvfrom(1024) except: continue packet = DNSQuery(data) # Return own IP adress. dns_sock.sendto(packet.respuesta(self.address), addr) dns_sock.close()
def set_monitor_mode(dev): ''' @brief Set wlan device to monitor mode. @return: * success - True * fail - False ''' cmd = "ifconfig %s down;iwconfig %s mode monitor;ifconfig %s up" %(dev, dev, dev) execute(cmd) time.sleep(0.5) p, r, out, e = execute('iwconfig '+ dev) if "Mode:Monitor" not in out: return False return True
def db_update(*args): return execute("%s %s \"%s\"" % ( glob.config.get("paths", "php"), glob.getfile("shared/bridge", "db_update.php"), "\" \"".join(args) ) )
def create_pool(cluster, pool_name, compression_type, tier=True, pg_num=32, pgp_num=32): """ Create erasure pool pool_name with compression compression_type """ if cluster.pool_exists(pool_name): cluster.delete_pool(pool_name) if tier and cluster.pool_exists(pool_name+"_tier"): cluster.delete_pool(pool_name+"_tier") try: cmds = ["./ceph osd pool create {0} {1} {2} erasure".format(pool_name, pg_num, pgp_num), "./ceph osd pool set {0} compression_type {1}".format(pool_name, compression_type) ] if tier: cmds.extend(["./ceph osd pool create {0}_tier {1} {2}".format(pool_name, pg_num, pgp_num), "./ceph osd tier add {0} {0}_tier".format(pool_name), "./ceph osd tier cache-mode {0}_tier writeback".format(pool_name), "./ceph osd tier set-overlay {0} {0}_tier".format(pool_name) ]) for cmd in cmds: res = execute(cmd) logger.debug(res) except Exception as ex: logger.error("%s failed: %s", cmd, ex.message()) return False return True
def check_time_delta(): """ Check the time delta between cluster nodes. Inputs: delta (int): Max allowable time delta Outputs: check (dict): Check results """ check = { "status": None, "delta": None } _, partner, _ = get_rsf_conf() try: ptime = int(execute("date +%s").splitlines()[-1]) logger.debug("Partner time is %d" % ptime) ltime = int(execute_ssh("date +%s", partner).splitlines()[-1]) logger.debug("Local time is %d" % ltime) delta = abs(ltime - ptime) except: raise else: check["status"] = True check["delta"] = delta return check
def arp_spoof(iface): execute('echo 1 > /proc/sys/net/ipv4/ip_forward') execute('service whoopsie stop') victim_hosts = network_host_ip(iface) gateway_ip = get_l_gateway_ip(iface) while True: for victim_ip in victim_hosts: to_gateway = ARP() to_gateway.psrc = victim_ip to_gateway.pdst = gateway_ip to_victim = ARP() to_victim.psrc = gateway_ip to_victim.pdst = victim_ip send(to_victim, verbose=0) send(to_gateway, verbose=0) time.sleep(5)
def get_l_gateway_mac(iface): command = '/usr/bin/arping -c 1 -I ' + iface + ' ' + get_l_gateway_ip(iface) p, r, output, e = execute(command) if output is not None: mac_address = re.findall(r'(\[.*\])', output)[0].replace('[', '').replace(']', '') return mac_address else: return False
def wep_run(self): execute('rm -rf replay_arp*.cap') self.wep_inject() dump_cmd = ['airodump-ng', '-c', self.channel, '--bssid', self.bssid, '-w', './log/' + self.bssid, self.iface] airodump_proc = Popen(dump_cmd, stdout=DN, stderr=DN) self.proc_list.append(airodump_proc) self.wep_fake_auth() self.wep_arp_send() crack_iv = 5000 while self.key == '': key_reader = csv.reader(open('./log/'+self.bssid+'-01.csv')) line = list(key_reader) try: self.ivs = int(line[2][10]) if self.ivs > crack_iv: execute('rm ./log/'+self.bssid+'.key') crack_cmd = ['aircrack-ng', '-b', self.bssid, './log/' + self.bssid + '-01.cap', '-l', './log/' + self.bssid + '.key'] crack_proc = Popen(crack_cmd, stdout=DN, stderr=DN) self.proc_list.append(crack_proc) kill_proc = lambda p: p.kill() timer = Timer(20, kill_proc, [crack_proc]) try: timer.start() crack_proc.communicate() finally: timer.cancel() try: f = open('./log/' + self.bssid + '.key') key = f.read() f.close() self.key = str(key.decode('hex')) self.crack_success = True airodump_proc.kill() airodump_proc.communicate() self.stop() except IOError: crack_iv = crack_iv + 5000 time.sleep(5) except: pass return self.key
def _execute(self, args, coffeescript='', cwd=None): path = self._get_path() self.path = path # FIXME: Side effect... required by exceptions raised from derived classes. try: javascript, error = execute(args=args, message=coffeescript, path=path, cwd=cwd) if error: raise CoffeeCompilationUnknownError(path, error) return javascript except OSError as e: raise CoffeeCompilationOSError(self.path, e)
def zpool(cmd, *args): """ foo Inputs: Outputs: """ retcode, output = execute(" ".join([ZPOOL, cmd, " ".join[args]])) return retcode, output
def auto_monitor(): ''' @brief Check monitor mode support. and set. ''' stop_monitor() disable_wlan_interface() # Get Wireless Interface p, r, out, err = execute('iw dev| grep phy') interface_list = out.replace('#','').split('\n') interface_list.pop() print "[*] Check Monitor mode...." isAPSupport = False isMonSupport = False if not interface_list: print "\nCouldn't find Wireless device" return False interface = None for intf in interface_list: if is_fit_in(intf): interface = intf break if interface == None: print '\n' print '[!!] Could not find the device to support the required mode.' print '[!!] Please check that the WLAN device that supports monitor mode on your system.' return False # Make Interface at monitor mode print "[*] Set Monitor mode...." for dev in _dev_name_list: execute('iw phy ' + interface + ' interface add '+ dev +' type monitor') time.sleep(0.5) if set_monitor_mode(dev) == False: # if Fail to Set up Monitor mode print '[!!] It failed to change the mode of the wireless LAN device.' print '[!!] Please try again later.' return False execute('rfkill unblock wlan') return True
def get_remote_mac(iface, ipaddr): command = '/usr/bin/arping -c 1 -I ' + iface + ' ' + ipaddr p, r, output, e = execute(command) if output is not None: try: mac_address = re.findall(r'(\[.*\])', output)[0].replace('[', '').replace(']', '') return mac_address except IndexError: return False else: return False
#!/usr/bin/python import tokengenerator import grammar import execute filename = input("Enter Filename: ") tokengenerator.tokengenerator(filename) print("\n\nCHECK GRAMMAR\n\n") grammar.addGrammars() ret = grammar.checkGrammar("START", 0) if len(ret.grammar) > 0: print("GRAMMAR CONSTRUCTION") for gram in ret.grammar: print(gram.grammar + "-> " + gram.token + " " + str(gram.type)) if len(ret.error_messages) > 0: print("ERROR MESSAGES") for message in ret.error_messages: print(message) print("\n\nCONSOLE INPUT") execute.execute(ret.grammar)
def _enable_pwd(self, child, keys, devices): pwd = None if not devices[keys]['port'] == 'zebra': child.sendcontrol('m') # time.sleep(10) child.sendcontrol('m') hostname = devices[keys]['Hostname'] clear_buffer.flushBuffer(1, child) child.sendcontrol('m') child.sendcontrol('m') child.sendcontrol('m') flag = child.expect('R*#', 'Password*', pexpect.EOF, pexpect.TIMEOUT, timeout=80) # print flag if flag == 0: # print 'Hostname set' flag = 2 # if flag == 1: # print 'Hostname set' if flag == 2: child.sendcontrol('m') child.send('enable') child.sendcontrol('m') child.sendcontrol('m') # pwd = child.expect(['Password',pexpect.EOF,pexpect.TIMEOUT],timeout=50) if pwd != 0: # print 'Setting the password and hostname' configs = """ configure terminal hostname %s enable password %s exit exit """ % (hostname, devices[keys]['pwd']) commands = configs.split('\n') execute.execute(child, commands) child.sendcontrol('m') child.sendcontrol('m') # time.sleep(10) # print "Hostname and Password set for %s" % keys if pwd == 0: child.send('\n') child.sendcontrol('m') # print "Password already set" child.sendcontrol('m') child.sendcontrol('m') child.sendcontrol('m') else: child.send('zebra') child.sendcontrol('m') flag = child.expect(['R*>', pexpect.EOF, pexpect.TIMEOUT], timeout=50) if flag == 0: child.send('enable') child.sendcontrol('m') flag = child.expect( ['Password*', pexpect.EOF, pexpect.TIMEOUT], timeout=50) if flag == 0: child.send('zebra') child.sendcontrol('m') child.sendcontrol('m') flag = child.expect(['R*#', pexpect.EOF, pexpect.TIMEOUT], timeout=50) if flag == 0: child.send('show ip route') child.sendcontrol('m')
def restartNBD(self): execute("/etc/init.d/nbd-server restart", "True")
if __name__ == '__main__': import sys if len(sys.argv) > 1: filename = sys.argv[1] f = open(filename) else: f = sys.stdin parser = SingleInputParser() find_keywords(parser) # init lexer while True: line = f.readline() if line == '': break if line == '\n': continue print ">", line, try: OLED.printToOLED(line) #for when I don't want to speak ast = parse(parser, scan(line)) printAST(ast) execute.execute(ast, f == sys.stdin) OLED.printStatus(execute.outputstring) except GrammaticalError as e: print("Error:", e) if f != sys.stdin: f.close() print 'ok'
def test_one(cmdline): print("Testing: %s ..." % cmdline, end=' ') sys.stdout.flush() execute(cmdline) print("OK")
def deploy(self, cr, uid, vals, context={}): context.update({'saas-self': self, 'saas-cr': cr, 'saas-uid': uid}) self.purge(cr, uid, vals, context=context) ssh, sftp = execute.connect(vals['server_domain'], vals['server_ssh_port'], 'root', context) cmd = ['sudo', 'docker', 'run', '-d'] nextport = vals['server_start_port'] for key, port in vals['container_ports'].iteritems(): if not port['hostport']: while not port[ 'hostport'] and nextport != vals['server_end_port']: port_ids = self.pool.get('saas.container.port').search( cr, uid, [('hostport', '=', nextport), ('container_id.server_id', '=', vals['server_id'])], context=context) if not port_ids and not execute.execute( ssh, ['netstat', '-an', '|', 'grep', str(nextport)], context): self.pool.get('saas.container.port').write( cr, uid, [port['id']], {'hostport': nextport}, context=context) port['hostport'] = nextport if port['name'] == 'ssh': vals['container_ssh_port'] = nextport nextport += 1 _logger.info('nextport %s', nextport) _logger.info('server_id %s, hostport %s, localport %s', vals['server_ip'], port['hostport'], port['localport']) udp = '' if port['udp']: udp = '/udp' cmd.extend([ '-p', vals['server_ip'] + ':' + str(port['hostport']) + ':' + port['localport'] + udp ]) for key, volume in vals['container_volumes'].iteritems(): if volume['hostpath']: arg = volume['hostpath'] + ':' + volume['name'] if volume['readonly']: arg += ':ro' cmd.extend(['-v', arg]) for key, link in vals['container_links'].iteritems(): if link['make_link'] and link['target']['link_server_id'] == vals[ 'server_id']: cmd.extend([ '--link', link['target']['link_name'] + ':' + link['code'] ]) if vals['container_privileged']: cmd.extend(['--privileged']) cmd.extend([ '-v', '/opt/keys/' + vals['container_fullname'] + ':/opt/keys', '--name', vals['container_name'], vals['image_version_fullname'] ]) #Deploy key now, otherwise the container will be angry to not find the key. We can't before because vals['container_ssh_port'] may not be set self.deploy_key(cr, uid, vals, context=context) #Run container execute.execute(ssh, cmd, context) time.sleep(3) self.deploy_post(cr, uid, vals, context) self.start(cr, uid, vals, context=context) ssh.close() sftp.close() for key, links in vals['container_links'].iteritems(): if links['name'] == 'postfix': ssh, sftp = execute.connect(vals['container_fullname'], context=context) execute.execute(ssh, [ 'echo "root=' + vals['config_email_sysadmin'] + '" > /etc/ssmtp/ssmtp.conf' ], context) execute.execute( ssh, ['echo "mailhub=postfix:25" >> /etc/ssmtp/ssmtp.conf'], context) execute.execute(ssh, [ 'echo "rewriteDomain=' + vals['container_fullname'] + '" >> /etc/ssmtp/ssmtp.conf' ], context) execute.execute(ssh, [ 'echo "hostname=' + vals['container_fullname'] + '" >> /etc/ssmtp/ssmtp.conf' ], context) execute.execute( ssh, ['echo "FromLineOverride=YES" >> /etc/ssmtp/ssmtp.conf'], context) ssh.close() sftp.close() #For shinken self.save(cr, uid, [vals['container_id']], context=context) return
def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(910, 612) #----------------------------------------- MainWindow.setWindowOpacity(1.0) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setEnabled(True) self.centralwidget.setObjectName("centralwidget") self.gridLayout = QtWidgets.QGridLayout(self.centralwidget) self.gridLayout.setObjectName("gridLayout") self.horizontalLayout_3 = QtWidgets.QHBoxLayout() self.horizontalLayout_3.setSizeConstraint( QtWidgets.QLayout.SetFixedSize) self.horizontalLayout_3.setContentsMargins(-1, -1, 0, -1) self.horizontalLayout_3.setSpacing(0) self.horizontalLayout_3.setObjectName("horizontalLayout_3") self.run = QtWidgets.QPushButton(self.centralwidget) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.run.sizePolicy().hasHeightForWidth()) self.run.setSizePolicy(sizePolicy) self.run.setObjectName("run") self.horizontalLayout_3.addWidget(self.run) self.step = QtWidgets.QPushButton(self.centralwidget) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.step.sizePolicy().hasHeightForWidth()) self.step.setSizePolicy(sizePolicy) self.step.setObjectName("step") self.horizontalLayout_3.addWidget(self.step) self.reset = QtWidgets.QPushButton(self.centralwidget) self.reset.setEnabled(True) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.reset.sizePolicy().hasHeightForWidth()) self.reset.setSizePolicy(sizePolicy) self.reset.setObjectName("reset") self.horizontalLayout_3.addWidget(self.reset) self.gridLayout.addLayout(self.horizontalLayout_3, 5, 2, 1, 2) self.tabWidget = QtWidgets.QTabWidget(self.centralwidget) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.tabWidget.sizePolicy().hasHeightForWidth()) self.tabWidget.setSizePolicy(sizePolicy) self.tabWidget.setMinimumSize(QtCore.QSize( 378, 0)) #------------------------------------ self.tabWidget.setTabPosition(QtWidgets.QTabWidget.North) self.tabWidget.setTabShape(QtWidgets.QTabWidget.Rounded) self.tabWidget.setIconSize(QtCore.QSize(16, 16)) self.tabWidget.setElideMode(QtCore.Qt.ElideNone) self.tabWidget.setUsesScrollButtons(True) self.tabWidget.setDocumentMode(False) self.tabWidget.setTabsClosable(False) self.tabWidget.setMovable(True) self.tabWidget.setObjectName("tabWidget") self.tab = QtWidgets.QWidget() self.tab.setObjectName("tab") self.verticalLayout = QtWidgets.QVBoxLayout(self.tab) self.verticalLayout.setObjectName("verticalLayout") self.tableView = QtWidgets.QTableView(self.tab) self.tableView.setObjectName("tableView") self.verticalLayout.addWidget(self.tableView) self.tabWidget.addTab(self.tab, "") self.tab_2 = QtWidgets.QWidget() self.tab_2.setObjectName("tab_2") self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.tab_2) self.verticalLayout_2.setObjectName("verticalLayout_2") self.tableView_2 = QtWidgets.QTableView(self.tab_2) self.tableView_2.setObjectName("tableView_2") self.tableView_2.resizeColumnsToContents() self.verticalLayout_2.addWidget(self.tableView_2) self.tabWidget.addTab(self.tab_2, "") self.gridLayout.addWidget(self.tabWidget, 1, 8, 2, 1) self.plainTextEdit_as = QtWidgets.QPlainTextEdit(self.centralwidget) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.plainTextEdit_as.sizePolicy().hasHeightForWidth()) self.plainTextEdit_as.setSizePolicy(sizePolicy) self.plainTextEdit_as.viewport().setProperty( "cursor", QtGui.QCursor(QtCore.Qt.IBeamCursor)) self.plainTextEdit_as.setHorizontalScrollBarPolicy( QtCore.Qt.ScrollBarAsNeeded) self.plainTextEdit_as.setLineWrapMode(QtWidgets.QPlainTextEdit.NoWrap) self.plainTextEdit_as.setPlainText("") self.plainTextEdit_as.setObjectName("plainTextEdit_as") self.highlight = syntax.AssemblyHighlighter( self.plainTextEdit_as.document()) #----------- MainWindow.setStyleSheet( '''QPlainTextEdit{font-size: 20px;font-weight: 400;}''' ) #----------- self.gridLayout.addWidget(self.plainTextEdit_as, 2, 2, 1, 1) self.plainTextEdit_mc = QtWidgets.QPlainTextEdit(self.centralwidget) self.plainTextEdit_mc.setObjectName("plainTextEdit_mc") self.gridLayout.addWidget(self.plainTextEdit_mc, 2, 3, 1, 1) self.horizontalLayout = QtWidgets.QHBoxLayout() self.horizontalLayout.setObjectName("horizontalLayout") self.comboBox = QtWidgets.QComboBox(self.centralwidget) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.comboBox.sizePolicy().hasHeightForWidth()) self.comboBox.setSizePolicy(sizePolicy) self.comboBox.setLayoutDirection(QtCore.Qt.LeftToRight) self.comboBox.setObjectName("comboBox") self.comboBox.addItem("") self.comboBox.addItem("") self.horizontalLayout.addWidget(self.comboBox) self.gridLayout.addLayout(self.horizontalLayout, 5, 8, 1, 1) self.horizontalLayout_2 = QtWidgets.QHBoxLayout() self.horizontalLayout_2.setObjectName("horizontalLayout_2") self.label = QtWidgets.QLabel(self.centralwidget) font = QtGui.QFont() font.setFamily("MS Reference Sans Serif") font.setPointSize(8) font.setBold(True) font.setItalic(False) font.setWeight(75) self.label.setFont(font) self.label.setAutoFillBackground(False) self.label.setFrameShape(QtWidgets.QFrame.StyledPanel) self.label.setFrameShadow(QtWidgets.QFrame.Sunken) self.label.setLineWidth(1) self.label.setMidLineWidth(0) self.label.setIndent(5) self.label.setObjectName("label") self.horizontalLayout_2.addWidget(self.label) self.as_assemble = QtWidgets.QPushButton(self.centralwidget) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.as_assemble.sizePolicy().hasHeightForWidth()) self.as_assemble.setSizePolicy(sizePolicy) self.as_assemble.setObjectName("as_assemble") self.horizontalLayout_2.addWidget(self.as_assemble) self.gridLayout.addLayout(self.horizontalLayout_2, 1, 2, 1, 1) self.horizontalLayout_4 = QtWidgets.QHBoxLayout() self.horizontalLayout_4.setObjectName("horizontalLayout_4") self.label_2 = QtWidgets.QLabel(self.centralwidget) font = QtGui.QFont() font.setFamily("MS Reference Sans Serif") font.setBold(True) font.setWeight(75) self.label_2.setFont(font) self.label_2.setFrameShape(QtWidgets.QFrame.StyledPanel) self.label_2.setFrameShadow(QtWidgets.QFrame.Raised) self.label_2.setObjectName("label_2") self.horizontalLayout_4.addWidget(self.label_2) self.mc_assemble = QtWidgets.QPushButton(self.centralwidget) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.mc_assemble.sizePolicy().hasHeightForWidth()) self.mc_assemble.setSizePolicy(sizePolicy) self.mc_assemble.setObjectName("mc_assemble") self.horizontalLayout_4.addWidget(self.mc_assemble) self.gridLayout.addLayout(self.horizontalLayout_4, 1, 3, 1, 1) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 910, 17)) self.menubar.setObjectName("menubar") self.menuFIle = QtWidgets.QMenu(self.menubar) self.menuFIle.setObjectName("menuFIle") self.menuAbout = QtWidgets.QMenu(self.menubar) self.menuAbout.setObjectName("menuAbout") MainWindow.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(MainWindow) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.statusbar.sizePolicy().hasHeightForWidth()) self.statusbar.setSizePolicy(sizePolicy) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.actionExit = QtWidgets.QAction(MainWindow) self.actionExit.setObjectName("actionExit") self.actionEixt = QtWidgets.QAction(MainWindow) self.actionEixt.setObjectName("actionEixt") self.actionHelp = QtWidgets.QAction(MainWindow) self.actionHelp.setObjectName("actionHelp") self.menuFIle.addAction(self.actionExit) self.menuFIle.addAction(self.actionEixt) self.menuAbout.addAction(self.actionHelp) self.menubar.addAction(self.menuFIle.menuAction()) self.menubar.addAction(self.menuAbout.menuAction()) self.retranslateUi(MainWindow) self.tabWidget.setCurrentIndex(0) QtCore.QMetaObject.connectSlotsByName(MainWindow) #populate self.comboIndex = 0 self.pc_temp = 0 self.Execute = execute() self.populate() self.run.clicked.connect(self.Run) self.as_assemble.clicked.connect(self.assemble_as) self.mc_assemble.clicked.connect(self.assemble_mc) self.reset.clicked.connect(self.assemble_mc) self.comboBox.currentIndexChanged.connect(self.on_combobox_changed) self.step.clicked.connect(self.Step) '''self.plainTextEdit_mc.setStyleSheet(
def w_interface_down(): p, retval, out, err = execute('iw dev |grep Interface') intf_list = out.replace('\tInterface', '').split() for interface in intf_list: execute('ifconfig ' + interface + ' down')
def stop_monitor(): ''' @brief Delete wlan device. ''' for dev in _dev_name_list: execute('iw dev ' + dev + ' del > /dev/null 2>&1')
def disable_wlan_interface(): p, r, o, e = execute("iwconfig |grep wlan |awk '{print $1}'") intf_list = o.split('\n') for intf in intf_list: execute("ifconfig %s down" % (intf))
def set_new_connection(essid, channel, pw, iface, enc_type): ''' @brief This function is a part that connects to the AP in pentest module. The connection method varies depending on the protocol used. Use the iw dev utility to verify that connection. ''' p, r, o, e = execute("ps -ef |grep dhcpcd-bin") if o: ol = o.split('\n') for out1 in ol: if out1.find(iface) != -1: if out1.split()[1].isdigit(): os.kill(int(out1.split()[1]), signal.SIGKILL) print out1.split()[1] p, r, o, e = execute("ps -ef |grep dhclient") if o: ol = o.split('\n') for out1 in ol: if out1.find(iface) != -1: if out1.split()[1].isdigit(): os.kill(int(out1.split()[1]), signal.SIGKILL) print out1.split()[1] p, r, o, e = execute("ps -ef |grep wpa_supplicant") if o: ol = o.split('\n') for out1 in ol: if out1.find(iface) != -1: if out1.split()[1].isdigit(): os.kill(int(out1.split()[1]), signal.SIGKILL) print out1.split()[1] execute('ifconfig ' + iface + ' down') execute('iwconfig ' + iface + ' mode managed') time.sleep(1) if "WEP" in enc_type.upper(): # If AP is encrypted with WEP, connect using the 'iwconfig' utility. execute('iwconfig ' + iface + ' essid ' + essid) execute('iwconfig ' + iface + ' key s:' + '\'' + pw + '\'') time.sleep(1) execute('ifconfig ' + iface + ' up') time.sleep(3) link = commands.getoutput('iw dev ' + iface + ' link') if 'Not connected.' in link: # verify return False p, r, out, err = execute('dhclient ' + iface) return True elif "WPA" in enc_type.upper(): # If AP is encrypted with WPA, connect using the 'wpa_supplicant' utility. execute('iwconfig ' + iface + ' essid ' + essid) proc = Popen('/usr/bin/wpa_passphrase '+essid+' > /etc/wpa_supplicant/wpa_supplicant.conf',\ shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE) proc.stdin.write(pw) execute('/sbin/wpa_supplicant -i ' + iface + ' -B -c /etc/wpa_supplicant/wpa_supplicant.conf') time.sleep(3) link = commands.getoutput('iw dev ' + iface + ' link') if 'Not connected.' in link: # verify return False p, r, out, err = execute('dhcpcd ' + iface + ' -t 10') # wait 10 seconds # Sometime dhcpcd occur the error and set invalid IP address. if "timed out" in err: for i in range(0, 5): # retry count 5 execute('dhcpcd -k ' + iface) execute('killall wpa_supplicant') time.sleep(1) execute('/sbin/wpa_supplicant -i ' + iface + ' -B -c /etc/wpa_supplicant/wpa_supplicant.conf') time.sleep(1) p, r, out, err = execute('dhcpcd ' + iface + ' -t 10') # wait 10 seconds if "timed out" not in err: # quit loop break elif i == 4: # 4 is last chance return False return True elif "OPN" in enc_type.upper(): # If AP is encrypted with WPA, connect using the 'iw' utility. execute('ifconfig ' + iface + ' up') execute('iw dev ' + iface + ' connect ' + essid) time.sleep(1) if commands.getoutput('iw dev ' + iface + ' link') is 'Not connected.': # verify return False execute('dhclient ' + iface) return True
def get_l_gateway_ip(iface): command = "route |grep " + iface + "| grep default | awk -F' ' '{print $2}'" p, ret, out, err = execute(command) gw_address = out.replace('\n', '') return gw_address
def Configure_ospf(self, Device, process_id, Networks_connected, Area, Action): device_data = getdata.get_data() hostname = device_data['Device_Details'][Device]['Hostname'] Dev = Devices.Devices() child = Dev.connect(Device) if (child): clear_buffer.flushBuffer(10, child) child.sendcontrol('m') child.sendcontrol('m') child.sendcontrol('m') #time.sleep(20) flag = child.expect([ hostname + '>', hostname + '#', 'Router\>', 'Router\#', pexpect.EOF, pexpect.TIMEOUT ], timeout=50) #print 'flag =%d' % flag if flag == 0 or flag == 2: Dev.Login(self, Device, child) if Action == 'enable': if (isinstance(Networks_connected, list)): for NID in Networks_connected: print NID configs = """ configure terminal router ospf %s network %s area %s exit exit """ % (process_id, NID, Area) commands = configs.split('\n') execute.execute(child, commands) # time.sleep(6) child.sendcontrol('m') # print "%s advertises 'I AM CONNECTED TO %s NETWORK'" % (Device,NID) # time.sleep(30) child.sendline('exit') child.sendcontrol('m') # print "OSPF enabled & neighbors set in %s" % Device else: NID = Networks_connected configs = """ configure terminal router ospf %s network %s area %s end """ % (process_id, NID, Area) commands = configs.split('\n') execute.execute(child, commands) # time.sleep(15) child.sendcontrol('m') # print '%s advertises I AM CONNECTED TO %s NETWORK' % (Device,NID) # print "OSPF enabled & neighbors set in %s" % Device else: unconfig = """ configure terminal no router ospf %s end """ % (process_id, NID, Area) commands = configs.split('\n') execute.execute(child, commands) # time.sleep(15) child.sendcontrol('m') # print "OSPF disabled and neighbors unset in %s" % Device if flag == 1 or flag == 3: if Action == 'enable': if (isinstance(Networks_connected, list)): for NID in Networks_connected: # print NID configs = """ configure terminal router ospf %s network %s area %s exit exit """ % (process_id, NID, Area) commands = configs.split('\n') execute.execute(child, commands) # time.sleep(6) child.sendcontrol('m') # print "%s advertises 'I AM CONNECTED TO %s NETWORK'" % (Device,NID) # time.sleep(30) child.sendline('exit') child.sendcontrol('m') # print "OSPF enabled & neighbors set in %s" % Device else: NID = Networks_connected configs = """ configure terminal router ospf %s network %s area %s end """ % (process_id, NID, Area) commands = configs.split('\n') execute.execute(child, commands) # time.sleep(15) child.sendcontrol('m') # print '%s advertises I AM CONNECTED TO %s NETWORK' % (Device,NID) # print "OSPF enabled & neighbors set in %s" % Device else: unconfig = """ configure terminal no router ospf %s end """ % (process_id, NID, Area) commands = configs.split('\n') execute.execute(child, commands) # time.sleep(15) child.sendcontrol('m') # print "OSPF disabled and neighbors unset in %s" % Device #else: # print 'Expected prompt not found' return True else: return False
def run_track_pattern_recognition(input_file, geo_file, dy, reconstructiblerequired, threeprong): ############################################# Load SHiP geometry ################################################### # Check geo file try: fgeo = ROOT.TFile(geo_file) except: print "An error with opening the ship geo file." raise sGeo = fgeo.FAIRGeom # Prepare ShipGeo dictionary if not fgeo.FindKey('ShipGeo'): if sGeo.GetVolume('EcalModule3') : ecalGeoFile = "ecal_ellipse6x12m2.geo" else: ecalGeoFile = "ecal_ellipse5x10m2.geo" if dy: ShipGeo = ConfigRegistry.loadpy("$FAIRSHIP/geometry/geometry_config.py", Yheight = dy, EcalGeoFile = ecalGeoFile) else: ShipGeo = ConfigRegistry.loadpy("$FAIRSHIP/geometry/geometry_config.py", EcalGeoFile = ecalGeoFile) else: upkl = Unpickler(fgeo) ShipGeo = upkl.load('ShipGeo') ############################################# Load SHiP modules #################################################### run = ROOT.FairRunSim() modules = shipDet_conf.configure(run,ShipGeo) ############################################# Load inpur data file ################################################# # Check input file try: fn = ROOT.TFile(input_file,'update') except: print "An error with opening the input data file." raise sTree = fn.cbmsim ############################## Initialize SHiP Spectrometer Tracker geometry ####################################### zlayer, \ zlayerv2, \ z34layer, \ z34layerv2, \ TStation1StartZ, \ TStation4EndZ, \ VetoStationZ, \ VetoStationEndZ = initialize(fgeo, ShipGeo) ########################################## Start Track Pattern Recognition ######################################### # Init book of hists for the quality measurements h = init_book_hist() # Start event loop nEvents = sTree.GetEntries() for iEvent in range(nEvents): if iEvent%10 == 0: print 'Event ', iEvent ########################################### Select one event ################################################### rc = sTree.GetEvent(iEvent) ########################################### Smear hits ######################################################### smeared_hits = smearHits(sTree, ShipGeo, modules, no_amb=None) if len(smeared_hits) == 0: continue ########################################### Do track pattern recognition ####################################### reco_tracks, theTracks = execute(smeared_hits, sTree, ShipGeo) ########################################### Get MC truth ####################################################### y = get_track_ids(sTree, smeared_hits) fittedtrackids, fittedtrackfrac = get_fitted_trackids(y, reco_tracks) reco_mc_tracks = getReconstructibleTracks(iEvent, sTree, sGeo, reconstructiblerequired, threeprong, TStation1StartZ, TStation4EndZ, VetoStationZ, VetoStationEndZ) # TODO:!!! ########################################### Measure quality metrics ############################################ quality_metrics(smeared_hits, sTree, reco_mc_tracks, reco_tracks, h) ############################################### Save results ####################################################### save_hists(h, 'hists.root') return
def write(self,filepath=None): if filepath is None: return str(self) #end if # get the ezfio path epath = filepath.rstrip('/') # check that write can occur if not epath.endswith('.ezfio'): self.error('cannot write input\nprovided path does not end in an ezfio directory\ndirectory must end with .ezfio\npath provided: {0}'.format(epath)) #end if path,edir = os.path.split(epath) if path=='': path = './' #end if if not os.path.exists(path): self.error('cannot write input\nattempted to write ezfio directory "{0}" at non-existent destination path\ndestination path: {1}'.format(edir,path)) #end if # if there is no ezfio directory, initialize one if not os.path.exists(epath): if self.structure is None: self.error('cannot write input\nstructure is missing\ninput path provided: {0}'.format(epath)) elif not isinstance(self.structure,Structure): self.error('cannot write input\nstructure must be of type: Structure\ntype provided: {0}\ninput path provided: {1}'.format(self.structure.__class__.__name__,epath)) #end if cwd = os.getcwd() os.chdir(path) prefix = edir.rsplit('.',1)[0] struct_file = prefix+'.xyz' self.structure.write_xyz(struct_file) command = 'qp_create_ezfio_from_xyz' if self.path_exists('ao_basis/ao_basis'): command += ' -b '+self.ao_basis.ao_basis #end if command += ' '+struct_file execute(command) if not os.path.exists(edir): self.error('cannot write input\nezfio creation command failed: {0}\nexecuted at path: {1}\ndirectory {2} not created\nplease source your quantum_package.rc file before running the current script'.format(command,path,edir)) #end if execute('qp_edit -c '+edir) os.chdir(cwd) #end if # write inputs into the ezfio directory/file tree extra = self.extract_added_keys() for secname,sec in self.iteritems(): secpath = os.path.join(epath,secname) if not os.path.exists(secpath): self.error('cannot write input\ninput section path does not exist\nsection path: {0}\nplease ensure that all variables were created previously for this ezfio directory\n(to create all variables, run "qp_edit -c {1}")'.format(secpath,edir)) #end if for varname,val in sec.iteritems(): vpath = os.path.join(secpath,varname) write_qp_value(vpath,val) #end for #end for self.restore_added_keys(extra) # take other steps that modify the input, as requested if 'run_control' in self: rc = self.run_control if 'frozen_core' in rc and rc.frozen_core: cwd = os.getcwd() os.chdir(path) execute('qp_set_frozen_core.py '+edir) os.chdir(cwd) #end if #end if return ''
''' Created on 06.12.2015. @author: xx ''' from execute import execute import os execute(os.path.split(__file__)[0], 'grammer.tx', 'test.test', True, True)
from read import read from execute import execute from write import write from scipy.stats import random_correlation if __name__ == "__main__": ### Read inputs ### # Tasks: # 1 - select your input folder # 2 - select your input file name inputFilePath = '' inputFileName = '' sheetName = 'Input' read(inputFilePath, inputFileName, sheetName) ### Execute operations ### execute() ### Write output ### # Tasks: # 1 - select your output folder # 2 - select your output file name outputFilePath = '' outputFileName = '' write(outputFilePath, outputFileName)
def deploy_files(self, cr, uid, vals, context={}): context.update({'saas-self': self, 'saas-cr': cr, 'saas-uid': uid}) base_obj = self.pool.get('saas.base') self.purge_files(cr, uid, vals, context=context) ssh, sftp = execute.connect(vals['server_domain'], vals['server_ssh_port'], 'root', context) if not execute.exist(sftp, vals['app_version_full_hostpath']): execute.execute(ssh, ['mkdir', '-p', vals['app_version_full_hostpath']], context) sftp.put(vals['app_version_full_archivepath_targz'], vals['app_version_full_hostpath'] + '.tar.gz') execute.execute(ssh, ['tar', '-xf', vals['app_version_full_hostpath'] + '.tar.gz', '-C', vals['app_version_full_hostpath']], context) execute.execute(ssh, ['rm', vals['app_full_hostpath'] + '/' + vals['app_version_name'] + '.tar.gz'], context) ssh.close() sftp.close() ssh, sftp = execute.connect(vals['container_fullname'], username=vals['apptype_system_user'], context=context) if 'files_from_service' in context: execute.execute(ssh, ['cp', '-R', vals['apptype_localpath_services'] + '/' + context['files_from_service'] + '/files', vals['service_full_localpath_files']], context) elif vals['service_custom_version'] or not vals['apptype_symlink']: execute.execute(ssh, ['cp', '-R', vals['app_version_full_localpath'], vals['service_full_localpath_files']], context) else: execute.execute(ssh, ['ln', '-s', vals['app_version_full_localpath'], vals['service_full_localpath_files']], context) service = self.browse(cr, uid, vals['service_id'], context=context) for base in service.base_ids: base_obj.save(cr, uid, [base.id], context=context) base_vals = base_obj.get_vals(cr, uid, base.id, context=context) base_obj.update_base(cr, uid, base_vals, context=context) ssh.close() sftp.close()
def deploy_key(self, cr, uid, vals, context={}): context.update({'saas-self': self, 'saas-cr': cr, 'saas-uid': uid}) # restart_required = False # try: # ssh_container, sftp_container = execute.connect(vals['container_fullname'], context=context) # except: # restart_required = True # pass self.purge_key(cr, uid, vals, context=context) execute.execute_local([ 'ssh-keygen', '-t', 'rsa', '-C', '*****@*****.**', '-f', vals['config_home_directory'] + '/.ssh/keys/' + vals['container_fullname'], '-N', '' ], context) execute.execute_write_file( vals['config_home_directory'] + '/.ssh/config', 'Host ' + vals['container_fullname'], context) execute.execute_write_file( vals['config_home_directory'] + '/.ssh/config', '\n HostName ' + vals['server_domain'], context) execute.execute_write_file( vals['config_home_directory'] + '/.ssh/config', '\n Port ' + str(vals['container_ssh_port']), context) execute.execute_write_file( vals['config_home_directory'] + '/.ssh/config', '\n User root', context) execute.execute_write_file( vals['config_home_directory'] + '/.ssh/config', '\n IdentityFile ~/.ssh/keys/' + vals['container_fullname'], context) execute.execute_write_file( vals['config_home_directory'] + '/.ssh/config', '\n#END ' + vals['container_fullname'] + '\n', context) ssh, sftp = execute.connect(vals['server_domain'], vals['server_ssh_port'], 'root', context) execute.execute(ssh, ['mkdir', '/opt/keys/' + vals['container_fullname']], context) sftp.put( vals['config_home_directory'] + '/.ssh/keys/' + vals['container_fullname'] + '.pub', '/opt/keys/' + vals['container_fullname'] + '/authorized_keys') ssh.close() sftp.close() # _logger.info('restart required %s', restart_required) # if not restart_required: # execute.execute(ssh_container, ['supervisorctl', 'restart', 'sshd'], context) # ssh_container.close() # sftp_container.close() # else: # self.start(cr, uid, vals, context=context) if vals['apptype_name'] == 'backup': shinken_ids = self.search( cr, uid, [('application_id.type_id.name', '=', 'shinken')], context=context) if not shinken_ids: execute.log( 'The shinken isnt configured in conf, skipping deploying backup keys in shinken', context) return for shinken in self.browse(cr, uid, shinken_ids, context=context): shinken_vals = self.get_vals(cr, uid, shinken.id, context=context) ssh, sftp = execute.connect(shinken_vals['container_fullname'], username='******', context=context) execute.execute(ssh, [ 'rm', '-rf', '/home/shinken/.ssh/keys/' + vals['container_fullname'] + '*' ], context) execute.send( sftp, vals['config_home_directory'] + '/.ssh/keys/' + vals['container_fullname'] + '.pub', '/home/shinken/.ssh/keys/' + vals['container_fullname'] + '.pub', context) execute.send( sftp, vals['config_home_directory'] + '/.ssh/keys/' + vals['container_fullname'], '/home/shinken/.ssh/keys/' + vals['container_fullname'], context) execute.execute(ssh, ['chmod', '-R', '700', '/home/shinken/.ssh'], context) execute.execute(ssh, [ 'sed', '-i', "'/Host " + vals['container_fullname'] + "/,/END " + vals['container_fullname'] + "/d'", '/home/shinken/.ssh/config' ], context) execute.execute(ssh, [ 'echo "Host ' + vals['container_fullname'] + '" >> /home/shinken/.ssh/config' ], context) execute.execute(ssh, [ 'echo " Hostname ' + vals['server_domain'] + '" >> /home/shinken/.ssh/config' ], context) execute.execute(ssh, [ 'echo " Port ' + str(vals['container_ssh_port']) + '" >> /home/shinken/.ssh/config' ], context) execute.execute( ssh, ['echo " User backup" >> /home/shinken/.ssh/config'], context) execute.execute(ssh, [ 'echo " IdentityFile ~/.ssh/keys/' + vals['container_fullname'] + '" >> /home/shinken/.ssh/config' ], context) execute.execute(ssh, [ 'echo "#END ' + vals['container_fullname'] + '" >> ~/.ssh/config' ], context)
def deploy(self, cr, uid, vals, context=None): container_obj = self.pool.get('saas.container') context.update({'saas-self': self, 'saas-cr': cr, 'saas-uid': uid}) self.purge(cr, uid, vals, context=context) execute.log('Creating database user', context=context) #SI postgres, create user if vals['database_type'] != 'mysql': ssh, sftp = execute.connect(vals['database_fullname'], username='******', context=context) execute.execute(ssh, ['psql', '-c', '"CREATE USER ' + vals['service_db_user'] + ' WITH PASSWORD \'' + vals['service_db_password'] + '\' CREATEDB;"'], context) ssh.close() sftp.close() ssh, sftp = execute.connect(vals['container_fullname'], username=vals['apptype_system_user'], context=context) execute.execute(ssh, ['sed', '-i', '"/:*:' + vals['service_db_user'] + ':/d" ~/.pgpass'], context) execute.execute(ssh, ['echo "' + vals['database_server'] + ':5432:*:' + vals['service_db_user'] + ':' + vals['service_db_password'] + '" >> ~/.pgpass'], context) execute.execute(ssh, ['chmod', '700', '~/.pgpass'], context) ssh.close() sftp.close() else: ssh, sftp = execute.connect(vals['database_fullname'], context=context) execute.execute(ssh, ["mysql -u root -p'" + vals['database_root_password'] + "' -se \"create user '" + vals['service_db_user'] + "' identified by '" + vals['service_db_password'] + "';\""], context) ssh.close() sftp.close() execute.log('Database user created', context) ssh, sftp = execute.connect(vals['container_fullname'], username=vals['apptype_system_user'], context=context) execute.execute(ssh, ['mkdir', '-p', vals['service_full_localpath']], context) ssh.close() sftp.close() self.deploy_files(cr, uid, vals, context=context) self.deploy_post_service(cr, uid, vals, context) container_obj.start(cr, uid, vals, context=context)
def execute(request): import execute return execute.execute(request)
def clean_one(cmdline): print("Running: %s ..." % cmdline, end=' ') sys.stdout.flush() execute(cmdline) print("OK")
def restartEXPORTS(self): execute("/etc/init.d/nfs-kernel-server restart", "True")
def Configure_EBGP(self, Device, AS_id, Interface, neighbor_AS_id, Action, NW_id, Mask): device_data = getdata.get_data() hostname = device_data['Device_Details'][Device]['Hostname'] Dev = Devices.Devices() child = Dev.connect(Device) port = device_data['Device_Details'][Device]['port'] if port != "zebra": if child: clear_buffer.flushBuffer(10, child) child.sendcontrol('m') child.sendcontrol('m') child.sendcontrol('m') flag = child.expect([hostname+'>', hostname+'#', 'Router\>', 'Router\#', \ pexpect.EOF, pexpect.TIMEOUT], timeout=90) if flag in (0, 2): Dev.Login(Device, child) if Action == 'enable': if isinstance(Interface, list): for interface in Interface: configs = """ configure terminal router bgp %d neighbor %s remote-as %d network %s mask %s exit exit """ % (AS_id, interface, neighbor_AS_id, NW_id, Mask) commands = configs.split('\n') execute.execute(child, commands) time.sleep(6) child.sendcontrol('m') child.sendline('exit') child.sendcontrol('m') else: interface = Interface configs = """ configure terminal router bgp %d neighbor %s remote-as %d network %s mask %s exit exit """ % (AS_id, interface, neighbor_AS_id, NW_id, Mask) commands = configs.split('\n') execute.execute(child, commands) child.sendcontrol('m') else: unconfig = """ configure terminal no router bgp %d exit exit """ % (AS_id) commands = unconfig.split('\n') execute.execute(child, commands) child.sendcontrol('m') if flag in (1, 3): if Action == 'enable': if isinstance(Interface, list): for interface in Interface: configs = """ configure terminal router bgp %d neighbor %s remote-as %d network %s mask %s exit exit """ % (AS_id, interface, neighbor_AS_id, NW_id, Mask) commands = configs.split('\n') execute.execute(child, commands) child.sendcontrol('m') child.sendline('exit') child.sendcontrol('m') else: interface = Interface configs = """ configure terminal router bgp %d neighbor %s remote-as %d network %s mask %s exit exit """ % (AS_id, interface, neighbor_AS_id, NW_id, Mask) commands = configs.split('\n') execute.execute(child, commands) child.sendcontrol('m') else: unconfig = """ configure terminal no router bgp %d exit exit """ % (AS_id) commands = unconfig.split('\n') execute.execute(child, commands) child.sendcontrol('m') return True elif port == 'zebra': port = "bgpd" device_data = getdata.get_data() IP_add = device_data['Device_Details'][Device]['ip_add'] child = pexpect.spawn('telnet ' + IP_add + ' ' + port) hostname = device_data['Device_Details'][Device]['Hostname'] clear_buffer.flushBuffer(10, child) child.sendcontrol('m') flag = (child.expect(['bgpd*', 'Password*', \ pexpect.EOF, pexpect.TIMEOUT], timeout=100)) if flag == 1: child.send('zebra') child.sendcontrol('m') flag = child.expect(['bgpd*>', pexpect.EOF, \ pexpect.TIMEOUT], timeout=50) if flag == 0: child.send('enable') child.sendcontrol('m') if child: flag = child.expect(['bgpd#*', pexpect.EOF, \ pexpect.TIMEOUT], timeout=90) if flag == 0: Dev.Login(Device, child) if Action == 'enable': if isinstance(Interface, list): for interface in Interface: configs = """ configure terminal router bgp %d neighbor %s remote-as %d network %s exit exit """ % (AS_id, interface, neighbor_AS_id, NW_id) commands = configs.split('\n') execute.execute(child, commands) time.sleep(6) child.sendcontrol('m') child.sendline('exit') child.sendcontrol('m') else: interface = Interface configs = """ configure terminal router bgp %d neighbor %s remote-as %d network %s exit exit """ % (AS_id, interface, neighbor_AS_id, NW_id) commands = configs.split('\n') execute.execute(child, commands) child.sendcontrol('m') else: unconfig = """ configure terminal no router bgp %d exit exit """ % (AS_id) commands = unconfig.split('\n') execute.execute(child, commands) child.sendcontrol('m') return True else: return False
find.find(search_dir, searchKey, cursor) else: print("incorrect usage of find") elif command[0] == "grep": if len(command) != 3: print("Incorrect usage") else: grep.grep(curr_dir, command[1], command[2], raw_cursor, cursor) elif command[0] == "exe": execute.execute(PATH, command[1], raw_cursor, cursor) elif command[0] == "setpath": PATH = utils.get_file_from_path(command[1], cursor) elif command[0] == "path": print(f"/{utils.get_file_path(PATH[0],cursor)}") elif command[0] == "exit": break except Error as e: print("Error while connecting to MySQL", e) except Error as e: print("Error while connecting to MySQL", e)
def redistribution_connected(self, Device, AS_id): device_data = getdata.get_data() hostname = device_data['Device_Details'][Device]['Hostname'] Dev = Devices.Devices() child = Dev.connect(Device) port = device_data['Device_Details'][Device]['port'] if port != "zebra": if child: clear_buffer.flushBuffer(10, child) child.sendcontrol('m') child.sendcontrol('m') child.sendcontrol('m') flag = child.expect([hostname+'>', hostname+'#', 'Router\>', 'Router\#', \ pexpect.EOF, pexpect.TIMEOUT], timeout=90) if flag in (0, 2): Dev.Login(Device, child) configs = """ configure terminal router bgp %d redistribute connected end """ % (AS_id) commands = configs.split('\n') execute.execute(child, commands) child.sendcontrol('m') if flag in (1, 3): configs = """ configure terminal router bgp %d redistribute connected end """ % (AS_id) commands = configs.split('\n') execute.execute(child, commands) child.sendcontrol('m') return True elif port == 'zebra': port = "bgpd" device_data = getdata.get_data() IP_add = device_data['Device_Details'][Device]['ip_add'] child = pexpect.spawn('telnet ' + IP_add + ' ' + port) hostname = device_data['Device_Details'][Device]['Hostname'] clear_buffer.flushBuffer(10, child) child.sendcontrol('m') flag = (child.expect(['bgpd*', 'Password*', pexpect.EOF,\ pexpect.TIMEOUT], timeout=100)) if flag == 1: child.send('zebra') child.sendcontrol('m') flag = child.expect(['bgpd*>', pexpect.EOF,\ pexpect.TIMEOUT], timeout=50) if flag == 0: child.send('enable') child.sendcontrol('m') if child: clear_buffer.flushBuffer(10, child) child.sendcontrol('m') child.sendcontrol('m') child.sendcontrol('m') flag = child.expect(['bgpd#*', pexpect.EOF, \ pexpect.TIMEOUT], timeout=90) if flag in (0, 2): Dev.Login(Device, child) configs = """ configure terminal router bgp %d redistribute connected end """ % (AS_id) commands = configs.split('\n') execute.execute(child, commands) child.sendcontrol('m') if flag in (1, 3): configs = """ configure terminal router bgp %d redistribute connected end """ % (AS_id) commands = configs.split('\n') execute.execute(child, commands) child.sendcontrol('m') return True else: return False
def connect_all(self, Action): device_data = getdata.get_data() devices = device_data["Device_Details"] for keys in devices.keys(): child = pexpect.spawn('telnet ' + devices[keys]['ip_add'] + ' ' + devices[keys]['port']) if not devices[keys]['port'] == 'zebra': child.sendline('\n') child.sendcontrol('m') hostname = devices[keys]['Hostname'] clear_buffer.flushBuffer(1, child) # child.send('configure terminal') child.sendcontrol('m') flag = (child.expect( ['R*#', 'Password*', pexpect.EOF, pexpect.TIMEOUT], timeout=100)) if flag == 0: # time.sleep(35) #print 'Telnet connection established with device '+keys #print 'Device %s is booting' % keys child.send('show ip route') child.sendcontrol('m') # time.sleep(15) child.sendcontrol('m') flag = 1 if (flag == 1): # time.sleep(35) #print "Device %s in user mode" % keys # child.expect(['R*#','Password*',pexpect.EOF,pexpect.TIMEOUT],timeout=40) #child.sendcontrol('m') self._enable_pwd(child, keys, devices) if flag in (2, 3): #print "Hostname and password already set" passwd = devices[keys]['pwd'] if Action == 'disable': child.sendcontrol('m') child.send('enable') child.sendcontrol('m') #child.sendcontrol('m') pwd = child.expect( ['Password*', pexpect.EOF, pexpect.TIMEOUT], timeout=50) # if pwd != 0: # print "Password already unset" if pwd == 0: # print "unset the password and hostname" child.sendline(passwd) child.sendcontrol('m') unconfig = """ configure terminal no hostname %s no enable password %s exit exit """ % (hostname, devices[keys]['pwd']) commands = unconfig.split('\n') execute.execute(child, commands) child.sendcontrol('m') child.sendcontrol('m') # time.sleep(10) # print "Hostname and Password unset for %s" % keys # else: # print " " # if flag == 3: #print 'Unable to connect to remote host %s:Connection refused' % keys #if flag == 4: # print 'Telnet connection established with device '+keys # print 'Timeout, no expected prompt found' return
def Configure_IBGP(self, Device, AS_id, Interface, Action): device_data = getdata.get_data() hostname = device_data['Device_Details'][Device]['Hostname'] Dev = Devices.Devices() child = Dev.connect(Device) if child: clear_buffer.flushBuffer(10, child) child.sendcontrol('m') child.sendcontrol('m') child.sendcontrol('m') flag = child.expect([hostname+'>', hostname+'#', 'Router\>', 'Router\#', \ pexpect.EOF, pexpect.TIMEOUT], timeout=90) if flag in (0, 2): Dev.Login(Device, child) if Action == 'enable': if isinstance(Interface, list): for interface in Interface: configs = """ configure terminal router bgp %d neighbor %s remote-as %d neighbor %s update-source loopback 0 exit exit """ % (AS_id, interface, AS_id, interface) commands = configs.split('\n') execute.execute(child, commands) time.sleep(6) child.sendcontrol('m') child.sendline('exit') child.sendcontrol('m') else: interface = Interface configs = """ configure terminal router bgp %d neighbor %s remote-as %d neighbor %s update-source loopback 0 exit exit """ % (AS_id, interface, AS_id, interface) commands = configs.split('\n') execute.execute(child, commands) child.sendcontrol('m') else: unconfig = """ configure terminal no router bgp %d exit exit """ % (AS_id) commands = configs.split('\n') execute.execute(child, commands) child.sendcontrol('m') if flag in (1, 3): if Action == 'enable': if isinstance(Interface, list): for interface in Interface: print(interface) configs = """ configure terminal router bgp %d neighbor %s remote-as %d neighbor %s update-source loopback 0 exit exit """ % (AS_id, interface, AS_id, interface) commands = configs.split('\n') execute.execute(child, commands) time.sleep(6) child.sendcontrol('m') child.sendline('exit') child.sendcontrol('m') else: interface = Interface configs = """ configure terminal router bgp %d neighbor %s remote-as %d neighbor %s update-source loopback 0 exit exit exit """ % (AS_id, interface, AS_id, interface) commands = configs.split('\n') execute.execute(child, commands) child.sendcontrol('m') else: unconfig = """ configure terminal no router bgp %d exit exit """ % (AS_id) commands = configs.split('\n') execute.execute(child, commands) child.sendcontrol('m') return True else: return False
just return silently. """ LOG.info('Merging locale={0}'.format(locale)) locale_directory = CONFIGURATION.get_messages_dir(locale) files_to_merge = ('django-partial.po', 'messages.po', 'mako.po') try: validate_files(locale_directory, files_to_merge) except Exception, e: if not fail_if_missing: return raise e # merged file is merged.po merge_cmd = 'msgcat -o merged.po ' + ' '.join(files_to_merge) execute(merge_cmd, working_directory=locale_directory) # clean up redunancies in the metadata merged_filename = locale_directory.joinpath('merged.po') clean_metadata(merged_filename) # rename merged.po -> django.po (default) django_filename = locale_directory.joinpath(target) os.rename(merged_filename, django_filename) # can't overwrite file on Windows def clean_metadata(file): """ Clean up redundancies in the metadata caused by merging. """ # Reading in the .po file and saving it again fixes redundancies.
def incorporate_result(self, result_name, result, sim): if result_name == 'charge_density': c = self.input.control res_path = os.path.abspath(result.locdir) loc_path = os.path.abspath(self.locdir) if res_path == loc_path: None # don't need to do anything if in same directory elif self.sync_from_scf: # rsync output into nscf dir outdir = os.path.join(self.locdir, c.outdir) command = 'rsync -av {0}/* {1}/'.format(result.outdir, outdir) if not os.path.exists(outdir): os.makedirs(outdir) #end if sync_record = os.path.join(outdir, 'nexus_sync_record') if not os.path.exists(sync_record): execute(command) f = open(sync_record, 'w') f.write('\n') f.close() #end if else: # attempt to use symbolic links instead link_loc = os.path.join(self.locdir, c.outdir, c.prefix + '.save') cd_loc = result.location cd_rel = os.path.relpath(cd_loc, link_loc) sp_loc = result.spin_location sp_rel = os.path.relpath(sp_loc, link_loc) cwd = os.getcwd() if not os.path.exists(link_loc): os.makedirs(link_loc) #end if os.chdir(link_loc) os.system('ln -s ' + cd_rel + ' charge-density.dat') os.system('ln -s ' + sp_rel + ' spin-polarization.dat') os.chdir(cwd) #end if elif result_name == 'structure': relstruct = result.structure.copy() relstruct.change_units('B') self.system.structure = relstruct self.system.remove_folded() #structure = self.system.structure #structure.change_units('B') #structure.set( # pos = relstruct.positions, # atoms = relstruct.atoms # ) input = self.input preserve_kp = 'k_points' in input and 'specifier' in input.k_points and ( input.k_points.specifier == 'automatic' or input.k_points.specifier == 'gamma') if preserve_kp: kp = input.k_points.copy() #end if input.incorporate_system(self.system) if preserve_kp: input.k_points = kp #end if else: self.error('ability to incorporate result ' + result_name + ' has not been implemented')