def _format_member_address(self, member):
     if is_valid_ip(member):
         address = '/{0}/{1}'.format(self.partition, member)
         return address
     else:
         raise F5ModuleError(
             'The provided member address is not a valid IP address')
Esempio n. 2
0
 def peer_server(self):
     if self._values['peer_server'] is None:
         return None
     if is_valid_ip(self._values['peer_server']):
         return self._values['peer_server']
     raise F5ModuleError(
         "The provided 'peer_server' parameter is not an IP address.")
Esempio n. 3
0
    def update(self):
        self.have = self.read_current_from_device()
        if not self.should_update():
            return False
        if self.want.reverse == 'enabled':
            if not self.want.receive and not self.have.receive:
                raise F5ModuleError(
                    "A 'receive' string must be specified when setting 'reverse'."
                )
            if self.want.time_until_up != 0 and self.have.time_until_up != 0:
                raise F5ModuleError(
                    "Monitors with the 'reverse' attribute are not currently compatible with 'time_until_up'."
                )
        if self._address_type_matches_query_type('a', validate_ip_v6_address):
            raise F5ModuleError(
                "Monitor has a IPv6 address. Only a 'query_type' of 'aaaa' is supported for IPv6."
            )
        elif self._address_type_matches_query_type('aaaa',
                                                   validate_ip_address):
            raise F5ModuleError(
                "Monitor has a IPv4 address. Only a 'query_type' of 'a' is supported for IPv4."
            )

        if self.want.accept_rcode == 'anything':
            if self.want.receive is not None and is_valid_ip(
                    self.want.receive) and self.have.receive is not None:
                raise F5ModuleError(
                    "No 'receive' string may be specified, or exist, when 'accept_rcode' is 'anything'."
                )
            elif self.want.receive is None and self.have.receive is not None:
                self.want.update({'receive': ''})
        if self.module.check_mode:
            return True
        self.update_on_device()
        return True
Esempio n. 4
0
 def remote_host(self):
     if is_valid_ip(self._values['remote_host']):
         return self._values['remote_host']
     elif self.is_valid_hostname(self._values['remote_host']):
         return str(self._values['remote_host'])
     raise F5ModuleError(
         "The provided 'remote_host' is not a valid IP or hostname")
Esempio n. 5
0
    def default_device_reference(self):
        if is_valid_ip(self.service_environment):
            # An IP address was specified
            filter = "address+eq+'{0}'".format(self.service_environment)
        else:
            # Assume a hostname was specified
            filter = "hostname+eq+'{0}'".format(self.service_environment)

        uri = "https://{0}:{1}/mgmt/shared/resolver/device-groups/cm-adccore-allbigipDevices/devices/?$filter={2}&$top=1&$select=selfLink".format(
            self.client.provider['server'],
            self.client.provider['server_port'],
            filter
        )
        resp = self.client.api.get(uri)
        try:
            response = resp.json()
        except ValueError as ex:
            raise F5ModuleError(str(ex))
        if resp.status == 200 and response['totalItems'] == 0:
            return None
        elif 'code' in response and response['code'] == 400:
            if 'message' in response:
                raise F5ModuleError(response['message'])
            else:
                raise F5ModuleError(resp._content)
        result = dict(
            link=response['items'][0]['selfLink']
        )
        return result
Esempio n. 6
0
 def local_ip(self):
     if self._values['local_ip'] in [None, 'none']:
         return None
     if is_valid_ip(self._values['local_ip']):
         return self._values['local_ip']
     else:
         raise F5ModuleError(
             "The provided 'local_ip' is not a valid IP address")
Esempio n. 7
0
 def address(self):
     if self._values['address'] is None:
         return None
     if is_valid_ip(self._values['address']):
         return self._values['address']
     raise F5ModuleError(
         "Specified 'address' is not an IP address."
     )
Esempio n. 8
0
 def _set_host_by_name(self):
     if is_valid_ip(self.want.name):
         self.want.update({'fqdn': None, 'address': self.want.name})
     else:
         if not is_valid_hostname(self.want.name):
             raise F5ModuleError(
                 "'name' is neither a valid IP address or FQDN name.")
         self.want.update({'fqdn': self.want.name, 'address': None})
 def gateway(self):
     if self._values['gateway'] is None:
         return None
     if is_valid_ip(self._values['gateway']):
         return self._values['gateway']
     else:
         raise F5ModuleError(
             "The 'gateway' must an IP address."
         )
 def ip(self):
     if self._values['ip'] is None:
         return None
     elif self._values['ip'] in ['*', '0.0.0.0']:
         return '*'
     elif is_valid_ip(self._values['ip']):
         return self._values['ip']
     raise F5ModuleError(
         "The provided 'ip' parameter is not an IP address.")
Esempio n. 11
0
 def address(self):
     if self._values['address'] is None:
         return None
     elif self._values['address'] == 'any6':
         return 'any6'
     if is_valid_ip(self._values['address']):
         return self._values['address']
     raise F5ModuleError(
         "The specified 'address' value is not a valid IP address.")
 def address(self):
     if self._values['address'] is None:
         return None
     if is_valid_ip(self._values['address']):
         return self._values['address']
     else:
         raise F5ModuleError(
             "The provided 'address' is not a valid IP address"
         )
Esempio n. 13
0
 def receive(self):
     if self._values['receive'] is None:
         return None
     if self._values['receive'] == '':
         return ''
     if is_valid_ip(self._values['receive']):
         return self._values['receive']
     raise F5ModuleError(
         "The specified 'receive' parameter must be either an IPv4 or v6 address."
     )
 def _validate_unicast_failover_address(self, address):
     if address != 'management-ip':
         if is_valid_ip(address):
             return address
         else:
             raise F5ModuleError(
                 "'address' field in unicast failover is not a valid IP address"
             )
     else:
         return address
 def mgmt_route(self):
     if self._values['mgmt_route'] is None:
         return None
     elif self._values['mgmt_route'] == 'none':
         return 'none'
     if is_valid_ip(self._values['mgmt_route']):
         return self._values['mgmt_route']
     else:
         raise F5ModuleError(
             "The specified 'mgmt_route' is not a valid IP address")
 def address(self):
     if self._values['destination'].count(':') >= 2:
         # IPv6
         parts = self._values['destination'].split('.')
     else:
         # IPv4
         parts = self._values['destination'].split(':')
     if is_valid_ip(parts[0]):
         return str(parts[0])
     raise F5ModuleError(
         "'address' parameter from API was not an IP address.")
 def fallback_ip(self):
     if self._values['fallback_ip'] is None:
         return None
     if self._values['fallback_ip'] == 'any':
         return 'any'
     if self._values['fallback_ip'] == 'any6':
         return 'any6'
     if is_valid_ip(self._values['fallback_ip']):
         return self._values['fallback_ip']
     else:
         raise F5ModuleError(
             'The provided fallback address is not a valid IPv4 address')
Esempio n. 18
0
    def source_mask(self):
        if self._values['source_mask'] is None:
            return None
        elif self._values['source_mask'] == 'any':
            return 0
        try:
            int(self._values['source_mask'])
            raise F5ModuleError("'source_mask' must not be in CIDR format.")
        except ValueError:
            pass

        if is_valid_ip(self._values['source_mask']):
            return self._values['source_mask']
Esempio n. 19
0
 def local_host_name(self):
     if self._values['local_host_name'] is None:
         return None
     if is_valid_ip(self._values['local_host_name']):
         return self._values['local_host_name']
     elif is_valid_hostname(self._values['local_host_name']):
         # else fallback to checking reasonably well formatted hostnames
         return str(self._values['local_host_name'])
     raise F5ModuleError(
         "The provided 'local_host_name' value {0} is not a valid IP or hostname".format(
             str(self._values['local_host_name'])
         )
     )
Esempio n. 20
0
    def create(self):
        self._set_changed_options()
        if self.want.reverse == 'enabled':
            if self.want.time_until_up != 0:
                raise F5ModuleError(
                    "Monitors with the 'reverse' attribute are not currently compatible with 'time_until_up'."
                )
            if not self.want.receive:
                raise F5ModuleError(
                    "A 'receive' string must be specified when setting 'reverse'."
                )

        if (self.want.receive is not None
                and validate_ip_v6_address(self.want.receive)
                and self.want.query_type == 'a'):
            raise F5ModuleError(
                "Monitor has a IPv6 address. Only a 'query_type' of 'aaaa' is supported for IPv6."
            )
        elif (self.want.receive is not None
              and validate_ip_address(self.want.receive)
              and self.want.query_type == 'aaaa'):
            raise F5ModuleError(
                "Monitor has a IPv4 address. Only a 'query_type' of 'a' is supported for IPv4."
            )

        if self.want.accept_rcode == 'anything':
            if self.want.receive is not None and is_valid_ip(
                    self.want.receive):
                raise F5ModuleError(
                    "No 'receive' string may be specified, or exist, when 'accept_rcode' is 'anything'."
                )
            elif self.want.receive is None:
                self.want.update({'receive': ''})

        if self.want.query_name is None:
            raise F5ModuleError(
                "'query_name' is required when creating a new DNS monitor.")
        if self.module.check_mode:
            return True
        self.create_on_device()
        return True
Esempio n. 21
0
 def device_is_address(self):
     if is_valid_ip(self.device):
         return True
     return False
 def _get_validated_ip_address(self, address):
     if is_valid_ip(self._values[address]):
         return self._values[address]
     raise F5ModuleError(
         "The specified '{0}' is not a valid IP address".format(address))