Changeset 1870 for lmd/trunk/fuentes/lmd-server.install
- Timestamp:
- Jun 8, 2016, 1:05:09 PM (5 years ago)
- Location:
- lmd/trunk/fuentes/lmd-server.install
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
lmd/trunk/fuentes/lmd-server.install/etc/n4d/conf.d/LmdServer
r392 r1870 6 6 (ip)do_command=admin,admins,adm 7 7 (ip)create_image=admin,admins,adm 8 create_imageWS=admin,admins,adm 8 9 (ip)export_image=admin,admins,adm 9 10 (ip)import_image=admin,admins,adm … … 13 14 (ip)cancel_job=anonymous 14 15 (ip)deploy_minimal_client=admin,admins,adm 16 deploy_minimal_clientWS=admin,admins,adm 15 17 getJobList=anonymous 16 18 getLastJobId=anonymous -
lmd/trunk/fuentes/lmd-server.install/usr/share/n4d/python-plugins/LmdImageManager.py
r392 r1870 9 9 self.imagepath="/etc/ltsp/images/" 10 10 self.tftppath="/var/lib/tftpboot/ltsp" 11 12 11 13 12 pass … … 40 39 ''' 41 40 Returns the metadata from certain image 42 ''' 41 42 // WIP HERE 43 44 -> mirar si accepta be el tercer parametre o cal fer el kwargs... 45 agafa aquest taskid i comprova amb getTask si existeix i el seu estat 46 i l'afig amb data["taskstatus"]=ret(....) 47 48 Aixi al renderImage de l'ImageManager ja podem tindre disponible l'estat sense haver 49 d'estar consultant-ho des de la gui 50 ''' 51 43 52 try: 44 53 json_data=open(self.imagepath+image) 45 54 data = json.load(json_data) 46 55 json_data.close() 56 57 if "taskid" in data: 58 taskid=data["taskid"]; 59 else: 60 taskid="0"; 61 62 # Searching task id for this image 63 status="DONE"; 64 ret=objects['TaskMan'].getTaskStatus(taskid); 65 66 if ret["status"]==True: 67 status=ret["taskStatus"] 68 # if ret[status] is false the task has been done time ago 69 data["task_status"]=status; 70 47 71 return json.dumps(data) 48 72 #return data; 49 73 except Exception as e: 74 print "[LmdImageManager]: getImage Exception "+str(e) 50 75 return str(e); 51 76 -
lmd/trunk/fuentes/lmd-server.install/usr/share/n4d/python-plugins/LmdServer.py
r1490 r1870 63 63 return {"status": True, "error": 'image_exists'} 64 64 return {"status": False} 65 65 66 67 def create_imageWS(self, imgid, name, template, description='', bgimg=''): 68 try: 69 # creates an image from an specified template 70 71 # Check if template exists 72 path="/etc/ltsp/templates/"+template; 73 if(os.path.isfile(path)): 74 extraLliurexOpts="--accept-unsigned-packages --purge-chroot" 75 # if template exists, create an image 76 print "[LmdServer] Create_imageWS from "+path 77 command="ltsp-build-client --config "+path+" "+extraLliurexOpts+" --chroot "+imgid+"&& service nbd-server restart"; 78 79 ret=objects['TaskMan'].newTask(command); 80 81 if ret["status"]==True: ## Task has launched ok 82 83 metadata = {'id':imgid, 'name' : name, 84 'desc' : description , 85 "template" : template, 86 'img': bgimg, 87 'taskid': ret["msg"], 88 'ltsp_fatclient': 'undefined', 89 'ldm_session': 'default', 90 'fat_ram_threshold': 'default', 91 'lmd_extra_params':'' } 92 metadata_string = unicode(json.dumps(metadata,indent=4,encoding="utf-8",ensure_ascii=False)).encode("utf-8") 93 objects['LmdImageManager'].setImage(imgid,metadata_string) 94 self.set_default_boot(imgid) 95 96 # Registering imgid for boot PXE MEnu 97 98 objects['LlxBootManager'].pushToBootList("ltsp_label"+str(imgid)); 99 100 return {"status": True, "msg": ret["msg"]} 101 102 else: 103 if ret["msg"]=="SERVER_BUSY": 104 return {'status':False, 'msg':'SERVER_BUSY'} 105 else: 106 return {'status':False, 'msg':'TEMPLATE_NOT:EXISTS'} 107 108 pass 109 except Exception as e: 110 print "Except: "+str(e) 111 return e 112 113 114 66 115 67 116 def create_image(self, ip, port, imgid, name, template, description='', bgimg='', srv_ip='127.0.0.1'): … … 95 144 96 145 # Registering imgid for boot PXE MEnu 97 objects['LlxBootManager'].pushToBootList("ltsp_label"+str(imgid)); 146 147 if (result==0): 148 objects['LlxBootManager'].pushToBootList("ltsp_label"+str(imgid)); 149 else: 150 # Image has not been built correctly 151 metadata = {'id':imgid, 'name' : name, 152 'desc' : description , 153 "template" : template, 154 'img': bgimg, 155 'ltsp_fatclient': 'undefined', 156 'ldm_session': 'default', 157 'fat_ram_threshold': 'default', 158 'status':'broken', 159 'lmd_extra_params':'' } 160 98 161 99 162 return result … … 164 227 def import_image(self, ip, port, imgid, path, srv_ip='127.0.0.1'): 165 228 try: 166 167 import xmlrpclib 168 client=xmlrpclib.ServerProxy("https://127.0.0.1:9779") 169 n4d_server_ip=client.get_variable("", "VariablesManager", "SRV_IP") 170 171 '''print ("[************************ ip]"+ip); 172 print ("[************************ srv_ip]"+srv_ip); 173 print ("[************************ ip from host:]"+lliurex.net.get_ip_from_host(ip)); 174 print ("[************************ n4d ip server]"+n4d_server_ip);''' 175 229 230 import xmlrpclib 231 client=xmlrpclib.ServerProxy("https://127.0.0.1:9779") 232 n4d_server_ip=client.get_variable("", "VariablesManager", "SRV_IP") 176 233 177 234 … … 243 300 self.set_default_boot(imgid) 244 301 result=self.do_command(ip, port, command, srv_ip,target=imgid) 245 246 # Step 2. Writing lts.conf for mini-light-client 247 248 print "[LMDServer] Writing lts.conf for mini-light-client" 249 f=open('/var/lib/tftpboot/ltsp/mini-light-client/lts.conf', 'w') 250 f.write('[Default]\n') 251 f.write('LDM_LANGUAGE=es_ES.UTF-8\n') 252 f.write('LTSP_FATCLIENT=false\n') 253 f.close() 254 255 # Step 3. Registering imgid for boot PXE menu 256 objects['LlxBootManager'].pushToBootList("ltsp_label"+str(imgid)); 257 258 try: 259 f=open("/etc/default/locale") 260 lines=f.readlines() 302 303 if result==0: 304 # Step 2. Writing lts.conf for mini-light-client 305 306 print "[LMDServer] Writing lts.conf for mini-light-client" 307 308 if not os.path.exists('/var/lib/tftpboot/ltsp/mini-light-client'): 309 os.makedirs('/var/lib/tftpboot/ltsp/mini-light-client') 310 311 f=open('/var/lib/tftpboot/ltsp/mini-light-client/lts.conf', 'w') 312 f.write('[Default]\n') 313 f.write('LDM_LANGUAGE=es_ES.UTF-8\n') 314 f.write('LTSP_FATCLIENT=false\n') 261 315 f.close() 262 for line in lines: 263 if "LANG=" in line: 264 lng=line.strip().split("=")[1].strip("'").strip('"') 265 if "es_ES" in lng: 266 language="es" 267 if "ca_ES" in lng: 268 language="ca_ES@valencia" 269 270 except: 316 317 # Step 3. Registering imgid for boot PXE menu 318 objects['LlxBootManager'].pushToBootList("ltsp_label"+str(imgid)); 319 320 try: 321 f=open("/etc/default/locale") 322 lines=f.readlines() 323 f.close() 324 for line in lines: 325 if "LANG=" in line: 326 lng=line.strip().split("=")[1].strip("'").strip('"') 327 if "es_ES" in lng: 328 language="es" 329 if "ca_ES" in lng: 330 language="ca_ES@valencia" 331 332 except: 333 return {"status": False, "msg": str(result)} 334 pass 335 336 return {"status": True, "msg": str(result)} 271 337 pass 272 273 274 275 276 277 278 return {"status": True, "msg": str(result)} 279 pass 280 338 339 else: 340 # result is not 0 -> Image creation cancelled 341 return {"status": True, "msg": str(result)} 342 pass 343 281 344 except Exception as e: 282 345 print "Except: "+str(e) 283 346 return {"status": False, "msg": str(e)} 284 347 348 349 #def deploy_minimal_clientWS(self, ws): 350 def deploy_minimal_clientWS(self): 351 #ws=objects['TaskMan'].getWS() -> no cal?? 352 try: 353 command="/usr/sbin/mini-light-client.py"; 354 #command="tasktest hola"; 355 356 357 #result=self.do_command(ip, port, command, srv_ip,target=imgid) 358 ret=objects['TaskMan'].newTask(command); 359 if ret["status"]==True: ## Task has launched ok 360 #print ret["status"] 361 362 # Writing json metadata in /etc/ltsp/images/ 363 imgid="mini-light-client" 364 365 lng="es_ES.UTF-8" 366 language="es_ES" 367 # After that, set image as available 368 metadata = {'status':'enabled-non-editable', 369 'taskid': ret["msg"], 370 'id':'mini-light-client', 371 'name':'Client Lleuger Minim', 372 'template':'Default by LMD', 373 'desc':'Minimal thin client -not fat- for Lliurex LTSP.', 374 'img':'llx-client16.png', 375 'ltsp_fatclient': 'false', 376 'ldm_session': 'startxfce4', 377 'fat_ram_threshold': 'default', 378 'lmd_extra_params':'XKBLAYOUT=es LDM_LANGUAGE="%s" LOCALE_DIR=%s'%(lng,language)} 379 metadata_string = unicode(json.dumps(metadata,indent=4,encoding="utf-8",ensure_ascii=False)).encode("utf-8") 380 objects['LmdImageManager'].setImage('mini-light-client',metadata_string) 381 self.set_default_boot(imgid) 382 383 # Writing lts.conf 384 print "[LMDServer] Writing lts.conf for mini-light-client" 385 if not os.path.exists('/var/lib/tftpboot/ltsp/mini-light-client'): 386 os.makedirs('/var/lib/tftpboot/ltsp/mini-light-client') 387 f=open('/var/lib/tftpboot/ltsp/mini-light-client/lts.conf', 'w') 388 f.write('[Default]\n') 389 f.write('LDM_LANGUAGE=es_ES.UTF-8\n') 390 f.write('LTSP_FATCLIENT=false\n') 391 f.close() 392 # Step 3. Registering imgid for boot PXE menu 393 objects['LlxBootManager'].pushToBootList("ltsp_label"+str(imgid)); 394 try: 395 f=open("/etc/default/locale") 396 lines=f.readlines() 397 f.close() 398 for line in lines: 399 if "LANG=" in line: 400 lng=line.strip().split("=")[1].strip("'").strip('"') 401 if "es_ES" in lng: 402 language="es" 403 if "ca_ES" in lng: 404 language="ca_ES@valencia" 405 406 except: 407 return {"status": False, "msg": ret["msg"]} 408 pass 409 410 # Returns true and ret.msg, that is job id 411 return {"status": True, "msg": ret["msg"]} 412 pass 413 414 else: 415 if ret["msg"]=="SERVER_BUSY": 416 return {'status':False, 'msg':'SERVER_BUSY'} 417 else: 418 return {'status':False, 'msg':'EXCEPTION'} 419 420 421 except Exception as e: 422 print "Except: "+str(e) 423 return {"status": False, "msg": str(e)} 424 425 285 426 286 427 def do_command(self, ip, port, command, srv_ip='127.0.0.1',target=None): … … 364 505 if (str(ret)=='0'): 365 506 job['status']="finished" 366 else: 367 job['status']="broken" 368 job['msg']=str(ret) 507 elif (str(ret)=='-9'): 508 job['status']="cancelled" 509 else: # return code 1 when install fails 510 job['msg']="broken" 369 511 print "[LmdServer] END WAIT AT"+str(datetime.datetime.now()) 370 512 print "[LmdServer] FINISHING!!!, return code: "+str(ret) 371 513 372 print "2"373 514 # Force umount (to avoid morrir destruction in mirrononnet) 374 515 proc=subprocess.call(["/usr/share/lmd-scripts/umount-chroot.sh"]) … … 383 524 self.locks[job['job_id']]['result'] = str(ret) 384 525 self.locks[job['job_id']]['lock'].release() 385 526 print str(ret) 386 527 return str(ret) 387 528 … … 525 666 526 667 How it Works: 527 * Search whic job has certain job_id (if specified) and remove its668 * Searches which job has certain job_id (if specified) and removes it 528 669 * If job_id is not specified, get it from ip:port 529 670 … … 541 682 job_id = self.global_listeners[tuple_ip_port] 542 683 # Get job identified by job_id 684 print self.joblist 685 print tuple_ip_port 686 print jobid 543 687 current_job_index=map(itemgetter('job_id'), self.joblist).index(job_id) 544 688 current_job=self.joblist[current_job_index] … … 569 713 570 714 ''' 571 572 715 # Remove listener 573 716 from operator import itemgetter … … 579 722 print self.global_listeners 580 723 job_id = self.global_listeners[tuple_ip_port] 724 print str(job_id) 725 581 726 # Get job identified by job_id 582 727 current_job_index=map(itemgetter('job_id'), self.joblist).index(job_id) 728 print current_job_index 583 729 current_job=self.joblist[current_job_index] 730 print current_job 584 731 # Get listener identified by (ip:port) 585 current_listener_index=map(itemgetter('ip','port'), current_job['listeners']).index((ip,int (port, base=10))) 732 try: 733 current_listener_index=map(itemgetter('ip','port'), current_job['listeners']).index((ip,int (port, base=10))) 734 print current_listener_index 735 except: 736 #print "*** jobid: ***" 737 #print port 738 print "*** port: ***" 739 print port 740 print "*** current_job: ***" 741 print current_job['listeners'] 742 print "*** joblist: ***" 743 print self.getJobList(); 744 current_listener_index=None 745 for listener in current_job['listeners']: 746 self.remove_listener(str(ip),str(port), job_id); 747 586 748 # Kill process (only addition to remove_listener) 587 749 os.killpg(current_job['process'].pid,signal.SIGKILL) 750 751 # Removes target 752 print "Removing target "+ str (current_job['target']) 753 r=objects['LmdImageManager'].deleteImage(current_job['target']); 754 print str(r); 755 print "Removied target" 756 588 757 current_job['status']='broken' 589 590 # Close port and remove listener to current_job 591 current_job['listeners'][current_listener_index]['socket'].close() 592 current_job['listeners'].remove(current_job['listeners'][current_listener_index]) 593 #remove listener reference 594 self.global_listeners.pop(tuple_ip_port) 758 759 if current_listener_index!=None: 760 # Close port and remove listener to current_job 761 current_job['listeners'][current_listener_index]['socket'].close() 762 current_job['listeners'].remove(current_job['listeners'][current_listener_index]) 763 #remove listener reference 764 self.global_listeners.pop(tuple_ip_port) 595 765 596 766 return True … … 680 850 681 851 def send_info_by_socket(self,job): 682 if not os.path.exists(job['filepipe']): 683 return False 684 pipe = open(job['filepipe'],'r') 685 pipe.seek(job['seek'],0) 686 try: 687 line = pipe.readline() 688 while (line and len(self.global_listeners)>0): 689 for listener in job['listeners']: 690 if(listener['socket']!=None): 691 try: 692 listener['socket'].send(line) 693 except Exception as e: 694 print "[LmdServer] EXCEPTION in Multicast internal loop: "+str(e) 695 continue 696 line=pipe.readline() 697 job['seek'] = pipe.tell() 698 except: 699 pass 700 701 if self.thread_jobs.has_key(job['job_id']): 702 self.thread_jobs.pop(job['job_id']) 703 852 try: 853 if not os.path.exists(job['filepipe']): 854 return False 855 pipe = open(job['filepipe'],'r') 856 pipe.seek(job['seek'],0) 857 try: 858 line = pipe.readline() 859 while (line and len(self.global_listeners)>0): 860 for listener in job['listeners']: 861 if(listener['socket']!=None): 862 try: 863 listener['socket'].send(line) 864 except Exception as e: 865 print "[LmdServer] EXCEPTION in Multicast internal loop: "+str(e) 866 continue 867 line=pipe.readline() 868 job['seek'] = pipe.tell() 869 except Exception as e: 870 print "[LMDServer] Exception wghile reading pipe "+str(e) 871 pass 872 873 if self.thread_jobs.has_key(job['job_id']): 874 self.thread_jobs.pop(job['job_id']) 875 876 except Exception as e: 877 print "[LMDServer] Exception wghile reading pipe "+str(e) 878 pass 704 879 def getLastJobId(self): 705 880 return self.last_job_id
Note: See TracChangeset
for help on using the changeset viewer.