From 0bf9dd8ed832a42d5093c143d820be8cb06ab352 Mon Sep 17 00:00:00 2001 From: sbasan Date: Tue, 5 Sep 2023 20:12:47 +0200 Subject: [PATCH] add: site policy list builder endpoints --- ENDPOINTS.md | 12 ++- ...uration_policy_data_prefix_list_builder.py | 2 +- .../configuration_policy_site_list_builder.py | 87 +++++++++++++++++++ vmngclient/endpoints/endpoints_container.py | 2 + 4 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 vmngclient/endpoints/configuration_policy_site_list_builder.py diff --git a/ENDPOINTS.md b/ENDPOINTS.md index 42b9878de..41a71d931 100644 --- a/ENDPOINTS.md +++ b/ENDPOINTS.md @@ -52,8 +52,18 @@ PUT /template/policy/list/dataprefix/{id}||[**ConfigurationPolicyDataPrefixListB GET /template/policy/list/dataprefix/{id}||[**ConfigurationPolicyDataPrefixListBuilder.get_lists_by_id**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L62)||[**DataPrefixList**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L38)| GET /template/policy/list/dataprefix||[**ConfigurationPolicyDataPrefixListBuilder.get_policy_lists**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L66)||DataSequence[[**DataPrefixList**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L38)]| GET /template/policy/list/dataprefix/filtered||[**ConfigurationPolicyDataPrefixListBuilder.get_policy_lists_with_info_tag**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L70)||DataSequence[[**DataPrefixList**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L38)]| -POST /template/policy/list/dataprefix/preview||[**ConfigurationPolicyDataPrefixListBuilder.preview_policy_list**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L77)|[**DataPrefixListCreationPayload**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L30)|None| +POST /template/policy/list/dataprefix/preview||[**ConfigurationPolicyDataPrefixListBuilder.preview_policy_list**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L77)|[**DataPrefixListCreationPayload**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L30)|[**PolicyListPreview**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/model/policy_list.py#L37)| GET /template/policy/list/dataprefix/preview/{id}||[**ConfigurationPolicyDataPrefixListBuilder.preview_policy_list_by_id**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L82)||[**PolicyListPreview**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/model/policy_list.py#L37)| +POST /template/policy/list/site/defaultsite||[**ConfigurationPolicySiteListBuilder.create_default_site_list**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_site_list_builder.py#L43)|[**SiteListCreationPayload**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_site_list_builder.py#L30)|[**PolicyListId**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/model/policy_list.py#L11)| +POST /template/policy/list/site||[**ConfigurationPolicySiteListBuilder.create_policy_list**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_site_list_builder.py#L47)|[**SiteListCreationPayload**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_site_list_builder.py#L30)|[**PolicyListId**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/model/policy_list.py#L11)| +DELETE /template/policy/list/site/{id}||[**ConfigurationPolicySiteListBuilder.delete_policy_list**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_site_list_builder.py#L51)||None| +DELETE /template/policy/list/site||[**ConfigurationPolicySiteListBuilder.delete_policy_lists_with_info_tag**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_site_list_builder.py#L55)||None| +PUT /template/policy/list/site/{id}||[**ConfigurationPolicySiteListBuilder.edit_policy_list**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_site_list_builder.py#L62)|[**SiteListEditPayload**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_site_list_builder.py#L34)|None| +GET /template/policy/list/site/{id}||[**ConfigurationPolicySiteListBuilder.get_lists_by_id**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_site_list_builder.py#L66)||[**SiteList**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_site_list_builder.py#L38)| +GET /template/policy/list/site||[**ConfigurationPolicySiteListBuilder.get_policy_lists**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_site_list_builder.py#L70)||DataSequence[[**SiteList**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_site_list_builder.py#L38)]| +GET /template/policy/list/site/filtered||[**ConfigurationPolicySiteListBuilder.get_policy_lists_with_info_tag**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_site_list_builder.py#L74)||DataSequence[[**SiteList**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_site_list_builder.py#L38)]| +POST /template/policy/list/site/preview||[**ConfigurationPolicySiteListBuilder.preview_policy_list**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_site_list_builder.py#L81)|[**SiteListCreationPayload**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_site_list_builder.py#L30)|[**PolicyListPreview**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/model/policy_list.py#L37)| +GET /template/policy/list/site/preview/{id}||[**ConfigurationPolicySiteListBuilder.preview_policy_list_by_id**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_site_list_builder.py#L85)||[**PolicyListPreview**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/model/policy_list.py#L37)| GET /settings/configuration/{setting_type}||[**ConfigurationSettings.get_configuration_by_setting_type**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_settings.py#L208)||dict| GET /settings/configuration/organization||[**ConfigurationSettings.get_organizations**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_settings.py#L212)||DataSequence[[**Organization**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_settings.py#L29)]| GET /settings/configuration/device||[**ConfigurationSettings.get_devices**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_settings.py#L216)||DataSequence[[**Device**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_settings.py#L35)]| diff --git a/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py b/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py index 15f79be2f..4eb998e0f 100644 --- a/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py +++ b/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py @@ -75,7 +75,7 @@ def get_policy_lists_with_info_tag(self, params: InfoTag) -> DataSequence[DataPr ... @post("/template/policy/list/dataprefix/preview") - def preview_policy_list(self, payload: DataPrefixListCreationPayload) -> None: + def preview_policy_list(self, payload: DataPrefixListCreationPayload) -> PolicyListPreview: # TODO: not working for some reason ... diff --git a/vmngclient/endpoints/configuration_policy_site_list_builder.py b/vmngclient/endpoints/configuration_policy_site_list_builder.py new file mode 100644 index 000000000..2949b2b94 --- /dev/null +++ b/vmngclient/endpoints/configuration_policy_site_list_builder.py @@ -0,0 +1,87 @@ +# mypy: disable-error-code="empty-body" +from typing import List + +from pydantic import BaseModel, Field + +from vmngclient.endpoints import APIEndpoints, delete, get, post, put +from vmngclient.model.policy_list import ( + InfoTag, + PolicyList, + PolicyListCreationPayload, + PolicyListEditPayload, + PolicyListId, + PolicyListPreview, +) +from vmngclient.typed_list import DataSequence + + +class SiteListEntry(BaseModel): + class Config: + allow_population_by_field_name = True + + site_id: str = Field(alias="siteId") + + +class SitePayload(BaseModel): + entries: List[SiteListEntry] + type: str = Field(default="site", const=True) + + +class SiteListCreationPayload(SitePayload, PolicyListCreationPayload): + pass + + +class SiteListEditPayload(SitePayload, PolicyListEditPayload): + pass + + +class SiteList(SitePayload, PolicyList): + pass + + +class ConfigurationPolicySiteListBuilder(APIEndpoints): + @post("/template/policy/list/site/defaultsite") + def create_default_site_list(self, payload: SiteListCreationPayload) -> PolicyListId: + ... + + @post("/template/policy/list/site") + def create_policy_list(self, payload: SiteListCreationPayload) -> PolicyListId: + ... + + @delete("/template/policy/list/site/{id}") + def delete_policy_list(self, id: str) -> None: + ... + + @delete("/template/policy/list/site") + def delete_policy_lists_with_info_tag(self, params: InfoTag) -> None: + # TODO: dont know how to assing tags to check if filter works + # (it is present in GET response but cannot be added to POST, PUT payload) + # for now it was tested with default info tag value == "" + ... + + @put("/template/policy/list/site/{id}") + def edit_policy_list(self, id: str, payload: SiteListEditPayload) -> None: + ... + + @get("/template/policy/list/site/{id}") + def get_lists_by_id(self, id: str) -> SiteList: + ... + + @get("/template/policy/list/site", "data") + def get_policy_lists(self) -> DataSequence[SiteList]: + ... + + @get("/template/policy/list/site/filtered", "data") + def get_policy_lists_with_info_tag(self, params: InfoTag) -> DataSequence[SiteList]: + # TODO: dont know how to assing tags to check if filter works + # (it is present in GET response but cannot be added to POST, PUT payload) + # for now it was tested with default info tag value == "" + ... + + @post("/template/policy/list/site/preview") + def preview_policy_list(self, payload: SiteListCreationPayload) -> PolicyListPreview: + ... + + @get("/template/policy/list/site/preview/{id}") + def preview_policy_list_by_id(self, id: str) -> PolicyListPreview: + ... diff --git a/vmngclient/endpoints/endpoints_container.py b/vmngclient/endpoints/endpoints_container.py index 900faf520..3789924b0 100644 --- a/vmngclient/endpoints/endpoints_container.py +++ b/vmngclient/endpoints/endpoints_container.py @@ -13,6 +13,7 @@ from vmngclient.endpoints.configuration_feature_profile import ConfigurationFeatureProfile from vmngclient.endpoints.configuration_group import ConfigurationGroup from vmngclient.endpoints.configuration_policy_data_prefix_list_builder import ConfigurationPolicyDataPrefixListBuilder +from vmngclient.endpoints.configuration_policy_site_list_builder import ConfigurationPolicySiteListBuilder from vmngclient.endpoints.configuration_settings import ConfigurationSettings from vmngclient.endpoints.monitoring_device_details import MonitoringDeviceDetails from vmngclient.endpoints.monitoring_status import MonitoringStatus @@ -36,6 +37,7 @@ def __init__(self, session: vManageSession): self.configuration_device_software_update = ConfigurationDeviceSoftwareUpdate(session) self.configuration_device_template = ConfigurationDeviceTemplate(session) self.configuration_policy_data_prefix_list_builder = ConfigurationPolicyDataPrefixListBuilder(session) + self.configuration_policy_site_list_builder = ConfigurationPolicySiteListBuilder(session) self.configuration_settings = ConfigurationSettings(session) self.monitoring_device_details = MonitoringDeviceDetails(session) self.monitoring_status = MonitoringStatus(session)