Example #1
0
 def modify_config(self,host,etcd,master,worker,vip,port):
     editor = utils.FileEdit("./sample-kk.yaml")
     editor.insert_data(host,anchor="  hosts:",type="under")
     editor.insert_data(etcd,anchor="    etcd:",type="under")
     editor.insert_data(master,anchor="    master:",type="under")
     editor.insert_data(worker,anchor="    worker:",type="under")
     editor.replace_data('    address: ""',f'    address: {vip}')
     editor.replace_data('    port: 8443',f'    port: {port}')
     utils.exec_cmd(f"echo '{editor.data}' > config-sample.yaml", self.conn)
Example #2
0
    def modify_conf(self,filepath,router_id, interface, virtual_router_id, priority,unicast_src_ip, unicast_peer_list, virtual_ipaddress):
        editor = utils.FileEdit("./sample-keepalived.conf")
        editor.replace_data("router_id LVS_DEVEL",f"router_id {router_id}")
        editor.replace_data("priority 100",f"priority {priority}")
        editor.replace_data("interface eno1", f"interface {interface}")
        editor.replace_data("virtual_router_id 60",f"virtual_router_id {virtual_router_id}")
        editor.replace_data("unicast_src_ip 127.0.0.1", f"unicast_src_ip {unicast_src_ip}")
        unicast_peer_data = ""
        for unicast_peer in unicast_peer_list:
            unicast_peer_data += f"    {unicast_peer}\n"
        editor.insert_data(unicast_peer_data,anchor="  unicast_peer {",type='under')
        editor.insert_data(f"    {virtual_ipaddress}",anchor="  virtual_ipaddress {",type='under')

        editor.data = rf"{editor.data}"
        utils.exec_cmd(f"echo '{editor.data}' > {filepath}", self.conn)
Example #3
0
    def change_corosync_conf(self, cluster_name, bindnetaddr_list, interface,
                             nodelist):
        # editor = utils.FileEdit(corosync_conf_path) # 读取原配置文件数据
        editor = utils.FileEdit(read_data)

        editor.replace_data(
            f"cluster_name: {self.original_attr['cluster_name']}",
            f"cluster_name: {cluster_name}")
        editor.replace_data(
            f"bindnetaddr: {self.original_attr['bindnetaddr']}",
            f"bindnetaddr: {bindnetaddr_list[0]}")
        editor.insert_data(interface, anchor=self.interface_pos, type='under')
        editor.insert_data(nodelist, anchor=self.nodelist_pos, type='above')
        if len(bindnetaddr_list) > 1:
            editor.insert_data(f'\trrp_mode: passive',
                               anchor='        # also set rrp_mode.',
                               type='under')

        utils.exec_cmd(f'echo "{editor.data}" > {corosync_conf_path}',
                       self.conn)
Example #4
0
 def recover_conf(self):
     editor = utils.FileEdit(read_data)  # 恢复原始配置文件,需要read_data存在
     utils.exec_cmd(f'echo "{editor.data}" > {corosync_conf_path}',
                    self.conn)
Example #5
0
 def modify_cfg(self,file_path,data):
     editor = utils.FileEdit("./sample-haproxy.cfg")
     editor.insert_data(f"{data}",f'    default-server inter 10s downinter 5s rise 2 fall 2 slowstart 60s maxconn 250 maxqueue 256 weight 100', type='under')
     utils.exec_cmd(f"echo '{editor.data}' > {file_path}", self.conn)