1#!/usr/bin/python 2 3# (c) 2017, NetApp, Inc 4# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 5 6from __future__ import absolute_import, division, print_function 7__metaclass__ = type 8 9 10ANSIBLE_METADATA = {'metadata_version': '1.1', 11 'status': ['deprecated'], 12 'supported_by': 'community'} 13 14 15DOCUMENTATION = ''' 16 17module: sf_check_connections 18deprecated: 19 removed_in: "2.11" 20 why: This Module has been replaced 21 alternative: please use M(na_elementsw_check_connections) 22short_description: Check connectivity to MVIP and SVIP. 23extends_documentation_fragment: 24 - netapp.solidfire 25version_added: '2.3' 26author: Sumit Kumar (@timuster) <sumit4@netapp.com> 27description: 28- Used to test the management connection to the cluster. 29- The test pings the MVIP and SVIP, and executes a simple API method to verify connectivity. 30 31options: 32 33 skip: 34 description: 35 - Skip checking connection to SVIP or MVIP. 36 choices: ['svip', 'mvip'] 37 38 mvip: 39 description: 40 - Optionally, use to test connection of a different MVIP. 41 - This is not needed to test the connection to the target cluster. 42 43 svip: 44 description: 45 - Optionally, use to test connection of a different SVIP. 46 - This is not needed to test the connection to the target cluster. 47 48''' 49 50 51EXAMPLES = """ 52 - name: Check connections to MVIP and SVIP 53 sf_check_connections: 54 hostname: "{{ solidfire_hostname }}" 55 username: "{{ solidfire_username }}" 56 password: "{{ solidfire_password }}" 57""" 58 59RETURN = """ 60 61""" 62import traceback 63 64from ansible.module_utils.basic import AnsibleModule 65from ansible.module_utils._text import to_native 66import ansible.module_utils.netapp as netapp_utils 67 68 69HAS_SF_SDK = netapp_utils.has_sf_sdk() 70 71 72class SolidFireConnection(object): 73 74 def __init__(self): 75 self.argument_spec = netapp_utils.ontap_sf_host_argument_spec() 76 self.argument_spec.update(dict( 77 skip=dict(required=False, type='str', default=None, choices=['mvip', 'svip']), 78 mvip=dict(required=False, type='str', default=None), 79 svip=dict(required=False, type='str', default=None) 80 )) 81 82 self.module = AnsibleModule( 83 argument_spec=self.argument_spec, 84 supports_check_mode=True 85 ) 86 87 p = self.module.params 88 89 # set up state variables 90 self.skip = p['skip'] 91 self.mvip = p['mvip'] 92 self.svip = p['svip'] 93 94 if HAS_SF_SDK is False: 95 self.module.fail_json(msg="Unable to import the SolidFire Python SDK") 96 else: 97 self.sfe = netapp_utils.ElementFactory.create(p['hostname'], p['username'], p['password'], port=442) 98 99 def check_mvip_connection(self): 100 """ 101 Check connection to MVIP 102 103 :return: true if connection was successful, false otherwise. 104 :rtype: bool 105 """ 106 try: 107 test = self.sfe.test_connect_mvip(mvip=self.mvip) 108 result = test.details.connected 109 # Todo - Log details about the test 110 return result 111 112 except Exception as e: 113 self.module.fail_json(msg='Error checking connection to MVIP: %s' % to_native(e), exception=traceback.format_exc()) 114 return False 115 116 def check_svip_connection(self): 117 """ 118 Check connection to SVIP 119 120 :return: true if connection was successful, false otherwise. 121 :rtype: bool 122 """ 123 try: 124 test = self.sfe.test_connect_svip(svip=self.svip) 125 result = test.details.connected 126 # Todo - Log details about the test 127 return result 128 129 except Exception as e: 130 self.module.fail_json(msg='Error checking connection to SVIP: %s' % to_native(e), exception=traceback.format_exc()) 131 return False 132 133 def check(self): 134 135 failed = True 136 msg = '' 137 138 if self.skip is None: 139 mvip_connection_established = self.check_mvip_connection() 140 svip_connection_established = self.check_svip_connection() 141 142 # Set failed and msg 143 if not mvip_connection_established: 144 failed = True 145 msg = 'Connection to MVIP failed.' 146 elif not svip_connection_established: 147 failed = True 148 msg = 'Connection to SVIP failed.' 149 else: 150 failed = False 151 152 elif self.skip == 'mvip': 153 svip_connection_established = self.check_svip_connection() 154 155 # Set failed and msg 156 if not svip_connection_established: 157 failed = True 158 msg = 'Connection to SVIP failed.' 159 else: 160 failed = False 161 162 elif self.skip == 'svip': 163 mvip_connection_established = self.check_mvip_connection() 164 165 # Set failed and msg 166 if not mvip_connection_established: 167 failed = True 168 msg = 'Connection to MVIP failed.' 169 else: 170 failed = False 171 172 if failed: 173 self.module.fail_json(msg=msg) 174 else: 175 self.module.exit_json() 176 177 178def main(): 179 v = SolidFireConnection() 180 v.check() 181 182 183if __name__ == '__main__': 184 main() 185