Exemple #1
0
    def save_files(self,
                   files_data,
                   saved=(),
                   existing=(),
                   failed=(),
                   rewrite_existing=False,
                   node_labels=None,
                   communication_list=None,
                   name="http.booth.save_files"):
        param_list = [("data_json", json.dumps(files_data))]
        if rewrite_existing:
            param_list.append(("rewrite_existing", "1"))

        place_multinode_call(
            self.__calls,
            name,
            node_labels,
            communication_list,
            action="remote/booth_save_files",
            param_list=param_list,
            output=json.dumps({
                "saved": saved,
                "existing": existing,
                "failed": failed,
            }),
        )
Exemple #2
0
 def check_sbd(self, communication_list=None, name="http.sbd.check_sbd"):
     place_multinode_call(
         self.__calls,
         name,
         communication_list=communication_list,
         action="remote/check_sbd",
     )
Exemple #3
0
 def get_config(self,
                booth_name,
                config_data=None,
                authfile=None,
                authfile_data=None,
                node_labels=None,
                communication_list=None,
                name="http.booth.get_config"):
     place_multinode_call(
         self.__calls,
         name,
         node_labels,
         communication_list,
         action="remote/booth_get_config",
         param_list=[("name", booth_name)],
         output=json.dumps({
             "config": {
                 "data": config_data,
             },
             "authfile": {
                 "name":
                 authfile,
                 "data":
                 base64.b64encode(authfile_data).decode("utf-8")
                 if authfile_data else None,
             },
         }),
     )
Exemple #4
0
    def remove_files(self,
                     node_labels=None,
                     pcsd_settings=False,
                     communication_list=None,
                     name="http.files.remove_files"):
        """
        Create a call for removing the files on the nodes.

        node_labels list -- create success responses from these nodes
        pcsd_settings bool -- if True, remove file pcsd_settings
        communication_list list -- create custom responses
        name string -- the key of this call
        """
        input_data = {}
        output_data = {}

        if pcsd_settings:
            file_id = "pcsd settings"
            input_data[file_id] = dict(type="pcsd_settings")
            output_data[file_id] = dict(
                code="deleted",
                message="",
            )

        place_multinode_call(self.__calls,
                             name,
                             node_labels,
                             communication_list,
                             action="remote/remove_file",
                             param_list=[("data_json", json.dumps(input_data))
                                         ],
                             output=json.dumps(dict(files=output_data)))
Exemple #5
0
 def set_sbd_config(
     self, config_generator=None, node_labels=None, communication_list=None,
     name="http.sbd.set_sbd_config"
 ):
     if bool(config_generator) == bool(communication_list):
         raise AssertionError(
             "Exactly one of 'config_generator', 'communication_list' "
             "must be specified"
         )
     if config_generator and not node_labels:
         raise AssertionError(
             "'node_labels' has to be defined if 'config_generator' is used"
         )
     if communication_list is None:
         communication_list = [
             dict(
                 param_list=[("config", config_generator(node))],
                 label=node,
             ) for node in node_labels
         ]
     place_multinode_call(
         self.__calls,
         name,
         None,
         communication_list,
         action="remote/set_sbd_config",
     )
Exemple #6
0
 def send_config(self,
                 booth_name,
                 config,
                 authfile=None,
                 authfile_data=None,
                 node_labels=None,
                 communication_list=None,
                 name="http.booth.send_config"):
     data = {
         "config": {
             "name": "{}.conf".format(booth_name),
             "data": config,
         }
     }
     if authfile and authfile_data:
         data["authfile"] = {
             "name": authfile,
             "data": base64.b64encode(authfile_data).decode("utf-8"),
         }
     place_multinode_call(self.__calls,
                          name,
                          node_labels,
                          communication_list,
                          action="remote/booth_set_config",
                          param_list=[("data_json", json.dumps(data))])
Exemple #7
0
 def enable_sbd(self,
                node_labels=None,
                communication_list=None,
                name="http.sbd.enable_sbd"):
     place_multinode_call(self.__calls,
                          name,
                          node_labels,
                          communication_list,
                          action="remote/sbd_enable")
Exemple #8
0
 def remove_stonith_watchdog_timeout(
         self,
         node_labels=None,
         communication_list=None,
         name="http.pcmk.remove_stonith_watchdog_timeout"):
     place_multinode_call(self.__calls,
                          name,
                          node_labels,
                          communication_list,
                          action="remote/remove_stonith_watchdog_timeout")
Exemple #9
0
 def qdevice_net_get_ca_cert(
     self, ca_cert=b"ca_cert", node_labels=None, communication_list=None,
     name="http.corosync.qdevice_net_get_ca_cert",
 ):
     place_multinode_call(
         self.__calls,
         name,
         node_labels,
         communication_list,
         action="remote/qdevice_net_get_ca_certificate",
         output=base64.b64encode(ca_cert),
     )
Exemple #10
0
 def qdevice_net_client_setup(
     self, ca_cert=b"ca_cert", node_labels=None, communication_list=None,
     name="http.corosync.qdevice_net_client_setup",
 ):
     place_multinode_call(
         self.__calls,
         name,
         node_labels,
         communication_list,
         action="remote/qdevice_net_client_init_certificate_storage",
         param_list=[("ca_certificate", base64.b64encode(ca_cert))],
     )
Exemple #11
0
 def qdevice_net_client_import_cert_and_key(
     self, cert=b"pk12 cert", node_labels=None, communication_list=None,
     name="http.corosync.qdevice_net_client_import_cert_and_key",
 ):
     place_multinode_call(
         self.__calls,
         name,
         node_labels,
         communication_list,
         action="remote/qdevice_net_client_import_certificate",
         param_list=[("certificate", base64.b64encode(cert))],
     )
Exemple #12
0
 def reload_corosync_conf(
     self, node_labels=None, communication_list=None,
     name="http.corosync.reload_corosync_conf"
 ):
     place_multinode_call(
         self.__calls,
         name,
         node_labels,
         communication_list,
         action="remote/reload_corosync_conf",
         output=json.dumps(dict(code="reloaded", message="")),
     )
Exemple #13
0
 def check_sbd(self,
               watchdog=None,
               device_list=(),
               node_labels=None,
               communication_list=None,
               name="http.sbd.check_sbd"):
     place_multinode_call(
         self.__calls,
         name,
         node_labels,
         communication_list,
         action="remote/check_sbd",
     )
Exemple #14
0
    def disable_sbd(self,
                    node_labels=None,
                    communication_list=None,
                    name="http.sbd.disable_sbd"):
        """
        Create a call for disabling sbd on nodes

        node_labels list -- create success responses from these nodes
        communication_list list -- create custom responses
        name string -- the key of this call
        """
        place_multinode_call(self.__calls,
                             name,
                             node_labels,
                             communication_list,
                             action="remote/sbd_disable")
    def check_corosync_offline(self,
                               node_labels=None,
                               communication_list=None,
                               name="http.corosync.check_corosync_offline"):
        """
        Create a call for checking that corosync is offline

        string name -- the key of this call
        list node_labels -- create success responses from these nodes
        list communication_list -- create custom responses
        """
        place_multinode_call(self.__calls,
                             name,
                             node_labels,
                             communication_list,
                             action="remote/status",
                             output='{"corosync":false}')
Exemple #16
0
 def qdevice_net_sign_certificate(
     self, cluster_name, cert=b"cert", signed_cert=b"signed cert",
     node_labels=None, communication_list=None,
     name="http.corosync.qdevice_net_sign_certificate",
 ):
     place_multinode_call(
         self.__calls,
         name,
         node_labels,
         communication_list,
         action="remote/qdevice_net_sign_node_certificate",
         param_list=[
             ("certificate_request", base64.b64encode(cert)),
             ("cluster_name", cluster_name),
         ],
         output=base64.b64encode(signed_cert),
     )
Exemple #17
0
    def update_known_hosts(
        self,
        node_labels=None,
        to_add=None,
        to_add_hosts=None,
        communication_list=None,
        name="http.host.update_known_hosts",
    ):
        """
        Create a call for updating known hosts on the hosts.

        node_labels list -- create success responses from these nodes
        dict to_add -- records to add:
                {host_name: {dest_list: [{"addr": , "port": ,}]}}
        list to_add_hosts -- constructs to_add from host names
        communication_list list -- create custom responses
        name string -- the key of this call
        """
        if to_add_hosts and to_add:
            raise AssertionError(
                "Cannot specify both 'to_add_hosts' and 'to_add'")
        if to_add_hosts:
            to_add = {
                name: {
                    "dest_list": [{
                        "addr": name,
                        "port": settings.pcsd_default_port
                    }]
                }
                for name in to_add_hosts
            }
        add_with_token = {
            name: dict(data, token=None)
            for name, data in to_add.items()
        }
        place_multinode_call(
            self.__calls,
            name,
            node_labels,
            communication_list,
            action="remote/known_hosts_change",
            param_list=[("data_json",
                         json.dumps(
                             dict(known_hosts_add=add_with_token,
                                  known_hosts_remove={})))],
        )
Exemple #18
0
    def set_stonith_watchdog_timeout_to_zero(
            self,
            node_labels=None,
            communication_list=None,
            name="http.pcmk.set_stonith_watchdog_timeout_to_zero"):
        """
        Create a call for setting on hosts

        node_labels list -- create success responses from these nodes
        communication_list list -- create custom responses
        name string -- the key of this call
        """
        place_multinode_call(
            self.__calls,
            name,
            node_labels,
            communication_list,
            action="remote/set_stonith_watchdog_timeout_to_zero")
Exemple #19
0
    def get_quorum_status(
        self,
        node_list=None,
        node_labels=None,
        communication_list=None,
        name="http.host.get_quorum_status",
    ):
        output = ""
        if node_list:
            output = outdent("""\
            Quorum information
            ------------------
            Date:             Fri Jan 16 13:03:28 2015
            Quorum provider:  corosync_votequorum
            Nodes:            {nodes_num}
            Node ID:          1
            Ring ID:          19860
            Quorate:          Yes\n
            Votequorum information
            ----------------------
            Expected votes:   {nodes_num}
            Highest expected: {nodes_num}
            Total votes:      {nodes_num}
            Quorum:           {quorum_num}
            Flags:            Quorate\n
            Membership information
            ----------------------
                Nodeid      Votes    Qdevice Name
            {nodes}\
            """).format(nodes_num=len(node_list),
                        quorum_num=(len(node_list) // 2) + 1,
                        nodes="".join([
                            _quorum_status_node_fixture(node_id, node)
                            for node_id, node in enumerate(node_list, 1)
                        ]))

        place_multinode_call(
            self.__calls,
            name,
            node_labels,
            communication_list,
            action="remote/get_quorum_info",
            output=output,
        )
    def qdevice_client_stop(self,
                            name="http.corosync.qdevice_client_stop",
                            node_labels=None,
                            communication_list=None):
        """
        Create a call for stopping qdevice service

        string name -- the key of this call
        list node_labels -- create success responses from these nodes
        list communication_list -- create custom responses
        """
        place_multinode_call(
            self.__calls,
            name,
            node_labels,
            communication_list,
            action="remote/qdevice_client_stop",
            output="corosync-qdevice stopped",
        )
Exemple #21
0
    def start_cluster(
        self,
        node_labels=None,
        communication_list=None,
        name="http.host.start_cluster",
    ):
        """
        Create a call for starting cluster on the nodes.

        node_labels list -- create success responses from these nodes
        communication_list list -- create custom responses
        name string -- the key of this call
        """
        place_multinode_call(
            self.__calls,
            name,
            node_labels,
            communication_list,
            action="remote/cluster_start",
        )
Exemple #22
0
    def cluster_destroy(
        self,
        node_labels=None,
        communication_list=None,
        name="http.host.cluster_destroy",
    ):
        """
        Create a call for destroying a cluster on the hosts

        node_labels list -- create success responses from these nodes
        communication_list list -- create custom responses
        name string -- the key of this call
        """
        place_multinode_call(
            self.__calls,
            name,
            node_labels,
            communication_list,
            action="remote/cluster_destroy",
        )
Exemple #23
0
    def check_auth(self,
                   node_labels=None,
                   communication_list=None,
                   name="http.host.check_auth"):
        """
        Create a call for checking authentication on hosts

        node_labels list -- create success responses from these nodes
        communication_list list -- create custom responses
        name string -- the key of this call
        """
        place_multinode_call(
            self.__calls,
            name,
            node_labels,
            communication_list,
            action="remote/check_auth",
            output='{"success":true}',
            param_list=[("check_auth_only", 1)],
        )
Exemple #24
0
 def remove_nodes_from_cib(
     self,
     nodes_to_remove,
     node_labels=None,
     communication_list=None,
     name="http.pcmk.remove_nodes_from_cib",
 ):
     place_multinode_call(
         self.__calls,
         name,
         node_labels,
         communication_list,
         action="remote/remove_nodes_from_cib",
         param_list=[("data_json",
                      json.dumps(dict(node_list=nodes_to_remove)))],
         output=json.dumps(dict(
             code="success",
             message="",
         )),
     )
Exemple #25
0
    def set_corosync_conf(
        self, corosync_conf, node_labels=None, communication_list=None,
        name="http.corosync.set_corosync_conf"
    ):
        """
        Create a call for sending corosync.conf text

        string corosync_conf -- corosync.conf text to be sent
        list node_labels -- create success responses from these nodes
        list communication_list -- create custom responses
        string name -- the key of this call
        """
        place_multinode_call(
            self.__calls,
            name,
            node_labels,
            communication_list,
            action="remote/set_corosync_conf",
            param_list=[("corosync_conf", corosync_conf)],
            output="Succeeded",
        )
Exemple #26
0
    def send_pcsd_cert(self,
                       cert,
                       key,
                       node_labels=None,
                       communication_list=None,
                       name="http.host.send_pcsd_cert"):
        """
        Create a call for sending pcsd SSL cert and key

        string cert -- pcsd SSL certificate
        string key -- pcsd SSL key
        node_labels list -- create success responses from these nodes
        communication_list list -- create custom responses
        name string -- the key of this call
        """
        place_multinode_call(
            self.__calls,
            name,
            node_labels,
            communication_list,
            action="remote/set_certs",
            param_list=[("ssl_cert", cert), ("ssl_key", key)],
        )
Exemple #27
0
    def get_host_info(
        self,
        node_labels=None,
        output_data=None,
        communication_list=None,
        name="http.host.get_host_info",
    ):
        """
        Create a call for getting overall info about a host

        node_labels list -- create success responses from these nodes
        output_data dict -- default output data which will be converted to JSON
        communication_list list -- create custom responses
        name string -- the key of this call
        """
        place_multinode_call(
            self.__calls,
            name,
            node_labels,
            communication_list,
            action="remote/check_host",
            output=json.dumps(output_data) if output_data else "",
        )
Exemple #28
0
    def put_files(
        self,
        node_labels=None,
        pcmk_authkey=None,
        corosync_authkey=None,
        corosync_conf=None,
        pcs_settings_conf=None,
        communication_list=None,
        name="http.files.put_files",
    ):
        """
        Create a call for the files distribution to the nodes.

        node_labels list -- create success responses from these nodes
        pcmk_authkey bytes -- content of pacemaker authkey file
        corosync_authkey bytes -- content of corosync authkey file
        corosync_conf string -- content of corosync.conf
        pcs_settings_conf string -- content of pcs_settings.conf
        communication_list list -- create custom responses
        name string -- the key of this call
        """
        input_data = {}
        output_data = {}
        written_output_dict = dict(
            code="written",
            message="",
        )

        if pcmk_authkey:
            file_id = "pacemaker_remote authkey"
            input_data[file_id] = dict(
                data=base64.b64encode(pcmk_authkey).decode("utf-8"),
                type="pcmk_remote_authkey",
                rewrite_existing=True,
            )
            output_data[file_id] = written_output_dict

        if corosync_authkey:
            file_id = "corosync authkey"
            input_data[file_id] = dict(
                data=base64.b64encode(corosync_authkey).decode("utf-8"),
                type="corosync_authkey",
                rewrite_existing=True,
            )
            output_data[file_id] = written_output_dict

        if corosync_conf:
            file_id = "corosync.conf"
            input_data[file_id] = dict(
                data=corosync_conf,
                type="corosync_conf",
            )
            output_data[file_id] = written_output_dict

        if pcs_settings_conf:
            file_id = "pcs_settings.conf"
            input_data[file_id] = dict(
                data=pcs_settings_conf,
                type="pcs_settings_conf",
                rewrite_existing=True,
            )
            output_data[file_id] = written_output_dict

        place_multinode_call(self.__calls,
                             name,
                             node_labels,
                             communication_list,
                             action="remote/put_file",
                             param_list=[("data_json", json.dumps(input_data))
                                         ],
                             output=json.dumps(dict(files=output_data)))
Exemple #29
0
 def place_multinode_call(self, *args, **kwargs):
     place_multinode_call(self.__calls, *args, **kwargs)