jssimporter / python-jss

python-jss is deprecated. Please see the wiki for alternatives.
GNU General Public License v3.0
102 stars 41 forks source link

Updating Groups doesn't work or is not documented #58

Closed dilawarzaman closed 7 years ago

dilawarzaman commented 7 years ago

Can't get updating a smart group criteria to work

sheagcraig commented 7 years ago

Go ahead and post up the data you're trying to update the group with.

I would try manually creating a smart group with the criteria you want and then retrieve it with python-jss. You can then compare the two to see what might be wrong or incorrectly formed.

dilawarzaman commented 7 years ago

This is how I am implementing it:

smart_group_name = policy.findtext("scope/computer_groups/computer_group/name") group = jss_connection.ComputerGroup(smart_group_name) stuff = group.find("name") stuff.text = "I messed with the Group Name" group.save()

sheagcraig commented 7 years ago

Hmmm. That definitely looks like it should work. (And I think this would blow up if you were getting more than one smart group as a response from the second line, so it's not a problem of duplicate names).

The only thing I notice right off the bat is that this would work fine for Smart Groups that only have a single criteria. The find method grabs the first subelement that matches. But that shouldn't have any bearing on whether the save works or not.

I think what you could do to help troubleshoot is to take the smart group, with the modified Application Title text, and print it and copy the output into here. Maybe there's something weird going on about how it's getting formatted that isn't obvious from this end.

dilawarzaman commented 7 years ago

I did some crazy stuff to get it working finally. Lots of iterations and assumptions that certain strings are unique.

new_pkg_version = get_package_info(new_pkg)

print("New Version:")

# print(new_pkg_version[1])

for elem in group.criteria.iter():
    if 'Application Version' in str(elem) and 'size' not in str(elem):
        for xml_row in elem.iter():
            if '<value>' in str(xml_row) and 'criterion' not in str(xml_row):
                # print(xml_row)
                xml_row.text = str(new_pkg_version[1])
                group.save()
                print("Updated Smart Group to version: %s" % str(new_pkg_version[1]))
                break
dilawarzaman commented 7 years ago

It works but could never figure out how to iterate criterion