def set_gslb_site_metricexchange(self, client) : try : gslbsite1 = gslbsite() gslbsite1.sitename = "bangalore1" gslbsite1.metricexchange = "enabled" gslbsite.update(client,gslbsite1) print("set_gslb_site_metricexchange - Done") except nitro_exception as e : print("Exception::set_gslb_site_metricexchange::errorcode="+str(e.errorcode)+",message="+ e.message) except Exception as e: print("Exception::set_gslb_site_metricexchange::message="+str(e.args))
def unset_gslb_site_metricexchange(self, client) : try : arr = ["metricexchange"] gslbsite1 = gslbsite() gslbsite1.sitename = "bangalore1" gslbsite.unset(client, gslbsite1, arr) print("unset_gslb_site_metricexchange - Done") except nitro_exception as e : print("Exception::unset_gslb_site_metricexchange::errorcode="+str(e.errorcode)+",message="+ e.message) except Exception as e: print("Exception::unset_gslb_site_metricexchange::message="+str(e.args))
def add_gslb_site(self, client) : try : gslbsite1 = gslbsite() gslbsite1.sitename = "bangalore1" gslbsite1.sitetype = "local" gslbsite1.metricexchange = "enabled" gslbsite1.siteipaddress = "10.102.3.222" gslbsite.add(client, gslbsite1) print("add_gslb_site - Done") except nitro_exception as e : print("Exception::add_gslb_site::errorcode="+str(e.errorcode)+",message="+ e.message) except Exception as e: print("Exception::add_gslb_site::message="+str(e.args))
def main(): module_specific_arguments = dict( sitename=dict(type='str'), sitetype=dict( type='str', choices=[ 'REMOTE', 'LOCAL', ] ), siteipaddress=dict(type='str'), publicip=dict(type='str'), metricexchange=dict( type='str', choices=[ 'enabled', 'disabled', ] ), nwmetricexchange=dict( type='str', choices=[ 'enabled', 'disabled', ] ), sessionexchange=dict( type='str', choices=[ 'enabled', 'disabled', ] ), triggermonitor=dict( type='str', choices=[ 'ALWAYS', 'MEPDOWN', 'MEPDOWN_SVCDOWN', ] ), parentsite=dict(type='str'), clip=dict(type='str'), publicclip=dict(type='str'), naptrreplacementsuffix=dict(type='str'), ) hand_inserted_arguments = dict( ) argument_spec = dict() argument_spec.update(netscaler_common_arguments) argument_spec.update(module_specific_arguments) argument_spec.update(hand_inserted_arguments) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, ) module_result = dict( changed=False, failed=False, loglines=loglines, ) # Fail the module if imports failed if not PYTHON_SDK_IMPORTED: module.fail_json(msg='Could not load nitro python sdk') # Fallthrough to rest of execution client = get_nitro_client(module) try: client.login() except nitro_exception as e: msg = "nitro exception during login. errorcode=%s, message=%s" % (str(e.errorcode), e.message) module.fail_json(msg=msg) except Exception as e: if str(type(e)) == "<class 'requests.exceptions.ConnectionError'>": module.fail_json(msg='Connection error %s' % str(e)) elif str(type(e)) == "<class 'requests.exceptions.SSLError'>": module.fail_json(msg='SSL Error %s' % str(e)) else: module.fail_json(msg='Unexpected error during login %s' % str(e)) readwrite_attrs = [ 'sitename', 'sitetype', 'siteipaddress', 'publicip', 'metricexchange', 'nwmetricexchange', 'sessionexchange', 'triggermonitor', 'parentsite', 'clip', 'publicclip', 'naptrreplacementsuffix', ] readonly_attrs = [ 'status', 'persistencemepstatus', 'version', '__count', ] immutable_attrs = [ 'sitename', 'sitetype', 'siteipaddress', 'publicip', 'parentsite', 'clip', 'publicclip', ] transforms = { 'metricexchange': [lambda v: v.upper()], 'nwmetricexchange': [lambda v: v.upper()], 'sessionexchange': [lambda v: v.upper()], } # Instantiate config proxy gslb_site_proxy = ConfigProxy( actual=gslbsite(), client=client, attribute_values_dict=module.params, readwrite_attrs=readwrite_attrs, readonly_attrs=readonly_attrs, immutable_attrs=immutable_attrs, transforms=transforms, ) try: ensure_feature_is_enabled(client, 'GSLB') # Apply appropriate state if module.params['state'] == 'present': log('Applying actions for state present') if not gslb_site_exists(client, module): if not module.check_mode: gslb_site_proxy.add() if module.params['save_config']: client.save_config() module_result['changed'] = True elif not gslb_site_identical(client, module, gslb_site_proxy): # Check if we try to change value of immutable attributes immutables_changed = get_immutables_intersection(gslb_site_proxy, diff_list(client, module, gslb_site_proxy).keys()) if immutables_changed != []: module.fail_json( msg='Cannot update immutable attributes %s' % (immutables_changed,), diff=diff_list(client, module, gslb_site_proxy), **module_result ) if not module.check_mode: gslb_site_proxy.update() if module.params['save_config']: client.save_config() module_result['changed'] = True else: module_result['changed'] = False # Sanity check for state if not module.check_mode: log('Sanity checks for state present') if not gslb_site_exists(client, module): module.fail_json(msg='GSLB site does not exist', **module_result) if not gslb_site_identical(client, module, gslb_site_proxy): module.fail_json(msg='GSLB site differs from configured', diff=diff_list(client, module, gslb_site_proxy), **module_result) elif module.params['state'] == 'absent': log('Applying actions for state absent') if gslb_site_exists(client, module): if not module.check_mode: gslb_site_proxy.delete() if module.params['save_config']: client.save_config() module_result['changed'] = True else: module_result['changed'] = False # Sanity check for state if not module.check_mode: log('Sanity checks for state absent') if gslb_site_exists(client, module): module.fail_json(msg='GSLB site still exists', **module_result) except nitro_exception as e: msg = "nitro exception errorcode=%s, message=%s" % (str(e.errorcode), e.message) module.fail_json(msg=msg, **module_result) client.logout() module.exit_json(**module_result)
def main(): module_specific_arguments = dict( sitename=dict(type='str'), sitetype=dict( type='str', choices=[ 'REMOTE', 'LOCAL', ] ), siteipaddress=dict(type='str'), publicip=dict(type='str'), metricexchange=dict( type='str', choices=[ 'enabled', 'disabled', ] ), nwmetricexchange=dict( type='str', choices=[ 'enabled', 'disabled', ] ), sessionexchange=dict( type='str', choices=[ 'enabled', 'disabled', ] ), triggermonitor=dict( type='str', choices=[ 'ALWAYS', 'MEPDOWN', 'MEPDOWN_SVCDOWN', ] ), parentsite=dict(type='str'), clip=dict(type='str'), publicclip=dict(type='str'), naptrreplacementsuffix=dict(type='str'), ) hand_inserted_arguments = dict( ) argument_spec = dict() argument_spec.update(netscaler_common_arguments) argument_spec.update(module_specific_arguments) argument_spec.update(hand_inserted_arguments) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, ) module_result = dict( changed=False, failed=False, loglines=loglines, ) # Fail the module if imports failed if not PYTHON_SDK_IMPORTED: module.fail_json(msg='Could not load nitro python sdk') # Fallthrough to rest of execution client = get_nitro_client(module) try: client.login() except nitro_exception as e: msg = "nitro exception during login. errorcode=%s, message=%s" % (str(e.errorcode), e.message) module.fail_json(msg=msg) except Exception as e: if str(type(e)) == "<class 'requests.exceptions.ConnectionError'>": module.fail_json(msg='Connection error %s' % str(e)) elif str(type(e)) == "<class 'requests.exceptions.SSLError'>": module.fail_json(msg='SSL Error %s' % str(e)) else: module.fail_json(msg='Unexpected error during login %s' % str(e)) readwrite_attrs = [ 'sitename', 'sitetype', 'siteipaddress', 'publicip', 'metricexchange', 'nwmetricexchange', 'sessionexchange', 'triggermonitor', 'parentsite', 'clip', 'publicclip', 'naptrreplacementsuffix', ] readonly_attrs = [ 'status', 'persistencemepstatus', 'version', '__count', ] immutable_attrs = [ 'sitename', 'sitetype', 'siteipaddress', 'publicip', 'parentsite', 'clip', 'publicclip', ] transforms = { 'metricexchange': [lambda v: v.upper()], 'nwmetricexchange': [lambda v: v.upper()], 'sessionexchange': [lambda v: v.upper()], } # Instantiate config proxy gslb_site_proxy = ConfigProxy( actual=gslbsite(), client=client, attribute_values_dict=module.params, readwrite_attrs=readwrite_attrs, readonly_attrs=readonly_attrs, immutable_attrs=immutable_attrs, transforms=transforms, ) try: ensure_feature_is_enabled(client, 'GSLB') # Apply appropriate state if module.params['state'] == 'present': log('Applying actions for state present') if not gslb_site_exists(client, module): if not module.check_mode: gslb_site_proxy.add() if module.params['save_config']: client.save_config() module_result['changed'] = True elif not gslb_site_identical(client, module, gslb_site_proxy): # Check if we try to change value of immutable attributes immutables_changed = get_immutables_intersection(gslb_site_proxy, diff_list(client, module, gslb_site_proxy).keys()) if immutables_changed != []: module.fail_json( msg='Cannot update immutable attributes %s' % (immutables_changed,), diff=diff_list(client, module, gslb_site_proxy), **module_result ) if not module.check_mode: gslb_site_proxy.update() if module.params['save_config']: client.save_config() module_result['changed'] = True else: module_result['changed'] = False # Sanity check for state if not module.check_mode: log('Sanity checks for state present') if not gslb_site_exists(client, module): module.fail_json(msg='GSLB site does not exist', **module_result) if not gslb_site_identical(client, module, gslb_site_proxy): module.fail_json(msg='GSLB site differs from configured', diff=diff_list(client, module, gslb_site_proxy), **module_result) elif module.params['state'] == 'absent': log('Applying actions for state absent') if gslb_site_exists(client, module): if not module.check_mode: gslb_site_proxy.delete() if module.params['save_config']: client.save_config() module_result['changed'] = True else: module_result['changed'] = False # Sanity check for state if not module.check_mode: log('Sanity checks for state absent') if gslb_site_exists(client, module): module.fail_json(msg='GSLB site still exists', **module_result) except nitro_exception as e: msg = "nitro exception errorcode=%s, message=%s" % (str(e.errorcode), e.message) module.fail_json(msg=msg, **module_result) client.logout() module.exit_json(**module_result)