~openstack-charmers/charms/trusty/neutron-openvswitch/trunk

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/contrib/network/ip.py

  • Committer: James Page
  • Date: 2016-05-18 13:08:44 UTC
  • Revision ID: james.page@ubuntu.com-20160518130844-f7ncxhlv66bjqeq1
Resync charm-helpers

Avoid use of 'service --status-all' which is currently
broken on trusty for upstart managed daemons; the change
moves to detecting how the daemon is managed, and then
using upstart status XXX or the return code of service XXX
status to determine whether a process is running.

Fixes for IPv6 network address detection under Ubuntu
16.04 which changes the output format of the ip commands
slightly.

Update the version map to include 8.1.x as a Neutron
version for Mitaka.

Change-Id: I023dbb4b3d7e16d7ec50e5b78636e5c7688ff9cc
Closes-Bug: 1581171
Closes-Bug: 1581598
Closes-Bug: 1580674

Show diffs side-by-side

added added

removed removed

Lines of Context:
214
214
 
215
215
def get_iface_addr(iface='eth0', inet_type='AF_INET', inc_aliases=False,
216
216
                   fatal=True, exc_list=None):
217
 
    """Return the assigned IP address for a given interface, if any."""
 
217
    """Return the assigned IP address for a given interface, if any.
 
218
 
 
219
    :param iface: network interface on which address(es) are expected to
 
220
                  be found.
 
221
    :param inet_type: inet address family
 
222
    :param inc_aliases: include alias interfaces in search
 
223
    :param fatal: if True, raise exception if address not found
 
224
    :param exc_list: list of addresses to ignore
 
225
    :return: list of ip addresses
 
226
    """
218
227
    # Extract nic if passed /dev/ethX
219
228
    if '/' in iface:
220
229
        iface = iface.split('/')[-1]
315
324
    We currently only support scope global IPv6 addresses i.e. non-temporary
316
325
    addresses. If no global IPv6 address is found, return the first one found
317
326
    in the ipv6 address list.
 
327
 
 
328
    :param iface: network interface on which ipv6 address(es) are expected to
 
329
                  be found.
 
330
    :param inc_aliases: include alias interfaces in search
 
331
    :param fatal: if True, raise exception if address not found
 
332
    :param exc_list: list of addresses to ignore
 
333
    :param dynamic_only: only recognise dynamic addresses
 
334
    :return: list of ipv6 addresses
318
335
    """
319
336
    addresses = get_iface_addr(iface=iface, inet_type='AF_INET6',
320
337
                               inc_aliases=inc_aliases, fatal=fatal,
336
353
            cmd = ['ip', 'addr', 'show', iface]
337
354
            out = subprocess.check_output(cmd).decode('UTF-8')
338
355
            if dynamic_only:
339
 
                key = re.compile("inet6 (.+)/[0-9]+ scope global dynamic.*")
 
356
                key = re.compile("inet6 (.+)/[0-9]+ scope global.* dynamic.*")
340
357
            else:
341
358
                key = re.compile("inet6 (.+)/[0-9]+ scope global.*")
342
359