-
Notifications
You must be signed in to change notification settings - Fork 194
Implementation for volume-counting #819
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
Changes from all commits
bd15a58
d12665a
4610481
5c41bda
a5638b4
7ef6acc
5b6e001
68d6c55
817eb85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"""List number of block storage volumes per datacenter.""" | ||
# :license: MIT, see LICENSE for more details. | ||
|
||
import click | ||
import SoftLayer | ||
from SoftLayer.CLI import columns as column_helper | ||
from SoftLayer.CLI import environment | ||
from SoftLayer.CLI import formatting | ||
|
||
COLUMNS = [ | ||
column_helper.Column('Datacenter', | ||
('serviceResource', 'datacenter', 'name'), | ||
mask="serviceResource.datacenter.name"), | ||
column_helper.Column('Count', | ||
'', | ||
mask=None) | ||
] | ||
|
||
DEFAULT_COLUMNS = [ | ||
'Datacenter', | ||
'Count' | ||
] | ||
|
||
|
||
@click.command() | ||
@click.option('--datacenter', '-d', help='Datacenter shortname') | ||
@click.option('--sortby', help='Column to sort by', default='Datacenter') | ||
@click.option('--columns', | ||
callback=column_helper.get_formatter(COLUMNS), | ||
help='Columns to display. Options: {0}'.format( | ||
', '.join(column.name for column in COLUMNS)), | ||
default=','.join(DEFAULT_COLUMNS)) | ||
@environment.pass_env | ||
def cli(env, sortby, columns, datacenter): | ||
"""List number of block storage volumes per datacenter.""" | ||
block_manager = SoftLayer.BlockStorageManager(env.client) | ||
block_volumes = block_manager.list_block_volumes(datacenter=datacenter, | ||
mask=columns.mask()) | ||
|
||
# cycle through all block volumes and count datacenter occurences. | ||
datacenters = dict() | ||
for volume in block_volumes: | ||
service_resource = volume['serviceResource'] | ||
if 'datacenter' in service_resource: | ||
datacenter = service_resource['datacenter']['name'] | ||
if datacenter not in datacenters.keys(): | ||
datacenters[datacenter] = 1 | ||
else: | ||
datacenters[datacenter] += 1 | ||
|
||
table = formatting.KeyValueTable(columns.columns) | ||
table.sortby = sortby | ||
for datacenter in datacenters: | ||
table.add_row([datacenter, datacenters[datacenter]]) | ||
env.fout(table) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"""List number of file storage volumes per datacenter.""" | ||
# :license: MIT, see LICENSE for more details. | ||
|
||
import click | ||
import SoftLayer | ||
from SoftLayer.CLI import columns as column_helper | ||
from SoftLayer.CLI import environment | ||
from SoftLayer.CLI import formatting | ||
|
||
COLUMNS = [ | ||
column_helper.Column('Datacenter', | ||
('serviceResource', 'datacenter', 'name'), | ||
mask="serviceResource.datacenter.name"), | ||
column_helper.Column('Count', | ||
'', | ||
mask=None) | ||
] | ||
|
||
DEFAULT_COLUMNS = [ | ||
'Datacenter', | ||
'Count' | ||
] | ||
|
||
|
||
@click.command() | ||
@click.option('--datacenter', '-d', help='Datacenter shortname') | ||
@click.option('--sortby', help='Column to sort by', default='Datacenter') | ||
@click.option('--columns', | ||
callback=column_helper.get_formatter(COLUMNS), | ||
help='Columns to display. Options: {0}'.format( | ||
', '.join(column.name for column in COLUMNS)), | ||
default=','.join(DEFAULT_COLUMNS)) | ||
@environment.pass_env | ||
def cli(env, sortby, columns, datacenter): | ||
"""List number of file storage volumes per datacenter.""" | ||
|
||
file_manager = SoftLayer.FileStorageManager(env.client) | ||
file_volumes = file_manager.list_file_volumes(datacenter=datacenter, | ||
mask=columns.mask()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of modifying the mask in the manager, just do something like this. fix the line width so tox doesn't complain about it too.
|
||
|
||
datacenters = dict() | ||
for volume in file_volumes: | ||
service_resource = volume['serviceResource'] | ||
if 'datacenter' in service_resource: | ||
datacenter = service_resource['datacenter']['name'] | ||
if datacenter not in datacenters.keys(): | ||
datacenters[datacenter] = 1 | ||
else: | ||
datacenters[datacenter] += 1 | ||
|
||
table = formatting.KeyValueTable(columns.columns) | ||
table.sortby = sortby | ||
for datacenter in datacenters: | ||
table.add_row([datacenter, datacenters[datacenter]]) | ||
env.fout(table) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,17 +41,33 @@ def list_block_volumes(self, datacenter=None, username=None, | |
'bytesUsed', | ||
'serviceResource.datacenter[name]', | ||
'serviceResourceBackendIpAddress', | ||
'activeTransactionCount' | ||
'activeTransactionCount', | ||
'replicationPartnerCount', | ||
',replicationPartners[id,username,' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "," at the start and end of the lines are not needed, as they are added by the join at the botton |
||
'serviceResourceBackendIpAddress,' | ||
'serviceResource[datacenter[name]],' | ||
'storageType,capacityGb,lunId,bytesUsed,' | ||
'activeTransactionCount,' | ||
'replicationSchedule[type[keyname]]]', | ||
] | ||
kwargs['mask'] = ','.join(items) | ||
|
||
# Retrieve relevant replicant information to be displayed. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These items are already in the mask above. Remove this section. |
||
kwargs['mask'] += ',replicationPartners[id,username,'\ | ||
'serviceResourceBackendIpAddress,'\ | ||
'serviceResource[datacenter[name]],'\ | ||
'storageType,capacityGb,lunId,bytesUsed,'\ | ||
'activeTransactionCount,'\ | ||
'replicationSchedule[type[keyname]]]' | ||
|
||
_filter = utils.NestedDict(kwargs.get('filter') or {}) | ||
|
||
_filter['iscsiNetworkStorage']['serviceResource']['type']['type'] = \ | ||
(utils.query_filter('!~ ISCSI')) | ||
|
||
_filter['iscsiNetworkStorage']['storageType']['keyName'] = ( | ||
utils.query_filter('*BLOCK_STORAGE*')) | ||
|
||
if storage_type: | ||
_filter['iscsiNetworkStorage']['storageType']['keyName'] = ( | ||
utils.query_filter('%s_BLOCK_STORAGE' % storage_type.upper())) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,10 +36,25 @@ def list_file_volumes(self, datacenter=None, username=None, | |
'serviceResource.datacenter[name]', | ||
'serviceResourceBackendIpAddress', | ||
'activeTransactionCount', | ||
'fileNetworkMountAddress' | ||
'fileNetworkMountAddress', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comments as the block section |
||
'replicationPartnerCount', | ||
',replicationPartners[id,username,' | ||
'serviceResourceBackendIpAddress,' | ||
'serviceResource[datacenter[name]],' | ||
'storageType,capacityGb,lunId,bytesUsed,' | ||
'activeTransactionCount,' | ||
'replicationSchedule[type[keyname]]]', | ||
] | ||
kwargs['mask'] = ','.join(items) | ||
|
||
# Retrieve relevant replicant information to be displayed. | ||
kwargs['mask'] += ',replicationPartners[id,username,'\ | ||
'serviceResourceBackendIpAddress,'\ | ||
'serviceResource[datacenter[name]],'\ | ||
'storageType,capacityGb,lunId,bytesUsed,'\ | ||
'activeTransactionCount,'\ | ||
'replicationSchedule[type[keyname]]]' | ||
|
||
_filter = utils.NestedDict(kwargs.get('filter') or {}) | ||
|
||
_filter['nasNetworkStorage']['serviceResource']['type']['type'] = \ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment as in the file volume-count CLI command