def create_from_template_on_device(self): full_name = fqdn_name(self.want.partition, self.want.name) cmd = 'tmsh create asm policy {0} policy-template {1}'.format(full_name, self.want.template) self.client.api.tm.util.bash.exec_cmd( 'run', utilCmdArgs='-c "{0}"'.format(cmd) )
def create_from_template_on_device(self): full_name = fqdn_name(self.want.partition, self.want.name) cmd = 'tmsh create asm policy {0} policy-template {1}'.format(full_name, self.want.template) self.client.api.tm.util.bash.exec_cmd( 'run', utilCmdArgs='-c "{0}"'.format(cmd) )
def import_to_device(self): self.client.api.shared.file_transfer.uploads.upload_file(self.want.file) time.sleep(2) name = os.path.split(self.want.file)[1] full_name = fqdn_name(self.want.partition, self.want.name) cmd = 'tmsh load asm policy {0} file /var/config/rest/downloads/{1}'.format(full_name, name) self.client.api.tm.util.bash.exec_cmd( 'run', utilCmdArgs='-c "{0}"'.format(cmd) ) return True
def import_to_device(self): self.client.api.shared.file_transfer.uploads.upload_file( self.want.file) time.sleep(2) name = os.path.split(self.want.file)[1] full_name = fqdn_name(self.want.partition, self.want.name) cmd = 'tmsh load asm policy {0} file /var/config/rest/downloads/{1}'.format( full_name, name) self.client.api.tm.util.bash.exec_cmd( 'run', utilCmdArgs='-c "{0}"'.format(cmd)) return True
def pools(self): result = [] if self._values['pools'] is None: return None for item in self._values['pools']: pool = dict() if 'ratio' in item: pool['ratio'] = item['ratio'] pool['name'] = fqdn_name(self.partition, item['name']) result.append(pool) return result
def full_path(self): return fqdn_name(self.name)
def main(): result = {} argument_spec = f5_argument_spec meta_args = dict( session_state=dict(type='str', choices=['enabled', 'disabled']), monitor_state=dict(type='str', choices=['enabled', 'disabled']), pool=dict(type='str', required=True), host=dict(type='str', required=True, aliases=['address', 'name']), port=dict(type='int', required=True), connection_limit=dict(type='int'), description=dict(type='str'), rate_limit=dict(type='int'), ratio=dict(type='int'), preserve_node=dict(type='bool', default=False), priority_group=dict(type='int'), state=dict(default='present', choices=['absent', 'present']), partition=dict( default='Common', fallback=(env_fallback, ['F5_PARTITION']) ) ) argument_spec.update(meta_args) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True ) if not bigsuds_found: module.fail_json(msg="the python bigsuds module is required") if module.params['validate_certs']: import ssl if not hasattr(ssl, 'SSLContext'): module.fail_json( msg='bigsuds does not support verifying certificates with python < 2.7.9. ' 'Either update python or set validate_certs=False on the task') server = module.params['server'] server_port = module.params['server_port'] user = module.params['user'] password = module.params['password'] state = module.params['state'] partition = module.params['partition'] validate_certs = module.params['validate_certs'] session_state = module.params['session_state'] monitor_state = module.params['monitor_state'] pool = fqdn_name(partition, module.params['pool']) connection_limit = module.params['connection_limit'] description = module.params['description'] rate_limit = module.params['rate_limit'] ratio = module.params['ratio'] priority_group = module.params['priority_group'] host = module.params['host'] address = fqdn_name(partition, host) port = module.params['port'] preserve_node = module.params['preserve_node'] if (host and port is None) or (port is not None and not host): module.fail_json(msg="both host and port must be supplied") if 0 > port or port > 65535: module.fail_json(msg="valid ports must be in range 0 - 65535") try: api = bigip_api(server, user, password, validate_certs, port=server_port) if not pool_exists(api, pool): module.fail_json(msg="pool %s does not exist" % pool) result = {'changed': False} # default if state == 'absent': if member_exists(api, pool, address, port): if not module.check_mode: remove_pool_member(api, pool, address, port) if preserve_node: result = {'changed': True} else: deleted = delete_node_address(api, address) result = {'changed': True, 'deleted': deleted} else: result = {'changed': True} elif state == 'present': if not member_exists(api, pool, address, port): if not module.check_mode: add_pool_member(api, pool, address, port) if connection_limit is not None: set_connection_limit(api, pool, address, port, connection_limit) if description is not None: set_description(api, pool, address, port, description) if rate_limit is not None: set_rate_limit(api, pool, address, port, rate_limit) if ratio is not None: set_ratio(api, pool, address, port, ratio) if session_state is not None: set_member_session_enabled_state(api, pool, address, port, session_state) if monitor_state is not None: set_member_monitor_state(api, pool, address, port, monitor_state) if priority_group is not None: set_priority_group(api, pool, address, port, priority_group) result = {'changed': True} else: # pool member exists -- potentially modify attributes if connection_limit is not None and connection_limit != get_connection_limit(api, pool, address, port): if not module.check_mode: set_connection_limit(api, pool, address, port, connection_limit) result = {'changed': True} if description is not None and description != get_description(api, pool, address, port): if not module.check_mode: set_description(api, pool, address, port, description) result = {'changed': True} if rate_limit is not None and rate_limit != get_rate_limit(api, pool, address, port): if not module.check_mode: set_rate_limit(api, pool, address, port, rate_limit) result = {'changed': True} if ratio is not None and ratio != get_ratio(api, pool, address, port): if not module.check_mode: set_ratio(api, pool, address, port, ratio) result = {'changed': True} if session_state is not None: session_status = get_member_session_status(api, pool, address, port) if session_state == 'enabled' and session_status == 'forced_disabled': if not module.check_mode: set_member_session_enabled_state(api, pool, address, port, session_state) result = {'changed': True} elif session_state == 'disabled' and session_status != 'forced_disabled': if not module.check_mode: set_member_session_enabled_state(api, pool, address, port, session_state) result = {'changed': True} if monitor_state is not None: monitor_status = get_member_monitor_status(api, pool, address, port) if monitor_state == 'enabled' and monitor_status == 'forced_down': if not module.check_mode: set_member_monitor_state(api, pool, address, port, monitor_state) result = {'changed': True} elif monitor_state == 'disabled' and monitor_status != 'forced_down': if not module.check_mode: set_member_monitor_state(api, pool, address, port, monitor_state) result = {'changed': True} if priority_group is not None and priority_group != get_priority_group(api, pool, address, port): if not module.check_mode: set_priority_group(api, pool, address, port, priority_group) result = {'changed': True} except Exception as e: module.fail_json(msg="received exception: %s" % e) module.exit_json(**result)
def pool(self): return fqdn_name(self.want.partition, self._values['pool'])
def full_path(self): return fqdn_name(self.name)
def vlan(self): if self._values['vlan'] is None: return None return fqdn_name(self.partition, self._values['vlan'])