예제 #1
0
파일: fw.py 프로젝트: attameer/python_sdk
def fw_policies_example(controller_ip, username, password, gw_name):
    """
    Performs actions related to FW policies
    Arguments:
    controller_ip - string - the controller host or IP
    username - string - the controller login username
    password - string - the controller login password
    gw_name - string - name of a gateway to use for testing
    """
    controller = Aviatrix(controller_ip)
    controller.login(username, password)

    gwy = controller.get_gateway_by_name('admin', gw_name)
    if not gwy:
        print 'Gateway %s not found\n' % (gw_name)
        return

    current = controller.get_fw_policy_full(gw_name)
    print 'CURRENT POLICY: %s' % (current)

    rules = current['security_rules']
    rules.append({
        'protocol': 'all',
        's_ip': '192.168.1.0/24',
        'd_ip': '10.0.0.0/24',
        'deny_allow': 'allow',
        'port': '',
        'log_enable': 'off'
    })
    controller.set_fw_policy_security_rules(gw_name, rules)
    current = controller.get_fw_policy_full(gw_name)
    print 'CURRENT POLICY: %s' % (current)
예제 #2
0
def fqdn_example(controller_ip, username, password, gw_name):
    """
    Performs actions related to FQDN filters
    Arguments:
    controller_ip - string - the controller host or IP
    username - string - the controller login username
    password - string - the controller login password
    gw_name - string - name of a gateway
    """
    controller = Aviatrix(controller_ip)
    controller.login(username, password)

    gwy = controller.get_gateway_by_name('admin', gw_name)
    if not gwy:
        print 'Gateway %s not found\n' % (gw_name)
        return

    controller.enable_snat(gw_name)
    controller.add_fqdn_filter_tag('TEST_TAG')
    tags = controller.list_fqdn_filters()
    if 'TEST_TAG' not in tags:
        print 'TEST_TAG not found!\n'
        return

    controller.delete_fqdn_filter_tag('TEST_TAG')
    tags = controller.list_fqdn_filters()
    if 'TEST_TAG' in tags:
        print 'TEST_TAG found!\n'
        return
    controller.add_fqdn_filter_tag('TEST_TAG')
    try:
        controller.set_fqdn_filter_domain_list('TEST_TAG', ['*.google.com', 'cnn.com', '*.aviatrix.com'])
    except BaseException, e:
        print str(e)
        pass