Пример #1
0
def main():
    """
    This function creates the new Tenant with a VRF, Bridge Domain and Subnet.
    """
    # create a session and define the root
    requests.packages.urllib3.disable_warnings()
    auth = cobra.mit.session.LoginSession("https://apic","admin","password")
    session = cobra.mit.access.MoDirectory(auth)
    session.login()

    root = cobra.model.pol.Uni('')

    # test if tenant name is already in use
    test_tenant(TENANT, session)

    # model new tenant configuration
    tenant = cobra.model.fv.Tenant(root, name=TENANT)
    vrf = cobra.model.fv.Ctx(tenant, name=VRF)
    bridge_domain = cobra.model.fv.BD(tenant, name=BRIDGEDOMAIN)
    attached_vrf = cobra.model.fv.RsCtx(bridge_domain, tnFvCtxName=VRF)
    subnet = cobra.model.fv.Subnet(bridge_domain, ip=GATEWAY, scope=SCOPE, name=SUBNETNAME)

    #submit the configuration to the apic and print a success message
    config_request = cobra.mit.request.ConfigRequest()
    config_request.addMo(tenant)
    session.commit(config_request)

    print("\nNew Tenant, {}, has been created:\n\n{}\n".format(TENANT, config_request.data))
Пример #2
0
def main():
    auth = cobra.mit.session.LoginSession(URL, LOGIN, PASSWORD)
    session = cobra.mit.access.MoDirectory(auth)
    session.login()

    root = cobra.model.pol.Uni('')

    tenant_snv = cobra.model.fv.Tenant(root, 'SnV')
    vrf_snv = cobra.model.fv.Ctx(tenant_snv, name='Superverse')
    bd_snv = cobra.model.fv.BD(tenant_snv, name='antigravity')
    bd_snv_vrf = cobra.model.fv.RsCtx(bd_snv, tnFvCtxName='Superverse')
    bd_snv_subnet = cobra.model.fv.Subnet(bd_snv, ip='10.2.10.1/23')

    contracts = (('web', 'http', 'tcp', '80', 'context'),
                 ('database', 'sql', 'tcp', '1433', 'application-profile'))
    for contract in contracts:
        create_contract(tenant_snv, contract[1], contract[2], contract[3],
                        contract[0], contract[4])

    app_names = (('Evolution_X', 'vlan-121',
                  'vlan-122'), ('Rescue', 'vlan-123', 'vlan-124'),
                 ('Chaos', 'vlan-125', 'vlan-126'), ('Power_Up', 'vlan-127',
                                                     'vlan-128'))
    for app in app_names:
        create_app(tenant_snv, app[0], bd_snv, app[1], app[2])

    config_request = cobra.mit.request.ConfigRequest()
    config_request.addMo(tenant_snv)
    session.commit(config_request)
Пример #3
0
from credentials import *
import cobra.mit.access
import cobra.mit.request
import cobra.mit.session
import cobra.model.fv
import cobra.model.pol

# connect to the apic
auth = cobra.mit.session.LoginSession(URL, LOGIN, PASSWORD)
session = cobra.mit.access.MoDirectory(auth)
session.login()

# Create a Variable for your Tenant Name
# Use your initials in the name
# Example: "tenant_name = "js_Toolkit_Tenant""
tenant_name = "INITIALS_Cobra_Tenant"
# create a new tenant
root = cobra.model.pol.Uni('')
new_tenant = cobra.model.fv.Tenant(root, tenant_name)

# commit the new configuration
 config_request = cobra.mit.request.ConfigRequest()
 config_request.addMo(new_tenant)
session.commit(config_request)
Пример #4
0
def commit_change(session, change):
    session.commit(change)
    logger.info('Change Committed...')