Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_cleanup_user(self, apics, certobject, userobject):
apic = apics[0]
user = apics[2]
password = apics[3]
secure = False if apics[1] == 'False' else True
userobject.aaaUser.delete()
session = LoginSession(apic, user, password, secure=secure)
moDir = MoDirectory(session)
moDir.login()
cr = ConfigRequest()
cr.addMo(userobject.aaaUser)
r = moDir.commit(cr)
assert r.status_code == 200
(LoginSession('http://2.2.2.2:7777', 'c', 'd'),
'http://2.2.2.2:7777', 'c', 'd', False, 90, 'xml'), # Test expected default
(LoginSession('http://1.1.1.1:80', 'a', 'b', True, 180, requestFormat='json'),
'http://1.1.1.1:80', 'a', 'b', True, 180, 'json'),
(LoginSession('http://1.1.1.1:80', 'a', 'b', True, 180, requestFormat='xml'),
'http://1.1.1.1:80', 'a', 'b', True, 180, 'xml'),
])
def test_LoginSession_init(self, session, url, user, password, secure,
timeout, requestFormat):
assert session.url == url
assert session.user == user
assert session.password == password
assert session.secure == secure
assert session.timeout == timeout
assert session.formatStr == requestFormat
def test_AliasRequest_getUrl(self, sessionUrl, dc, aliasStr, clear,
requestType):
dnStr = 'uni'
session = LoginSession(sessionUrl, 'admin', 'password',
requestFormat=requestType)
ar = AliasRequest(dnStr)
expectedUrl = sessionUrl + '/api/alias/mo/' + dnStr + '.' + requestType
if clear:
ar.alias = aliasStr
ar.clear()
expectedUrl += '?clear=yes'
else:
ar.alias = aliasStr
expectedUrl += '?set=' + aliasStr
ar.id = dc
expectedUrl += '&_dc=' + dc
assert ar.getUrl(session) == expectedUrl
def moDir(request):
url, user, password, secure = request.param
secure = False if secure == 'False' else True
session = cobra.mit.session.LoginSession(url, user, password,
secure=secure)
md = cobra.mit.access.MoDirectory(session)
md.login()
return md
def test_reauth(self, apic, getResponseMock):
"""Verify that the reauth function works."""
if apic[0] == 'http://mock':
getResponseMock.start()
url, user, password, secure = apic
secure = False if secure == 'False' else True
session = cobra.mit.session.LoginSession(url, user, password,
secure=secure,
requestFormat='json')
moDir = cobra.mit.access.MoDirectory(session)
moDir.login()
logger.debug(
'refresh token: {0}'.format(moDir._session._cookie))
assert moDir._session._cookie
if apic[0] == 'http://mock':
getResponseMock.stop()
def test_getDomains(self, apic):
"""Verify that the getLoginDomains() method works.
"""
url, user, password, secure = apic
secure = False if secure == 'False' else True
session = cobra.mit.session.LoginSession(url, user, password,
secure=secure)
session.getLoginDomains()
assert session.domains != []
def test_LoginRequest_getUrl(self, sessionUrl):
session = LoginSession(sessionUrl, 'admin', 'password')
expected = sessionUrl + '/api/aaaLogin.json'
lr = LoginRequest('admin', 'password')
assert lr.getUrl(session) == expected
def aci_login():
auth = cobra.mit.session.LoginSession(URL, LOGIN, PASSWORD)
session = cobra.mit.access.MoDirectory(auth)
session.login()
return session
from cobra.internal.codec.xmlcodec import toXMLStr
from credentials import *
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# configuration variables
tenant = 'Heroes'
bridge_domain = 'Hero_Land'
application = 'Save_The_Network'
vlan1 = 'vlan-211'
vlan2 = 'vlan-212'
vlan3 = 'vlan-210'
# log into an APIC and create a directory object
ls = cobra.mit.session.LoginSession(URL, LOGIN, PASSWORD)
md = cobra.mit.access.MoDirectory(ls)
md.login()
# the top level object on which operations will be made
polUni = cobra.model.pol.Uni('')
fvTenant = cobra.model.fv.Tenant(polUni, tenant)
# build the request using cobra syntax
fvAp = cobra.model.fv.Ap(fvTenant, ownerKey=u'', name=application, prio=u'unspecified', ownerTag=u'', descr=u'')
fvAEPg = cobra.model.fv.AEPg(fvAp, isAttrBasedEPg=u'no', matchT=u'AtleastOne', prio=u'unspecified', name=u'app', descr=u'')
fvRsCons = cobra.model.fv.RsCons(fvAEPg, tnVzBrCPName=u'sql', prio=u'unspecified')
fvRsPathAtt = cobra.model.fv.RsPathAtt(fvAEPg, tDn=u'topology/pod-1/protpaths-101-102/pathep-[Heroes_FI-2B]', instrImedcy=u'lazy', encap=vlan1, descr=u'', mode=u'regular')
fvRsPathAtt2 = cobra.model.fv.RsPathAtt(fvAEPg, tDn=u'topology/pod-1/protpaths-101-102/pathep-[Heroes_FI-2A]', instrImedcy=u'lazy', encap=vlan1, descr=u'', mode=u'regular')
fvRsDomAtt = cobra.model.fv.RsDomAtt(fvAEPg, instrImedcy=u'lazy', resImedcy=u'lazy', encap=u'unknown', tDn=u'uni/phys-Heroes_phys')
fvRsCustQosPol = cobra.model.fv.RsCustQosPol(fvAEPg, tnQosCustomPolName=u'')
fvRsBd = cobra.model.fv.RsBd(fvAEPg, tnFvBDName=bridge_domain)