database separate file
This commit is contained in:
33
server_api/mir_server.py
Normal file
33
server_api/mir_server.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import requests
|
||||
from .models import MirServerSettings, MissionStatus
|
||||
from . import db
|
||||
|
||||
def execute_mission(mission_id, hostname):
|
||||
mir_settings = MirServerSettings.query.first()
|
||||
if not mir_settings:
|
||||
print("MIR server settings not found.")
|
||||
return
|
||||
|
||||
mir_ip = mir_settings.ip_address
|
||||
auth_header = mir_settings.auth_header
|
||||
url = f"http://{mir_ip}/api/v2.0.0/mission_scheduler"
|
||||
headers = {
|
||||
'accept': 'application/json',
|
||||
'Authorization': auth_header,
|
||||
'Accept-Language': 'en_US',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.post(url, headers=headers, json={"mission_id": mission_id})
|
||||
if response.status_code in {200, 201}:
|
||||
print(f"Mission {mission_id} executed successfully.")
|
||||
mission_data = response.json()
|
||||
mission_guid = mission_data.get('id')
|
||||
mission_status = MissionStatus(hostname=hostname, mission_id=mission_id, mission_guid=mission_guid, status='Started')
|
||||
db.session.add(mission_status)
|
||||
db.session.commit()
|
||||
else:
|
||||
print(f"Failed to execute mission {mission_id}: {response.text}")
|
||||
except Exception as e:
|
||||
print(f"Error executing mission {mission_id}: {e}")
|
||||
Reference in New Issue
Block a user