@opscompass/opscompass-cli 1.0.41 → 1.0.42

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.
@@ -0,0 +1,285 @@
1
+ const { getOpsCompassClient } = require("../../opscompass.js");
2
+ const { utilsModule: utils } = require("../../lib/utils.js");
3
+ const maskValues = require("../../lib/maskValues.js");
4
+
5
+ /**
6
+ * @module license-manager:nutanix
7
+ * @description License Manager Nutanix module for OpsCompass CLI
8
+ */
9
+
10
+ const { createMaskedConfig, updateMaskedConfig } = require("./maskedConfig.js");
11
+
12
+ async function deleteNutanixConfiguration(args) {
13
+ let id = undefined;
14
+ for (let i = 0; i < args.length - 1; i++) {
15
+ switch (args[i].toLowerCase()) {
16
+ case "--id":
17
+ id = args[++i];
18
+ break;
19
+ }
20
+ }
21
+
22
+ const client = await getOpsCompassClient();
23
+ const response = await client.licenseManager.nutanix.deleteConfiguration(id);
24
+
25
+ console.log(JSON.stringify(response, null, 2));
26
+ }
27
+
28
+ async function listNutanixConfigurations(args) {
29
+ const client = await getOpsCompassClient();
30
+ const listNutanixConfigs =
31
+ await client.licenseManager.nutanix.listConfigurations(
32
+ global.monitoringConfig
33
+ );
34
+
35
+ // For listing show the raw data (do not unmask the data here)
36
+ // if (listNutanixConfigs && listNutanixConfigs.length > 0) {
37
+ // await maskValues.unmaskObjValues(listNutanixConfigs);
38
+ // }
39
+ console.log(JSON.stringify(listNutanixConfigs, null, 2));
40
+ }
41
+
42
+ async function getNutanixConfiguration(args) {
43
+ let id = undefined;
44
+ for (let i = 0; i < args.length - 1; i++) {
45
+ switch (args[i].toLowerCase()) {
46
+ case "--id":
47
+ id = args[++i];
48
+ break;
49
+ }
50
+ }
51
+
52
+ const client = await getOpsCompassClient();
53
+ const getNutanixConfig = await client.licenseManager.nutanix.getConfiguration(
54
+ id
55
+ );
56
+
57
+ console.log(JSON.stringify(getNutanixConfig, null, 2));
58
+ }
59
+
60
+ async function createNutanixConfiguration(args) {
61
+ let configurationName = undefined;
62
+ let optionalParams = {
63
+ actions: undefined,
64
+ server: undefined,
65
+ user: undefined,
66
+ password: undefined,
67
+ };
68
+ for (let i = 0; i < args.length - 1; i++) {
69
+ switch (args[i].toLowerCase()) {
70
+ case "--name":
71
+ case "--configuration-name":
72
+ case "--configurationname":
73
+ configurationName = args[++i];
74
+ break;
75
+ case "--action":
76
+ if (optionalParams.actions === undefined) optionalParams.actions = [];
77
+ optionalParams.actions.push(args[++i]);
78
+ break;
79
+ case "--server":
80
+ optionalParams.server = args[++i];
81
+ break;
82
+ case "--user":
83
+ optionalParams.user = args[++i];
84
+ break;
85
+ case "--password":
86
+ optionalParams.password = args[++i];
87
+ break;
88
+ }
89
+ }
90
+
91
+ const nutanixConfiguration = await createMaskedConfig(
92
+ arguments.callee.name,
93
+ configurationName,
94
+ optionalParams
95
+ );
96
+ console.log(JSON.stringify(nutanixConfiguration, null, 2));
97
+ }
98
+
99
+ async function updateNutanixConfiguration(args) {
100
+ for (let i = 0; i < args.length - 1; i++) {
101
+ switch (args[i].toLowerCase()) {
102
+ case "--id":
103
+ callParams.id = args[++i];
104
+ break;
105
+ case "--name":
106
+ case "--configurationname":
107
+ case "--configuration-name":
108
+ callParams.configurationName = args[++i];
109
+ break;
110
+ case "--action":
111
+ if (callParams.actions === undefined) callParams.actions = [];
112
+ callParams.actions.push(args[++i]);
113
+ break;
114
+ case "--server":
115
+ callParams.server = args[++i];
116
+ break;
117
+ case "--user":
118
+ callParams.user = args[++i];
119
+ break;
120
+ case "--password":
121
+ callParams.password = args[++i];
122
+ break;
123
+ }
124
+ }
125
+
126
+ const nutanixConfiguration = await updateMaskedConfig(
127
+ arguments.callee.name,
128
+ callParams.id,
129
+ callParams
130
+ );
131
+ console.log(JSON.stringify(nutanixConfiguration, null, 2));
132
+ }
133
+
134
+ async function updateNutanixConfigurations(args) {
135
+ let callParamsArray = [];
136
+ let jsonIndex = args.indexOf("--json-updates");
137
+ let idIndex = args.indexOf("--id");
138
+ let callParams = {};
139
+
140
+ /* Process bulk update with JSON */
141
+ if (jsonIndex !== -1) {
142
+ const jsonString = args[jsonIndex + 1] || (await utils.readFromStdinSync());
143
+ if (!jsonString) {
144
+ if (process.stdin.isTTY) {
145
+ console.error("No JSON nutanix string provided as argument or stdin");
146
+ return console.log("");
147
+ }
148
+ }
149
+ callParamsArray = utils.parseConfigurationJson(jsonString);
150
+ } else if (idIndex !== -1) {
151
+ /* If no '--json-update' flag, process bulk update with parameter flags (e.g. --id, --name, etc.) */
152
+ for (let i = 0; i < args.length - 1; i++) {
153
+ if (args[i] === "--id") {
154
+ /* Reset callParams object when a second id is encountered */
155
+ callParams = {};
156
+ /* if theres an existing callParams object, toss it into the array and move on. */
157
+ callParamsArray.push(callParams);
158
+ /* Create the object's properties based on the index (e.g. if the index is --id, you'll find the value at the next index */
159
+ callParams.id = args[i + 1];
160
+ } else if (
161
+ args[i].toLowerCase() === "--configurationname" ||
162
+ args[i].toLowerCase() === "--configuration-name" ||
163
+ args[i].toLowerCase() === "--name"
164
+ ) {
165
+ callParams.configurationName = args[i + 1];
166
+ } else if (args[i].toLowerCase() === "--action") {
167
+ if (callParams.actions === undefined) callParams.actions = [];
168
+ callParams.actions.push(args[i + 1]);
169
+ } else if (args[i.toLowerCase] === "--server") {
170
+ callParams.server = args[i + 1];
171
+ } else if (args[i.toLowerCase] === "--user") {
172
+ callParams.user = args[i + 1];
173
+ } else if (args[i.toLowerCase] === "--password") {
174
+ callParams.password = args[i + 1];
175
+ }
176
+ }
177
+ } else {
178
+ console.warn("Invalid input, please see help for examples.");
179
+ return console.log("");
180
+ }
181
+ // In case the cut/paste from an local config with values hashed
182
+ utils.decryptValues(callParamsArray);
183
+
184
+ // If the callParamsArray is empty, we have nothing to mask
185
+ if (!callParamsArray) {
186
+ console.warn("No nutanix configurations provided to update.");
187
+ return console.log("");
188
+ }
189
+
190
+ // Here we need to mask the callParamsArray object
191
+ await maskValues.maskObjValues(callParamsArray);
192
+
193
+ /* Call the API and print to console */
194
+ const client = await getOpsCompassClient();
195
+ const nutanixConfigurations =
196
+ await client.licenseManager.nutanix.updateConfigurations(callParamsArray);
197
+ console.log(JSON.stringify(nutanixConfigurations, null, 2));
198
+ }
199
+
200
+ async function printNutanixHelp() {
201
+ console.log(
202
+ "list-nutanix-configurations",
203
+ "Lists all of the nutanix configurations associated with the given monitoring configuration"
204
+ );
205
+ console.log("Parameters:");
206
+ console.log("--monitoring-configuration-id [monitoring_configuration_id]");
207
+ console.log();
208
+ console.log(
209
+ "get-nutanix-configuration",
210
+ "Get a single nutanix configuration associated with the given monitoring configuration"
211
+ );
212
+ console.log("Parameters:");
213
+ console.log("--id [nutanix_configuration_id]");
214
+ console.log();
215
+ console.log(
216
+ "create-nutanix-configuration",
217
+ "Create a single nutanix configuration associated with the given monitoring configuration."
218
+ );
219
+ console.log("Parameters:");
220
+ console.log("--monitoring-configuration-id [monitoring_configuration_id]");
221
+ console.log("--name [unique name]");
222
+ console.log(
223
+ `--action (optional) pass multiple times to define which actions this configuration can take e.g. --action "skip" --action "inventory"`
224
+ );
225
+ console.log("--server (optional) [the hostname or ip address]");
226
+ console.log("--user (optional) [server username]");
227
+ console.log("--password (optional) [server password]");
228
+ console.log();
229
+ console.log(
230
+ "update-nutanix-configuration",
231
+ "Update a single nutanix configuration."
232
+ );
233
+ console.log("Parameters:");
234
+ console.log("--id [configuration id]");
235
+ console.log("--name or --configuration-name (optional) [unique name]");
236
+ console.log(
237
+ "--action (optional) pass multiple times to define which actions this configuration can take e.g. --action 'skip' --action 'inventory']"
238
+ );
239
+ console.log("--server (optional) [the hostname or ip address]");
240
+ console.log("--user (optional) [server username]");
241
+ console.log("--password (optional) [server password]");
242
+ console.log();
243
+ console.log(
244
+ "update-nutanix-configurations",
245
+ "Bulk Update nutanix configurations."
246
+ );
247
+ console.log("Parameters:");
248
+ console.log("--id [configuration id]");
249
+ console.log("--name or --configuration-name (optional) [unique name]");
250
+ console.log(
251
+ `--action (optional) pass multiple times to define which actions this configuration can take e.g. --action "skip" --action "inventory"`
252
+ );
253
+ console.log("--server (optional) [the hostname or ip address]");
254
+ console.log("--user (optional) [server username]");
255
+ console.log("--password (optional) [server password]");
256
+ console.log("OR --json-updates [stringified json objects with your updates]");
257
+ console.log("For quick updates, you may use the above parameters");
258
+ console.log(
259
+ `e.g. opscompass license-manager update-nutanix-configurations --id 137 --name "updatedName" --id 138 --name "otherUpdatedName" --id 144 --name "lastUpdatedName" --action "skip" --action "inventory";`
260
+ );
261
+ console.log(
262
+ "For larger updates, JavaScript Object Notation (JSON) may be used with the --json-updates flag"
263
+ );
264
+ console.log(
265
+ `e.g. opscompass license-manager update-nutanix-configurations --json-updates '[{\"id\":\"137\",\"configurationName\":\"updatedName\"},{\"id\":\"138\",\"configurationName\":\"otherUpdatedName\"},{\"id\":\"144\",\"configurationName\":\"lastUpdatedName\", \"actions\":[\"skip\", \"inventory\"]}]'`
266
+ );
267
+ console.log();
268
+ console.log("delete-nutanix-configuration", "Delete a nutanix configuration");
269
+ console.log("Parameters:");
270
+ console.log("--id [nutanix_configuration_id]");
271
+ console.log();
272
+ }
273
+
274
+ const licenseManagerNutanixModule = {
275
+ description: "License Manager Nutanix module for OpsCompass CLI",
276
+ requiresLogin: true,
277
+ listNutanixConfigurations,
278
+ getNutanixConfiguration,
279
+ createNutanixConfiguration,
280
+ updateNutanixConfiguration,
281
+ updateNutanixConfigurations,
282
+ deleteNutanixConfiguration,
283
+ printNutanixHelp,
284
+ };
285
+ module.exports = licenseManagerNutanixModule;
@@ -0,0 +1,281 @@
1
+ const { getOpsCompassClient } = require("../../opscompass.js");
2
+ const { utilsModule: utils } = require("../../lib/utils.js");
3
+ const maskValues = require("../../lib/maskValues.js");
4
+
5
+ /**
6
+ * @module license-manager:vcenter
7
+ * @description License Manager Vcenter module for OpsCompass CLI
8
+ */
9
+
10
+ const { createMaskedConfig, updateMaskedConfig } = require("./maskedConfig.js");
11
+
12
+ async function deleteVcenterConfiguration(args) {
13
+ let id = undefined;
14
+ for (let i = 0; i < args.length - 1; i++) {
15
+ switch (args[i].toLowerCase()) {
16
+ case "--id":
17
+ id = args[++i];
18
+ break;
19
+ }
20
+ }
21
+
22
+ const client = await getOpsCompassClient();
23
+ const response = await client.licenseManager.vcenter.deleteConfiguration(id);
24
+
25
+ console.log(JSON.stringify(response, null, 2));
26
+ }
27
+
28
+ async function listVcenterConfigurations(args) {
29
+ const client = await getOpsCompassClient();
30
+ const listVcenterConfigs =
31
+ await client.licenseManager.vcenter.listConfigurations(
32
+ global.monitoringConfig
33
+ );
34
+
35
+ console.log(JSON.stringify(listVcenterConfigs, null, 2));
36
+ }
37
+
38
+ async function getVcenterConfiguration(args) {
39
+ let id = undefined;
40
+ for (let i = 0; i < args.length - 1; i++) {
41
+ switch (args[i].toLowerCase()) {
42
+ case "--id":
43
+ id = args[++i];
44
+ break;
45
+ }
46
+ }
47
+
48
+ const client = await getOpsCompassClient();
49
+ const getVcenterConfig = await client.licenseManager.vcenter.getConfiguration(
50
+ id
51
+ );
52
+
53
+ console.log(JSON.stringify(getVcenterConfig, null, 2));
54
+ }
55
+
56
+ async function createVcenterConfiguration(args) {
57
+ let configurationName = undefined;
58
+ let optionalParams = {
59
+ actions: undefined,
60
+ connection: undefined,
61
+ user: undefined,
62
+ password: undefined,
63
+ };
64
+ for (let i = 0; i < args.length - 1; i++) {
65
+ switch (args[i].toLowerCase()) {
66
+ case "--name":
67
+ case "--configuration-name":
68
+ case "--configurationname":
69
+ configurationName = args[++i];
70
+ break;
71
+ case "--action":
72
+ if (optionalParams.actions === undefined) optionalParams.actions = [];
73
+ optionalParams.actions.push(args[++i]);
74
+ break;
75
+ case "--connection":
76
+ optionalParams.connection = args[++i];
77
+ break;
78
+ case "--user":
79
+ optionalParams.user = args[++i];
80
+ break;
81
+ case "--password":
82
+ optionalParams.password = args[++i];
83
+ break;
84
+ }
85
+ }
86
+
87
+ const vCenterConfiguration = await createMaskedConfig(
88
+ arguments.callee.name,
89
+ configurationName,
90
+ optionalParams
91
+ );
92
+ console.log(JSON.stringify(vCenterConfiguration, null, 2));
93
+ }
94
+
95
+ async function updateVcenterConfiguration(args) {
96
+ for (let i = 0; i < args.length - 1; i++) {
97
+ switch (args[i].toLowerCase()) {
98
+ case "--id":
99
+ callParams.id = args[++i];
100
+ break;
101
+ case "--name":
102
+ case "--configurationname":
103
+ case "--configuration-name":
104
+ callParams.configurationName = args[++i];
105
+ break;
106
+ case "--action":
107
+ if (callParams.actions === undefined) callParams.actions = [];
108
+ callParams.actions.push(args[++i]);
109
+ break;
110
+ case "--connection":
111
+ callParams.connection = args[++i];
112
+ break;
113
+ case "--user":
114
+ callParams.user = args[++i];
115
+ break;
116
+ case "--password":
117
+ callParams.password = args[++i];
118
+ break;
119
+ }
120
+ }
121
+
122
+ const vCenterConfiguration = await updateMaskedConfig(
123
+ arguments.callee.name,
124
+ callParams.id,
125
+ callParams
126
+ );
127
+ console.log(JSON.stringify(vCenterConfiguration, null, 2));
128
+ }
129
+
130
+ async function updateVcenterConfigurations(args) {
131
+ let callParamsArray = [];
132
+ let jsonIndex = args.indexOf("--json-updates");
133
+ let idIndex = args.indexOf("--id");
134
+ let callParams = {};
135
+
136
+ /* Process bulk update with JSON */
137
+ if (jsonIndex !== -1) {
138
+ const jsonString = args[jsonIndex + 1] || (await utils.readFromStdinSync());
139
+ if (!jsonString) {
140
+ if (process.stdin.isTTY) {
141
+ console.error("No JSON vCenter string provided as argument or stdin");
142
+ return console.log("");
143
+ }
144
+ }
145
+ callParamsArray = utils.parseConfigurationJson(jsonString);
146
+ } else if (idIndex !== -1) {
147
+ /* If no '--json-update' flag, process bulk update with parameter flags (e.g. --id, --name, etc.) */
148
+ for (let i = 0; i < args.length - 1; i++) {
149
+ if (args[i] === "--id") {
150
+ /* Reset callParams object when a second id is encountered */
151
+ callParams = {};
152
+ /* if theres an existing callParams object, toss it into the array and move on. */
153
+ callParamsArray.push(callParams);
154
+ /* Create the object's properties based on the index (e.g. if the index is --id, you'll find the value at the next index */
155
+ callParams.id = args[i + 1];
156
+ } else if (
157
+ args[i].toLowerCase() === "--configurationname" ||
158
+ args[i].toLowerCase() === "--configuration-name" ||
159
+ args[i].toLowerCase() === "--name"
160
+ ) {
161
+ callParams.configurationName = args[i + 1];
162
+ } else if (args[i].toLowerCase() === "--action") {
163
+ if (callParams.actions === undefined) callParams.actions = [];
164
+ callParams.actions.push(args[i + 1]);
165
+ } else if (args[i.toLowerCase] === "--connection") {
166
+ callParams.connection = args[i + 1];
167
+ } else if (args[i.toLowerCase] === "--user") {
168
+ callParams.user = args[i + 1];
169
+ } else if (args[i.toLowerCase] === "--password") {
170
+ callParams.password = args[i + 1];
171
+ }
172
+ }
173
+ } else {
174
+ console.warn("Invalid input, please see help for examples.");
175
+ return console.log("");
176
+ }
177
+ // In case the cut/paste from an local config with values hashed
178
+ utils.decryptValues(callParamsArray);
179
+
180
+ // If the callParamsArray is empty, we have nothing to mask
181
+ if (!callParamsArray) {
182
+ console.warn("No vCenter configurations provided to update.");
183
+ return console.log("");
184
+ }
185
+
186
+ // Here we need to mask the callParamsArray object
187
+ await maskValues.maskObjValues(callParamsArray);
188
+
189
+ /* Call the API and print to console */
190
+ const client = await getOpsCompassClient();
191
+ const vCenterConfigurations =
192
+ await client.licenseManager.vcenter.updateConfigurations(callParamsArray);
193
+ console.log(JSON.stringify(vCenterConfigurations, null, 2));
194
+ }
195
+
196
+ async function printVcenterHelp() {
197
+ console.log(
198
+ "list-vcenter-configurations",
199
+ "Lists all of the vcenter configurations associated with the given monitoring configuration"
200
+ );
201
+ console.log("Parameters:");
202
+ console.log("--monitoring-configuration-id [monitoring_configuration_id]");
203
+ console.log();
204
+ console.log(
205
+ "get-vcenter-configuration",
206
+ "Get a single vcenter configuration associated with the given monitoring configuration"
207
+ );
208
+ console.log("Parameters:");
209
+ console.log("--id [vcenter_configuration_id]");
210
+ console.log();
211
+ console.log(
212
+ "create-vcenter-configuration",
213
+ "Create a single vcenter configuration associated with the given monitoring configuration."
214
+ );
215
+ console.log("Parameters:");
216
+ console.log("--monitoring-configuration-id [monitoring_configuration_id]");
217
+ console.log("--name [unique name]");
218
+ console.log(
219
+ `--action (optional) pass multiple times to define which actions this configuration can take e.g. --action "skip" --action "vmotion"`
220
+ );
221
+ console.log("--connection (optional) [the hostname or ip address]");
222
+ console.log("--user (optional) [connection username]");
223
+ console.log("--password (optional) [connection password]");
224
+ console.log();
225
+ console.log(
226
+ "update-vcenter-configuration",
227
+ "Update a single vcenter configuration."
228
+ );
229
+ console.log("Parameters:");
230
+ console.log("--id [configuration id]");
231
+ console.log("--name or --configuration-name (optional) [unique name]");
232
+ console.log(
233
+ "--action (optional) pass multiple times to define which actions this configuration can take e.g. --action 'skip' --action 'vmotion']"
234
+ );
235
+ console.log("--connection (optional) [the hostname or ip address]");
236
+ console.log("--user (optional) [connection username]");
237
+ console.log("--password (optional) [connection password]");
238
+ console.log();
239
+ console.log(
240
+ "update-vcenter-configurations",
241
+ "Bulk Update vcenter configurations."
242
+ );
243
+ console.log("Parameters:");
244
+ console.log("--id [configuration id]");
245
+ console.log("--name or --configuration-name (optional) [unique name]");
246
+ console.log(
247
+ `--action (optional) pass multiple times to define which actions this configuration can take e.g. --action "skip" --action "vmotion"`
248
+ );
249
+ console.log("--connection (optional) [the hostname or ip address]");
250
+ console.log("--user (optional) [connection username]");
251
+ console.log("--password (optional) [connection password]");
252
+ console.log("OR --json-updates [stringified json objects with your updates]");
253
+ console.log("For quick updates, you may use the above parameters");
254
+ console.log(
255
+ `e.g. opscompass license-manager update-vcenter-configurations --id 137 --name "updatedName" --id 138 --name "otherUpdatedName" --id 144 --name "lastUpdatedName" --action "skip" --action "vmotion";`
256
+ );
257
+ console.log(
258
+ "For larger updates, JavaScript Object Notation (JSON) may be used with the --json-updates flag"
259
+ );
260
+ console.log(
261
+ `e.g. opscompass license-manager update-vcenter-configurations --json-updates '[{\"id\":\"137\",\"configurationName\":\"updatedName\"},{\"id\":\"138\",\"configurationName\":\"otherUpdatedName\"},{\"id\":\"144\",\"configurationName\":\"lastUpdatedName\", \"actions\":[\"skip\", \"vmotion\"]}]'`
262
+ );
263
+ console.log();
264
+ console.log("delete-vcenter-configuration", "Delete a vcenter configuration");
265
+ console.log("Parameters:");
266
+ console.log("--id [vcenter_configuration_id]");
267
+ console.log();
268
+ }
269
+
270
+ const licenseManagerVcenterModule = {
271
+ description: "License Manager Vcenter module for OpsCompass CLI",
272
+ requiresLogin: true,
273
+ listVcenterConfigurations,
274
+ getVcenterConfiguration,
275
+ createVcenterConfiguration,
276
+ updateVcenterConfiguration,
277
+ updateVcenterConfigurations,
278
+ deleteVcenterConfiguration,
279
+ printVcenterHelp,
280
+ };
281
+ module.exports = licenseManagerVcenterModule;