summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Hwang <mhwang@research.att.com>2017-09-18 13:25:28 -0400
committerMichael Hwang <mhwang@research.att.com>2017-09-19 09:42:33 -0400
commit249fa95e2bea21f840f3ee5c8311a0bfe13a1b3c (patch)
treea6f48400fe4bb7ecfc314639f24e355e97872aef
parent4188380fb7b806640103f557afec344455787a34 (diff)
Make dcae-cli more tolerant aka configurable
* Seeding configuration is no longer a fatal issue * Setup database connection * Seeding profiles is no longer a fatal issue Change-Id: Ica2150a1ca52bb422e4bf6d1213c6eacfb0ba128 Issue-Id: DCAEGEN2-110 Signed-off-by: Michael Hwang <mhwang@research.att.com>
-rw-r--r--dcae-cli/ChangeLog.md7
-rw-r--r--dcae-cli/README.md16
-rw-r--r--dcae-cli/dcae_cli/util/config.py32
-rw-r--r--dcae-cli/dcae_cli/util/profiles.py12
4 files changed, 54 insertions, 13 deletions
diff --git a/dcae-cli/ChangeLog.md b/dcae-cli/ChangeLog.md
index 4e169fc..794b6a7 100644
--- a/dcae-cli/ChangeLog.md
+++ b/dcae-cli/ChangeLog.md
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
+## []
+
+* Make server url (url to webserver that has static artifacts like json schemas) a configuration parameter
+* Seeding configuration is no longer a fatal issue
+* Setup database connection via manual user inputs if seed config not there
+* Seeding profiles is no longer a fatal issue
+
## [2.9.0]
* Add data format generate command
diff --git a/dcae-cli/README.md b/dcae-cli/README.md
index bcbc065..2806f5e 100644
--- a/dcae-cli/README.md
+++ b/dcae-cli/README.md
@@ -1,7 +1,19 @@
# dcae-cli
-The DCAE on-boarding Python command-line tool that provides functionality to manage data formats and components.
+The `dcae-cli` is a Python command-line tool used to manage and to test components and their data formats in onboarding.
## Documentation
-Please review the [DCAE platform documentation](ONAP URL TBD) which has a [`dcae-cli` walkthrough](ONAP URL TBD).
+Please review the [DCAE platform documentation](ONAP URL TBD) which has a detailed [`dcae-cli` walkthrough](ONAP URL TBD).
+
+## Local use
+
+The dcae-cli requires access to an onboarding catalog which is a postgres database. If there is no shared instance for your team or organization, then a workaround is to run a local instance of postgres on your machine. One quick way is to run a postgres Docker container:
+
+```
+docker run -e POSTGRES_PASSWORD=<your password> -e PGDATA=/var/lib/postgresql/data/pgdata -v <local directory>:/var/lib/postgresql/data/pgdata -p 5432:5432 -d postgres:9.5.2
+```
+
+Use your favorite sql client to log into this local instance and create a database named `dcae_onboarding_db`.
+
+Now that your onboarding catalog is setup, run `dcae_cli --reinit` and walkthrough the prompts to configure your dcae-cli to point to this local instance.
diff --git a/dcae-cli/dcae_cli/util/config.py b/dcae-cli/dcae_cli/util/config.py
index 6a53de4..d3d9f16 100644
--- a/dcae-cli/dcae_cli/util/config.py
+++ b/dcae-cli/dcae_cli/util/config.py
@@ -51,28 +51,44 @@ def _init_config_user():
click.echo("Invalid user id. Please try again.")
def _init_config_server_url():
- return click.prompt('Please enter the remote server url', type=str).strip()
+ return click.prompt("Please enter the remote server url", type=str).strip()
+
+def _init_config_db_url():
+ click.echo("Now we need to set up access to the onboarding catalog")
+ hostname = click.prompt("Please enter the onboarding catalog hostname").strip()
+ user = click.prompt("Please enter the onboarding catalog user").strip()
+ password = click.prompt("Please enter the onboarding catalog password").strip()
+ return "postgresql://{user}:{password}@{hostname}:5432/dcae_onboarding_db".format(
+ hostname=hostname, user=user, password=password)
def _init_config():
'''Returns an initial dict for populating the config'''
# Grab the remote config and merge it in
+ new_config = {}
+
try:
server_url = _init_config_server_url()
new_config = util.fetch_file_from_web(server_url, "/dcae-cli/config.json")
new_config["server_url"] = server_url
except:
- # REVIEW: Should we allow users to manually setup their config if not
- # able to pull from remote server?
- raise ConfigurationInitError("Could not download configuration from remote server")
+ # Failing to pull seed configuration from remote server is not considered
+ # a problem. Just continue and give user the option to set it up
+ # themselves.
+ if not click.confirm("Could not download initial configuration from remote server. Attempt manually setting up?"):
+ raise ConfigurationInitError("Could not setup dcae-cli configuration")
new_config["user"] = _init_config_user()
new_config["cli_version"] = _version.__version__
if "db_url" not in new_config or not new_config["db_url"]:
- # Really you should never get to this point because the remote config
- # should have a postgres db url.
- fallback = ''.join(('sqlite:///', os.path.join(get_app_dir(), 'dcae_cli.db')))
- new_config["db_url"] = fallback
+ # The seed configuration was not provided so manually set up the db
+ # connection
+ new_config["db_url"] = _init_config_db_url()
+
+ if "active_profile" not in new_config:
+ # The seed configuration was not provided which means the profiles will
+ # be the same. The profile will be hardcoded to a an empty default.
+ new_config["active_profile"] = "default"
return new_config
diff --git a/dcae-cli/dcae_cli/util/profiles.py b/dcae-cli/dcae_cli/util/profiles.py
index 83a7ca9..34580d6 100644
--- a/dcae-cli/dcae_cli/util/profiles.py
+++ b/dcae-cli/dcae_cli/util/profiles.py
@@ -27,6 +27,7 @@ import os
from collections import namedtuple
import six
+import click
from dcae_cli import util
from dcae_cli.util import get_app_dir, get_pref, write_pref
@@ -98,9 +99,14 @@ def reinit_profiles():
server_url = config.get_server_url()
new_profiles = util.fetch_file_from_web(server_url, "/dcae-cli/profiles.json")
except:
- # REVIEW: Should we allow users to manually setup their config if not
- # able to pull from remote server?
- raise ProfilesInitError("Could not download profiles from remote server")
+ # Failing to pull seed profiles from remote server is not considered
+ # a problem. Just continue and give user the option to use an empty
+ # default.
+ if click.confirm("Could not download initial profiles from remote server. Set empty default?"):
+ new_profiles = {"default": { "consul_host": "", "config_binding_service": "",
+ "cdap_broker": "", "docker_host": ""}}
+ else:
+ raise ProfilesInitError("Could not setup dcae-cli profiles")
profiles_path = get_profiles_path()