def param_check(module, connection): res = True action = module.params['action'] err_msg = [] if (action == 'add' or action == 'edit' or action == 'delete') and not module.params['name']: err_msg.append('The name need to set.') res = False if action == 'add' and not module.params['status']: err_msg.append('The status need to set.') res = False if action == 'add' and not module.params['ip']: err_msg.append('The ip or ipv6 must be set.') res = False if is_vdom_enable(connection) and not module.params['vdom']: err_msg.append( 'The vdom is enable in system setting, vdom must be set.') res = False elif is_vdom_enable( connection) and module.params['vdom'] and not is_user_in_vdom( connection, module.params['vdom']): err_msg.append('The user can not accsee the vdom ' + module.params['vdom']) res = False return res, err_msg
def param_check(module, connection): res = True action = module.params['action'] err_msg = [] if (action == 'edit' or action == 'delete') and not module.params['route_id']: err_msg.append('The route_id need to set.') res = False if module.params['route_id']: try: i = int(module.params['route_id']) except ValueError: err_msg.append('The route_id must be integer.') res = False if action == 'add' and not module.params['desination']: err_msg.append('The desination need to set.') res = False if action == 'add' and not module.params['gateway']: err_msg.append('The gateway must be set.') res = False if is_vdom_enable(connection) and not module.params['vdom']: err_msg.append( 'The vdom is enable in system setting, vdom must be set.') res = False elif is_vdom_enable( connection) and module.params['vdom'] and not is_user_in_vdom( connection, module.params['vdom']): err_msg.append('The user can not accsee the vdom ' + module.params['vdom']) res = False return res, err_msg
def param_check(module, connection): res = True action = module.params['action'] err_msg = [] if (action == 'add' or action == 'edit' or action == 'delete') and not module.params['name']: err_msg.append('The name need to set.') res = False if action == 'add' and module.params['intf_type'] == 'physical': err_msg.append('can not create intface type physical.') res = False if action == 'add' and module.params['intf_type'] == 'vlan' and not module.params['vlanid']: err_msg.append('The vlan id must be set when interface type is vlan.') res = False if action == 'add' and module.params['intf_type'] == 'vlan' and not module.params['interface']: err_msg.append('The interface id must be set when interface type is vlan.') res = False #if action == 'edit' and module.params['intf_type'] == 'vlan' and module.params['vlanid']: # err_msg.append('Can not change vlan id.') # res = False #if action == 'edit' and module.params['intf_type'] == 'vlan' and module.params['interface']: # err_msg.append('Can not change interface.') # res = False if action == 'add' and not module.params['IPandMask'] and not module.params['IPv6andMask']: err_msg.append('The ip or ipv6 must be set.') res = False if is_vdom_enable(connection) and not module.params['vdom']: err_msg.append('The vdom is enable in system setting, vdom must be set.') res = False elif is_vdom_enable(connection) and module.params['vdom'] and not is_user_in_vdom(connection, module.params['vdom']): err_msg.append('The user can not accsee the vdom ' + module.params['vdom']) res = False return res, err_msg
def add_interface(module, connection): name = module.params['name'] mode = module.params['mode'] status = module.params['status'] IPandMask = module.params['IPandMask'] IPv6andMask = module.params['IPv6andMask'] allowaccess = list_to_str(module.params['allowaccess']) intf_type = module.params['intf_type'] vlanid = module.params['vlanid'] vdom = module.params['vdom'] interface = module.params['interface'] mtu = module.params['mtu'] aggregate_algorithm = module.params['aggregate_algorithm'] aggregate_mode = module.params['aggregate_mode'] default_gw = module.params['default_gw'] dhcp_gw_override = module.params['dhcp_gw_override'] dhcp_gw_distance = module.params['dhcp_gw_distance'] disc_retry_timeout = module.params['disc_retry_timeout'] pppoe_username = module.params['pppoe_username'] pppoe_passwd = module.params['pppoe_passwd'] floating = module.params['floating'] floating_ip = module.params['floating_ip'] redundant_member = list_to_str(module.params['redundant_member']) traffic_group = module.params['traffic_group'] payload = {'mkey': name, 'mode': mode, 'mtu' : mtu, 'ip' : IPandMask, 'ip6' : IPv6andMask, 'interface' : interface, 'allowaccess' : allowaccess, 'type' : intf_type, 'vdom' : vdom, 'vlanid' : vlanid, 'status' : status, 'aggregate-algorithm': aggregate_algorithm, 'aggregate-mode' : aggregate_mode, 'dedicate-to-management' : 'disable', 'default-gw' : default_gw, 'dhcp_gw_distance' : dhcp_gw_distance, 'dhcp_gw_override' : dhcp_gw_override, 'dhcp_ip_overlap' : '1', 'disc-retry-timeout' : disc_retry_timeout, 'dns-server-override' : 'enable', 'floating' : floating, 'floating-ip' : floating_ip, 'redundant-member' : redundant_member, 'secondary-ip' : 'disable', 'traffic-group' : traffic_group, 'username' : pppoe_username, } url = '/api/system_interface' if is_vdom_enable(connection) and not is_global_admin(connection): url += '?vdom=' + vdom code, response = connection.send_request(url, payload) return code, response
def add_basic_vs(module, connection): name = module.params['name'] application = module.params['application'] address = module.params['address'] interface = module.params['interface'] pool = module.params['pool'] port = module.params['port'] vdom = module.params['vdom'] payload = { 'mkey': name, 'application': application, 'address': address, 'interface': interface, 'pool': pool, 'port': port } url = '/api/load_balance_virtual_server/vs_advanced_edit' if is_vdom_enable(connection): url += '?vdom=' + vdom code, response = connection.send_request(url, payload) response['post'] = payload return code, response
def add_rs_pool(module, connection): name = module.params['name'] iptype = module.params['iptype'] healthcheck = module.params['healthcheck'] health_check_relationship = module.params['health_check_relationship'] health_check_list = list_to_str(module.params['health_check_list']) rs_profile = module.params['rs_profile'] vdom = module.params['vdom'] payload = { 'mkey': name, 'pool_type': iptype, 'health_check': healthcheck, 'health_check_relationship': health_check_relationship, 'health_check_list': health_check_list, 'rs_profile': rs_profile } url = '/api/load_balance_pool' if is_vdom_enable(connection): url += '?vdom=' + vdom code, response = connection.send_request(url, payload) return code, response
def add_nat_pool(module, connection): pkey = module.params['natpool_name'] name = module.params['name'] interface = module.params['interface'] pooltype = module.params['pooltype'] ipmin = module.params['ipmin'] ipmax = module.params['ipmax'] vdom = module.params['vdom'] payload = {'mkey': name, 'interface': interface, 'pool_type': pooltype, } if pooltype == 'ipv6': payload['ip6_max'] = ipmax payload['ip6_min'] = ipmin else: payload['ip_max'] = ipmax payload['ip_min'] = ipmin url = '/api/load_balance_ippool_child_node_member?pkey=' + pkey if is_vdom_enable(connection): url += '?vdom=' + vdom code, response = connection.send_request(url, payload) return code, response
def add_nat_pool(module, connection): name = module.params['name'] interface = module.params['interface'] iptype = module.params['iptype'] ipstart = module.params['ipstart'] ipend = module.params['ipend'] vdom = module.params['vdom'] payload = { 'mkey': name, 'interface': interface, 'pool_type': iptype, } if iptype == 'ipv6': payload['ip6-start'] = ipstart payload['ip6-end'] = ipend else: payload['ip-start'] = ipstart payload['ip-end'] = ipend url = '/api/load_balance_ippool' if is_vdom_enable(connection): url += '?vdom=' + vdom code, response = connection.send_request(url, payload) return code, response
def edit_rs(module, payload, connection): name = module.params['name'] url = '/api/load_balance_real_server?mkey=' + name if is_vdom_enable(connection): vdom = module.params['vdom'] url += '&vdom=' + vdom code, response = connection.send_request(url, payload, 'PUT') return code, response
def edit_route_static(module, payload, connection): name = module.params['route_id'] url = '/api/router_static?mkey=' + name if is_vdom_enable(connection): vdom = module.params['vdom'] url += '&vdom=' + vdom code, response = connection.send_request(url, payload, 'PUT') return code, response
def edit_interface(module, payload, connection): name = module.params['name'] url = '/api/system_interface?mkey=' + name if is_vdom_enable(connection) and not is_global_admin(connection): vdom = module.params['vdom'] url += '&vdom=' + vdom code, response = connection.send_request(url, payload, 'PUT') return code, response
def delete_rs_pool(module, connection): name = module.params['name'] vdom = module.params['vdom'] payload = {} url = '/api/load_balance_pool?mkey=' + name if is_vdom_enable(connection): vdom = module.params['vdom'] url += '&vdom=' + vdom code, response = connection.send_request(url, payload, 'DELETE') return code, response
def add_rs_pool_member(module, connection): pkey = module.params['pool_name'] member_id = module.params['member_id'] port = module.params['port'] rs = module.params['rs'] status = module.params['status'] recover = module.params['recover'] rs_profile_inherit = module.params['rs_profile_inherit'] rs_profile = module.params['rs_profile'] warmrate = module.params['warmrate'] weight = module.params['weight'] warmup = module.params['warmup'] backup = module.params['backup'] connlimit = module.params['connlimit'] connection_ratelimit = module.params['connection_ratelimit'] cookie = module.params['cookie'] health_check_inherit = module.params['health_check_inherit'] health_check = module.params['health_check'] health_check_list = list_to_str(module.params['health_check_list']) health_check_relationship = module.params['health_check_relationship'] mysql_group_id = module.params['mysql_group_id'] mysql_read_only = module.params['mysql_read_only'] vdom = module.params['vdom'] payload = { 'mkey': member_id, 'status': status, 'real_server_id': rs, 'port': port, 'recover': recover, 'rs_profile_inherit': rs_profile_inherit, 'weight': weight, 'warmup': warmup, 'warmrate': warmrate, 'connlimit': connlimit, 'connection-rate-limit': connection_ratelimit, 'cookie': cookie, 'health_check_inherit': health_check_inherit, 'm_health_check': health_check, 'm_health_check_list': health_check_list, 'm_health_check_relationship': health_check_relationship, 'mysql_group_id': mysql_group_id, 'mysql_read_only': mysql_read_only, 'backup': backup, 'rs_profile': rs_profile, } url = '/api/load_balance_pool_child_pool_member?pkey=' + pkey if is_vdom_enable(connection): url += '&vdom=' + vdom code, response = connection.send_request(url, payload) return code, response
def edit_rs_pool(module, payload, connection): name = module.params['name'] vdom = module.params['vdom'] url = '/api/load_balance_pool?mkey=' + name if is_vdom_enable(connection): vdom = module.params['vdom'] url += '&vdom=' + vdom logger.debug(payload) code, response = connection.send_request(url, payload, 'PUT') return code, response
def main(): argument_spec = dict( name=dict(type='str', required=True), application=dict(type='str', required=True), address=dict(type='str', required=True), interface=dict(type='str', required=True), pool=dict(type='str', required=True), port=dict(type='str', required=True), ssl=dict(type='str', default='disable'), ssl_profile=dict(type='str'), vdom=dict(type='str'), ) argument_spec.update(fadcos_argument_spec) result = {} required_if = [('name')] module = AnsibleModule(argument_spec=argument_spec, required_if=required_if) connection = Connection(module._socket_path) if is_vdom_enable(connection) and not module.params['vdom']: result['err_msg'] = 'The vdom is enable, please set vdom' result['failed'] = True elif is_vdom_enable( connection) and module.params['vdom'] and not is_user_in_vdom( connection, module.params['vdom']): result[ 'err_msg'] = 'The user can not accsee the vdom ' + module.params[ 'vdom'] result['failed'] = True else: code, response = add_basic_vs(module, connection) result = {'code': code} result['res'] = response result['changed'] = True if 'res' in result.keys() and type(result['res']) is dict\ and type(result['res']['payload']) is int and result['res']['payload'] < 0: result['err_msg'] = get_err_msg(connection, result['res']['payload']) result['changed'] = False result['failed'] = True module.exit_json(**result)
def edit_nat_pool(module, payload, connection): pkey = module.params['natpool_name'] name = module.params['name'] vdom = module.params['vdom'] url = '/api/load_balance_ippool_child_node_member?pkey=' + pkey +'&mkey=' + name if is_vdom_enable(connection): vdom = module.params['vdom'] url += '&vdom=' + vdom code, response = connection.send_request(url, payload, 'PUT') return code, response
def edit_rs_pool_member(module, payload, connection): member_id = module.params['member_id'] pkey = module.params['pool_name'] vdom = module.params['vdom'] url = '/api/load_balance_pool_child_pool_member?pkey=' + pkey + '&mkey=' + member_id if is_vdom_enable(connection): vdom = module.params['vdom'] url += '&vdom=' + vdom code, response = connection.send_request(url, payload, 'PUT') return code, response
def get_route_static(module, connection): name = module.params['route_id'] payload = {} url = '/api/router_static' if name: url += '?mkey=' + name if is_vdom_enable(connection): vdom = module.params['vdom'] if name: url += '&vdom=' + vdom else: url += '?vdom=' + vdom code, response = connection.send_request(url, payload, 'GET') return code, response
def edit_nat_pool(module, payload, connection): name = module.params['name'] vdom = module.params['vdom'] url = '/api/load_balance_ippool' if name: url += '?mkey=' + name if is_vdom_enable(connection): vdom = module.params['vdom'] if name: url += '&vdom=' + vdom else: url += '?vdom=' + vdom code, response = connection.send_request(url, payload, 'PUT') return code, response
def get_vs(module, connection): name = module.params['name'] vdom = module.params['vdom'] payload = {} url = '/api/load_balance_virtual_server' if name: url += '?mkey=' + name if is_vdom_enable(connection): vdom = module.params['vdom'] if name: url += '&vdom=' + vdom else: url += '?vdom=' + vdom code, response = connection.send_request(url, payload, 'GET') return code, response
def main(): argument_spec = dict( action=dict(type='str', required=True), name=dict(type='str', required=True), ) argument_spec.update(fadcos_argument_spec) required_if = [('name')] module = AnsibleModule(argument_spec=argument_spec, required_if=required_if) connection = Connection(module._socket_path) action = module.params['action'] result = {} if not is_vdom_enable(connection): result['err_msg'] = 'vdom is disable in system setting, please check' result['failed'] = True elif action == 'add': code, response = add_vdom(module, connection) result['res'] = response result['changed'] = True elif action == 'get': code, response = get_vdom(module, connection) result['res'] = response elif action == 'delete': code, data = get_vdom(module, connection) if 'payload' in data.keys() and data['payload'] and type( data['payload']) is not int: code, response = delete_vdom(module, connection) result['res'] = response result['changed'] = True else: result['failed'] = True res = False result['err_msg'] = 'Entry not found' else: result['err_msg'] = 'error action: ' + action result['failed'] = True if 'res' in result.keys() and type(result['res']) is dict\ and type(result['res']['payload']) is int and result['res']['payload'] < 0: result['err_msg'] = get_err_msg(connection, result['res']['payload']) result['changed'] = False result['failed'] = True module.exit_json(**result)
def add_rs(module, connection): name = module.params['name'] status = module.params['status'] ip = module.params['ip'] ipv6 = module.params['ipv6'] vdom = module.params['vdom'] payload = {'mkey': name, 'status': status, 'address': ip, 'address6': ipv6, } url = '/api/load_balance_real_server' if is_vdom_enable(connection): url += '?vdom=' + vdom code, response = connection.send_request(url, payload) return code, response
def add_route_static(module, connection): route_id = module.params['route_id'] desination = module.params['desination'] gateway = module.params['gateway'] distance = module.params['distance'] vdom = module.params['vdom'] payload = { 'mkey': route_id, 'dest': desination, 'distance': distance, 'gw': gateway, } url = '/api/router_static' if is_vdom_enable(connection): url += '?vdom=' + vdom code, response = connection.send_request(url, payload) return code, response
def add_vs(module, connection): name = module.params['name'] status = module.params['status'] iptype = module.params['iptype'] ip = module.params['ip'] public_iptype = module.params['public_iptype'] public_ip = module.params['public_ip'] interface = module.params['interface'] vstype = module.params['vstype'] pool = module.params['pool'] port = module.params['port'] profile = module.params['profile'] method = module.params['method'] ssl_mirror = module.params['ssl_mirror'] ssl_mirror_intf = module.params['ssl_mirror_intf'] traffic_group = module.params['traffic_group'] traffic_log = module.params['traffic_log'] trans_rate_limit = module.params['trans_rate_limit'] warmrate = module.params['warmrate'] warmup = module.params['warmup'] alone = module.params['alone'] av_profile = module.params['av_profile'] client_ssl_profile = module.params['client_ssl_profile'] clone_pool = module.params['clone_pool'] clone_traffic_type = module.params['clone_traffic_type'] connection_limit = module.params['connection_limit'] connection_rate_limit = module.params['connection_rate_limit'] content_rewriting = module.params['content_rewriting'] content_rewriting_list = list_to_str( module.params['content_rewriting_list']) content_routing = module.params['content_routing'] content_routing_list = list_to_str(module.params['content_routing_list']) schedule_list = module.params['schedule_list'] schedule_pool_list = list_to_str(module.params['schedule_pool_list']) scripting_flag = module.params['scripting_flag'] scripting_list = list_to_str(module.params['scripting_list']) source_pool_list = list_to_str(module.params['source_pool_list']) waf_profile = module.params['waf_profile'] http2https = module.params['http2https'] http2https_port = module.params['http2https_port'] l2_exception_list = module.params['l2_exception_list'] packet_fwd_method = module.params['packet_fwd_method'] pagespeed = module.params['pagespeed'] persistence = module.params['persistence'] protocol = module.params['protocol'] adfs_published_service = module.params['adfs_published_service'] error_msg = module.params['error_msg'] error_page = module.params['error_msg'] fortiview = module.params['fortiview'] wccp = module.params['wccp'] comments = module.params['comments'] vdom = module.params['vdom'] payload = { 'mkey': name, 'addr-type': iptype, 'public-ip-type': public_iptype, 'interface': interface, 'status': status, 'pool': pool, 'port': port, 'alone': alone, 'type': vstype, 'profile': profile, 'method': method, 'ssl-mirror': ssl_mirror, 'ssl-mirror-intf': ssl_mirror_intf, 'traffic-group': traffic_group, 'traffic-log': traffic_log, 'trans-rate-limit': trans_rate_limit, 'warmrate': warmrate, 'warmup': warmup, 'av-profile': av_profile, 'client_ssl_profile': client_ssl_profile, 'clone-pool': clone_pool, 'clone-traffic-type': clone_traffic_type, 'connection-limit': connection_limit, 'connection-rate-limit': connection_rate_limit, 'content-rewriting': content_rewriting, 'content-rewriting-list': content_rewriting_list, 'content-routing': content_routing, 'content-routing-list': content_routing_list, 'schedule-list': schedule_list, 'schedule-pool-list': schedule_pool_list, 'scripting_flag': scripting_flag, 'scripting_list': scripting_list, 'source-pool-list': source_pool_list, 'waf-profile': waf_profile, 'http2https': http2https, 'http2https-port': http2https_port, 'l2-exception-list': l2_exception_list, 'packet-fwd-method': packet_fwd_method, 'pagespeed': pagespeed, 'persistence': persistence, 'protocol': protocol, 'adfs-published-service': adfs_published_service, 'error-msg': error_msg, 'error-page': error_page, 'comments': comments, 'fortiview': fortiview, 'wccp': wccp } if iptype == 'ipv6': payload['address6'] = ip else: payload['address'] = ip if public_iptype == 'ipv6' and module.params['public_ip']: payload['public-ip6'] = public_ip elif module.params['public_ip']: payload['public-ip'] = public_ip url = '/api/load_balance_virtual_server' if is_vdom_enable(connection): url += '?vdom=' + vdom code, response = connection.send_request(url, payload) return code, response