diff --git a/contrib/fuel-setup-network/fuel-setup-network b/contrib/fuel-setup-network/fuel-setup-network index 3a80bb4..a9ef6fe 100755 --- a/contrib/fuel-setup-network/fuel-setup-network +++ b/contrib/fuel-setup-network/fuel-setup-network @@ -4,7 +4,6 @@ import argparse from ipaddress import ip_network import os import shutil -import sys import tempfile import paramiko @@ -12,6 +11,10 @@ import psycopg2 import yaml +class EnvironmentDoesntExistException(Exception): + pass + + def get_env_networks(name, host='localhost', user='fuel_devops', database='fuel_devops', password='fuel_devops'): conn = psycopg2.connect(host=host, user=user, database=database, @@ -20,7 +23,14 @@ def get_env_networks(name, host='localhost', user='fuel_devops', cursor = conn.cursor() cursor.execute('SELECT DISTINCT id FROM devops_environment WHERE name=%s', [name]) - env_id = cursor.fetchone()[0] + + env_id = cursor.fetchone() + + if env_id is not None: + env_id = env_id[0] + else: + error = 'No environment named "{}" has been found.'.format(name) + raise EnvironmentDoesntExistException(error) cursor.execute(('SELECT name,ip_network FROM devops_network' ' WHERE environment_id=%s'), [env_id])