Skip to content

Commit 8aeb0b4

Browse files
authored
Enhancement.icall tmsh (#200)
* Added iCall script to IRULES/IAPPS Tree treeViewsProviders * Fixed an issue with big-ip obj wrapper * Added iCall and TMSH scripts to the editor tree. - modified: package.json - modified: src/tclCore.ts - modified: src/treeViewsProviders/tclTreeProvider.ts
1 parent 187622c commit 8aeb0b4

File tree

3 files changed

+141
-7
lines changed

3 files changed

+141
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@
181181
},
182182
{
183183
"id": "as3Tasks",
184-
"name": "iRules/iApps",
184+
"name": "Tcl Objects",
185185
"when": "f5.tcl"
186186
},
187187
{

src/tclCore.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,24 @@ export default function tclCore(context: ExtensionContext) {
5757
return tclTreeProvider.deleteRule(rule);
5858
}));
5959

60+
// --- ICALL Script COMMANDS ---
61+
context.subscriptions.push(commands.registerCommand('f5-tcl.getIcallscript', async (icallscript) => {
62+
return tclTreeProvider.displayIcallscript(icallscript);
63+
}));
64+
65+
context.subscriptions.push(commands.registerCommand('f5-tcl.deleteIcallscript', async (icallscript) => {
66+
return tclTreeProvider.deleteIcallscript(icallscript);
67+
}));
6068

6169

70+
// --- TMSH Script COMMANDS ---
71+
context.subscriptions.push(commands.registerCommand('f5-tcl.getTMSHscript', async (tmshscript) => {
72+
return tclTreeProvider.displayTMSHscript(tmshscript);
73+
}));
74+
75+
context.subscriptions.push(commands.registerCommand('f5-tcl.deleteTMSHscript', async (tmshscript) => {
76+
return tclTreeProvider.deleteTMSHscript(tmshscript);
77+
}));
6278

6379

6480
// --- IAPP COMMANDS ---

src/treeViewsProviders/tclTreeProvider.ts

Lines changed: 124 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export class TclTreeProvider implements TreeDataProvider<TCLitem> {
3434
readonly onDidChangeTreeData: Event<TCLitem | undefined> = this._onDidChangeTreeData.event;
3535

3636
private _iRules: string[] = [];
37+
private _iCallScripts: string[] = [];
38+
private _TMSHScripts: string[] = [];
3739
private _apps: string[] = [];
3840
private _iAppTemplates: string[] = [];
3941

@@ -69,28 +71,48 @@ export class TclTreeProvider implements TreeDataProvider<TCLitem> {
6971
{ command: 'f5-tcl.getRule', title: '', arguments: [el] });
7072
});
7173

72-
} else if (element.label === 'Deployed-Apps'){
74+
} else if (element.label === 'iCall Scripts'){
75+
treeItems = this._iCallScripts.map( (el: any) => {
76+
const content = `sys icall script ${el.fullPath} {\r\n` + `definition {\r\n` + el.definition + '\r\n}\r\n}';
77+
const toolTip = new MarkdownString()
78+
.appendCodeblock(content, 'irule-lang');
79+
return new TCLitem(el.fullPath, '', toolTip, 'iCallScript', TreeItemCollapsibleState.None,
80+
{ command: 'f5-tcl.getIcallscript', title: '', arguments: [el] });
81+
});
82+
} else if (element.label === 'TMSH Scripts'){
83+
treeItems = this._TMSHScripts.map( (el: any) => {
84+
const content = `cli script ${el.fullPath} {\r\n` + el.apiAnonymous + '\r\n}';
85+
const toolTip = new MarkdownString()
86+
.appendCodeblock(content, 'irule-lang');
87+
return new TCLitem(el.fullPath, '', toolTip, 'tmshScript', TreeItemCollapsibleState.None,
88+
{ command: 'f5-tcl.getTMSHscript', title: '', arguments: [el] });
89+
});
90+
} else if (element.label === 'iApps (Deployed)'){
7391
// todo: get iapps stuff
7492
treeItems = this._apps.map( (el: any) => {
7593
return new TCLitem(el.fullPath, '', '', 'iApp', TreeItemCollapsibleState.None,
7694
{ command: 'f5-tcl.getApp', title: '', arguments: [el] });
7795
});
7896

79-
} else if (element.label === 'iApp-Templates'){
97+
} else if (element.label === 'iApps (Templates)'){
8098
// todo: get iapp templates stuff
8199
treeItems = this._iAppTemplates.map( (el: any) => {
82100
return new TCLitem(el.fullPath, '', '', 'iAppTemplate', TreeItemCollapsibleState.None,
83101
{ command: 'f5-tcl.getTMPL', title: '', arguments: [el] });
84102
});
85-
}
103+
}
86104

87105
} else {
88106

89107
await this.getIrules(); // refresh tenant information
108+
await this.getIcallscripts(); // refresh tenant information
109+
await this.getTMSHscripts(); // refresh tenant information
90110
await this.getApps(); // refresh tasks information
91111
await this.getTemplates(); // refresh tasks information
92112

93113
const ruleCount = this._iRules.length !== 0 ? this._iRules.length.toString() : '';
114+
const icallscriptsCount = this._iCallScripts.length !== 0 ? this._iCallScripts.length.toString() : '';
115+
const TMSHscriptsCount = this._TMSHScripts.length !== 0 ? this._TMSHScripts.length.toString() : '';
94116
const appCount = this._apps.length !== 0 ? this._apps.length.toString() : '';
95117
const tempCount = this._iAppTemplates.length !== 0 ? this._iAppTemplates.length.toString() : '';
96118

@@ -99,11 +121,19 @@ export class TclTreeProvider implements TreeDataProvider<TCLitem> {
99121
{ command: '', title: '', arguments: [''] })
100122
);
101123
treeItems.push(
102-
new TCLitem('Deployed-Apps', appCount, '', '', TreeItemCollapsibleState.Collapsed,
124+
new TCLitem('iCall Scripts', icallscriptsCount, '', '', TreeItemCollapsibleState.Collapsed,
125+
{ command: '', title: '', arguments: [''] })
126+
);
127+
treeItems.push(
128+
new TCLitem('TMSH Scripts', TMSHscriptsCount, '', '', TreeItemCollapsibleState.Collapsed,
129+
{ command: '', title: '', arguments: [''] })
130+
);
131+
treeItems.push(
132+
new TCLitem('iApps (Deployed)', appCount, '', '', TreeItemCollapsibleState.Collapsed,
103133
{ command: '', title: '', arguments: [''] })
104134
);
105135
treeItems.push(
106-
new TCLitem('iApp-Templates', tempCount, '', '', TreeItemCollapsibleState.Collapsed,
136+
new TCLitem('iApps (Templates)', tempCount, '', '', TreeItemCollapsibleState.Collapsed,
107137
{ command: '', title: '', arguments: [''] })
108138
);
109139
}
@@ -123,6 +153,24 @@ export class TclTreeProvider implements TreeDataProvider<TCLitem> {
123153
.then( resp => this._iRules = resp.data.items );
124154
}
125155

156+
/**
157+
* Get all iCall scripts to hold in "this" view class
158+
*/
159+
private async getIcallscripts() {
160+
this._iCallScripts = []
161+
await ext.f5Client?.https(`/mgmt/tm/sys/icall/script`)
162+
.then( resp => this._iCallScripts = resp.data.items );
163+
}
164+
165+
/**
166+
* Get all TMSH scripts to hold in "this" view class
167+
*/
168+
private async getTMSHscripts() {
169+
this._TMSHScripts = []
170+
await ext.f5Client?.https(`/mgmt/tm/cli/script`)
171+
.then( resp => this._TMSHScripts = resp.data.items );
172+
}
173+
126174
/**
127175
* Get all deployed iApp-Apps to hold in "this" view class
128176
*/
@@ -193,6 +241,76 @@ export class TclTreeProvider implements TreeDataProvider<TCLitem> {
193241
});
194242
}
195243

244+
245+
/**
246+
* crafts iCall tcl object and displays in editor with icall language
247+
* @param item iCule item passed from view click
248+
*/
249+
async displayIcallscript(item: any) {
250+
251+
// make it look like a tcl irule object so it can be merged back with changes
252+
const content = `sys icall script ${item.fullPath} {\r\n` + `definition {\r\n` + item.definition + '\r\n}\r\n}';
253+
254+
// open editor and feed it the content
255+
const doc = await workspace.openTextDocument({ content: content, language: 'irule-lang' });
256+
// make the editor appear
257+
await window.showTextDocument( doc, { preview: false });
258+
return doc; // return something for automated testing
259+
}
260+
261+
async deleteIcallscript(item: any) {
262+
logger.debug('deleteIcallscript: ', item);
263+
264+
const name = this.name2uri(item.label);
265+
266+
// const resp: any = await ext.mgmtClient?.makeRequest(`/mgmt/tm/sys/icall/script/${name}`, {
267+
// method: 'DELETE'
268+
// });
269+
270+
const resp = await ext.f5Client?.https(`/mgmt/tm/sys/icall/script/${name}`, {
271+
method: 'DELETE'
272+
})
273+
.then (resp => {
274+
setTimeout( () => { this.refresh();}, 500); // refresh after update
275+
return `${resp.status}-${resp.statusText}`;
276+
});
277+
}
278+
279+
/**
280+
* crafts tmsh script tcl object and displays in editor with tmsh language
281+
* @param item tmsh script item passed from view click
282+
*/
283+
async displayTMSHscript(item: any) {
284+
285+
// make it look like a tcl tmsh script object so it can be merged back with changes
286+
const content = `cli script ${item.fullPath} {\r\n` + item.apiAnonymous + '\r\n}';
287+
288+
// open editor and feed it the content
289+
const doc = await workspace.openTextDocument({ content: content, language: 'irule-lang' });
290+
// make the editor appear
291+
await window.showTextDocument( doc, { preview: false });
292+
return doc; // return something for automated testing
293+
}
294+
295+
async deleteTMSHscript(item: any) {
296+
logger.debug('deleteTMSHscript: ', item);
297+
298+
const name = this.name2uri(item.label);
299+
300+
// const resp: any = await ext.mgmtClient?.makeRequest(`/mgmt/tm/cli/script/${name}`, {
301+
// method: 'DELETE'
302+
// });
303+
304+
const resp = await ext.f5Client?.https(`/mgmt/tm/cli/script/${name}`, {
305+
method: 'DELETE'
306+
})
307+
.then (resp => {
308+
setTimeout( () => { this.refresh();}, 500); // refresh after update
309+
return `${resp.status}-${resp.statusText}`;
310+
});
311+
}
312+
313+
196314
/**
197315
* display .tmpl from f5 in editor
198316
* @param item from tree view click
@@ -520,4 +638,4 @@ class TCLitem extends TreeItem {
520638
super(label, collapsibleState);
521639
}
522640
contextValue = this.context;
523-
}
641+
}

0 commit comments

Comments
 (0)