Skip to content
This repository was archived by the owner on Dec 8, 2025. It is now read-only.

Commit 821e7a4

Browse files
authored
Merge pull request #78 from IBM/SLAFix
SLA Changes
2 parents 5436d67 + 86a3e95 commit 821e7a4

File tree

6 files changed

+81
-48
lines changed

6 files changed

+81
-48
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ straightforward as possible.
1616

1717
### Fixed
1818

19+
## [1.0.1] - 2021-08-27
20+
21+
### Fixed
22+
23+
* Reverts SLA-Endpoint changes to stop counting removed VM's.
24+
* Pagesize code inside of the rest-request remains unchanged.
25+
26+
### Changed
27+
28+
* Changes SLA-Request count-field name and group name to a better matching candidate.
29+
* Removes the need to cut of prefix via regex
30+
* Removes associated regex code
31+
* Changes REST-Client query time measurement from using a timer to using the result-internal timer.
32+
1933
## [1.0.0] - 2021-08-26
2034

2135
### Major changes summary

python/influx/definitions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ def add_table_definitions(cls, database: Database):
486486
'vmCountBySLA': Datatype.INT
487487
},
488488
tags=[
489+
'slaId',
489490
'slaName'
490491
],
491492
retention_policy=cls._RP_DAYS_90(),

python/sppConnection/api_queries.py

Lines changed: 62 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
ApiQueries
55
"""
66
import logging
7-
from typing import List, Dict, Any
7+
from typing import List, Dict, Any, Optional
88
import json
9+
import urllib.parse
910

11+
from utils.execption_utils import ExceptionUtils
12+
from utils.spp_utils import SppUtils
1013
from sppConnection.rest_client import RequestType, RestClient
1114

1215

@@ -108,33 +111,67 @@ def get_all_vms(self) -> List[Dict[str, Any]]:
108111

109112
def get_vms_per_sla(self) -> List[Dict[str, Any]]:
110113
"""retrieves and calculates all vmware per SLA."""
111-
endpoint = "/api/endeavour/catalog/recovery/hypervisorvm"
112-
params = {
113-
"action": "aggregate",
114-
"pageSize": None
115-
}
116-
# other options: volume, vm, tag, tagcategory
117-
post_data = {
118-
"op":[
119-
{
120-
"operation": "count",
121-
"fieldname": "protectionInfo.policyName",
122-
"outputname": "vmCountBySLA" # buggy request, does actually not change anything
123-
}
124-
],
125-
"group": [
126-
"protectionInfo.policyName"
127-
]
128-
}
129114

130-
return self.__rest_client.get_objects(
115+
endpoint = "/ngp/slapolicy"
116+
allow_list = ["name", "id"]
117+
array_name = "slapolicies"
118+
119+
sla_policty_list = self.__rest_client.get_objects(
131120
endpoint=endpoint,
132-
params=params,
133-
request_type=RequestType.POST,
134-
post_data=post_data,
135-
add_time_stamp=True,
136-
array_name="results")
121+
allow_list=allow_list,
122+
array_name=array_name,
123+
add_time_stamp=False
124+
)
125+
126+
result_list: List[Dict[str, Any]] = []
127+
for sla_policty in sla_policty_list:
128+
try:
129+
sla_name: str = sla_policty["name"]
130+
except KeyError as error:
131+
ExceptionUtils.exception_info(error, extra_message="skipping one sla entry due missing name.")
132+
continue
133+
sla_id: Optional[str] = sla_policty.get("id", None)
134+
135+
result_dict: Dict[str, Any] = {}
136+
137+
## hotadd:
138+
sla_name = urllib.parse.quote_plus(sla_name)
139+
140+
endpoint = "/api/hypervisor/search"
141+
params = {
142+
"resourceType": "vm",
143+
"from": "hlo",
144+
"pageSize": 1,
145+
"filter": json.dumps([
146+
{
147+
"property": "storageProfileName",
148+
"value": sla_name,
149+
"op": "="
150+
}
151+
])
152+
}
153+
# other options: volume, vm, tag, tagcategory
154+
post_data = {
155+
"name": "*",
156+
"hypervisorType": "vmware",
157+
}
158+
159+
(response_json, _) = self.__rest_client.query_url(
160+
self.__rest_client.get_url(endpoint),
161+
params,
162+
RequestType.POST,
163+
post_data)
164+
165+
result_dict["slaName"] = sla_name
166+
result_dict["slaId"] = sla_id
167+
result_dict["vmCountBySLA"] = response_json.get("total", None)
168+
169+
time_key, time = SppUtils.get_capture_timestamp_sec()
170+
result_dict[time_key] = time
171+
172+
result_list.append(result_dict)
137173

174+
return result_list
138175

139176
def get_sla_dump(self) -> List[Dict[str, Any]]:
140177
"""retrieves all storage profiles."""

python/sppConnection/rest_client.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,6 @@ def query_url(
357357

358358
# send the query
359359
try:
360-
start_time = time.perf_counter()
361360
if(request_type == RequestType.GET):
362361
response_query = get(
363362
url=url, headers=self.__headers, verify=False,
@@ -368,8 +367,7 @@ def query_url(
368367
url=url, headers=self.__headers, verify=False,
369368
params=params, json=post_data, auth=auth,
370369
timeout=(self.__initial_connection_timeout, self.__timeout))
371-
end_time = time.perf_counter()
372-
send_time = (end_time - start_time)
370+
send_time = response_query.elapsed.total_seconds()
373371

374372
except ReadTimeout as timeout_error:
375373

python/sppmon.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
08/22/2021 version 0.15 Added --fullLogs argument and reduced regular/loaded joblog query to SUMMARY-Only
6666
08/25/2021 version 0.15.1 Replaced SLA-Endpoint by so-far unknown endpoint, bringing it in line with other api-requests.
6767
08/27/2021 version 1.0.0 Release of SPPMon
68+
08/27/2021 version 1.0.1 Reverted parts of the SLA-Endpoint change
6869
"""
6970
from __future__ import annotations
7071

@@ -93,7 +94,7 @@
9394
from utils.spp_utils import SppUtils
9495

9596
# Version:
96-
VERSION = "1.0.0 (2021/08/27)"
97+
VERSION = "1.0.1 (2021/08/27)"
9798

9899

99100
# ----------------------------------------------------------------------------

python/sppmonMethods/protection.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"""
77
import logging
88

9-
from re import compile, sub
109
from typing import List, Dict, Any, Union, Optional
1110

1211
from influx.influx_client import InfluxClient
@@ -55,25 +54,8 @@ def vms_per_sla(self) -> None:
5554
LOGGER.info("> calculating number of VMs per SLA")
5655
result = MethodUtils.query_something(
5756
name="VMs per SLA",
58-
source_func=self.__api_queries.get_vms_per_sla,
59-
rename_tuples=[
60-
("_id.protectionInfo.policyName", "slaName"),
61-
("count", "vmCountBySLA") # buggy request
62-
],
63-
deactivate_verbose=True
57+
source_func=self.__api_queries.get_vms_per_sla
6458
)
65-
66-
# the endpoint offers a prefix `vmware_`
67-
# due to compability reasons the prefix is removed
68-
# may be reintroduced if other types occur.
69-
pattern = compile(r"^vmware_")
70-
for sla in result:
71-
# replaces the first occurence
72-
sla['slaName'] = sub(pattern, "", sla['slaName'], 1)
73-
74-
if(self.__verbose):
75-
MethodUtils.my_print(result)
76-
7759
LOGGER.info(">> inserting number of VMs per SLA into DB")
7860
self.__influx_client.insert_dicts_to_buffer(
7961
table_name="slaStats", list_with_dicts=result)

0 commit comments

Comments
 (0)