70 lines
3.0 KiB
Python
70 lines
3.0 KiB
Python
"""ForeignKey 수정 후 재배포 + P2 라우터 활성화"""
|
|
import paramiko, sys, time
|
|
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
|
|
c = paramiko.SSHClient(); c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect('101.79.17.164', username='root', password='1q2w3e!Q', timeout=15)
|
|
sftp = c.open_sftp()
|
|
|
|
def run(label, cmd, timeout=30):
|
|
print(f'\n[{label}]')
|
|
_, o, _ = c.exec_command(cmd, timeout=timeout)
|
|
print(o.read().decode('utf-8','replace').strip()[:400])
|
|
|
|
# 1. 수정된 models.py 업로드
|
|
sftp.put('C:/GUARDiA/workspace/guardia-itsm/models.py', '/opt/guardia/app/models.py')
|
|
print('✅ models.py 업로드')
|
|
|
|
# 2. P2 라우터 활성화 (주석 해제)
|
|
run('P2 라우터 활성화',
|
|
r"""sed -i 's/^#from routers import kubernetes/from routers import kubernetes/' /opt/guardia/app/main.py
|
|
sed -i 's/^#app.include_router(kubernetes/app.include_router(kubernetes/' /opt/guardia/app/main.py
|
|
sed -i 's/^#app.include_router(sso_provider/app.include_router(sso_provider/' /opt/guardia/app/main.py
|
|
sed -i 's/^#app.include_router(predictive_ops/app.include_router(predictive_ops/' /opt/guardia/app/main.py
|
|
sed -i 's/^#app.include_router(slack_connector/app.include_router(slack_connector/' /opt/guardia/app/main.py
|
|
sed -i 's/^#app.include_router(white_label/app.include_router(white_label/' /opt/guardia/app/main.py
|
|
echo "완료"
|
|
grep -c "include_router" /opt/guardia/app/main.py""")
|
|
|
|
# 3. DB 테이블 생성
|
|
db_script = """
|
|
import asyncio, sys
|
|
sys.path.insert(0, '/opt/guardia/app')
|
|
from database import engine, Base
|
|
from models import K8sCluster, SSOConfig, SSOSession, SlackConfig, TenantBranding
|
|
|
|
async def create():
|
|
async with engine.begin() as conn:
|
|
await conn.run_sync(Base.metadata.create_all)
|
|
print('테이블 생성 완료')
|
|
|
|
asyncio.run(create())
|
|
"""
|
|
with sftp.open('/tmp/create_tables.py', 'w') as f: f.write(db_script)
|
|
run('DB 테이블 생성',
|
|
'cd /opt/guardia/app && /opt/guardia/venv/bin/python3 /tmp/create_tables.py 2>&1; rm /tmp/create_tables.py',
|
|
timeout=30)
|
|
|
|
# 4. 포트 정리 + 재시작
|
|
run('포트 kill + 재시작',
|
|
'fuser -k 9001/tcp 2>/dev/null || true; sleep 2; systemctl restart guardia && sleep 8 && systemctl is-active guardia')
|
|
time.sleep(5)
|
|
|
|
# 5. 검증
|
|
verify = """
|
|
import urllib.request, json
|
|
d = json.loads(urllib.request.urlopen("http://localhost:9001/openapi.json", timeout=10).read())
|
|
paths = sorted(d["paths"].keys())
|
|
p1_kw = ["/api/rag","/api/jira","/api/kpi","/api/portal","/api/bi/","/api/workflow"]
|
|
p2_kw = ["/api/k8s","/api/sso","/api/predict","/api/slack","/api/brand"]
|
|
p1 = [p for p in paths if any(k in p for k in p1_kw)]
|
|
p2 = [p for p in paths if any(k in p for k in p2_kw)]
|
|
print(f"전체: {len(paths)}개, P1: {len(p1)}개, P2: {len(p2)}개")
|
|
print("P2 경로:")
|
|
for p in p2: print(" ", p)
|
|
"""
|
|
with sftp.open('/tmp/verify.py', 'w') as f: f.write(verify)
|
|
run('최종 검증', 'python3 /tmp/verify.py 2>&1; rm /tmp/verify.py', timeout=20)
|
|
|
|
sftp.close(); c.close()
|
|
print('\n=== 완료 ===')
|