Skip to content

added to classic_api #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/reference/models_classic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Network Segments
:toctree: _autosummary

ClassicNetworkSegment
ClassicNetworkSegmentsItem
ClassicNetworkSegmentItem

Packages
--------
Expand Down
90 changes: 84 additions & 6 deletions src/jamf_pro_sdk/clients/classic_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
ClassicComputer,
ClassicComputersItem,
)
from ..models.classic.network_segments import (
ClassicNetworkSegment,
ClassicNetworkSegmentItem,
)
from ..models.classic.packages import ClassicPackage, ClassicPackageItem

if TYPE_CHECKING:
Expand All @@ -45,6 +49,7 @@
int, ClassicAdvancedComputerSearch, ClassicAdvancedComputerSearchesItem
]
PackageId = Union[int, ClassicPackage, ClassicPackageItem]
NetworkSegmentId = Union[int, ClassicNetworkSegment, ClassicNetworkSegmentItem]


def parse_response_id(xml: str) -> int:
Expand Down Expand Up @@ -180,7 +185,8 @@ def get_computers(
computers = self.list_all_computers()

return self.concurrent_api_requests(
self.get_computer_by_id, [{"computer": i, "subsets": subsets} for i in computers]
self.get_computer_by_id,
[{"computer": i, "subsets": subsets} for i in computers],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check that you are using the formatting settings in the project? It looks like black is shortening lines to the default 88 characters when the project file is set to 100.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have black and ruff running from the project's virtual environment they should pick up the correct settings automatically.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will rebuild my .venv I probably did something to break it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a problem with format on save in my VS Code. I'll figure it out on the weekend,

Why black didn't pick it up is another question. Maybe it doesn't unfold sort lines it just folds long ones.

I got black to fix the file.

)

def update_computer_by_id(
Expand Down Expand Up @@ -234,11 +240,16 @@ def set_computer_unmanaged_by_id(self, computer: ComputerId) -> None:
update_management = ClassicComputer(**data)
computer_id = ClassicApi._parse_id(computer)
self.api_request(
method="put", resource_path=f"computers/id/{computer_id}", data=update_management
method="put",
resource_path=f"computers/id/{computer_id}",
data=update_management,
)

def set_computer_managed_by_id(
self, computer: ComputerId, management_user: str = "admin", management_password: str = None
self,
computer: ComputerId,
management_user: str = "admin",
management_password: str = None,
) -> None:
"""Sets the management status to `managed` for a single computer using the ID.

Expand Down Expand Up @@ -272,7 +283,9 @@ def set_computer_managed_by_id(
}
manage_computer = ClassicComputer(**data)
self.api_request(
method="put", resource_path=f"computers/id/{computer_id}", data=manage_computer
method="put",
resource_path=f"computers/id/{computer_id}",
data=manage_computer,
)

# /computergroups APIs
Expand Down Expand Up @@ -416,7 +429,9 @@ def create_advanced_computer_search(
resp = self.api_request(method="post", resource_path="advancedcomputersearches", data=data)
return parse_response_id(resp.text)

def list_all_advanced_computer_searches(self) -> List[ClassicAdvancedComputerSearchesItem]:
def list_all_advanced_computer_searches(
self,
) -> List[ClassicAdvancedComputerSearchesItem]:
"""Returns a list of all advanced computer searches.

:return: List of advanced computer searches.
Expand Down Expand Up @@ -447,7 +462,8 @@ def get_advanced_computer_search_by_id(self, advanced_search: AdvancedComputerSe
"""
advanced_search_id = ClassicApi._parse_id(advanced_search)
resp = self.api_request(
method="get", resource_path=f"advancedcomputersearches/id/{advanced_search_id}"
method="get",
resource_path=f"advancedcomputersearches/id/{advanced_search_id}",
)
return ClassicAdvancedComputerSearch(**resp.json()["advanced_computer_search"])

Expand Down Expand Up @@ -497,6 +513,68 @@ def delete_advanced_computer_search_by_id(self, advanced_search: AdvancedCompute
resource_path=f"advancedcomputersearches/id/{advanced_search_id}",
)

# /networksegments APIs

def list_all_network_segments(self) -> List[ClassicNetworkSegmentItem]:
"""Returns a list of all network segments.

:return: List of network segments.
:rtype: List[ClassicNetworkSegmentItem]

"""
resp = self.api_request(method="get", resource_path="networksegments")
return [ClassicNetworkSegmentItem(**i) for i in resp.json()["network_segments"]]

def get_network_segment_by_id(self, network_segment: NetworkSegmentId) -> ClassicNetworkSegment:
"""Returns a single network segment record using the ID.

:param network_segment: A network segment ID or supported Classic API model.
:type network_segment: Union[int, ClassicNetworkSegment, ClassicNetworkSegmentItem]

:return: Network segment.
:rtype: ClassicNetworkSegment

"""
network_segment_id = ClassicApi._parse_id(network_segment)
resp = self.api_request(
method="get", resource_path=f"networksegments/id/{network_segment_id}"
)
return ClassicNetworkSegment(**resp.json()["network_segment"])

def update_network_segment_by_id(
self, network_segment: NetworkSegmentId, data: Union[str, ClassicNetworkSegment]
) -> None:
"""Update a single network segment record using the ID.

:param network_segment: A network segment ID or supported Classic API model.
:type network_segment: Union[int, ClassicNetworkSegment, ClassicNetworkSegmentItem]

param data: Can be an XML string or a
:class:`~jamf_pro_sdk.models.classic.network_segments.ClassicNetworkSegment` object.
:type data: Union[str, ClassicNetworkSegment]

"""

network_segment_id = ClassicApi._parse_id(network_segment)
self.api_request(
method="put",
resource_path=f"networksegments/id/{network_segment_id}",
data=data,
)

def delete_network_segment_by_id(self, network_segment: NetworkSegmentId) -> None:
"""Delete a single network segment record using the ID.

:param network_segment: A network segment ID or supported Classic API model.
:type network_segment: Union[int, ClassicNetworkSegment, ClassicNetworkSegmentItem]

"""
network_segment_id = ClassicApi._parse_id(network_segment)
self.api_request(
method="delete",
resource_path=f"networksegments/id/{network_segment_id}",
)

# /packages APIs

def create_package(self, data: Union[str, ClassicPackage]) -> int:
Expand Down