diff --git a/fuel_plugin/ostf_adapter/config.py b/fuel_plugin/ostf_adapter/config.py index 6396b9aa..797be4e5 100644 --- a/fuel_plugin/ostf_adapter/config.py +++ b/fuel_plugin/ostf_adapter/config.py @@ -1,4 +1,4 @@ -# Copyright 2013 Mirantis, Inc. +# Copyright 2015 Mirantis, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain @@ -15,6 +15,8 @@ import logging import os +from fuel_plugin.ostf_adapter import mixins + try: from oslo.config import cfg except ImportError: @@ -101,4 +103,5 @@ def init_config(args=[]): else: config_files.append(path) - cfg.CONF(args, project='fuel_ostf', default_config_files=config_files) + cfg.CONF(args, project='fuel_ostf', default_config_files=config_files, + version=mixins.get_version_string()) diff --git a/fuel_plugin/ostf_adapter/mixins.py b/fuel_plugin/ostf_adapter/mixins.py index 932d8585..6cd40020 100644 --- a/fuel_plugin/ostf_adapter/mixins.py +++ b/fuel_plugin/ostf_adapter/mixins.py @@ -1,4 +1,4 @@ -# Copyright 2013 Mirantis, Inc. +# Copyright 2015 Mirantis, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain @@ -19,6 +19,11 @@ try: except ImportError: from oslo_config import cfg +try: + from oslo.serialization import jsonutils +except ImportError: + from oslo_serialization import jsonutils + import requests from sqlalchemy.orm import joinedload @@ -30,6 +35,8 @@ LOG = logging.getLogger(__name__) TEST_REPOSITORY = [] +# TODO(ikutukov): remove hardcoded Nailgun API urls here and below +NAILGUN_VERSION_API_URL = 'http://{0}:{1}/api/v1/version' def delete_db_data(session): @@ -107,6 +114,18 @@ def discovery_check(session, cluster_id, token=None): session.merge(cluster_state) +def get_version_string(token=None): + requests_session = requests.Session() + requests_session.trust_env = False + request_url = NAILGUN_VERSION_API_URL.format(cfg.CONF.adapter.nailgun_host, + cfg.CONF.adapter.nailgun_port) + try: + response = requests_session.get(request_url).json() + return jsonutils.dumps(response) + except (ValueError, IOError, requests.exceptions.HTTPError): + return "Can't obtain version via Nailgun API" + + def _get_cluster_attrs(cluster_id, token=None): cluster_attrs = {}