Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue appending to object groups #6

Open
imatrycode opened this issue Jul 31, 2019 · 2 comments
Open

Issue appending to object groups #6

imatrycode opened this issue Jul 31, 2019 · 2 comments

Comments

@imatrycode
Copy link

hello again,

Still using this and again its ace so thak you , just wondernig if there is an easy way to add to a group.

for example a user group has 2 members, if I set the members attribute on the group to add the additional it replaces the 2 with the 1 so it replaces instead of appends.

Any help on this would be appreicated

E.g. this creates the group with the member

t.print_data (t.create(['cmdb', 'user', 'group'], data={'name':'VLAN-'+(vlan)+'-GRP','group-type':'firewall','member':[{'name':(username)}]}),verbose=True)

Editing it's member attribute to say:

member':[{'name':(username), {'name':("SOMETHING")}]} replaces it with these 2

Bit If I do

ember':[{'name':("SOMETHING")}]}

it replaces all the members with the new one, wonder if there is an append method.

@imatrycode
Copy link
Author

I have found a workaround but its pretty messy. basically gets the current lot of members then appends the new one to it.

@staticmethod
def print_dataAddress(response, response2=None, verbose=False):
if response['status']=='success':
if verbose:
pprint.pprint (response)
elif response['http_method']=='GET':
global data
data = {'member': []}
for member in response['results']:
for whats in member['member']:
data['member'].append({'name':((whats)['name'])})
else:
print ('OK!')
else:
print ('Fail!')
pprint.pprint (response)

then

a=t.show(['cmdb', 'user', 'group',(group)])
b=t.print_dataAddress(a)
data['member'].append({"name":(username)})
x=json.dumps(data)

@eoprede
Copy link
Owner

eoprede commented Jul 31, 2019

@imatrycode
When you are working with the group, you can not access members separately. You can only deal with them as a whole set, whether you are creating or editing them.

Unfortunately I don't have fortigate readily available anymore, but I recall that some endpoints were allowing to edit some subitems. You could try to do something like t.create(['cmdb', 'user', 'group',X], data= {'name':("SOMETHING")}), where X is the id of your group. Again - I am not sure if you can access it or not and can't test it, but I recall some endpoints allowing you to do it.

Otherwise you have found acceptable workaround - just grab the list of all members, add/remove them as needed and push the whole list back to the firewall.

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

No branches or pull requests

2 participants