index.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # coding: utf-8
  2. from flask import Flask, request
  3. from flask import jsonify
  4. import json
  5. from InstanceID import privateIP2InstanceID
  6. from EIPChanger import AliyunEip
  7. from ECSCreater import AliyunECS
  8. import logging
  9. logging.basicConfig(level=logging.DEBUG,
  10. format='%(asctime)s %(levelname)s %(message)s',
  11. datefmt='%Y-%m-%d %H:%M:%S',
  12. filename='logs/debug.log',
  13. filemode='a')
  14. app = Flask(__name__)
  15. @app.route("/instaceid", methods=['POST'])
  16. def getinstanceid():
  17. privateip = request.form['privateip']
  18. region=request.form['region']
  19. result = privateIP2InstanceID(privateip, region)
  20. return jsonify(result)
  21. @app.route("/reseteip", methods=['POST'])
  22. def reseteip():
  23. # ""
  24. #data = json.loads(request.get_data(as_text=True))
  25. privateip = request.form['privateip']
  26. region=request.form['region']
  27. d = privateIP2InstanceID(privateip,region)
  28. instanceid = d['instanceid']
  29. if d.get('eipid'):
  30. eipid = d['eipid']
  31. runner = AliyunEip(instanceid, region, eipid)
  32. else:
  33. runner = AliyunEip(instanceid, region)
  34. data = runner.run()
  35. return jsonify(data)
  36. @app.route("/createecs", methods=['POST'])
  37. def createecs():
  38. # set_Region
  39. # set_InternetChargeType PayByTraffic or PayByBandwidth
  40. # set_InstanceChargeType PostPaid or PrePaid
  41. # set_Password
  42. # set_Amount
  43. set_Region = request.form['set_Region']
  44. set_InternetChargeType = request.form['set_InternetChargeType']
  45. set_InstanceChargeType = request.form['set_InstanceChargeType']
  46. set_Password = request.form['set_Password']
  47. set_Amount = request.form['set_Amount']
  48. instance = AliyunECS(set_Region=set_Region, set_InternetChargeType=set_InternetChargeType, set_InstanceChargeType=set_InstanceChargeType, set_Password=set_Password, set_Amount=set_Amount)
  49. result = instance.CreateECSInstance
  50. return jsonify(result)
  51. @app.route("/describeinstances", methods=['POST'])
  52. def describeinstances():
  53. set_Region = request.form['set_Region']
  54. InstanceIds = eval(request.form['InstanceIds'])
  55. instance = AliyunECS(set_Region=set_Region)
  56. result = instance.DescribeInstances(InstanceIds)
  57. return jsonify(result)
  58. @app.route("/releaseinstances", methods=['POST'])
  59. def releaseinstances():
  60. set_Region = request.form['set_Region']
  61. InstanceIds = eval(request.form['InstanceIds'])
  62. instance = AliyunECS(set_Region=set_Region)
  63. result = instance.ReleaseInstances(InstanceIds)
  64. return jsonify(result)
  65. if __name__ == "__main__":
  66. app.run(host="0.0.0.0")