mas-cli 10.0.5__py3-none-any.whl → 10.1.0__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.

Potentially problematic release.


This version of mas-cli might be problematic. Click here for more details.

@@ -1,284 +0,0 @@
1
- #!python
2
- # *****************************************************************************
3
- # Copyright (c) 2024 IBM Corporation and other Contributors.
4
- #
5
- # All rights reserved. This program and the accompanying materials
6
- # are made available under the terms of the Eclipse Public License v1.0
7
- # which accompanies this distribution, and is available at
8
- # http://www.eclipse.org/legal/epl-v10.html
9
- #
10
- # *****************************************************************************
11
-
12
- import argparse
13
- import sys
14
- import logging
15
- import logging.handlers
16
- from prompt_toolkit import prompt, print_formatted_text, HTML
17
- from prompt_toolkit.completion import WordCompleter
18
-
19
- from halo import Halo
20
-
21
- from mas.cli import __version__ as packageVersion
22
- from mas.cli.cli import BaseApp, getHelpFormatter
23
- from mas.cli.validators import InstanceIDValidator, YesNoValidator
24
- from mas.devops.ocp import createNamespace
25
- from mas.devops.mas import listMasInstances, verifyMasInstance
26
- from mas.devops.tekton import installOpenShiftPipelines, updateTektonDefinitions, launchUninstallPipeline
27
- from openshift.dynamic.exceptions import NotFoundError
28
-
29
- logger = logging.getLogger(__name__)
30
-
31
- class App(BaseApp):
32
- def uninstall(self, args):
33
- """
34
- Uninstall MAS instance
35
- """
36
- instanceId = args.instance_id
37
- self.noConfirm = args.no_confirm
38
-
39
- if args.uninstall_all_deps:
40
- uninstallGrafana = True
41
- uninstallIBMCatalog = True
42
- uninstallCommonServices = True
43
- uninstallCertManager = True
44
- uninstallUDS = True
45
- uninstallMongoDb = True
46
- uninstallSLS = True
47
- else:
48
- uninstallGrafana = args.uninstall_grafana
49
- uninstallIBMCatalog = args.uninstall_ibm_catalog
50
- uninstallCommonServices = args.uninstall_common_services
51
- uninstallCertManager = args.uninstall_cert_manager
52
- uninstallUDS = args.uninstall_uds
53
- uninstallMongoDb = args.uninstall_mongodb
54
- uninstallSLS = args.uninstall_sls
55
-
56
- if instanceId is None:
57
- self.printH1("Set Target OpenShift Cluster")
58
- # Connect to the target cluster
59
- self.connect()
60
- else:
61
- logger.debug("MAS instance ID is set, so we assume already connected to the desired OCP")
62
-
63
- if self.dynamicClient is None:
64
- print_formatted_text(HTML("<Red>Error: The Kubernetes dynamic Client is not available. See log file for details</Red>"))
65
- sys.exit(1)
66
-
67
- if instanceId is None:
68
- # Interactive mode
69
- self.printH1("Instance Selection")
70
- print_formatted_text(HTML("<LightSlateGrey>Select a MAS instance to uninstall from the list below:</LightSlateGrey>"))
71
- suites = listMasInstances(self.dynamicClient)
72
- suiteOptions = []
73
- for suite in suites:
74
- print_formatted_text(HTML(f"- <u>{suite['metadata']['name']}</u> v{suite['status']['versions']['reconciled']}"))
75
- suiteOptions.append(suite['metadata']['name'])
76
-
77
- suiteCompleter = WordCompleter(suiteOptions)
78
- print()
79
- instanceId = prompt(HTML(f'<Yellow>Enter MAS instance ID: </Yellow>'), completer=suiteCompleter, validator=InstanceIDValidator(), validate_while_typing=False)
80
-
81
- self.printH1("Uninstall MAS Dependencies")
82
- uninstallCertManager = prompt(HTML(f'<Yellow>Uninstall Certificate Manager? </Yellow>'), validator=YesNoValidator()) in ["y", "yes"]
83
- if uninstallCertManager:
84
- # If you choose to uninstall Cert-Manager, everything will be uninstalled
85
- uninstallGrafana = True
86
- uninstallIBMCatalog = True
87
- uninstallCommonServices = True
88
- uninstallUDS = True
89
- uninstallMongoDb = True
90
- uninstallSLS = True
91
- else:
92
- uninstallMongoDb = prompt(HTML(f'<Yellow>Uninstall MongoDb? </Yellow>'), validator=YesNoValidator()) in ["y", "yes"]
93
- if uninstallMongoDb:
94
- # If you are removing MongoDb then SLS needs to be uninstalled too
95
- uninstallSLS = True
96
- else:
97
- uninstallSLS = prompt(HTML(f'<Yellow>Uninstall IBM Suite Licensing Service? </Yellow>'), validator=YesNoValidator()) in ["y", "yes"]
98
-
99
- uninstallGrafana = prompt(HTML(f'<Yellow>Uninstall Grafana? </Yellow>'), validator=YesNoValidator()) in ["y", "yes"]
100
- uninstallIBMCatalog = prompt(HTML(f'<Yellow>Uninstall IBM Catalog Source? </Yellow>'), validator=YesNoValidator()) in ["y", "yes"]
101
- if uninstallIBMCatalog:
102
- # If you choose to uninstall IBM Operator Catalog, everything from the catalog will be uninstalled
103
- uninstallCommonServices = True
104
- uninstallUDS = True
105
- uninstallMongoDb = True
106
- uninstallSLS = True
107
- else:
108
- uninstallCommonServices = prompt(HTML(f'<Yellow>Uninstall IBM Common Services? </Yellow>'), validator=YesNoValidator()) in ["y", "yes"]
109
- uninstallUDS = prompt(HTML(f'<Yellow>Uninstall IBM User Data Services? </Yellow>'), validator=YesNoValidator()) in ["y", "yes"]
110
-
111
- else:
112
- # Non-interactive mode
113
- if not verifyMasInstance(self.dynamicClient, instanceId):
114
- print_formatted_text(HTML(f"<Red>Error: MAS Instance {instanceId} not found on this cluster</Red>"))
115
- sys.exit(1)
116
-
117
- # Default to Red Hat Cert-Manager, and check if IBM cert-manager is installed
118
- certManagerProvider="redhat"
119
- try:
120
- # Check if 'ibm-common-services' namespace exist, this will throw NotFoundError exception when not found.
121
- namespaceAPI = self.dynamicClient.resources.get(api_version="v1", kind="Namespace")
122
- namespaceAPI.get(name="ibm-common-services")
123
-
124
- podsAPI = self.dynamicClient.resources.get(api_version="v1", kind="Pod")
125
- podsList = podsAPI.get(namespace="ibm-common-services")
126
- for pod in podsList.items:
127
- if pod is not None and "cert-manager-cainjector" in pod.metadata.name:
128
- certManagerProvider = "ibm"
129
- except NotFoundError:
130
- print()
131
- # ibm cert manager not found, proceed with default redhat.
132
-
133
- self.printH1("Review Settings")
134
- print_formatted_text(HTML(f"<LightSlateGrey>Instance ID ..................... {instanceId}</LightSlateGrey>"))
135
- print_formatted_text(HTML(f"<LightSlateGrey>Uninstall Cert-Manager .......... {uninstallCertManager} ({certManagerProvider})</LightSlateGrey>"))
136
- print_formatted_text(HTML(f"<LightSlateGrey>Uninstall Grafana ............... {uninstallGrafana}</LightSlateGrey>"))
137
- print_formatted_text(HTML(f"<LightSlateGrey>Uninstall IBM Operator Catalog .. {uninstallIBMCatalog}</LightSlateGrey>"))
138
- print_formatted_text(HTML(f"<LightSlateGrey>Uninstall IBM Common Services ... {uninstallCommonServices}</LightSlateGrey>"))
139
- print_formatted_text(HTML(f"<LightSlateGrey>Uninstall UDS ................... {uninstallUDS}</LightSlateGrey>"))
140
- print_formatted_text(HTML(f"<LightSlateGrey>Uninstall MongoDb ............... {uninstallMongoDb}</LightSlateGrey>"))
141
- print_formatted_text(HTML(f"<LightSlateGrey>Uninstall SLS ................... {uninstallSLS}</LightSlateGrey>"))
142
-
143
- if not self.noConfirm:
144
- print()
145
- continueWithUninstall = prompt(HTML(f'<Yellow>Proceed with these settings?</Yellow> '), validator=YesNoValidator(), validate_while_typing=False)
146
-
147
- if self.noConfirm or continueWithUninstall in ["y", "yes"]:
148
- self.printH1("Launch uninstall")
149
- pipelinesNamespace = f"mas-{instanceId}-pipelines"
150
-
151
- with Halo(text='Validating OpenShift Pipelines installation', spinner=self.spinner) as h:
152
- installOpenShiftPipelines(self.dynamicClient)
153
- h.stop_and_persist(symbol=self.successIcon, text=f"OpenShift Pipelines Operator is installed and ready to use")
154
-
155
- with Halo(text=f'Preparing namespace ({pipelinesNamespace})', spinner=self.spinner) as h:
156
- createNamespace(self.dynamicClient, pipelinesNamespace)
157
- h.stop_and_persist(symbol=self.successIcon, text=f"Namespace is ready ({pipelinesNamespace})")
158
-
159
- with Halo(text=f'Installing latest Tekton definitions (v{self.version})', spinner=self.spinner) as h:
160
- updateTektonDefinitions(pipelinesNamespace, self.tektonDefsPath)
161
- h.stop_and_persist(symbol=self.successIcon, text=f"Latest Tekton definitions are installed (v{self.version})")
162
-
163
- with Halo(text='Submitting PipelineRun for {instanceId} uninstall', spinner=self.spinner) as h:
164
- pipelineURL = launchUninstallPipeline(
165
- dynClient = self.dynamicClient,
166
- instanceId = instanceId,
167
- certManagerProvider = "redhat",
168
- uninstallCertManager = uninstallCertManager,
169
- uninstallGrafana = uninstallGrafana,
170
- uninstallCatalog = uninstallCommonServices,
171
- uninstallCommonServices = uninstallCommonServices,
172
- uninstallUDS = uninstallUDS,
173
- uninstallMongoDb = uninstallMongoDb,
174
- uninstallSLS = uninstallSLS
175
- )
176
- if pipelineURL is not None:
177
- h.stop_and_persist(symbol=self.successIcon, text=f"PipelineRun for {instanceId} uninstall submitted")
178
- print_formatted_text(HTML(f"\nView progress:\n <Cyan><u>{pipelineURL}</u></Cyan>\n"))
179
- else:
180
- h.stop_and_persist(symbol=self.failureIcon, text=f"Failed to submit PipelineRun for {instanceId} uninstall, see log file for details")
181
- print()
182
-
183
- if __name__ == '__main__':
184
- parser = argparse.ArgumentParser(
185
- prog='mas uninstall',
186
- description="\n".join([
187
- f"IBM Maximo Application Suite Admin CLI v{packageVersion}",
188
- "Uninstall MAS by configuring and launching the MAS Uninstall Tekton Pipeline.\n",
189
- "Interactive Mode:",
190
- "Omitting the --instance-id option will trigger an interactive prompt"
191
- ]),
192
- epilog="Refer to the online documentation for more information: https://ibm-mas.github.io/cli/",
193
- formatter_class=getHelpFormatter(),
194
- add_help=False
195
- )
196
-
197
- masArgGroup = parser.add_argument_group('MAS Instance Selection')
198
- masArgGroup.add_argument(
199
- '--instance-id',
200
- required=False,
201
- help="The MAS instance ID to be uninstalled"
202
- )
203
-
204
- depsArgGroup = parser.add_argument_group('MAS Dependencies Selection')
205
- depsArgGroup.add_argument(
206
- '--uninstall-all-deps',
207
- required=False,
208
- action='store_true',
209
- default=False,
210
- help="Uninstall all MAS-related dependencies from the target cluster",
211
- )
212
-
213
- depsArgGroup.add_argument(
214
- '--uninstall-cert-manager',
215
- required=False,
216
- action='store_true',
217
- default=False,
218
- help="Uninstall Certificate Manager from the target cluster",
219
- )
220
- depsArgGroup.add_argument(
221
- '--uninstall-common-services',
222
- required=False,
223
- action='store_true',
224
- default=False,
225
- help="Uninstall IBM Common Services from the target cluster",
226
- )
227
- depsArgGroup.add_argument(
228
- '--uninstall-grafana',
229
- required=False,
230
- action='store_true',
231
- default=False,
232
- help="Uninstall Grafana from the target cluster",
233
- )
234
- depsArgGroup.add_argument(
235
- '--uninstall-ibm-catalog',
236
- required=False,
237
- action='store_true',
238
- default=False,
239
- help="Uninstall the IBM Maximo Operator Catalog Source (ibm-operator-catalog) from the target cluster",
240
- )
241
- depsArgGroup.add_argument(
242
- '--uninstall-mongodb',
243
- required=False,
244
- action='store_true',
245
- default=False,
246
- help="Uninstall MongoDb from the target cluster",
247
- )
248
- depsArgGroup.add_argument(
249
- '--uninstall-sls',
250
- required=False,
251
- action='store_true',
252
- default=False,
253
- help="Uninstall IBM Suite License Service from the target cluster",
254
- )
255
- depsArgGroup.add_argument(
256
- '--uninstall-uds',
257
- required=False,
258
- action='store_true',
259
- default=False,
260
- help="Uninstall IBM User Data Services from the target cluster",
261
- )
262
-
263
- otherArgGroup = parser.add_argument_group('More')
264
- otherArgGroup.add_argument(
265
- '--no-confirm',
266
- required=False,
267
- action='store_true',
268
- default=False,
269
- help="Launch the upgrade without prompting for confirmation",
270
- )
271
- otherArgGroup.add_argument(
272
- '-h', "--help",
273
- action='help',
274
- default=False,
275
- help="Show this help message and exit",
276
- )
277
-
278
- args = parser.parse_args()
279
-
280
- try:
281
- app = App()
282
- app.uninstall(args)
283
- except KeyboardInterrupt as e:
284
- pass