10000 feat: added clients for systems management service create virtual sys… · ni/nisystemlink-clients-python@f73c04f · GitHub
[go: up one dir, main page]

Skip to content

Commit f73c04f

Browse files
ammarhusain-EMRAmmar Husain Mian FazululAravindhan Palanisamy
authored
feat: added clients for systems management service create virtual system, remove systems and query system API (#138)
Co-authored-by: Ammar Husain Mian Fazulul <ammar.husain.mian.fazulul@ni.com> Co-authored-by: Aravindhan Palanisamy <aravindhan.palanisamy@ni.corp.natinst.com>
1 parent dd9907f commit f73c04f

File tree

13 files changed

+471
-2
lines changed

13 files changed

+471
-2
lines changed

docs/api_reference/systems.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.. _api_tag_page:
2+
3+
nisystemlink.clients.systems
4+
======================
5+
6+
.. autoclass:: nisystemlink.clients.spec.SystemsClient
7+
:exclude-members: __init__
8+
9+
.. automethod:: __init__
10+
.. automethod:: create_virtual_system
11+
.. automethod:: remove_systems
12+
.. automethod:: query_systems
13+
14+
.. automodule:: nisystemlink.clients.systems.models
15+
:members:
16+
:imported-members:

docs/getting_started.rst

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,6 @@ Create, query, retry, and cancel notebook executions.
321321
:language: python
322322
:linenos:
323323

324-
325324
Asset Management API
326325
-------
327326

@@ -346,4 +345,30 @@ create, delete and query asset
346345

347346
.. literalinclude:: ../examples/assetmanagement/assets.py
348347
:language: python
349-
:linenos:
348+
:linenos:
349+
350+
Systems API
351+
-------
352+
353+
Overview
354+
~~~~~~~~
355+
356+
The :class:`.SystemsClient` class is the primary entry point of the Systems API.
357+
358+
When constructing a :class:`.SystemsClient`, you can pass an
359+
:class:`.HttpConfiguration` (like one retrieved from the
360+
:class:`.HttpConfigurationManager`), or let :class:`.SystemsClient` use the
361+
default connection. The default connection depends on your environment.
362+
363+
With a :class:`.SystemsClient` object, you can:
364+
365+
* Create, query, and remove systems.
366+
367+
Examples
368+
~~~~~~~~
369+
370+
Create, query, and remove some systems.
371+
372+
.. literalinclude:: ../examples/systems/systems.py
373+
:language: python
374+
:linenos:

examples/systems/systems.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from nisystemlink.clients.core._http_configuration import HttpConfiguration
2+
from nisystemlink.clients.systems._systems_client import SystemsClient
3+
from nisystemlink.clients.systems.models._create_virtual_systems_request import (
4+
CreateVirtualSystemRequest,
5+
)
6+
from nisystemlink.clients.systems.models._query_systems_request import (
7+
QuerySystemsRequest,
8+
)
9+
10+
# Setup the server configuration to point to your instance of
11+
# SystemLink Enterprise.
12+
server_configuration = HttpConfiguration(
13+
server_uri="https://yourserver.yourcompany.com",
14+
api_key="YourAPIKeyGeneratedFromSystemLink",
15+
)
16+
client = SystemsClient(configuration=server_configuration)
17+
18+
# Systems request metadata.
19+
create_virtual_system_request: CreateVirtualSystemRequest = CreateVirtualSystemRequest(
20+
alias="Python integration virtual system",
21+
workspace="33eba2fe-fe42-48a1-a47f-a6669479a8aa",
22+
)
23+
24+
# Create a virtual system.
25+
create_virtual_system_response = client.create_virtual_system(
26+
create_virtual_system_request=create_virtual_system_request
27+
)
28+
29+
minion_id = None
30+
31+
if create_virtual_system_response and create_virtual_system_response.minionId:
32+
minion_id = create_virtual_system_response.minionId
33+
34+
# Query systems using id.
35+
query_systems_request = QuerySystemsRequest(
36+
filter=f'id="{minion_id}"', projection="new(id, alias)"
37+
)
38+
39+
client.query_systems(query=query_systems_request)
40+
41+
# Delete the created systems.
42+
if minion_id is not None:
43+
remove_systems = [minion_id]
44+
client.remove_systems(tgt=remove_systems)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from nisystemlink.clients.systems._systems_client import SystemsClient
2+
3+
# flake8: noqa
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
"""Implementation of SystemsClient"""
2+
3+
from typing import List, Optional
4+
5+
from nisystemlink.clients import core
6+
from nisystemlink.clients.core._uplink._base_client import BaseClient
7+
from nisystemlink.clients.core._uplink._methods import post
8+
from uplink import Field, retry
9+
10+
from . import models
11+
12+
13+
@retry(
14+
when=retry.when.status(408, 429, 502, 503, 504),
15+
stop=retry.stop.after_attempt(5),
16+
on_exception=retry.CONNECTION_ERROR,
17+
)
18+
class SystemsClient(BaseClient):
19+
20+
def __init__(self, configuration: Optional[core.HttpConfiguration] = None):
21+
"""Initialize an instance.
22+
23+
Args:
24+
configuration: Defines the web server to connect to and information about
25+
how to connect. If not provided, the
26+
:class:`HttpConfigurationManager <nisystemlink.clients.core.HttpConfigurationManager>`
27+
is used to obtain the configuration.
28+
29+
Raises:
30+
ApiException: if unable to communicate with the Systems Service.
31+
"""
32+
if configuration is None:
33+
configuration = core.HttpConfigurationManager.get_configuration()
34+
35+
super().__init__(configuration, base_path="/nisysmgmt/v1/")
36+
37+
@post("virtual")
38+
def create_virtual_system(
39+
self, create_virtual_system_request: models.CreateVirtualSystemRequest
40+
) -> models.CreateVirtualSystemResponse:
41+
"""Creates a virtual system.
42+
43+
Args:
44+
alias: The alias of the virtual system.
45+
workspace: The workspace to create the virtual system in.
46+
47+
Raises:
48+
ApiException: if unable to communicate with the `/nisysmgmt` service or provided invalid
49+
arguments.
50+
"""
51+
...
52+
53+
@post("query-systems")
54+
def query_systems(
55+
self, query: models.QuerySystemsRequest
56+
) -> models.QuerySystemsResponse:
57+
"""Queries for systems that match the filter.
58+
59+
Args:
60+
query : The query contains a DynamicLINQ query string in addition to other details
61+
about how to filter and return the list of systems.
62+
63+
Returns:
64+
Response containing the list of systems that match the filter.
65+
66+
Raises:
67+
ApiException: if unable to communicate with the `/nisysmgmt` Service or provided invalid
68+
arguments.
69+
"""
70+
...
71+
72+
@post("remove-systems", args=[Field("tgt")])
73+
def remove_systems(self, tgt: List[str]) -> models.RemoveSystemsResponse:
74+
"""Removes multiple systems.
75+
76+
Args:
77+
virtual_system_to_remove : List of unique IDs of systems.
78+
79+
Returns:
80+
A partial success if any systems failed to remove, or None if all
81+
systems were removed successfully.
82+
83+
Raises:
84+
ApiException: if unable to communicate with the `/nisysmgmt` Service
85+
or provided an invalid argument.
86+
"""
87+
...
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from nisystemlink.clients.systems.models._create_virtual_systems_request import (
2+
CreateVirtualSystemRequest,
3+
)
4+
from nisystemlink.clients.systems.models._create_virtual_systems_response import (
5+
CreateVirtualSystemResponse,
6+
)
7+
from nisystemlink.clients.systems.models._query_systems_request import (
8+
QuerySystemsRequest,
9+
)
10+
from nisystemlink.clients.systems.models._query_systems_response import (
11+
QuerySystemsResponse,
12+
)
13+
from nisystemlink.clients.systems.models._remove_systems_response import (
14+
RemoveSystemsResponse,
15+
)
16+
17+
# flake8: noqa
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from nisystemlink.clients.core._uplink._json_model import JsonModel
2+
3+
4+
class CreateVirtualSystemRequest(JsonModel):
5+
"""Model for create virtual system response containing the minion ID of the system which is created."""
6+
7+
alias: str
8+
"""Alias of the virtual system."""
9+
10+
workspace: str
11+
"""Workspace to create the virtual system in."""
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from typing import Optional
2+
3+
from nisystemlink.clients.core._uplink._json_model import JsonModel
4+
5+
6+
class CreateVirtualSystemResponse(JsonModel):
7+
"""Model for create virtual system response containing the minion ID of the system which is created."""
8+
9+
minionId: Optional[str] = None
10+
"""The minion ID of the created virtual system."""
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
from typing import Optional
2+
3+
from nisystemlink.clients.core._uplink._json_model import JsonModel
4+
5+
6+
class QuerySystemsRequest(JsonModel):
7+
"""Model for query systems request."""
8+
9+
skip: Optional[int] = None
10+
"""Gets or sets the number of systems to skip."""
11+
12+
take: Optional[int] = None
13+
"""Gets or sets number of systems to return maximum value is 1000."""
14+
15+
filter: Optional[str] = None
16+
"""The systems query filter is dynamic LINQ format.
17+
18+
`id` : String representing the ID of the system.
19+
`createdTimestamp`: ISO-8601 formatted timestamp string specifying the
20+
date when the system was registered.
21+
`lastUpdatedTimestamp`: ISO-8601 formatted timestamp string
22+
specifying the last date the system was updated.
23+
`alias`: String representing the alias of the system.
24+
`activation.lastUpdatedTimestamp`: ISO-8601 formatted timestamp string
25+
specifying the last date the system activation was updated.
26+
`activation.data.activated`: Boolean representing whether the system is
27+
activated or not.
28+
`activation.data.licenseName`: String representing the name of the license.
29+
`activation.data.licenseVersion`: String representing the license version.
30+
`connected.lastUpdatedTimestamp`: ISO-8601 formatted timestamp string
31+
specifying the last date the system connection was updated.
32+
`connected.data.state`: String representing the state of the system.
33+
`grains.lastUpdatedTimestamp`: ISO-8601 formatted timestamp string
34+
specifying the last date the system grains were updated.
35+
`grains.data`: Dictionary of string to object representing general
36+
information about the system. Example: grains.data.os == "Windows"
37+
`packages.lastUpdatedTimestamp`: ISO-8601 formatted timestamp string
38+
specifying the last date the system installed packages were updated.
39+
`packages.data`: Dictionary representing software packages installed on the
40+
system.
41+
Example: packages.data.ni-package-manager-upgrader.version: String
42+
representing the installed version of ni-package-manager-upgrader package.
43+
`feeds.lastUpdatedTimestamp`: ISO-8601 formatted timestamp string
44+
specifying the last date the system configured feeds were updated.
45+
`feeds.data`: Dictionary representing the feeds configured on the system.
46+
`keywords.lastUpdatedTimestamp`: ISO-8601 formatted timestamp string
47+
specifying the last date the system keywords were updated.
48+
`keywords.data`: Array of strings representing the keywords of the system.
49+
Example: keywords.data.Contains("test")
50+
`properties.lastUpdatedTimestamp`: ISO-8601 formatted timestamp string
51+
specifying the last date the system properties were updated.
52+
`properties.data`: Dictionary of string to string representing metadata
53+
information about a system. Example: properties.data.owner == "admin"
54+
`status.data.http_connected`: Boolean representing the status of the http
55+
connection to the master.
56+
57+
See [Dynamic Linq](https://github.com/ni/systemlink-OpenAPI-documents/wiki/Dynamic-Linq-Query-Language)
58+
documentation for more details.
59+
60+
`"@0"`, `"@1"` etc. can be used in conjunction with the `substitutions` parameter to keep this
61+
query string more simple and reusable."""
62+
63+
projection: Optional[str] = None
64+
"""Gets or sets specifies the projection for resources.
65+
Use this field to receive specific properties of the model."""
66+
67+
order_by: Optional[str] = None
68+
"""Gets or sets the order in which data returns."""
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from typing import Any, Dict, List, Optional
2+
3+
from nisystemlink.clients.core._uplink._json_model import JsonModel
4+
5+
6+
class QuerySystemsResponse(JsonModel):
7+
"""Model for query systems request."""
8+
9+
count: Optional[int] = None
10+
"""Number of systems match the query."""
11+
12+
data: Optional[List[Dict[str, Any]]] = None
13+
"""Contains info of the queried systems."""

0 commit comments

Comments
 (0)
0