def set_pm_partition_info(self,pm_partition_data): ''' 执行划分分区主函数 ''' partition_result = False for host_ip in self.iplist: if 'data' in pm_partition_data: data_mount_dir = pm_partition_data['data']['mount_dir'] data_mount_type = pm_partition_data['data']['mount_type'] data_mount_path = pm_partition_data['data']['path'] partition_data_result = self.check_new_partition(host_ip,data_mount_dir,data_mount_type,data_mount_path) if not partition_data_result: print "host: %s partition data failed! please check it~" % host_ip return False if 'other' in pm_partition_data: other_mount_dir = pm_partition_data['other']['mount_dir'] other_mount_type = pm_partition_data['other']['mount_type'] other_mount_path = pm_partition_data['other']['path'] partition_other_result = self.check_new_partition(host_ip,other_mount_dir,other_mount_type,other_mount_path) if not partition_other_result: print "host: %s partition other failed! please check it~" % host_ip return False cmd = "mount -a" remote_user = "******" deal_ssh.remote_ssh_key_exec_simple_online(host_ip,remote_user,cmd)
def check_new_partition(self,host_ip,new_mount_dir,new_mount_type,mount_path): ''' 检查/etc/fstab 分区信息 ''' result = "" remote_user = "******" sql = "select partition_name,partition_type from partition_info where (server_busi_ip = (select host_busi_ip from server_info where host_busi_ip = '%s' or host_data_ip = '%s')) and ( partition_mount_point = '%s')" result = super(Exec_partition_cls, self).select_with_desc(sql,host_ip,host_ip,mount_path) if len(result) > 1: return False else: old_mount_dir = result[0]['partition_name'] old_mount_type = result[0]['partition_type'] if len(result) == 0: #没有找目录和路径 cmd = self.partition_new(new_mount_dir,new_mount_type,mount_path) deal_ssh.remote_ssh_key_exec_simple_online(host_ip,remote_user,cmd) elif len(result) == 1: if (old_mount_dir == new_mount_dir) and (old_mount_type == new_mount_type): pass elif (old_mount_dir != new_mount_dir) and (old_mount_type == new_mount_type): cmd = self.clean_partion_old(old_mount_dir,mount_path) deal_ssh.remote_ssh_key_exec_simple_online(host_ip,remote_user,cmd) cmd = self.rename_partion_old(new_mount_dir,new_mount_type,mount_path) deal_ssh.remote_ssh_key_exec_simple_online(host_ip,remote_user,cmd) elif (old_mount_dir == new_mount_dir) and (old_mount_type != new_mount_type): cmd = self.clean_partion_old(old_mount_dir,mount_path) deal_ssh.remote_ssh_key_exec_simple_online(host_ip,remote_user,cmd) cmd = self.partition_new(new_mount_dir,new_mount_type,mount_path) deal_ssh.remote_ssh_key_exec_simple_online(host_ip,remote_user,cmd) else: print "Unknow partition type!" return False return True
def set_vm_partition_info(self): ''' 处理虚机分区信息 ''' new_partition_cmd,replace_partition_cmd = "","" data_partition = re.compile("(/data[0-9]*)") search_partition = re.compile("/search(.*)") exsit_data_partition = False exsit_partition = False new_partition_cmd = "mkfs.xfs /dev/vdb;mkdir /data;echo \"/dev/vdb /data xfs defaults,noatime,nodiratime 0 0\" >> /etc/fstab;mount -a" replace_partition_cmd = "umount /dev/vdb;sed -i '/\/dev\/vdb/d' /etc/fstab;echo \"/dev/vdb /data xfs defaults,noatime,nodiratime 0 0\" >> /etc/fstab;mkdir /data ;mount -a;df -h" for host_ip in self.iplist: sql = "select partition_mount_point,partition_name from partition_info where server_busi_ip in (select host_busi_ip from server_info where host_busi_ip = '%s' or host_data_ip = '%s') and (partition_name like '%%search%%' or partition_name like '%%data%%')" result = super(Exec_partition_cls, self).select_with_desc(sql,host_ip,host_ip) partition_comfortable = 0 for partitions_data in result: if data_partition.match(partitions_data['partition_name']): exsit_data_partition = True elif search_partition.match(partitions_data['partition_name']): exsit_search_partition = True if not exsit_data_partition: if not exsit_search_partition: result = deal_ssh.remote_ssh_key_exec_simple_online(host_ip,self.remote_user,new_partition_cmd) if not result: print "host: %s partition failed" % host_ip else: result = deal_ssh.remote_ssh_key_exec_simple_online(host_ip,self.remote_user,replace_partition_cmd) if not result: print "host: %s partition failed" % host_ip else: print "exsit_data_partition"