def _install(self): """Upload the key on the BIG-IP system.""" name = self._params['name'] param_set = {} if self._params['fromEditor']: param_set = {'from-editor': self._params['fromEditor']} if self._params['fromLocalFile']: param_set = {'from-local-file': self._params['fromLocalFile']} if self._params['fromUrl']: param_set = {'from-url': self._params['fromUrl']} if param_set: param_set.update({'name': name}) if self._params['consumer']: param_set.update({'consumer': self._params['consumer']}) if self._params['noOverwrite']: param_set.update({'no-overwrite': self._params['noOverwrite']}) # Install the key self._methods['exec_cmd']('install', **param_set) else: raise AnsibleF5Error("Missing required parameter 'from-*' to install the cert.") # Make sure it is installed if not self._exists(): raise AnsibleF5Error("Failed to create the object.") return True
def source_address_translation(self): if self._params['sourceAddressTranslation']: if self._params['sourceAddressTranslation'][ 'type'] == 'automap' and 'pool' in self._params[ 'sourceAddressTranslation']: raise AnsibleF5Error( "Cannot specify a pool when using automap.") else: return None
def flush(self): result = dict(changed=False) try: license = self._methods['read']() except Exception: raise AnsibleF5Error("Unable to retrieve licensing information.") result.update(status=license.status) return result
def flush(self): result = dict(changed=False, stdout=list()) try: output = self._methods['run']('run', utilCmdArgs=self._params['cipherString']) # result['changed'] = True except Exception: raise AnsibleF5Error("Could not execute the Client SSL Ciphers command.") if hasattr(output, 'commandResult'): result['stdout'].append(str(output.commandResult)) result['stdout_lines'] = list(to_lines(result['stdout'])) return result
def flush(self): result = dict(changed=False) if self._check_mode: result['changed'] = True return result try: self._methods['download_file'](self._params['fileName'], self._params['downloadPath']) result['changed'] = True except Exception: raise AnsibleF5Error("Cannot download the file.") return result
def flush(self): result = dict(changed=False, stdout=list()) try: stats = self._read() except Exception: raise AnsibleF5Error("Unable to retrieve stats.") if hasattr(stats, 'apiRawValues'): result['stdout'].append(stats.apiRawValues['apiAnonymous']) result['stdout_lines'] = list(to_lines(result['stdout'])) return result
def flush(self): result = dict(changed=False, stdout=list()) try: output = self._methods['list']('run', utilCmdArgs=self._params['path']) # result['changed'] = True except Exception as exc: err_msg = 'Cannot show the contents of this folder.' err_msg += ' The error message was "{0}".'.format(str(exc)) raise AnsibleF5Error(err_msg) if hasattr(output, 'commandResult'): result['stdout'].append(str(output.commandResult)) result['stdout_lines'] = list(to_lines(result['stdout'])) return result
def flush(self): result = dict(changed=False) try: failover_status = self._methods['read'] failover_status.refresh() failover_status_stats = \ failover_status.entries['https://localhost/mgmt/tm/cm/failover-status/0']['nestedStats']['entries'] except Exception: raise AnsibleF5Error( "Unable to retrieve the failover status of the device.") result.update(color=failover_status_stats['color']['description'], status=failover_status_stats['status']['description'], summary=failover_status_stats['summary']['description']) return result
def flush(self): result = dict(changed=False) try: failover_state = self._methods['read']() except Exception: raise AnsibleF5Error( "Cannot retrieve BIG-IP failover state information.") result.update( failover_state=failover_state.failoverState, is_enabled=failover_state.isEnabled, last_update_micros=failover_state.lastUpdateMicros, next_poll_time=failover_state.nextPollTime, poll_cycle_period_millis=failover_state.pollCyclePeriodMillis) return result
def flush(self): result = dict(changed=False) try: version = self._methods['read']() version_stats = version.entries[ 'https://localhost/mgmt/tm/sys/version/0']['nestedStats'][ 'entries'] except Exception: raise AnsibleF5Error("Cannot display the version information.") result.update(build=version_stats['Build']['description'], date=version_stats['Date']['description'], edition=version_stats['Edition']['description'], product=version_stats['Product']['description'], title=version_stats['Title']['description'], version=version_stats['Version']['description']) return result
def flush(self): result = dict(changed=False) if self._check_mode: result['changed'] = True return result try: if self._params['filepathname']: self._methods['upload_file'](self._params['filepathname']) elif self._params['stringio']: self._methods['upload_stringio'](self._params['stringio']) elif self._params['bytestring']: self._methods['upload_bytes'](self._params['bytestring']) result['changed'] = True except Exception: AnsibleF5Error("Cannot upload the file.") return result
def flush(self): result = dict(changed=False) command = self._params.pop('command', None) # Remove empty params params = dict( (k, v) for k, v in iteritems(self._params) if v is not None) if self._check_mode: result['changed'] = True return result try: self._methods['exec_cmd'](command, **params) result['changed'] = True except Exception as exc: raise AnsibleF5Error("Could not execute '" + command + "' command: " + exc.message) return result
def mgmt_root(self): err = None retries = self.provider.get('f5_retries', 3) timeout = self.provider.get('f5_timeout', 10) for x in range(retries): try: return BigIqMgmtRoot(self.provider['f5_hostname'], self.provider['f5_username'], self.provider['f5_password'], port=self.provider['f5_port'], verify=self.provider['f5_verify']) except Exception as exc: err = exc time.sleep(timeout) err_msg = 'Unable to connect to host {0} on port {1}.'.format( self.provider['f5_hostname'], self.provider['f5_port']) if err is not None: err_msg += ' The error message was "{0}".'.format(str(err)) raise AnsibleF5Error(err_msg)
def flush(self): result = dict(changed=False, stdout=list()) if self._check_mode: result['changed'] = True return result try: output = self._methods['run']('run', utilCmdArgs=self._params['cmdArgs']) result['changed'] = True except Exception as exc: err_msg = 'Could not execute the Bash command.' err_msg += ' The error message was "{0}".'.format(str(exc)) raise AnsibleF5Error(err_msg) if hasattr(output, 'commandResult'): result['stdout'].append(str(output.commandResult)) result['stdout_lines'] = list(to_lines(result['stdout'])) return result
def flush(self): result = dict(changed=False, stdout=list()) if self._check_mode: result['changed'] = True return result try: output = self._methods['run']('run', utilCmdArgs='{0}'.format(' '.join( str(a) for a in self._params.values()))) result['changed'] = True except Exception as exc: err_msg = 'Cannot generate the Qkview file.' err_msg += ' The error message was "{0}".'.format(str(exc)) raise AnsibleF5Error(err_msg) if hasattr(output, 'commandResult'): result['stdout'].append(str(output.commandResult)) result['stdout_lines'] = list(to_lines(result['stdout'])) return result
def flush(self): result = dict(changed=False, stdout=list()) if self._check_mode: result['changed'] = True return result try: output = self._methods['run']('run', utilCmdArgs='{0}/{2} {1}/{2}'.format( self._params['sourcePath'], self._params['destPath'], self._params['fileName'])) result['changed'] = True except Exception as exc: err_msg = 'Cannot move the file.' err_msg += ' The error message was "{0}".'.format(str(exc)) raise AnsibleF5Error(err_msg) if hasattr(output, 'commandResult'): result['stdout'].append(str(output.commandResult)) result['stdout_lines'] = list(to_lines(result['stdout'])) return result
def __init__(self, **kwargs): if not HAS_F5SDK: raise AnsibleF5Error( "The python f5-sdk module is required. Try 'pip install f5-sdk'." ) self.provider = kwargs.get('provider', None)
def _update(self): raise AnsibleF5Error("%s does not support update" % self.__class__.__name__)