def main_function(self):
     fv_tenant = self.check_if_tenant_exist()
     for filter in self.filters:
         createFilter.create_filter(fv_tenant,
                                    filter['name'],
                                    optional_args=filter['optional_args'])
     for contract in self.contracts:
         createContract.create_contract(
             fv_tenant,
             contract['name'],
             optional_args=contract['optional_args'])
def lab3(modir, tenant_name):
    """Following the lab guide, we create three filters and three contracts"""

    # Create filters
    create_filter(modir, tenant_name, 'Web_Filter', ether_type='ip', ip_protocol='tcp', destination_port_from='http', destination_port_to='http')
    create_filter(modir, tenant_name, 'App_Filter', ether_type='ip', ip_protocol='tcp', destination_port_from='1433', destination_port_to='1433')
    create_filter(modir, tenant_name, 'DB_Filter', ether_type='ip', ip_protocol='tcp', destination_port_from='1521', destination_port_to='1521')
    # Create contracts
    create_contract(modir, tenant_name, 'Web_Con', subject_name='web_subj', filter_name='Web_Filter')
    create_contract(modir, tenant_name, 'App_Con', subject_name='app_subj', filter_name='App_Filter')
    create_contract(modir, tenant_name, 'DB_Con', subject_name='db_subj', filter_name='DB_Filter')
def lab3(modir, tenant_name):
    """Following the lab guide, we create three filters and three contracts"""

    # Create filters
    create_filter(modir,
                  tenant_name,
                  'Web_Filter',
                  ether_type='ip',
                  ip_protocol='tcp',
                  destination_port_from='http',
                  destination_port_to='http')
    create_filter(modir,
                  tenant_name,
                  'App_Filter',
                  ether_type='ip',
                  ip_protocol='tcp',
                  destination_port_from='1433',
                  destination_port_to='1433')
    create_filter(modir,
                  tenant_name,
                  'DB_Filter',
                  ether_type='ip',
                  ip_protocol='tcp',
                  destination_port_from='1521',
                  destination_port_to='1521')
    # Create contracts
    create_contract(modir,
                    tenant_name,
                    'Web_Con',
                    subject_name='web_subj',
                    filter_name='Web_Filter')
    create_contract(modir,
                    tenant_name,
                    'App_Con',
                    subject_name='app_subj',
                    filter_name='App_Filter')
    create_contract(modir,
                    tenant_name,
                    'DB_Con',
                    subject_name='db_subj',
                    filter_name='DB_Filter')
Ejemplo n.º 4
0
import sys
from utility import *
import createFilter
import createContract


if __name__ == '__main__':

    # Login
    hostname, username, password = input_login_info(msg='')
    try:
        modir = apic_login(hostname, username, password)
        print 'Login succeed.'
    except KeyError:
        print 'Login fail.'
        sys.exit()

    # Wizard starts asking inputs step by step
    tenant_name = input_tenant_name()
    filter_array = add_mos_with_options(createFilter.input_key_args, createFilter.input_optional_args, 'Create a Filter')
    contract_array = add_mos_with_options(createContract.input_key_args, createContract.input_optional_args, 'Create a Contract')

    # Running
    for filter in filter_array:
        print filter, filter_array
        createFilter.create_filter(modir, tenant_name, filter[0], args_from_CLI=filter[1])
    for contract in contract_array:
        createContract.create_contract(modir, tenant_name, contract[0], args_from_CLI=contract[1])

    modir.logout()
    args = vars(parser.parse_args())

    try:
        data = read_config_yaml_file(args['yaml'], login_info=False)
    except IOError:
        print 'No such file or directory:', args['yaml']
        sys.exit()
    else:
        host, user, password = get_login_info(data)
        tenant = data['tenant']
    modir = apic_login(host, user, password)

    # Create filters
    for filter in data['filters']:
        create_filter(modir,
                      tenant,
                      filter['name'],
                      ether_type=filter['ether_type'],
                      ip_protocol=filter['ip_protocol'],
                      destination_port_from=filter['destination_port_from'],
                      destination_port_to=filter['destination_port_to'])
    # Create contracts
    for contract in data['contracts']:
        create_contract(modir,
                        tenant,
                        contract['name'],
                        subject_name=contract['subject_name'],
                        filter_name=contract['filter_name'])

    modir.logout()
    parser = argparse.ArgumentParser(description='Create three filters and three contracts.')
    parser.add_argument('yaml', help='Imported yaml file.')
    args = vars(parser.parse_args())

    try:
        data = read_config_yaml_file(args['yaml'], login_info=False)
    except IOError:
        print 'No such file or directory:', args['yaml']
        sys.exit()
    else:
        host, user, password = get_login_info(data)
        tenant = data['tenant']
    modir = apic_login(host, user, password)

    # Create filters
    for filter in data['filters']:
        create_filter(modir, tenant, filter['name'],
                      ether_type=filter['ether_type'],
                      ip_protocol=filter['ip_protocol'],
                      destination_port_from=filter['destination_port_from'],
                      destination_port_to=filter['destination_port_to'])
    # Create contracts
    for contract in data['contracts']:
        create_contract(modir, tenant, contract['name'],
                        subject_name=contract['subject_name'],
                        filter_name=contract['filter_name'])


    modir.logout()
 def main_function(self):
     fv_tenant = self.check_if_tenant_exist()
     for filter in self.filters:
         createFilter.create_filter(fv_tenant, filter['name'], optional_args=filter['optional_args'])
     for contract in self.contracts:
         createContract.create_contract(fv_tenant, contract['name'], optional_args=contract['optional_args'])