How to use the cobra.model.fv.Tenant function in cobra

To help you get started, we’ve selected a few cobra examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github datacenter / cobra / tests / rest / test_rest.py View on Github external
def test_createtenant(self, moDir, tenantname):
        """
        create a tenant and commit it
        """
        dcid = str(time.time()).replace('.', '')

        polUni = cobra.model.pol.Uni('')
        tenant = cobra.model.fv.Tenant(polUni, tenantname[0])

        configRequest = cobra.mit.request.ConfigRequest()
        configRequest.addMo(tenant)
        configRequest.subtree = 'full'
        configRequest.id = dcid

        mos = moDir.commit(configRequest)
        assert mos

        mo = mos[0]
        assert len(mos) > 0
        assert str(mo.dn) == str(tenant.dn)
        assert len(list(mo.children)) >= 1
github datacenter / cobra / tests / mit / test_request.py View on Github external
def test_ConfigRequest_removeMo_raises(self):
        fvTenant = Tenant('uni', 'testing')
        cr = ConfigRequest()
        with pytest.raises(KeyError):
            cr.removeMo(fvTenant)
github datacenter / cobra / tests / mit / test_request.py View on Github external
def test_ConfigRequest_removeMo_and_hasMo_negative(self):
        fvTenant = Tenant('uni', 'testing')
        fvnsVlanInstP = VlanInstP('uni/infra', 'namespace1', 'dynamic')
        cr = ConfigRequest()
        cr.addMo(fvTenant)
        cr.removeMo(fvTenant)
        cr.addMo(fvnsVlanInstP)
        assert not cr.hasMo(fvTenant.dn)
github datacenter / cobra / tests / mit / test_request.py View on Github external
},
                       'timeout': 90,
                       'verify': False
                   }
        expected2 = {
                       'data': '\n' +
                               '',
                       'headers': {
                           'Cookie': 'APIC-cookie=None'
                       },
                       'timeout': 90,
                       'verify': False
                   }
        polUni = Uni('')
        fvTenant = Tenant(polUni, 'testing')
        session = LoginSession('http://1.1.1.1', 'admin', 'password')
        cr = ConfigRequest()
        cr.addMo(fvTenant)
        assert (cr.requestargs(session) == expected1 or
                cr.requestargs(session) == expected2)
github datacenter / cobra / tests / mit / test_request.py View on Github external
def test_ConfigRequest_data(self):
        expected = ('{"fvTenant": {"attributes": {"name": "test", "status": ' +
                    '"created,modified"}}}')
        polUni = Uni('')
        fvTenant = Tenant(polUni, 'test')
        cr = ConfigRequest()
        cr.addMo(fvTenant)
        assert cr.data == expected
github datacenter / ACI / configuration-python / Lab3 / utility.py View on Github external
def check_if_tenant_exist(modir, tenant_name):
    fv_tenant = modir.lookupByDn('uni/tn-' + tenant_name)
    if not isinstance(fv_tenant, Tenant):
        print 'Tenant', tenant_name, 'does not existed. \nPlease create a tenant.'
        sys.exit()
    return fv_tenant
github datacenter / ACI / configuration-python / utility.py View on Github external
def check_if_tenant_exist(modir, tenant_name):
    fv_tenant = modir.lookupByDn('uni/tn-' + tenant_name)
    if not isinstance(fv_tenant, Tenant):
        print 'Tenant', tenant_name, 'does not existed. \nPlease create a tenant.'
        sys.exit()
    return fv_tenant
github datacenter / ACI / configuration-python / generic_code / apicPython / createMo.py View on Github external
def check_if_tenant_exist(self, return_boolean=False, set_mo=True):
        """
        :param return_boolean: if set, return value is True or False
        :param set_mo: if set, self.mo is set to be Tenant
        :return: the tenant MO
        """
        fv_tenant = self.look_up_mo('uni/tn-', self.tenant, set_mo=set_mo)
        if not isinstance(fv_tenant, Tenant):
            print 'Tenant', self.tenant, 'does not existed. \nPlease create a tenant.'
            return False if return_boolean else sys.exit()
        return fv_tenant
github CiscoDevNet / aci-learning-labs-code-samples / sbx-intermediate-aci / sbx-intermediate-aci-02_cobra / cobra_tenant.py View on Github external
"""
    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(URL, LOGIN, 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))
github datacenter / arya / pyra / pyra.py View on Github external
def main():
    """Use locals() to create a PyraTree, then get JSON/XML representations of the PyraTree data and print them."""
    # Put Arya-generated code here
    polUni = cobra.model.pol.Uni('')
    fvTenant = cobra.model.fv.Tenant(polUni, 'pod1')

    # Create the tree
    tree = PyraTree('polUni', locals())

    # Acquire a copy of the tree to use, e.g to save/modify/post.
    dict_tree = tree.dtree
    xml_tree = tree.etree
    json_tree = tree.jtree

    # Example output
    print(ElementTree.tostring(xml_tree, encoding='utf-8'))
    print(json.dumps(json_tree, indent=4, sort_keys=True))