Utils¶
Utility modules providing helper functions and common operations.
Base Utils¶
base_utils
¶
new_parse_input_args(token_info)
¶
Parse and validate the input token information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token_info
|
dict or str
|
Dictionary containing token information or a file path to a YAML/JSON file with token information. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Parsed token information for supported applications. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the token_info is invalid. |
Note
When "unified" credentials are present, any "glp" or "new_central" entries
in the same dict are ignored. Unified mode requires client credentials
(client_id, client_secret, and workspace_id). An optional
access_token can be provided to skip initial token creation; the
client credentials are still required for token refresh when the
access token expires. Pass base_url or cluster_name under
unified to also enable Central API calls.
Source code in pycentral/utils/base_utils.py
load_token_info(token_info)
¶
Load token information from a file if it's a string path, or return the dictionary as is.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token_info
|
dict or str
|
Either a dictionary containing token information or a string path to a YAML/JSON file with token information. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Parsed token information dictionary. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the file format is unsupported or the file cannot be parsed. |
FileNotFoundError
|
If the specified file path does not exist. |
Source code in pycentral/utils/base_utils.py
build_url(base_url, path='', params='', query=None, fragment='')
¶
Construct a complete URL based on multiple parts of the URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str
|
Base URL for an HTTP request. |
required |
path
|
str
|
API endpoint path. |
''
|
params
|
str
|
API endpoint path parameters. |
''
|
query
|
dict
|
HTTP request URL query parameters. |
None
|
fragment
|
str
|
URL fragment identifier. |
''
|
Returns:
| Type | Description |
|---|---|
str
|
Parsed URL. |
Source code in pycentral/utils/base_utils.py
console_logger(name, level='DEBUG')
¶
Create an instance of python logging with a formatted output.
Sets the following format for log messages: <date> <time> - <name> - <level> - <message>
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
String displayed after date and time. Define it to identify from which part of the code the log message is generated. |
required |
level
|
str
|
Logging level to display messages from a certain level. |
'DEBUG'
|
Returns:
| Type | Description |
|---|---|
Logger
|
An instance of the logging.Logger class. |
Source code in pycentral/utils/base_utils.py
valid_url(url)
¶
Verify and return the URL in a valid format.
If the URL is missing the https prefix, the function will prepend the prefix after verifying that it's a valid base URL of an Central cluster.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
Base URL for an HTTP request. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Valid base URL. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the URL is invalid. |
Source code in pycentral/utils/base_utils.py
save_access_token(app_name, access_token, token_file_path, logger)
¶
Update the access token for a specific application in the credentials file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_name
|
str
|
Name of the application to update (e.g., "new_central", "glp"). |
required |
access_token
|
str
|
The new access token value. |
required |
token_file_path
|
str
|
Path to the credentials file. |
required |
logger
|
Logger
|
Logger instance to log messages. |
required |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the credentials file doesn't exist. |
ValueError
|
If the app_name isn't found in the credentials file. |
IOError
|
If there is an error writing to the credentials file. |
Source code in pycentral/utils/base_utils.py
Common Utils¶
common_utils
¶
__setattrs__(self, config_attrs)
¶
Dynamically set attributes of an object based on the provided dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_attrs
|
dict
|
Dictionary whose keys will be added as attributes to the object with corresponding values. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary of attribute names and their values. |
Source code in pycentral/utils/common_utils.py
create_attrs(obj, data_dictionary)
¶
Create class attributes from a dictionary.
Uses setattr() to set the value of attributes on the specified object. If an attribute already exists and its current value is not None, it keeps the previous value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
object
|
Object instance to create/set attributes on. |
required |
data_dictionary
|
dict
|
Dictionary containing keys that will become attributes. |
required |
Source code in pycentral/utils/common_utils.py
parse_input_file(file_path)
¶
Parse data from a YAML or JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Path to the file. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Parsed data from the file. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the specified file does not exist. |
ValueError
|
If the file format is unsupported or file cannot be loaded. |
Source code in pycentral/utils/common_utils.py
Constants¶
constants
¶
Constants used across the pycentral package.
This module contains constant values for API endpoints, cluster URLs, and configuration mappings used throughout the pycentral SDK.
Attributes:
| Name | Type | Description |
|---|---|---|
CLUSTER_BASE_URLS |
dict[str, str]
|
Public Central cluster names with their corresponding API Base URLs. You can update this dictionary to add your own private cluster details. You can learn more about Base URLs here. |
SUPPORTED_CONFIG_PERSONAS |
dict[str, str]
|
Supported New Central Device Personas and their corresponding API values. You can learn more about Device Personas here. |
AUTHENTICATION |
dict[str, str]
|
Authentication endpoints for OAuth flows for token creation. |
GLP_URLS |
dict[str, str]
|
GreenLake Platform (GLP) API URLs and endpoints. |
SCOPE_URLS |
dict[str, str]
|
Scope-related API URLs for site and device organization. |
GLP Utils¶
glp_utils
¶
rate_limit_check(input_array, input_size_limit, rate_per_minute)
¶
Check and handle rate limiting for API requests.
Splits the input array into smaller chunks and calculates wait time to prevent rate limit errors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_array
|
list
|
Array of items to process. |
required |
input_size_limit
|
int
|
Maximum size of each chunk. |
required |
rate_per_minute
|
int
|
Maximum number of requests allowed per minute. |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
A tuple containing:
|
Source code in pycentral/utils/glp_utils.py
check_progress(conn, id, module_instance, limit=None)
¶
Check progress of an async GLP API operation.
Polls the status of an asynchronous operation until it completes, times out, or fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
NewCentralBase
|
PyCentral base connection object. |
required |
id
|
str
|
Async transaction ID. |
required |
module_instance
|
object
|
Instance of the module class (Devices or Subscriptions). |
required |
limit
|
int
|
Rate limit for the module. If None, uses default based on module type (20 for Devices, 5 for Subscriptions). |
None
|
Returns:
| Type | Description |
|---|---|
tuple
|
A tuple containing:
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If module_instance is not an instance of Devices or Subscriptions. |
Source code in pycentral/utils/glp_utils.py
Monitoring Utils¶
monitoring_utils
¶
build_timestamp_filter(start_time=None, end_time=None, duration=None, fmt='rfc3339', max_period_days=DEFAULT_MAX_PERIOD_DAYS)
¶
Build a formatted timestamp filter for API queries.
Returns timestamps for filtering based on the provided parameters.
Behavior
- If start_time and end_time are given, parses and converts them to the requested format.
- If duration is given, computes timestamps relative to now. - Max supported duration defaults to 90 days and can be overridden.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_time
|
str
|
RFC3339 or Unix timestamp (ms or s) for start. |
None
|
end_time
|
str
|
RFC3339 or Unix timestamp (ms or s) for end. |
None
|
duration
|
str
|
Duration string like '3h', '2d', '1w', '1m' (hours, days, weeks, minutes). |
None
|
fmt
|
str
|
Output format, either 'rfc3339' or 'unix'. |
'rfc3339'
|
max_period_days
|
int | float
|
Maximum allowed duration, in days. Defaults to DEFAULT_MAX_PERIOD_DAYS. |
DEFAULT_MAX_PERIOD_DAYS
|
Returns:
| Type | Description |
|---|---|
tuple
|
A tuple of (start_time, end_time) formatted strings. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If invalid parameter combinations are provided, the maximum duration is invalid, or duration exceeds the configured maximum. |
Source code in pycentral/utils/monitoring_utils.py
generate_timestamp_str(start_time, end_time, duration, max_period_days=DEFAULT_MAX_PERIOD_DAYS)
¶
Generate a timestamp filter string for API queries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_time
|
str
|
Start timestamp. |
required |
end_time
|
str
|
End timestamp. |
required |
duration
|
str
|
Duration string. |
required |
max_period_days
|
int | float
|
Maximum allowed duration, in days. |
DEFAULT_MAX_PERIOD_DAYS
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted filter string "timestamp gt |
Source code in pycentral/utils/monitoring_utils.py
execute_get(central_conn, endpoint, params=None, version='latest')
¶
Execute a GET request to the monitoring API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
central_conn
|
NewCentralBase
|
Central connection object. |
required |
endpoint
|
str
|
API endpoint path. |
required |
params
|
dict
|
Query parameters for the request. |
None
|
version
|
str
|
API version to use (e.g. "v1alpha1", "v1"). Defaults to "latest". |
'latest'
|
Returns:
| Type | Description |
|---|---|
dict
|
The message portion of the API response. |
Raises:
| Type | Description |
|---|---|
ParameterError
|
If central_conn is None or endpoint is invalid. |
Exception
|
If the API call returns a non-200 status code. |
Source code in pycentral/utils/monitoring_utils.py
simplified_site_resp(site)
¶
Simplify the site response structure for easier consumption.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
site
|
dict
|
Raw site data from API response. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Simplified site data with restructured health, devices, clients, and alerts. |
Source code in pycentral/utils/monitoring_utils.py
clean_raw_trend_data(raw_results, data=None)
¶
Clean and restructure raw trend data from API response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw_results
|
dict
|
Raw trend data containing 'graph' with 'keys' and 'samples'. |
required |
data
|
dict
|
Existing data dictionary to append to. |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with timestamps as keys and metric values as nested dictionaries. |
Source code in pycentral/utils/monitoring_utils.py
merged_dict_to_sorted_list(merged)
¶
Convert a merged dictionary to a sorted list of timestamped entries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
merged
|
dict
|
Dictionary with timestamps as keys. |
required |
Returns:
| Type | Description |
|---|---|
list
|
Sorted list of dictionaries with 'timestamp' key and all associated values. |
Source code in pycentral/utils/monitoring_utils.py
validate_central_conn_and_serial(central_conn, serial_number)
¶
Validate central connection and device serial number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
central_conn
|
NewCentralBase
|
Central connection object (required). |
required |
serial_number
|
str
|
Device serial number (required). |
required |
Raises:
| Type | Description |
|---|---|
ParameterError
|
If central_conn is None or serial_number is missing/invalid. |
Note
Internal SDK function
Source code in pycentral/utils/monitoring_utils.py
validate_query_length(name, value, max_length=MAX_QUERY_LEN)
¶
Raise ParameterError if a query string parameter exceeds the allowed length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Parameter name (used in error message). |
required |
value
|
str | None
|
Parameter value to check. |
required |
max_length
|
int
|
Maximum allowed character length. Defaults to MAX_QUERY_LEN. |
MAX_QUERY_LEN
|
Raises:
| Type | Description |
|---|---|
ParameterError
|
If value is not None and exceeds max_length. |
Source code in pycentral/utils/monitoring_utils.py
validate_limit_and_next(limit, next_page, max_limit, next_name='next_page')
¶
Raise ParameterError if pagination parameters are out of range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int
|
Requested page size. |
required |
next_page
|
int
|
Page cursor/index (must be >= 1). |
required |
max_limit
|
int
|
Maximum allowed value for limit. |
required |
next_name
|
str
|
Name of the next_page parameter for error messages. |
'next_page'
|
Raises:
| Type | Description |
|---|---|
ParameterError
|
If limit exceeds max_limit or next_page is less than 1. |
Source code in pycentral/utils/monitoring_utils.py
validate_required_value(name, value)
¶
Raise ParameterError if a required parameter is missing or empty.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Parameter name (used in error message). |
required |
value
|
Any
|
Parameter value to check. |
required |
Raises:
| Type | Description |
|---|---|
ParameterError
|
If value is None or an empty string. |
Source code in pycentral/utils/monitoring_utils.py
validate_serial_query(serial_number, max_len=MAX_SERIAL_LEN)
¶
Raise ParameterError if an optional serial_number query parameter exceeds max_len.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
serial_number
|
str | None
|
Serial number to validate. Skipped if None. |
required |
max_len
|
int
|
Maximum allowed length. Defaults to MAX_SERIAL_LEN. |
MAX_SERIAL_LEN
|
Raises:
| Type | Description |
|---|---|
ParameterError
|
If serial_number is not None and exceeds max_len. |
Source code in pycentral/utils/monitoring_utils.py
normalize_metric(metric, allowed_metrics, name='metric')
¶
Validate and normalize a metric string against a set of allowed values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric
|
str
|
Metric name provided by the caller. |
required |
allowed_metrics
|
dict | set
|
Collection of allowed metric names (lowercase). |
required |
name
|
str
|
Parameter name for error messages. Defaults to 'metric'. |
'metric'
|
Returns:
| Type | Description |
|---|---|
str
|
Normalized (stripped, lowercased) metric name. |
Raises:
| Type | Description |
|---|---|
ParameterError
|
If metric is not a non-empty string or is not in allowed_metrics. |
Source code in pycentral/utils/monitoring_utils.py
build_trend_params(start_time=None, end_time=None, duration=None, site_id=None, extra_params=None)
¶
Build a query-parameter dict for trend endpoints.
Validates site_id, merges extra_params, and generates a timestamp filter string when any time argument is provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_time
|
int | str
|
Start time (epoch seconds or RFC3339). |
None
|
end_time
|
int | str
|
End time (epoch seconds or RFC3339). |
None
|
duration
|
str | int
|
Duration string (e.g. '3h') or seconds. |
None
|
site_id
|
str
|
Site identifier; validated against MAX_SITE_ID_LEN. |
None
|
extra_params
|
dict
|
Additional parameters to merge into the result. |
None
|
Returns:
| Type | Description |
|---|---|
dict | None
|
Parameter dict, or None if no parameters are set. |
Raises:
| Type | Description |
|---|---|
ParameterError
|
If site_id is too long or timestamp arguments are invalid. |
Source code in pycentral/utils/monitoring_utils.py
normalize_trend_response(response, return_raw_response=False)
¶
Normalize a raw trend API response from any device type.
Dispatches to the appropriate cleaner based on the response shape:
- Switch responses are wrapped in a "response" key and are handled
by _clean_switch_trend_data.
- AP/gateway responses use a "graph" key and are handled by
clean_raw_trend_data.
- Some gateway endpoints wrap the single trend object in a list; such
single-element lists are unwrapped to a dict before processing.
If return_raw_response is True the response is returned as-is (after any single-element list unwrapping so callers always receive a dict).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
dict | list
|
Raw API response. |
required |
return_raw_response
|
bool
|
Return raw payload when True. |
False
|
Returns:
| Type | Description |
|---|---|
dict | list
|
Raw response or normalized sorted list of trend samples. |
Source code in pycentral/utils/monitoring_utils.py
execute_trend_request(central_conn, base_path, serial_number, metric, metric_map, resource_path=None, start_time=None, end_time=None, duration=None, site_id=None, extra_params=None, return_raw_response=False)
¶
Execute a trend API request for a monitoring resource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
central_conn
|
NewCentralBase
|
Central connection object. |
required |
base_path
|
str
|
Base endpoint path (e.g. 'aps', 'gateways'). |
required |
serial_number
|
str
|
Device serial number. |
required |
metric
|
str
|
Metric name to retrieve. |
required |
metric_map
|
dict
|
Mapping of metric names to endpoint path segments. |
required |
resource_path
|
str
|
Sub-resource path segment (e.g. 'ports/1'). |
None
|
start_time
|
int | str
|
Start time for range queries. |
None
|
end_time
|
int | str
|
End time for range queries. |
None
|
duration
|
str
|
Duration string (e.g. '3h'). |
None
|
site_id
|
str
|
Site identifier. |
None
|
extra_params
|
dict
|
Additional query parameters. |
None
|
return_raw_response
|
bool
|
Return raw API payload when True. |
False
|
Returns:
| Type | Description |
|---|---|
dict | list
|
Raw response or normalized trend samples. |
Source code in pycentral/utils/monitoring_utils.py
get_all_pages(method, limit, next_arg_name='next_page', **kwargs)
¶
Fetch all pages from a paginated monitoring API method.
Calls method repeatedly, passing the current page cursor via the keyword argument named next_arg_name, until all items have been retrieved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
callable
|
Single-page fetch method. Must accept |
required |
limit
|
int
|
Page size to request on each call. |
required |
next_arg_name
|
str
|
Name of the pagination cursor parameter. Defaults to 'next_page'. |
'next_page'
|
**kwargs
|
Any
|
Additional keyword arguments forwarded to method on every call. |
{}
|
Returns:
| Type | Description |
|---|---|
list[dict]
|
Aggregated list of all items across all pages. |
Source code in pycentral/utils/monitoring_utils.py
Profile Utils¶
profile_utils
¶
validate_local(local)
¶
Validate local profile attributes and prepare them for API requests.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
local
|
dict or None
|
Local profile attributes dictionary containing scope_id (int) and persona (str). |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Validated local attributes dictionary with object_type set to "LOCAL". |
Raises:
| Type | Description |
|---|---|
ParameterError
|
If local is not a dictionary or missing required keys with correct types. |
Source code in pycentral/utils/profile_utils.py
Scope Utils¶
scope_utils
¶
fetch_attribute(obj, attribute)
¶
Fetch the value associated with the provided attribute in the object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
object
|
Object whose attribute has to be returned. |
required |
attribute
|
str
|
Attribute within the object that has to be returned. |
required |
Returns:
| Type | Description |
|---|---|
any
|
Value of the required attribute if it exists, None otherwise. |
Source code in pycentral/utils/scope_utils.py
update_attribute(obj, attribute, new_value)
¶
Update the value of the provided attribute in the object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
object
|
Object whose attribute has to be updated. |
required |
attribute
|
str
|
Attribute within the object that has to be updated. |
required |
new_value
|
any
|
New value to set for the attribute. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the attribute was successfully updated, False otherwise. |
Source code in pycentral/utils/scope_utils.py
get_attributes(obj)
¶
Return all attributes of the provided object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
object
|
Object whose attributes have to be returned. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary of attributes defined in the object. |
Source code in pycentral/utils/scope_utils.py
get_all_scope_elements(obj, scope)
¶
Make GET API calls to Central to get all elements of the specified scope.
This method is supported for site, site collection, and device groups scopes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
object
|
Class instance that will be used to make API calls to Central. |
required |
scope
|
str
|
The type of the element. Valid values: "site", "site_collection", "device_group". |
required |
Returns:
| Type | Description |
|---|---|
list or None
|
List of all scope elements, or None if there are errors. |
Source code in pycentral/utils/scope_utils.py
get_scope_elements(obj, scope, limit=50, offset=0, filter_field='', sort='')
¶
Make GET API calls to Central to get scope elements based on provided attributes.
This method is supported for site, site collection, and device groups scopes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
object
|
Class instance that will be used to make API calls to Central. |
required |
scope
|
str
|
The type of the element. Valid values: "site", "site_collection", "device_group". |
required |
limit
|
int
|
Number of scope elements to be fetched. |
50
|
offset
|
int
|
Pagination start index. |
0
|
filter_field
|
str
|
Field for sorting. For sites: scopeName, address, state, country, city, deviceCount, collectionName, zipcode, timezone. For site_collection: scopeName, description, deviceCount, siteCount. |
''
|
sort
|
str
|
Direction of sorting. Accepted values: ASC or DESC. |
''
|
Returns:
| Type | Description |
|---|---|
dict or None
|
API response with scope elements, or None if there are errors. |
Source code in pycentral/utils/scope_utils.py
set_attributes(obj, attributes_dict, required_attributes, optional_attributes=None, object_attributes=None)
¶
Set attributes of the given object based on the attributes dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
object
|
Class instance whose attributes will be set. |
required |
attributes_dict
|
dict
|
Dictionary of attributes to set on the object. |
required |
required_attributes
|
list
|
List of required attribute names. |
required |
optional_attributes
|
dict
|
Dictionary of optional attributes with their default values. |
None
|
object_attributes
|
dict
|
Dictionary of object-type attributes with their default values. |
None
|
Source code in pycentral/utils/scope_utils.py
get_scope_element(obj, scope, scope_id=None)
¶
Make GET API calls to Central to find the specified scope element.
This method is supported for site, site collection, and device groups scopes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
object
|
Class instance that will be used to make API calls to Central. |
required |
scope
|
str
|
The type of the element. Valid values: "site", "site_collection", "device_group". |
required |
scope_id
|
int
|
ID of the scope element to be returned. |
None
|
Returns:
| Type | Description |
|---|---|
dict or None
|
Attributes of the scope element if found, None otherwise. |
Source code in pycentral/utils/scope_utils.py
rename_keys(api_dict, api_attribute_mapping)
¶
Rename the keys of attributes from the API response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_dict
|
dict
|
Dictionary of information from Central API Response. |
required |
api_attribute_mapping
|
dict
|
Dictionary mapping API keys to object attributes. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Renamed dictionary with keys mapped to object attributes. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an unknown attribute is found in the API response. |
Source code in pycentral/utils/scope_utils.py
validate_find_scope_elements(ids=None, names=None, serials=None, scope='')
¶
Validate the input parameters for finding scope elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ids
|
str or list
|
ID(s) of the element(s). |
None
|
names
|
str or list
|
Name(s) of the element(s). |
None
|
serials
|
str or list
|
Serial number(s) of the element(s) (only for devices). |
None
|
scope
|
str
|
Specific scope to search in (e.g., "site", "device"). |
''
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If validation fails due to multiple parameters or invalid scope for serials. |
Source code in pycentral/utils/scope_utils.py
validate_iso_location(state=None, country=None, city=None)
¶
Validate the input parameters for ISO 3166-1 short name format for location.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
str
|
State name, i.e., "California". |
None
|
country
|
str
|
Country name, i.e., "United States". |
None
|
city
|
str
|
City name, i.e., "San Francisco". |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If validation fails invalid values. |
Source code in pycentral/utils/scope_utils.py
lookup_in_map(keys, lookup_map)
¶
Perform lookup in a map for the given key(s).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
keys
|
str, int, or list
|
Key(s) to look up. |
required |
lookup_map
|
dict
|
Map to search in. |
required |
Returns:
| Type | Description |
|---|---|
any or list or None
|
Found value(s) or None if not found. |
Source code in pycentral/utils/scope_utils.py
Troubleshooting Utils¶
troubleshooting_utils
¶
Utilities for troubleshooting operations
This module provides constants related to supported device types and mappings for troubleshooting methods to supported devices.
Attributes:
| Name | Type | Description |
|---|---|---|
SUPPORTED_DEVICE_TYPES |
list[str]
|
List of supported device types for troubleshooting operations. |
TROUBLESHOOTING_METHOD_DEVICE_MAPPING |
dict[str, list[str]]
|
Mapping of troubleshooting method names to lists of compatible device types. Each key represents a supported troubleshooting test, and the value is a list of device types that support it. |
URL utils¶
url_utils
¶
get_prefix(category='configuration', version='latest')
¶
Generate URL prefix for a given category and version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
category
|
str
|
API category name. |
'configuration'
|
version
|
str
|
API version. |
'latest'
|
Returns:
| Type | Description |
|---|---|
str
|
URL prefix in the format "category_value/version/". |
Raises:
| Type | Description |
|---|---|
ValueError
|
If category is not supported or version is invalid. |
Source code in pycentral/utils/url_utils.py
generate_url(api_endpoint, category='configuration', version='latest')
¶
Generate complete API URL for a given endpoint, category, and version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_endpoint
|
str
|
The API endpoint path to append to the URL. |
required |
category
|
str
|
API category name. |
'configuration'
|
version
|
str
|
API version. |
'latest'
|
Returns:
| Type | Description |
|---|---|
str
|
Complete API URL in the format "category[value]/version/api_endpoint". |
Raises:
| Type | Description |
|---|---|
ValueError
|
If category is not supported or version is invalid. |
TypeError
|
If api_endpoint is not a string. |