Skip to content
This repository has been archived by the owner on Sep 11, 2023. It is now read-only.

Arya converstion problem #2

Open
coopsart opened this issue Jun 23, 2015 · 2 comments
Open

Arya converstion problem #2

coopsart opened this issue Jun 23, 2015 · 2 comments
Assignees

Comments

@coopsart
Copy link

I am trying to generate a python script that upgrades the APIC cluster. I am using Arya to build the script from the following JSON code from the API inspector:

{"ctrlrInst":{"attributes":{"dn":"uni/controller","status":"modified"},"children":[{"firmwareCtrlrFwP":{"attributes":{"dn":"uni/controller/ctrlrfwpol","version":"apic-1.1(1j)"},"children":[]}},{"maintCtrlrMaintP":{"attributes":{"dn":"uni/controller/ctrlrmaintpol","adminSt":"triggered"},"children":[]}},{"trigSchedP":{"attributes":{"dn":"uni/controller/schedp-ConstSchedP","status":"modified"},"children":[{"trigAbsWindowP":{"attributes":{"dn":"uni/controller/schedp-ConstSchedP/abswinp-ConstAbsWindowP","date":"2015-06-23T02:16:16.402+00:00"},"children":[]}}]}}]}}

Arya built this:

import cobra.mit.access
import cobra.mit.request
import cobra.mit.session
import cobra.model.ctrlr
import cobra.model.firmware
import cobra.model.maint
import cobra.model.pol
import cobra.model.trig
from cobra.internal.codec.xmlcodec import toXMLStr

log into an APIC and create a directory object

ls = cobra.mit.session.LoginSession('https://10.221.79.101', 'admin', 'C!sco123')
md = cobra.mit.access.MoDirectory(ls)
md.login()

the top level object on which operations will be made

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

build the request using cobra syntax

ctrlrInst = cobra.model.ctrlr.Inst(topMo)
firmwareCtrlrFwP = cobra.model.firmware.CtrlrFwP(ctrlrInst, version=u'apic-1.1(1j)')
maintCtrlrMaintP = cobra.model.maint.CtrlrMaintP(ctrlrInst, adminSt=u'triggered')
trigSchedP = cobra.model.trig.SchedP(ctrlrInst)
trigAbsWindowP = cobra.model.trig.AbsWindowP(trigSchedP, date=u'2015-06-23T02:16:16.402+00:00')

commit the generated code to APIC

print toXMLStr(topMo)
c = cobra.mit.request.ConfigRequest()
c.addMo(topMo)
md.commit(c)

When I try and run the script I get the following error:

Traceback (most recent call last):
File "upgrade_apic.py", line 24, in
trigSchedP = cobra.model.trig.SchedP(ctrlrInst)
TypeError: init() takes at least 3 arguments (2 given)

Thanks
Ben

@paullesiak
Copy link
Contributor

Ben, thanks for pointing this out. Looks like the GUI generated JSON is passing the naming properties in through the DN, which doesn't get populated as attributes in the JSON dictionary, hence the missing parameter.

    "trigSchedP": {
      "attributes": {
        "dn": "uni/controller/schedp-ConstSchedP",
        "status": "modified"
      },

For now you'll need to manually pass the name in, e.g.,

trigSchedP = cobra.model.trig.SchedP(ctrlrInst, 'ConstSchedP')

Let's keep this issue open for now, so I can track this for some major rework I'll be doing in arya.

In short the code fix here will be to use the Dn parsing from Cobra, extract naming properties and pass those to the object constructors, but of course I don't want cobra to be a dependency so the fallback code will have to do what's currently in place, meaning this issue will remain if cobra isn't installed on a system.

@paullesiak paullesiak self-assigned this Jun 24, 2015
@coopsart
Copy link
Author

Hi Paul.

I manually passed the name as you mentioned above but received the following error:

Traceback (most recent call last):
File "upgrade_apic.py", line 25, in
trigAbsWindowP = cobra.model.trig.AbsWindowP(trigSchedP, date=u'2015-06-23T02:16:16.402+00:00')
TypeError: init() takes at least 3 arguments (2 given)

To resolve the issue I removed the following line and the script worked.

trigAbsWindowP = cobra.model.trig.AbsWindowP(trigSchedP, date=u'2015-06-23T02:16:16.402+00:00')

Thanks
Ben

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants