Software Development Kit (SDK) and API Discussions

Struggles with useradmin-user-info element and Python

danieltd

I am trying to add a new user with a python script but it does not like my useradmin-user-info element and I am out of guesses for what is wrong.

Here is the command I am trying to get to work.

     out = s.invoke("useradmin-user-add", "password", service_acct_passwd, "useradmin-user", opsmgr_user)

This is the error that I am getting.

     Didn't find expected typedef useradmin-user-info for element useradmin-user

Below is how I am constructing the useradmin-user-info element.

     opsmgr_user = NaElement("useradmin-user-info")

     opsmgr_user.child_add_string("name", "OpsManager")

     opsmgr_user.child_add_string("comment", "")

     opsmgr_user.child_add(admin_group)

I have tried both building the admin_group element and pulling it.  No luck with either.

     #admin_group_pull = s.invoke("useradmin-group-list", "group-name", "administrators" )

     #admin_group_pull = admin_group.child_get("useradmin-groups")

     #admin_group_pull = admin_group.child_get("useradmin-group-info")

     admin_group_make = NaElement("useradmin-group-info")

     admin_group_make.child_add_string("name", "Administrators")

     admin_group = NaElement("useradmin-groups")

     admin_group.child_add(admin_group_make)

Here is a sprintf() of the opsmgr_user

<useradmin-user-info>

          <name>OpsManager</name>

          <comment></comment>

          <useradmin-groups>

                    <useradmin-group-info>

                              <name>Administrators</name>

                    </useradmin-group-info>

          </useradmin-groups>

</useradmin-user-info>

This seems to match perfectly with a sample pulled from an existing user.

     test = s.invoke("useradmin-user-list", "user-name", "sftp_user2")

     test = test.child_get("useradmin-users")

     test = test.child_get("useradmin-user-info")

     print(test.sprintf())

<useradmin-user-info>

          <name>sftp_user2</name>

          <comment></comment>

          <useradmin-groups>

                    <useradmin-group-info>

                              <name>sftp_group</name>

                    </useradmin-group-info>

          </useradmin-groups>

</useradmin-user-info>

Any help is greatly appreciated.

Thanks,

Daniel DeCristofaro

1 ACCEPTED SOLUTION

danieltd

Got the issue sorted out.  Thanks Ben!

My problem was that the .invoke method only supports simple name value pairs and was not compatible with elements.  I had use the .invoke_elem() method to pass the objects correctly.

snapdrive_user = NaElement("useradmin-user")

useradminuserinfoElement = NaElement("useradmin-user-info")

snapdrive_user.child_add(useradminuserinfoElement)

useradminuserinfoElement.child_add_string("name", "snapdrive")

useradmingroupsElement = NaElement("useradmin-groups")

useradminuserinfoElement.child_add(useradmingroupsElement)

useradmingroupinfoElement = NaElement("useradmin-group-info")

useradmingroupsElement.child_add(useradmingroupinfoElement)

useradmingroupinfoElement.child_add_string("name", "Administrators")

#print(snapdrive_user.sprintf())

opsmgr_user = NaElement("useradmin-user")

useradminuserinfoElement = NaElement("useradmin-user-info")

opsmgr_user.child_add(useradminuserinfoElement)

useradminuserinfoElement.child_add_string("name", "OpsManager")

useradmingroupsElement = NaElement("useradmin-groups")

useradminuserinfoElement.child_add(useradmingroupsElement)

useradmingroupinfoElement = NaElement("useradmin-group-info")

useradmingroupsElement.child_add(useradmingroupinfoElement)

useradmingroupinfoElement.child_add_string("name", "Administrators")

#print(opsmgr_user.sprintf())

add_snapdrive_user = NaElement("useradmin-user-add")

add_snapdrive_user.child_add_string("password", service_acct_passwd)

add_snapdrive_user.child_add(snapdrive_user)

#print(add_snapdrive_user.sprintf())

out = s.invoke_elem(add_snapdrive_user)

if (out.results_status() == "failed") :

    print ("Error:\n")

    print (out.sprintf())

    sys.exit (1)

add_opsmgr_user = NaElement("useradmin-user-add")

add_opsmgr_user.child_add_string("password", service_acct_passwd)

add_opsmgr_user.child_add(opsmgr_user)

#print(add_opsmgr_user.sprintf())

out = s.invoke_elem(add_opsmgr_user)

if (out.results_status() == "failed") :

    print ("Error:\n")

    print (out.sprintf())

    sys.exit (1)

View solution in original post

1 REPLY 1

danieltd

Got the issue sorted out.  Thanks Ben!

My problem was that the .invoke method only supports simple name value pairs and was not compatible with elements.  I had use the .invoke_elem() method to pass the objects correctly.

snapdrive_user = NaElement("useradmin-user")

useradminuserinfoElement = NaElement("useradmin-user-info")

snapdrive_user.child_add(useradminuserinfoElement)

useradminuserinfoElement.child_add_string("name", "snapdrive")

useradmingroupsElement = NaElement("useradmin-groups")

useradminuserinfoElement.child_add(useradmingroupsElement)

useradmingroupinfoElement = NaElement("useradmin-group-info")

useradmingroupsElement.child_add(useradmingroupinfoElement)

useradmingroupinfoElement.child_add_string("name", "Administrators")

#print(snapdrive_user.sprintf())

opsmgr_user = NaElement("useradmin-user")

useradminuserinfoElement = NaElement("useradmin-user-info")

opsmgr_user.child_add(useradminuserinfoElement)

useradminuserinfoElement.child_add_string("name", "OpsManager")

useradmingroupsElement = NaElement("useradmin-groups")

useradminuserinfoElement.child_add(useradmingroupsElement)

useradmingroupinfoElement = NaElement("useradmin-group-info")

useradmingroupsElement.child_add(useradmingroupinfoElement)

useradmingroupinfoElement.child_add_string("name", "Administrators")

#print(opsmgr_user.sprintf())

add_snapdrive_user = NaElement("useradmin-user-add")

add_snapdrive_user.child_add_string("password", service_acct_passwd)

add_snapdrive_user.child_add(snapdrive_user)

#print(add_snapdrive_user.sprintf())

out = s.invoke_elem(add_snapdrive_user)

if (out.results_status() == "failed") :

    print ("Error:\n")

    print (out.sprintf())

    sys.exit (1)

add_opsmgr_user = NaElement("useradmin-user-add")

add_opsmgr_user.child_add_string("password", service_acct_passwd)

add_opsmgr_user.child_add(opsmgr_user)

#print(add_opsmgr_user.sprintf())

out = s.invoke_elem(add_opsmgr_user)

if (out.results_status() == "failed") :

    print ("Error:\n")

    print (out.sprintf())

    sys.exit (1)

View solution in original post

Announcements
Register for Insight 2021 Digital

INSIGHT 2021 Digital: Meet the Specialists 2

On October 20-22, gear up for a fully digital, totally immersive virtual experience with a downright legendary lineup of world-renowned specialists. Tune in for visionary conversations, solution deep dives, technical sessions and more.

NetApp on Discord Image

We're on Discord, are you?

Live Chat, Watch Parties, and More!

Explore Banner

Meet Explore, NetApp’s digital sales platform

Engage digitally throughout the sales process, from product discovery to configuration, and handle all your post-purchase needs.

NetApp Insights to Action
I2A Banner
Public