summaryrefslogtreecommitdiffstats
path: root/utils/env_prepare
diff options
context:
space:
mode:
Diffstat (limited to 'utils/env_prepare')
-rw-r--r--utils/env_prepare/quota_prepare.py27
-rw-r--r--utils/env_prepare/stack_prepare.py37
2 files changed, 61 insertions, 3 deletions
diff --git a/utils/env_prepare/quota_prepare.py b/utils/env_prepare/quota_prepare.py
index 267e70ab..8dcdf3d6 100644
--- a/utils/env_prepare/quota_prepare.py
+++ b/utils/env_prepare/quota_prepare.py
@@ -42,14 +42,37 @@ nova_quota = {"ram": -1,
"injected_file_path_bytes": -1}
+def check_https_enabled():
+ LOG.debug("Check if https is enabled in OpenStack")
+ os_auth_url = os.getenv('OS_AUTH_URL')
+ if os_auth_url.startswith('https'):
+ LOG.debug("https is enabled")
+ return True
+ LOG.debug("https is not enabled")
+ return False
+
+
def quota_env_prepare():
+ https_enabled = check_https_enabled()
+ insecure_option = ''
+ insecure = os.getenv('OS_INSECURE',)
+ if https_enabled:
+ LOG.info("https is enabled")
+ if insecure:
+ if insecure.lower() == "true":
+ insecure_option = ' --insecure '
+ else:
+ LOG.warn("Env variable OS_INSECURE is {}: if https + no "
+ "credential used, it should be set as True."
+ .format(insecure))
+
tenant_name = os.getenv("OS_TENANT_NAME")
- cmd = ("openstack project list | grep " +
+ cmd = ("openstack {} project list | grep ".format(insecure_option) +
tenant_name +
" | awk '{print $2}'")
result = commands.getstatusoutput(cmd)
- if result[0] == 0:
+ if result[0] == 0 and 'exception' not in result[1]:
LOG.info("Get %s project id is %s" % (tenant_name, result[1]))
else:
LOG.error("can't get openstack project id")
diff --git a/utils/env_prepare/stack_prepare.py b/utils/env_prepare/stack_prepare.py
index 25c2a29b..6b9bc510 100644
--- a/utils/env_prepare/stack_prepare.py
+++ b/utils/env_prepare/stack_prepare.py
@@ -14,6 +14,7 @@ from utils.logger import Logger
from utils.parser import Parser as config
import utils.infra_setup.heat.manager as utils
import utils.infra_setup.runner.docker_env as docker_env
+import utils.infra_setup.heat.manager as client_manager
LOG = Logger(__name__).getLogger()
@@ -73,7 +74,14 @@ def _source_file(rc_file):
p = subprocess.Popen(". %s; env" % rc_file, stdout=subprocess.PIPE,
shell=True)
output = p.communicate()[0]
- env = dict((line.split('=', 1) for line in output.splitlines()))
+ output_lines = output.splitlines()
+ env = list()
+ for line in output_lines:
+ if '=' in line:
+ env.append(tuple(line.split('=', 1)))
+
+ env = dict(env)
+# env = dict((line.split('=', 1) for line in output_lines))
os.environ.update(env)
return env
@@ -93,3 +101,30 @@ def _append_external_network(rc_file):
except OSError as e:
if e.errno != errno.EEXIST:
raise
+
+
+def prepare_image(image_name, image_dir):
+ glance_client = client_manager._get_glance_client()
+ if not os.path.isfile(image_dir):
+ LOG.error("Error: file %s does not exist.", image_dir)
+ return None
+ try:
+ images = glance_client.images.list()
+ image_id = next((i.id for i in images if i.name == image_name), None)
+ if image_id is not None:
+ LOG.info("Image %s already exists.", image_name)
+ else:
+ LOG.info("Creating image '%s' from '%s'...", image_name, image_dir)
+
+ image = glance_client.images.create(
+ name=image_name, visibility="public", disk_format="qcow2",
+ container_format="bare")
+ image_id = image.id
+ with open(image_dir) as image_data:
+ glance_client.images.upload(image_id, image_data)
+ return image_id
+ except Exception: # pylint: disable=broad-except
+ LOG.error(
+ "Error [create_glance_image(glance_client, '%s', '%s')]",
+ image_name, image_dir)
+ return None