def configure_corosync(ring0_name, ring1_name, old_mcast_port, new_mcast_port):
    """
    Process configuration including negotiated multicast port, no IP address information required

    :param ring0_name:
    :param ring1_name:
    :param old_mcast_port: None if we are configuring corosync for the first-time, present if changing mcast port
    :param new_mcast_port: desired corosync multicast port as configured by user
    :return: Value using simple return protocol
    """

    interfaces = [InterfaceInfo(CorosyncRingInterface(name=ring0_name, ringnumber=0, mcastport=new_mcast_port),
                                None,
                                None),
                  InterfaceInfo(CorosyncRingInterface(name=ring1_name, ringnumber=1, mcastport=new_mcast_port),
                                None,
                                None)]

    config = render_config([interface.corosync_iface for interface in interfaces])

    write_config_to_file("/etc/corosync/corosync.conf", config)

    if old_mcast_port is not None:
        error = firewall_control.remove_rule(old_mcast_port, "udp", "corosync", persist=True)

        if error:
            return agent_error(error)

    return agent_ok_or_error(firewall_control.add_rule(new_mcast_port, "udp", "corosync", persist=True) or
                             corosync_service.enable())
def configure_network(ring0_name,
                      ring1_name=None,
                      ring0_ipaddr=None,
                      ring0_prefix=None,
                      ring1_ipaddr=None,
                      ring1_prefix=None):
    """
    Configure rings, bring up interfaces and set addresses. no multicast port or peers specified.
    """
    interfaces = [
        InterfaceInfo(CorosyncRingInterface(name=ring0_name, ringnumber=0),
                      ring0_ipaddr, ring0_prefix)
    ]

    if ring1_name:
        interfaces.append(
            InterfaceInfo(CorosyncRingInterface(ring1_name, ringnumber=1),
                          ring1_ipaddr, ring1_prefix))

    for interface in interfaces:
        if interface.ipaddr and interface.ipaddr == ring1_ipaddr:
            # we only want to set ring1, ring0 already set and should not be modified
            interface.corosync_iface.set_address(interface.ipaddr,
                                                 interface.prefix)

    return agent_result_ok
def configure_network(
    ring0_name,
    ring1_name=None,
    ring0_ipaddr=None,
    ring0_prefix=None,
    ring1_ipaddr=None,
    ring1_prefix=None,
):
    """
    Configure rings, bring up interfaces and set addresses. no multicast port or peers specified.
    """
    interfaces = [
        InterfaceInfo(
            CorosyncRingInterface(name=ring0_name, ringnumber=0),
            ring0_ipaddr,
            ring0_prefix,
        )
    ]

    if ring1_name:
        interfaces.append(
            InterfaceInfo(
                CorosyncRingInterface(ring1_name, ringnumber=1),
                ring1_ipaddr,
                ring1_prefix,
            ))

    for interface in interfaces:
        interface.corosync_iface.set_address(interface.ipaddr,
                                             interface.prefix)

    return agent_result_ok
Esempio n. 4
0
def configure_corosync2_stage_2(ring0_name, ring1_name, new_node_fqdn, mcast_port, pcs_password, create_cluster):
    """Process configuration including peers and negotiated multicast port, no IP address
    information required

    Note: "The pcs cluster setup command will automatically configure two_node: 1 in
    corosync.conf, so a two-node cluster will "just work". If you are using a different cluster
    shell, you will have to configure corosync.conf appropriately yourself." Therefore
    no-quorum-policy does not have to be set when setting up cluster with pcs.

    :param ring0_name:
    :param ring1_name:
    :param peer_fqdns:
    :param mcast_port:
    :return:
    """

    interfaces = [InterfaceInfo(CorosyncRingInterface(name=ring0_name, ringnumber=0,
                                                      mcastport=mcast_port), None, None),
                  InterfaceInfo(CorosyncRingInterface(name=ring1_name, ringnumber=1,
                                                      mcastport=mcast_port), None, None)]

    config_params = {
        'token': '17000',
        'fail_recv_const': '10',
        'transport': 'udp',
        'rrpmode': 'passive',
        'addr0': interfaces[0].corosync_iface.bindnetaddr,
        'addr1': interfaces[1].corosync_iface.bindnetaddr,
        'mcast0': interfaces[0].corosync_iface.mcastaddr,
        'mcast1': interfaces[1].corosync_iface.mcastaddr,
        'mcastport0': interfaces[0].corosync_iface.mcastport,
        'mcastport1': interfaces[1].corosync_iface.mcastport
    }

    # authenticate nodes in cluster
    authenticate_nodes_in_cluster_command = ['pcs', 'cluster', 'auth', new_node_fqdn,
                                             '-u', PCS_USER, '-p', pcs_password]

    # build command string for setup of cluster which will result in corosync.conf rather than
    # writing from template, note we don't start the cluster here as services are managed
    # independently
    if create_cluster:
        cluster_setup_command = ['pcs', 'cluster', 'setup', '--name', PCS_CLUSTER_NAME, '--force'] + [new_node_fqdn]
        for param in ['transport', 'rrpmode', 'addr0', 'mcast0', 'mcastport0', 'addr1', 'mcast1',
                      'mcastport1', 'token', 'fail_recv_const']:
            # pull this value from the dictionary using parameter keyword
            cluster_setup_command.extend(["--" + param, str(config_params[param])])
    else:
        cluster_setup_command = ['pcs', 'cluster', 'node', 'add', new_node_fqdn]

    return agent_ok_or_error(AgentShell.run_canned_error_message(authenticate_nodes_in_cluster_command) or
                             AgentShell.run_canned_error_message(cluster_setup_command))
Esempio n. 5
0
 def get_ring0():
     return CorosyncRingInterface('eth0.1.1?1b34*430')
 def get_shared_ring():
     return CorosyncRingInterface("eth0.1.1?1b34*430")