Profiles¶
The Profiles module manages network configuration profiles.
profiles
¶
Profiles(name=None, central_conn=None, config_dict=dict(), local=None)
¶
Instantiate a configuration Profile object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Profiles require an identifier key/value pair, typically "name" or "id" or another key is used, this value will be mapped accordingly. |
None
|
central_conn
|
NewCentralBase
|
Established Central connection object. |
None
|
config_dict
|
dict
|
Dictionary containing API keys & values used to configure the configuration profile. |
dict()
|
local
|
dict
|
A dictionary containing keys scope_id type int and persona. type str required to designate a local profile. |
None
|
Raises:
| Type | Description |
|---|---|
ParameterError
|
If name is provided but not a valid string. |
Source code in pycentral/profiles/profiles.py
get_resource_str()
¶
Return the resource string for the profile.
Used in profile assignment to scopes.
Returns:
| Type | Description |
|---|---|
str
|
Resource string for the profile, ex: "layer2-vlan/StaffVlan". |
Raises:
| Type | Description |
|---|---|
VerificationError
|
If self.object_data['resource'] or self.name is missing. |
Source code in pycentral/profiles/profiles.py
set_resource(resource)
¶
Set the resource for the profile.
The resource is used for assigning local profiles and is typically the same as the last value (not including name/id) of the API path, ex) "layer2-vlan" for VLAN profiles, "policies" for Policy profiles, etc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource
|
str
|
Resource for the profile, ex: "layer2-vlan". |
required |
Raises:
| Type | Description |
|---|---|
ParameterError
|
If resource is not provided or not a valid string. |
Source code in pycentral/profiles/profiles.py
set_name(name)
¶
Set the name for the profile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name for the profile, ex: "StaffVlan". |
required |
Raises:
| Type | Description |
|---|---|
ParameterError
|
If name is not provided or not a valid string. |
Source code in pycentral/profiles/profiles.py
set_bulk_key(bulk_key)
¶
Set the bulk key for the profile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bulk_key
|
str
|
Bulk key for the profile, ex: "profile". |
required |
Raises:
| Type | Description |
|---|---|
ParameterError
|
If bulk_key is not provided or not a valid string. |
Source code in pycentral/profiles/profiles.py
get_bulk_key()
¶
Return the bulk key for the profile.
Returns:
| Type | Description |
|---|---|
str | None
|
The bulk key if set, otherwise None. |
set_path(path)
¶
Set the URL path for the profile.
Sets self.object_data['path']. Does NOT include base_url
(https://
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
URL path for the profile, ex: "layer2-vlan". |
required |
Raises:
| Type | Description |
|---|---|
ParameterError
|
If URL path is not provided. |
Source code in pycentral/profiles/profiles.py
get_path()
¶
Return the URL path for the profile, excluding base_url.
Returns:
| Type | Description |
|---|---|
str | None
|
The URL path if set, otherwise None. |
set_central_conn(central_conn)
¶
Set the central connection object for the profile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
central_conn
|
NewCentralBase
|
Established Central connection object. |
required |
Raises:
| Type | Description |
|---|---|
ParameterError
|
If central_conn is not provided. |
Source code in pycentral/profiles/profiles.py
get_central_conn()
¶
Retrieve the Central connection object associated with the profile, if set.
Returns:
| Type | Description |
|---|---|
NewCentralBase or None
|
The Central connection object if set, otherwise None. |
Source code in pycentral/profiles/profiles.py
set_config_dict(config_dict)
¶
Set self.config_dict as a copy of the provided dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_dict
|
dict
|
Dictionary containing the configuration properties for a Profile. |
required |
Raises:
| Type | Description |
|---|---|
ParameterError
|
If config_dict is not provided or not a valid dictionary. |
Source code in pycentral/profiles/profiles.py
set_config(config_key, config_value)
¶
Update self.config_dict[config_key] with the provided config_value.
Updates self.config_dict[config_key] with the provided config_value and sets the attribute of the object to match the same config_value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_key
|
str
|
The configuration key to update. |
required |
config_value
|
any
|
The configuration value to set. |
required |
Raises:
| Type | Description |
|---|---|
ParameterError
|
If config_key is not provided or not a valid string. |
Source code in pycentral/profiles/profiles.py
set_local_parameters(local)
¶
Set the local profile parameters for the object.
Dict provided must have the keys scope_id type int and persona type str.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
local
|
dict
|
A dictionary containing keys scope_id type int and persona type str required to designate a local profile. |
required |
Source code in pycentral/profiles/profiles.py
get_local_parameters()
¶
Return required keys/values for local profile API calls.
Returns:
| Type | Description |
|---|---|
dict | None
|
Local attributes dictionary if self.local is set, otherwise None. |
Source code in pycentral/profiles/profiles.py
apply()
¶
Main method used to update or create a Profile.
Checks whether the Profile exists in Central. Calls self.update() if Profile is being updated. Calls self.create() if a Profile is being created.
Returns:
| Type | Description |
|---|---|
bool
|
True if object was created or modified, else False. |
Source code in pycentral/profiles/profiles.py
create()
¶
Create new configuration profile in Central.
This function assumes that required attributes such as central_conn, path, and config_dict are set. Use Profiles.set_path(), Profiles.set_central_conn(), and Profiles.set_config_dict() to ensure all required attributes are set if not provided at initialization.
Returns:
| Type | Description |
|---|---|
tuple(bool, dict)
|
Boolean of operation success, and dict of the API response. |
Raises:
| Type | Description |
|---|---|
VerificationError
|
If required attributes are missing. |
Source code in pycentral/profiles/profiles.py
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 | |
get()
¶
Get a configuration profile in Central.
This function assumes that required attributes such as central_conn and path are set. Use Profiles.set_path() and Profiles.set_central_conn() to ensure all required attributes are set if not provided at initialization.
Returns:
| Type | Description |
|---|---|
tuple(bool, dict)
|
Boolean of operations success, and dict of the get API response. |
Raises:
| Type | Description |
|---|---|
VerificationError
|
If required attributes are missing. |
Source code in pycentral/profiles/profiles.py
compare_objects(obj1, obj2)
¶
Recursively compare two objects (dicts or lists) and report differences.
Prioritizes contents of obj1 and ignores extra attributes in obj2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj1
|
dict | list
|
First object (reference object). |
required |
obj2
|
dict | list
|
Second object (comparison object). |
required |
Returns:
| Type | Description |
|---|---|
list
|
Dictionaries containing differences found. |
Source code in pycentral/profiles/profiles.py
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 | |
update(compare_dict=None, update_data=None)
¶
Updates a configuration profile in Central.
Uses values from self.config_dict OR update_data if provided. If no compare_dict provided the function will execute a GET to retrieve data for the Central profile. If a diff is found, self.config_dict will be pushed to Central. Invalid configurations in self.config_dict or update_data results in a failed update. This function assumes that required attributes such as central_conn, path, and config_dict are set. Use Profiles.set_path(), Profiles.set_central_conn(), and Profiles.set_config_dict() to ensure all required attributes are set if not provided at initialization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
compare_dict
|
dict
|
Optional dict to compare against, if provided no GET request will be executed. |
None
|
update_data
|
dict
|
Values for updating existing profile. |
None
|
Returns:
| Type | Description |
|---|---|
tuple(bool, dict)
|
Boolean of operation result, and dict of the update API response. |
Raises:
| Type | Description |
|---|---|
VerificationError
|
If required attributes are missing. |
ParameterError
|
If compare_dict invalid. |
Source code in pycentral/profiles/profiles.py
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 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 | |
delete()
¶
Delete a profile from Central.
Returns:
| Type | Description |
|---|---|
tuple(bool, dict)
|
Boolean of operation result, and dict of the create API response. |
Source code in pycentral/profiles/profiles.py
create_profile(path, config_dict, central_conn, bulk_key=None, local=None)
staticmethod
¶
Create a configuration profile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The API endpoint for request, omitting base_url - it's recommended to use the helper function pycentral.utils.url_utils.generate_url(). |
required |
config_dict
|
dict
|
Dictionary containing API keys & values used to create the configuration profile. |
required |
central_conn
|
NewCentralBase
|
Established Central connection object. |
required |
bulk_key
|
str
|
The key required to wrap the configurations for multiple profiles for the bulk API - refer to the API reference for valid values. ex: "profile" for DNS, "layer2-vlan" for VLANs, etc. |
None
|
local
|
dict
|
A dictionary containing keys scope_id type int and persona type str required to designate a local profile. |
None
|
Returns:
| Type | Description |
|---|---|
tuple(bool, dict)
|
Boolean of operation result, and dict of the create API response. |
Raises:
| Type | Description |
|---|---|
ParameterError
|
If config_dict is invalid. |
Source code in pycentral/profiles/profiles.py
get_profile(path, central_conn, local=None)
staticmethod
¶
Get existing profile(s) from Central.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The API endpoint for request, omitting base_url - it's recommended to use the helper function pycentral.utils.url_utils.generate_url(). If the path does not include the profile name/id, the API will return all profiles for that type. |
required |
central_conn
|
NewCentralBase
|
Established Central connection object. |
required |
local
|
dict
|
A dictionary containing keys scope_id type int and persona type str required to designate a local profile. |
None
|
Returns:
| Type | Description |
|---|---|
tuple(bool, dict)
|
Boolean of operation result, and dict of the get API response. |
Source code in pycentral/profiles/profiles.py
update_profile(path, config_dict, central_conn, bulk_key=None, local=None)
staticmethod
¶
Update a configuration profile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The API endpoint for request, omitting base_url - it's recommended to use the helper function pycentral.utils.url_utils.generate_url(). |
required |
config_dict
|
dict
|
Dictionary containing API keys & values used to update the configuration profile. |
required |
central_conn
|
NewCentralBase
|
Established Central connection object. |
required |
bulk_key
|
str
|
The key required to wrap the configurations for multiple profiles for the bulk API - refer to the API reference for valid values. ex: "profile" for DNS, "layer2-vlan" for VLANs, etc. |
None
|
local
|
dict
|
A dictionary containing keys scope_id type int and persona type str required to designate a local profile. |
None
|
Returns:
| Type | Description |
|---|---|
tuple(bool, dict)
|
Boolean of operation result, and dict of the update API response. |
Raises:
| Type | Description |
|---|---|
ParameterError
|
If config_dict is invalid or not provided. |
Source code in pycentral/profiles/profiles.py
delete_profile(path, central_conn, local=None)
staticmethod
¶
Delete a configuration profile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The API endpoint for request, omitting base_url - it's recommended to use the helper function pycentral.utils.url_utils.generate_url(). |
required |
central_conn
|
NewCentralBase
|
Established Central connection object. |
required |
local
|
dict
|
A dictionary containing keys scope_id type int and persona type str required to designate a local profile. |
None
|
Returns:
| Type | Description |
|---|---|
tuple(bool, dict)
|
Boolean of operation result, and dict of the delete API response. |
Raises:
| Type | Description |
|---|---|
ParameterError
|
If path is invalid. |
Source code in pycentral/profiles/profiles.py
create_profiles(bulk_key, path, central_conn, list_dict=None, list_obj=None, local=None)
staticmethod
¶
Create multiple configuration profiles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bulk_key
|
str
|
The key required to wrap the configurations for multiple profiles for the bulk API - refer to the API reference for valid values. ex: "profile" for DNS, "layer2-vlan" for VLANs, etc. |
required |
path
|
str
|
The API endpoint for request, omitting base_url - it's recommended to use the helper function pycentral.utils.url_utils.generate_url(). |
required |
central_conn
|
NewCentralBase
|
Established Central connection object. |
required |
list_dict
|
list
|
List of profile configuration dictionaries. |
None
|
list_obj
|
list
|
List of Profiles objects containing the config_dict attribute. |
None
|
local
|
dict
|
A dictionary containing keys scope_id type int and persona type str required to designate a local profile. |
None
|
Returns:
| Type | Description |
|---|---|
tuple(bool, dict)
|
Boolean of operation result, and dict of the create API response. |
Raises:
| Type | Description |
|---|---|
ParameterError
|
If neither list_dict nor list_obj is provided or invalid. |
Source code in pycentral/profiles/profiles.py
update_profiles(bulk_key, path, central_conn, list_dict=None, list_obj=None, local=None)
staticmethod
¶
Update multiple configuration profiles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bulk_key
|
str
|
The key required to wrap the configurations for multiple profiles for the bulk API - refer to the API reference for valid values. ex: "profile" for DNS, "layer2-vlan" for VLANs, etc. |
required |
path
|
str
|
The API endpoint for request, omitting base_url - it's recommended to use the helper function pycentral.utils.url_utils.generate_url(). |
required |
central_conn
|
NewCentralBase
|
Established Central connection object. |
required |
list_dict
|
list
|
List of profile configuration dictionaries. |
None
|
list_obj
|
list
|
List of Profiles objects containing the config_dict attribute. |
None
|
local
|
dict
|
A dictionary containing keys scope_id type int and persona type str required to designate a local profile. |
None
|
Returns:
| Type | Description |
|---|---|
tuple(bool, dict)
|
Boolean of operation result, and dict of the update API response. |
Raises:
| Type | Description |
|---|---|
ParameterError
|
If neither list_dict nor list_obj is provided. |
Source code in pycentral/profiles/profiles.py
delete_profiles(path_list, central_conn, local=None, error_on_fail=True)
staticmethod
¶
Delete multiple configuration profiles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path_list
|
list
|
List of API paths as type string for requests. It's recommended to use the helper function pycentral.utils.url_utils.generate_url(). |
required |
central_conn
|
NewCentralBase
|
Established Central connection object. |
required |
local
|
dict
|
A dictionary containing keys scope_id type int and persona type str required to designate a local profile. |
None
|
error_on_fail
|
bool
|
Flag to indicate whether to log an error with the logger on failure. When flag is set True each delete operation that fails will log the error message from the API response with the central_conn logger. When set, False operations will not log errors to the central_conn logger. |
True
|
Returns:
| Type | Description |
|---|---|
list
|
Empty if profiles were successfully deleted, else populated with failed paths. |
Raises:
| Type | Description |
|---|---|
ParameterError
|
If path_list is invalid. |