def post(): form, error = JsonParser('name', 'type', 'zone', 'docker_uri', 'ssh_ip', 'ssh_port', Argument('desc', nullable=True, required=False)).parse() if error is None: host = Host(**form) host.save() return json_response(host) return json_response(message=error)
def host_import(): data = excel_parse() if data: index_map = {key: index for index, key in enumerate(data.keys())} for row in zip(*data.values()): print(row) Host( name=row[index_map['主机名称']], desc=row[index_map['备注信息']], type=row[index_map['主机类型']], zone=row[index_map['所属区域']], docker_uri=row[index_map['Docker连接地址']], ssh_ip=row[index_map['SSH连接地址']], ssh_port=row[index_map['SSH端口']], ).add() db.session.commit() return json_response(data='导入成功')