zack commited on
Commit
f638612
·
1 Parent(s): 6a7131f

🔧 fix: update app.py with socketio configurations

Browse files
Files changed (1) hide show
  1. backend/app.py +23 -9
backend/app.py CHANGED
@@ -100,15 +100,25 @@ def remove_port():
100
 
101
  @app.route("/api/open/ports", methods=["GET"])
102
  def open_ports():
 
103
  return jsonify(visable)
104
 
105
  ## Proxmox API
106
 
107
- @app.route('/addProxmoxVM', methods=['POST'])
108
  def add_proxmox_vm():
109
  data = request.json
110
- # Save or process Proxmox VM data here
111
- return {"status": "VM added"}, 200
 
 
 
 
 
 
 
 
 
112
 
113
  @socketio.on('connect')
114
  def handle_connect():
@@ -121,14 +131,18 @@ def handle_disconnect():
121
  @socketio.on('fetchVmData')
122
  def handle_fetch_vm_data(data):
123
  # Fetch VM data from Proxmox using the provided VM address
124
- vm_data = requests.get(f"http://{data['vm_address']}/api2/json")
125
- emit('vmData', vm_data.json())
 
 
 
 
 
126
 
127
- if __name__ == '__main__':
128
- socketio.run(app, debug=True, host='0.0.0.0')
129
-
130
- ## Gradio API
131
 
 
132
  if __name__ == "__main__":
133
 
134
  parser = argparse.ArgumentParser()
 
100
 
101
  @app.route("/api/open/ports", methods=["GET"])
102
  def open_ports():
103
+ # Assuming 'visable' is a list of open ports information
104
  return jsonify(visable)
105
 
106
  ## Proxmox API
107
 
108
+ @app.route('/api/addProxmoxVM', methods=['POST'])
109
  def add_proxmox_vm():
110
  data = request.json
111
+ # Placeholder for saving or processing Proxmox VM data
112
+ # This should include logic to handle the data received from the frontend
113
+ return jsonify({"status": "VM added"}), 200
114
+
115
+ @app.route('/api/getVncUrl', methods=['GET'])
116
+ def get_vnc_url():
117
+ vm_address = request.args.get('vmAddress')
118
+ # Placeholder for fetching VNC URL based on VM address
119
+ # This should include logic to retrieve the VNC URL for the specified VM
120
+ vnc_url = "https://example.com/vnc/" + vm_address # Example VNC URL
121
+ return jsonify({"vncUrl": vnc_url})
122
 
123
  @socketio.on('connect')
124
  def handle_connect():
 
131
  @socketio.on('fetchVmData')
132
  def handle_fetch_vm_data(data):
133
  # Fetch VM data from Proxmox using the provided VM address
134
+ # The actual fetching should be adapted to match your Proxmox setup and API
135
+ try:
136
+ vm_data = requests.get(f"http://{data['vm_address']}/api2/json", verify=False) # Example request
137
+ emit('vmData', vm_data.json())
138
+ except requests.exceptions.RequestException as e:
139
+ print(f"Error fetching VM data: {e}")
140
+ emit('vmData', {'error': 'Failed to fetch VM data'})
141
 
142
+ if __name__ == '__main__':
143
+ socketio.run(app, debug=True, host='0.0.0.0')
 
 
144
 
145
+ ## Gradio API
146
  if __name__ == "__main__":
147
 
148
  parser = argparse.ArgumentParser()