Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
dev-uxmt: merge main (0.33.8) (#728)
Browse files Browse the repository at this point in the history
* Revert "Dev/rebase migration" (#513)

* Fix find_template_values when vipValue not present (#520)

* clear cookies on login, bump minor (#532)

* [Fix] validation software timeout (#534)

* clear cookies on login, bump minor

* fix validation value

---------

Co-authored-by: sbasan <[email protected]>

* fix log message level for request exceptions

* bump patch version

* disable relogin flag during logout (#537)

* fix typo (#542)

* update deprecated github actions (#544)

* update deprecated github actions

* fix type error

* Simplify conditional logic. Add comments. Create new field in cisco vpn feature template model. (new in 20.14)

* Transfer to cisco-open repository (#1)

* use new uri, add missing copyright, bump version, regenerate ENDPOINTS.md

* regenerate endpoints after rebase

* define codeowners

* .github codeowners

* usernames in codeowners

* remove pydantic v1 models (#10)

* remove pydantic v1 models

* fix problems

* bump minor version

* Fix DeviceData types (#13)

* Fix DeviceData types

* Bump sdk version

* Update README.md

* Update README.md

* Update README.md

* Update README.md

* Add default None values to the Tier model (#16)

* Fix: admintech wait (#17)

* version check and model update for user

* admin tech - wait for file ready

* get token

* correct logic

* Add default None values to the Tier model (#16)

---------

Co-authored-by: Nikhil <[email protected]>
Co-authored-by: PrzeG <[email protected]>

* fix admintech, generate endpoints md for new release (#18)

* generate endpoints md

* fix admintech api and unittests

* Update README.md

* Update versions_utils.py

```
--------------------------------------------------
nExpress_mtt.test_nExpress_mtt_verify_provider_software_upgrade_data
--------------------------------------------------
verify_provider_software_upgrade_vmanage(PROVIDER)
[PASS] "All VManages updated correctly."

verify_provider_software_upgrade_vbond(PROVIDER)
[PASS] "All VBonds updated correctly."

verify_set_default_partition_for_vbond(PROVIDER)
[PASS] "Successfully set the default version for partition."
```

* Update versions_utils.py

* Update versions_utils.py

* Update versions_utils.py

* Release 0.33.3

* server_info

* monitoring

* monitoring

* tests

* fix tags field for DeviceDetailsResponse

* unit-test

* enhance modesl for configuration_settings

* don't use Union

* allow centralized cli policy creation

* fix for groupId for get_list_of_installed_devices

* Release/0.33.4

* url_monitoring initial commit

* GET Monitoring Security Policy Device List (#45)

* GET Monitoring Security Policy Device List

* Update security_policy.py

* Update security_policy.py

* Update test_monitoring_security_policy.py

* Add files via upload

* Delete endpoints/endpoints_container.py

* Delete endpoints/monitoring/security_policy.py

* Delete models/security_policy.py

* Delete tests/test_monitoring_security_policy.py

* Add files via upload

* Add files via upload

* Update security_policy.py

* Delete catalystwan/models/security_policy.py

* Update endpoints_container.py

* Update endpoints_container.py

* Update security_policy.py

* Update security_policy.py

* Update test_monitoring_security_policy.py

* Update security_policy.py

* Update security_policy.py

* Adding api support for Lxc virutal image Upgrade,Activate and Delete action

* Ran black and flake8 on change files

* Fixing poetry check error from pre-commit

* Fixing errors from pre-commit

* Release/0.33.5

* fix pre-commit for python 3.12 (#614)

* Update README.md

* Update README.md

* allow disabling of response validation against pydantic model

* rename property, remove print from tests

* unit tests added for url_monitoring

* updated the imports

* updated import sort

* Fix sequence creation when payload is None. Use Field instead of conint

* Revert breaking change

* Fix value for field examples

* include original cause and info from server in ManagerHTTPError

* fix: request and response must be provided as kwargs

* Bump version to 0.33.6

* introduce find method for DataSequence (#627)

* api and endpoints containers as cached properties (#629)

* hotfix ManagerErrorInfo model

* Fix find_template_values to return device variables in correct structure

* Delete if condition with pass

* Fix Issue646 Not content in response

* restore tenant model validate during login

* bump release version

* alarms-20.15

* 0.33.8

* Validate XSRF token returned by server

In same case this token can be login page and raise incorrect error in future login flow.

* Add copy and deepcopy

* Remove 2023 license

* merge and fix confilcts

---------

Co-authored-by: PrzeG <[email protected]>
Co-authored-by: cicharka <[email protected]>
Co-authored-by: JimOverholt <[email protected]>
Co-authored-by: Jakub Krajewski <[email protected]>
Co-authored-by: Nikhil <[email protected]>
Co-authored-by: Piotr Smialkowski <[email protected]>
Co-authored-by: Jim Overholt <[email protected]>
Co-authored-by: acichon <[email protected]>
Co-authored-by: nikhilkp93 <[email protected]>
Co-authored-by: Renuka Mohan Channapatna (rchannap) <[email protected]>
Co-authored-by: Robert Mooy <[email protected]>
Co-authored-by: Surendran Palanimuthu <[email protected]>
Co-authored-by: renukavinay <[email protected]>
Co-authored-by: Jakub Krajewski <[email protected]>
  • Loading branch information
15 people authored Jun 11, 2024
1 parent fdb1dd7 commit 6488f61
Show file tree
Hide file tree
Showing 80 changed files with 1,547 additions and 717 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ repos:
hooks:
- id: flake8
additional_dependencies: [
"flake8-quotes==3.3.2"
"flake8-quotes==3.4.0"
]
fail_fast: true

Expand Down
12 changes: 8 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ Start reading our code, and you'll get the hang of it.
Example:
```python
# to keep example brief we define models and endpoints in single file - however it is suggested to use separate files
from pydantic import BaseModel, Field
from typing import List
from catalystwan.endpoints import APIEndpoints, delete, versions, view
Expand All @@ -112,17 +113,20 @@ Start reading our code, and you'll get the hang of it.

Please note that when using `@request` decorator method must have no body. Request will be built automatically and return value based on defined type will be provided.

API endpoints Definitions can be found in: `catalystwan/endpoints` directory.
API endpoints definitions can be found in: `catalystwan/endpoints` directory.

The organization of items **strictly** follows an OpenAPI spec: https://developer.cisco.com/docs/sdwan/#!sd-wan-vmanage-v20-9
The organization of items should follow OpenAPI spec: https://developer.cisco.com/docs/sdwan/#!sd-wan-vmanage-v20-9

For example with given tag `Configuration - Feature Profile (SDWAN)` items should be placed in:
- `catalystwan/endpoints/configuration/feature_profile/sdwan/...` for APIEndpoints sub-classes
- `catalystwan/models/configuration/feature_profile/sdwan/...` for pydantic models defining payload, return type and possibly query params.

Auto generated python methods names can be found in: https://ghe-msite.cisco.com/sbasan/openapi-generator-vmanage

If common data-model is being reused by more than one `APIEndpoints` class it should be moved to `catalystwan/model` folder with appropriate module name.

Dedicated pre-commit step will automatically check corectness and add documentation for endpoints with `@request` (or `@get`, `@post`, `@put`, `@delete`) decorator.

Custom payload types are allowed (eg. for sending various types of files) please check example: [**SoftwarePackageUpdatePayload**](catalystwan/utils/upgrades_helper.py#L68)
Custom payload types are allowed (eg. for sending various types of files) please check example: [**SoftwarePackageUploadPayload**](catalystwan/utils/upgrades_helper.py#L77)

1. Check that endpoints you want to utilize in your API already defined in `catalystwan/endpoints`.
2. If endpoint not present, create new file with endpoint including data-model and methods with `@request`, `@view` and `@versions` decorators when needed.
Expand Down
287 changes: 145 additions & 142 deletions ENDPOINTS.md

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ alarms_from_n_hours = session.api.alarms.get(from_time=n)
To get all critical alarms from past `n` hours:

```python
from catalystwan.utils.alarm_status import Severity
n = 48
critical_alarms = session.api.alarms.get(from_time=n).filter(severity=Severity.CRITICAL)
```
Expand All @@ -196,6 +197,7 @@ critical_alarms = session.api.alarms.get(from_time=n).filter(severity=Severity.C
session.api.users.get()

# Create user
from catalystwan.endpoints.administration_user_and_group import User
new_user = User(username="new_user", password="new_user", group=["netadmin"], description="new user")
session.api.users.create(new_user)

Expand Down
2 changes: 1 addition & 1 deletion catalystwan/abstractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ def session_type(self) -> Optional[SessionType]:
...

@property
def validate_response(self) -> bool:
def validate_responses(self) -> bool:
...
7 changes: 6 additions & 1 deletion catalystwan/api/alarms_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ def get(self, from_time: Optional[int] = None) -> DataSequence[AlarmData]:
>>> alarms = AlarmsAPI(session).get()
>>> critical_alarms = alarms.filter(severity=Severity.CRITICAL)
"""
query: Dict[str, Any] = {"query": {"condition": "AND", "rules": []}}
query: Dict[str, Any] = {
"query": {
"condition": "AND",
"rules": [{"field": "active", "type": "boolean", "value": ["true"], "operator": "equal"}],
}
}
if from_time:
query["query"]["rules"].append(
{
Expand Down
2 changes: 2 additions & 0 deletions catalystwan/api/api_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from catalystwan.api.tenant_management_api import TenantManagementAPI
from catalystwan.api.tenant_migration_api import TenantMigrationAPI
from catalystwan.api.versions_utils import RepositoryAPI
from catalystwan.api.virtual_image_action_api import LxcActionAPI

if TYPE_CHECKING:
from catalystwan.session import ManagerSession
Expand All @@ -59,6 +60,7 @@ def __init__(self, session: ManagerSession):
self.repository = RepositoryAPI(session)
self.resource_pool = ResourcePoolAPI(session)
self.software = SoftwareActionAPI(session)
self.lxcsoftware = LxcActionAPI(session)
self.partition = PartitionManagerAPI(session)
self.users = UsersAPI(session)
self.cluster_management = ClusterManagementAPI(session)
Expand Down
3 changes: 2 additions & 1 deletion catalystwan/api/configuration_groups/parcel.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class _ParcelBase(BaseModel):
validation_alias="description",
description="Set the parcel description",
)
data: Optional[Any] = None
_parcel_data_key: str = PrivateAttr(default="data")

@model_serializer(mode="wrap")
Expand Down Expand Up @@ -86,7 +87,7 @@ class OptionType(str, Enum):


class ParcelAttribute(BaseModel):
model_config = ConfigDict(extra="forbid", populate_by_name=True)
model_config = ConfigDict(extra="forbid")
option_type: OptionType = Field(serialization_alias="optionType", validation_alias="optionType")


Expand Down
78 changes: 73 additions & 5 deletions catalystwan/api/versions_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
from pydantic import BaseModel, ConfigDict, Field

from catalystwan.endpoints.configuration.software_actions import SoftwareImageDetails
from catalystwan.endpoints.configuration_device_actions import PartitionDevice
from catalystwan.endpoints.configuration_device_actions import (
InstallLxcImage,
LxcActivateDevice,
LxcUpgradeDevice,
PartitionDevice,
)
from catalystwan.endpoints.configuration_device_inventory import DeviceDetailsResponse
from catalystwan.exceptions import ImageNotInRepositoryError
from catalystwan.typed_list import DataSequence
Expand Down Expand Up @@ -67,6 +72,18 @@ def get_all_software_images(self) -> DataSequence[SoftwareImageDetails]:
software_images = self.session.endpoints.configuration_software_actions.get_list_of_all_images()
return software_images

def get_all_virtual_images(self) -> DataSequence[SoftwareImageDetails]:
"""
Get all info about all software images stored in Vmanage repository
Returns:
list: software images list
"""
software_images = self.session.endpoints.configuration_software_actions.get_list_of_all_images(
"imageType=virtualmachine"
)
return software_images

def get_devices_versions_repository(self) -> Dict[str, DeviceSoftwareRepository]:
"""
Create DeviceSoftwareRepository dataclass,
Expand Down Expand Up @@ -209,6 +226,54 @@ def _validate_devices_required_fields(self, devices: DataSequence[DeviceDetailsR
f"device.device_ip (current value: {device.device_ip})"
)

def get_lxcactivate_device_list(
self,
version_to_set_up: str,
devices: DataSequence[DeviceDetailsResponse],
) -> DataSequence[LxcActivateDevice]:
self._validate_devices_required_fields(devices)
install_image_payload = [
InstallLxcImage(
network_function_type="app-hosting",
version_name=version_to_set_up,
version_type_name="UTD-Snort-Feature",
)
]
devices_payload = DataSequence(
LxcActivateDevice,
[
LxcActivateDevice(
device_id=str(device.uuid),
device_ip=str(device.local_system_ip),
install_images=install_image_payload,
)
for device in devices
], # type: ignore
)

return devices_payload

def get_lxcupgrade_device_list(
self,
version_to_set_up: str,
devices: DataSequence[DeviceDetailsResponse],
) -> DataSequence[LxcUpgradeDevice]:
self._validate_devices_required_fields(devices)
install_image_payload = [InstallLxcImage(version_name=version_to_set_up)]
devices_payload = DataSequence(
LxcUpgradeDevice,
[
LxcUpgradeDevice(
device_id=str(device.uuid),
device_ip=str(device.local_system_ip),
install_images=install_image_payload,
)
for device in devices
], # type: ignore
)

return devices_payload

def _get_device_list_in(
self, version_to_set_up: str, devices: DataSequence[DeviceDetailsResponse], version_type: str
) -> DataSequence[PartitionDevice]:
Expand All @@ -227,8 +292,10 @@ def _get_device_list_in(
self._validate_devices_required_fields(devices)
devices_payload = DataSequence(
PartitionDevice,
[PartitionDevice(device_id=device.uuid, device_ip=device.device_ip) for device in devices], # type: ignore
[PartitionDevice(device_id=str(device.uuid), device_ip=str(device.local_system_ip)) for device in devices],
# type: ignore
)

all_dev_versions = self.repository.get_devices_versions_repository()
for device in devices_payload:
device_versions = getattr(all_dev_versions[device.device_id], version_type)
Expand Down Expand Up @@ -295,9 +362,10 @@ def _get_devices_chosen_version(

devices_payload = DataSequence(
PartitionDevice,
[PartitionDevice(
device_id=device.uuid, device_ip=device.local_system_ip # type: ignore
) for device in devices], # type: ignore
[
PartitionDevice(device_id=device.uuid, device_ip=device.local_system_ip) # type: ignore
for device in devices
], # type: ignore
)
all_dev_versions = self.repository.get_devices_versions_repository()
for device in devices_payload:
Expand Down
Loading

0 comments on commit 6488f61

Please sign in to comment.