forked from redhat-developer/vscode-openshift-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstorage.ts
More file actions
59 lines (52 loc) · 3.41 KB
/
storage.ts
File metadata and controls
59 lines (52 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*-----------------------------------------------------------------------------------------------
* Copyright (c) Red Hat, Inc. All rights reserved.
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/
import { window } from 'vscode';
import { isEmpty } from "validator";
import { OpenShiftItem } from "./openshiftItem";
import { OpenShiftObject, ContextType } from "../odo";
import { Progress } from "../util/progress";
export class Storage extends OpenShiftItem {
static async create(context: OpenShiftObject): Promise<string> {
const component = await Storage.getOpenShiftCmdData(context,
"In which Project you want to create a Storage",
"In which Application you want to create a Storage",
"In which Component you want to create a Storage",
(value: OpenShiftObject) => value.contextValue === ContextType.COMPONENT_PUSHED || value.contextValue === ContextType.COMPONENT);
if (!component) return null;
const storageList: Array<OpenShiftObject> = await OpenShiftItem.odo.getStorageNames(component);
const storageName = await Storage.getName('Storage name', storageList);
if (!storageName) return null;
const mountPath = await window.showInputBox({prompt: "Specify the mount path",
ignoreFocusOut: true,
validateInput: (value: string) => {
if (isEmpty(value.trim())) {
return 'Invalid mount path';
}
}});
if (!mountPath) return null;
const storageSize = await window.showQuickPick(['1Gi', '1.5Gi', '2Gi'], {placeHolder: 'Select a Storage size', ignoreFocusOut: true});
if (!storageSize) return null;
return Progress.execFunctionWithProgress(`Creating the Storage '${component.getName()}'`, () => Storage.odo.createStorage(component, storageName, mountPath, storageSize))
.then(() => `Storage '${storageName}' successfully created for Component '${component.getName()}'`)
.catch((err) => Promise.reject(Error(`New Storage command failed with error: '${err}'!`)));
}
static async del(treeItem: OpenShiftObject): Promise<string> {
let storage = treeItem;
const component = await Storage.getOpenShiftCmdData(storage,
"From which Project you want to delete Storage",
"From which Application you want to delete Storage",
"From which Component you want to delete Storage");
if (!storage && component) storage = await window.showQuickPick(Storage.getStorageNames(component), {placeHolder: "Select Storage to delete", ignoreFocusOut: true});
if (storage) {
const value = await window.showWarningMessage(`Do you want to delete Storage '${storage.getName()}' from Component '${storage.getParent().getName()}'?`, 'Yes', 'Cancel');
if (value === 'Yes') {
return Progress.execFunctionWithProgress(`Deleting Storage ${storage.getName()} from Component ${component.getName()}`, () => Storage.odo.deleteStorage(storage))
.then(() => `Storage '${storage.getName()}' from Component '${storage.getParent().getName()}' successfully deleted`)
.catch((err) => Promise.reject(Error(`Failed to delete Storage with error '${err}'`)));
}
}
return null;
}
}