-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(storagelist): Add storages list group shared by storage name
- Loading branch information
1 parent
32224a9
commit aa02b00
Showing
4 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from pvecontrol.utils import filter_keys, print_tableoutput | ||
|
||
|
||
def action_storagelist(proxmox, args): | ||
"""Describe cluster storages""" | ||
keys_to_order = ['storage', 'nodes', 'shared', 'usage', 'maxdisk', 'disk', 'plugintype', 'status'] | ||
storages = {} | ||
for storage in proxmox.storages: | ||
d = storage.__dict__ | ||
node = d.pop('node') | ||
value = { | ||
**d, | ||
'nodes': [], | ||
'usage': f"{storage.percentage:.1f}%" | ||
} | ||
if storage.shared: | ||
storages[storage.storage] = storages.get(storage.storage, value) | ||
storages[storage.storage]['nodes'] += [node] | ||
else: | ||
storages[storage.id] = value | ||
storages[storage.id]['nodes'] += [node] | ||
|
||
for id, storage in storages.items(): | ||
storages[id]['nodes'] = ', '.join(storages[id]['nodes']) | ||
|
||
output = [ filter_keys(n, keys_to_order) for n in storages.values()] | ||
print_tableoutput(output, sortby='storage') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
class PVEStorage: | ||
"""Proxmox VE Storage""" | ||
|
||
_acceptable_kwargs = ( | ||
'storage', 'shared', 'maxdisk', 'disk', 'plugintype', 'status' | ||
) | ||
|
||
def __init__(self, node, id, **kwargs): | ||
self.id = id | ||
self.node = node | ||
|
||
for k in kwargs.keys(): | ||
if k in self._acceptable_kwargs: | ||
self.__setattr__(k, kwargs[k]) | ||
|
||
@property | ||
def percentage(self): | ||
if self.maxdisk: | ||
return self.disk / self.maxdisk *100 | ||
return 0 | ||
|
||
def __str__(self): | ||
output = f"Node: {self.node}\n" + f"Id: {self.id}\n" | ||
for key in self._acceptable_kwargs: | ||
output += f"{key.capitalize()}: {self.__getattribute__(key)}\n" | ||
return output |