def validate_policy_handlers(api, rules, cluster_name, cluster_type): for rule in rules: protocol = str(rule.srcAddr.protocol).lower() if protocol == "http": if not (__validate_handler_params( api, ip=rule.srcAddr.primaryAddress, port=rule.srcAddr.secondaryAddress)): raise exceptions.ApiError( "source port {} is already taken".format( rule.srcAddr.secondaryAddress), 409) elif protocol == "mq": if not (__validate_handler_params( api, queue_manager=rule.srcAddr.primaryAddress, cluster_name=cluster_name, cluster_type=cluster_type)): raise exceptions.ApiError( "queue manager {} is not valid".format( rule.srcAddr.primaryAddress), 400) else: raise exceptions.ApiError("front handler protocol is not valid", 400) return True
def validate_mpgw_name_is_free(api, name): try: mpgw = api.mpgw.get(name) if mpgw: raise exceptions.ApiError( "MultiProtoclGateway name is already taken", 409) except Exception as e: if e.status_code == 409: raise exceptions.ApiError(e.message, 409) return True
def get_mqqm_cluster(cluster_name, cluster_type): try: cluster_creds = get_cluster_creds(cluster_name, cluster_type) cluster_data = get_cluster_data(cluster_name, cluster_type) if cluster_creds and cluster_data: api = init_dpapi_from_cluster(cluster_data, cluster_creds) return jsonify([qm["name"] for qm in api.mqqm.get_all()]) else: raise exceptions.ApiError("Not a valid cluster", 400) except exceptions.ApiError as e: raise exceptions.ApiError(e.message, e.status_code)
def is_policy_rules_exist(api, rules): for rule in rules: try: rule = api.rule.get(rule["name"]) if rule: raise exceptions.ApiError( "One of the provided rules already exists exist.", 409) except Exception as e: if e.status_code == 409: raise exceptions.ApiError(e.message, 409) return True
def get_filelist_cluster(cluster_name, cluster_type, parent): try: cluster_creds = get_cluster_creds(cluster_name, cluster_type) cluster_data = get_cluster_data(cluster_name, cluster_type) if cluster_creds and cluster_data: api = init_dpapi_from_cluster(cluster_data, cluster_creds) return jsonify(api.filestore.get_filelist_recursive("local")) else: raise exceptions.ApiError("Not a valid cluster", 400) except exceptions.ApiError as e: raise exceptions.ApiError(e.message, e.status_code)
def get_mq_handler(name): try: api = init_dpapi(request.args) mq_handler = api.mq_handler.get(name) return jsonify(mq_handler) except exceptions.ApiError as e: raise exceptions.ApiError(e.message, e.status_code)
def get_http_handlers(): try: api = init_dpapi(request.args) http_handlers = api.http_handler.get_all() return jsonify(http_handlers) except exceptions.ApiError as e: raise exceptions.ApiError(e.message, e.status_code)
def create_load_balncer_group(): try: api = init_dpapi(request.args) lbg_req = request.get_json(force=True) create_lbg(lbg_req, api) return success_response("Load Balancer Group {} was created successfully".format(lbg_req["name"])) except exceptions.ApiError as e: raise exceptions.ApiError(e.message, e.status_code)
def create_http_handler(): try: json_data = request.get_json(force=True) api = init_dpapi(request.args) handler = api.http_handler.create_from_dict(json_data["name"], fields=json_data) return success_response('HTTP Handler "' + handler["name"] + '" was created') except exceptions.ApiError as e: raise exceptions.ApiError(e.message, e.status_code)
def validate_handlers_exists(api, handlers): for handler in handlers: try: http_handler = api.http_handler.get(handler) except Exception as e: try: mq_handler = api.mq_handler.get(handler) except Exception as e: if e.status_code == 404: raise exceptions.ApiError( "One of the provided handlers doesn't exist.", 400) return True
def create_mpgw_from_template(): try: api = init_dpapi(request.args) req = request.get_json(force=True) mpgw = populate_mpgw_template(req, api) xml_manager_name = create_xml_manager(mpgw["name"], api) policy = create_style_policy(mpgw["rules"], mpgw["name"], api=api) api.mpgw.create(mpgw["name"], mpgw["handlers"], xml_manager_name, policy["name"], state="enabled", UserSummary=str(req)) return success_response('MultiProtocolGateway "' + mpgw["name"] + '" was created') except exceptions.ApiError as e: raise exceptions.ApiError(e.message, e.status_code)
def create_mq_handler(): try: json_data = request.get_json(force=True) handlers = [] api = init_dpapi(request.args) if isinstance(json_data, list): for handler_obj in json_data: api.mq_handler.create_from_dict(handler_obj["name"], fields=handler_obj) handlers.append(handler_obj["name"]) else: api.mq_handler.create_from_dict(json_data["name"], fields=json_data) return success_response('MQ Handler "' + json_data["name"] + '" was created') return success_response('MQ Handlers ' + str(handlers).strip('[]') + ' were created') except exceptions.ApiError as e: raise exceptions.ApiError(e.message, e.status_code)
def get_mqqm(): try: api = init_dpapi(request.args) return jsonify([qm["name"] for qm in api.mqqm.get_all()]) except exceptions.ApiError as e: raise exceptions.ApiError(e.message, e.status_code)