def update_hacluster_vip(service, relation_data):
    """ Configure VIP resources based on provided configuration

    @param service: Name of the service being configured
    @param relation_data: Pointer to dictionary of relation data.
    """
    cluster_config = get_hacluster_config()
    vip_group = []
    for vip in cluster_config['vip'].split():
        if is_ipv6(vip):
            res_neutron_vip = 'ocf:heartbeat:IPv6addr'
            vip_params = 'ipv6addr'
        else:
            res_neutron_vip = 'ocf:heartbeat:IPaddr2'
            vip_params = 'ip'

        iface = (get_iface_for_address(vip) or
                 config('vip_iface'))
        netmask = (get_netmask_for_address(vip) or
                   config('vip_cidr'))

        if iface is not None:
            vip_key = 'res_{}_{}_vip'.format(service, iface)
            if vip_key in vip_group:
                if vip not in relation_data['resource_params'][vip_key]:
                    vip_key = '{}_{}'.format(vip_key, vip_params)
                else:
                    log("Resource '%s' (vip='%s') already exists in "
                        "vip group - skipping" % (vip_key, vip), WARNING)
                    continue

            relation_data['resources'][vip_key] = res_neutron_vip
            relation_data['resource_params'][vip_key] = (
                'params {ip}="{vip}" cidr_netmask="{netmask}" '
                'nic="{iface}"'.format(ip=vip_params,
                                       vip=vip,
                                       iface=iface,
                                       netmask=netmask)
            )
            vip_group.append(vip_key)

    if len(vip_group) >= 1:
        relation_data['groups'] = {
            'grp_{}_vips'.format(service): ' '.join(vip_group)
        }
Esempio n. 2
0
def update_hacluster_vip(service, relation_data):
    """ Configure VIP resources based on provided configuration

    @param service: Name of the service being configured
    @param relation_data: Pointer to dictionary of relation data.
    """
    cluster_config = get_hacluster_config()
    vip_group = []
    for vip in cluster_config['vip'].split():
        if is_ipv6(vip):
            res_neutron_vip = 'ocf:heartbeat:IPv6addr'
            vip_params = 'ipv6addr'
        else:
            res_neutron_vip = 'ocf:heartbeat:IPaddr2'
            vip_params = 'ip'

        iface = (get_iface_for_address(vip) or config('vip_iface'))
        netmask = (get_netmask_for_address(vip) or config('vip_cidr'))

        if iface is not None:
            vip_key = 'res_{}_{}_vip'.format(service, iface)
            if vip_key in vip_group:
                if vip not in relation_data['resource_params'][vip_key]:
                    vip_key = '{}_{}'.format(vip_key, vip_params)
                else:
                    log(
                        "Resource '%s' (vip='%s') already exists in "
                        "vip group - skipping" % (vip_key, vip), WARNING)
                    continue

            relation_data['resources'][vip_key] = res_neutron_vip
            relation_data['resource_params'][vip_key] = (
                'params {ip}="{vip}" cidr_netmask="{netmask}" '
                'nic="{iface}"'.format(ip=vip_params,
                                       vip=vip,
                                       iface=iface,
                                       netmask=netmask))
            vip_group.append(vip_key)

    if len(vip_group) >= 1:
        relation_data['groups'] = {
            'grp_{}_vips'.format(service): ' '.join(vip_group)
        }
Esempio n. 3
0
def update_hacluster_vip(service, relation_data):
    """ Configure VIP resources based on provided configuration

    @param service: Name of the service being configured
    @param relation_data: Pointer to dictionary of relation data.
    """
    cluster_config = get_hacluster_config()
    vip_group = []
    vips_to_delete = []
    for vip in cluster_config['vip'].split():
        if is_ipv6(vip):
            res_vip = 'ocf:heartbeat:IPv6addr'
            vip_params = 'ipv6addr'
        else:
            res_vip = 'ocf:heartbeat:IPaddr2'
            vip_params = 'ip'

        iface, netmask, fallback = get_vip_settings(vip)

        vip_monitoring = 'op monitor timeout="20s" interval="10s" depth="0"'
        if iface is not None:
            # NOTE(jamespage): Delete old VIP resources
            # Old style naming encoding iface in name
            # does not work well in environments where
            # interface/subnet wiring is not consistent
            vip_key = 'res_{}_{}_vip'.format(service, iface)
            if vip_key in vips_to_delete:
                vip_key = '{}_{}'.format(vip_key, vip_params)
            vips_to_delete.append(vip_key)

            vip_key = 'res_{}_{}_vip'.format(
                service,
                hashlib.sha1(vip.encode('UTF-8')).hexdigest()[:7])

            relation_data['resources'][vip_key] = res_vip
            # NOTE(jamespage):
            # Use option provided vip params if these where used
            # instead of auto-detected values
            if fallback:
                relation_data['resource_params'][vip_key] = (
                    'params {ip}="{vip}" cidr_netmask="{netmask}" '
                    'nic="{iface}" {vip_monitoring}'.format(
                        ip=vip_params,
                        vip=vip,
                        iface=iface,
                        netmask=netmask,
                        vip_monitoring=vip_monitoring))
            else:
                # NOTE(jamespage):
                # let heartbeat figure out which interface and
                # netmask to configure, which works nicely
                # when network interface naming is not
                # consistent across units.
                relation_data['resource_params'][vip_key] = (
                    'params {ip}="{vip}" {vip_monitoring}'.format(
                        ip=vip_params, vip=vip, vip_monitoring=vip_monitoring))

            vip_group.append(vip_key)

    if vips_to_delete:
        try:
            relation_data['delete_resources'].extend(vips_to_delete)
        except KeyError:
            relation_data['delete_resources'] = vips_to_delete

    if len(vip_group) >= 1:
        key = VIP_GROUP_NAME.format(service=service)
        try:
            relation_data['groups'][key] = ' '.join(vip_group)
        except KeyError:
            relation_data['groups'] = {key: ' '.join(vip_group)}
Esempio n. 4
0
def update_hacluster_vip(service, relation_data):
    """ Configure VIP resources based on provided configuration

    @param service: Name of the service being configured
    @param relation_data: Pointer to dictionary of relation data.
    """
    cluster_config = get_hacluster_config()
    vip_group = []
    vips_to_delete = []
    for vip in cluster_config['vip'].split():
        if is_ipv6(vip):
            res_vip = 'ocf:heartbeat:IPv6addr'
            vip_params = 'ipv6addr'
        else:
            res_vip = 'ocf:heartbeat:IPaddr2'
            vip_params = 'ip'

        iface, netmask, fallback = get_vip_settings(vip)

        vip_monitoring = 'op monitor depth="0" timeout="20s" interval="10s"'
        if iface is not None:
            # NOTE(jamespage): Delete old VIP resources
            # Old style naming encoding iface in name
            # does not work well in environments where
            # interface/subnet wiring is not consistent
            vip_key = 'res_{}_{}_vip'.format(service, iface)
            if vip_key in vips_to_delete:
                vip_key = '{}_{}'.format(vip_key, vip_params)
            vips_to_delete.append(vip_key)

            vip_key = 'res_{}_{}_vip'.format(
                service,
                hashlib.sha1(vip.encode('UTF-8')).hexdigest()[:7])

            relation_data['resources'][vip_key] = res_vip
            # NOTE(jamespage):
            # Use option provided vip params if these where used
            # instead of auto-detected values
            if fallback:
                relation_data['resource_params'][vip_key] = (
                    'params {ip}="{vip}" cidr_netmask="{netmask}" '
                    'nic="{iface}" {vip_monitoring}'.format(
                        ip=vip_params,
                        vip=vip,
                        iface=iface,
                        netmask=netmask,
                        vip_monitoring=vip_monitoring))
            else:
                # NOTE(jamespage):
                # let heartbeat figure out which interface and
                # netmask to configure, which works nicely
                # when network interface naming is not
                # consistent across units.
                relation_data['resource_params'][vip_key] = (
                    'params {ip}="{vip}" {vip_monitoring}'.format(
                        ip=vip_params,
                        vip=vip,
                        vip_monitoring=vip_monitoring))

            vip_group.append(vip_key)

    if vips_to_delete:
        try:
            relation_data['delete_resources'].extend(vips_to_delete)
        except KeyError:
            relation_data['delete_resources'] = vips_to_delete

    if len(vip_group) >= 1:
        key = VIP_GROUP_NAME.format(service=service)
        try:
            relation_data['groups'][key] = ' '.join(vip_group)
        except KeyError:
            relation_data['groups'] = {
                key: ' '.join(vip_group)
            }
def update_hacluster_vip(service, relation_data):
    """ Configure VIP resources based on provided configuration

    @param service: Name of the service being configured
    @param relation_data: Pointer to dictionary of relation data.
    """
    cluster_config = get_hacluster_config()
    vip_group = []
    vips_to_delete = []
    for vip in cluster_config['vip'].split():
        if is_ipv6(vip):
            res_vip = 'ocf:heartbeat:IPv6addr'
            vip_params = 'ipv6addr'
        else:
            res_vip = 'ocf:heartbeat:IPaddr2'
            vip_params = 'ip'

        iface = get_iface_for_address(vip)
        netmask = get_netmask_for_address(vip)

        fallback_params = False
        if iface is None:
            iface = config('vip_iface')
            fallback_params = True
        if netmask is None:
            netmask = config('vip_cidr')
            fallback_params = True

        if iface is not None:
            # NOTE(jamespage): Delete old VIP resources
            # Old style naming encoding iface in name
            # does not work well in environments where
            # interface/subnet wiring is not consistent
            vip_key = 'res_{}_{}_vip'.format(service, iface)
            if vip_key in vips_to_delete:
                vip_key = '{}_{}'.format(vip_key, vip_params)
            vips_to_delete.append(vip_key)

            vip_key = 'res_{}_{}_vip'.format(
                service,
                hashlib.sha1(vip.encode('UTF-8')).hexdigest()[:7])

            relation_data['resources'][vip_key] = res_vip
            # NOTE(jamespage):
            # Use option provided vip params if these where used
            # instead of auto-detected values
            if fallback_params:
                relation_data['resource_params'][vip_key] = (
                    'params {ip}="{vip}" cidr_netmask="{netmask}" '
                    'nic="{iface}"'.format(ip=vip_params,
                                           vip=vip,
                                           iface=iface,
                                           netmask=netmask))
            else:
                # NOTE(jamespage):
                # let heartbeat figure out which interface and
                # netmask to configure, which works nicely
                # when network interface naming is not
                # consistent across units.
                relation_data['resource_params'][vip_key] = (
                    'params {ip}="{vip}"'.format(ip=vip_params, vip=vip))

            vip_group.append(vip_key)

    if vips_to_delete:
        relation_data['delete_resources'] = vips_to_delete

    if len(vip_group) >= 1:
        relation_data['groups'] = {
            'grp_{}_vips'.format(service): ' '.join(vip_group)
        }