kaqing 1.77.0__py3-none-any.whl → 2.0.171__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- adam/__init__.py +1 -0
- adam/app_session.py +182 -0
- {walker → adam}/apps.py +8 -24
- {walker → adam}/batch.py +54 -97
- {walker → adam}/checks/check.py +3 -3
- {walker → adam}/checks/check_result.py +1 -1
- adam/checks/check_utils.py +65 -0
- {walker → adam}/checks/compactionstats.py +6 -6
- {walker → adam}/checks/cpu.py +14 -8
- adam/checks/cpu_metrics.py +52 -0
- {walker → adam}/checks/disk.py +6 -6
- {walker → adam}/checks/gossip.py +5 -5
- {walker → adam}/checks/memory.py +7 -7
- {walker → adam}/checks/status.py +5 -5
- {walker → adam}/cli.py +3 -3
- {walker → adam}/columns/column.py +1 -1
- adam/columns/columns.py +45 -0
- {walker → adam}/columns/compactions.py +5 -5
- {walker → adam}/columns/cpu.py +6 -4
- adam/columns/cpu_metrics.py +22 -0
- {walker → adam}/columns/dir_data.py +3 -3
- {walker → adam}/columns/dir_snapshots.py +3 -3
- {walker → adam}/columns/gossip.py +5 -5
- {walker → adam}/columns/host_id.py +3 -3
- {walker → adam}/columns/memory.py +3 -3
- {walker → adam}/columns/node_address.py +3 -3
- {walker → adam}/columns/node_load.py +3 -3
- {walker → adam}/columns/node_owns.py +3 -3
- {walker → adam}/columns/node_status.py +3 -3
- {walker → adam}/columns/node_tokens.py +3 -3
- {walker → adam}/columns/node_utils.py +2 -2
- {walker → adam}/columns/pod_name.py +2 -2
- {walker → adam}/columns/volume_cassandra.py +4 -4
- {walker → adam}/columns/volume_root.py +3 -3
- adam/commands/__init__.py +15 -0
- adam/commands/alter_tables.py +81 -0
- adam/commands/app_cmd.py +38 -0
- {walker → adam}/commands/app_ping.py +10 -16
- adam/commands/audit/audit.py +84 -0
- adam/commands/audit/audit_repair_tables.py +74 -0
- adam/commands/audit/audit_run.py +50 -0
- adam/commands/audit/show_last10.py +48 -0
- adam/commands/audit/show_slow10.py +47 -0
- adam/commands/audit/show_top10.py +45 -0
- adam/commands/audit/utils_show_top10.py +59 -0
- adam/commands/bash/__init__.py +5 -0
- adam/commands/bash/bash.py +36 -0
- adam/commands/bash/bash_completer.py +93 -0
- adam/commands/bash/utils_bash.py +16 -0
- adam/commands/cat.py +50 -0
- adam/commands/cd.py +43 -0
- adam/commands/check.py +73 -0
- {walker → adam}/commands/cli_commands.py +7 -8
- adam/commands/code.py +57 -0
- adam/commands/command.py +190 -0
- {walker → adam}/commands/command_helpers.py +1 -1
- {walker → adam}/commands/commands_utils.py +15 -25
- adam/commands/cp.py +89 -0
- adam/commands/cql/cql_completions.py +33 -0
- {walker/commands → adam/commands/cql}/cqlsh.py +20 -35
- adam/commands/cql/utils_cql.py +343 -0
- {walker/commands/frontend → adam/commands/deploy}/code_start.py +11 -14
- adam/commands/deploy/code_stop.py +40 -0
- {walker/commands/frontend → adam/commands/deploy}/code_utils.py +7 -9
- adam/commands/deploy/deploy.py +25 -0
- adam/commands/deploy/deploy_frontend.py +49 -0
- adam/commands/deploy/deploy_pg_agent.py +35 -0
- adam/commands/deploy/deploy_pod.py +108 -0
- adam/commands/deploy/deploy_utils.py +29 -0
- adam/commands/deploy/undeploy.py +25 -0
- adam/commands/deploy/undeploy_frontend.py +38 -0
- adam/commands/deploy/undeploy_pg_agent.py +39 -0
- adam/commands/deploy/undeploy_pod.py +48 -0
- adam/commands/devices/device.py +118 -0
- adam/commands/devices/device_app.py +173 -0
- adam/commands/devices/device_auit_log.py +49 -0
- adam/commands/devices/device_cass.py +185 -0
- adam/commands/devices/device_export.py +86 -0
- adam/commands/devices/device_postgres.py +144 -0
- adam/commands/devices/devices.py +25 -0
- {walker → adam}/commands/exit.py +3 -6
- adam/commands/export/clean_up_all_export_sessions.py +37 -0
- adam/commands/export/clean_up_export_sessions.py +51 -0
- adam/commands/export/drop_export_database.py +55 -0
- adam/commands/export/drop_export_databases.py +43 -0
- adam/commands/export/export.py +53 -0
- adam/commands/export/export_databases.py +170 -0
- adam/commands/export/export_handlers.py +71 -0
- adam/commands/export/export_select.py +81 -0
- adam/commands/export/export_select_x.py +54 -0
- adam/commands/export/export_use.py +52 -0
- adam/commands/export/exporter.py +352 -0
- adam/commands/export/import_session.py +40 -0
- adam/commands/export/importer.py +67 -0
- adam/commands/export/importer_athena.py +80 -0
- adam/commands/export/importer_sqlite.py +47 -0
- adam/commands/export/show_column_counts.py +54 -0
- adam/commands/export/show_export_databases.py +36 -0
- adam/commands/export/show_export_session.py +48 -0
- adam/commands/export/show_export_sessions.py +44 -0
- adam/commands/export/utils_export.py +314 -0
- {walker → adam}/commands/help.py +17 -12
- adam/commands/intermediate_command.py +49 -0
- adam/commands/issues.py +43 -0
- adam/commands/kubectl.py +38 -0
- adam/commands/login.py +70 -0
- {walker → adam}/commands/logs.py +8 -10
- adam/commands/ls.py +41 -0
- adam/commands/medusa/medusa.py +27 -0
- adam/commands/medusa/medusa_backup.py +57 -0
- adam/commands/medusa/medusa_restore.py +83 -0
- adam/commands/medusa/medusa_show_backupjobs.py +51 -0
- adam/commands/medusa/medusa_show_restorejobs.py +47 -0
- {walker → adam}/commands/nodetool.py +17 -21
- {walker → adam}/commands/param_get.py +15 -16
- adam/commands/param_set.py +43 -0
- adam/commands/postgres/postgres.py +104 -0
- adam/commands/postgres/postgres_context.py +274 -0
- {walker → adam}/commands/postgres/postgres_ls.py +7 -11
- {walker → adam}/commands/postgres/postgres_preview.py +8 -13
- adam/commands/postgres/psql_completions.py +10 -0
- adam/commands/postgres/utils_postgres.py +66 -0
- adam/commands/preview_table.py +37 -0
- adam/commands/pwd.py +47 -0
- adam/commands/reaper/reaper.py +35 -0
- adam/commands/reaper/reaper_forward.py +93 -0
- adam/commands/reaper/reaper_forward_session.py +6 -0
- {walker → adam}/commands/reaper/reaper_forward_stop.py +13 -19
- {walker → adam}/commands/reaper/reaper_restart.py +10 -17
- adam/commands/reaper/reaper_run_abort.py +46 -0
- adam/commands/reaper/reaper_runs.py +82 -0
- adam/commands/reaper/reaper_runs_abort.py +63 -0
- adam/commands/reaper/reaper_schedule_activate.py +45 -0
- adam/commands/reaper/reaper_schedule_start.py +45 -0
- adam/commands/reaper/reaper_schedule_stop.py +45 -0
- {walker → adam}/commands/reaper/reaper_schedules.py +6 -16
- {walker → adam}/commands/reaper/reaper_status.py +11 -19
- adam/commands/reaper/utils_reaper.py +196 -0
- adam/commands/repair/repair.py +26 -0
- {walker → adam}/commands/repair/repair_log.py +7 -10
- adam/commands/repair/repair_run.py +70 -0
- adam/commands/repair/repair_scan.py +71 -0
- {walker → adam}/commands/repair/repair_stop.py +8 -11
- adam/commands/report.py +61 -0
- adam/commands/restart.py +60 -0
- {walker → adam}/commands/rollout.py +25 -30
- adam/commands/shell.py +34 -0
- adam/commands/show/show.py +39 -0
- walker/commands/show/show_version.py → adam/commands/show/show_adam.py +14 -10
- adam/commands/show/show_app_actions.py +57 -0
- {walker → adam}/commands/show/show_app_id.py +12 -15
- {walker → adam}/commands/show/show_app_queues.py +9 -12
- adam/commands/show/show_cassandra_repairs.py +38 -0
- adam/commands/show/show_cassandra_status.py +124 -0
- {walker → adam}/commands/show/show_cassandra_version.py +6 -16
- adam/commands/show/show_commands.py +59 -0
- walker/commands/show/show_storage.py → adam/commands/show/show_host.py +11 -13
- adam/commands/show/show_login.py +62 -0
- {walker → adam}/commands/show/show_params.py +4 -4
- adam/commands/show/show_processes.py +51 -0
- adam/commands/show/show_storage.py +42 -0
- adam/commands/watch.py +82 -0
- {walker → adam}/config.py +10 -22
- {walker → adam}/embedded_apps.py +1 -1
- adam/embedded_params.py +2 -0
- adam/log.py +47 -0
- {walker → adam}/pod_exec_result.py +10 -2
- adam/repl.py +182 -0
- adam/repl_commands.py +124 -0
- adam/repl_state.py +458 -0
- adam/sql/__init__.py +0 -0
- adam/sql/sql_completer.py +120 -0
- adam/sql/sql_state_machine.py +618 -0
- adam/sql/term_completer.py +76 -0
- adam/sso/__init__.py +0 -0
- {walker → adam}/sso/authenticator.py +5 -1
- adam/sso/authn_ad.py +170 -0
- {walker → adam}/sso/authn_okta.py +39 -22
- adam/sso/cred_cache.py +60 -0
- adam/sso/id_token.py +23 -0
- adam/sso/idp.py +143 -0
- adam/sso/idp_login.py +50 -0
- adam/sso/idp_session.py +55 -0
- adam/sso/sso_config.py +63 -0
- adam/utils.py +679 -0
- adam/utils_app.py +98 -0
- adam/utils_athena.py +145 -0
- adam/utils_audits.py +106 -0
- adam/utils_issues.py +32 -0
- adam/utils_k8s/__init__.py +0 -0
- adam/utils_k8s/app_clusters.py +28 -0
- adam/utils_k8s/app_pods.py +33 -0
- adam/utils_k8s/cassandra_clusters.py +36 -0
- adam/utils_k8s/cassandra_nodes.py +33 -0
- adam/utils_k8s/config_maps.py +34 -0
- {walker/k8s_utils → adam/utils_k8s}/custom_resources.py +7 -2
- adam/utils_k8s/deployment.py +56 -0
- {walker/k8s_utils → adam/utils_k8s}/ingresses.py +3 -4
- {walker/k8s_utils → adam/utils_k8s}/jobs.py +3 -3
- adam/utils_k8s/k8s.py +87 -0
- {walker/k8s_utils → adam/utils_k8s}/kube_context.py +4 -4
- adam/utils_k8s/pods.py +290 -0
- {walker/k8s_utils → adam/utils_k8s}/secrets.py +8 -4
- adam/utils_k8s/service_accounts.py +170 -0
- {walker/k8s_utils → adam/utils_k8s}/services.py +3 -4
- {walker/k8s_utils → adam/utils_k8s}/statefulsets.py +6 -16
- {walker/k8s_utils → adam/utils_k8s}/volumes.py +10 -1
- adam/utils_net.py +24 -0
- adam/utils_repl/__init__.py +0 -0
- adam/utils_repl/automata_completer.py +48 -0
- adam/utils_repl/repl_completer.py +46 -0
- adam/utils_repl/state_machine.py +173 -0
- adam/utils_sqlite.py +109 -0
- adam/version.py +5 -0
- {kaqing-1.77.0.dist-info → kaqing-2.0.171.dist-info}/METADATA +1 -1
- kaqing-2.0.171.dist-info/RECORD +236 -0
- kaqing-2.0.171.dist-info/entry_points.txt +3 -0
- kaqing-2.0.171.dist-info/top_level.txt +1 -0
- kaqing-1.77.0.dist-info/RECORD +0 -159
- kaqing-1.77.0.dist-info/entry_points.txt +0 -3
- kaqing-1.77.0.dist-info/top_level.txt +0 -1
- walker/__init__.py +0 -3
- walker/app_session.py +0 -168
- walker/checks/check_utils.py +0 -97
- walker/columns/columns.py +0 -43
- walker/commands/add_user.py +0 -68
- walker/commands/app.py +0 -67
- walker/commands/bash.py +0 -87
- walker/commands/cd.py +0 -115
- walker/commands/check.py +0 -68
- walker/commands/command.py +0 -104
- walker/commands/cp.py +0 -95
- walker/commands/cql_utils.py +0 -53
- walker/commands/devices.py +0 -89
- walker/commands/frontend/code_stop.py +0 -57
- walker/commands/frontend/setup.py +0 -60
- walker/commands/frontend/setup_frontend.py +0 -58
- walker/commands/frontend/teardown.py +0 -61
- walker/commands/frontend/teardown_frontend.py +0 -42
- walker/commands/issues.py +0 -69
- walker/commands/login.py +0 -72
- walker/commands/ls.py +0 -145
- walker/commands/medusa/medusa.py +0 -69
- walker/commands/medusa/medusa_backup.py +0 -61
- walker/commands/medusa/medusa_restore.py +0 -86
- walker/commands/medusa/medusa_show_backupjobs.py +0 -52
- walker/commands/medusa/medusa_show_restorejobs.py +0 -52
- walker/commands/param_set.py +0 -44
- walker/commands/postgres/postgres.py +0 -113
- walker/commands/postgres/postgres_session.py +0 -225
- walker/commands/preview_table.py +0 -98
- walker/commands/processes.py +0 -53
- walker/commands/pwd.py +0 -64
- walker/commands/reaper/reaper.py +0 -78
- walker/commands/reaper/reaper_forward.py +0 -100
- walker/commands/reaper/reaper_run_abort.py +0 -65
- walker/commands/reaper/reaper_runs.py +0 -97
- walker/commands/reaper/reaper_runs_abort.py +0 -83
- walker/commands/reaper/reaper_schedule_activate.py +0 -64
- walker/commands/reaper/reaper_schedule_start.py +0 -64
- walker/commands/reaper/reaper_schedule_stop.py +0 -64
- walker/commands/reaper/reaper_session.py +0 -159
- walker/commands/repair/repair.py +0 -68
- walker/commands/repair/repair_run.py +0 -72
- walker/commands/repair/repair_scan.py +0 -79
- walker/commands/report.py +0 -57
- walker/commands/restart.py +0 -61
- walker/commands/show/show.py +0 -72
- walker/commands/show/show_app_actions.py +0 -53
- walker/commands/show/show_cassandra_status.py +0 -35
- walker/commands/show/show_commands.py +0 -58
- walker/commands/show/show_processes.py +0 -35
- walker/commands/show/show_repairs.py +0 -47
- walker/commands/status.py +0 -128
- walker/commands/storage.py +0 -52
- walker/commands/user_entry.py +0 -69
- walker/commands/watch.py +0 -85
- walker/embedded_params.py +0 -2
- walker/k8s_utils/cassandra_clusters.py +0 -48
- walker/k8s_utils/cassandra_nodes.py +0 -26
- walker/k8s_utils/pods.py +0 -211
- walker/repl.py +0 -165
- walker/repl_commands.py +0 -58
- walker/repl_state.py +0 -211
- walker/sso/authn_ad.py +0 -94
- walker/sso/idp.py +0 -150
- walker/sso/idp_login.py +0 -29
- walker/sso/sso_config.py +0 -45
- walker/utils.py +0 -194
- walker/version.py +0 -5
- {walker → adam}/checks/__init__.py +0 -0
- {walker → adam}/checks/check_context.py +0 -0
- {walker → adam}/checks/issue.py +0 -0
- {walker → adam}/cli_group.py +0 -0
- {walker → adam}/columns/__init__.py +0 -0
- {walker/commands → adam/commands/audit}/__init__.py +0 -0
- {walker/commands/frontend → adam/commands/cql}/__init__.py +0 -0
- {walker/commands/medusa → adam/commands/deploy}/__init__.py +0 -0
- {walker/commands/postgres → adam/commands/devices}/__init__.py +0 -0
- {walker/commands/reaper → adam/commands/export}/__init__.py +0 -0
- {walker/commands/repair → adam/commands/medusa}/__init__.py +0 -0
- {walker → adam}/commands/nodetool_commands.py +0 -0
- {walker/commands/show → adam/commands/postgres}/__init__.py +0 -0
- {walker/k8s_utils → adam/commands/reaper}/__init__.py +0 -0
- {walker/sso → adam/commands/repair}/__init__.py +0 -0
- /walker/medusa_show_restorejobs.py → /adam/commands/show/__init__.py +0 -0
- {walker → adam}/repl_session.py +0 -0
- {kaqing-1.77.0.dist-info → kaqing-2.0.171.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from adam.app_session import AppSession
|
|
2
|
+
from adam.utils import ing
|
|
3
|
+
from adam.utils_k8s.ingresses import Ingresses
|
|
4
|
+
from adam.utils_k8s.services import Services
|
|
5
|
+
|
|
6
|
+
def deploy_frontend(name: str, namespace: str, label_selector: str):
|
|
7
|
+
app_session: AppSession = AppSession.create('c3', 'c3', namespace)
|
|
8
|
+
port = 7678
|
|
9
|
+
labels = gen_labels(label_selector)
|
|
10
|
+
with ing('Creating service'):
|
|
11
|
+
Services.create_service(name, namespace, port, labels, labels=labels)
|
|
12
|
+
with ing('Creating ingress'):
|
|
13
|
+
Ingresses.create_ingress(name, namespace, app_session.host, '/c3/c3/ops($|/)', port, annotations={
|
|
14
|
+
'kubernetes.io/ingress.class': 'nginx',
|
|
15
|
+
'nginx.ingress.kubernetes.io/use-regex': 'true',
|
|
16
|
+
'nginx.ingress.kubernetes.io/rewrite-target': '/'
|
|
17
|
+
}, labels=labels)
|
|
18
|
+
|
|
19
|
+
return f'https://{app_session.host}/c3/c3/ops'
|
|
20
|
+
|
|
21
|
+
def undeploy_frontend(namespace: str, label_selector: str):
|
|
22
|
+
with ing('Deleting ingress'):
|
|
23
|
+
Ingresses.delete_ingresses(namespace, label_selector=label_selector)
|
|
24
|
+
with ing('Deleting service'):
|
|
25
|
+
Services.delete_services(namespace, label_selector=label_selector)
|
|
26
|
+
|
|
27
|
+
def gen_labels(label_selector: str):
|
|
28
|
+
kv = label_selector.split('=')
|
|
29
|
+
return {kv[0]: kv[1]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import click
|
|
2
|
+
|
|
3
|
+
from adam.commands.deploy.undeploy_frontend import UndeployFrontend
|
|
4
|
+
from adam.commands.deploy.undeploy_pg_agent import UndeployPgAgent
|
|
5
|
+
from adam.commands.deploy.undeploy_pod import UndeployPod
|
|
6
|
+
from adam.commands.intermediate_command import IntermediateCommand
|
|
7
|
+
|
|
8
|
+
class Undeploy(IntermediateCommand):
|
|
9
|
+
COMMAND = 'undeploy'
|
|
10
|
+
|
|
11
|
+
# the singleton pattern
|
|
12
|
+
def __new__(cls, *args, **kwargs):
|
|
13
|
+
if not hasattr(cls, 'instance'): cls.instance = super(Undeploy, cls).__new__(cls)
|
|
14
|
+
|
|
15
|
+
return cls.instance
|
|
16
|
+
|
|
17
|
+
def command(self):
|
|
18
|
+
return Undeploy.COMMAND
|
|
19
|
+
|
|
20
|
+
def cmd_list(self):
|
|
21
|
+
return [UndeployFrontend(), UndeployPod(), UndeployPgAgent()]
|
|
22
|
+
|
|
23
|
+
class UndeployCommandHelper(click.Command):
|
|
24
|
+
def get_help(self, ctx: click.Context):
|
|
25
|
+
IntermediateCommand.intermediate_help(super().get_help(ctx), Undeploy.COMMAND, Undeploy().cmd_list())
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from adam.commands.command import Command
|
|
2
|
+
from adam.commands.deploy.deploy_utils import undeploy_frontend
|
|
3
|
+
from adam.config import Config
|
|
4
|
+
from adam.repl_state import ReplState, RequiredState
|
|
5
|
+
|
|
6
|
+
class UndeployFrontend(Command):
|
|
7
|
+
COMMAND = 'undeploy frontend'
|
|
8
|
+
|
|
9
|
+
# the singleton pattern
|
|
10
|
+
def __new__(cls, *args, **kwargs):
|
|
11
|
+
if not hasattr(cls, 'instance'): cls.instance = super(UndeployFrontend, cls).__new__(cls)
|
|
12
|
+
|
|
13
|
+
return cls.instance
|
|
14
|
+
|
|
15
|
+
def __init__(self, successor: Command=None):
|
|
16
|
+
super().__init__(successor)
|
|
17
|
+
|
|
18
|
+
def command(self):
|
|
19
|
+
return UndeployFrontend.COMMAND
|
|
20
|
+
|
|
21
|
+
def required(self):
|
|
22
|
+
return RequiredState.NAMESPACE
|
|
23
|
+
|
|
24
|
+
def run(self, cmd: str, state: ReplState):
|
|
25
|
+
if not(args := self.args(cmd)):
|
|
26
|
+
return super().run(cmd, state)
|
|
27
|
+
|
|
28
|
+
with self.validate(args, state) as (args, state):
|
|
29
|
+
label_selector = Config().get('pod.label-selector', 'run=ops')
|
|
30
|
+
undeploy_frontend(state.namespace, label_selector)
|
|
31
|
+
|
|
32
|
+
return state
|
|
33
|
+
|
|
34
|
+
def completion(self, state: ReplState):
|
|
35
|
+
return super().completion(state)
|
|
36
|
+
|
|
37
|
+
def help(self, _: ReplState):
|
|
38
|
+
return f'{UndeployFrontend.COMMAND}\t undeploy Web frontend'
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
from adam.commands.command import Command
|
|
2
|
+
from adam.commands.postgres.postgres_context import PostgresContext
|
|
3
|
+
from adam.config import Config
|
|
4
|
+
from adam.repl_state import ReplState, RequiredState
|
|
5
|
+
from adam.utils import ing
|
|
6
|
+
|
|
7
|
+
class UndeployPgAgent(Command):
|
|
8
|
+
COMMAND = 'undeploy pg-agent'
|
|
9
|
+
|
|
10
|
+
# the singleton pattern
|
|
11
|
+
def __new__(cls, *args, **kwargs):
|
|
12
|
+
if not hasattr(cls, 'instance'): cls.instance = super(UndeployPgAgent, cls).__new__(cls)
|
|
13
|
+
|
|
14
|
+
return cls.instance
|
|
15
|
+
|
|
16
|
+
def __init__(self, successor: Command=None):
|
|
17
|
+
super().__init__(successor)
|
|
18
|
+
|
|
19
|
+
def command(self):
|
|
20
|
+
return UndeployPgAgent.COMMAND
|
|
21
|
+
|
|
22
|
+
def required(self):
|
|
23
|
+
return RequiredState.NAMESPACE
|
|
24
|
+
|
|
25
|
+
def run(self, cmd: str, state: ReplState):
|
|
26
|
+
if not(args := self.args(cmd)):
|
|
27
|
+
return super().run(cmd, state)
|
|
28
|
+
|
|
29
|
+
with self.validate(args, state) as (args, state):
|
|
30
|
+
with ing('Deleting pod'):
|
|
31
|
+
PostgresContext.undeploy_pg_agent(Config().get('pg.agent.name', 'ops-pg-agent'), state.namespace)
|
|
32
|
+
|
|
33
|
+
return state
|
|
34
|
+
|
|
35
|
+
def completion(self, state: ReplState):
|
|
36
|
+
return super().completion(state)
|
|
37
|
+
|
|
38
|
+
def help(self, _: ReplState):
|
|
39
|
+
return f'{UndeployPgAgent.COMMAND}\t undeploy Postgres agent'
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
from adam.commands.command import Command
|
|
2
|
+
from adam.commands.deploy.deploy_utils import undeploy_frontend
|
|
3
|
+
from adam.config import Config
|
|
4
|
+
from adam.utils import ing
|
|
5
|
+
from adam.utils_k8s.config_maps import ConfigMaps
|
|
6
|
+
from adam.utils_k8s.deployment import Deployments
|
|
7
|
+
from adam.utils_k8s.pods import Pods
|
|
8
|
+
from adam.utils_k8s.service_accounts import ServiceAccounts
|
|
9
|
+
from adam.repl_state import ReplState, RequiredState
|
|
10
|
+
|
|
11
|
+
class UndeployPod(Command):
|
|
12
|
+
COMMAND = 'undeploy pod'
|
|
13
|
+
|
|
14
|
+
# the singleton pattern
|
|
15
|
+
def __new__(cls, *args, **kwargs):
|
|
16
|
+
if not hasattr(cls, 'instance'): cls.instance = super(UndeployPod, cls).__new__(cls)
|
|
17
|
+
|
|
18
|
+
return cls.instance
|
|
19
|
+
|
|
20
|
+
def __init__(self, successor: Command=None):
|
|
21
|
+
super().__init__(successor)
|
|
22
|
+
|
|
23
|
+
def command(self):
|
|
24
|
+
return UndeployPod.COMMAND
|
|
25
|
+
|
|
26
|
+
def required(self):
|
|
27
|
+
return RequiredState.NAMESPACE
|
|
28
|
+
|
|
29
|
+
def run(self, cmd: str, state: ReplState):
|
|
30
|
+
if not(args := self.args(cmd)):
|
|
31
|
+
return super().run(cmd, state)
|
|
32
|
+
|
|
33
|
+
with self.validate(args, state) as (args, state):
|
|
34
|
+
label_selector = Config().get('pod.label-selector', 'run=ops')
|
|
35
|
+
with ing('Deleting service account'):
|
|
36
|
+
ServiceAccounts.delete(state.namespace, label_selector=label_selector)
|
|
37
|
+
with ing('Deleting config map'): ConfigMaps.delete_with_selector(state.namespace, label_selector)
|
|
38
|
+
with ing('Deleting deployment'): Deployments.delete_with_selector(state.namespace, label_selector, grace_period_seconds=0)
|
|
39
|
+
with ing('Deleting pod'): Pods.delete_with_selector(state.namespace, label_selector, grace_period_seconds=0)
|
|
40
|
+
undeploy_frontend(state.namespace, label_selector)
|
|
41
|
+
|
|
42
|
+
return state
|
|
43
|
+
|
|
44
|
+
def completion(self, state: ReplState):
|
|
45
|
+
return super().completion(state)
|
|
46
|
+
|
|
47
|
+
def help(self, _: ReplState):
|
|
48
|
+
return f'{UndeployPod.COMMAND}\t undeploy Ops pod'
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
from abc import abstractmethod
|
|
2
|
+
|
|
3
|
+
from adam.commands.command import Command
|
|
4
|
+
from adam.config import Config
|
|
5
|
+
from adam.pod_exec_result import PodExecResult
|
|
6
|
+
from adam.repl_state import BashSession, ReplState
|
|
7
|
+
from adam.utils import log2
|
|
8
|
+
|
|
9
|
+
class Device:
|
|
10
|
+
@abstractmethod
|
|
11
|
+
def ls(self, cmd: str, state: ReplState):
|
|
12
|
+
pass
|
|
13
|
+
|
|
14
|
+
def ls_completion(self, cmd: str, state: ReplState, default: dict = {}):
|
|
15
|
+
return default
|
|
16
|
+
|
|
17
|
+
@abstractmethod
|
|
18
|
+
def cat(self, cmd: str, state: ReplState):
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
def cat_completion(self, cmd: str, state: ReplState, default: dict = {}):
|
|
22
|
+
return default
|
|
23
|
+
|
|
24
|
+
def cd(self, dir: str, state: ReplState):
|
|
25
|
+
pass
|
|
26
|
+
|
|
27
|
+
def cd_completion(self, cmd: str, state: ReplState, default: dict = {}):
|
|
28
|
+
return default
|
|
29
|
+
|
|
30
|
+
@abstractmethod
|
|
31
|
+
def pwd(self, state: ReplState):
|
|
32
|
+
pass
|
|
33
|
+
|
|
34
|
+
def try_fallback_action(self, chain: Command, state: ReplState, cmd: str):
|
|
35
|
+
return False, None
|
|
36
|
+
|
|
37
|
+
def enter(self, state: ReplState):
|
|
38
|
+
pass
|
|
39
|
+
|
|
40
|
+
def preview(self, table: str, state: ReplState):
|
|
41
|
+
if not table:
|
|
42
|
+
if state.in_repl:
|
|
43
|
+
log2('Table is required.')
|
|
44
|
+
log2()
|
|
45
|
+
log2('Tables:')
|
|
46
|
+
self.show_tables(state)
|
|
47
|
+
else:
|
|
48
|
+
log2('* Table is missing.')
|
|
49
|
+
self.show_tables(state)
|
|
50
|
+
|
|
51
|
+
Command.display_help()
|
|
52
|
+
|
|
53
|
+
return 'command-missing'
|
|
54
|
+
|
|
55
|
+
rows = Config().get('preview.rows', 10)
|
|
56
|
+
self.show_table_preview(state, table, rows)
|
|
57
|
+
|
|
58
|
+
return state
|
|
59
|
+
|
|
60
|
+
@abstractmethod
|
|
61
|
+
def show_tables(self, state: ReplState):
|
|
62
|
+
pass
|
|
63
|
+
|
|
64
|
+
@abstractmethod
|
|
65
|
+
def show_table_preview(self, state: ReplState, table: str, rows: int):
|
|
66
|
+
pass
|
|
67
|
+
|
|
68
|
+
def bash(self, s0: ReplState, s1: ReplState, args: list[str]):
|
|
69
|
+
if s1.in_repl:
|
|
70
|
+
if self.bash_target_changed(s0, s1):
|
|
71
|
+
r = self._exec_with_dir(s1, args)
|
|
72
|
+
else:
|
|
73
|
+
r = self._exec_with_dir(s0, args)
|
|
74
|
+
|
|
75
|
+
if not r:
|
|
76
|
+
s1.exit_bash()
|
|
77
|
+
|
|
78
|
+
return 'inconsistent pwd'
|
|
79
|
+
|
|
80
|
+
return r
|
|
81
|
+
else:
|
|
82
|
+
self.exec_no_dir(' '.join(args), s1)
|
|
83
|
+
|
|
84
|
+
return s1
|
|
85
|
+
|
|
86
|
+
def _exec_with_dir(self, state: ReplState, args: list[str]) -> list[PodExecResult]:
|
|
87
|
+
session_just_created = False
|
|
88
|
+
if not args:
|
|
89
|
+
session_just_created = True
|
|
90
|
+
session = BashSession(state.device)
|
|
91
|
+
state.enter_bash(session)
|
|
92
|
+
|
|
93
|
+
if state.bash_session:
|
|
94
|
+
if args != ['pwd']:
|
|
95
|
+
if args:
|
|
96
|
+
args.append('&&')
|
|
97
|
+
args.extend(['pwd', '>', f'/tmp/.qing-{state.bash_session.session_id}'])
|
|
98
|
+
|
|
99
|
+
if not session_just_created:
|
|
100
|
+
if pwd := state.bash_session.pwd(state):
|
|
101
|
+
args = ['cd', pwd, '&&'] + args
|
|
102
|
+
|
|
103
|
+
return self.exec_with_dir(' '.join(args), session_just_created, state)
|
|
104
|
+
|
|
105
|
+
@abstractmethod
|
|
106
|
+
def bash_target_changed(self, s0: ReplState, s1: ReplState):
|
|
107
|
+
pass
|
|
108
|
+
|
|
109
|
+
@abstractmethod
|
|
110
|
+
def exec_no_dir(self, command: str, state: ReplState):
|
|
111
|
+
pass
|
|
112
|
+
|
|
113
|
+
@abstractmethod
|
|
114
|
+
def exec_with_dir(self, command: str, session_just_created: bool, state: ReplState):
|
|
115
|
+
pass
|
|
116
|
+
|
|
117
|
+
def bash_completion(self, cmd: str, state: ReplState, default: dict = {}):
|
|
118
|
+
return default
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
from adam.apps import Apps
|
|
2
|
+
from adam.commands import app
|
|
3
|
+
from adam.commands.bash.bash_completer import BashCompleter
|
|
4
|
+
from adam.commands.command import Command, InvalidState
|
|
5
|
+
from adam.commands.devices.device import Device
|
|
6
|
+
from adam.config import Config
|
|
7
|
+
from adam.repl_state import ReplState
|
|
8
|
+
from adam.utils import lines_to_tabular, log, wait_log
|
|
9
|
+
from adam.utils_k8s.app_pods import AppPods
|
|
10
|
+
from adam.utils_k8s.ingresses import Ingresses
|
|
11
|
+
|
|
12
|
+
class DeviceApp(Command, Device):
|
|
13
|
+
COMMAND = f'{ReplState.A}:'
|
|
14
|
+
|
|
15
|
+
# the singleton pattern
|
|
16
|
+
def __new__(cls, *args, **kwargs):
|
|
17
|
+
if not hasattr(cls, 'instance'): cls.instance = super(DeviceApp, cls).__new__(cls)
|
|
18
|
+
|
|
19
|
+
return cls.instance
|
|
20
|
+
|
|
21
|
+
def __init__(self, successor: Command=None):
|
|
22
|
+
super().__init__(successor)
|
|
23
|
+
|
|
24
|
+
def command(self):
|
|
25
|
+
return DeviceApp.COMMAND
|
|
26
|
+
|
|
27
|
+
def run(self, cmd: str, state: ReplState):
|
|
28
|
+
if not self.args(cmd):
|
|
29
|
+
return super().run(cmd, state)
|
|
30
|
+
|
|
31
|
+
state.device = ReplState.A
|
|
32
|
+
|
|
33
|
+
return state
|
|
34
|
+
|
|
35
|
+
def completion(self, state: ReplState):
|
|
36
|
+
return super().completion(state)
|
|
37
|
+
|
|
38
|
+
def help(self, _: ReplState):
|
|
39
|
+
return f'{DeviceApp.COMMAND}\t move to App Operations device'
|
|
40
|
+
|
|
41
|
+
def ls(self, cmd: str, state: ReplState):
|
|
42
|
+
if state.app_pod:
|
|
43
|
+
return self.bash(state, state, cmd.split(' '))
|
|
44
|
+
elif state.app_app:
|
|
45
|
+
pods = AppPods.pod_names(state.namespace, state.app_env, state.app_app)
|
|
46
|
+
|
|
47
|
+
log(lines_to_tabular(pods, 'POD_NAME'))
|
|
48
|
+
elif state.app_env:
|
|
49
|
+
def line(n: str, ns: str):
|
|
50
|
+
host = Ingresses.get_host(Config().get('app.login.ingress', '{app_id}-k8singr-appleader-001').replace('{app_id}', f'{ns}-{n}'), ns)
|
|
51
|
+
if not host:
|
|
52
|
+
return None
|
|
53
|
+
|
|
54
|
+
endpoint = Config().get('app.login.url', 'https://{host}/{env}/{app}').replace('{host}', host).replace('{env}', state.app_env).replace('{app}', 'c3')
|
|
55
|
+
if not endpoint:
|
|
56
|
+
return None
|
|
57
|
+
|
|
58
|
+
return f"{n.split('-')[1]},{Ingresses.get_host(f'{ns}-{n}-k8singr-appleader-001', ns)},{endpoint}"
|
|
59
|
+
|
|
60
|
+
svcs = [l for l in [line(n, ns) for n, ns in Apps.apps(state.app_env)] if l]
|
|
61
|
+
|
|
62
|
+
log(lines_to_tabular(svcs, 'APP,HOST,ENDPOINT', separator=','))
|
|
63
|
+
else:
|
|
64
|
+
svcs = [n for n, ns in Apps.envs()]
|
|
65
|
+
|
|
66
|
+
log(lines_to_tabular(svcs, 'ENV', separator=','))
|
|
67
|
+
|
|
68
|
+
def ls_completion(self, cmd, state, default: dict = {}):
|
|
69
|
+
if state.app_app:
|
|
70
|
+
def pod_names():
|
|
71
|
+
return [p for p in AppPods.pod_names(state.namespace, state.app_env, state.app_app)]
|
|
72
|
+
|
|
73
|
+
return super().completion(state) | {f'@{p}': {cmd: None} for p in pod_names()}
|
|
74
|
+
|
|
75
|
+
return default
|
|
76
|
+
|
|
77
|
+
def cat(self, cmd: str, state: ReplState):
|
|
78
|
+
if state.app_pod:
|
|
79
|
+
return self.bash(state, state, cmd.split(' '))
|
|
80
|
+
|
|
81
|
+
return InvalidState()
|
|
82
|
+
|
|
83
|
+
def cat_completion(self, cmd: str, state: ReplState, default: dict = {}):
|
|
84
|
+
if state.app_app:
|
|
85
|
+
return {f'@{p}': {cmd: None} for p in AppPods.pod_names(state.namespace, state.app_env, state.app_app)}
|
|
86
|
+
|
|
87
|
+
return default
|
|
88
|
+
|
|
89
|
+
def cd(self, dir: str, state: ReplState):
|
|
90
|
+
if dir == '':
|
|
91
|
+
state.app_env = None
|
|
92
|
+
state.app_app = None
|
|
93
|
+
state.app_pod = None
|
|
94
|
+
elif dir == '..':
|
|
95
|
+
if state.app_pod:
|
|
96
|
+
state.app_pod = None
|
|
97
|
+
elif state.app_app:
|
|
98
|
+
state.app_app = None
|
|
99
|
+
else:
|
|
100
|
+
state.app_env = None
|
|
101
|
+
else:
|
|
102
|
+
if state.app_app:
|
|
103
|
+
state.app_pod = dir
|
|
104
|
+
elif not state.app_env:
|
|
105
|
+
tks = dir.split('@')
|
|
106
|
+
if len(tks) > 1:
|
|
107
|
+
state.namespace = tks[1]
|
|
108
|
+
|
|
109
|
+
state.app_env = dir.split('@')[0]
|
|
110
|
+
else:
|
|
111
|
+
state.app_app = dir
|
|
112
|
+
|
|
113
|
+
def cd_completion(self, cmd: str, state: ReplState, default: dict = {}):
|
|
114
|
+
if state.app_app:
|
|
115
|
+
return {cmd: {'..': None} | {pod: None for pod in AppPods.pod_names(state.namespace, state.app_env, state.app_app)}}
|
|
116
|
+
elif state.app_env:
|
|
117
|
+
return {cmd: {'..': None} | {app[0].split('-')[1]: None for app in Apps.apps(state.app_env)}}
|
|
118
|
+
else:
|
|
119
|
+
return {cmd: {'..': None} | {env[0]: None for env in Apps.envs()}}
|
|
120
|
+
|
|
121
|
+
def pwd(self, state: ReplState):
|
|
122
|
+
words = []
|
|
123
|
+
|
|
124
|
+
if state.app_env:
|
|
125
|
+
words.append(f'env/{state.app_env}')
|
|
126
|
+
if state.app_app:
|
|
127
|
+
words.append(f'app/{state.app_app}')
|
|
128
|
+
|
|
129
|
+
return '\t'.join([f'{ReplState.X}:>'] + (words if words else ['/']))
|
|
130
|
+
|
|
131
|
+
def try_fallback_action(self, chain: Command, state: ReplState, cmd: str):
|
|
132
|
+
if state.app_app:
|
|
133
|
+
return True, chain.run(f'app {cmd}', state)
|
|
134
|
+
|
|
135
|
+
return False, None
|
|
136
|
+
|
|
137
|
+
def enter(self, state: ReplState):
|
|
138
|
+
if not state.app_env:
|
|
139
|
+
if auto_enter := Config().get('repl.a.auto-enter', 'c3/c3/*'):
|
|
140
|
+
if auto_enter != 'no':
|
|
141
|
+
ea = auto_enter.split('/')
|
|
142
|
+
state.app_env = ea[0]
|
|
143
|
+
if len(ea) > 2:
|
|
144
|
+
state.app_app = ea[1]
|
|
145
|
+
state.app_pod = ea[2]
|
|
146
|
+
if state.app_pod == '*':
|
|
147
|
+
if (pods := AppPods.pod_names(state.namespace, ea[0], ea[1])):
|
|
148
|
+
state.app_pod = pods[0]
|
|
149
|
+
wait_log(f'Moving to {state.app_env}/{state.app_app}/{state.app_pod}...')
|
|
150
|
+
else:
|
|
151
|
+
wait_log(f'No pods found, moving to {state.app_env}/{state.app_app}...')
|
|
152
|
+
else:
|
|
153
|
+
wait_log(f'Moving to {state.app_env}/{state.app_app}/{state.app_pod}...')
|
|
154
|
+
elif len(ea) > 1:
|
|
155
|
+
state.app_app = ea[1]
|
|
156
|
+
wait_log(f'Moving to {state.app_env}/{state.app_app}...')
|
|
157
|
+
else:
|
|
158
|
+
wait_log(f'Moving to {state.app_env}...')
|
|
159
|
+
|
|
160
|
+
def bash_target_changed(self, s0: ReplState, s1: ReplState):
|
|
161
|
+
return s0.app_env != s1.app_env or s0.app_app != s1.app_app or s0.app_pod != s1.app_pod
|
|
162
|
+
|
|
163
|
+
def exec_no_dir(self, command: str, state: ReplState):
|
|
164
|
+
with app(state) as pods:
|
|
165
|
+
return pods.exec(command)
|
|
166
|
+
|
|
167
|
+
def exec_with_dir(self, command: str, session_just_created: bool, state: ReplState):
|
|
168
|
+
with app(state) as pods:
|
|
169
|
+
return pods.exec(command, not session_just_created)
|
|
170
|
+
|
|
171
|
+
def bash_completion(self, cmd: str, state: ReplState, default: dict = {}):
|
|
172
|
+
return {cmd: BashCompleter(lambda: [])} | \
|
|
173
|
+
{f'@{p}': {cmd: BashCompleter(lambda: [])} for p in AppPods.pod_names(state.namespace, state.app_env, state.app_app)}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from adam.commands.command import Command
|
|
2
|
+
from adam.commands.devices.device import Device
|
|
3
|
+
from adam.repl_state import ReplState
|
|
4
|
+
from adam.utils import lines_to_tabular, log
|
|
5
|
+
from adam.utils_athena import Athena
|
|
6
|
+
|
|
7
|
+
class DeviceAuditLog(Command, Device):
|
|
8
|
+
COMMAND = f'{ReplState.L}:'
|
|
9
|
+
|
|
10
|
+
# the singleton pattern
|
|
11
|
+
def __new__(cls, *args, **kwargs):
|
|
12
|
+
if not hasattr(cls, 'instance'): cls.instance = super(DeviceAuditLog, cls).__new__(cls)
|
|
13
|
+
|
|
14
|
+
return cls.instance
|
|
15
|
+
|
|
16
|
+
def __init__(self, successor: Command=None):
|
|
17
|
+
super().__init__(successor)
|
|
18
|
+
|
|
19
|
+
def command(self):
|
|
20
|
+
return DeviceAuditLog.COMMAND
|
|
21
|
+
|
|
22
|
+
def run(self, cmd: str, state: ReplState):
|
|
23
|
+
if not self.args(cmd):
|
|
24
|
+
return super().run(cmd, state)
|
|
25
|
+
|
|
26
|
+
state.device = ReplState.L
|
|
27
|
+
|
|
28
|
+
return state
|
|
29
|
+
|
|
30
|
+
def completion(self, state: ReplState):
|
|
31
|
+
return super().completion(state)
|
|
32
|
+
|
|
33
|
+
def help(self, _: ReplState):
|
|
34
|
+
return f'{DeviceAuditLog.COMMAND}\t move to Audit Log Operations device'
|
|
35
|
+
|
|
36
|
+
def ls(self, cmd: str, _: ReplState):
|
|
37
|
+
log(lines_to_tabular(Athena.table_names(), 'NAME', separator=','))
|
|
38
|
+
|
|
39
|
+
def pwd(self, _: ReplState):
|
|
40
|
+
return '\t'.join([f'{ReplState.L}:>', '/'])
|
|
41
|
+
|
|
42
|
+
def try_fallback_action(self, chain: Command, state: ReplState, cmd: str):
|
|
43
|
+
return True, chain.run(f'audit {cmd}', state)
|
|
44
|
+
|
|
45
|
+
def show_tables(self, _: ReplState):
|
|
46
|
+
log(lines_to_tabular(Athena.table_names(), separator=','))
|
|
47
|
+
|
|
48
|
+
def show_table_preview(self, _: ReplState, table: str, rows: int):
|
|
49
|
+
Athena.run_query(f'select * from {table} limit {rows}')
|