Ejemplo n.º 1
0
def create_workspace(facade: WorkspaceFacade, name):
    """
    Creates a workspace.
    """

    try:
        facade.create(name)

        click.echo("{} - Successfully set {} workspace".format(
            click.style("Info", bold=True, fg='green'),
            click.style(name, bold=True, fg='green')))

    except Exception as e:
        handle_specific_exception(e)
        handle_exception(e)
Ejemplo n.º 2
0
def set_workspace(facade: WorkspaceFacade, name, ind):
    """
    Set current model environment workspace.
    """

    try:

        # ensure arguments are correctly defined
        validate_inputs([name, ind], ['name', 'ind'])

        # selection by index
        if ind is not None:
            name = facade.get_workspace_by_ind(ind)

        if facade.exists_by_name(name):
            facade.set_by_name(name)

            click.echo("{} - Successfully set {} workspace".format(
                click.style("Info", bold=True, fg='green'),
                click.style(name, bold=True, fg='green')))

        else:
            similar = facade.find_similar_workspaces(name)

            if similar:
                click.echo(
                    "{} - Workspace {} does not exist. Did you mean one of these?"
                    .format(click.style("Warning", bold=True, fg='yellow'),
                            click.style(name, bold=True, fg='green')))
                click.echo('\n'.join(
                    map(lambda t: click.style(t, bold=True, fg='red'),
                        similar)))
            else:
                click.echo(
                    "{} - Workspace {} does not exist. Check the existing workspaces with `{}`"
                    .format(
                        click.style("Warning", bold=True, fg='yellow'),
                        click.style(name, bold=True, fg='green'),
                        click.style("kaos workspace list",
                                    bold=True,
                                    fg='white')))

    except Exception as e:
        handle_specific_exception(e)
        handle_exception(e)
Ejemplo n.º 3
0
def list_workspaces(facade: WorkspaceFacade):
    """
    List all available workspaces.
    """
    try:

        workspaces = facade.list()
        if len(workspaces) > 0:

            facade.cache(workspaces)
            table = render_table(workspaces)
            click.echo(table)

        else:
            click.echo("{} - There are currently {} active workspaces - first run {}".format(
                click.style("Warning", bold=True, fg='yellow'),
                click.style('no', bold=True, fg='red'),
                click.style("kaos workspace create", bold=True, fg='green')))

    except Exception as e:
        handle_specific_exception(e)
        handle_exception(e)
Ejemplo n.º 4
0
def kill_workspace(facade: WorkspaceFacade):
    """
    Kill all resources running in a workspace.
    """
    try:

        name = facade.current()

        # confirm kill
        click.confirm('{} - Are you sure about killing all {} resources?'.format(
            click.style("Warning", bold=True, fg='yellow'),
            click.style(name, bold=True, fg='red')),
            abort=True)

        name = facade.delete()

        click.echo('{} - Successfully killed all {} resources'.format(
            click.style("Info", bold=True, fg='green'),
            click.style(name, bold=True, fg='green')))

    except Exception as e:
        handle_specific_exception(e)
        handle_exception(e)
Ejemplo n.º 5
0
def workspace_info(facade: WorkspaceFacade):
    """
    Identify all running resources within a workspace.
    """
    try:

        info = facade.info()['response']

        click.echo('\n--- Workspace {} ---\n'.format(click.style(info['name'], bold=True, fg='green')))
        print_list('Pipelines', info['pipelines'])
        print_list('Repos', info['repos'])
    except Exception as e:
        handle_specific_exception(e)
        handle_exception(e)
Ejemplo n.º 6
0
def current_workspace(facade: WorkspaceFacade):
    """
    Get current model environment workspace.
    """
    try:
        # return <name> as workspace
        name = facade.current()
        click.echo("{} - Workspace {} is currently set".format(
            click.style("Info", bold=True, fg='green'),
            click.style(name, bold=True, fg='green')))

    except Exception as e:
        handle_specific_exception(e)
        handle_exception(e)
Ejemplo n.º 7
0
def kill_workspace(facade: WorkspaceFacade):
    """
    Kill all resources running in a workspace.
    """

    name = facade.current()
    # confirm kill
    if not click.confirm(
            '{} - Are you sure about killing all {} resources?'.format(
                click.style("Warning", bold=True, fg='yellow'),
                click.style(name, bold=True, fg='red')),
            abort=False):
        click.echo(
            "{} - Workspace {} kill operation aborted. Re-initiate using `{}` if required"
            .format(click.style("Info", bold=True, fg='white'),
                    click.style(name, bold=True, fg='green'),
                    click.style("kaos workspace kill", bold=True, fg='green')))
        sys.exit(1)
    else:
        name = facade.delete()

        click.echo('{} - Successfully killed all {} resources'.format(
            click.style("Info", bold=True, fg='green'),
            click.style(name, bold=True, fg='green')))
Ejemplo n.º 8
0
    def _create_facades(state=None, terraform=None):
        template = TemplateFacade()
        backend = BackendFacade(state, terraform)
        workspace = WorkspaceFacade(state)
        train = TrainFacade(state)
        serve = ServeFacade(state)
        notebook = NotebookFacade(state)

        facades = {
            BackendFacade: backend,
            WorkspaceFacade: workspace,
            TemplateFacade: template,
            TrainFacade: train,
            ServeFacade: serve,
            NotebookFacade: notebook
        }
        return facades