NIOS WAPI Operations
Copyright 2023 Infoblox
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
1 | |
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Gift
Bases: NiosServiceMixin, NiosFileopMixin
Handles interactions with the Infoblox WAPI.
This class provides a range of classes to interact with Infoblox WAPI, including session management, data retrieval, file operations, and service management.
Attributes:
| Name | Type | Description |
|---|---|---|
grid_mgr |
str
|
IP address or hostname of the Grid Manager. |
wapi_ver |
str
|
Version of the Infoblox WAPI. |
ssl_verify |
bool
|
Flag to determine SSL certificate verification. |
conn |
Client
|
Active session to the WAPI grid. Default is None. |
grid_ref |
str
|
Reference ID of the connected grid. Default is None. |
Examples:
Initialize the WAPI instance with a dictionary of properties:
Build up the WAPI instance one property at a time:
Source code in src/ibx_sdk/nios/gift.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 | |
url
property
Constructs a property using grid_mgr and wapi_ver attributes for the WAPI class.
Parameters: - grid_mgr (str): The IP address or hostname of the grid manager. - wapi_ver (str): The version of the WAPI.
Returns: - url (str): The URL constructed using the grid manager and WAPI version.
Raises: - None.
Example:
__basic_auth_request(username, password)
This private method makes a request to the specified URL with basic authentication using the provided username and password. It stores the session connection in the instance attribute 'conn*' and the grid reference in the instance attribute 'grid_ref'.
Note
This method requires the 'httpx' library to be installed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
username
|
str
|
The username for basic authentication. |
required |
password
|
str
|
The password for basic authentication. |
required |
Returns:
| Type | Description |
|---|---|
dict | None
|
grid _ref (dict): A dictionary |
Raises:
| Type | Description |
|---|---|
WapiRequestException
|
If an error occurs during the request. |
Source code in src/ibx_sdk/nios/gift.py
__certificate_auth_request(certificate)
This private method performs a certificate authentication request to the API. It uses the provided certificate to establish a connection with the API server using the httpx library.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
certificate
|
str
|
The certificate to be used for authentication with the API. |
required |
Returns:
| Type | Description |
|---|---|
dict | None
|
grid _ref (dict): A dictionary |
Raises:
| Type | Description |
|---|---|
WapiRequestException
|
If there is an error with the request to the API. |
Source code in src/ibx_sdk/nios/gift.py
connect(username=None, password=None, certificate=None)
Make a connection to the grid manager using the WAPI instance
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
username
|
str | None
|
A string representing the username for the connection. (default: None) |
None
|
password
|
str | None
|
A string representing the password for the connection. (default: None) |
None
|
certificate
|
str | None
|
A string representing the certificate for the connection. (default: None) |
None
|
Raises: WapiInvalidParameterException: If neither a username and password nor a certificate is provided.
Source code in src/ibx_sdk/nios/gift.py
delete(wapi_object_ref, **kwargs)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wapi_object_ref
|
str
|
A string representing the reference to the WAPI object that needs to be deleted. |
required |
**kwargs
|
Any
|
Additional keyword arguments that can be passed to the |
{}
|
Returns:
| Type | Description |
|---|---|
Response
|
A |
Source code in src/ibx_sdk/nios/gift.py
get(wapi_object, params=None, **kwargs)
Return WAPI object(s). Args: wapi_object (str): The name of the WAPI object to retrieve. params (Optional[dict]): Optional parameters to include in the request URL. **kwargs: Additional keyword arguments to pass to the request.
Returns:
| Name | Type | Description |
|---|---|---|
Response |
Response
|
The response object containing the result of the request. |
Source code in src/ibx_sdk/nios/gift.py
get_paginated(wapi_object, limit=1000, params=None, **kwargs)
Fetches paginated data from the WAPI API.
This method retrieves data in chunks using a pagination mechanism. The function handles API responses, manages pagination parameters, and consolidates the results into a list. It raises exceptions if timeout, HTTP status errors, or request errors are encountered during the process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wapi_object
|
str
|
The name of the WAPI object to fetch data from. |
required |
limit
|
int
|
Maximum number of records to retrieve per API request. Defaults to 1000. |
1000
|
params
|
Optional[dict]
|
Additional query parameters to include in the request. Defaults to None. |
None
|
**kwargs
|
Any
|
Additional keyword arguments passed to the HTTP GET request. |
{}
|
Returns:
| Type | Description |
|---|---|
List[dict]
|
A list of dictionaries containing the retrieved data from the WAPI API. |
Raises:
| Type | Description |
|---|---|
WapiRequestException
|
If there is a timeout, HTTP status error, or |
Source code in src/ibx_sdk/nios/gift.py
getone(wapi_object, params=None, **kwargs)
Return the reference of a single WAPI object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wapi_object
|
str
|
A string representing the object to retrieve data from. |
required |
params
|
Optional[dict]
|
Optional dictionary of parameters to include in the request. |
None
|
**kwargs
|
Any
|
Additional keyword arguments to be passed to the request. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A string response containing the _ref of the WAPI object. |
Raises:
| Type | Description |
|---|---|
WapiRequestException
|
If multiple data records were returned or no data was returned. |
Source code in src/ibx_sdk/nios/gift.py
max_wapi_ver()
Retrieves and sets the maximum supported version of the WAPI.
This method queries the WAPI to find the highest supported version and updates
the wapi_ver attribute of the instance with this value. It does not return
any value.
Raises:
| Type | Description |
|---|---|
WapiRequestException
|
If there is an error in making the GET request to retrieve the WAPI version. This could be due to network issues, authentication errors, or other problems in the request process. |
Example Usage:
Note
This method updates the wapi_ver attribute of the WAPI session instance.
Source code in src/ibx_sdk/nios/gift.py
object_fields(wapi_object)
Retrieves the object fields for a specified WAPI object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wapi_object
|
str
|
The name of the WAPI object for which to retrieve the fields. |
required |
Returns:
| Type | Description |
|---|---|
Union[str, None]
|
Union[str, None]: A string containing the fields separated by commas, or None if an |
Union[str, None]
|
error occurred. |
Raises:
| Type | Description |
|---|---|
WapiRequestException
|
If there was an error connecting to the WAPI service. |
Example:
Source code in src/ibx_sdk/nios/gift.py
post(wapi_object, data=None, json=None, **kwargs)
Create a POST request to create a WAPI object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wapi_object
|
str
|
The object to which the POST request is being made. |
required |
data
|
optional
|
The data to be sent in the body of the request. Can be a dictionary or a string. Default is None. |
None
|
json
|
optional
|
The JSON data to be sent in the body of the request. Should be a dictionary. Default is None. |
None
|
**kwargs
|
optional
|
Additional keyword arguments to be passed to the request. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Response |
Response
|
The response object containing the server's response to the POST request. |
Source code in src/ibx_sdk/nios/gift.py
put(wapi_object_ref, data=None, **kwargs)
Create a PUT request to update a WAPI object by its _ref.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wapi_object_ref
|
str
|
The reference string for the WAPI object. |
required |
data
|
Optional[dict]
|
Optional data to be sent with the request. Can be a dictionary or a string. Defaults to None. |
None
|
**kwargs
|
Any
|
Additional keyword arguments to be passed to the request. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Response |
Response
|
The response object for the PUT request. |