API sr.*() converted to ES6.
This commit is contained in:
parent
0d4b9b4bce
commit
0c3304f041
@ -1,46 +0,0 @@
|
||||
{$coroutine, $wait} = require '../fibers-utils'
|
||||
|
||||
#=====================================================================
|
||||
|
||||
exports.set = $coroutine (params) ->
|
||||
try
|
||||
SR = @getObject params.id, 'SR'
|
||||
catch
|
||||
@throw 'NO_SUCH_OBJECT'
|
||||
|
||||
xapi = @getXAPI SR
|
||||
|
||||
for param, field of {
|
||||
'name_label'
|
||||
'name_description'
|
||||
}
|
||||
continue unless param of params
|
||||
|
||||
$wait xapi.call "SR.set_#{field}", SR.ref, params[param]
|
||||
|
||||
return true
|
||||
exports.set.permission = 'admin'
|
||||
exports.set.params = {
|
||||
id: { type: 'string' }
|
||||
|
||||
name_label: { type: 'string', optional: true }
|
||||
|
||||
name_description: { type: 'string', optional: true }
|
||||
}
|
||||
|
||||
|
||||
exports.scan = $coroutine ({id}) ->
|
||||
try
|
||||
SR = @getObject id, 'SR'
|
||||
catch
|
||||
@throw 'NO_SUCH_OBJECT'
|
||||
|
||||
xapi = @getXAPI SR
|
||||
|
||||
$wait xapi.call 'SR.scan', SR.ref
|
||||
|
||||
return true
|
||||
exports.scan.permission = 'admin'
|
||||
exports.scan.params = {
|
||||
id: { type: 'string' }
|
||||
}
|
59
src/api/sr.js
Normal file
59
src/api/sr.js
Normal file
@ -0,0 +1,59 @@
|
||||
import forEach from 'lodash.foreach';
|
||||
import {$coroutine, $wait} from '../fibers-utils';
|
||||
|
||||
//====================================================================
|
||||
|
||||
let set = $coroutine(params => {
|
||||
let SR;
|
||||
try {
|
||||
SR = this.getObject(params.id, 'SR');
|
||||
} catch (error) {
|
||||
this.throw('NO_SUCH_OBJECT');
|
||||
}
|
||||
|
||||
let xapi = this.getXAPI(SR);
|
||||
|
||||
forEach(['name_label', 'name_description'], param => {
|
||||
let value = params[param];
|
||||
if (value === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
$wait(xapi.call(`SR.set_${value}`, SR.ref, params[param]));
|
||||
});
|
||||
|
||||
return true;
|
||||
});
|
||||
set.permission = 'admin';
|
||||
set.params = {
|
||||
id: { type: 'string' },
|
||||
|
||||
name_label: { type: 'string', optional: true },
|
||||
|
||||
name_description: { type: 'string', optional: true },
|
||||
};
|
||||
|
||||
export {set};
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
let scan = $coroutine(({id}) => {
|
||||
let SR;
|
||||
try {
|
||||
SR = this.getObject(id, 'SR');
|
||||
} catch (error) {
|
||||
this.throw('NO_SUCH_OBJECT');
|
||||
}
|
||||
|
||||
let xapi = this.getXAPI(SR);
|
||||
|
||||
$wait(xapi.call('SR.scan', SR.ref));
|
||||
|
||||
return true;
|
||||
});
|
||||
scan.permission = 'admin';
|
||||
scan.params = {
|
||||
id: { type: 'string' },
|
||||
};
|
||||
|
||||
export {scan};
|
Loading…
Reference in New Issue
Block a user