charmhelpers.contrib.network package¶
charmhelpers.contrib.network.ip module¶
-
charmhelpers.contrib.network.ip.
assert_charm_supports_ipv6
()¶ Check whether we are able to support charms ipv6.
-
charmhelpers.contrib.network.ip.
format_ipv6_addr
(address)¶ If address is IPv6, wrap it in ‘[]’ otherwise return None.
This is required by most configuration files when specifying IPv6 addresses.
-
charmhelpers.contrib.network.ip.
get_address_in_network
(network, fallback=None, fatal=False)¶ Get an IPv4 or IPv6 address within the network from the host.
Parameters: - (str) (fallback) – CIDR presentation format. For example, ‘192.168.1.0/24’. Supports multiple networks as a space-delimited list.
- (str) – If no address is found, return fallback.
- (boolean) (fatal) – If no address is found, fallback is not set and fatal is True then exit(1).
-
charmhelpers.contrib.network.ip.
get_bridge_nics
(bridge, vnic_dir='/sys/devices/virtual/net')¶ Return a list of nics comprising a given bridge on the system.
-
charmhelpers.contrib.network.ip.
get_bridges
(vnic_dir='/sys/devices/virtual/net')¶ Return a list of bridges on the system.
-
charmhelpers.contrib.network.ip.
get_host_ip
(hostname, fallback=None)¶ Resolves the IP for a given hostname, or returns the input if it is already an IP.
-
charmhelpers.contrib.network.ip.
get_hostname
(address, fqdn=True)¶ Resolves hostname for given IP, or returns the input if it is already a hostname.
-
charmhelpers.contrib.network.ip.
get_iface_addr
(iface='eth0', inet_type='AF_INET', inc_aliases=False, fatal=True, exc_list=None)¶ Return the assigned IP address for a given interface, if any.
Parameters: - iface – network interface on which address(es) are expected to be found.
- inet_type – inet address family
- inc_aliases – include alias interfaces in search
- fatal – if True, raise exception if address not found
- exc_list – list of addresses to ignore
Returns: list of ip addresses
-
charmhelpers.contrib.network.ip.
get_iface_for_address
(address, *, key='iface')¶ Retrieve an attribute of or the physical interface that the IP address provided could be bound to.
Parameters: - (str) (address) – An individual IPv4 or IPv6 address without a net mask or subnet prefix. For example, ‘192.168.1.1’.
- key – ‘iface’ for the physical interface name or an attribute of the configured interface, for example ‘netmask’.
Returns str: Requested attribute or None if address is not bindable.
-
charmhelpers.contrib.network.ip.
get_iface_from_addr
(addr)¶ Work out on which interface the provided address is configured.
-
charmhelpers.contrib.network.ip.
get_ipv4_addr
(iface='eth0', *, inet_type='AF_INET', inc_aliases=False, fatal=True, exc_list=None)¶ Return the assigned IP address for a given interface, if any.
Parameters: - iface – network interface on which address(es) are expected to be found.
- inet_type – inet address family
- inc_aliases – include alias interfaces in search
- fatal – if True, raise exception if address not found
- exc_list – list of addresses to ignore
Returns: list of ip addresses
-
charmhelpers.contrib.network.ip.
get_ipv6_addr
(*args, **kwargs)¶
-
charmhelpers.contrib.network.ip.
get_netmask_for_address
(address, *, key='netmask')¶ Retrieve an attribute of or the physical interface that the IP address provided could be bound to.
Parameters: - (str) (address) – An individual IPv4 or IPv6 address without a net mask or subnet prefix. For example, ‘192.168.1.1’.
- key – ‘iface’ for the physical interface name or an attribute of the configured interface, for example ‘netmask’.
Returns str: Requested attribute or None if address is not bindable.
-
charmhelpers.contrib.network.ip.
get_relation_ip
(interface, cidr_network=None)¶ Return this unit’s IP for the given interface.
Allow for an arbitrary interface to use with network-get to select an IP. Handle all address selection options including passed cidr network and IPv6.
Usage: get_relation_ip(‘amqp’, cidr_network=‘10.0.0.0/8’)
@param interface: string name of the relation. @param cidr_network: string CIDR Network to select an address from. @raises Exception if prefer-ipv6 is configured but IPv6 unsupported. @returns IPv6 or IPv4 address
-
charmhelpers.contrib.network.ip.
is_address_in_network
(network, address)¶ Determine whether the provided address is within a network range.
Parameters: - (str) (network) – CIDR presentation format. For example, ‘192.168.1.0/24’.
- address – An individual IPv4 or IPv6 address without a net mask or subnet prefix. For example, ‘192.168.1.1’.
Returns boolean: Flag indicating whether address is in network.
-
charmhelpers.contrib.network.ip.
is_bridge_member
(nic)¶ Check if a given nic is a member of a bridge.
-
charmhelpers.contrib.network.ip.
is_ip
(address)¶ Returns True if address is a valid IP address.
-
charmhelpers.contrib.network.ip.
is_ipv6
(address)¶ Determine whether provided address is IPv6 or not.
-
charmhelpers.contrib.network.ip.
is_ipv6_disabled
()¶
-
charmhelpers.contrib.network.ip.
no_ip_found_error_out
(network)¶
-
charmhelpers.contrib.network.ip.
ns_query
(address)¶
-
charmhelpers.contrib.network.ip.
port_has_listener
(address, port)¶ Returns True if the address:port is open and being listened to, else False.
@param address: an IP address or hostname @param port: integer port
Note calls ‘zc’ via a subprocess shell
-
charmhelpers.contrib.network.ip.
resolve_network_cidr
(ip_address)¶ Resolves the full address cidr of an ip_address based on configured network interfaces
-
charmhelpers.contrib.network.ip.
sniff_iface
(f)¶ Ensure decorated function is called with a value for iface.
If no iface provided, inject net iface inferred from unit private address.