def create_diskpool(self, vd_name): ''' This method create diskpool. Arguments : None Return: None ''' uri = "pools" payload_dict = { "Name": "diskpool 1", "Server": self.server_id, "Disks": self.disk_pool_disk[0:1] } if vd_name.lower() != "standard": payload_dict["Deduplication"] = "True" res = ILDC().do_create_pool(uri, header=None, payload=payload_dict) msg = "Diskpool created successfully with capacity optimization" time.sleep(2) self.verification(res.json(), msg) self.pool_id = res.json()['Id'] if len(self.disk_pool_disk) > 1: self.add_disk_to_pool() msg = "Reclamation started..." print(msg) LogCreat().logger_info.info(msg) time.sleep(30) disk_id = self.get_disks_id() while (self.reclamation(disk_id) == False): print(".", sep='', end='', flush=True) time.sleep(30) print("\n") msg = "Reclamation completed" print(msg) LogCreat().logger_info.info(msg)
def set_vd_properties(self, virtual_disk): ''' This method used to set virtual disk property. Arguments (str): virtual disk Return: None ''' payload = {} #Once the VD is created set virtual disk properties if virtual_disk.lower() != "standard": if virtual_disk.lower().strip() == "ildc": payload["Deduplication"] = True payload["Compression"] = True elif virtual_disk.lower() == "ild": payload["Deduplication"] = True elif virtual_disk.lower() == "ilc": payload["Compression"] = True uri = "virtualdisks/" + self.vd_id res = ILDC().do_enable_cap_opt_on_vd(uri, header=None, payload=payload) msg = virtual_disk + " property enable at virtual disk level" if str(res) == '<Response [200]>': print(msg) LogCreate().logger_info.info(msg) else: self.verification(res.json(), msg)
def create_diskpool(self, vd_name): ''' This method create diskpool. Arguments : None Return: None ''' uri = "pools" payload_dict = { "Name": "diskpool 1", "Server": self.server_id, "Disks": self.disk_pool_disk[0:1] } if vd_name.lower() != "standard": payload_dict["Deduplication"] = "True" res = ILDC().do_create_pool(uri, header=None, payload=payload_dict) msg = "Diskpool created successfully with CO" time.sleep(2) self.verification(res.json(), msg) self.pool_id = res.json()['Id'] if len(self.disk_pool_disk) > 1: self.add_disk_to_pool() while True: flag = self.reclamination() if flag == 1: break
def start_server(self): ''' This method used to start server. Arguments : None Return: None ''' uri = "servers/" + self.server_id payload_dict = {"Operation": "StartServer"} res = ILDC().do_serve_on_off(uri, header=None, payload=payload_dict) msg = "Start server successfully" self.verification(res.json(), msg)
def get_host(self): ''' This method used to get host details. Arguments : None Return: None ''' uri = 'hosts' res = ILDC().do_ssy_details(uri, header=None) msg = 'Get host details' if str(res) == '<Response [200]>': LogCreate().logger_info.info(msg) else: self.verification(res.json(), msg)
def create_file(self, file_name, vd_name, diskindex, workload): ''' This method create dynamic folder structure to store results of VdBench Parameters ---------- file_name : str it store workload file path vd_name : str store virtual disk name diskindex : str store virtual disk index workload : str store type of virtual disk Returns ------- workload_path : str store workload path result_path : str store result path where need to store the vdbench results ''' uri = "servers" res = ILDC().do_ssy_details(uri, header=None) self.build = res.json()[0]['ProductBuild'] workload_path = os.path.abspath( r'../../../Config/VdBench_config/Workload') self.absulute = os.path.abspath(r'../../../Result/Vdbench') self.new_ = self.absulute + '/' + self.build + '_' + self.time_stamp + '/' if file_name.split('.')[0] == '4-4k-4-fill': result_path = self.new_ + vd_name + '/' + workload + '_' + file_name.split( '.')[0] else: result_path = self.new_ + vd_name + '/' + vd_name + '_' + file_name.split( '.')[0] workload_path = os.path.join(workload_path, file_name) file = open(workload_path, "r+") data = file.readlines() file.close() for index, val in enumerate(data): split_ = val.split('PhysicalDrive') if len(split_) > 1: data[index] = split_[0] + "PhysicalDrive" + str( diskindex) + "\n" file = open(workload_path, "w") for _ in data: file.write(_) file.close() return workload_path, result_path
def delete_pool(self): ''' This method used to delete diskpool. Arguments : None Return: None ''' uri = "pools/" + self.pool_id res = ILDC().do_pool_delete(uri) msg = "Diskpool deleted successfully" if str(res) == '<Response [200]>': print(msg) LogCreate().logger_info.info(msg) else: self.verification(res.json(), msg)
def delete_vd(self): ''' This method used to delete virtual disk. Arguments : None Return: None ''' uri = "virtualdisks/" + self.vd_id res = ILDC().do_vd_delete(uri) msg = "Virtual disk deleted" if str(res) == '<Response [200]>': print(msg) LogCreate().logger_info.info(msg) else: self.verification(res.json(), msg)
def get_server(self): ''' This method collect all results of SSY required to update in HTML file Arguments : None Return: None ''' uri = "servers" res = ILDC().do_ssy_details(uri, header=None) self.build = res.json()[0]['ProductBuild'] host = res.json()[0]['HostName'] ram = res.json()[0]['TotalSystemMemory']['Value'] ram_ = str(round(int(ram) / 1073741824, 2)) ram_ = ram_ + ' GB' available_memory = res.json()[0]['AvailableSystemMemory']['Value'] sync = res.json()[0]['IldcConfigurationData']['IldcSyncMode'] primaycach = res.json( )[0]['IldcConfigurationData']['IldcPrimaryCacheMode'] ssy = int(ram) - int(available_memory) ssy = (round((ssy) / 1073741824, 2)) ssy = str(ssy) + ' GB' if self.merge_list[0] != '-': zfs = int(self.zfs_max) / 1073741824 zfs = str(round(zfs, 2)) zfs = zfs + ' GB' else: zfs = '-' vd_size = '500GB' self.data_put = [ self.build, host, str(zfs), str(ssy), primaycach, ram_, sync, vd_size ]
def get_server(self): ''' This method used to get server details. Arguments : None Return: None ''' uri = "servers" res = ILDC().do_ssy_details(uri, header=None) self.server_id = res.json()[0]['Id'] msg = 'Get server details' if str(res) == '<Response [200]>': LogCreate().logger_info.info(msg) else: self.verification(res.json(), msg)
def un_server_vd(self): ''' This method used to unserve virtual disk from host. Arguments : None Return: None ''' uri = "virtualdisks/" + self.vd_id payload_dict = {"Operation": "Unserve", "Host": self.server_id} res = ILDC().do_serve_vd(uri, header=None, payload=payload_dict) msg = "Unserve Virtual disk sucessfuly" if str(res) == '<Response [200]>': print(msg) LogCreate().logger_info.info(msg) else: self.verification(res.json(), msg)
def test_create_virtual_disk(self, virtual_disk): ''' This method used to create Virtual disk. Arguments (str): virtual disk Return: None ''' uri = "virtualdisks" vd_payload = { "Name": virtual_disk + "_VD", "Description": "Description of virtual disk", "Size": "500GB", "SectorSize": "512B", "PoolVolumeType": "0", # 0-stripped, 1-spanned, "Pool": self.pool_id, "Type": "0", "Count": "1", } res = ILDC().do_create_vd(uri, header=None, payload=vd_payload) msg = "Virtual disk created successfully" if str(res) == '<Response [200]>': print(msg) LogCreate().logger_info.info(msg) else: self.verification(json.loads(res.content), msg) res = json.loads(res.content) if len(res) != 0: vd_id = [x["Id"] for x in res] self.vd_id = vd_id[0]
def reclamination(self): ''' This method verify reclamination of diskpool. Arguments : None Return (int): self.flag ''' uri = "performancebytype/DiskPoolPerformance" res = ILDC().do_ssy_details(uri, header=None) if res.json() != []: for _ in res.json(): for key, val in _.items(): if key == 'PerformanceData' and val[ "BytesInReclamation"] == 0: self.flag = 1 time.sleep(60) return self.flag
def test_enable_cap_opt_at_server(self): ''' This method Enable capacity optimization at server level. Arguments : None Return: None ''' uri = "servers/" + self.server_id payload_dict = { "Operation": "EnableCapacityOptimization", "Disks": self.co_disk, } res = ILDC().do_enable_capacity_optimization(uri, header=None, payload=payload_dict) msg = "Capacity Optimization is enabled successfully at server level" self.verification(res.json(), msg)
def run(self): ''' This method validate disk is used by othere process. If its used by othere process it will raise error and stop execution of tool. Arguments : None Return: None ''' flag = 0 self.read_config() pd_ids = self.get_physical_disk_id() for _ in self.disk: ILDC().clean_diskpart(_) if int(_) not in pd_ids.keys(): msg = 'Disk index ' + str(_) + ' Already used by other process' print(msg) LogCreate().logger_error.error(msg) flag = 1 else: if _ in self.config_dict['co disk']: self.co_disk.append(pd_ids[int(_)]) else: self.disk_pool_disk.append(pd_ids[int(_)]) del self.config_dict return flag
def run(self): ''' This method validates if disk is used by other process. If it is used by other process it will raise error and stop execution of tool. Arguments : None Return (int): flag ''' flag = 0 flag = self.read_config() time.sleep(120) pd_ids = self.get_physical_disk_id() for _ in self.disk: ILDC().clean_diskpart(_) if int(_) not in pd_ids.keys(): msg = 'Disk index ' + str(_) + ' Already used by other process' print(msg) LogCreat().logger_error.error(msg) flag = 1 else: if _ in self.config_dict['co disk']: self.co_disk.append(pd_ids[int(_)]) elif _ in self.config_dict['diskpool_disk']: self.disk_pool_disk.append(pd_ids[int(_)]) elif _ in self.config_dict['l2arc_disk']: self.l2arc.append(pd_ids[int(_)]) else: self.slog.append(pd_ids[int(_)]) self.release_disk(pd_ids[int(_)]) time.sleep(1) return flag
def add_disk_to_pool(self): ''' This method add disks to diskpool. Arguments : None Return: None ''' uri = "pools/" + self.pool_id payload_dict = { "Operation": "AddDisks", "Disks": self.disk_pool_disk[1:] } res = ILDC().do_create_pool(uri, header=None, payload=payload_dict) msg = "Disks are added to Diskpool" if str(res) == '<Response [200]>': LogCreate().logger_info.info(msg) else: self.verification(res.json(), msg)
def get_server(self): ''' This method collect all results of SSY required to update in HTML file Returns ------- None. ''' status_slog = 'OFF' status_l2arc = 'OFF' status_encrp = 'OFF' configur = ConfigParser() configur.read(r"../../../Config/VdBench_config/VDBench_config.ini") print('check', configur.get('first run', 'slog_flag'), configur.get('first run', 'l2arc_flag'), configur.get('first run', 'enryption_flag')) if configur.get('first run', 'slog_flag').strip() == 'True': status_slog = 'ON' if configur.get('first run', 'l2arc_flag').strip() == 'True': status_l2arc = 'ON' if configur.get('first run', 'enryption_flag').strip() == 'True': status_encrp = 'ON' uri = "servers" res = ILDC().do_ssy_details(uri, header=None) self.build = res.json()[0]['ProductBuild'] host = res.json()[0]['HostName'] ram = res.json()[0]['TotalSystemMemory']['Value'] ram_ = str(round(int(ram) / 1073741824, 2)) ram_ = ram_ + ' GB' # available = res.json()[0]['AvailableSystemMemory']['Value'] sync = res.json()[0]['IldcConfigurationData']['IldcSyncMode'] primaycach = res.json( )[0]['IldcConfigurationData']['IldcPrimaryCacheMode'] # ssy = int(ram) - int(available) # ssy = (round((ssy)/1073741824,2)) # ssy = str(ssy) + ' GB' ssy = int(ram) * 0.65 if self.merge_list[0] != '-': zfs = int(self.zfs_max) / 1073741824 ssy = int(round((ssy) / 1073741824, 2)) ssy = ssy - zfs zfs = str(round(zfs, 2)) ssy = str(int(ssy)) + ' GB' zfs = zfs + ' GB' else: zfs = '-' ssy = str(int(ssy)) + ' GB' self.data_put = [ self.build, host, str(zfs), str(ssy), primaycach, ram_, sync, '500GB', status_slog, status_encrp ]
def test_disable_cap_opt_at_server(self): ''' This method used to disable capacity optimization at server level. Arguments : None Return: None ''' uri = "servers/" + self.server_id payload_dict = { "Operation": "RemoveCapacityOptimizationDisks", "Disks": self.co_disk, } res = ILDC().do_disable_capacity_optimization(uri, header=None, payload=payload_dict) msg = "Capacity Optimization disabled successfully at server" response_flag = self.verification(res.json(), msg) if response_flag == 1: print( "Rest API for disabling the Capacity optimization failed, trying PowerShell" ) LogCreat().logger_error.error( 'Rest API for disabling the Capacity optimization failed, trying PowerShell' ) cmd = "powershell.exe -File \'C:/Program Files/DataCore/Powershell Support\Register-DcsCmdlets.ps1\'" + "\n" process = subprocess.Popen( ['powershell', cmd], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf8', universal_newlines=True, bufsize=0, creationflags=subprocess.CREATE_NEW_CONSOLE) process.stdin.write("connect-dcsserver" + "\n") process.stdin.write("Disable-DcsCapacityOptimization" + "\n") process.stdin.write(self.server_id + "\n") process.stdin.close() output = process.stdout.read().split('\n') LogCreat().logger_info.info(output)
def create_file(self, file_name, vd_name, diskindex, workload): ''' This method create dynamic folder structure to store results of VdBench Arguments (str, str, int): file_name,vd_name,diskindex Return (str, str): workload_path, result_path ''' uri = "servers" res = ILDC().do_ssy_details(uri, header=None) self.build = res.json()[0]['ProductBuild'] workload_path = os.path.abspath( r'../../../Config/VdBench_config/Workload') self.absulute = os.path.abspath(r'../../../Result/Vdbench') self.new_ = self.absulute + '/' + self.build + '_' + self.time_stamp + '/' if file_name.split('.')[0] == '4-4k-4-fill': result_path = self.new_ + vd_name + '/' + workload + '_' + file_name.split( '.')[0] else: result_path = self.new_ + vd_name + '/' + vd_name + '_' + file_name.split( '.')[0] workload_path = os.path.join(workload_path, file_name) with open(workload_path) as file: # file = open(workload_path, "r+") data = file.readlines() file.close() for index, val in enumerate(data): split_ = val.split('PhysicalDrive') if len(split_) > 1: data[index] = split_[0] + "PhysicalDrive" + str( diskindex) + "\n" with open(workload_path, 'w') as file: # file = open(workload_path, "w") for _ in data: file.write(_) file.close() return workload_path, result_path
def release_disk(self, disk): ''' This function release disk to OS Parameters ---------- disk : str this is disk id which used to release disk Returns ------- None. ''' uri = "physicaldisks/" + disk ILDC().do_enable_capacity_optimization(uri, header=None, payload=None)
def initialize_vd(self): ''' This method used to initialize virtual disk. Arguments : None Return: None ''' uri = "physicaldisks" pd_data = Disks().do_get_physical_disks(uri, header=None) pd_data = json.loads(pd_data.content) for i in range(len(pd_data)): for key, val in pd_data[i].items(): if key == "VirtualDiskId" and val in self.vd_id: diskindex = pd_data[i]['DiskIndex'] ILDC().initial_disk(diskindex) msg = "Initialized Virtual disk" print(msg) LogCreate().logger_info.info(msg) break return diskindex
def test_serve_vd_to_host(self): ''' This method used serve virtual disk to host. Arguments : None Return: None ''' uri = "virtualdisks/" + self.vd_id serve_payload = { "Operation": "Serve", "Host": self.server_id, "Redundancy": "false" } res = ILDC().do_serve_vd(uri, header=None, payload=serve_payload) msg = "Virtual disk server to the host" if str(res) == '<Response [200]>': print(msg) LogCreate().logger_info.info(msg) else: self.verification(res, msg)