Dre4m Shell
Server IP : 85.214.239.14  /  Your IP : 3.147.77.51
Web Server : Apache/2.4.62 (Debian)
System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.18
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /lib/python3/dist-packages/ansible_collections/community/network/plugins/modules/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /lib/python3/dist-packages/ansible_collections/community/network/plugins/modules/dladm_etherstub.py
#!/usr/bin/python
# -*- coding: utf-8 -*-

# (c) 2015, Adam Števko <adam.stevko@gmail.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
__metaclass__ = type


DOCUMENTATION = '''
---
module: dladm_etherstub
short_description: Manage etherstubs on Solaris/illumos systems.
description:
    - Create or delete etherstubs on Solaris/illumos systems.
author: Adam Števko (@xen0l)
options:
    name:
        description:
            - Etherstub name.
        required: true
    temporary:
        description:
            - Specifies that the etherstub is temporary. Temporary etherstubs
              do not persist across reboots.
        required: false
        default: false
        type: bool
    state:
        description:
            - Create or delete Solaris/illumos etherstub.
        required: false
        default: "present"
        choices: [ "present", "absent" ]
'''

EXAMPLES = '''
- name: Create 'stub0' etherstub
  community.network.dladm_etherstub:
    name: stub0
    state: present

- name: Remove 'stub0 etherstub
  community.network.dladm_etherstub:
    name: stub0
    state: absent
'''

RETURN = '''
name:
    description: etherstub name
    returned: always
    type: str
    sample: "switch0"
state:
    description: state of the target
    returned: always
    type: str
    sample: "present"
temporary:
    description: etherstub's persistence
    returned: always
    type: bool
    sample: "True"
'''
from ansible.module_utils.basic import AnsibleModule


class Etherstub(object):

    def __init__(self, module):
        self.module = module

        self.name = module.params['name']
        self.temporary = module.params['temporary']
        self.state = module.params['state']

    def etherstub_exists(self):
        cmd = [self.module.get_bin_path('dladm', True)]

        cmd.append('show-etherstub')
        cmd.append(self.name)

        (rc, dummy, dummy) = self.module.run_command(cmd)

        if rc == 0:
            return True
        else:
            return False

    def create_etherstub(self):
        cmd = [self.module.get_bin_path('dladm', True)]

        cmd.append('create-etherstub')

        if self.temporary:
            cmd.append('-t')
        cmd.append(self.name)

        return self.module.run_command(cmd)

    def delete_etherstub(self):
        cmd = [self.module.get_bin_path('dladm', True)]

        cmd.append('delete-etherstub')

        if self.temporary:
            cmd.append('-t')
        cmd.append(self.name)

        return self.module.run_command(cmd)


def main():
    module = AnsibleModule(
        argument_spec=dict(
            name=dict(required=True),
            temporary=dict(default=False, type='bool'),
            state=dict(default='present', choices=['absent', 'present']),
        ),
        supports_check_mode=True
    )

    etherstub = Etherstub(module)

    rc = None
    out = ''
    err = ''
    result = {}
    result['name'] = etherstub.name
    result['state'] = etherstub.state
    result['temporary'] = etherstub.temporary

    if etherstub.state == 'absent':
        if etherstub.etherstub_exists():
            if module.check_mode:
                module.exit_json(changed=True)
            (rc, out, err) = etherstub.delete_etherstub()
            if rc != 0:
                module.fail_json(name=etherstub.name, msg=err, rc=rc)
    elif etherstub.state == 'present':
        if not etherstub.etherstub_exists():
            if module.check_mode:
                module.exit_json(changed=True)
            (rc, out, err) = etherstub.create_etherstub()

        if rc is not None and rc != 0:
            module.fail_json(name=etherstub.name, msg=err, rc=rc)

    if rc is None:
        result['changed'] = False
    else:
        result['changed'] = True

    if out:
        result['stdout'] = out
    if err:
        result['stderr'] = err

    module.exit_json(**result)


if __name__ == '__main__':
    main()

Anon7 - 2022
AnonSec Team