コード例 #1
0
ファイル: sync.py プロジェクト: wyatt88/pcs
def _set_config_on_node(
    communicator, reporter, node, name, config_data, authfile=None,
    authfile_data=None
):
    """
    Set booth config for instance 'name' on specified node.

    communicator -- NodeCommunicator
    reporter -- report processor
    node -- NodeAddresses
    name -- name of booth instance
    config_data -- booth config as string
    authfile -- path to authfile
    authfile_data -- authfile content as bytes
    """
    data = {
        "config": {
            "name": "{0}.conf".format(name),
            "data": config_data
        }
    }
    if authfile is not None and authfile_data is not None:
        data["authfile"] = {
            "name": os.path.basename(authfile),
            "data": base64.b64encode(authfile_data).decode("utf-8")
        }
    communicator.call_node(
        node,
        "remote/booth_set_config",
        NodeCommunicator.format_data_dict([("data_json", json.dumps(data))])
    )
    reporter.process(reports.booth_config_saved(node.label, [name]))
コード例 #2
0
def _set_config_on_node(
    communicator, reporter, node, name, config_data, authfile=None,
    authfile_data=None
):
    """
    Set booth config for instance 'name' on specified node.

    communicator -- NodeCommunicator
    reporter -- report processor
    node -- NodeAddresses
    name -- name of booth instance
    config_data -- booth config as string
    authfile -- path to authfile
    authfile_data -- authfile content as bytes
    """
    data = {
        "config": {
            "name": "{0}.conf".format(name),
            "data": config_data
        }
    }
    if authfile is not None and authfile_data is not None:
        data["authfile"] = {
            "name": os.path.basename(authfile),
            "data": base64.b64encode(authfile_data).decode("utf-8")
        }
    communicator.call_node(
        node,
        "remote/booth_set_config",
        NodeCommunicator.format_data_dict([("data_json", json.dumps(data))])
    )
    reporter.process(reports.booth_config_accepted_by_node(node.label, [name]))
コード例 #3
0
ファイル: sync.py プロジェクト: wyatt88/pcs
def pull_config_from_node(communicator, node, name):
    """
    Get config of specified booth instance and its authfile if there is one
    from 'node'. It returns dictionary with format:
    {
        "config": {
            "name": <file name of config>,
            "data": <content of file>
        },
        "authfile": {
            "name": <file name of authfile, None if it doesn't exist>,
            "data": <base64 coded content of authfile>
        }

    communicator -- NodeCommunicator
    node -- NodeAddresses
    name -- name of booth instance
    """
    try:
        return json.loads(communicator.call_node(
            node,
            "remote/booth_get_config",
            NodeCommunicator.format_data_dict([("name", name)])
        ))
    except NodeCommunicationException as e:
        raise LibraryError(node_communicator_exception_to_report_item(e))
    except ValueError:
        raise LibraryError(lib_reports.invalid_response_format(node.label))
コード例 #4
0
def pull_config_from_node(communicator, node, name):
    """
    Get config of specified booth instance and its authfile if there is one
    from 'node'. It returns dictionary with format:
    {
        "config": {
            "name": <file name of config>,
            "data": <content of file>
        },
        "authfile": {
            "name": <file name of authfile, None if it doesn't exist>,
            "data": <base64 coded content of authfile>
        }

    communicator -- NodeCommunicator
    node -- NodeAddresses
    name -- name of booth instance
    """
    try:
        return json.loads(communicator.call_node(
            node,
            "remote/booth_get_config",
            NodeCommunicator.format_data_dict([("name", name)])
        ))
    except NodeCommunicationException as e:
        raise LibraryError(node_communicator_exception_to_report_item(e))
    except ValueError:
        raise LibraryError(lib_reports.invalid_response_format(node.label))
コード例 #5
0
ファイル: sbd.py プロジェクト: cwjenkins/pcs
def check_sbd(communicator, node, watchdog, device_list):
    """
    Check SBD on specified 'node' and existence of specified watchdog and
    devices.

    communicator -- NodeCommunicator
    node -- NodeAddresses
    watchdog -- watchdog path
    device_list -- list of strings
    """
    return communicator.call_node(
        node, "remote/check_sbd",
        NodeCommunicator.format_data_dict([
            ("watchdog", watchdog),
            ("device_list", NodeCommunicator.format_data_json(device_list)),
        ]))
コード例 #6
0
ファイル: env.py プロジェクト: jmartign/pcs
 def node_communicator(self):
     return NodeCommunicator(
         self.logger,
         self.report_processor,
         self.__get_auth_tokens(),
         self.user_login,
         self.user_groups
     )
コード例 #7
0
ファイル: live.py プロジェクト: rriifftt/pcs
def set_remote_corosync_conf(node_communicator, node_addr, config_text):
    """
    Send corosync.conf to a node
    node_addr instance of NodeAddresses
    config_text corosync.conf text
    """
    dummy_response = node_communicator.call_node(
        node_addr, "remote/set_corosync_conf",
        NodeCommunicator.format_data_dict({'corosync_conf': config_text}))
コード例 #8
0
ファイル: live.py プロジェクト: idevat/pcs
def set_remote_corosync_conf(node_communicator, node_addr, config_text):
    """
    Send corosync.conf to a node
    node_addr instance of NodeAddresses
    config_text corosync.conf text
    """
    dummy_response = node_communicator.call_node(
        node_addr, "remote/set_corosync_conf", NodeCommunicator.format_data_dict({"corosync_conf": config_text})
    )
コード例 #9
0
def set_sbd_config(communicator, node, config):
    """
    Send SBD configuration to 'node'.

    communicator -- NodeCommunicator
    node -- NodeAddresses
    config -- string, SBD configuration file
    """
    communicator.call_node(
        node, "remote/set_sbd_config",
        NodeCommunicator.format_data_dict([("config", config)]))
コード例 #10
0
def check_sbd(communicator, node, watchdog):
    """
    Check SBD on specified 'node' and existence of specified watchdog.

    communicator -- NodeCommunicator
    node -- NodeAddresses
    watchdog -- watchdog path
    """
    return communicator.call_node(
        node, "remote/check_sbd",
        NodeCommunicator.format_data_dict([("watchdog", watchdog)]))
コード例 #11
0
def node_check_auth(communicator, node):
    """
    Check authentication and online status of 'node'.

    communicator -- NodeCommunicator
    node -- NodeAddresses
    """
    communicator.call_node(
        node,
        "remote/check_auth",
        NodeCommunicator.format_data_dict({"check_auth_only": 1})
    )
コード例 #12
0
ファイル: sbd.py プロジェクト: dchirikov/pcs
def check_sbd(communicator, node, watchdog):
    """
    Check SBD on specified 'node' and existence of specified watchdog.

    communicator -- NodeCommunicator
    node -- NodeAddresses
    watchdog -- watchdog path
    """
    return communicator.call_node(
        node,
        "remote/check_sbd",
        NodeCommunicator.format_data_dict([("watchdog", watchdog)])
    )
コード例 #13
0
ファイル: sbd.py プロジェクト: dchirikov/pcs
def set_sbd_config(communicator, node, config):
    """
    Send SBD configuration to 'node'.

    communicator -- NodeCommunicator
    node -- NodeAddresses
    config -- string, SBD configuration file
    """
    communicator.call_node(
        node,
        "remote/set_sbd_config",
        NodeCommunicator.format_data_dict([("config", config)])
    )
コード例 #14
0
ファイル: sync.py プロジェクト: wyatt88/pcs
def send_all_config_to_node(
    communicator,
    reporter,
    node,
    rewrite_existing=False,
    skip_wrong_config=False
):
    """
    Send all booth configs from default booth config directory and theri
    authfiles to specified node.

    communicator -- NodeCommunicator
    reporter -- report processor
    node -- NodeAddress
    rewrite_existing -- if True rewrite existing file
    skip_wrong_config -- if True skip local configs that are unreadable
    """
    config_dict = booth_conf.read_configs(reporter, skip_wrong_config)
    if not config_dict:
        return
    file_list = []
    for config, config_data in sorted(config_dict.items()):
        try:
            authfile_path = config_structure.get_authfile(
                config_parser.parse(config_data)
            )
            file_list.append({
                "name": config,
                "data": config_data,
                "is_authfile": False
            })
            if authfile_path:
                content = booth_conf.read_authfile(reporter, authfile_path)
                if not content:
                    continue
                file_list.append({
                    "name": os.path.basename(authfile_path),
                    "data": base64.b64encode(content).decode("utf-8"),
                    "is_authfile": True
                })
        except LibraryError:
            reporter.process(reports.booth_skipping_config(
                config, "unable to parse config"
            ))

    data = [("data_json", json.dumps(file_list))]

    if rewrite_existing:
        data.append(("rewrite_existing", "1"))

    reporter.process(reports.booth_sending_local_configs_to_node(node.label))
    try:
        response = json.loads(communicator.call_node(
            node,
            "remote/booth_save_files",
            NodeCommunicator.format_data_dict(data)
        ))
        report_list = []
        for file in response["existing"]:
            report_list.append(lib_reports.file_already_exists(
                None,
                file,
                Severities.WARNING if rewrite_existing else Severities.ERROR,
                (
                    None if rewrite_existing
                    else report_codes.FORCE_FILE_OVERWRITE
                ),
                node.label
            ))
        for file, reason in response["failed"].items():
            report_list.append(reports.booth_config_not_saved(
                node.label, reason, file
            ))
        reporter.process_list(report_list)
        reporter.process(
            reports.booth_config_saved(node.label, response["saved"])
        )
    except NodeCommunicationException as e:
        raise LibraryError(node_communicator_exception_to_report_item(e))
    except (KeyError, ValueError):
        raise LibraryError(lib_reports.invalid_response_format(node.label))
コード例 #15
0
def send_all_config_to_node(
    communicator,
    reporter,
    node,
    rewrite_existing=False,
    skip_wrong_config=False
):
    """
    Send all booth configs from default booth config directory and theri
    authfiles to specified node.

    communicator -- NodeCommunicator
    reporter -- report processor
    node -- NodeAddress
    rewrite_existing -- if True rewrite existing file
    skip_wrong_config -- if True skip local configs that are unreadable
    """
    config_dict = booth_conf.read_configs(reporter, skip_wrong_config)
    if not config_dict:
        return

    reporter.process(reports.booth_config_distribution_started())

    file_list = []
    for config, config_data in sorted(config_dict.items()):
        try:
            authfile_path = config_structure.get_authfile(
                config_parser.parse(config_data)
            )
            file_list.append({
                "name": config,
                "data": config_data,
                "is_authfile": False
            })
            if authfile_path:
                content = booth_conf.read_authfile(reporter, authfile_path)
                if not content:
                    continue
                file_list.append({
                    "name": os.path.basename(authfile_path),
                    "data": base64.b64encode(content).decode("utf-8"),
                    "is_authfile": True
                })
        except LibraryError:
            reporter.process(reports.booth_skipping_config(
                config, "unable to parse config"
            ))

    data = [("data_json", json.dumps(file_list))]

    if rewrite_existing:
        data.append(("rewrite_existing", "1"))

    try:
        response = json.loads(communicator.call_node(
            node,
            "remote/booth_save_files",
            NodeCommunicator.format_data_dict(data)
        ))
        report_list = []
        for file in response["existing"]:
            report_list.append(lib_reports.file_already_exists(
                None,
                file,
                Severities.WARNING if rewrite_existing else Severities.ERROR,
                (
                    None if rewrite_existing
                    else report_codes.FORCE_FILE_OVERWRITE
                ),
                node.label
            ))
        for file, reason in response["failed"].items():
            report_list.append(reports.booth_config_distribution_node_error(
                node.label, reason, file
            ))
        reporter.process_list(report_list)
        reporter.process(
            reports.booth_config_accepted_by_node(node.label, response["saved"])
        )
    except NodeCommunicationException as e:
        raise LibraryError(node_communicator_exception_to_report_item(e))
    except (KeyError, ValueError):
        raise LibraryError(lib_reports.invalid_response_format(node.label))