first cosmoserver commit
This commit is contained in:
46
files/api/shrink.py
Normal file
46
files/api/shrink.py
Normal file
@ -0,0 +1,46 @@
|
||||
|
||||
def get_properties_keys(self, component = None):
|
||||
component_properties = []
|
||||
if component == None:
|
||||
component_properties = self._properties.items()
|
||||
else:
|
||||
component_properties = self.get_property(component)
|
||||
result = self.process_key_list(key_items = component_properties, key_name = "Property", return_type = "key" key_value = "Value")
|
||||
return result
|
||||
|
||||
def get_metrics_keys(self):
|
||||
result = self.process_key_list(key_items = self._metrics.items(), key_name = "Metric", key_value = "Data", return_type = "key")
|
||||
return result
|
||||
|
||||
def get_properties_strings(self, return_simple = True):
|
||||
result = self.process_key_list(key_items = self._properties.items(), key_name = "Property", return_type = "string", return_simple = return_simple)
|
||||
return result
|
||||
|
||||
def get_metrics_strings(self, return_simple = True):
|
||||
result = self.process_key_list(key_items = self._metrics.items(), key_name = "Metric", return_type = "string", return_simple = return_simple)
|
||||
return result
|
||||
|
||||
def process_key_list(self, key_items: str, key_name: str, return_type: str, key_value = "none"):
|
||||
result = []
|
||||
empty_value = ["", "null", None, []]
|
||||
for name, values in key_items:
|
||||
for value in (values if isinstance(values, list) else [values]):
|
||||
if value not in empty_value and name not in self.virt_ignore:
|
||||
this_key_string = f"{name}: {value}"
|
||||
if return_simple:
|
||||
result.append(this_key_string)
|
||||
elif return_keys:
|
||||
this_key_value = {
|
||||
"Source": self.name,
|
||||
key_name: name,
|
||||
key_value: value
|
||||
}
|
||||
result.append(this_key_value)
|
||||
else:
|
||||
complex_key_string = {
|
||||
"Source": self.name,
|
||||
key_name: this_key_string
|
||||
}
|
||||
result.append(complex_key_string)
|
||||
|
||||
return result
|
||||
Reference in New Issue
Block a user