Skip to content

Commit 1a790d1

Browse files
caberoscaberos
caberos
authored and
caberos
committed
update
2 parents 8277090 + 54ddf9c commit 1a790d1

14 files changed

+164
-9
lines changed

SoftLayer/CLI/account/bandwidth_pools_detail.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ def cli(env, identifier):
3737
inbound = '-'
3838
table.add_row(['Inbound Usage', inbound])
3939
if bandwidths['hardware'] != []:
40-
table.add_row(['hardware', _bw_table(bandwidths['hardware'])])
40+
table.add_row(['hardware', *(_bw_table(bandwidths['hardware']))])
4141
else:
4242
table.add_row(['hardware', 'Not Found'])
4343

4444
if bandwidths['virtualGuests'] != []:
45-
table.add_row(['virtualGuests', _virtual_table(bandwidths['virtualGuests'])])
45+
table.add_row(['virtualGuests', *(_virtual_table(bandwidths['virtualGuests']))])
4646
else:
4747
table.add_row(['virtualGuests', 'Not Found'])
4848

4949
if bandwidths['bareMetalInstances'] != []:
50-
table.add_row(['Netscaler', _bw_table(bandwidths['bareMetalInstances'])])
50+
table.add_row(['Netscaler', *(_bw_table(bandwidths['bareMetalInstances']))])
5151
else:
5252
table.add_row(['Netscaler', 'Not Found'])
5353

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""Display details for a specified cloud object storage."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
import SoftLayer
6+
from SoftLayer.CLI import environment
7+
from SoftLayer.CLI import formatting
8+
9+
10+
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
11+
@click.argument('object_id')
12+
@environment.pass_env
13+
def cli(env, object_id):
14+
"""Display details for a cloud object storage."""
15+
16+
block_manager = SoftLayer.BlockStorageManager(env.client)
17+
18+
cloud = block_manager.get_volume_details(object_id)
19+
bucket = block_manager.get_buckets(object_id)
20+
21+
table = formatting.KeyValueTable(['Name', 'Value'])
22+
table.align['Name'] = 'r'
23+
table.align['Value'] = 'l'
24+
25+
table.add_row(['Id', cloud.get('id')])
26+
table.add_row(['Username', cloud.get('username')])
27+
table.add_row(['Name Service Resource', cloud['serviceResource']['name']])
28+
table.add_row(['Type Service Resource', cloud['serviceResource']['type']['type']])
29+
table.add_row(['Datacenter', cloud['serviceResource']['datacenter']['name']])
30+
table.add_row(['Storage type', cloud['storageType']['keyName']])
31+
table.add_row(['Bytes Used', formatting.b_to_gb(bucket[0]['bytesUsed'])])
32+
table.add_row(['Bucket name', bucket[0]['name']])
33+
34+
env.fout(table)

SoftLayer/CLI/firewall/monitoring.py

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""Get monitoring for a firewall device."""
2+
# :license: MIT, see LICENSE for more details.
3+
import datetime
4+
5+
import click
6+
7+
import SoftLayer
8+
from SoftLayer.CLI import environment
9+
from SoftLayer.CLI import formatting
10+
11+
12+
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
13+
@click.argument('identifier')
14+
@environment.pass_env
15+
def cli(env, identifier):
16+
"""Gets bandwidth details for a firewall from the past 30 days."""
17+
18+
mgr = SoftLayer.FirewallManager(env.client)
19+
20+
_firewall = mgr.get_instance(identifier)
21+
22+
table = formatting.KeyValueTable(['name', 'value'])
23+
table.align['name'] = 'r'
24+
table.align['value'] = 'l'
25+
26+
end = datetime.date.today()
27+
start = end.replace(day=1)
28+
last_month = start - datetime.timedelta(days=30)
29+
30+
monitoring = mgr.get_summary(_firewall['metricTrackingObject']['id'],
31+
last_month.strftime('%Y-%m-%d'), end.strftime('%Y-%m-%d'))
32+
public_out = 0
33+
public_in = 0
34+
for monitor in monitoring:
35+
36+
if monitor['type'] == 'publicOut_net_octet':
37+
public_out += monitor['counter']
38+
39+
if monitor['type'] == 'publicIn_net_octet':
40+
public_in += monitor['counter']
41+
42+
table.add_row(['Id', _firewall.get('id')])
43+
table.add_row(['Name', _firewall['networkGateway']['name']])
44+
table.add_row(['Stard Date', last_month.strftime('%Y-%m-%d')])
45+
table.add_row(['End Date', end.strftime('%Y-%m-%d')])
46+
table.add_row(['Out', formatting.b_to_gb(public_out)])
47+
table.add_row(['In', formatting.b_to_gb(public_in)])
48+
table.add_row(['Total', formatting.b_to_gb(public_out + public_in)])
49+
table.add_row(['Status', _firewall['networkGateway']['status']['name']])
50+
51+
env.fout(table)

SoftLayer/CLI/routes.py

+2
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
('block:volume-convert', 'SoftLayer.CLI.block.convert:cli'),
128128
('block:volume-set-note', 'SoftLayer.CLI.block.set_note:cli'),
129129
('block:object-list', 'SoftLayer.CLI.block.object_list:cli'),
130+
('block:object-storage-detail', 'SoftLayer.CLI.block.object_storage_detail:cli'),
130131

131132
('email', 'SoftLayer.CLI.email'),
132133
('email:list', 'SoftLayer.CLI.email.list:cli'),
@@ -180,6 +181,7 @@
180181
('firewall:detail', 'SoftLayer.CLI.firewall.detail:cli'),
181182
('firewall:edit', 'SoftLayer.CLI.firewall.edit:cli'),
182183
('firewall:list', 'SoftLayer.CLI.firewall.list:cli'),
184+
('firewall:monitoring', 'SoftLayer.CLI.firewall.monitoring:cli'),
183185

184186
('globalip', 'SoftLayer.CLI.globalip'),
185187
('globalip:assign', 'SoftLayer.CLI.globalip.assign:cli'),

SoftLayer/fixtures/SoftLayer_Network_Storage.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,11 @@
149149
}
150150
],
151151
'serviceProviderId': 1,
152-
'serviceResource': {'datacenter': {'id': 449500, 'name': 'dal05'}},
152+
'serviceResource': {'datacenter': {'id': 449500, 'name': 'dal05'},
153+
'name': 'Cleversafe - US Region',
154+
'type': {
155+
'type': 'CLEVERSAFE_SVC_API'
156+
}},
153157
'serviceResourceBackendIpAddress': '10.1.2.3',
154158
'serviceResourceName': 'Storage Type 01 Aggregate staaspar0101_pc01',
155159
'snapshotCapacityGb': '10',

SoftLayer/fixtures/SoftLayer_Network_Vlan_Firewall.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@
174174
"modifyDate": "2022-05-17T14:00:42-06:00",
175175
"primarySubnetId": 2623338,
176176
"vlanNumber": 1255
177+
},
178+
"status": {
179+
"description": "Gateway is ready to accept commands and actions",
180+
"id": 1,
181+
"keyName": "ACTIVE",
182+
"name": "Active"
177183
}
178184
},
179185
"rules": [
@@ -212,7 +218,16 @@
212218
'action': 'permit',
213219
'sourceIpAddress': '0.0.0.0'
214220
}
215-
]
221+
],
222+
"metricTrackingObject": {
223+
"id": 147258369,
224+
"resourceTableId": 17438,
225+
"startDate": "2022-05-17T14:01:48-06:00",
226+
"type": {
227+
"keyname": "FIREWALL_CONTEXT",
228+
"name": "Firewall Module Context"
229+
}
230+
}
216231

217232
}
218233

SoftLayer/managers/block.py

+10
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,13 @@ def get_cloud_list(self):
207207
mask = 'mask[id,username,billingItem,storageType, notes]'
208208

209209
return self.client.call('Account', 'getHubNetworkStorage', mask=mask)
210+
211+
def get_buckets(self, object_id):
212+
"""Return buckets data of the cloud storage.
213+
214+
:param object_id cloud object storage identifier
215+
216+
Returns: Get buckets
217+
218+
"""
219+
return self.client.call('SoftLayer_Network_Storage_Hub_Cleversafe_Account', 'getBuckets', id=object_id)

SoftLayer/managers/firewall.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,9 @@ def get_instance(self, firewall_id, mask=None):
297297
:param integer firewall_id: the instance ID of the standard firewall
298298
"""
299299
if not mask:
300-
mask = 'mask[firewallType,networkGateway[insideVlans,members,privateIpAddress,publicIpAddress,' \
301-
'publicIpv6Address,privateVlan,publicVlan],datacenter,managementCredentials,networkVlan]'
300+
mask = 'mask[firewallType,datacenter,managementCredentials,networkVlan,' \
301+
'metricTrackingObject[data,type],networkGateway[insideVlans,members,privateIpAddress,' \
302+
'publicIpAddress,publicIpv6Address,privateVlan,publicVlan,status]]'
302303

303304
svc = self.client['Network_Vlan_Firewall']
304305

@@ -319,3 +320,20 @@ def get_firewalls_gatewalls(self):
319320
_filter = {"networkGateways": {"networkFirewall": {"operation": "not null"}}}
320321

321322
return self.account.getNetworkGateways(mask=mask, filter=_filter)
323+
324+
def get_summary(self, identifier, start_date, end_date):
325+
"""Returns the metric data for the date range provided
326+
327+
:param integer metric_tracking_id
328+
"""
329+
body = [{
330+
"keyName": "PUBLICIN",
331+
"summaryType": "sum"
332+
333+
}, {
334+
"keyName": "PUBLICOUT",
335+
"summaryType": "sum"
336+
}]
337+
338+
return self.client['Metric_Tracking_Object'].getSummaryData(start_date,
339+
end_date, body, 86400, id=identifier)

docs/cli/block.rst

+4
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ Block Commands
160160
:prog: block object-list
161161
:show-nested:
162162

163+
.. click:: SoftLayer.CLI.block.object_storage_detail:cli
164+
:prog: block object-storage-detail
165+
:show-nested:
166+
163167
.. click:: SoftLayer.CLI.block.duplicate_convert_status:cli
164168
:prog: block duplicate-convert-status
165169
:show-nested:

docs/cli/firewall.rst

+4
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ Firewall Management
2222
.. click:: SoftLayer.CLI.firewall.list:cli
2323
:prog: firewall list
2424
:show-nested:
25+
26+
.. click:: SoftLayer.CLI.firewall.monitoring:cli
27+
:prog: firewall monitoring
28+
:show-nested:

tests/CLI/modules/block_tests.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ def test_snapshot_restore(self):
444444

445445
self.assert_no_fail(result)
446446
self.assertEqual(result.output, 'Block volume 12345678 is being'
447-
' restored using snapshot 87654321\n')
447+
' restored using snapshot 87654321\n')
448448

449449
@mock.patch('SoftLayer.BlockStorageManager.order_snapshot_space')
450450
def test_snapshot_order_order_not_placed(self, order_mock):
@@ -825,3 +825,9 @@ def test_object_list(self):
825825

826826
self.assert_no_fail(result)
827827
self.assert_called_with('SoftLayer_Account', 'getHubNetworkStorage')
828+
829+
def test_object_details(self):
830+
result = self.run_command(['block', 'object-storage-detail', '1234'])
831+
832+
self.assert_no_fail(result)
833+
self.assert_called_with('SoftLayer_Network_Storage_Hub_Cleversafe_Account', 'getBuckets')

tests/CLI/modules/firewall_tests.py

+4
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,7 @@ def test_edit(self, confirm_mock):
154154
confirm_mock.return_value = True
155155
result = self.run_command(['firewall', 'edit', 'vlan:1234'])
156156
print(result.output)
157+
158+
def test_monitoring(self):
159+
result = self.run_command(['firewall', 'monitoring', '123456'])
160+
print(result.output)

tests/managers/block_tests.py

+4
Original file line numberDiff line numberDiff line change
@@ -1119,3 +1119,7 @@ def test_convert_block_depdupe(self):
11191119
def test_get_cloud_list(self):
11201120
self.block.get_cloud_list()
11211121
self.assert_called_with('SoftLayer_Account', 'getHubNetworkStorage')
1122+
1123+
def test_get_bucket(self):
1124+
self.block.get_buckets(1234)
1125+
self.assert_called_with('SoftLayer_Network_Storage_Hub_Cleversafe_Account', 'getBuckets')

tests/managers/firewall_tests.py

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ def test_get_standard_fwl_rules(self):
4646
identifier=1234)
4747

4848
def test_get_dedicated_fwl_rules(self):
49-
5049
rules = self.firewall.get_dedicated_fwl_rules(1234)
5150

5251
self.assertEqual(rules,

0 commit comments

Comments
 (0)