def post(self): json_req = request.get_json(force=True) command = utils.get_command(request.path) command = 'dt_' + command init_data = cmd.parser(json_req, command) respons = {} if init_data['action'] == 'insert': table = init_data['data'][0]['table'] fields = init_data['data'][0]['fields'] try: result = model.insert(table, fields) except Exception as e: respons = {"status": False, "error": str(e)} else: respons = {"status": True, "messages": "Success", "id": result} finally: return response(200, data=fields, message=respons) if init_data['action'] == 'remove': table = "" tags = dict() fields = "" for i in init_data['data']: table = i['table'] tags = i['tags'] fields = str(list(tags.keys())[0]) try: result = model.delete(table, fields, tags[fields]) except Exception as e: respons = {"status": False, "messages": str(e)} else: respons = {"status": result, "messages": "Success!"} finally: return response(200, data=tags, message=respons) if init_data['action'] == 'where': obj_userdata = list() table = "" fields = "" tags = dict() for i in init_data['data']: table = i['table'] tags = i['tags'] for a in tags: if tags[a] is not None: fields = a try: result = model.get_by_id(table, fields, tags[fields]) except Exception as e: respons = {"status": False, "messages": str(e)} else: for i in result: data = { "id_product": str(i['id_product']), "nm_product": i["nm_product"], "nm_databaseref": i["nm_databaseref"] } obj_userdata.append(data) respons = {"status": True, "messages": "Fine!"} finally: return response(200, data=obj_userdata, message=respons)
def post(self): json_req = request.get_json(force=True) command = utils.get_command(request.path) command = 'dt_' + command init_data = cmd.parser(json_req, command) respons = dict() if init_data['action'] == 'insert': table = init_data['data'][0]['table'] fields = init_data['data'][0]['fields'] try: result = model.insert(table, fields) except Exception as e: respons = {"status": False, "error": str(e)} else: respons = {"status": True, "messages": "Success", "id": result} finally: return response(200, data=fields, message=respons) if init_data['action'] == 'remove': table = "" tags = dict() fields = "" for i in init_data['data']: table = i['table'] tags = i['tags'] fields = str(list(tags.keys())[0]) try: result = model.delete(table, fields, tags[fields]) except Exception as e: respons = {"status": False, "messages": str(e)} else: respons = {"status": result, "messages": "Success!"} finally: return response(200, data=tags, message=respons) if init_data['action'] == 'where': obj_userdata = list() table = "" fields = "" tags = dict() for i in init_data['data']: table = i['table'] tags = i['tags'] for a in tags: if tags[a] is not None: fields = a try: result = model.get_by_id(table, fields, tags[fields]) except Exception as e: respons = {"status": False, "messages": str(e)} else: for i in result: data = { "id_hosting": str(i['id_hosting']), "id_company_product": str(i['id_company_product']), 'spec_price': i['spec_price'], "spec_storage": i['spec_storage'], 'spec_database': i['spec_database'], "spec_free_domain": i['spec_free_domain'], "spec_hosting_domain": i['spec_hosting_domain'], 'spec_subdomain': i['spec_subdomain'], "spec_ftp_user": i['spec_ftp_user'], "spec_control_panel": i['spec_control_panel'], 'spec_email_account': i['spec_email_account'], "spec_spam_filter": i['spec_spam_filter'], "date_time": i['date_time'] } obj_userdata.append(data) respons = {"status": True, "messages": "Fine!"} finally: return response(200, data=obj_userdata, message=respons) if init_data['action'] == 'view': obj_userdata = list() table = "" fields = None tags = dict() for i in init_data['data']: table = i['table'] tags = i['tags'] for a in tags: if tags[a] is not None: fields = a column = model.get_columns("v_product_hosting") try: result = list() if fields is None: query = """select * from v_product_hosting""" db.execute(query) rows = db.fetchall() for row in rows: result.append(dict(zip(column, row))) else: query = """ select * from v_product_hosting where """ + fields + """='""" + tags[ fields] + """'""" db.execute(query) rows = db.fetchall() for row in rows: result.append(dict(zip(column, row))) except Exception as e: respons = {"status": False, "messages": str(e)} else: for i in result: data = { "id_company": str(i["id_company"]), "id_product": str(i["id_product"]), "id_hosting": str(i['id_hosting']), "id_company_product": str(i['id_company_product']), "id_additional_features": str(i["id_additional_features"]), "nm_company": i['nm_company'], "url_company": i['url_company'], "nm_product": i['nm_product'], "nm_company_product": i['nm_company_product'], "spec_storage": i['spec_storage'], 'spec_price': i['spec_price'], "spec_storage": i['spec_storage'], 'spec_database': i['spec_database'], "spec_free_domain": i['spec_free_domain'], "spec_hosting_domain": i['spec_hosting_domain'], 'spec_subdomain': i['spec_subdomain'], "spec_ftp_user": i['spec_ftp_user'], "spec_control_panel": i['spec_control_panel'], 'spec_email_account': i['spec_email_account'], "spec_spam_filter": i['spec_spam_filter'], "date_time": i['date_time'], "spec_features": i['spec_features'], "spec_features_value": i['spec_features_value'], "spec_features_price": i['spec_features_price'] } obj_userdata.append(data) respons = {"status": True, "messages": "Fine!"} finally: return response(200, data=obj_userdata, message=respons)
def post(self): url_env = os.getenv("SOCKET_AGENT_HOST") port = os.getenv("SOCKET_AGENT_PORT") url_fix = url_env + ":" + port url = url_fix + "/api/command_rest" json_req = request.get_json(force=True) command = utils.get_command(request.path) init_data = parse.parser(json_req, command) respons = dict() if init_data['action'] == 'conf-read': respons = cmd.conf_read() http_respons = utils.send_http(url, data=respons) return response(200, data=http_respons) if init_data['action'] == 'conf-insert': tags = dict() for i in init_data['data']: tags = i['tags'] respons = cmd.config_insert(tags) cmd.conf_begin_http(url) http_respons = utils.send_http(url, respons) if http_respons: # state change state = utils.change_state("id_zone", tags['id_zone'], "1") db.update("zn_zone", data=state) cmd.conf_commit_http(url) return response(200, data=http_respons) if init_data['action'] == 'zone-read': tags = dict() for i in init_data['data']: tags = i['tags'] respons = cmd.zone_read(tags) http_respons = utils.send_http(url, respons) return response(200, data=http_respons) if init_data['action'] == 'zone-soa-insert': result = list() for i in init_data['data']: tags = i['tags'] begin_json = cmd.zone_begin(tags) begin_respon = utils.send_http(url, begin_json) result.append(begin_respon) try: id_record, respons = cmd.zone_soa_insert_default(tags) except Exception as e: respons = {"Status": False, "Error": str(e)} return response(400, message=respons) else: http_respons = utils.send_http(url, respons) # state change if http_respons: state = utils.change_state("id_record", id_record, "1") db.update("zn_record", data=state) result.append(http_respons) commit_json = cmd.zone_commit(tags) commit_response = utils.send_http(url, commit_json) result.append(commit_response) return response(200, data=result) if init_data['action'] == 'zone-begin': for i in init_data['data']: tags = i['tags'] respons = cmd.zone_begin(tags) http_response = utils.send_http(url, respons) return response(200, data=http_response) if init_data['action'] == 'zone-commit': for i in init_data['data']: tags = i['tags'] respons = cmd.zone_commit(tags) http_response = utils.send_http(url, respons) return response(200, data=http_response) if init_data['action'] == 'zone-insert': respons = list() for i in init_data['data']: tags = i['tags'] json_begin = cmd.zone_begin_http(url, tags) respons.append(json_begin) json_command = cmd.zone_insert(tags) http_response = utils.send_http(url, json_command) # change state if http_response: state = utils.change_state("id_record", tags['id_record'], "1") try: db.update("zn_record", data=state) except Exception as e: print(e) respons.append(http_response) res_commit = cmd.zone_commit_http(url, tags) respons.append(res_commit) return response(200, data=respons) if init_data['action'] == 'zone-ns-insert': respons = list() for i in init_data['data']: tags = i['tags'] res_begin = cmd.z_begin(url, tags) respons.append(res_begin) try: result = cmd.zone_ns_insert(tags) except Exception as e: respons = {"Status": False, "Error": str(e)} return response(400, message=respons) else: for i in result: state = None http_response = utils.send_http(url, i['command']) # state change if http_response: state = utils.change_state("id_record", i['id_record'], "1") try: db.update("zn_record", data=state) except Exception as e: print(e) respons.append(http_response) res_commit = cmd.z_commit(url, tags) respons.append(res_commit) return response(200, data=respons) if init_data['action'] == 'zone-srv-insert': result = list() for i in init_data['data']: tags = i['tags'] begin_json = cmd.zone_begin_http(url, tags) # begin_respon = utils.send_http(url,begin_json) result.append(begin_json) try: respons = cmd.zone_insert_srv(tags) except Exception as e: respons = {"status": False, "error": str(e)} return response(400, data=result, message=respons) else: http_response = utils.send_http(url, respons) if http_response: state = utils.change_state("id_record", tags['id_record'], "1") try: db.update("zn_record", data=state) except Exception as e: print(e) result.append(http_response) commit_json = cmd.zone_commit_http(url, tags) # commit_response = utils.send_http(url,commit_json) result.append(commit_json) return response(200, data=result) if init_data['action'] == 'zone-mx-insert': result = list() for i in init_data['data']: tags = i['tags'] begin_json = cmd.zone_begin_http(url, tags) # begin_respon = utils.send_http(url,begin_json) result.append(begin_json) try: respons = cmd.zone_insert_mx(tags) except Exception as e: respons = {"status": False, "error": str(e)} return response(400, data=result, message=respons) else: http_response = utils.send_http(url, respons) # change state if http_respons: state = utils.change_state("id_record", tags['id_record'], "1") try: db.update("zn_record", data=state) except Exception as e: print(e) result.append(http_response) commit_json = cmd.zone_commit_http(url, tags) result.append(commit_json) return response(200, data=result) # delete all zone if init_data['action'] == 'conf-unset': result = list() for i in init_data['data']: tags = i['tags'] data = cmd.conf_unset(tags) cmd.conf_begin_http(url) http_respons = utils.send_http(url, data) cmd.conf_commit_http(url) return response(200, data=http_respons) if init_data['action'] == 'zone-unset': result = list() for i in init_data['data']: print(i) tags = i['tags'] respons = list() res_begin = cmd.zone_begin_http(url, tags) respons.append(res_begin) json_command = cmd.zone_unset(tags) http_response = utils.send_http(url, json_command) respons.append(http_response) res_commit = cmd.zone_commit_http(url, tags) respons.append(res_commit) return response(200, data=respons)
def post(self): json_req = request.get_json(force=True) command = utils.get_command(request.path) command = 'dt_' + command init_data = cmd.parser(json_req, command) respons = {} if init_data['action'] == 'insert': table = init_data['data'][0]['table'] fields = init_data['data'][0]['fields'] try: result = model.insert(table, fields) except Exception as e: respons = {"status": False, "error": str(e)} else: respons = {"status": True, "messages": "Success", "id": result} finally: return response(200, data=fields, message=respons) if init_data['action'] == 'remove': table = "" tags = dict() fields = "" for i in init_data['data']: table = i['table'] tags = i['tags'] fields = str(list(tags.keys())[0]) try: result = model.delete(table, fields, tags[fields]) except Exception as e: respons = {"status": False, "messages": str(e)} else: respons = {"status": result, "messages": "Success!"} finally: return response(200, data=tags, message=respons) if init_data['action'] == 'view': obj_userdata = list() table = "" fields = None tags = dict() for i in init_data['data']: table = i['table'] tags = i['tags'] for a in tags: if tags[a] is not None: fields = a column = model.get_columns("v_product_vm") try: result = list() if fields is None: query = """select * from v_product_vm""" db.execute(query) rows = db.fetchall() for row in rows: result.append(dict(zip(column, row))) else: query = """ select * from v_product_vm_test where """ + fields + """='""" + tags[ fields] + """'""" db.execute(query) rows = db.fetchall() for row in rows: result.append(dict(zip(column, row))) except Exception as e: respons = {"status": False, "messages": str(e)} else: for i in result: data = { "id_company": str(i['id_company']), "id_company_product": str(i['id_company_product']), "id_product": str(i['id_product']), 'id_vm': str(i['id_vm']), "id_additional_features": str(i['id_additional_features']), "nm_company": i['nm_company'], "url_company": i['url_company'], 'nm_company_product': i['nm_company_product'], "nm_product": i['nm_product'], "currency_used": i['currency_used'], 'spec_clock': i['spec_clock'], "spec_ram": i['spec_ram'], "spec_os": i['spec_os'], 'spec_storage_volume': i['spec_storage_volume'], "spec_ssd_volume": i['spec_ssd_volume'], "spec_snapshot_volume": i['spec_snapshot_volume'], "spec_template_volume": i['spec_template_volume'], 'spec_iso_volume': i['spec_iso_volume'], "spec_public_ip": i['spec_public_ip'], "spec_backup_storage": i['spec_backup_storage'], 'spec_features': i['spec_features'], "spec_features_value": i['spec_features_value'], "spec_features_price": i['spec_features_price'], 'spec_price': i['spec_price'], "date_time": i['date_time'] } obj_userdata.append(data) respons = {"status": True, "messages": "Fine!"} finally: return response(200, data=obj_userdata, message=respons) if init_data['action'] == 'where': obj_userdata = list() table = "" fields = "" tags = dict() for i in init_data['data']: table = i['table'] tags = i['tags'] for a in tags: if tags[a] is not None: fields = a try: result = model.get_by_id(table, fields, tags[fields]) except Exception as e: respons = {"status": False, "messages": str(e)} else: for i in result: data = { "id_vm": str(i['id_vm']), "id_company_product": str(i['id_company_product']), "spec_vcpu": i['spec_vcpu'], 'spec_clock': i['spec_clock'], "spec_ram": i['spec_ram'], "spec_os": i['spec_os'], "spec_storage_volume": i['spec_storage_volume'], 'spec_ssd_volume': i['spec_ssd_volume'], "spec_snapshot_volume": i['spec_snapshot_volume'], "spec_template_volume": i['spec_template_volume'], 'spec_iso_volume': i['spec_iso_volume'], "spec_public_ip": i['spec_public_ip'], "spec_backup_storage": i['spec_backup_storage'], 'spec_price': i['spec_price'], "spec_notes": i['spec_notes'], "date_time": i['date_time'] } obj_userdata.append(data) respons = {"status": True, "messages": "Fine!"} finally: return response(200, data=obj_userdata, message=respons)
def post(self): json_req = request.get_json(force=True) command = utils.get_command(request.path) command = "zn_" + command init_data = cmd.parser(json_req, command) respons = dict() if init_data['action'] == 'insert': table = init_data['data'][0]['table'] fields = init_data['data'][0]['fields'] try: result = model.insert(table, fields) except Exception as e: respons = {"status": False, "error": str(e)} else: respons = {"status": True, "messages": "Fine!", "id": result} finally: return response(200, data=fields, message=respons) if init_data['action'] == 'where': obj_userdata = list() table = "" fields = "" tags = dict() for i in init_data['data']: table = i['table'] tags = i['tags'] for a in tags: if tags[a] is not None: fields = a try: result = model.get_by_id(table, fields, tags[fields]) except Exception as e: respons = {"status": False, "messages": str(e)} else: for i in result: data = { "id_content": str(i['id_content']), "id_ttldata": str(i['id_ttldata']), "nm_content": str(i['nm_content']) } obj_userdata.append(data) respons = {"status": True, "messages": "Fine!"} finally: return response(200, data=obj_userdata, message=respons) if init_data['action'] == 'remove': table = "" tags = dict() fields = "" for i in init_data['data']: table = i['table'] tags = i['tags'] for a in tags: if tags[a] is not None: fields = a try: result = model.delete(table, fields, tags[fields]) except Exception as e: respons = {"status": False, "messages": str(e)} else: respons = {"status": result, "messages": "Fine Deleted!"} finally: return response(200, data=tags, message=respons) if init_data['action'] == 'view': obj_userdata = list() table = "" fields = None tags = dict() for i in init_data['data']: table = i['table'] tags = i['tags'] for a in tags: if tags[a] is not None: fields = a column = model.get_columns("v_contentdata") try: result = list() if fields is None: query = """select * from v_contentdata""" db.execute(query) rows = db.fetchall() for row in rows: result.append(dict(zip(column, row))) else: query = """ select * from v_contentdata where """ + fields + """='""" + tags[ fields] + """'""" db.execute(query) rows = db.fetchall() for row in rows: result.append(dict(zip(column, row))) except Exception as e: respons = {"status": False, "messages": str(e)} else: for i in result: data = { "id_content": str(i['id_content']), "nm_zone": str(i['nm_zone']), "nm_record": str(i['nm_record']), "nm_type": str(i['nm_type']), "nm_ttl": i['nm_ttl'], "id_record": str(i['id_record']), "nm_content": str(i['nm_content']), } obj_userdata.append(data) respons = {"status": True, "messages": "Fine!"} finally: return response(200, data=obj_userdata, message=respons)