Changeset 2516
- Timestamp:
- Sep 27, 2016, 1:07:19 PM (4 years ago)
- Location:
- lliurex-mirror/trunk/fuentes
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
lliurex-mirror/trunk/fuentes/admin-center-lliurex-mirror.install/lliurex-mirror/src/js/lliurex-mirror.js
r2482 r2516 330 330 var n4dclass="MirrorManager"; 331 331 var n4dmethod="update"; 332 var arglist=[ self.activedistro];332 var arglist=['',self.activedistro,null]; 333 333 334 334 Utils.n4d(credentials, n4dclass, n4dmethod, arglist, function updatemirror(response){ -
lliurex-mirror/trunk/fuentes/debian/control
r2405 r2516 11 11 Depends: ${misc:Depends}, python, python-clint 12 12 Provides: lliurex-mirror-core 13 Conflicts: lliurex-mirror-core 14 Replaces: lliurex-mirror-core 13 Conflicts: lliurex-mirror-core (<< 2.0) 14 Replaces: lliurex-mirror-core (<< 2.0) 15 15 Description: LliureX Mirror Cli 16 16 lliurex-mirror-cli provice command line to execute lliurex-mirror functions … … 19 19 Architecture: all 20 20 Depends: ${misc:Depends}, n4d, python-llxvars, python-jinja2, debmirror, apache2, python-pexpect 21 Provides: lliurex-mirror-n4d-server , lliurex-mirror-core22 Conflicts: lliurex-mirror-n4d-server, lliurex-mirror-core 23 Replaces: lliurex-mirror-n4d-server, lliurex-mirror-core 21 Provides: lliurex-mirror-n4d-server 22 Conflicts: lliurex-mirror-n4d-server, lliurex-mirror-core (<< 2.0) 23 Replaces: lliurex-mirror-n4d-server, lliurex-mirror-core (<< 2.0) 24 24 Description: LliureX Mirror - N4D plugin 25 25 n4d-lliurex-mirror provides a n4d plugin -
lliurex-mirror/trunk/fuentes/lliurex-mirror-cli/usr/bin/lliurex-mirror
r2482 r2516 21 21 22 22 def runDebmirror(self,distro): 23 result = self.client.update(self.credentials,"MirrorManager", distro)23 result = self.client.update(self.credentials,"MirrorManager",'',distro,None) 24 24 print result['msg'] 25 25 sys.exit( 0 if result['status'] else 1 ) … … 71 71 sys.exit( 0 if result['status'] else 1 ) 72 72 73 def stopWebserver(self ):74 result = self.client.stop_webserver(self.credentials,"MirrorManager" )73 def stopWebserver(self,port): 74 result = self.client.stop_webserver(self.credentials,"MirrorManager",port) 75 75 print str(result['msg']) 76 76 sys.exit( 0 if result['status'] else 1 ) … … 108 108 puts("getpercentage") 109 109 puts("enablewebserverforpath PATH") 110 puts("stopwebserver ")110 puts("stopwebserver PORT") 111 111 puts("stopupdate") 112 112 puts("getavailabledistros") … … 206 206 lliurexmirror.enableWebserverForPath(args.get(0)) 207 207 elif action == "stopwebserver": 208 lliurexmirror.stopWebserver( )208 lliurexmirror.stopWebserver(args.get(0)) 209 209 elif action == "getavailabledistros": 210 210 lliurexmirror.getAvailableDistros() -
lliurex-mirror/trunk/fuentes/lliurex-mirror-gui/lliurex_mirror_connect.py
r2510 r2516 11 11 self.credentials = credentials 12 12 self.localcredentials = self.get_local_credentials() 13 self.localport = None 14 self.remoteport = None 13 15 #def __init__ 14 16 … … 43 45 44 46 def mirror_list(self): 45 if type(self.client) == None:47 if type(self.client) == type(None): 46 48 return {} 47 49 result = self.client.get_all_configs(self.credentials,'MirrorManager') … … 64 66 65 67 def create_conf(self,config): 66 if type(self.client) == None: 68 print config 69 if type(self.client) == type(None): 67 70 return {} 68 71 result = self.client.new_mirror_config(self.credentials,'MirrorManager',config) 72 print 2 69 73 if result['status']: 70 74 return result['msg'] … … 78 82 ''' 79 83 self.mode = None 84 self.localport = None 85 callback_args = None 80 86 if mode == '2': 81 87 self.mode = 2 82 88 result = self.client.get_client_ip('','MirrorManager','') 83 print result84 89 tempserver = result['msg'] 85 90 result = self.localclient.enable_webserver_into_folder(self.localcredentials,'MirrorManager',data) 86 tempserver = str(tempserver) + ":" + str(result['msg']) 91 print result 92 tempserver = tempserver + ":" + str(result['msg']) 87 93 data = tempserver 88 print data 89 self.localclient.watch_update_finish(self.localcredentials,'MirrorManager',self.credentials,self.serverip) 94 callback_args = {} 95 callback_args['port'] = str(result['msg']) 96 self.localport = str(result['msg']) 90 97 if data != None: 91 98 self.client.set_mirror_orig(self.credentials,'MirrorManager',mirror,data,mode) 92 99 self.client.set_option_update(self.credentials,'MirrorManager',mirror,mode) 93 result = self.client.update(self.credentials,'MirrorManager', mirror)100 result = self.client.update(self.credentials,'MirrorManager','',mirror,callback_args) 94 101 return result['status'] 95 102 #def update … … 101 108 result = self.client.get_all_configs(self.credentials,'MirrorManager') 102 109 config = result['msg'][mirror] 103 110 result = self.client.get_client_ip('','MirrorManager','') 111 ip = result['msg'] 104 112 # Open webserver for mirror and get ip 105 113 result = self.client.enable_webserver_into_folder(self.credentials,'MirrorManager',config['MIRROR_PATH']) 106 114 port = str(result['msg']) 115 self.remoteport = port 107 116 # Modify Config and write 108 117 109 118 config['MIRROR_PATH'] = folder 110 config[ ] = '3'111 config['ORIGS']['3'] = self.serverip + ":" + str( result['msg'])119 config['CURRENT_UPDATE_OPTION'] = '3' 120 config['ORIGS']['3'] = self.serverip + ":" + str(port) 112 121 result = self.client.render_debmirror_config(self.credentials,'MirrorManager',config) 113 122 temp_file = tempfile.mktemp() … … 115 124 f.write(result['msg']) 116 125 f.close() 117 126 callback_args = {} 127 callback_args['ip'] = ip 128 callback_args['port'] = port 118 129 # Execute mirror 119 self.localclient.get_mirror(self.localcredentials,'MirrorManager',temp_file)130 print self.localclient.get_mirror(self.localcredentials,'MirrorManager',temp_file,callback_args) 120 131 return True 121 132 #def export … … 145 156 def stop_update(self): 146 157 if self.mode == '2': 147 self. client.stop_webserver(self.credentials,'MirrorManager')158 self.localclient.stop_webserver(self.credentials,'MirrorManager',self.localport) 148 159 result = self.client.stopupdate(self.credentials,'MirrorManager') 160 return result['status'] 161 #def stop_update 162 163 def stop_export(self): 164 self.client.stop_webserver(self.credentials,'MirrorManager',self.remoteport) 165 result = self.localclient.stopgetmirror(self.credentials,'MirrorManager') 149 166 return result['status'] 150 167 #def stop_update … … 153 170 if __name__ == '__main__': 154 171 c = LliurexMirrorN4d('localhost',['kbut','lliurex']) 155 config = {'IGN_GPG': 1, 'NAME': 'LliureX Xenial', 'ORIGS': {'1': 'lliurex.net/xenial', '3': '172.20.8.6/mirror/lliurex', '2': ''}, 'SECTIONS': ['main', 'main/debian-installer', 'universe', 'restricted', 'multiverse', 'partner'], 'MIRROR_PATH': '/net/mirror/llx16', 'ARCHITECTURES': ['amd64', 'i386'], 'CHK_MD5': 0, 'IGN_RELEASE': 0, 'BANNER': '', 'CURRENT_UPDATE_OPTION': '3', 'DISTROS': ['xenial', 'xenial-updates', 'xenial-security']} 156 #print c.save_config('llx16',config) 157 #print c.update('llx16','3','172.20.8.6/mirror/lliurex') 158 #print c.update('llx16','2','/net/mirror/lugar') 159 #print c.update('llx16','3') 172 config = {'IGN_GPG': 1, 'NAME': 'Mi ppa', 'ORIGS': {'1': 'ppa.launchpad.net/llxdev/xenial/ubuntu', '3': '172.20.8.6/mirror/ppa-xenial/', '2': '/home/kbut/miMirrorPortatil'}, 'SECTIONS': ['main', 'universe', 'restricted', 'multiverse'], 'MIRROR_PATH': '/home/mirror-ppa', 'ARCHITECTURES': ['amd64', 'i386'], 'CHK_MD5': 0, 'IGN_RELEASE': 0, 'BANNER': '', 'CURRENT_UPDATE_OPTION': '1', 'DISTROS': ['xenial']} 173 #print c.save_config('mippa',config) 174 #print c.create_conf(config) 175 #print c.update('mippa','3','172.20.8.6/mirror/ppa-xenial') 176 #print c.update('mippa','2','/home/mirror-ppa-otracarpeta') 177 #print c.update('mippa','1') 160 178 #print c.mirror_list() 161 print c.export('llx16','/net/miexportacion') 162 #print c.is_alive_export() 163 #print c.get_percentage('llx16') 179 #print c.export('mippa','/home/mirror16') 180 print c.is_alive_export() 181 print c.get_percentage_export() 182 #print c.get_percentage('mippa') 164 183 #print c.is_alive() 165 #print c.stop_update()184 print c.stop_export() -
lliurex-mirror/trunk/fuentes/n4d-lliurex-mirror.install/etc/n4d/conf.d/MirrorManager
r2509 r2516 5 5 [METHODS] 6 6 set_cname=adm,admins 7 update=adm,admins7 (ip)update=adm,admins 8 8 is_alive=adm,admins 9 9 set_mirror_info=adm,admins … … 18 18 render_debmirror_config=adm,admins 19 19 enable_webserver_into_folder=adm,admins 20 stop_webserver=a dm,admins20 stop_webserver=anonymous,* 21 21 set_checksum_validation=adm,admins 22 22 get_checksum_validation=anonymous,* … … 30 30 update_mirror_config=adm,admins 31 31 (ip)get_client_ip=anonymous,* 32 watch_update_finish=adm,admins33 32 is_alive_get_mirror=anonymous,* 34 33 get_mirror=adm,admins 34 stopgetmirror=adm,admins -
lliurex-mirror/trunk/fuentes/n4d-lliurex-mirror.install/usr/share/n4d/python-plugins/MirrorManager.py
r2510 r2516 17 17 import socket 18 18 from urllib2 import urlopen 19 19 import string 20 20 21 21 class MirrorManager: … … 28 28 self.configpath = os.path.join(self.defaultpath,'conf') 29 29 self.distro="llx16" 30 self.httpd = None30 self.httpd = {} 31 31 self.debmirrorprocess = None 32 32 … … 37 37 self.exportpercentage = 0 38 38 self.mirrorworking = None 39 self.webserverprocess = None39 self.webserverprocess = {} 40 40 self.defaultmirrorinfo = {"status_mirror":"New","last_mirror_date":None,"mirror_size":0,"progress":0} 41 self.valid_chars = "-_.%s%s" % (string.ascii_letters, string.digits) 41 42 self.default_mirror_config = ''' 42 43 { … … 131 132 #def set_cname 132 133 133 def update(self, distro=None):134 def update(self,ip,distro=None,callback_args=None): 134 135 135 136 if distro==None: … … 140 141 141 142 self.percentage=(0,None) 142 self.update_thread=threading.Thread(target=self._update,args=( distro,))143 self.update_thread=threading.Thread(target=self._update,args=(ip,distro,callback_args,)) 143 144 self.update_thread.daemon=True 144 145 self.update_thread.start() … … 148 149 #def update 149 150 150 def _update(self, distro):151 def _update(self,ip,distro,callback_args): 151 152 if not self.variable.has_key(distro): 152 153 self.variable[distro]=self.defaultmirrorinfo … … 155 156 self.n4d_vars.set_variable("LLIUREXMIRROR",self.variable) 156 157 self.build_debmirror_config(distro) 157 if os.path. exists('/etc/debmirror.conf'):158 if os.path.lexists('/etc/debmirror.conf'): 158 159 os.remove('/etc/debmirror.conf') 159 160 os.symlink(os.path.join(self.debmirrorconfpath,distro),'/etc/debmirror.conf') … … 189 190 break 190 191 192 if type(callback_args) != type(None): 193 if callback_args.has_key('port'): 194 import xmlrpclib as x 195 c = x.ServerProxy('https://' + ip + ':9779') 196 c.stop_webserver('','MirrorManager',callback_args['port']) 197 191 198 self.download_time_file(distro) 192 193 199 self.set_mirror_info(distro) 194 200 self.mirrorworking = None … … 273 279 configpath = os.path.join(self.configpath,distro + ".json") 274 280 config = json.load(open(configpath,'r')) 275 if not os.path. exists(configpath):281 if not os.path.lexists(configpath): 276 282 return {'status':False,'msg':'not exists debmirror.conf to '+ distro } 277 283 … … 305 311 configpath = os.path.join(self.configpath,distro + ".json") 306 312 config = json.load(open(configpath,'r')) 307 if not os.path. exists(configpath):313 if not os.path.lexists(configpath): 308 314 return {'status':False,'msg':'not exists debmirror.conf to '+ distro } 309 315 … … 333 339 configpath = os.path.join(self.configpath,distro + ".json") 334 340 config = json.load(open(configpath,'r')) 335 if not os.path. exists(configpath):341 if not os.path.lexists(configpath): 336 342 return {'status':False,'msg':'not exists debmirror.conf to '+ distro } 337 343 … … 392 398 393 399 def enable_webserver_into_folder(self,path): 400 394 401 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 395 402 s.bind(('localhost', 0)) 396 403 addr, port = s.getsockname() 397 404 s.close() 398 self.webserverprocess = Process(target=self._enable_webserver_into_folder,args=(port,path,))399 self.webserverprocess .start()405 self.webserverprocess[str(port)] = Process(target=self._enable_webserver_into_folder,args=(port,path,)) 406 self.webserverprocess[str(port)].start() 400 407 return {'status':True,'msg':port} 401 408 #enable_webserver_into_folder … … 409 416 handler = SimpleHTTPRequestHandler 410 417 handler.protocol_version = proto 411 self.httpd = BaseHTTPServer.HTTPServer(sock,handler)412 self.httpd .serve_forever()418 self.httpd[str(port)] = BaseHTTPServer.HTTPServer(sock,handler) 419 self.httpd[str(port)].serve_forever() 413 420 except Exception, e: 414 421 return None 415 422 #_enable_webserver_into_folder 416 423 417 def stop_webserver(self): 418 if self.webserverprocess != None: 419 self.webserverprocess.terminate() 420 return {'status':True,'msg':'Server stopped'} 424 def stop_webserver(self,port): 425 if self.webserverprocess.has_key(port): 426 self.webserverprocess[port].terminate() 427 self.webserverprocess.pop(port) 428 return {'status':True,'msg':'Server stopped'} 429 return {'status':False,'msg':'Server not exists'} 421 430 #stop_webserver 422 431 … … 439 448 configpath = os.path.join(self.configpath,distro + ".json") 440 449 config = json.load(open(configpath,'r')) 441 if not os.path. exists(configpath):450 if not os.path.lexists(configpath): 442 451 return {'status':False,'msg':'not exists debmirror.conf to '+ distro } 443 452 if "IGN_GPG" in config.keys(): … … 459 468 return {'status':False,'msg':str(e)} 460 469 470 def stopgetmirror(self): 471 try: 472 self.get_mirror_process.terminate() 473 return {'status':True,'msg':'debmirror stopped'} 474 except Exception as e: 475 return {'status':False,'msg':str(e)} 461 476 462 477 def download_time_file(self,distro): … … 539 554 def new_mirror_config(self,config): 540 555 name = config["NAME"].lower().strip() 541 import string 542 valid_chars = "-_.%s%s" % (string.ascii_letters, string.digits) 543 name = ''.join(c for c in name if c in valid_chars) 556 name = ''.join(c for c in name if c in self.valid_chars) 544 557 545 558 # Checks … … 548 561 while True: 549 562 newconfigpath = os.path.join(self.configpath,name + '.json') 550 if not os.path. exists(newconfigpath):563 if not os.path.lexists(newconfigpath): 551 564 break 552 565 name = name + "1" … … 587 600 #def get_client_ip 588 601 589 def watch_update_finish(self,credentials,server):590 self.watch_thread=threading.Thread(target=self._update,args=(credentials,server,))591 self.watch_thread.daemon=True592 self.watch_thread.start()593 594 #def watch_update_finish595 596 def _watch_update_finish(self,credentials,server):597 import time598 import xmlrpclib as x599 while True:600 try:601 time.sleep(240)602 c = x.ServerProxy('https://'+ server +':9779')603 result = c.is_alive(credentials,'MirrorManager')604 if not result:605 self.stop_webserver()606 break607 except:608 break609 #def _watch_update_finish610 611 602 def is_alive_get_mirror(self): 612 603 return {'status':self.get_mirror_thread.is_alive(),'msg':self.exportpercentage} 613 604 #def is_alive_get_mirror 614 605 615 def get_mirror(self,config_path ):616 self.get_mirror_thread = threading.Thread(target=self._get_mirror,args=(config_path ))606 def get_mirror(self,config_path,callback_args): 607 self.get_mirror_thread = threading.Thread(target=self._get_mirror,args=(config_path,callback_args,)) 617 608 self.get_mirror_thread.daemon = True 618 609 self.get_mirror_thread.start() 619 610 #def get_mirror 620 611 621 def _get_mirror(self,config_path ):612 def _get_mirror(self,config_path,callback_args): 622 613 self.get_mirror_process = pexpect.spawn("/usr/bin/debmirror --config-file="+config_path) 623 614 while True: … … 638 629 except Exception as e: 639 630 break 631 if callback_args.has_key('port') and callback_args.has_key('ip'): 632 import xmlrpclib as x 633 c = x.ServerProxy('https://' + callback_args['ip'] + ':9779') 634 c.stop_webserver('','MirrorManager',callback_args['port']) 640 635 #def _get
Note: See TracChangeset
for help on using the changeset viewer.