Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

k-91: Remote backend init for remote clusters #89

Merged
merged 8 commits into from
Dec 18, 2019
7 changes: 7 additions & 0 deletions cli/kaos_cli/exceptions/handle_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ def _(e):
click.echo(e.message, err=True)


@handle_specific_exception.register(KeyError)
def _(e):
click.echo("{} - Ignoring {}. Creating a new section in config".format(
click.style("Info", bold=True, fg='yellow'),
click.style(str(e), bold=True, fg='green')))


@handle_specific_exception.register(IndexError)
def _(e):
click.echo(str(e), err=True)
Expand Down
18 changes: 14 additions & 4 deletions cli/kaos_cli/facades/backend_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import requests
from kaos_cli.constants import DOCKER, MINIKUBE, PROVIDER_DICT, AWS, BACKEND, INFRASTRUCTURE, GCP, LOCAL_CONFIG_DICT, \
CONTEXTS, ACTIVE, BACKEND_CACHE, DEFAULT, USER, REMOTE
CONTEXTS, ACTIVE, BACKEND_CACHE, DEFAULT, USER, REMOTE, KAOS_STATE_DIR
from kaos_cli.exceptions.exceptions import HostnameError
from kaos_cli.services.state_service import StateService
from kaos_cli.services.terraform_service import TerraformService
Expand Down Expand Up @@ -50,13 +50,23 @@ def kubeconfig(self):
return self.state_service.get_section(self.active_context, INFRASTRUCTURE, 'kubeconfig')

def init(self, url, token):
if not self.state_service.is_created():
if not self.state_service.is_created(KAOS_STATE_DIR):
self.state_service.create()
self.state_service.set(BACKEND, url=url, token=token)
self.state_service.set_section(REMOTE, BACKEND, url=url, token=token)

self.state_service.set(DEFAULT, user=USER)
self._set_context_list(REMOTE)
self._set_active_context(REMOTE)
self.state_service.set(REMOTE)
try:
self.state_service.set_section(REMOTE, BACKEND, url=url, token=token)
except Exception as e:
handle_specific_exception(e)
handle_exception(e)
self.state_service.write()

def is_created(self):
return self.state_service.is_created(KAOS_STATE_DIR)

def list(self):
try:
contexts = self.state_service.get(CONTEXTS, 'environments')
Expand Down