def stop_server(self): """ Stops the tgtd service :return: None """ try: shell.call_service_command('stop', 'tgtd', 'Dead') except ShellException: raise iscsi_exceptions.StopFailedException()
def stop_server(self): """ Stops the iSCSI server. Returns: None if successful or an exception """ # TODO: Same as for start function regarding strings. self.server_status = "Dead" if self.show_status() is not "Dead": raise iscsi_exceptions.StopFailedException()
def start_server(self): """ Starts the iSCSI server. Returns: None, if successful or an exception. """ # TODO: See my previous comment, modify strings to constants. self.server_status = "Running" if self.show_status() is not "Running": # TODO: I think its better to have a generic StateChangeException. raise iscsi_exceptions.StopFailedException()
def stop_server(self): command = "echo {0} | sudo -S service iscsitarget stop".format( self.password) p = subprocess.Popen(command, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE) output, err = p.communicate() # output = sh.service.iscsitarget.stop() if p.returncode == 0: return output.strip() else: logger.info("Raising Stop Failed Exception") raise iscsi_exceptions.StopFailedException()
def __check_status(self, on): output = sh.service.iscsitarget.status(_ok_code=[0, 3]) ansi_escape = re.compile(r'\x1b[^m]*m') output = ansi_escape.sub('', output.strip()) parts = output.split("\n") active = not on targets = [] failed_mount = [] duplicates = [] for part in parts: s_part = part.strip() if s_part.startswith("Active"): line_parts = s_part.split() if line_parts[1] + line_parts[2] == "active(running)": active = True if line_parts[1] + line_parts[2] == "inactive(dead)": active = False elif s_part.find("created target") != -1: line = s_part[s_part.find("created target"):].split() targets.append(line[2].split(".")[2]) elif s_part.find("unable to create logical unit") != -1: target = targets.pop() failed_mount.append(target) elif s_part.find("duplicated target") != -1: line = s_part[s_part.find("duplicated target"):].split() duplicates.append(line[2].split(".")[2]) if failed_mount: logger.info("Raising Mount Exception for %s", failed_mount) raise iscsi_exceptions.MountException(failed_mount) if duplicates: logger.info("Raising Mount Exception for %s", duplicates) raise iscsi_exceptions.DuplicatesException(duplicates) if not active and on: logger.info("Raising Restart Failed Exception") raise iscsi_exceptions.RestartFailedException() elif not on and active: logger.info("Raising Stop Failed Exception") raise iscsi_exceptions.StopFailedException()