import pathlib,json,sys,hashlib,datetime,time,urllib.request sys.path.insert(0,'/home/ps/huobao-gpu-selection') from docker_worker_ops import api,inspect,write_json,set_env work=pathlib.Path('/home/ps/huobao-gpu-selection/panel-8189');name='comfyui-manju' before=json.loads((work/'before.json').read_text());current=inspect(name) assert current['Id']==before['Id'],'8189 changed since preparation' def get(path,token=None): h={'X-H3-Canary-Token':token} if token else {} with urllib.request.urlopen(urllib.request.Request('http://192.168.110.111:8189'+path,headers=h),timeout=4) as r:return json.load(r) q=get('/queue');assert not q['queue_running'] and not q['queue_pending'],'8189 is busy; no restart performed' history=get('/history');snapshot={'schema':1,'queue_empty':True,'source_container_id':before['Id'],'history':history} assert all(v.get('status',{}).get('status_str') in ('success','error') for v in history.values()) (work/'history.json').write_text(json.dumps(snapshot));(work/'history.json').chmod(0o644) cfg=json.loads((work/'create.json').read_text());k='H3_HISTORY_SNAPSHOT_SHA256';v=hashlib.sha256((work/'history.json').read_bytes()).hexdigest() set_env(cfg,k,v);cfg['Cmd'].insert(cfg['Cmd'].index('/opt/conda/bin/python3'),k+'='+v) write_json(work/'create.json',cfg) q=get('/queue');assert not q['queue_running'] and not q['queue_pending'],'8189 received a new job; leaving it running' stamp=datetime.datetime.now().strftime('%Y%m%d-%H%M%S');old=name+'-before-huobao-'+stamp api('POST','/containers/'+name+'/stop?t=20');api('POST','/containers/'+name+'/rename?name='+old) created=False try: api('POST','/containers/create?name='+name,cfg);created=True;api('POST','/containers/'+name+'/start') token=(work/'control/canary.token').read_text() for _ in range(35): try: info=get('/object_info',token) if 'H3CaptionPipeline' in info:break except Exception:pass time.sleep(1) else:raise RuntimeError('8189 did not become ready') required=set(json.loads((work/'allowed_node_classes.json').read_text())['required_classes']) assert required<=set(info),'A previously available class is missing' restored=get('/history',token) assert all(restored.get(k)==v for k,v in history.items()),'History verification failed' (work/'control/control.json').write_text(json.dumps({'schema':1,'maintenance':False})) write_json(work/'deployed.json',{'old_container':old,'new_id':inspect(name)['Id'],'history_count':len(history),'classes':len(info)}) print(json.dumps({'deployed':name,'port':8189,'history_preserved':len(history),'classes':len(info),'previous_container':old})) except Exception: if created: api('POST','/containers/'+name+'/stop?t=10');api('POST','/containers/'+name+'/rename?name='+name+'-failed-'+stamp) api('POST','/containers/'+old+'/rename?name='+name);api('POST','/containers/'+name+'/start') raise