Skip to content

Commit 2ce632b

Browse files
Merge pull request #1593 from caberos/issue1591
New Command slcli hardware|virtual monitoring
2 parents 7a90f9d + 6fdb936 commit 2ce632b

File tree

11 files changed

+152
-6
lines changed

11 files changed

+152
-6
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""Get monitoring for a hardware device."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
6+
import SoftLayer
7+
from SoftLayer.CLI import environment
8+
from SoftLayer.CLI import formatting
9+
10+
11+
@click.command()
12+
@click.argument('identifier')
13+
@environment.pass_env
14+
def cli(env, identifier):
15+
"""Get details for a hardware monitors device."""
16+
17+
hardware = SoftLayer.HardwareManager(env.client)
18+
19+
table = formatting.KeyValueTable(['name', 'value'])
20+
table.align['name'] = 'r'
21+
table.align['value'] = 'l'
22+
23+
monitoring = hardware.get_hardware(identifier)
24+
25+
table.add_row(['Domain', monitoring.get('fullyQualifiedDomainName')])
26+
table.add_row(['Public Ip', monitoring.get('primaryIpAddress')])
27+
table.add_row(['Private Ip', monitoring.get('primaryBackendIpAddress')])
28+
table.add_row(['Location', monitoring['datacenter']['longName']])
29+
30+
monitoring_table = formatting.Table(['Id', 'IpAddress', 'Status', 'Type', 'Notify'])
31+
for monitor in monitoring['networkMonitors']:
32+
monitoring_table.add_row([monitor.get('id'), monitor.get('ipAddress'), monitor.get('status'),
33+
monitor['queryType']['name'], monitor['responseAction']['actionDescription']])
34+
35+
table.add_row(['Devices monitors', monitoring_table])
36+
37+
env.fout(table)

SoftLayer/CLI/routes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
('virtual:capacity', 'SoftLayer.CLI.virt.capacity:cli'),
5353
('virtual:placementgroup', 'SoftLayer.CLI.virt.placementgroup:cli'),
5454
('virtual:migrate', 'SoftLayer.CLI.virt.migrate:cli'),
55+
('virtual:monitoring', 'SoftLayer.CLI.virt.monitoring:cli'),
5556

5657
('dedicatedhost', 'SoftLayer.CLI.dedicatedhost'),
5758
('dedicatedhost:list', 'SoftLayer.CLI.dedicatedhost.list:cli'),
@@ -280,6 +281,7 @@
280281
('hardware:storage', 'SoftLayer.CLI.hardware.storage:cli'),
281282
('hardware:upgrade', 'SoftLayer.CLI.hardware.upgrade:cli'),
282283
('hardware:sensor', 'SoftLayer.CLI.hardware.sensor:cli'),
284+
('hardware:monitoring', 'SoftLayer.CLI.hardware.monitoring:cli'),
283285

284286
('securitygroup', 'SoftLayer.CLI.securitygroup'),
285287
('securitygroup:list', 'SoftLayer.CLI.securitygroup.list:cli'),

SoftLayer/CLI/virt/monitoring.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""Get monitoring for a VSI device."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
6+
import SoftLayer
7+
from SoftLayer.CLI import environment
8+
from SoftLayer.CLI import formatting
9+
10+
11+
@click.command()
12+
@click.argument('identifier')
13+
@environment.pass_env
14+
def cli(env, identifier):
15+
"""Get details for a vsi monitors device."""
16+
17+
vsi = SoftLayer.VSManager(env.client)
18+
19+
table = formatting.KeyValueTable(['name', 'value'])
20+
table.align['name'] = 'r'
21+
table.align['value'] = 'l'
22+
23+
monitoring = vsi.get_instance(identifier)
24+
25+
table.add_row(['Domain', monitoring.get('fullyQualifiedDomainName')])
26+
table.add_row(['Public Ip', monitoring.get('primaryIpAddress')])
27+
table.add_row(['Private Ip', monitoring.get('primaryBackendIpAddress')])
28+
table.add_row(['Location', monitoring['datacenter']['longName']])
29+
30+
monitoring_table = formatting.Table(['Id', 'IpAddress', 'Status', 'Type', 'Notify'])
31+
for monitor in monitoring['networkMonitors']:
32+
monitoring_table.add_row([monitor.get('id'), monitor.get('ipAddress'), monitor.get('status'),
33+
monitor['queryType']['name'], monitor['responseAction']['actionDescription']])
34+
35+
table.add_row(['Devices monitors', monitoring_table])
36+
37+
env.fout(table)

SoftLayer/fixtures/SoftLayer_Hardware_Server.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
getObject = {
22
'id': 1000,
33
'globalIdentifier': '1a2b3c-1701',
4-
'datacenter': {'id': 50, 'name': 'TEST00',
4+
'datacenter': {'id': 50, 'name': 'TEST00', 'longName': 'test 00',
55
'description': 'Test Data Center'},
66
'billingItem': {
77
'id': 6327,
@@ -74,7 +74,35 @@
7474
'friendlyName': 'Friendly Transaction Name',
7575
'id': 6660
7676
}
77-
}
77+
},
78+
'networkMonitors': [
79+
{
80+
'hardwareId': 3123796,
81+
'hostId': 3123796,
82+
'id': 19016454,
83+
'ipAddress': '169.53.167.199',
84+
'queryTypeId': 1,
85+
'responseActionId': 2,
86+
'status': 'ON',
87+
'waitCycles': 0,
88+
'lastResult': {
89+
'finishTime': '2022-03-10T08:31:40-06:00',
90+
'responseStatus': 2,
91+
'responseTime': 159.15,
92+
},
93+
'queryType': {
94+
'description': 'Test ping to address',
95+
'id': 1,
96+
'monitorLevel': 0,
97+
'name': 'SERVICE PING'
98+
},
99+
'responseAction': {
100+
'actionDescription': 'Notify Users',
101+
'id': 2,
102+
'level': 0
103+
}
104+
}
105+
]
78106
}
79107
editObject = True
80108
setTags = True

SoftLayer/fixtures/SoftLayer_Virtual_Guest.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
'preset': {'keyName': 'B1_8X16X100'}
4848
}
4949
},
50-
'datacenter': {'id': 50, 'name': 'TEST00',
50+
'datacenter': {'id': 50, 'name': 'TEST00', 'longName': 'test 00',
5151
'description': 'Test Data Center'},
5252
'powerState': {'keyName': 'RUNNING', 'name': 'Running'},
5353
'maxCpu': 2,
@@ -83,6 +83,29 @@
8383
'softwareDescription': {'name': 'Ubuntu'}}
8484
}],
8585
'tagReferences': [{'tag': {'name': 'production'}}],
86+
'networkMonitors': [
87+
{
88+
'guestId': 116114480,
89+
'hostId': 116114480,
90+
'id': 17653845,
91+
'ipAddress': '52.116.23.73',
92+
'queryTypeId': 1,
93+
'responseActionId': 1,
94+
'status': 'ON',
95+
'waitCycles': 0,
96+
'queryType': {
97+
'description': 'Test ping to address',
98+
'id': 1,
99+
'monitorLevel': 0,
100+
'name': 'SERVICE PING'
101+
},
102+
'responseAction': {
103+
'actionDescription': 'Do Nothing',
104+
'id': 1,
105+
'level': 0
106+
}
107+
}
108+
]
86109
}
87110
getCreateObjectOptions = {
88111
'flavors': [
@@ -894,6 +917,6 @@
894917
allowAccessToNetworkStorageList = True
895918

896919
attachDiskImage = {
897-
"createDate": "2021-03-22T13:15:31-06:00",
898-
"id": 1234567
899-
}
920+
"createDate": "2021-03-22T13:15:31-06:00",
921+
"id": 1234567
922+
}

SoftLayer/managers/hardware.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ def get_hardware(self, hardware_id, **kwargs):
231231
'domain,'
232232
'provisionDate,'
233233
'hardwareStatus,'
234+
'bareMetalInstanceFlag,'
234235
'processorPhysicalCoreAmount,'
235236
'memoryCapacity,'
236237
'notes,'
@@ -269,6 +270,7 @@ def get_hardware(self, hardware_id, **kwargs):
269270
'hourlyBillingFlag,'
270271
'tagReferences[id,tag[name,id]],'
271272
'networkVlans[id,vlanNumber,networkSpace],'
273+
'monitoringServiceComponent,networkMonitors[queryType,lastResult,responseAction],'
272274
'remoteManagementAccounts[username,password]'
273275
)
274276

SoftLayer/managers/vs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ def get_instance(self, instance_id, **kwargs):
252252
'tagReferences[id,tag[name,id]],'
253253
'networkVlans[id,vlanNumber,networkSpace],'
254254
'dedicatedHost.id,'
255+
'monitoringServiceComponent,networkMonitors[queryType,lastResult,responseAction],'
255256
'placementGroupId'
256257
)
257258

docs/cli/hardware.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ Interacting with Hardware
2424
:prog: hardware create
2525
:show-nested:
2626

27+
.. click:: SoftLayer.CLI.hardware.monitoring:cli
28+
:prog: hardware monitoring
29+
:show-nested:
30+
2731

2832
Provides some basic functionality to order a server. `slcli order` has a more full featured method of ordering servers. This command only supports the FAST_PROVISION type.
2933

docs/cli/vs.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ If no timezone is specified, IMS local time (CST) will be assumed, which might n
271271
:prog: virtual authorize-storage
272272
:show-nested:
273273

274+
.. click:: SoftLayer.CLI.virt.monitoring:cli
275+
:prog: virtual monitoring
276+
:show-nested:
277+
274278
Manages the migration of virutal guests. Supports migrating virtual guests on Dedicated Hosts as well.
275279

276280
Reserved Capacity

tests/CLI/modules/server_tests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,3 +1010,7 @@ def test_sensor(self):
10101010
def test_sensor_discrete(self):
10111011
result = self.run_command(['hardware', 'sensor', '100', '--discrete'])
10121012
self.assert_no_fail(result)
1013+
1014+
def test_monitoring(self):
1015+
result = self.run_command(['hardware', 'monitoring', '100'])
1016+
self.assert_no_fail(result)

0 commit comments

Comments
 (0)