@@ 5901-5998 (lines=98) @@ | ||
5898 | ||
5899 | return self._send_xml_command(cmd) |
|
5900 | ||
5901 | def modify_user( |
|
5902 | self, |
|
5903 | user_id: str = None, |
|
5904 | name: str = None, |
|
5905 | *, |
|
5906 | new_name: Optional[str] = None, |
|
5907 | comment: Optional[str] = None, |
|
5908 | password: Optional[str] = None, |
|
5909 | auth_source: Optional[UserAuthType] = None, |
|
5910 | role_ids: Optional[List[str]] = None, |
|
5911 | hosts: Optional[List[str]] = None, |
|
5912 | hosts_allow: Optional[bool] = False, |
|
5913 | ifaces: Optional[List[str]] = None, |
|
5914 | ifaces_allow: Optional[bool] = False, |
|
5915 | group_ids: Optional[List[str]] = None, |
|
5916 | ) -> Any: |
|
5917 | """Modifies an existing user. Most of the fields need to be supplied |
|
5918 | for changing a single field even if no change is wanted for those. |
|
5919 | Else empty values are inserted for the missing fields instead. |
|
5920 | Arguments: |
|
5921 | user_id: UUID of the user to be modified. Overrides name element |
|
5922 | argument. |
|
5923 | name: The name of the user to be modified. Either user_id or name |
|
5924 | must be passed. |
|
5925 | new_name: The new name for the user. |
|
5926 | comment: Comment on the user. |
|
5927 | password: The password for the user. |
|
5928 | auth_source: Source allowed for authentication for this user. |
|
5929 | roles_id: List of roles UUIDs for the user. |
|
5930 | hosts: User access rules: List of hosts. |
|
5931 | hosts_allow: Defines how the hosts list is to be interpreted. |
|
5932 | If False (default) the list is treated as a deny list. |
|
5933 | All hosts are allowed by default except those provided by |
|
5934 | the hosts parameter. If True the list is treated as a |
|
5935 | allow list. All hosts are denied by default except those |
|
5936 | provided by the hosts parameter. |
|
5937 | ifaces: User access rules: List of ifaces. |
|
5938 | ifaces_allow: Defines how the ifaces list is to be interpreted. |
|
5939 | If False (default) the list is treated as a deny list. |
|
5940 | All ifaces are allowed by default except those provided by |
|
5941 | the ifaces parameter. If True the list is treated as a |
|
5942 | allow list. All ifaces are denied by default except those |
|
5943 | provided by the ifaces parameter. |
|
5944 | group_ids: List of group UUIDs for the user. |
|
5945 | ||
5946 | Returns: |
|
5947 | The response. See :py:meth:`send_command` for details. |
|
5948 | """ |
|
5949 | if not user_id and not name: |
|
5950 | raise RequiredArgument( |
|
5951 | function=self.modify_user.__name__, argument='user_id or name' |
|
5952 | ) |
|
5953 | ||
5954 | cmd = XmlCommand("modify_user") |
|
5955 | ||
5956 | if user_id: |
|
5957 | cmd.set_attribute("user_id", user_id) |
|
5958 | else: |
|
5959 | cmd.add_element("name", name) |
|
5960 | ||
5961 | if new_name: |
|
5962 | cmd.add_element("new_name", new_name) |
|
5963 | ||
5964 | if role_ids: |
|
5965 | for role in role_ids: |
|
5966 | cmd.add_element("role", attrs={"id": role}) |
|
5967 | ||
5968 | if hosts: |
|
5969 | cmd.add_element( |
|
5970 | "hosts", |
|
5971 | to_comma_list(hosts), |
|
5972 | attrs={"allow": to_bool(hosts_allow)}, |
|
5973 | ) |
|
5974 | ||
5975 | if ifaces: |
|
5976 | cmd.add_element( |
|
5977 | "ifaces", |
|
5978 | to_comma_list(ifaces), |
|
5979 | attrs={"allow": to_bool(ifaces_allow)}, |
|
5980 | ) |
|
5981 | ||
5982 | if comment: |
|
5983 | cmd.add_element("comment", comment) |
|
5984 | ||
5985 | if password: |
|
5986 | cmd.add_element("password", password) |
|
5987 | ||
5988 | if auth_source: |
|
5989 | _xmlauthsrc = cmd.add_element("sources") |
|
5990 | _xmlauthsrc.add_element("source", auth_source.value) |
|
5991 | ||
5992 | if group_ids: |
|
5993 | _xmlgroups = cmd.add_element("groups") |
|
5994 | for group_id in group_ids: |
|
5995 | _xmlgroups.add_element("group", attrs={"id": group_id}) |
|
5996 | ||
5997 | return self._send_xml_command(cmd) |
|
5998 | ||
5999 | def restore(self, entity_id: str) -> Any: |
|
6000 | """Restore an entity from the trashcan |
|
6001 |
@@ 391-483 (lines=93) @@ | ||
388 | ||
389 | return self._send_xml_command(cmd) |
|
390 | ||
391 | def modify_user( |
|
392 | self, |
|
393 | user_id: str = None, |
|
394 | *, |
|
395 | name: Optional[str] = None, |
|
396 | comment: Optional[str] = None, |
|
397 | password: Optional[str] = None, |
|
398 | auth_source: Optional[UserAuthType] = None, |
|
399 | role_ids: Optional[List[str]] = None, |
|
400 | hosts: Optional[List[str]] = None, |
|
401 | hosts_allow: Optional[bool] = False, |
|
402 | ifaces: Optional[List[str]] = None, |
|
403 | ifaces_allow: Optional[bool] = False, |
|
404 | group_ids: Optional[List[str]] = None, |
|
405 | ) -> Any: |
|
406 | ||
407 | """Modifies an existing user. Most of the fields need to be supplied |
|
408 | for changing a single field even if no change is wanted for those. |
|
409 | Else empty values are inserted for the missing fields instead. |
|
410 | ||
411 | Arguments: |
|
412 | user_id: UUID of the user to be modified. |
|
413 | name: The new name for the user. |
|
414 | comment: Comment on the user. |
|
415 | password: The password for the user. |
|
416 | auth_source: Source allowed for authentication for this user. |
|
417 | roles_id: List of roles UUIDs for the user. |
|
418 | hosts: User access rules: List of hosts. |
|
419 | hosts_allow: Defines how the hosts list is to be interpreted. |
|
420 | If False (default) the list is treated as a deny list. |
|
421 | All hosts are allowed by default except those provided by |
|
422 | the hosts parameter. If True the list is treated as a |
|
423 | allow list. All hosts are denied by default except those |
|
424 | provided by the hosts parameter. |
|
425 | ifaces: User access rules: List of ifaces. |
|
426 | ifaces_allow: Defines how the ifaces list is to be interpreted. |
|
427 | If False (default) the list is treated as a deny list. |
|
428 | All ifaces are allowed by default except those provided by |
|
429 | the ifaces parameter. If True the list is treated as a |
|
430 | allow list. All ifaces are denied by default except those |
|
431 | provided by the ifaces parameter. |
|
432 | group_ids: List of group UUIDs for the user. |
|
433 | ||
434 | Returns: |
|
435 | The response. See :py:meth:`send_command` for details. |
|
436 | """ |
|
437 | if not user_id: |
|
438 | raise RequiredArgument( |
|
439 | function=self.modify_user.__name__, argument='user_id' |
|
440 | ) |
|
441 | ||
442 | cmd = XmlCommand("modify_user") |
|
443 | ||
444 | if user_id: |
|
445 | cmd.set_attribute("user_id", user_id) |
|
446 | ||
447 | if name: |
|
448 | cmd.add_element("new_name", name) |
|
449 | ||
450 | if role_ids: |
|
451 | for role in role_ids: |
|
452 | cmd.add_element("role", attrs={"id": role}) |
|
453 | ||
454 | if hosts: |
|
455 | cmd.add_element( |
|
456 | "hosts", |
|
457 | to_comma_list(hosts), |
|
458 | attrs={"allow": to_bool(hosts_allow)}, |
|
459 | ) |
|
460 | ||
461 | if ifaces: |
|
462 | cmd.add_element( |
|
463 | "ifaces", |
|
464 | to_comma_list(ifaces), |
|
465 | attrs={"allow": to_bool(ifaces_allow)}, |
|
466 | ) |
|
467 | ||
468 | if comment: |
|
469 | cmd.add_element("comment", comment) |
|
470 | ||
471 | if password: |
|
472 | cmd.add_element("password", password) |
|
473 | ||
474 | if auth_source: |
|
475 | _xmlauthsrc = cmd.add_element("sources") |
|
476 | _xmlauthsrc.add_element("source", auth_source.value) |
|
477 | ||
478 | if group_ids: |
|
479 | _xmlgroups = cmd.add_element("groups") |
|
480 | for group_id in group_ids: |
|
481 | _xmlgroups.add_element("group", attrs={"id": group_id}) |
|
482 | ||
483 | return self._send_xml_command(cmd) |
|
484 |