当前位置: 首页>>代码示例>>Python>>正文


Python acitoolkit.Session类代码示例

本文整理汇总了Python中acitoolkit.Session的典型用法代码示例。如果您正苦于以下问题:Python Session类的具体用法?Python Session怎么用?Python Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Session类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_inherit_contract_and_delete

    def test_inherit_contract_and_delete(self):
        self.delete_tenant()
        config_json = self.get_config_json()
        args = TestArgs()
        apic = Session(APIC_URL, APIC_USERNAME, APIC_PASSWORD)
        apic.login()
        self.setup_tenant(apic)
        tool = execute_tool(args, cli_mode=False)
        tool.add_config(config_json)
        time.sleep(2)

        # Verify that the contract is not inherited by the child EPG
        self.verify_not_inherited(apic)
        time.sleep(2)

        # Add the contract
        self.add_contract(apic)
        time.sleep(2)

        # Verify that the contract is now inherited by the child EPG
        self.verify_inherited(apic)

        # Remove the contract from the parent EPG
        self.remove_contract(apic)
        time.sleep(2)

        # Verify that the contract is not inherited by the child EPG
        self.verify_not_inherited(apic)

        self.delete_tenant()
开发者ID:bischatt78,项目名称:acitoolkit,代码行数:30,代码来源:inheritance_test.py

示例2: main

def main():
    """
    Main execution routine

    :return: None
    """
    # Take login credentials from the command line if provided
    # Otherwise, take them from your environment variables file ~/.profile
    description = ('Simple application that logs on to the APIC and displays all'
                   ' of the physical nodes; both belonging to and connected to the fabric.')
    creds = Credentials('apic', description)
    args = creds.get()

    # Login to APIC
    session = Session(args.url, args.login, args.password)
    resp = session.login()
    if not resp.ok:
        print('%% Could not login to APIC')
        sys.exit(0)

    # List of classes to get and print
    phy_classes = (Node, ExternalSwitch)

    for phy_class in phy_classes:
        # Print the class name
        class_name = phy_class.__name__
        print(class_name)
        print('=' * len(class_name))

        # Get and print all of the items from the APIC
        items = phy_class.get(session)
        for item in items:
            print(item.info())
开发者ID:JMSrulez,项目名称:acitoolkit,代码行数:33,代码来源:aci-show-nodes.py

示例3: main

def main():
    """
    Main common routine for show interface description
    :return: None
    """
    # Set up the command line options
    creds = Credentials(['apic', 'nosnapshotfiles'],
                        description=("This application replicates the switch "
                                     "CLI command 'show interface description'"))
    creds.add_argument('-s', '--switch',
                       type=str,
                       default=None,
                       help='Specify a particular switch id, e.g. "101"')
    creds.add_argument('-i', '--interface',
                       type=str,
                       default=None,
                       help='Specify a specific interface, e.g. "eth1/1"')
    args = creds.get()

    # Login to APIC
    apic = Session(args.url, args.login, args.password)
    if not apic.login().ok:
        print('%% Could not login to APIC')
        return

    # Show interface description
    node_ids = get_node_ids(apic, args)
    apic_intf_classes = ['l1PhysIf', 'pcAggrIf', 'l3EncRtdIf', 'sviIf',
                         'tunnelIf', 'mgmtMgmtIf', 'l3LbRtdIf']
    for apic_intf_class in apic_intf_classes:
        show_interface_description(apic, node_ids, apic_intf_class=apic_intf_class,
                                   specific_interface=args.interface)
开发者ID:amney,项目名称:acitoolkit,代码行数:32,代码来源:aci-show-interface-description.py

示例4: main

def main():
    """
    Main execution routine
    """
    description = ('Simple application that logs on to the APIC'
                   ' and displays usage information for a given DN')
    creds = Credentials('apic', description)
    creds.add_argument("-d", "--dn_name",
                       help="DN to query for usage information")

    args = creds.get()

    session = Session(args.url, args.login, args.password)
    resp = session.login()
    if not resp.ok:
        print('%% Could not login to APIC')
    url = '/api/mo/{}.json?query-target=children&target-subtree-class=relnFrom'
    url = url.format(args.dn_name)

    resp = session.get(url)

    if resp.ok:
        used_by = resp.json()['imdata']
        for item in used_by:
            kls = next(iter(item))
            attributes = item[kls]['attributes']
            data.append((attributes['tDn'], kls))
    print(tabulate(data, headers=["Used by", "Class"]))
开发者ID:datacenter,项目名称:acitoolkit,代码行数:28,代码来源:aci-where-used.py

示例5: main

def main():
    """
    Main show Process routine
    :return: None
    """
    description = 'Simple application that logs on to the APIC and check cluster information for a fabric'
    creds = Credentials('apic', description)

    args = creds.get()

    session = Session(args.url, args.login, args.password)
    resp = session.login()
    if not resp.ok:
        print '%% Could not login to APIC'
        sys.exit(0)

    cluster = Cluster.get(session)

    if (cluster.config_size != cluster.cluster_size):
        print("*******************************************************")
        print ("WARNING, configured cluster size "), cluster.config_size
        print (":   not equal to the actual size "), cluster.cluster_size
        print "WARNING, desired stats collection might be lost"
        print("*******************************************************")
        print("APICs in the cluster"), cluster.name, (":")
        for apic in cluster.apics:
            print json.dumps(apic, indent=4, sort_keys=True)
    else:
        print("PASS")
开发者ID:aidan-,项目名称:acitoolkit,代码行数:29,代码来源:aci-check-cluster.py

示例6: main

def main():
    """
    Main execution routine

    :return: None
    """
    creds = Credentials('apic')
    creds.add_argument('--tenant', help='The name of Tenant')
    creds.add_argument('--app', help='The name of ApplicationProfile')
    creds.add_argument('--bd', help='The name of BridgeDomain')
    creds.add_argument('--epg', help='The name of EPG')
    creds.add_argument('--json', const='false', nargs='?', help='Json output only')

    args = creds.get()
    session = Session(args.url, args.login, args.password)
    session.login()

    tenant = Tenant(args.tenant)
    app = AppProfile(args.app, tenant)
    bd = BridgeDomain(args.bd, tenant)
    epg = EPG(args.epg, app)
    epg.add_bd(bd)

    if args.json:
        print(tenant.get_json())
    else:
        resp = session.push_to_apic(tenant.get_url(),
                                    tenant.get_json())

        if not resp.ok:
            print('%% Error: Could not push configuration to APIC')
            print(resp.text)
开发者ID:datacenter,项目名称:acitoolkit,代码行数:32,代码来源:aci-create-epg.py

示例7: test_basic_inherit_add_subnet

    def test_basic_inherit_add_subnet(self):
        config_json = {
            "apic": {
                "user_name": APIC_USERNAME,
                "password": APIC_PASSWORD,
                "ip_address": APIC_IP,
                "use_https": False
            },
            "inheritance_policies": [
                {
                    "epg": {
                        "tenant": "inheritanceautomatedtest",
                        "epg_container": {
                            "name": "myl3out",
                            "container_type": "l3out"
                        },
                        "name": "childepg"
                    },
                    "allowed": True,
                    "enabled": True
                },
                {
                    "epg": {
                        "tenant": "inheritanceautomatedtest",
                        "epg_container": {
                            "name": "myl3out",
                            "container_type": "l3out"
                        },
                        "name": "parentepg"
                    },
                    "allowed": True,
                    "enabled": False
                }
            ]
        }
        args = TestArgs()
        apic = Session(APIC_URL, APIC_USERNAME, APIC_PASSWORD)
        apic.login()
        self.setup_tenant(apic)
        tool = execute_tool(args, cli_mode=False)
        tool.add_config(config_json)
        time.sleep(2)

        # Verify that the contract is not inherited by the child EPG
        self.verify_not_inherited(apic)

        # Add the child subnet
        self.add_child_subnet(apic)
        time.sleep(2)

        # Verify that the contract is now inherited by the child EPG
        self.verify_inherited(apic)

        self.delete_tenant()
开发者ID:bischatt78,项目名称:acitoolkit,代码行数:54,代码来源:inheritance_test.py

示例8: main

def main():
    # Set up the Command Line options
    creds = Credentials(('apic', 'nosnapshotfiles'), description='')
    creds.add_argument('--printonly', action='store_true',
                       help='Only print the JSON but do not push to APIC.')
    group = creds.add_mutually_exclusive_group()
    group.add_argument('--config', default=None,
                       help='Optional .ini file providing failure scenario configuration')
    group.add_argument('--delete', action='store_true',
                       help='Delete ALL of the randomized configuration from the APIC')
    args = creds.get()

    # Login to APIC
    session = Session(args.url, args.login, args.password)
    resp = session.login()
    if not resp.ok:
        print('%% Could not login to APIC')
        print resp.status_code, resp.text
        return

    # Handle the delete case
    if args.delete:
        delete_all_randomized_tenants(session)
        return

    # Ensure that a config file has been given
    if args.config is None:
        print '%% Expected --config or --delete option'
        return

    config = ConfigParser.ConfigParser()
    config.read(args.config)
    randomizer = ConfigRandomizer(config)
    interfaces = ['eth 1/101/1/17', 'eth 1/102/1/17']
    randomizer.create_random_config(interfaces)
    flows = randomizer.get_flows(1)
    flow_json = []
    for flow in flows:
        flow_json.append(flow.get_json())
    flow_json = json.dumps({'flows': flow_json})

    for tenant in randomizer.tenants:
        print 'TENANT CONFIG'
        print '-------------'
        print tenant.get_json()
        print
        print
        if not args.printonly:
            resp = tenant.push_to_apic(session)
            if not resp.ok:
                print resp.status_code, resp.text
            assert resp.ok
    print 'Total number of tenants pushed:', len(randomizer.tenants)
开发者ID:aidan-,项目名称:acitoolkit,代码行数:53,代码来源:aci_configuration_randomizer.py

示例9: main

def main():
    """
    Main execution routine
    """
    description = 'Simple application that logs on to the APIC and displays all of the Tenants.'
    creds = Credentials('apic', description)
    creds.add_argument(
        "-d",
        "--domain-name",
        type=str,
        help="list of domains. usage -d tennat.infra")
    creds.add_argument(
        "-t",
        "--tenant-name",
        type=str,
        help="name of the tenant of which faults are to be displayed. If not given faults of all the tenants are shown")
    creds.add_argument('--continuous', action='store_true',
                       help='Continuously monitor for faults')
    args = creds.get()

    # Login to APIC
    session = Session(args.url, args.login, args.password)
    resp = session.login()
    if not resp.ok:
        print('%% Could not login to APIC')
        return

    faults_obj = Faults()
    fault_filter = None
    if args.domain_name is not None:
        fault_filter = {'domain': args.domain_name.split(',')}
    tenant_name = None
    if args.tenant_name is not None:
        tenant_name = args.tenant_name

    faults_obj.subscribe_faults(session, fault_filter)
    while faults_obj.has_faults(session, fault_filter) or args.continuous:
        if faults_obj.has_faults(session, fault_filter):
            faults = faults_obj.get_faults(
                session, fault_filter=fault_filter, tenant_name=tenant_name)
            if faults is not None:
                for fault in faults:
                    if fault is not None:
                        print "---------------"
                        if fault.descr is not None:
                            print "     descr     : " + fault.descr
                        else:
                            print "     descr     : " + "  "
                        print "     dn        : " + fault.dn
                        print "     rule      : " + fault.rule
                        print "     severity  : " + fault.severity
                        print "     type      : " + fault.type
                        print "     domain    : " + fault.domain
开发者ID:amney,项目名称:acitoolkit,代码行数:53,代码来源:aci-show-faults-by-domain.py

示例10: main

def main():
    """
    Main execution routine

    :return: None
    """
    # Take login credentials from the command line if provided
    # Otherwise, take them from your environment variables file ~/.profile
    description = ('Application dealing with tenant configuration. '
                   'It can download a tenant configuration from the APIC and store it as raw JSON in a file. '
                   'It can also push a tenant configuration stored as raw JSON in a file to the APIC.')
    creds = Credentials(('apic', 'nosnapshotfiles'), description)
    creds.add_argument('--config', default=None, help='Configuration file to push/pull tenant configuration')
    creds.add_argument('--tenant', default=None, help='Tenant name')
    group = creds.add_mutually_exclusive_group()
    group.add_argument('--push-to-apic', action='store_true',
                       help='Push the tenant configuration file to the APIC')
    group.add_argument('--pull-from-apic', action='store_true',
                       help=('Pull the tenant configuration from the APIC and'
                             'store in the specified configuration file'))

    # Get the command line arguments
    args = creds.get()

    # Sanity check the command line arguments
    if args.config is None:
        print '%% No configuration file given.'
        creds.print_help()
        return
    if args.tenant is None:
        print '%% No Tenant name given.'
        creds.print_help()
        return
    if not args.push_to_apic and not args.pull_from_apic:
        print '%% No direction (push-to-apic/pull-from-apic) given.'
        creds.print_help()
        return

    # Login to APIC
    session = Session(args.url, args.login, args.password)
    resp = session.login()
    if not resp.ok:
        print '%% Could not login to APIC'
        return

    # Do the work
    if args.pull_from_apic:
        pull_config_from_apic(session, args.tenant, args.config)

    if args.push_to_apic:
        push_config_to_apic(session, args.tenant, args.config)
开发者ID:JMSrulez,项目名称:acitoolkit,代码行数:51,代码来源:aci-copy-tenant-config.py

示例11: delete_tenant

 def delete_tenant(self):
     tenant = Tenant('inheritanceautomatedtest')
     tenant.mark_as_deleted()
     apic = Session(APIC_URL, APIC_USERNAME, APIC_PASSWORD)
     apic.login()
     resp = tenant.push_to_apic(apic)
     self.assertTrue(resp.ok)
     time.sleep(4)
     resp = tenant.push_to_apic(apic)
     self.assertTrue(resp.ok)
     time.sleep(2)
     tenants = Tenant.get(apic)
     for tenant in tenants:
         self.assertTrue(tenant.name != 'inheritanceautomatedtest')
开发者ID:bischatt78,项目名称:acitoolkit,代码行数:14,代码来源:inheritance_test.py

示例12: main

def main():
    # Set up the Command Line options
    creds = Credentials(('apic', 'nosnapshotfiles'), description='')
    group = creds.add_mutually_exclusive_group()
    group.add_argument('--config', default=None,
                       help='Optional .ini file providing failure scenario configuration')
    group.add_argument('--delete', action='store_true',
                       help='Delete ALL of the randomized configuration from the APIC')
    args = creds.get()

    # Login to APIC
    session = Session(args.url, args.login, args.password)
    resp = session.login()
    if not resp.ok:
        print('%% Could not login to APIC')
        print resp.status_code, resp.text
        return

    # Handle the delete case
    if args.delete:
        delete_all_randomized_tenants(session)
        return

    # Ensure that a config file has been given
    if args.config is None:
        print '%% Expected --config or --delete option'
        return

    config = ConfigParser.ConfigParser()
    config.read(args.config)

    # Handle the random creation
    num_tenants = random_number(int(config.get('Tenants', 'Minimum')),
                                int(config.get('Tenants', 'Maximum')))
    for i in range(0, num_tenants):
        tenant = create_random_tenant_config(config)
        print 'TENANT CONFIG'
        print '-------------'
        print tenant.get_json()
        print
        print
        resp = tenant.push_to_apic(session)
        if not resp.ok:
            print resp.status_code, resp.text
        assert resp.ok
    print 'Total number of tenants pushed:', num_tenants
开发者ID:dyoshiha,项目名称:acitoolkit,代码行数:46,代码来源:aci_configuration_randomizer.py

示例13: __init__

 def __init__(self, url, login, password):
     # Login to APIC
     self._apic = Session(url, login, password)
     if not self._apic.login().ok:
         self._logged_in = False
         print '%% Could not login to APIC'
     else:
         self._logged_in = True
开发者ID:amney,项目名称:acitoolkit,代码行数:8,代码来源:aci-show-fex.py

示例14: main

def main():
    """
    Main show Subnets routine
    :return: None
    """
    # Take login credentials from the command line if provided
    # Otherwise, take them from your environment variables file ~/.profile
    description = ('Simple application that logs on to the APIC'
                   ' and displays all of the Subnets.')
    creds = Credentials('apic', description)
    creds.add_argument('--tenant', help='The name of Tenant')
    args = creds.get()

    # Login to APIC
    session = Session(args.url, args.login, args.password)
    resp = session.login()
    if not resp.ok:
        print('%% Could not login to APIC')

    # Download all of the tenants, app profiles, and Subnets
    # and store the names as tuples in a list
    tenants = Tenant.get(session)
    for tenant in tenants:
        check_longest_name(tenant.name, "Tenant")
        if args.tenant is None:
            get_subnet(session, tenant)
        else:
            if tenant.name == args.tenant:
                get_subnet(session, tenant)

    # Display the data downloaded
    template = '{0:' + str(longest_names["Tenant"]) + '} ' \
               '{1:' + str(longest_names["Application Profile"]) + '} ' \
               '{2:' + str(longest_names["Bridge Domain"]) + '} ' \
               '{3:' + str(longest_names["Subnet"]) + '} ' \
               '{4:' + str(longest_names["Scope"]) + '}'
    print(template.format("Tenant", "Application Profile",
                          "Bridge Domain", "Subnet", "Scope"))
    print(template.format('-' * longest_names["Tenant"],
                          '-' * longest_names["Application Profile"],
                          '-' * longest_names["Bridge Domain"],
                          '-' * longest_names["Subnet"],
                          '-' * longest_names["Scope"]))
    for rec in sorted(data):
        print(template.format(*rec))
开发者ID:datacenter,项目名称:acitoolkit,代码行数:45,代码来源:aci-show-subnets.py

示例15: main

def main():
    """
    Main routine
    """
    # Get all the arguments
    description = 'Creates a tenant with a micro-EPG.'
    creds = Credentials('apic', description)
    args = creds.get()

    # Login to the APIC
    session = Session(args.url, args.login, args.password)
    resp = session.login()
    if not resp.ok:
        print('%% Could not login to APIC')

    # Create the Tenant and AppProfile
    tenant = Tenant('acitoolkit-microepg-example')
    app_profile = AppProfile('myapp', tenant)

    # Create a Base EPG that will provide networking for the microEPGs
    base_epg = EPG('base', app_profile)
    base_epg.add_static_leaf_binding('101', 'vlan', '1', encap_mode='untagged')
    vrf = Context('myvrf', tenant)
    bd = BridgeDomain('mybd', tenant)
    bd.add_context(vrf)
    base_epg.add_bd(bd)

    # Create a microEPG
    microepg = EPG('microepg', app_profile)
    microepg.is_attributed_based = True
    microepg.set_base_epg(base_epg)
    # Add an IP address to this microepg
    criterion = AttributeCriterion('criterion', microepg)
    criterion.add_ip_address('1.2.3.4')

    # Contracts can be provided/consumed from the microepg as desired (not shown)

    # Push the tenant to the APIC
    resp = tenant.push_to_apic(session)
    if not resp.ok:
        print('%% Error: Could not push configuration to APIC')
        print(resp.text)
开发者ID:datacenter,项目名称:acitoolkit,代码行数:42,代码来源:aci-create-microepg.py


注:本文中的acitoolkit.Session类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。