Skip to content
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

New Command slcli hardware|virtual monitoring #1593

Merged
merged 4 commits into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions SoftLayer/CLI/hardware/monitoring.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""Get monitoring for a hardware device."""
# :license: MIT, see LICENSE for more details.

import click

import SoftLayer
from SoftLayer.CLI import environment
from SoftLayer.CLI import formatting


@click.command()
@click.argument('identifier')
@environment.pass_env
def cli(env, identifier):
"""Get details for a hardware monitors device."""

hardware = SoftLayer.HardwareManager(env.client)

table = formatting.KeyValueTable(['name', 'value'])
table.align['name'] = 'r'
table.align['value'] = 'l'

monitoring = hardware.get_hardware(identifier)

table.add_row(['domain', monitoring.get('fullyQualifiedDomainName')])
table.add_row(['public Ip', monitoring.get('primaryIpAddress')])
table.add_row(['private Ip', monitoring.get('primaryBackendIpAddress')])
table.add_row(['location', monitoring['datacenter']['longName']])

monitoring_table = formatting.Table(['Id', 'ipAddress', 'status', 'type', 'notify'])
caberos marked this conversation as resolved.
Show resolved Hide resolved
for monitor in monitoring['networkMonitors']:
monitoring_table.add_row([monitor.get('id'), monitor.get('ipAddress'), monitor.get('status'),
monitor['queryType']['name'], monitor['responseAction']['actionDescription']])

table.add_row(['Devices monitors', monitoring_table])

env.fout(table)
2 changes: 2 additions & 0 deletions SoftLayer/CLI/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
('virtual:capacity', 'SoftLayer.CLI.virt.capacity:cli'),
('virtual:placementgroup', 'SoftLayer.CLI.virt.placementgroup:cli'),
('virtual:migrate', 'SoftLayer.CLI.virt.migrate:cli'),
('virtual:monitoring', 'SoftLayer.CLI.virt.monitoring:cli'),

('dedicatedhost', 'SoftLayer.CLI.dedicatedhost'),
('dedicatedhost:list', 'SoftLayer.CLI.dedicatedhost.list:cli'),
Expand Down Expand Up @@ -280,6 +281,7 @@
('hardware:storage', 'SoftLayer.CLI.hardware.storage:cli'),
('hardware:upgrade', 'SoftLayer.CLI.hardware.upgrade:cli'),
('hardware:sensor', 'SoftLayer.CLI.hardware.sensor:cli'),
('hardware:monitoring', 'SoftLayer.CLI.hardware.monitoring:cli'),

('securitygroup', 'SoftLayer.CLI.securitygroup'),
('securitygroup:list', 'SoftLayer.CLI.securitygroup.list:cli'),
Expand Down
37 changes: 37 additions & 0 deletions SoftLayer/CLI/virt/monitoring.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""Get monitoring for a vSI device."""
caberos marked this conversation as resolved.
Show resolved Hide resolved
# :license: MIT, see LICENSE for more details.

import click

import SoftLayer
from SoftLayer.CLI import environment
from SoftLayer.CLI import formatting


@click.command()
@click.argument('identifier')
@environment.pass_env
def cli(env, identifier):
"""Get details for a vsi monitors device."""

vsi = SoftLayer.VSManager(env.client)

table = formatting.KeyValueTable(['name', 'value'])
table.align['name'] = 'r'
table.align['value'] = 'l'

monitoring = vsi.get_instance(identifier)

table.add_row(['domain', monitoring.get('fullyQualifiedDomainName')])
table.add_row(['public Ip', monitoring.get('primaryIpAddress')])
table.add_row(['private Ip', monitoring.get('primaryBackendIpAddress')])
table.add_row(['location', monitoring['datacenter']['longName']])

monitoring_table = formatting.Table(['Id', 'ipAddress', 'status', 'type', 'notify'])
caberos marked this conversation as resolved.
Show resolved Hide resolved
for monitor in monitoring['networkMonitors']:
monitoring_table.add_row([monitor.get('id'), monitor.get('ipAddress'), monitor.get('status'),
monitor['queryType']['name'], monitor['responseAction']['actionDescription']])

table.add_row(['Devices monitors', monitoring_table])

env.fout(table)
32 changes: 30 additions & 2 deletions SoftLayer/fixtures/SoftLayer_Hardware_Server.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
getObject = {
'id': 1000,
'globalIdentifier': '1a2b3c-1701',
'datacenter': {'id': 50, 'name': 'TEST00',
'datacenter': {'id': 50, 'name': 'TEST00', 'longName': 'test 00',
'description': 'Test Data Center'},
'billingItem': {
'id': 6327,
Expand Down Expand Up @@ -74,7 +74,35 @@
'friendlyName': 'Friendly Transaction Name',
'id': 6660
}
}
},
'networkMonitors': [
{
'hardwareId': 3123796,
'hostId': 3123796,
'id': 19016454,
'ipAddress': '169.53.167.199',
'queryTypeId': 1,
'responseActionId': 2,
'status': 'ON',
'waitCycles': 0,
'lastResult': {
'finishTime': '2022-03-10T08:31:40-06:00',
'responseStatus': 2,
'responseTime': 159.15,
},
'queryType': {
'description': 'Test ping to address',
'id': 1,
'monitorLevel': 0,
'name': 'SERVICE PING'
},
'responseAction': {
'actionDescription': 'Notify Users',
'id': 2,
'level': 0
}
}
]
}
editObject = True
setTags = True
Expand Down
31 changes: 27 additions & 4 deletions SoftLayer/fixtures/SoftLayer_Virtual_Guest.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
'preset': {'keyName': 'B1_8X16X100'}
}
},
'datacenter': {'id': 50, 'name': 'TEST00',
'datacenter': {'id': 50, 'name': 'TEST00', 'longName': 'test 00',
'description': 'Test Data Center'},
'powerState': {'keyName': 'RUNNING', 'name': 'Running'},
'maxCpu': 2,
Expand Down Expand Up @@ -83,6 +83,29 @@
'softwareDescription': {'name': 'Ubuntu'}}
}],
'tagReferences': [{'tag': {'name': 'production'}}],
'networkMonitors': [
{
'guestId': 116114480,
'hostId': 116114480,
'id': 17653845,
'ipAddress': '52.116.23.73',
'queryTypeId': 1,
'responseActionId': 1,
'status': 'ON',
'waitCycles': 0,
'queryType': {
'description': 'Test ping to address',
'id': 1,
'monitorLevel': 0,
'name': 'SERVICE PING'
},
'responseAction': {
'actionDescription': 'Do Nothing',
'id': 1,
'level': 0
}
}
]
}
getCreateObjectOptions = {
'flavors': [
Expand Down Expand Up @@ -894,6 +917,6 @@
allowAccessToNetworkStorageList = True

attachDiskImage = {
"createDate": "2021-03-22T13:15:31-06:00",
"id": 1234567
}
"createDate": "2021-03-22T13:15:31-06:00",
"id": 1234567
}
2 changes: 2 additions & 0 deletions SoftLayer/managers/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ def get_hardware(self, hardware_id, **kwargs):
'domain,'
'provisionDate,'
'hardwareStatus,'
'bareMetalInstanceFlag,'
'processorPhysicalCoreAmount,'
'memoryCapacity,'
'notes,'
Expand Down Expand Up @@ -269,6 +270,7 @@ def get_hardware(self, hardware_id, **kwargs):
'hourlyBillingFlag,'
'tagReferences[id,tag[name,id]],'
'networkVlans[id,vlanNumber,networkSpace],'
'monitoringServiceComponent,networkMonitors[queryType,lastResult,responseAction],'
caberos marked this conversation as resolved.
Show resolved Hide resolved
'remoteManagementAccounts[username,password]'
)

Expand Down
1 change: 1 addition & 0 deletions SoftLayer/managers/vs.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ def get_instance(self, instance_id, **kwargs):
'tagReferences[id,tag[name,id]],'
'networkVlans[id,vlanNumber,networkSpace],'
'dedicatedHost.id,'
'monitoringServiceComponent,networkMonitors[queryType,lastResult,responseAction],'
caberos marked this conversation as resolved.
Show resolved Hide resolved
'placementGroupId'
)

Expand Down
4 changes: 4 additions & 0 deletions docs/cli/hardware.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ Interacting with Hardware
:prog: hardware create
:show-nested:

.. click:: SoftLayer.CLI.hardware.monitoring:cli
:prog: hardware monitoring
:show-nested:


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.

Expand Down
4 changes: 4 additions & 0 deletions docs/cli/vs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ If no timezone is specified, IMS local time (CST) will be assumed, which might n
:prog: virtual authorize-storage
:show-nested:

.. click:: SoftLayer.CLI.virt.monitoring:cli
:prog: virtual monitoring
:show-nested:

Manages the migration of virutal guests. Supports migrating virtual guests on Dedicated Hosts as well.

Reserved Capacity
Expand Down
4 changes: 4 additions & 0 deletions tests/CLI/modules/server_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,3 +1010,7 @@ def test_sensor(self):
def test_sensor_discrete(self):
result = self.run_command(['hardware', 'sensor', '100', '--discrete'])
self.assert_no_fail(result)

def test_monitoring(self):
result = self.run_command(['hardware', 'monitoring', '100'])
self.assert_no_fail(result)
4 changes: 4 additions & 0 deletions tests/CLI/modules/vs/vs_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,3 +937,7 @@ def test_authorize_volume_and_portable_storage_vs(self):
result = self.run_command(['vs', 'authorize-storage', '--username-storage=SL01SEL301234-11',
'--portable-id=12345', '1234'])
self.assert_no_fail(result)

def test_monitoring_vs(self):
result = self.run_command(['vs', 'monitoring', '1234'])
self.assert_no_fail(result)