The problem comes from create_target.
If the condition is not fulfilled, the
You should update Python to 3.6 or later.
Python 3.5 and 2.7 are End of Life: https://devguide.python.org/#status-of-python-branches
If you put your code into function, it's later easier to test.
Here your function:
If the condition is not fulfilled, the
target_id
is not assigned.You should update Python to 3.6 or later.
Python 3.5 and 2.7 are End of Life: https://devguide.python.org/#status-of-python-branches
If you put your code into function, it's later easier to test.
Here your function:
def create_target(ip_address): xml_data = ( f"--xml=<create_target><name>Subnet {ip_address} " f"</name><hosts> {ip_address} </hosts></create_target>" ) cmd = ["omp", "--username", "admin", "--password", "admin", xml_data] proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False, encoding="utf8") stdout, stderr = proc.communicate() if "OK" in stdout: print("target was created, target id:") target_id_tuple = re.findall(r'\w+(?:-\w+)+', stdout) target_id = target_id_tuple[0] print(target_id) return True elif "Failed to acquire socket." in stderr: print("omp service is not running") else: print(stdout, stderr) return False
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!