def reconfigure_interface(host, address, netmask, gateway): cuisine.connect('test%s' % i) # Assume only two interfaces: 'eth*' and 'lo' eth_name = cuisine.run('ifconfig -s').split('\n')[1].split()[0] interfaces_config = '''auto lo iface lo inet loopback auto %(eth_name)s iface %(eth_name)s inet static address %(address)s netmask %(netmask)s gateway %(gateway)s dns-nameservers 192.168.1.11 ''' interfaces_config = interfaces_config % {'eth_name': eth_name, 'address': address, 'netmask': netmask, 'gateway': gateway} cuisine.file_update('/etc/network/interfaces', lambda _: interfaces_config) cuisine.run('echo "ifdown %(eth_name)s; ifup %(eth_name)s" | at now + 1 minute' % {'eth_name': eth_name})
def reconfigure_interface(host, address, netmask, gateway): cuisine.connect('test%s' % i) # Assume only two interfaces: 'eth*' and 'lo' eth_name = cuisine.run('ifconfig -s').split('\n')[1].split()[0] interfaces_config = '''auto lo iface lo inet loopback auto %(eth_name)s iface %(eth_name)s inet static address %(address)s netmask %(netmask)s gateway %(gateway)s dns-nameservers 192.168.1.11 ''' interfaces_config = interfaces_config % { 'eth_name': eth_name, 'address': address, 'netmask': netmask, 'gateway': gateway } cuisine.file_update('/etc/network/interfaces', lambda _: interfaces_config) cuisine.run( 'echo "ifdown %(eth_name)s; ifup %(eth_name)s" | at now + 1 minute' % {'eth_name': eth_name})
import yaml import sys import json import cuisine __author__ = "Anoop P Alias" __copyright__ = "Copyright 2014, PiServe Technologies Pvt Ltd , India" __license__ = "GPL" __email__ = "*****@*****.**" installation_path = "/opt/nDeploy" # Absolute Installation Path cluster_config_file = installation_path+"/conf/ndeploy_cluster.yaml" cluster_data_yaml = open(cluster_config_file, 'r') cluster_data_yaml_parsed = yaml.safe_load(cluster_data_yaml) cluster_data_yaml.close() serverlist = cluster_data_yaml_parsed.keys() cpjson = json.load(sys.stdin) mydict = cpjson["data"] cpaneluser = mydict["user"] for server in serverlist: connect_server_dict = cluster_data_yaml_parsed.get(server) connect_ip = connect_server_dict.get("connect") cuisine.connect(connect_ip) cuisine.user_remove_linux(cpaneluser, rmhome=True) cuisine.run('if [ -f '+installation_path+'/php-fpm.d/'+cpaneluser+'.conf ] ;then rm -f '+installation_path+'/php-fpm.d/'+cpaneluser+'.conf ;fi') cuisine.run(installation_path+"/scripts/init_backends.py reload") print("1 nDeploy:clusteraccountdelete:"+cpaneluser)
pass else: print("The hostname of master: "+masterserver+" is invalid") sys.exit(1) if is_valid_hostname(slaveserver): pass else: print("The hostname of slave: "+slaveserver+" is invalid ") sys.exit(1) print("Installing csync2,unison and lsyncd") subprocess.call('yum --enablerepo=ndeploy -y install lsyncd csync2-nDeploy unison-nDeploy', shell=True) sed_cmd1 = 'sed -i "s/MASTERSERVER/'+masterserver+'/g" /etc/csync2/csync2.cfg' sed_cmd2 = 'sed -i "s/SLAVESERVER/'+slaveserver+'/g" /etc/csync2/csync2.cfg' subprocess.call(sed_cmd1, shell=True) subprocess.call(sed_cmd2, shell=True) cuisine.connect(slaveserver) cuisine.run("yum -y install epel-release http://rpm.piserve.com/nDeploy-release-centos-1.0-1.noarch.rpm") print("Next operation may take some time to complete. Please wait till it completes...") cuisine.run("yum --enablerepo=ndeploy -y install lsyncd csync2-nDeploy unison-nDeploy nginx-nDeploy nDeploy-cluster-slave") subprocess.call('csync2 -k /etc/csync2/csync2.key', shell=True) cuisine.rsync("/etc/csync2/", "/etc/csync2/") if not os.path.isdir("/root/.unison"): os.mkdir("/root/.unison") sed_cmd3 = 'sed "s/SLAVESERVER/'+slaveip+'/g" '+installation_path+'/conf/default.prf > /root/.unison/default.prf' subprocess.call(sed_cmd3, shell=True) rsync_cmd1 = 'rsync -av '+installation_path+'/conf/lsyncd_master.conf /etc/lsyncd.conf' subprocess.call(rsync_cmd1, shell=True) sed_cmd4 = 'sed -e "s/MASTERSERVER/'+masteripalone+'/g" -e "s/MASTERSSHPORT/'+masterport+'/g" '+installation_path+'/conf/lsyncd_slave.conf > /tmp/nDeploy_lsyncd.conf' subprocess.call(sed_cmd4, shell=True) cuisine.rsync("/tmp/nDeploy_lsyncd.conf", "/etc/lsyncd.conf") os.remove("/tmp/nDeploy_lsyncd.conf")
import cuisine, os TEXT = "file_write is broken" PATH = "/tmp/cuisine-bug-124.txt" if os.path.exists(PATH): os.unlink(PATH) cuisine.connect("localhost") cuisine.file_write(PATH, TEXT) assert os.path.exists(PATH), "file_write did not create file %s" % (PATH) with open(PATH) as f: text = f.read() assert TEXT == text, "Expected: %s, got %s" % (repr(TEXT), repr(text)) print("OK") # EOF
__copyright__ = "Copyright 2014, PiServe Technologies Pvt Ltd , India" __license__ = "GPL" __email__ = "*****@*****.**" installation_path = "/opt/nDeploy" # Absolute Installation Path cluster_config_file = installation_path + "/conf/ndeploy_cluster.yaml" cluster_data_yaml = open(cluster_config_file, 'r') cluster_data_yaml_parsed = yaml.safe_load(cluster_data_yaml) cluster_data_yaml.close() serverlist = cluster_data_yaml_parsed.keys() cpjson = json.load(sys.stdin) mydict = cpjson["data"] cpaneluser = mydict["user"] cpaneluserhome = mydict["homedir"] cpaneldomain = mydict["domain"] cpdomainyaml = "/var/cpanel/userdata/" + cpaneluser + "/" + cpaneldomain cpaneldomain_data_stream = open(cpdomainyaml, 'r') yaml_parsed_cpaneldomain = yaml.safe_load(cpaneldomain_data_stream) cpanel_ipv4 = yaml_parsed_cpaneldomain.get('ip') for server in serverlist: connect_server_dict = cluster_data_yaml_parsed.get(server) connect_ip = connect_server_dict.get("connect") cuisine.connect(connect_ip) cuisine.user_create_linux(cpaneluser, home=cpaneluserhome) ipmap_dict = connect_server_dict.get("ipmap") remote_domain_ip = ipmap_dict.get(cpanel_ipv4) subprocess.call(installation_path + "/scripts/cluster_dns_setup.pl add " + cpaneldomain + " " + remote_domain_ip, shell=True) print("1 nDeploy:clusteraccountcreate:" + cpaneluser)
print("The hostname of master: " + masterserver + " is invalid") sys.exit(1) if is_valid_hostname(slaveserver): pass else: print("The hostname of slave: " + slaveserver + " is invalid ") sys.exit(1) print("Installing csync2,unison and lsyncd") subprocess.call( 'yum --enablerepo=ndeploy -y install lsyncd csync2-nDeploy unison-nDeploy', shell=True) sed_cmd1 = 'sed -i "s/MASTERSERVER/' + masterserver + '/g" /etc/csync2/csync2.cfg' sed_cmd2 = 'sed -i "s/SLAVESERVER/' + slaveserver + '/g" /etc/csync2/csync2.cfg' subprocess.call(sed_cmd1, shell=True) subprocess.call(sed_cmd2, shell=True) cuisine.connect(slaveserver) cuisine.run( "yum -y install epel-release http://rpm.piserve.com/nDeploy-release-centos-1.0-1.noarch.rpm" ) print( "Next operation may take some time to complete. Please wait till it completes..." ) cuisine.run( "yum --enablerepo=ndeploy -y install lsyncd csync2-nDeploy unison-nDeploy nginx-nDeploy nDeploy-cluster-slave" ) subprocess.call('csync2 -k /etc/csync2/csync2.key', shell=True) cuisine.rsync("/etc/csync2/", "/etc/csync2/") if not os.path.isdir("/root/.unison"): os.mkdir("/root/.unison") sed_cmd3 = 'sed "s/SLAVESERVER/' + slaveip + '/g" ' + installation_path + '/conf/default.prf > /root/.unison/default.prf' subprocess.call(sed_cmd3, shell=True)
import cuisine, os TEXT = "file_write is broken" PATH = "/tmp/cuisine-bug-124.txt" if os.path.exists(PATH): os.unlink(PATH) cuisine.connect("localhost") cuisine.file_write(PATH, TEXT) assert os.path.exists(PATH), "file_write did not create file %s" % (PATH) text = file(PATH).read() assert TEXT == text, "Expected: %s, got %s" % (repr(TEXT), repr(text)) print "OK" # EOF