Commit 063f4fef authored by mazx-test's avatar mazx-test

Initial commit

parents
venv/
static/
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="Flask">
<option name="enabled" value="true" />
</component>
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TemplatesService">
<option name="TEMPLATE_FOLDERS">
<list>
<option value="$MODULE_DIR$/../base_service_L2\templates" />
</list>
</option>
</component>
</module>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6 (base_service_L2)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/base_service_L2.iml" filepath="$PROJECT_DIR$/.idea/base_service_L2.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="e3b22d69-4e8f-4a58-9467-81fee667c148" name="Default Changelist" comment="" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Flask Main" />
<option value="Python Script" />
</list>
</option>
</component>
<component name="ProjectId" id="2Vh3SxnxoMomatNvH6vmOrwsfFh" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showExcludedFiles" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="settings.editor.selected.configurable" value="com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable" />
</component>
<component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
<recent name="D:\代码项目\python\keycloak\base_service_L2\eip_product" />
</key>
</component>
<component name="RunManager" selected="Python.app">
<configuration name="app" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="base_service_L2" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/app.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="base_service_L2" type="Python.FlaskServer">
<module name="base_service_L2" />
<option name="target" value="$PROJECT_DIR$/app.py" />
<option name="targetType" value="PATH" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="launchJavascriptDebuger" value="false" />
<method v="2" />
</configuration>
<recent_temporary>
<list>
<item itemvalue="Python.app" />
</list>
</recent_temporary>
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="e3b22d69-4e8f-4a58-9467-81fee667c148" name="Default Changelist" comment="" />
<created>1695274487617</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1695274487617</updated>
<workItem from="1695274519054" duration="15527000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
</component>
<component name="WindowStateProjectService">
<state x="552" y="183" key="#Notifications" timestamp="1695276511020">
<screen x="0" y="0" width="1920" height="1050" />
</state>
<state x="552" y="183" key="#Notifications/0.0.1920.1050@0.0.1920.1050" timestamp="1695276511020" />
<state x="705" y="327" key="#com.intellij.fileTypes.FileTypeChooser" timestamp="1695274606399">
<screen x="0" y="0" width="1920" height="1050" />
</state>
<state x="705" y="327" key="#com.intellij.fileTypes.FileTypeChooser/0.0.1920.1050@0.0.1920.1050" timestamp="1695274606399" />
<state width="1877" height="379" key="GridCell.Tab.0.bottom" timestamp="1695302412542">
<screen x="0" y="0" width="1920" height="1050" />
</state>
<state width="1877" height="379" key="GridCell.Tab.0.bottom/0.0.1920.1050@0.0.1920.1050" timestamp="1695302412542" />
<state width="1877" height="379" key="GridCell.Tab.0.center" timestamp="1695302412542">
<screen x="0" y="0" width="1920" height="1050" />
</state>
<state width="1877" height="379" key="GridCell.Tab.0.center/0.0.1920.1050@0.0.1920.1050" timestamp="1695302412542" />
<state width="1877" height="379" key="GridCell.Tab.0.left" timestamp="1695302412542">
<screen x="0" y="0" width="1920" height="1050" />
</state>
<state width="1877" height="379" key="GridCell.Tab.0.left/0.0.1920.1050@0.0.1920.1050" timestamp="1695302412542" />
<state width="1877" height="379" key="GridCell.Tab.0.right" timestamp="1695302412542">
<screen x="0" y="0" width="1920" height="1050" />
</state>
<state width="1877" height="379" key="GridCell.Tab.0.right/0.0.1920.1050@0.0.1920.1050" timestamp="1695302412542" />
<state x="461" y="167" key="SettingsEditor" timestamp="1695282657228">
<screen x="0" y="0" width="1920" height="1050" />
</state>
<state x="461" y="167" key="SettingsEditor/0.0.1920.1050@0.0.1920.1050" timestamp="1695282657228" />
<state x="92" y="92" width="1736" height="866" key="com.intellij.history.integration.ui.views.FileHistoryDialog" timestamp="1695277350220">
<screen x="0" y="0" width="1920" height="1050" />
</state>
<state x="92" y="92" width="1736" height="866" key="com.intellij.history.integration.ui.views.FileHistoryDialog/0.0.1920.1050@0.0.1920.1050" timestamp="1695277350220" />
</component>
<component name="com.intellij.coverage.CoverageDataManagerImpl">
<SUITE FILE_PATH="coverage/base_service_L2$app.coverage" NAME="app Coverage Results" MODIFIED="1695286327858" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
</component>
</project>
\ No newline at end of file
from db_init import DB_URI
from init import auto_man
from eip_product import eip_bp
def run():
auto_man.config['SQLALCHEMY_DATABASE_URI'] = DB_URI
auto_man.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
auto_man.register_blueprint(eip_bp, url_prefix='/eip')
auto_man.run(host='0.0.0.0', port=8080, threaded=True, processes=1)
if __name__ == '__main__':
run()
import json
import requests
FORBIDDEN_403 = {
"http_code": 403,
"code": "notAuthorized",
"message": "You are not authorised to execute this."
}
UNAUTHORIZED_401 = {
"http_code": 401,
"code": "notAuthorized",
"message": "Invalid authentication."
}
def login(username, password):
try:
iam_url = "https://iam.inspurcloudapi.com/auth/v1/token"
user_data = {
"username": username,
"password": password
}
resonse = requests.post(url=iam_url, data=json.dumps(user_data))
if resonse.ok:
return "200"
else:
return "401"
except Exception as error:
print("当前请求token失败", error)
SECRET_KEY: "0tYdTBiQk2sorTK7O0sAg1BIFqMgy8I2MEV60q5Nu3k="
datasource:
db_host: "35.205.104.41"
db_port: 30492
db_user: "root"
db_password: "Jya3QE7M0e"
db_database: "icp_eip"
from flask_sqlalchemy import SQLAlchemy
import yaml
from init import auto_man
#
with open(file='config', mode='r', encoding='utf-8') as f:
result = yaml.load(f, Loader=yaml.FullLoader)
db_info = result['datasource']
print(db_info)
DB_URI = "mysql+pymysql://{username}:{password}@{host}:{port}/{db}?charset=utf8".format(username=db_info.get("db_user"),
password=db_info.get("db_password"),
host=db_info.get("db_host"),
port=db_info.get("db_port"),
db=db_info.get("db_database"))
auto_man.config['SQLALCHEMY_DATABASE_URI'] = DB_URI
auto_man.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(auto_man)
from .eip_view import eip_bp
from flask_restful import reqparse, fields, marshal_with, Resource
from eip_product import eip_db
class EipInfo(Resource):
resource_fields = {
"message": fields.String(default="success"),
"status": fields.Integer(default=0),
"data": fields.Nested(
{"eips": fields.List(
fields.Nested(
{
"eip": fields.String,
"user_name": fields.String
}),
)
})}
@marshal_with(resource_fields)
def get(self):
parser = reqparse.RequestParser()
parser.add_argument('instances_id', type=str, help='请提供eip的实例id', required=True, trim=True)
parser.add_argument('secret_key', type=str, help='请提供凭证', required=True, trim=True)
args = parser.parse_args()
eip_list = []
try:
result = eip_db.get_eip_by_uuid(args.get("instances_id"))
print("查询结果", result)
if len(result) > 0:
eip_list.append({"eip": result[0]["eip"], "user_name": result[0]["user_name"]})
return {"data": {"eips": eip_list}}
else:
return {"data": {"eips": []}}
except Exception as e:
return {"message": '查询失败,{error}'.format(error=e)}
from db_init import db
import json
from uuid import uuid4
def get_eip_by_uuid(eip_instance_id):
find_eip_by_id_sql = "select eip_address,user_name,region from icp_eip.eip where id='{instance_id}' limit 1".format(instance_id=eip_instance_id)
try:
eip_list = []
results = db.session.execute(find_eip_by_id_sql)
for eip in results:
eip_list.append({"eip": eip['eip_address'], "user_name": eip['user_name']})
print("eip_list", eip_list)
return eip_list
except Exception as e:
print("数据库查询失败,{error}".format(error=e))
from flask import Blueprint
from flask_restful import Api
from .eip_api import EipInfo
eip_bp = Blueprint('eip_product', __name__)
eip_api = Api(eip_bp)
eip_api.add_resource(EipInfo, '/eipList')
\ No newline at end of file
from flask import Flask
auto_man = Flask(__name__)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment