Exemple #1
0
def map_params_to_obj(module, required_if=None):
    obj = []
    addr6 = False
    aggregate = module.params.get('aggregate')

    if aggregate:
        for item in aggregate:
            if item['name'] is not None and validate_ip_v6_address(
                    item['name']):
                addr6 = True
            for key in item:
                if item.get(key) is None:
                    item[key] = module.params[key]

            check_required_if(module, required_if, item)
            item.update({'addr6': addr6})

            d = item.copy()
            d['level'] = set(d['level']) if d['level'] is not None else None
            if d['dest'] != 'host':
                d['name'] = None
                d['udp_port'] = None

            if d['dest'] != 'buffered':
                d['level'] = None
            del d['check_running_config']
            obj.append(d)

    else:
        if module.params['name'] is not None and validate_ip_v6_address(
                module.params['name']):
            addr6 = True
        if module.params['dest'] != 'host':
            module.params['name'] = None
            module.params['udp_port'] = None

        if module.params['dest'] != 'buffered':
            module.params['level'] = None

        obj.append({
            'dest':
            module.params['dest'],
            'name':
            module.params['name'],
            'udp_port':
            module.params['udp_port'],
            'level':
            set(module.params['level']) if module.params['level'] else None,
            'facility':
            module.params['facility'],
            'state':
            module.params['state'],
            'addr6':
            addr6
        })
    return obj
Exemple #2
0
def is_valid_ip(addr, type='all'):
    if type in ['all', 'ipv4']:
        if validate_ip_address(addr):
            return True
    if type in ['all', 'ipv6']:
        if validate_ip_v6_address(addr):
            return True
    return False
def validate_ip_addr_type(ip, arg_spec, module):
    '''This function will check if the argument ip is type v4/v6 and return appropriate infoblox network type
    '''
    check_ip = ip.split('/')

    if validate_ip_address(check_ip[0]) and 'ipaddr' in arg_spec:
        arg_spec['ipv4addr'] = arg_spec.pop('ipaddr')
        module.params['ipv4addr'] = module.params.pop('ipaddr')
        return NIOS_IPV4_FIXED_ADDRESS, arg_spec, module
    elif validate_ip_v6_address(check_ip[0]) and 'ipaddr' in arg_spec:
        arg_spec['ipv6addr'] = arg_spec.pop('ipaddr')
        module.params['ipv6addr'] = module.params.pop('ipaddr')
        return NIOS_IPV6_FIXED_ADDRESS, arg_spec, module
Exemple #4
0
    def __init__(self, argument_spec):
        self.spec = argument_spec
        self.module = None
        self.init_module()

        # file copy parameters
        self.local_file = self.module.params['local_file']
        self.remote_file = self.module.params['remote_file']
        self.file_system = self.module.params['file_system']
        self.host_is_ipv6 = validate_ip_v6_address(
            self.module.params['provider']['host'])

        # state
        self.transfer_result = None
        self.changed = False
Exemple #5
0
def check_ip_addr_type(obj_filter, ib_spec):
    '''This function will check if the argument ip is type v4/v6 and return appropriate infoblox
       network/networkcontainer type
    '''

    ip = obj_filter['network']
    if 'container' in obj_filter and obj_filter['container']:
        check_ip = ip.split('/')
        del ib_spec[
            'container']  # removing the container key from post arguments
        del ib_spec[
            'options']  # removing option argument as for network container it's not supported
        if validate_ip_address(check_ip[0]):
            return NIOS_IPV4_NETWORK_CONTAINER, ib_spec
        elif validate_ip_v6_address(check_ip[0]):
            return NIOS_IPV6_NETWORK_CONTAINER, ib_spec
    else:
        check_ip = ip.split('/')
        del ib_spec[
            'container']  # removing the container key from post arguments
        if validate_ip_address(check_ip[0]):
            return NIOS_IPV4_NETWORK, ib_spec
        elif validate_ip_v6_address(check_ip[0]):
            return NIOS_IPV6_NETWORK, ib_spec
Exemple #6
0
 def _get_rdns(self):
     ip_address = self.module.params.get("ip_address")
     if utils.validate_ip_address(ip_address):
         if self.hcloud_server.public_net.ipv4.ip == ip_address:
             self.hcloud_rdns = {
                 "ip_address": self.hcloud_server.public_net.ipv4.ip,
                 "dns_ptr": self.hcloud_server.public_net.ipv4.dns_ptr,
             }
         else:
             self.module.fail_json(
                 msg="The selected server does not have this IP address")
     elif utils.validate_ip_v6_address(ip_address):
         for ipv6_address_dns_ptr in self.hcloud_server.public_net.ipv6.dns_ptr:
             if ipv6_address_dns_ptr["ip"] == ip_address:
                 self.hcloud_rdns = {
                     "ip_address": ipv6_address_dns_ptr["ip"],
                     "dns_ptr": ipv6_address_dns_ptr["dns_ptr"],
                 }
     else:
         self.module.fail_json(msg="The given IP address is not valid")
Exemple #7
0
def map_obj_to_commands(updates):
    dest_group = ('host', 'console', 'persistence', 'enable')
    commands = list()
    want, have = updates

    for w in want:
        dest = w['dest']
        name = w['name']
        level = w['level']
        state = w['state']
        udp_port = w['udp_port']
        facility = w['facility']
        del w['state']
        del w['facility']

        facility_name = ''
        facility_level = ''
        if name is not None and validate_ip_v6_address(name):
            name = 'ipv6 ' + name

        if facility:
            for item in have:
                if item['dest'] == 'facility':
                    facility_name = item['dest']
                    facility_level = item['facility']

        if state == 'absent':
            if have == []:
                if facility:
                    commands.append('no logging facility')

                if dest == 'buffered':
                    for item in have:
                        if item['dest'] == 'buffered':
                            want_level = level
                            have_level = item['level']
                            for item in want_level:
                                commands.append(
                                    'no logging buffered {0}'.format(item))

                if dest == 'host':
                    if name and udp_port:
                        commands.append(
                            'no logging host {0} udp-port {1}'.format(
                                name, udp_port))
                    elif name:
                        commands.append('no logging host {0}'.format(name))
                else:
                    if dest == 'rfc5424':
                        commands.append('no logging enable {0}'.format(dest))
                    else:
                        if dest != 'buffered':
                            commands.append('no logging {0}'.format(dest))

            if facility:
                if facility_name == 'facility' and facility_level != 'user':
                    commands.append('no logging facility')

            if dest == 'buffered':
                for item in have:
                    if item['dest'] == 'buffered':
                        want_level = level
                        have_level = item['level']
                        for item in want_level:
                            if item in have_level:
                                commands.append(
                                    'no logging buffered {0}'.format(item))

            if w in have:
                if dest == 'host':
                    if name and udp_port:
                        commands.append(
                            'no logging host {0} udp-port {1}'.format(
                                name, udp_port))
                    elif name:
                        commands.append('no logging host {0}'.format(name))
                else:
                    if dest == 'rfc5424':
                        commands.append('no logging enable {0}'.format(dest))
                    else:
                        if dest != 'buffered':
                            commands.append('no logging {0}'.format(dest))

        if state == 'present':
            if facility:
                if facility != facility_level:
                    commands.append('logging facility {0}'.format(facility))
            if w not in have:
                if dest == 'host':
                    if name and udp_port:
                        commands.append('logging host {0} udp-port {1}'.format(
                            name, udp_port))
                    elif name:
                        commands.append('logging host {0}'.format(name))
                elif dest == 'buffered':
                    adds, removes = diff_in_list(want, have)
                    for item in adds:
                        commands.append('logging buffered {0}'.format(item))
                    for item in removes:
                        commands.append('no logging buffered {0}'.format(item))
                elif dest == 'rfc5424':
                    commands.append('logging enable {0}'.format(dest))
                else:
                    commands.append('logging {0}'.format(dest))

    return commands