Skip to content

Commit 135ddf8

Browse files
config: action args remapping framework
This implements actions args remapping framework which allows developers to specify how to provide/show args to the user/admin or how to override based on the resource by means of (a) `value(record)` function, (b) statically defined `api` name, (c) `options` array. For example, in the config file: ``` args: ['id', 'virtualmachineid', 'mode'], mapping: { id: { api: 'listIsos' }, virtualmachineid: { value: (record, params) => { return record.id } }, mode: { options: ['http', 'nfs', 'something else'] } } ``` Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent babae99 commit 135ddf8

File tree

16 files changed

+260
-164
lines changed

16 files changed

+260
-164
lines changed

ui/src/config/section/compute.js

Lines changed: 68 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -90,47 +90,69 @@ export default {
9090
docHelp: 'adminguide/virtual_machines.html#stopping-and-starting-vms',
9191
dataView: true,
9292
groupAction: true,
93-
args: ['id', 'forced'],
93+
args: ['forced'],
9494
show: (record) => { return ['Running'].includes(record.state) }
9595
},
9696
{
9797
api: 'rebootVirtualMachine',
9898
icon: 'reload',
9999
label: 'label.action.reboot.instance',
100100
dataView: true,
101-
args: ['id'],
102101
show: (record) => { return ['Running'].includes(record.state) }
103102
},
104103
{
105104
api: 'restoreVirtualMachine',
106105
icon: 'sync',
107106
label: 'label.reinstall.vm',
108107
dataView: true,
109-
args: ['virtualmachineid', 'templateid']
108+
args: ['virtualmachineid', 'templateid'],
109+
mapping: {
110+
virtualmachineid: {
111+
value: (record) => { return record.id }
112+
}
113+
}
110114
},
111115
{
112116
api: 'createVMSnapshot',
113117
icon: 'camera',
114118
label: 'Create VM Snapshot',
115119
dataView: true,
116120
args: ['virtualmachineid', 'name', 'description', 'snapshotmemory', 'quiescevm'],
117-
show: (record) => { return ['Running'].includes(record.state) }
121+
show: (record) => { return ['Running'].includes(record.state) },
122+
mapping: {
123+
virtualmachineid: {
124+
value: (record, params) => { return record.id }
125+
}
126+
}
118127
},
119128
{
120129
api: 'attachIso',
121130
icon: 'paper-clip',
122131
label: 'label.action.attach.iso',
123132
dataView: true,
124133
args: ['id', 'virtualmachineid'],
125-
show: (record) => { return !record.isoid }
134+
show: (record) => { return !record.isoid },
135+
mapping: {
136+
id: {
137+
api: 'listIsos'
138+
},
139+
virtualmachineid: {
140+
value: (record, params) => { return record.id }
141+
}
142+
}
126143
},
127144
{
128145
api: 'detachIso',
129146
icon: 'link',
130147
label: 'label.action.detach.iso',
131148
dataView: true,
132-
args: ['id', 'virtualmachineid'],
133-
show: (record) => { return 'isoid' in record && record.isoid }
149+
args: ['virtualmachineid'],
150+
show: (record) => { return 'isoid' in record && record.isoid },
151+
mapping: {
152+
virtualmachineid: {
153+
value: (record, params) => { return record.id }
154+
}
155+
}
134156
},
135157
{
136158
api: 'migrateVirtualMachine',
@@ -158,68 +180,77 @@ export default {
158180
icon: 'swap',
159181
label: 'label.change.affinity',
160182
dataView: true,
161-
args: ['id', 'serviceofferingid'],
183+
args: ['affinitygroupids'],
162184
show: (record) => { return ['Stopped'].includes(record.state) }
163185
},
164186
{
165187
api: 'scaleVirtualMachine',
166188
icon: 'arrows-alt',
167189
label: 'Scale VM',
168190
dataView: true,
169-
args: ['id', 'serviceofferingid', 'details'],
170-
show: (record) => { return record.state === 'Stopped' || record.hypervisor === 'VMWare' }
191+
args: ['serviceofferingid', 'details'],
192+
show: (record) => { return record.hypervisor !== 'KVM' }
171193
},
172194
{
173195
api: 'changeServiceForVirtualMachine',
174196
icon: 'sliders',
175197
label: 'Change Service Offering',
176198
dataView: true,
177-
args: ['id', 'serviceofferingid'],
199+
args: ['serviceofferingid'],
178200
show: (record) => { return ['Stopped'].includes(record.state) }
179201
},
180202
{
181203
api: 'resetPasswordForVirtualMachine',
182204
icon: 'key',
183205
label: 'Reset Instance Password',
184206
dataView: true,
185-
args: ['id'],
186207
show: (record) => { return ['Stopped'].includes(record.state) }
187208
},
188209
{
189210
api: 'resetSSHKeyForVirtualMachine',
190211
icon: 'lock',
191212
label: 'Reset SSH Key',
192213
dataView: true,
193-
show: (record) => { return ['Stopped'].includes(record.state) }
214+
args: ['keypair'],
215+
show: (record) => { return ['Stopped'].includes(record.state) },
216+
mapping: {
217+
keypair: {
218+
api: 'listSSHKeyPairs'
219+
}
220+
}
194221
},
195222
{
196223
api: 'assignVirtualMachine',
197224
icon: 'user-add',
198225
label: 'Assign Instance to Another Account',
199226
dataView: true,
200-
show: (record) => { return ['Stopped'].includes(record.state) }
227+
show: (record) => { return ['Stopped'].includes(record.state) },
228+
args: ['virtualmachineid', 'account', 'domainid'],
229+
mapping: {
230+
virtualmachineid: {
231+
value: (record, params) => { return record.id }
232+
}
233+
}
201234
},
202235
{
203236
api: 'recoverVirtualMachine',
204237
icon: 'medicine-box',
205238
label: 'label.recover.vm',
206-
args: ['id'],
207239
dataView: true,
208240
show: (record) => { return ['Destroyed'].includes(record.state) }
209241
},
210242
{
211243
api: 'expungeVirtualMachine',
212244
icon: 'delete',
213245
label: 'label.action.expunge.instance',
214-
args: ['id'],
215246
dataView: true,
216247
show: (record) => { return ['Destroyed'].includes(record.state) }
217248
},
218249
{
219250
api: 'destroyVirtualMachine',
220251
icon: 'delete',
221252
label: 'label.action.destroy.instance',
222-
args: ['id', 'expunge', 'volumeids'],
253+
args: ['expunge', 'volumeids'],
223254
dataView: true,
224255
groupAction: true
225256
}
@@ -266,8 +297,7 @@ export default {
266297
api: 'deleteInstanceGroup',
267298
icon: 'delete',
268299
label: 'Delete Instance Group',
269-
dataView: true,
270-
args: ['id']
300+
dataView: true
271301
}
272302
]
273303
},
@@ -304,7 +334,18 @@ export default {
304334
icon: 'delete',
305335
label: 'Delete SSH key pair',
306336
dataView: true,
307-
args: ['name', 'account', 'domainid']
337+
args: ['name', 'account', 'domainid'],
338+
mapping: {
339+
name: {
340+
value: (record, params) => { return record.name }
341+
},
342+
account: {
343+
value: (record, params) => { return record.account }
344+
},
345+
domainid: {
346+
value: (record, params) => { return record.domainid }
347+
}
348+
}
308349
}
309350
]
310351
},
@@ -327,14 +368,18 @@ export default {
327368
icon: 'plus',
328369
label: 'New Affinity Group',
329370
listView: true,
330-
args: ['name', 'description', 'type']
371+
args: ['name', 'description', 'type'],
372+
mapping: {
373+
type: {
374+
options: ['host anti-affinity', 'host affinity']
375+
}
376+
}
331377
},
332378
{
333379
api: 'deleteAffinityGroup',
334380
icon: 'delete',
335381
label: 'Delete Affinity Group',
336-
dataView: true,
337-
args: ['id']
382+
dataView: true
338383
}
339384
]
340385
}

ui/src/config/section/iam.js

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,44 +41,40 @@ export default {
4141
icon: 'edit',
4242
label: 'label.edit',
4343
dataView: true,
44-
args: ['id', 'username', 'email', 'firstname', 'lastname', 'timezone']
44+
args: ['username', 'email', 'firstname', 'lastname', 'timezone']
4545
},
4646
{
4747
api: 'updateUser',
4848
icon: 'key',
4949
label: 'Change Password',
5050
dataView: true,
51-
args: ['id', 'currentpassword', 'password']
51+
args: ['currentpassword', 'password']
5252
},
5353
{
5454
api: 'registerUserKeys',
5555
icon: 'file-protect',
5656
label: 'Generate Keys',
57-
dataView: true,
58-
args: ['id']
57+
dataView: true
5958
},
6059
{
6160
api: 'enableUser',
6261
icon: 'play-circle',
6362
label: 'Enable User',
6463
dataView: true,
65-
show: (record) => { return record.state === 'disabled' },
66-
args: ['id']
64+
show: (record) => { return record.state === 'disabled' }
6765
},
6866
{
6967
api: 'disableUser',
7068
icon: 'pause-circle',
7169
label: 'Disable User',
7270
dataView: true,
73-
args: ['id'],
7471
show: (record) => { return record.state === 'enabled' }
7572
},
7673
{
7774
api: 'deleteUser',
7875
icon: 'delete',
7976
label: 'Delete user',
80-
dataView: true,
81-
args: ['id']
77+
dataView: true
8278
}
8379
]
8480
},
@@ -102,7 +98,7 @@ export default {
10298
icon: 'edit',
10399
label: 'label.update.account',
104100
dataView: true,
105-
args: ['id', 'newname', 'domainid', 'roleid', 'networkdomain', 'details']
101+
args: ['newname', 'domainid', 'roleid', 'networkdomain', 'details']
106102
},
107103
{
108104
api: 'updateResourceCount',
@@ -117,7 +113,6 @@ export default {
117113
label: 'Enable Account',
118114
dataView: true,
119115
show: (record) => { return record.state === 'disabled' || record.state === 'locked' },
120-
args: ['id'],
121116
params: { lock: 'false' }
122117
},
123118
{
@@ -126,7 +121,6 @@ export default {
126121
label: 'Disable Account',
127122
dataView: true,
128123
show: (record) => { return record.state === 'enabled' },
129-
args: ['id'],
130124
params: { lock: 'false' }
131125
},
132126
{
@@ -135,7 +129,7 @@ export default {
135129
label: 'Lock account',
136130
dataView: true,
137131
show: (record) => { return record.state === 'enabled' },
138-
args: ['id', 'lock']
132+
args: ['lock']
139133
},
140134
{
141135
api: 'deleteAccount',
@@ -175,22 +169,27 @@ export default {
175169
icon: 'edit',
176170
label: 'label.action.edit.domain',
177171
dataView: true,
178-
args: ['id', 'name', 'networkdomain']
172+
args: ['name', 'networkdomain']
179173
},
180174
{
181175
api: 'updateResourceCount',
182176
icon: 'sync',
183177
label: 'label.action.update.resource.count',
184178
dataView: true,
185-
args: ['domainid']
179+
args: ['domainid'],
180+
mapping: {
181+
domainid: {
182+
value: (record) => { return record.id }
183+
}
184+
}
186185
},
187186
{
188187
api: 'deleteDomain',
189188
icon: 'delete',
190189
label: 'label.delete.domain',
191190
dataView: true,
192191
show: (record) => { return record.level !== 0 },
193-
args: ['id', 'cleanup']
192+
args: ['cleanup']
194193
}
195194
]
196195
},
@@ -214,14 +213,13 @@ export default {
214213
icon: 'edit',
215214
label: 'Edit Role',
216215
dataView: true,
217-
args: ['id', 'name', 'description', 'type']
216+
args: ['name', 'description', 'type']
218217
},
219218
{
220219
api: 'deleteRole',
221220
icon: 'delete',
222221
label: 'label.delete.role',
223-
dataView: true,
224-
args: ['id']
222+
dataView: true
225223
}
226224
]
227225
}

0 commit comments

Comments
 (0)