| @@ 2175-2231 (lines=57) @@ | ||
| 2172 | cmd.add_element("copy", task_id) |
|
| 2173 | return self._send_xml_command(cmd) |
|
| 2174 | ||
| 2175 | def create_user( |
|
| 2176 | self, |
|
| 2177 | name: str, |
|
| 2178 | *, |
|
| 2179 | password: Optional[str] = None, |
|
| 2180 | hosts: Optional[List[str]] = None, |
|
| 2181 | hosts_allow: Optional[bool] = False, |
|
| 2182 | ifaces: Optional[List[str]] = None, |
|
| 2183 | ifaces_allow: Optional[bool] = False, |
|
| 2184 | role_ids: Optional[List[str]] = None, |
|
| 2185 | ) -> Any: |
|
| 2186 | """Create a new user |
|
| 2187 | ||
| 2188 | Arguments: |
|
| 2189 | name: Name of the user |
|
| 2190 | password: Password of the user |
|
| 2191 | hosts: A list of host addresses (IPs, DNS names) |
|
| 2192 | hosts_allow: If True allow only access to passed hosts otherwise |
|
| 2193 | deny access. Default is False for deny hosts. |
|
| 2194 | ifaces: A list of interface names |
|
| 2195 | ifaces_allow: If True allow only access to passed interfaces |
|
| 2196 | otherwise deny access. Default is False for deny interfaces. |
|
| 2197 | role_ids: A list of role UUIDs for the user |
|
| 2198 | ||
| 2199 | Returns: |
|
| 2200 | The response. See :py:meth:`send_command` for details. |
|
| 2201 | """ |
|
| 2202 | if not name: |
|
| 2203 | raise RequiredArgument( |
|
| 2204 | function=self.create_user.__name__, argument='name' |
|
| 2205 | ) |
|
| 2206 | ||
| 2207 | cmd = XmlCommand("create_user") |
|
| 2208 | cmd.add_element("name", name) |
|
| 2209 | ||
| 2210 | if password: |
|
| 2211 | cmd.add_element("password", password) |
|
| 2212 | ||
| 2213 | if hosts: |
|
| 2214 | cmd.add_element( |
|
| 2215 | "hosts", |
|
| 2216 | _to_comma_list(hosts), |
|
| 2217 | attrs={"allow": _to_bool(hosts_allow)}, |
|
| 2218 | ) |
|
| 2219 | ||
| 2220 | if ifaces: |
|
| 2221 | cmd.add_element( |
|
| 2222 | "ifaces", |
|
| 2223 | _to_comma_list(ifaces), |
|
| 2224 | attrs={"allow": _to_bool(ifaces_allow)}, |
|
| 2225 | ) |
|
| 2226 | ||
| 2227 | if role_ids: |
|
| 2228 | for role in role_ids: |
|
| 2229 | cmd.add_element("role", attrs={"id": role}) |
|
| 2230 | ||
| 2231 | return self._send_xml_command(cmd) |
|
| 2232 | ||
| 2233 | def clone_user(self, user_id: str) -> Any: |
|
| 2234 | """Clone an existing user |
|
| @@ 4104-4160 (lines=57) @@ | ||
| 4101 | cmd.add_element("copy", task_id) |
|
| 4102 | return self._send_xml_command(cmd) |
|
| 4103 | ||
| 4104 | def create_user( |
|
| 4105 | self, |
|
| 4106 | name: str, |
|
| 4107 | *, |
|
| 4108 | password: Optional[str] = None, |
|
| 4109 | hosts: Optional[List[str]] = None, |
|
| 4110 | hosts_allow: Optional[bool] = False, |
|
| 4111 | ifaces: Optional[List[str]] = None, |
|
| 4112 | ifaces_allow: Optional[bool] = False, |
|
| 4113 | role_ids: Optional[List[str]] = None, |
|
| 4114 | ) -> Any: |
|
| 4115 | """Create a new user |
|
| 4116 | ||
| 4117 | Arguments: |
|
| 4118 | name: Name of the user |
|
| 4119 | password: Password of the user |
|
| 4120 | hosts: A list of host addresses (IPs, DNS names) |
|
| 4121 | hosts_allow: If True allow only access to passed hosts otherwise |
|
| 4122 | deny access. Default is False for deny hosts. |
|
| 4123 | ifaces: A list of interface names |
|
| 4124 | ifaces_allow: If True allow only access to passed interfaces |
|
| 4125 | otherwise deny access. Default is False for deny interfaces. |
|
| 4126 | role_ids: A list of role UUIDs for the user |
|
| 4127 | ||
| 4128 | Returns: |
|
| 4129 | The response. See :py:meth:`send_command` for details. |
|
| 4130 | """ |
|
| 4131 | if not name: |
|
| 4132 | raise RequiredArgument( |
|
| 4133 | function=self.create_user.__name__, argument='name' |
|
| 4134 | ) |
|
| 4135 | ||
| 4136 | cmd = XmlCommand("create_user") |
|
| 4137 | cmd.add_element("name", name) |
|
| 4138 | ||
| 4139 | if password: |
|
| 4140 | cmd.add_element("password", password) |
|
| 4141 | ||
| 4142 | if hosts: |
|
| 4143 | cmd.add_element( |
|
| 4144 | "hosts", |
|
| 4145 | _to_comma_list(hosts), |
|
| 4146 | attrs={"allow": _to_bool(hosts_allow)}, |
|
| 4147 | ) |
|
| 4148 | ||
| 4149 | if ifaces: |
|
| 4150 | cmd.add_element( |
|
| 4151 | "ifaces", |
|
| 4152 | _to_comma_list(ifaces), |
|
| 4153 | attrs={"allow": _to_bool(ifaces_allow)}, |
|
| 4154 | ) |
|
| 4155 | ||
| 4156 | if role_ids: |
|
| 4157 | for role in role_ids: |
|
| 4158 | cmd.add_element("role", attrs={"id": role}) |
|
| 4159 | ||
| 4160 | return self._send_xml_command(cmd) |
|
| 4161 | ||
| 4162 | def clone_user(self, user_id: str) -> Any: |
|
| 4163 | """Clone an existing user |
|