Skip to content

Commit dff9d1e

Browse files
authored
Help messages for new commands (#145)
* Help messages for new commands
1 parent 8fb9855 commit dff9d1e

6 files changed

Lines changed: 778 additions & 18 deletions

File tree

ckan_cloud_operator/providers/ckan/cli.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from .storage import cli as ckan_storage_cli
1010
from .deployment import cli as ckan_deployment_cli
1111
from .instance import cli as instance_cli
12-
12+
from .env import cli as env_cli
1313

1414
@click.group()
1515
def ckan():
@@ -20,7 +20,7 @@ def ckan():
2020
ckan.add_command(ckan_storage_cli.storage)
2121
ckan.add_command(ckan_deployment_cli.deployment)
2222
ckan.add_command(instance_cli.instance)
23-
23+
ckan.add_command(env_cli.env)
2424

2525
@ckan.command()
2626
@click.option('--interactive', is_flag=True)
@@ -123,3 +123,19 @@ def db_migration_import_urls(old_site_id, raw):
123123
print(' '.join(urls))
124124
else:
125125
logs.print_yaml_dump(list(urls))
126+
127+
@ckan.command()
128+
@click.option('--environment-name', help='name of the environment to initialize (one of the result of `cco ckan env list`)')
129+
def init(environment_name):
130+
'''
131+
Initialize ckan-cloud-operator for working with environment.
132+
This command gets all the necessary credentials for working
133+
with the given environment. Eg, gets and saves `kubeconfig`
134+
file in `~/.kube/config` directory
135+
136+
Without flags initializes current working environment added with `cco ckan env add`
137+
138+
\b
139+
cco ckan init --environment-name poc
140+
> POC environment was succesfully initialized
141+
'''

ckan_cloud_operator/providers/ckan/env/__init__.py

Whitespace-only changes.
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import click
2+
import yaml
3+
import json
4+
import traceback
5+
6+
from ckan_cloud_operator import logs
7+
from ckan_cloud_operator import kubectl
8+
9+
from . import manager
10+
11+
12+
@click.group()
13+
def env():
14+
'''Manage CKAN Environments
15+
'''
16+
pass
17+
18+
@env.command('list')
19+
def list_env():
20+
'''
21+
Lists existing environments
22+
23+
\b
24+
cco ckan env list
25+
> POC
26+
> DEV
27+
> PRD
28+
'''
29+
30+
@env.command()
31+
@click.argument('ENVIRONMENT')
32+
@click.option('--cloud-provider', help='One of minukube, azure, gcp, aws', required=True)
33+
@click.option('--cluster-name', help='Kubernetes cluster name', required=True)
34+
@click.option('--resource-group', help='Azure resource group name [Azure only]')
35+
@click.option('--subscription', help='Azure subscription id [Azure only]')
36+
@click.option('--region', help='GCP region id Eg: europe-west1 [GCP only]')
37+
@click.option('--project', help='GCP project name [GCP only]')
38+
def add(environment, cloud_provider, cluster_name, resource_group, subscription, region, project):
39+
'''
40+
Adds an environment
41+
42+
ENVIRONMENT: The name of the environment Eg: poc
43+
44+
\b
45+
cco ckan env add poc --cloud-provider cloud-provider-name \\
46+
--resource-group resource-group-name \\
47+
--cluster-name cluster-name \\
48+
--subscription subscription-id \\
49+
--region region-name \\
50+
--project project-name
51+
> POC environment was succefully added
52+
'''
53+
54+
@env.command()
55+
@click.argument('ENVIRONMENT')
56+
@click.option('--cloud-provider', help='One of minukube, azure, gcp, aws')
57+
@click.option('--cluster-name', help='Kubernetes cluster name')
58+
@click.option('--resource-group', help='Azure resource group name [Azure only]')
59+
@click.option('--subscription', help='Azure subscription id [Azure only]')
60+
@click.option('--region', help='GCP region id Eg: europe-west1 [GCP only]')
61+
@click.option('--project', help='GCP project name [GCP only]')
62+
def update(environment, cloud_provider, cluster_name, resource_group, subscription, region, project):
63+
'''
64+
Update configurations for given environment
65+
66+
ENVIRONMENT: The name of the environment Eg: dev
67+
68+
\b
69+
cco ckan env add poc --cloud-provider cloud-provider-name \\
70+
--resource-group resource-group-name \\
71+
--cluster-name new-cluster-name \\
72+
--subscription subscription-id \\
73+
--region region-name \\
74+
--project project-name
75+
> POC environment was succefully updated
76+
'''
77+
78+
@env.command()
79+
@click.argument('ENVIRONMENT')
80+
def set(environment):
81+
'''
82+
Sets given environment as a current working environment
83+
84+
ENVIRONMENT: The name of the environment Eg: dev
85+
86+
\b
87+
cco ckan env set poc
88+
> You are working with POC environment now
89+
'''
90+
91+
@env.command()
92+
@click.argument('ENVIRONMENT')
93+
def rm(environment):
94+
'''
95+
Deletes given environment
96+
97+
ENVIRONMENT: The name of the environment Eg: dev
98+
99+
cco ckan env rm poc
100+
> POC environment was succesfully removed
101+
'''

0 commit comments

Comments
 (0)