From 666ca1e3bc0406bf75d85d10eb1c350e61b4ced5 Mon Sep 17 00:00:00 2001 From: allmightyspiff Date: Tue, 28 Oct 2014 18:01:20 -0500 Subject: [PATCH 01/11] added in the monitor manager and cli module. only basic functionality for now --- SoftLayer/CLI/core.py | 1 + SoftLayer/CLI/modules/monitor.py | 66 ++++++++++++++++++++++++++++++ SoftLayer/managers/__init__.py | 3 +- SoftLayer/managers/monitor.py | 70 ++++++++++++++++++++++++++++++++ 4 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 SoftLayer/CLI/modules/monitor.py create mode 100644 SoftLayer/managers/monitor.py diff --git a/SoftLayer/CLI/core.py b/SoftLayer/CLI/core.py index c47b24a54..33eb339d8 100644 --- a/SoftLayer/CLI/core.py +++ b/SoftLayer/CLI/core.py @@ -37,6 +37,7 @@ ticket Manage account tickets summary Display an overall summary of your account help Show help + monitor View monitoring information See 'sl help ' for more information on a specific module. diff --git a/SoftLayer/CLI/modules/monitor.py b/SoftLayer/CLI/modules/monitor.py new file mode 100644 index 000000000..f4426456a --- /dev/null +++ b/SoftLayer/CLI/modules/monitor.py @@ -0,0 +1,66 @@ +""" +usage: sl monitor [] [...] [options] + +Manage Monitoring. + +The available commands are: + status Show basic monitoring status of servers + +""" + +import SoftLayer +from SoftLayer.CLI import environment +from SoftLayer.CLI import exceptions +from SoftLayer.CLI import formatting +from SoftLayer.CLI import helpers +from SoftLayer import utils + + +from pprint import pprint as pp +from datetime import date + +class MonitorStatus(environment.CLIRunnable): + """ +usage: sl monitor status [options] + +Unless specified, shows status of all servers. + +Options: + --hardware only show hardware servers + --virtual only show virtual servers + + """ + action = 'status' + def execute(self, args): + hardware = args.get('--hardware') + virtual = args.get('--virtual') + + table = formatting.Table([ + 'id', 'datacenter', 'FQDN', 'public ip', + 'status', 'last checked at' + ]) + + manager = SoftLayer.MonitoringManager(self.client) + results = manager.list_hardware_status() + for server in results: + server = utils.NestedDict(server) + res = server['networkMonitors'][0]['lastResult']['responseStatus'] + date = server['networkMonitors'][0]['lastResult']['finishTime'] + status = '\033[35mUNKNOWN\033[0m' + if res == 0: + status = '\033[31mDOWN\033[0m' + elif res == 1: + status = '\033[93mWARNING\033[0m' + elif res == 2: + status = '\033[32mOK\033[0m' + + table.add_row([ + server['id'], + server['datacenter']['name'] or formatting.blank(), + server['fullyQualifiedDomainName'], + server['primaryIpAddress'] or formatting.blank(), + status, + date + ]) + + return table \ No newline at end of file diff --git a/SoftLayer/managers/__init__.py b/SoftLayer/managers/__init__.py index 8c1211ba3..2fa19c611 100644 --- a/SoftLayer/managers/__init__.py +++ b/SoftLayer/managers/__init__.py @@ -25,9 +25,10 @@ from SoftLayer.managers.ssl import SSLManager # NOQA from SoftLayer.managers.ticket import TicketManager # NOQA from SoftLayer.managers.vs import VSManager # NOQA +from SoftLayer.managers.monitor import MonitoringManager # NOQA __all__ = ['CCIManager', 'DNSManager', 'FirewallManager', 'HardwareManager', 'ImageManager', 'MessagingManager', 'MetadataManager', 'CDNManager', 'NetworkManager', 'SshKeyManager', 'SSLManager', 'TicketManager', 'VSManager', 'ISCSIManager', 'LoadBalancerManager', - 'OrderingManager'] + 'OrderingManager', 'MonitoringManager'] diff --git a/SoftLayer/managers/monitor.py b/SoftLayer/managers/monitor.py new file mode 100644 index 000000000..cbbd7257c --- /dev/null +++ b/SoftLayer/managers/monitor.py @@ -0,0 +1,70 @@ +""" + SoftLayer.monitor + ~~~~~~~~~~~~~~~~~~ + Monitoring Manager/helpers + + :license: MIT, see LICENSE for more details. +""" +# Invalid names are ignored due to long method names and short argument names +# pylint: disable=C0103 +import socket + +from SoftLayer.managers import ordering +from SoftLayer.managers import hardware +from SoftLayer.managers import vs +from SoftLayer import utils + +from pprint import pprint as pp + +class MonitoringManager(utils.IdentifierMixin, object): + """ + Manages monitoring for Hardware and Virtual Servers + + :param SoftLayer.API.CLient client: an API client instance + :param string server_tpe: should be either + 'Hardware_Server' or 'Virtual_Guest' + + """ + + def __init__(self, client, server_type = 'Hardware_Server'): + self.client = client + self.account = self.client['Account'] + # self.resolvers = [self._get_ids_from_ip, self._get_ids_from_hostname] + self.server = self.client[server_type] + + + def get_status(self, server_id): + #Monitoring Status number meanings + # 0 = Down + # 1 = Warning + # 2 = OK + # >2 = something strange happened + + print "\033[32mGetting status of %s\033[0m" % server_id + mask = "lastResult, subnet[virtualGuests,hardware]" + agent = self.server.getNetworkMonitors(id=server_id, mask=mask) + pp(agent) + + def list_hardware_status(self, **kwargs): + """ List all hardware with their monitoring status + + :param dict \\*\\*kwargs: response-level options (mask, limit, filter) + :returns: Retrns a list of dictionaries with server and monitoring + information. + """ + if 'mask' not in kwargs: + hw_items = [ + 'id', + 'fullyQualifiedDomainName', + 'primaryBackendIpAddress', + 'primaryIpAddress', + 'datacenter', + 'networkMonitors[lastResult]' + ] + + kwargs['mask'] = ('[mask[%s]]' + % (','.join(hw_items))) + kwargs['filter'] = '' + output = self.account.getHardware(**kwargs) + return output + From 098fbd3a15f909cb603385d408287224f7b1688b Mon Sep 17 00:00:00 2001 From: allmightyspiff Date: Tue, 28 Oct 2014 18:10:35 -0500 Subject: [PATCH 02/11] cleaning up pep8 complaints --- SoftLayer/CLI/modules/monitor.py | 20 +++++--------------- SoftLayer/managers/__init__.py | 2 +- SoftLayer/managers/monitor.py | 17 ++++------------- 3 files changed, 10 insertions(+), 29 deletions(-) diff --git a/SoftLayer/CLI/modules/monitor.py b/SoftLayer/CLI/modules/monitor.py index f4426456a..14a9c2eeb 100644 --- a/SoftLayer/CLI/modules/monitor.py +++ b/SoftLayer/CLI/modules/monitor.py @@ -10,35 +10,25 @@ import SoftLayer from SoftLayer.CLI import environment -from SoftLayer.CLI import exceptions from SoftLayer.CLI import formatting -from SoftLayer.CLI import helpers from SoftLayer import utils -from pprint import pprint as pp -from datetime import date - class MonitorStatus(environment.CLIRunnable): """ usage: sl monitor status [options] -Unless specified, shows status of all servers. - -Options: - --hardware only show hardware servers - --virtual only show virtual servers +Unless shows status of all servers. """ action = 'status' + def execute(self, args): - hardware = args.get('--hardware') - virtual = args.get('--virtual') table = formatting.Table([ 'id', 'datacenter', 'FQDN', 'public ip', 'status', 'last checked at' - ]) + ]) manager = SoftLayer.MonitoringManager(self.client) results = manager.list_hardware_status() @@ -47,7 +37,7 @@ def execute(self, args): res = server['networkMonitors'][0]['lastResult']['responseStatus'] date = server['networkMonitors'][0]['lastResult']['finishTime'] status = '\033[35mUNKNOWN\033[0m' - if res == 0: + if res == 0: status = '\033[31mDOWN\033[0m' elif res == 1: status = '\033[93mWARNING\033[0m' @@ -61,6 +51,6 @@ def execute(self, args): server['primaryIpAddress'] or formatting.blank(), status, date - ]) + ]) return table \ No newline at end of file diff --git a/SoftLayer/managers/__init__.py b/SoftLayer/managers/__init__.py index 2fa19c611..b7a938a3d 100644 --- a/SoftLayer/managers/__init__.py +++ b/SoftLayer/managers/__init__.py @@ -19,13 +19,13 @@ from SoftLayer.managers.load_balancer import LoadBalancerManager # NOQA from SoftLayer.managers.messaging import MessagingManager # NOQA from SoftLayer.managers.metadata import MetadataManager # NOQA +from SoftLayer.managers.monitor import MonitoringManager # NOQA from SoftLayer.managers.network import NetworkManager # NOQA from SoftLayer.managers.ordering import OrderingManager # NOQA from SoftLayer.managers.sshkey import SshKeyManager # NOQA from SoftLayer.managers.ssl import SSLManager # NOQA from SoftLayer.managers.ticket import TicketManager # NOQA from SoftLayer.managers.vs import VSManager # NOQA -from SoftLayer.managers.monitor import MonitoringManager # NOQA __all__ = ['CCIManager', 'DNSManager', 'FirewallManager', 'HardwareManager', 'ImageManager', 'MessagingManager', 'MetadataManager', 'CDNManager', diff --git a/SoftLayer/managers/monitor.py b/SoftLayer/managers/monitor.py index cbbd7257c..12d2aaa85 100644 --- a/SoftLayer/managers/monitor.py +++ b/SoftLayer/managers/monitor.py @@ -7,43 +7,35 @@ """ # Invalid names are ignored due to long method names and short argument names # pylint: disable=C0103 -import socket -from SoftLayer.managers import ordering -from SoftLayer.managers import hardware -from SoftLayer.managers import vs from SoftLayer import utils -from pprint import pprint as pp class MonitoringManager(utils.IdentifierMixin, object): """ Manages monitoring for Hardware and Virtual Servers :param SoftLayer.API.CLient client: an API client instance - :param string server_tpe: should be either + :param string server_tpe: should be either 'Hardware_Server' or 'Virtual_Guest' """ - def __init__(self, client, server_type = 'Hardware_Server'): + def __init__(self, client, server_type='Hardware_Server'): self.client = client self.account = self.client['Account'] - # self.resolvers = [self._get_ids_from_ip, self._get_ids_from_hostname] self.server = self.client[server_type] - def get_status(self, server_id): - #Monitoring Status number meanings + # Monitoring Status number meanings # 0 = Down # 1 = Warning # 2 = OK # >2 = something strange happened - print "\033[32mGetting status of %s\033[0m" % server_id mask = "lastResult, subnet[virtualGuests,hardware]" agent = self.server.getNetworkMonitors(id=server_id, mask=mask) - pp(agent) + return agent def list_hardware_status(self, **kwargs): """ List all hardware with their monitoring status @@ -67,4 +59,3 @@ def list_hardware_status(self, **kwargs): kwargs['filter'] = '' output = self.account.getHardware(**kwargs) return output - From 01f8ae3452368728e9ac55d89bd74c2b45414d3b Mon Sep 17 00:00:00 2001 From: allmightyspiff Date: Tue, 28 Oct 2014 18:14:09 -0500 Subject: [PATCH 03/11] cleaning up pep8 complaints --- SoftLayer/CLI/modules/monitor.py | 2 +- SoftLayer/managers/monitor.py | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/SoftLayer/CLI/modules/monitor.py b/SoftLayer/CLI/modules/monitor.py index 14a9c2eeb..403f4375a 100644 --- a/SoftLayer/CLI/modules/monitor.py +++ b/SoftLayer/CLI/modules/monitor.py @@ -53,4 +53,4 @@ def execute(self, args): date ]) - return table \ No newline at end of file + return table diff --git a/SoftLayer/managers/monitor.py b/SoftLayer/managers/monitor.py index 12d2aaa85..262de0379 100644 --- a/SoftLayer/managers/monitor.py +++ b/SoftLayer/managers/monitor.py @@ -27,11 +27,15 @@ def __init__(self, client, server_type='Hardware_Server'): self.server = self.client[server_type] def get_status(self, server_id): - # Monitoring Status number meanings - # 0 = Down - # 1 = Warning - # 2 = OK - # >2 = something strange happened + """ get the monitoring status of a server + :param int server_id: the id of the server + + Definition of some of the monitoring status codes + 0 = Down + 1 = Warning + 2 = OK + >2 = something strange happened + """ mask = "lastResult, subnet[virtualGuests,hardware]" agent = self.server.getNetworkMonitors(id=server_id, mask=mask) From d8b9a48483938c6846133b346ce9692269d82636 Mon Sep 17 00:00:00 2001 From: allmightyspiff Date: Wed, 29 Oct 2014 14:50:16 -0500 Subject: [PATCH 04/11] add virtual_guest status and tests --- SoftLayer/CLI/modules/monitor.py | 16 +++++++++++++- SoftLayer/managers/monitor.py | 27 ++++++++++++++++++---- SoftLayer/testing/fixtures/Account.py | 32 +++++++++++++++++++++++---- SoftLayer/testing/fixtures/Monitor.py | 0 4 files changed, 66 insertions(+), 9 deletions(-) create mode 100644 SoftLayer/testing/fixtures/Monitor.py diff --git a/SoftLayer/CLI/modules/monitor.py b/SoftLayer/CLI/modules/monitor.py index 403f4375a..b920da63a 100644 --- a/SoftLayer/CLI/modules/monitor.py +++ b/SoftLayer/CLI/modules/monitor.py @@ -20,6 +20,10 @@ class MonitorStatus(environment.CLIRunnable): Unless shows status of all servers. +Options: + --only-hardware Show only hardware servers + --only-virtual Show only virtual servers + """ action = 'status' @@ -31,7 +35,17 @@ def execute(self, args): ]) manager = SoftLayer.MonitoringManager(self.client) - results = manager.list_hardware_status() + if args.get('--only-virtual'): + hardware = [] + guest = manager.list_guest_status() + elif args.get('--only-hardware'): + hardware = manager.list_hardware_status() + guest = [] + else: + hardware = manager.list_hardware_status() + guest = manager.list_guest_status() + + results = hardware + guest for server in results: server = utils.NestedDict(server) res = server['networkMonitors'][0]['lastResult']['responseStatus'] diff --git a/SoftLayer/managers/monitor.py b/SoftLayer/managers/monitor.py index 262de0379..e502f1d3a 100644 --- a/SoftLayer/managers/monitor.py +++ b/SoftLayer/managers/monitor.py @@ -44,12 +44,31 @@ def get_status(self, server_id): def list_hardware_status(self, **kwargs): """ List all hardware with their monitoring status + :param dict \\*\\*kwargs: response-level options (mask, limit, filter) + :returns: Retrns a list of dictionaries with server and monitoring + information. + """ + return self._get_network_monitors('getHardware', **kwargs) + + def list_guest_status(self, **kwargs): + """ List all virtual guests with their monitoring status + + :param dict \\*\\*kwargs: response-level options (mask, limit, filter) + :returns: Retrns a list of dictionaries with server and monitoring + information. + """ + return self._get_network_monitors('getVirtualGuests', **kwargs) + + def _get_network_monitors(self, call, **kwargs): + """ Does all the actual work of getting the servers monitoring status + :param string call: method from the account class to call + 'getHardware' or 'getVirtualGuests' :param dict \\*\\*kwargs: response-level options (mask, limit, filter) :returns: Retrns a list of dictionaries with server and monitoring information. """ if 'mask' not in kwargs: - hw_items = [ + vs_items = [ 'id', 'fullyQualifiedDomainName', 'primaryBackendIpAddress', @@ -59,7 +78,7 @@ def list_hardware_status(self, **kwargs): ] kwargs['mask'] = ('[mask[%s]]' - % (','.join(hw_items))) + % (','.join(vs_items))) kwargs['filter'] = '' - output = self.account.getHardware(**kwargs) - return output + function = getattr(self.account, call) + return function(**kwargs) diff --git a/SoftLayer/testing/fixtures/Account.py b/SoftLayer/testing/fixtures/Account.py index b3f0b64f0..4e5e5984c 100644 --- a/SoftLayer/testing/fixtures/Account.py +++ b/SoftLayer/testing/fixtures/Account.py @@ -31,7 +31,6 @@ 'globalIdentifier': '1a2b3c-1701', 'primaryBackendIpAddress': '10.45.19.37', 'hourlyBillingFlag': False, - 'billingItem': { 'id': 6327, 'recurringFee': 1.54, @@ -43,6 +42,11 @@ } } }, + 'networkMonitors': [{ + 'guestId': 100, + 'hardwareId': '', + 'lastResult': {'responseStatus': 2} + }], }, { 'id': 104, 'hostname': 'vs-test2', @@ -69,6 +73,11 @@ } } }, + 'networkMonitors': [{ + 'guestId': 104, + 'hardwareId': '', + 'lastResult': {'responseStatus': 0} + }], }] getMonthlyVirtualGuests = [vs for vs in getVirtualGuests @@ -135,7 +144,12 @@ 'friendlyName': 'Friendly Transaction Name', 'id': 6660 } - } + }, + 'networkMonitors': [{ + 'guestId': '', + 'hardwareId': 1000, + 'lastResult': {'responseStatus': 2} + }], }, { 'id': 1001, 'datacenter': {'name': 'TEST00', @@ -178,7 +192,12 @@ 'vlanNumber': 3672, 'id': 19082 }, - ] + ], + 'networkMonitors': [{ + 'guestId': '', + 'hardwareId': 1001, + 'lastResult': {'responseStatus': 0} + }], }, { 'id': 1002, 'datacenter': {'name': 'TEST00', @@ -221,7 +240,12 @@ 'vlanNumber': 3672, 'id': 19082 }, - ] + ], + 'networkMonitors': [{ + 'guestId': '', + 'hardwareId': 1002, + 'lastResult': {'responseStatus': 2} + }], }] getDomains = [{'name': 'example.com', 'id': 12345, diff --git a/SoftLayer/testing/fixtures/Monitor.py b/SoftLayer/testing/fixtures/Monitor.py new file mode 100644 index 000000000..e69de29bb From fc1b6ce9eaa4583050573812e0f64c0dee1bc1fc Mon Sep 17 00:00:00 2001 From: allmightyspiff Date: Wed, 29 Oct 2014 15:31:42 -0500 Subject: [PATCH 05/11] more changes to make pep8 happy --- SoftLayer/CLI/{modules => monitor}/monitor.py | 6 +++--- SoftLayer/managers/monitor.py | 17 ++++++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) rename SoftLayer/CLI/{modules => monitor}/monitor.py (97%) diff --git a/SoftLayer/CLI/modules/monitor.py b/SoftLayer/CLI/monitor/monitor.py similarity index 97% rename from SoftLayer/CLI/modules/monitor.py rename to SoftLayer/CLI/monitor/monitor.py index b920da63a..ba375b2b7 100644 --- a/SoftLayer/CLI/modules/monitor.py +++ b/SoftLayer/CLI/monitor/monitor.py @@ -5,7 +5,6 @@ The available commands are: status Show basic monitoring status of servers - """ import SoftLayer @@ -15,7 +14,8 @@ class MonitorStatus(environment.CLIRunnable): - """ + """Manages all things related to monitoring + usage: sl monitor status [options] Unless shows status of all servers. @@ -23,8 +23,8 @@ class MonitorStatus(environment.CLIRunnable): Options: --only-hardware Show only hardware servers --only-virtual Show only virtual servers +""" - """ action = 'status' def execute(self, args): diff --git a/SoftLayer/managers/monitor.py b/SoftLayer/managers/monitor.py index e502f1d3a..1917965f9 100644 --- a/SoftLayer/managers/monitor.py +++ b/SoftLayer/managers/monitor.py @@ -12,13 +12,11 @@ class MonitoringManager(utils.IdentifierMixin, object): - """ - Manages monitoring for Hardware and Virtual Servers + """Manages monitoring for Hardware and Virtual Servers :param SoftLayer.API.CLient client: an API client instance :param string server_tpe: should be either 'Hardware_Server' or 'Virtual_Guest' - """ def __init__(self, client, server_type='Hardware_Server'): @@ -27,7 +25,8 @@ def __init__(self, client, server_type='Hardware_Server'): self.server = self.client[server_type] def get_status(self, server_id): - """ get the monitoring status of a server + """get the monitoring status of a server + :param int server_id: the id of the server Definition of some of the monitoring status codes @@ -42,31 +41,35 @@ def get_status(self, server_id): return agent def list_hardware_status(self, **kwargs): - """ List all hardware with their monitoring status + """List all hardware with their monitoring status :param dict \\*\\*kwargs: response-level options (mask, limit, filter) :returns: Retrns a list of dictionaries with server and monitoring information. """ + return self._get_network_monitors('getHardware', **kwargs) def list_guest_status(self, **kwargs): - """ List all virtual guests with their monitoring status + """List all virtual guests with their monitoring status :param dict \\*\\*kwargs: response-level options (mask, limit, filter) :returns: Retrns a list of dictionaries with server and monitoring information. """ + return self._get_network_monitors('getVirtualGuests', **kwargs) def _get_network_monitors(self, call, **kwargs): - """ Does all the actual work of getting the servers monitoring status + """Does all the actual work of getting the servers monitoring status + :param string call: method from the account class to call 'getHardware' or 'getVirtualGuests' :param dict \\*\\*kwargs: response-level options (mask, limit, filter) :returns: Retrns a list of dictionaries with server and monitoring information. """ + if 'mask' not in kwargs: vs_items = [ 'id', From e4be3e05ed5fb4f5d55c16e21a5179381beca97c Mon Sep 17 00:00:00 2001 From: allmightyspiff Date: Fri, 31 Oct 2014 15:42:55 -0500 Subject: [PATCH 06/11] making pep8 happy --- SoftLayer/CLI/monitor/__init__.py | 1 + SoftLayer/CLI/monitor/monitor.py | 70 ----------------------- SoftLayer/CLI/monitor/status.py | 65 +++++++++++++++++++++ SoftLayer/CLI/routes.py | 3 + SoftLayer/tests/managers/monitor_tests.py | 34 +++++++++++ 5 files changed, 103 insertions(+), 70 deletions(-) create mode 100644 SoftLayer/CLI/monitor/__init__.py delete mode 100644 SoftLayer/CLI/monitor/monitor.py create mode 100644 SoftLayer/CLI/monitor/status.py create mode 100644 SoftLayer/tests/managers/monitor_tests.py diff --git a/SoftLayer/CLI/monitor/__init__.py b/SoftLayer/CLI/monitor/__init__.py new file mode 100644 index 000000000..c2a201acc --- /dev/null +++ b/SoftLayer/CLI/monitor/__init__.py @@ -0,0 +1 @@ +"""Monitoring""" diff --git a/SoftLayer/CLI/monitor/monitor.py b/SoftLayer/CLI/monitor/monitor.py deleted file mode 100644 index ba375b2b7..000000000 --- a/SoftLayer/CLI/monitor/monitor.py +++ /dev/null @@ -1,70 +0,0 @@ -""" -usage: sl monitor [] [...] [options] - -Manage Monitoring. - -The available commands are: - status Show basic monitoring status of servers -""" - -import SoftLayer -from SoftLayer.CLI import environment -from SoftLayer.CLI import formatting -from SoftLayer import utils - - -class MonitorStatus(environment.CLIRunnable): - """Manages all things related to monitoring - -usage: sl monitor status [options] - -Unless shows status of all servers. - -Options: - --only-hardware Show only hardware servers - --only-virtual Show only virtual servers -""" - - action = 'status' - - def execute(self, args): - - table = formatting.Table([ - 'id', 'datacenter', 'FQDN', 'public ip', - 'status', 'last checked at' - ]) - - manager = SoftLayer.MonitoringManager(self.client) - if args.get('--only-virtual'): - hardware = [] - guest = manager.list_guest_status() - elif args.get('--only-hardware'): - hardware = manager.list_hardware_status() - guest = [] - else: - hardware = manager.list_hardware_status() - guest = manager.list_guest_status() - - results = hardware + guest - for server in results: - server = utils.NestedDict(server) - res = server['networkMonitors'][0]['lastResult']['responseStatus'] - date = server['networkMonitors'][0]['lastResult']['finishTime'] - status = '\033[35mUNKNOWN\033[0m' - if res == 0: - status = '\033[31mDOWN\033[0m' - elif res == 1: - status = '\033[93mWARNING\033[0m' - elif res == 2: - status = '\033[32mOK\033[0m' - - table.add_row([ - server['id'], - server['datacenter']['name'] or formatting.blank(), - server['fullyQualifiedDomainName'], - server['primaryIpAddress'] or formatting.blank(), - status, - date - ]) - - return table diff --git a/SoftLayer/CLI/monitor/status.py b/SoftLayer/CLI/monitor/status.py new file mode 100644 index 000000000..0722df4cb --- /dev/null +++ b/SoftLayer/CLI/monitor/status.py @@ -0,0 +1,65 @@ +""" +usage: sl monitor [] [...] [options] + +Manage Monitoring. + +The available commands are: + status Show basic monitoring status of servers +""" + +import click + +import SoftLayer +from SoftLayer.CLI import environment +from SoftLayer.CLI import formatting +from SoftLayer import utils + + +@click.command() +@click.option('--only_hardware', is_flag=True, + help="Show only physical servers") +@click.option('--only_virtual', is_flag=True, + help="Show only virtual servers") +@environment.pass_env +def cli(env, only_hardware=False, only_virtual=False): + """shows SERVER_PING status of all servers.""" + + table = formatting.Table([ + 'id', 'datacenter', 'FQDN', 'public ip', + 'status', 'last checked at' + ]) + + manager = SoftLayer.MonitoringManager(env.client) + if only_virtual: + hardware = [] + guest = manager.list_guest_status() + elif only_hardware: + hardware = manager.list_hardware_status() + guest = [] + else: + hardware = manager.list_hardware_status() + guest = manager.list_guest_status() + + results = hardware + guest + for server in results: + server = utils.NestedDict(server) + res = server['networkMonitors'][0]['lastResult']['responseStatus'] + date = server['networkMonitors'][0]['lastResult']['finishTime'] + status = '\033[35mUNKNOWN\033[0m' + if res == 0: + status = '\033[31mDOWN\033[0m' + elif res == 1: + status = '\033[93mWARNING\033[0m' + elif res == 2: + status = '\033[32mOK\033[0m' + + table.add_row([ + server['id'], + server['datacenter']['name'] or formatting.blank(), + server['fullyQualifiedDomainName'], + server['primaryIpAddress'] or formatting.blank(), + status, + date + ]) + + return table diff --git a/SoftLayer/CLI/routes.py b/SoftLayer/CLI/routes.py index 05c3f78ea..4cd6ed23b 100644 --- a/SoftLayer/CLI/routes.py +++ b/SoftLayer/CLI/routes.py @@ -116,6 +116,9 @@ ('metadata', 'SoftLayer.CLI.metadata:cli'), + ('monitor', 'SoftLayer.CLI.monitor'), + ('monitor:status', 'SoftLayer.CLI.monitor.status:cli'), + ('nas', 'SoftLayer.CLI.nas'), ('nas:list', 'SoftLayer.CLI.nas.list:cli'), diff --git a/SoftLayer/tests/managers/monitor_tests.py b/SoftLayer/tests/managers/monitor_tests.py new file mode 100644 index 000000000..28b9ad075 --- /dev/null +++ b/SoftLayer/tests/managers/monitor_tests.py @@ -0,0 +1,34 @@ +""" + SoftLayer.tests.managers.monitor_tests + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + :license: MIT, see LICENSE for more details. +""" +import mock + +import SoftLayer +from SoftLayer import testing +from SoftLayer.testing import fixtures + + +class MonitorTests(testing.TestCase): + + def set_up(self): + self.client = testing.FixtureClient() + self.monitor_manager = SoftLayer.MonitoringManager(self.client) + + def test_list_hardware_status(self): + mcall = mock.call(mask=mock.ANY, filter='') + service = self.client['Account'] + + result = self.monitor_manager.list_hardware_status() + self.assertEqual(result, fixtures.Account.getHardware) + service.getHardware.assert_has_calls(mcall) + + def test_list_guest_status(self): + mcall = mock.call(mask=mock.ANY, filter='') + service = self.client['Account'] + + result = self.monitor_manager.list_guest_status() + self.assertEqual(result, fixtures.Account.getVirtualGuests) + service.getVirtualGuests.assert_has_calls(mcall) \ No newline at end of file From b1999185b55686b2facbddf6186fbed982386ab4 Mon Sep 17 00:00:00 2001 From: allmightyspiff Date: Mon, 3 Nov 2014 15:03:37 -0600 Subject: [PATCH 07/11] code cleanup --- SoftLayer/CLI/monitor/status.py | 14 +++++++++----- SoftLayer/managers/monitor.py | 4 +--- SoftLayer/tests/managers/monitor_tests.py | 4 ++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/SoftLayer/CLI/monitor/status.py b/SoftLayer/CLI/monitor/status.py index 0722df4cb..3f8110491 100644 --- a/SoftLayer/CLI/monitor/status.py +++ b/SoftLayer/CLI/monitor/status.py @@ -45,20 +45,24 @@ def cli(env, only_hardware=False, only_virtual=False): server = utils.NestedDict(server) res = server['networkMonitors'][0]['lastResult']['responseStatus'] date = server['networkMonitors'][0]['lastResult']['finishTime'] - status = '\033[35mUNKNOWN\033[0m' + status = 'UNKNOWN' + status_color = None if res == 0: - status = '\033[31mDOWN\033[0m' + status = 'DOWN' + status_color = 'red' elif res == 1: - status = '\033[93mWARNING\033[0m' + status = 'WARNING' + status_color = 'yellow' elif res == 2: - status = '\033[32mOK\033[0m' + status = 'OK' + status_color = 'green' table.add_row([ server['id'], server['datacenter']['name'] or formatting.blank(), server['fullyQualifiedDomainName'], server['primaryIpAddress'] or formatting.blank(), - status, + click.style(status, fg=status_color), date ]) diff --git a/SoftLayer/managers/monitor.py b/SoftLayer/managers/monitor.py index 1917965f9..e8f9a4984 100644 --- a/SoftLayer/managers/monitor.py +++ b/SoftLayer/managers/monitor.py @@ -5,8 +5,7 @@ :license: MIT, see LICENSE for more details. """ -# Invalid names are ignored due to long method names and short argument names -# pylint: disable=C0103 + from SoftLayer import utils @@ -82,6 +81,5 @@ def _get_network_monitors(self, call, **kwargs): kwargs['mask'] = ('[mask[%s]]' % (','.join(vs_items))) - kwargs['filter'] = '' function = getattr(self.account, call) return function(**kwargs) diff --git a/SoftLayer/tests/managers/monitor_tests.py b/SoftLayer/tests/managers/monitor_tests.py index 28b9ad075..3f47d5616 100644 --- a/SoftLayer/tests/managers/monitor_tests.py +++ b/SoftLayer/tests/managers/monitor_tests.py @@ -18,7 +18,7 @@ def set_up(self): self.monitor_manager = SoftLayer.MonitoringManager(self.client) def test_list_hardware_status(self): - mcall = mock.call(mask=mock.ANY, filter='') + mcall = mock.call(mask=mock.ANY) service = self.client['Account'] result = self.monitor_manager.list_hardware_status() @@ -26,7 +26,7 @@ def test_list_hardware_status(self): service.getHardware.assert_has_calls(mcall) def test_list_guest_status(self): - mcall = mock.call(mask=mock.ANY, filter='') + mcall = mock.call(mask=mock.ANY) service = self.client['Account'] result = self.monitor_manager.list_guest_status() From 041299e29920033987eaca8579296934866b597f Mon Sep 17 00:00:00 2001 From: allmightyspiff Date: Thu, 11 Dec 2014 17:22:22 -0600 Subject: [PATCH 08/11] cleaned up the monitor status, and merged in master --- SoftLayer/CLI/monitor/status.py | 54 ++++++++++++++++++--------------- SoftLayer/managers/monitor.py | 2 +- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/SoftLayer/CLI/monitor/status.py b/SoftLayer/CLI/monitor/status.py index 3f8110491..efbeaf0eb 100644 --- a/SoftLayer/CLI/monitor/status.py +++ b/SoftLayer/CLI/monitor/status.py @@ -25,8 +25,8 @@ def cli(env, only_hardware=False, only_virtual=False): """shows SERVER_PING status of all servers.""" table = formatting.Table([ - 'id', 'datacenter', 'FQDN', 'public ip', - 'status', 'last checked at' + 'id', 'datacenter', 'FQDN', 'IP', + 'status', 'Type', 'last checked at' ]) manager = SoftLayer.MonitoringManager(env.client) @@ -41,29 +41,33 @@ def cli(env, only_hardware=False, only_virtual=False): guest = manager.list_guest_status() results = hardware + guest - for server in results: - server = utils.NestedDict(server) - res = server['networkMonitors'][0]['lastResult']['responseStatus'] - date = server['networkMonitors'][0]['lastResult']['finishTime'] - status = 'UNKNOWN' - status_color = None - if res == 0: - status = 'DOWN' - status_color = 'red' - elif res == 1: - status = 'WARNING' - status_color = 'yellow' - elif res == 2: - status = 'OK' - status_color = 'green' + for serverObject in results: + server = utils.NestedDict(serverObject) + for monitor in server['networkMonitors']: + res = monitor['lastResult']['responseStatus'] + date = monitor['lastResult']['finishTime'] + ip = monitor['ipAddress'] + monitorType = monitor['queryType']['name'] + status = 'UNKNOWN' + status_color = None + if res == 0: + status = 'DOWN' + status_color = 'red' + elif res == 1: + status = 'WARNING' + status_color = 'yellow' + elif res == 2: + status = 'OK' + status_color = 'green' - table.add_row([ - server['id'], - server['datacenter']['name'] or formatting.blank(), - server['fullyQualifiedDomainName'], - server['primaryIpAddress'] or formatting.blank(), - click.style(status, fg=status_color), - date - ]) + table.add_row([ + server['id'], + server['datacenter']['name'] or formatting.blank(), + server['fullyQualifiedDomainName'], + ip or formatting.blank(), + click.style(status, fg=status_color), + monitorType, + date + ]) return table diff --git a/SoftLayer/managers/monitor.py b/SoftLayer/managers/monitor.py index e8f9a4984..d60790627 100644 --- a/SoftLayer/managers/monitor.py +++ b/SoftLayer/managers/monitor.py @@ -76,7 +76,7 @@ def _get_network_monitors(self, call, **kwargs): 'primaryBackendIpAddress', 'primaryIpAddress', 'datacenter', - 'networkMonitors[lastResult]' + 'networkMonitors[lastResult,queryType]' ] kwargs['mask'] = ('[mask[%s]]' From f335a58918de89284b2288b9c8f84dd8a3a23f70 Mon Sep 17 00:00:00 2001 From: allmightyspiff Date: Tue, 16 Dec 2014 13:18:46 -0600 Subject: [PATCH 09/11] changed some formatting on the status output. fixed unit tests --- SoftLayer/CLI/monitor/status.py | 14 +++++++------- SoftLayer/tests/managers/monitor_tests.py | 15 ++------------- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/SoftLayer/CLI/monitor/status.py b/SoftLayer/CLI/monitor/status.py index efbeaf0eb..9dc95f2ac 100644 --- a/SoftLayer/CLI/monitor/status.py +++ b/SoftLayer/CLI/monitor/status.py @@ -41,13 +41,13 @@ def cli(env, only_hardware=False, only_virtual=False): guest = manager.list_guest_status() results = hardware + guest - for serverObject in results: - server = utils.NestedDict(serverObject) + for server_object in results: + server = utils.NestedDict(server_object) for monitor in server['networkMonitors']: res = monitor['lastResult']['responseStatus'] date = monitor['lastResult']['finishTime'] - ip = monitor['ipAddress'] - monitorType = monitor['queryType']['name'] + ip_address = monitor['ipAddress'] + monitor_type = monitor['queryType']['name'] status = 'UNKNOWN' status_color = None if res == 0: @@ -64,10 +64,10 @@ def cli(env, only_hardware=False, only_virtual=False): server['id'], server['datacenter']['name'] or formatting.blank(), server['fullyQualifiedDomainName'], - ip or formatting.blank(), + ip_address or formatting.blank(), click.style(status, fg=status_color), - monitorType, - date + monitor_type, + date ]) return table diff --git a/SoftLayer/tests/managers/monitor_tests.py b/SoftLayer/tests/managers/monitor_tests.py index 3f47d5616..a94146495 100644 --- a/SoftLayer/tests/managers/monitor_tests.py +++ b/SoftLayer/tests/managers/monitor_tests.py @@ -4,8 +4,6 @@ :license: MIT, see LICENSE for more details. """ -import mock - import SoftLayer from SoftLayer import testing from SoftLayer.testing import fixtures @@ -14,21 +12,12 @@ class MonitorTests(testing.TestCase): def set_up(self): - self.client = testing.FixtureClient() self.monitor_manager = SoftLayer.MonitoringManager(self.client) def test_list_hardware_status(self): - mcall = mock.call(mask=mock.ANY) - service = self.client['Account'] - result = self.monitor_manager.list_hardware_status() - self.assertEqual(result, fixtures.Account.getHardware) - service.getHardware.assert_has_calls(mcall) + self.assertEqual(result, fixtures.SoftLayer_Account.getHardware) def test_list_guest_status(self): - mcall = mock.call(mask=mock.ANY) - service = self.client['Account'] - result = self.monitor_manager.list_guest_status() - self.assertEqual(result, fixtures.Account.getVirtualGuests) - service.getVirtualGuests.assert_has_calls(mcall) \ No newline at end of file + self.assertEqual(result, fixtures.SoftLayer_Account.getVirtualGuests) From 532e7832ad33dd53ce11266cd557bbaa4851c9db Mon Sep 17 00:00:00 2001 From: allmightyspiff Date: Tue, 16 Dec 2014 13:33:56 -0600 Subject: [PATCH 10/11] improving monitoring unit tests --- SoftLayer/tests/managers/monitor_tests.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SoftLayer/tests/managers/monitor_tests.py b/SoftLayer/tests/managers/monitor_tests.py index a94146495..a7c960d9b 100644 --- a/SoftLayer/tests/managers/monitor_tests.py +++ b/SoftLayer/tests/managers/monitor_tests.py @@ -17,7 +17,9 @@ def set_up(self): def test_list_hardware_status(self): result = self.monitor_manager.list_hardware_status() self.assertEqual(result, fixtures.SoftLayer_Account.getHardware) + self.assert_called_with('SoftLayer_Account', 'getHardware') def test_list_guest_status(self): result = self.monitor_manager.list_guest_status() self.assertEqual(result, fixtures.SoftLayer_Account.getVirtualGuests) + self.assert_called_with('SoftLayer_Account', 'getVirtualGuests') From e2e2a8d3631a616ea85d824fff3fc350a1923687 Mon Sep 17 00:00:00 2001 From: allmightyspiff Date: Wed, 28 Jan 2015 18:37:52 -0600 Subject: [PATCH 11/11] refactoring monitor manager to have 2 distinct managers for virtual and hardware --- SoftLayer/CLI/monitor/status.py | 29 ++++--- SoftLayer/managers/__init__.py | 6 +- SoftLayer/managers/monitor.py | 85 ------------------- SoftLayer/managers/monitor/__init__.py | 6 ++ SoftLayer/managers/monitor/hw_monitor.py | 40 +++++++++ SoftLayer/managers/monitor/vs_monitor.py | 40 +++++++++ .../testing/fixtures/SoftLayer_Account.py | 52 ++++++++++-- SoftLayer/tests/CLI/modules/monitor_tests.py | 31 +++++++ SoftLayer/tests/managers/monitor_tests.py | 7 +- 9 files changed, 191 insertions(+), 105 deletions(-) delete mode 100644 SoftLayer/managers/monitor.py create mode 100644 SoftLayer/managers/monitor/__init__.py create mode 100644 SoftLayer/managers/monitor/hw_monitor.py create mode 100644 SoftLayer/managers/monitor/vs_monitor.py create mode 100644 SoftLayer/tests/CLI/modules/monitor_tests.py diff --git a/SoftLayer/CLI/monitor/status.py b/SoftLayer/CLI/monitor/status.py index 9dc95f2ac..ec622abec 100644 --- a/SoftLayer/CLI/monitor/status.py +++ b/SoftLayer/CLI/monitor/status.py @@ -28,26 +28,35 @@ def cli(env, only_hardware=False, only_virtual=False): 'id', 'datacenter', 'FQDN', 'IP', 'status', 'Type', 'last checked at' ]) - - manager = SoftLayer.MonitoringManager(env.client) + hw_manager = SoftLayer.HardwareMonitorManager(env.client) + vs_manager = SoftLayer.VSMonitorManager(env.client) if only_virtual: hardware = [] - guest = manager.list_guest_status() + guest = vs_manager.list_status() elif only_hardware: - hardware = manager.list_hardware_status() + hardware = hw_manager.list_status() guest = [] else: - hardware = manager.list_hardware_status() - guest = manager.list_guest_status() + hardware = hw_manager.list_status() + guest = vs_manager.list_status() results = hardware + guest for server_object in results: server = utils.NestedDict(server_object) for monitor in server['networkMonitors']: - res = monitor['lastResult']['responseStatus'] - date = monitor['lastResult']['finishTime'] - ip_address = monitor['ipAddress'] - monitor_type = monitor['queryType']['name'] + try: + res = monitor['lastResult']['responseStatus'] + date = monitor['lastResult']['finishTime'] + ip_address = monitor['ipAddress'] + monitor_type = monitor['queryType']['name'] + except KeyError: + # if a monitor does't have the lastResult ususally it is + # still being provisioned + res = 0 + date = "--" + ip_address = None + monitor_type = "--" + status = 'UNKNOWN' status_color = None if res == 0: diff --git a/SoftLayer/managers/__init__.py b/SoftLayer/managers/__init__.py index 43d0f140a..b2ad30300 100644 --- a/SoftLayer/managers/__init__.py +++ b/SoftLayer/managers/__init__.py @@ -18,7 +18,8 @@ from SoftLayer.managers.load_balancer import LoadBalancerManager # NOQA from SoftLayer.managers.messaging import MessagingManager # NOQA from SoftLayer.managers.metadata import MetadataManager # NOQA -from SoftLayer.managers.monitor import MonitoringManager # NOQA +from SoftLayer.managers.monitor.hw_monitor import HardwareMonitorManager # NOQA +from SoftLayer.managers.monitor.vs_monitor import VSMonitorManager # NOQA from SoftLayer.managers.network import NetworkManager # NOQA from SoftLayer.managers.ordering import OrderingManager # NOQA from SoftLayer.managers.sshkey import SshKeyManager # NOQA @@ -31,4 +32,5 @@ 'MetadataManager', 'CDNManager', 'NetworkManager', 'SshKeyManager', 'SSLManager', 'TicketManager', 'VSManager', 'ISCSIManager', 'LoadBalancerManager', - 'OrderingManager', 'MonitoringManager'] + 'OrderingManager', 'HardwareMonitorManager', + 'VSMonitorManager'] diff --git a/SoftLayer/managers/monitor.py b/SoftLayer/managers/monitor.py deleted file mode 100644 index d60790627..000000000 --- a/SoftLayer/managers/monitor.py +++ /dev/null @@ -1,85 +0,0 @@ -""" - SoftLayer.monitor - ~~~~~~~~~~~~~~~~~~ - Monitoring Manager/helpers - - :license: MIT, see LICENSE for more details. -""" - - -from SoftLayer import utils - - -class MonitoringManager(utils.IdentifierMixin, object): - """Manages monitoring for Hardware and Virtual Servers - - :param SoftLayer.API.CLient client: an API client instance - :param string server_tpe: should be either - 'Hardware_Server' or 'Virtual_Guest' - """ - - def __init__(self, client, server_type='Hardware_Server'): - self.client = client - self.account = self.client['Account'] - self.server = self.client[server_type] - - def get_status(self, server_id): - """get the monitoring status of a server - - :param int server_id: the id of the server - - Definition of some of the monitoring status codes - 0 = Down - 1 = Warning - 2 = OK - >2 = something strange happened - """ - - mask = "lastResult, subnet[virtualGuests,hardware]" - agent = self.server.getNetworkMonitors(id=server_id, mask=mask) - return agent - - def list_hardware_status(self, **kwargs): - """List all hardware with their monitoring status - - :param dict \\*\\*kwargs: response-level options (mask, limit, filter) - :returns: Retrns a list of dictionaries with server and monitoring - information. - """ - - return self._get_network_monitors('getHardware', **kwargs) - - def list_guest_status(self, **kwargs): - """List all virtual guests with their monitoring status - - :param dict \\*\\*kwargs: response-level options (mask, limit, filter) - :returns: Retrns a list of dictionaries with server and monitoring - information. - """ - - return self._get_network_monitors('getVirtualGuests', **kwargs) - - def _get_network_monitors(self, call, **kwargs): - """Does all the actual work of getting the servers monitoring status - - :param string call: method from the account class to call - 'getHardware' or 'getVirtualGuests' - :param dict \\*\\*kwargs: response-level options (mask, limit, filter) - :returns: Retrns a list of dictionaries with server and monitoring - information. - """ - - if 'mask' not in kwargs: - vs_items = [ - 'id', - 'fullyQualifiedDomainName', - 'primaryBackendIpAddress', - 'primaryIpAddress', - 'datacenter', - 'networkMonitors[lastResult,queryType]' - ] - - kwargs['mask'] = ('[mask[%s]]' - % (','.join(vs_items))) - function = getattr(self.account, call) - return function(**kwargs) diff --git a/SoftLayer/managers/monitor/__init__.py b/SoftLayer/managers/monitor/__init__.py new file mode 100644 index 000000000..2d7c460c5 --- /dev/null +++ b/SoftLayer/managers/monitor/__init__.py @@ -0,0 +1,6 @@ +""" + SoftLayer.managers.monitor + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + :license: MIT, see LICENSE for more details. +""" diff --git a/SoftLayer/managers/monitor/hw_monitor.py b/SoftLayer/managers/monitor/hw_monitor.py new file mode 100644 index 000000000..784a7d67e --- /dev/null +++ b/SoftLayer/managers/monitor/hw_monitor.py @@ -0,0 +1,40 @@ +""" + SoftLayer.monitor.hw_monitor + ~~~~~~~~~~~~~~~~~~ + Monitoring Manager/helpers for Hardware_Server + + :license: MIT, see LICENSE for more details. +""" + + +class HardwareMonitorManager(object): + """Manages monitoring for Hardware Servers + + :param SoftLayer.API.CLient client: an API client instance + """ + + def __init__(self, client): + self.client = client + self.account = self.client['Account'] + self.server = self.client['Hardware_Server'] + + def list_status(self, **kwargs): + """List all hardware with their monitoring status + + :param dict \\*\\*kwargs: response-level options (mask, limit, filter) + :returns: Retrns a list of dictionaries with server and monitoring + information. + """ + + vs_items = [ + 'id', + 'fullyQualifiedDomainName', + 'primaryBackendIpAddress', + 'primaryIpAddress', + 'datacenter', + 'networkMonitors[lastResult,queryType]' + ] + + kwargs['mask'] = ('[mask[%s]]' + % (','.join(vs_items))) + return self.account.call('getHardware', **kwargs) diff --git a/SoftLayer/managers/monitor/vs_monitor.py b/SoftLayer/managers/monitor/vs_monitor.py new file mode 100644 index 000000000..f1f9d084a --- /dev/null +++ b/SoftLayer/managers/monitor/vs_monitor.py @@ -0,0 +1,40 @@ +""" + SoftLayer.monitor.vs_monitor + ~~~~~~~~~~~~~~~~~~ + Monitoring Manager/helpers for Virtual_Guest + + :license: MIT, see LICENSE for more details. +""" + + +class VSMonitorManager(object): + """Manages monitoring for Virtual Servers + + :param SoftLayer.API.CLient client: an API client instance + """ + + def __init__(self, client): + self.client = client + self.account = self.client['Account'] + self.server = self.client['Virtual_Guest'] + + def list_status(self, **kwargs): + """List all virtual guests with their monitoring status + + :param dict \\*\\*kwargs: response-level options (mask, limit, filter) + :returns: Retrns a list of dictionaries with server and monitoring + information. + """ + + vs_items = [ + 'id', + 'fullyQualifiedDomainName', + 'primaryBackendIpAddress', + 'primaryIpAddress', + 'datacenter', + 'networkMonitors[lastResult,queryType]' + ] + + kwargs['mask'] = ('[mask[%s]]' + % (','.join(vs_items))) + return self.account.call('getVirtualGuests', **kwargs) diff --git a/SoftLayer/testing/fixtures/SoftLayer_Account.py b/SoftLayer/testing/fixtures/SoftLayer_Account.py index a8a830236..81675afe0 100644 --- a/SoftLayer/testing/fixtures/SoftLayer_Account.py +++ b/SoftLayer/testing/fixtures/SoftLayer_Account.py @@ -45,7 +45,20 @@ 'networkMonitors': [{ 'guestId': 100, 'hardwareId': '', - 'lastResult': {'responseStatus': 2} + 'ipAddress': '158.85.177.200', + 'queryType': {'name': 'SERVICE_PING'}, + 'lastResult': { + 'responseStatus': 2, + 'finishTime': '2015-01-28T17:27:06-06:00' + } + }, { + 'guestId': 104, + 'hardwareId': '', + 'ipAddress': '158.85.177.200', + 'queryType': {'name': 'KEY_ERROR'}, + 'lastResult': { + 'responseStatus': 1 + } }], }, { 'id': 104, @@ -76,7 +89,21 @@ 'networkMonitors': [{ 'guestId': 104, 'hardwareId': '', - 'lastResult': {'responseStatus': 0} + 'ipAddress': '158.85.177.200', + 'queryType': {'name': 'SERVICE_PING'}, + 'lastResult': { + 'responseStatus': 0, + 'finishTime': '2014-01-28T17:27:06-06:00' + } + }, { + 'guestId': 104, + 'hardwareId': '', + 'ipAddress': '158.85.177.200', + 'queryType': {'name': 'SERVICE_PING'}, + 'lastResult': { + 'responseStatus': 1, + 'finishTime': '2014-01-28T17:27:06-06:00' + } }], }] @@ -149,7 +176,12 @@ 'networkMonitors': [{ 'guestId': '', 'hardwareId': 1000, - 'lastResult': {'responseStatus': 2} + 'ipAddress': '158.85.177.200', + 'queryType': {'name': 'SERVICE_PING'}, + 'lastResult': { + 'responseStatus': 1, + 'finishTime': '2014-01-28T17:27:06-06:00' + } }], }, { 'id': 1001, @@ -198,7 +230,12 @@ 'networkMonitors': [{ 'guestId': '', 'hardwareId': 1001, - 'lastResult': {'responseStatus': 0} + 'ipAddress': '158.85.177.200', + 'queryType': {'name': 'SERVICE_PING'}, + 'lastResult': { + 'responseStatus': 0, + 'finishTime': '2014-01-28T17:27:06-06:00' + } }], }, { 'id': 1002, @@ -246,7 +283,12 @@ 'networkMonitors': [{ 'guestId': '', 'hardwareId': 1002, - 'lastResult': {'responseStatus': 2} + 'ipAddress': '158.85.177.200', + 'queryType': {'name': 'SERVICE_PING'}, + 'lastResult': { + 'responseStatus': 2, + 'finishTime': '2014-01-28T17:27:06-06:00' + } }], }] getDomains = [{'name': 'example.com', diff --git a/SoftLayer/tests/CLI/modules/monitor_tests.py b/SoftLayer/tests/CLI/modules/monitor_tests.py new file mode 100644 index 000000000..13fe3eb79 --- /dev/null +++ b/SoftLayer/tests/CLI/modules/monitor_tests.py @@ -0,0 +1,31 @@ +""" + SoftLayer.tests.managers.monitor_tests + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + :license: MIT, see LICENSE for more details. +""" +import SoftLayer +from SoftLayer import testing + + +class MonitorTests(testing.TestCase): + + def set_up(self): + self.hw_monitor_manager = SoftLayer.HardwareMonitorManager(self.client) + self.vs_monitor_manager = SoftLayer.VSMonitorManager(self.client) + + def test_list_status(self): + result = self.run_command(['monitor', 'status']) + self.assertEqual(result.exit_code, 0) + self.assert_called_with('SoftLayer_Account', 'getVirtualGuests') + self.assert_called_with('SoftLayer_Account', 'getHardware') + + def test_list_only_hardware(self): + result = self.run_command(['monitor', 'status', '--only_hardware']) + self.assert_called_with('SoftLayer_Account', 'getHardware') + self.assertEqual(result.exit_code, 0) + + def test_list_only_virtual(self): + result = self.run_command(['monitor', 'status', '--only_virtual']) + self.assert_called_with('SoftLayer_Account', 'getVirtualGuests') + self.assertEqual(result.exit_code, 0) diff --git a/SoftLayer/tests/managers/monitor_tests.py b/SoftLayer/tests/managers/monitor_tests.py index a7c960d9b..469ae000e 100644 --- a/SoftLayer/tests/managers/monitor_tests.py +++ b/SoftLayer/tests/managers/monitor_tests.py @@ -12,14 +12,15 @@ class MonitorTests(testing.TestCase): def set_up(self): - self.monitor_manager = SoftLayer.MonitoringManager(self.client) + self.hw_monitor_manager = SoftLayer.HardwareMonitorManager(self.client) + self.vs_monitor_manager = SoftLayer.VSMonitorManager(self.client) def test_list_hardware_status(self): - result = self.monitor_manager.list_hardware_status() + result = self.hw_monitor_manager.list_status() self.assertEqual(result, fixtures.SoftLayer_Account.getHardware) self.assert_called_with('SoftLayer_Account', 'getHardware') def test_list_guest_status(self): - result = self.monitor_manager.list_guest_status() + result = self.vs_monitor_manager.list_status() self.assertEqual(result, fixtures.SoftLayer_Account.getVirtualGuests) self.assert_called_with('SoftLayer_Account', 'getVirtualGuests')