本文整理汇总了Python中netaddr.valid_ipv6方法的典型用法代码示例。如果您正苦于以下问题:Python netaddr.valid_ipv6方法的具体用法?Python netaddr.valid_ipv6怎么用?Python netaddr.valid_ipv6使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类netaddr
的用法示例。
在下文中一共展示了netaddr.valid_ipv6方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _ping
# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import valid_ipv6 [as 别名]
def _ping(self):
cmd_ping = 'ping'
if netaddr.valid_ipv6(self.targetip):
cmd_ping = 'ping6'
ping_cmd = [cmd_ping, '-c', self.count,
'-W', self.timeout,
'-i', self.interval,
self.targetip]
try:
# NOTE(gongysh) since it is called in a loop, the debug log
# should be disabled to avoid eating up mistral executor.
linux_utils.execute(ping_cmd, check_exit_code=True,
debuglog=False)
return 'REACHABLE'
except RuntimeError:
LOG.warning(("Cannot ping ip address: %s"), self.targetip)
return 'UNREACHABLE'
示例2: _create_alarm_url
# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import valid_ipv6 [as 别名]
def _create_alarm_url(self, vnf_id, mon_policy_name, mon_policy_action):
# alarm_url = 'http://host:port/v1.0/vnfs/vnf-uuid/monitoring-policy
# -name/action-name?key=8785'
host = cfg.CONF.ceilometer.host
port = cfg.CONF.ceilometer.port
LOG.info("Tacker in heat listening on %(host)s:%(port)s",
{'host': host,
'port': port})
origin = "http://%(host)s:%(port)s/v1.0/vnfs" % {
'host': host, 'port': port}
if netaddr.valid_ipv6(host):
origin = "http://[%(host)s]:%(port)s/v1.0/vnfs" % {
'host': host, 'port': port}
access_key = ''.join(
random.SystemRandom().choice(
string.ascii_lowercase + string.digits)
for _ in range(8))
alarm_url = "".join([origin, '/', vnf_id, '/', mon_policy_name, '/',
mon_policy_action, '/', access_key])
return alarm_url
示例3: get_token_from_zbxserver
# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import valid_ipv6 [as 别名]
def get_token_from_zbxserver(self, node):
temp_auth_api = copy.deepcopy(zapi.dAUTH_API)
temp_auth_api['params']['user'] = \
self.hostinfo[node]['zbx_info']['zabbix_user']
temp_auth_api['params']['password'] = \
self.hostinfo[node]['zbx_info']['zabbix_pass']
zabbixip = \
self.hostinfo[node]['zbx_info']['zabbix_ip']
zabbixport = \
self.hostinfo[node]['zbx_info']['zabbix_port']
self.URL = "http://" + zabbixip + ":" + \
str(zabbixport) + zapi.URL
if netaddr.valid_ipv6(zabbixip):
self.URL = "http://[" + zabbixip + "]:" + \
str(zabbixport) + zapi.URL
response = requests.post(
self.URL,
headers=zapi.HEADERS,
data=jsonutils.dump_as_bytes(temp_auth_api)
)
response_dict = dict(response.json())
VNFMonitorZabbix.check_error(response_dict)
LOG.info('Success Connect Zabbix Server')
return response_dict['result']
示例4: _is_pingable
# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import valid_ipv6 [as 别名]
def _is_pingable(self, mgmt_ip='', retry=5, timeout=5, port=80, **kwargs):
"""Checks whether the server is reachable by using urllib.
Waits for connectivity for `timeout` seconds,
and if connection refused, it will retry `retry`
times.
:param mgmt_ip: IP to check
:param retry: times to reconnect if connection refused
:param timeout: seconds to wait for connection
:param port: port number to check connectivity
:return: bool - True or False depending on pingability.
"""
url = 'http://' + mgmt_ip + ':' + str(port)
if netaddr.valid_ipv6(mgmt_ip):
url = 'http://[' + mgmt_ip + ']:' + str(port)
for retry_index in range(int(retry)):
try:
urlreq.urlopen(url, timeout=timeout)
return True
except urlerr.URLError:
LOG.warning('Unable to reach to the url %s', url)
return 'failure'
示例5: is_valid_ipv6
# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import valid_ipv6 [as 别名]
def is_valid_ipv6(address):
"""Verify that address represents a valid IPv6 address.
:param address: Value to verify
:type address: string
:returns: bool
.. versionadded:: 1.1
"""
if not address:
return False
parts = address.rsplit("%", 1)
address = parts[0]
scope = parts[1] if len(parts) > 1 else None
if scope is not None and (len(scope) < 1 or len(scope) > 15):
return False
try:
return netaddr.valid_ipv6(address, netaddr.core.INET_PTON)
except netaddr.AddrFormatError:
return False
示例6: validate_ip_addr
# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import valid_ipv6 [as 别名]
def validate_ip_addr(ip_addr):
if netaddr.valid_ipv4(ip_addr):
return lib_consts.IP_VERSION_4
elif netaddr.valid_ipv6(ip_addr):
return lib_consts.IP_VERSION_6
else:
raise bgp_driver_exc.InvalidParamType(param=ip_addr,
param_type='ip-address')
示例7: _set_static_network_config_legacy
# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import valid_ipv6 [as 别名]
def _set_static_network_config_legacy(name, address, netmask, gateway,
dnsnameservers):
if netaddr.valid_ipv6(address):
LOG.warning("Setting IPv6 info not available on this system")
return
adapter_config = WindowsUtils._get_network_adapter(name).associators(
wmi_result_class='Win32_NetworkAdapterConfiguration')[0]
LOG.debug("Setting static IP address")
(ret_val,) = adapter_config.EnableStatic([address], [netmask])
if ret_val > 1:
raise exception.CloudbaseInitException(
"Cannot set static IP address on network adapter: %d" %
ret_val)
reboot_required = (ret_val == 1)
if gateway:
LOG.debug("Setting static gateways")
(ret_val,) = adapter_config.SetGateways([gateway], [1])
if ret_val > 1:
raise exception.CloudbaseInitException(
"Cannot set gateway on network adapter: %d" % ret_val)
reboot_required = reboot_required or ret_val == 1
if dnsnameservers:
LOG.debug("Setting static DNS servers")
(ret_val,) = adapter_config.SetDNSServerSearchOrder(dnsnameservers)
if ret_val > 1:
raise exception.CloudbaseInitException(
"Cannot set DNS on network adapter: %d" % ret_val)
reboot_required = reboot_required or ret_val == 1
return reboot_required
示例8: _set_static_network_config
# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import valid_ipv6 [as 别名]
def _set_static_network_config(name, address, prefix_len, gateway):
if netaddr.valid_ipv6(address):
family = AF_INET6
else:
family = AF_INET
# This is needed to avoid the error:
# "Inconsistent parameters PolicyStore PersistentStore and
# Dhcp Enabled"
WindowsUtils._fix_network_adapter_dhcp(name, False, family)
conn = wmi.WMI(moniker='//./root/standardcimv2')
existing_addresses = conn.MSFT_NetIPAddress(
AddressFamily=family, InterfaceAlias=name)
for existing_address in existing_addresses:
LOG.debug(
"Removing existing IP address \"%(ip)s\" "
"from adapter \"%(name)s\"",
{"ip": existing_address.IPAddress, "name": name})
existing_address.Delete_()
existing_routes = conn.MSFT_NetRoute(
AddressFamily=family, InterfaceAlias=name)
for existing_route in existing_routes:
LOG.debug(
"Removing existing route \"%(route)s\" "
"from adapter \"%(name)s\"",
{"route": existing_route.DestinationPrefix, "name": name})
existing_route.Delete_()
conn.MSFT_NetIPAddress.create(
AddressFamily=family, InterfaceAlias=name, IPAddress=address,
PrefixLength=prefix_len, DefaultGateway=gateway)
示例9: _get_default_dns_nameservers
# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import valid_ipv6 [as 别名]
def _get_default_dns_nameservers(network_details):
ipv4_nameservers = []
ipv6_nameservers = []
for s in network_details.services:
if isinstance(s, network_model.NameServerService):
for nameserver in s.addresses:
if netaddr.valid_ipv6(nameserver):
ipv6_nameservers.append(nameserver)
else:
ipv4_nameservers.append(nameserver)
return (ipv4_nameservers, ipv6_nameservers)
示例10: _process_networks
# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import valid_ipv6 [as 别名]
def _process_networks(osutils, network_details):
reboot_required = False
ipv4_ns, ipv6_ns = NetworkConfigPlugin._get_default_dns_nameservers(
network_details)
for net in network_details.networks:
ip_address, prefix_len = net.address_cidr.split("/")
gateway = None
default_gw_route = [
r for r in net.routes if
netaddr.IPNetwork(r.network_cidr).prefixlen == 0]
if default_gw_route:
gateway = default_gw_route[0].gateway
nameservers = net.dns_nameservers
if not nameservers:
if netaddr.valid_ipv6(ip_address):
nameservers = ipv6_ns
else:
nameservers = ipv4_ns
LOG.info(
"Setting static IP configuration on network adapter "
"\"%(name)s\". IP: %(ip)s, prefix length: %(prefix_len)s, "
"gateway: %(gateway)s, dns: %(dns)s",
{"name": net.link, "ip": ip_address, "prefix_len": prefix_len,
"gateway": gateway, "dns": nameservers})
reboot = osutils.set_static_network_config(
net.link, ip_address, prefix_len, gateway, nameservers)
reboot_required = reboot or reboot_required
return reboot_required
示例11: valid_ip_address
# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import valid_ipv6 [as 别名]
def valid_ip_address(addr):
if not netaddr.valid_ipv4(addr) and not netaddr.valid_ipv6(addr):
return False
return True
示例12: _check_rf_and_normalize
# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import valid_ipv6 [as 别名]
def _check_rf_and_normalize(prefix):
""" check prefix's route_family and if the address is
IPv6 address, return IPv6 route_family and normalized IPv6 address.
If the address is IPv4 address, return IPv4 route_family
and the prefix itself.
"""
ip, masklen = prefix.split('/')
if netaddr.valid_ipv6(ip):
# normalize IPv6 address
ipv6_prefix = str(netaddr.IPAddress(ip)) + '/' + masklen
return vrfs.VRF_RF_IPV6, ipv6_prefix
else:
return vrfs.VRF_RF_IPV4, prefix
示例13: is_valid_ip
# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import valid_ipv6 [as 别名]
def is_valid_ip(ip):
"""Return True if the IP is either v4 or v6
Return False if invalid.
"""
return netaddr.valid_ipv4(ip) or netaddr.valid_ipv6(ip)
示例14: _is_pingable
# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import valid_ipv6 [as 别名]
def _is_pingable(self, mgmt_ip="", count=None, timeout=None,
interval=None, retry=None, **kwargs):
"""Checks whether an IP address is reachable by pinging.
Use linux utils to execute the ping (ICMP ECHO) command.
Sends 5 packets with an interval of 1 seconds and timeout of 1
seconds. Runtime error implies unreachability else IP is pingable.
:param ip: IP to check
:return: bool - True or string 'failure' depending on pingability.
"""
cmd_ping = 'ping'
if netaddr.valid_ipv6(mgmt_ip):
cmd_ping = 'ping6'
if not count:
count = cfg.CONF.monitor_ping.count
if not timeout:
timeout = cfg.CONF.monitor_ping.timeout
if not interval:
interval = cfg.CONF.monitor_ping.interval
if not retry:
retry = cfg.CONF.monitor_ping.retry
ping_cmd = [cmd_ping,
'-c', count,
'-W', timeout,
'-i', interval,
mgmt_ip]
for retry_range in range(int(retry)):
try:
linux_utils.execute(ping_cmd, check_exit_code=True)
return True
except RuntimeError:
LOG.warning("Cannot ping ip address: %s", mgmt_ip)
return 'failure'
示例15: is_ip
# 需要导入模块: import netaddr [as 别名]
# 或者: from netaddr import valid_ipv6 [as 别名]
def is_ip(string):
try:
if netaddr.valid_ipv4(string):
return True
if netaddr.valid_ipv6(string):
return True
return False
except:
traceback.print_exc()
return False