add methods for SR: createIso, destroy and forget

This commit is contained in:
Olivier Lambert 2015-02-25 18:10:10 +01:00
parent fd3d60ed7d
commit 31a7e48768

View File

@ -57,3 +57,100 @@ scan.params = {
};
export {scan};
//--------------------------------------------------------------------
// TODO: find a way to call this "delete" and not destroy
let destroy = $coroutine(function ({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.destroy', SR.ref));
return true;
});
destroy.permission = 'admin';
destroy.params = {
id: { type: 'string' },
};
export {destroy};
//--------------------------------------------------------------------
let forget = $coroutine(function ({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.forget', SR.ref));
return true;
});
forget.permission = 'admin';
forget.params = {
id: { type: 'string' },
};
export {forget};
//--------------------------------------------------------------------
let createIso = $coroutine(function ({
host,
nameLabel,
nameDescription,
path
}) {
try {
host = this.getObject(host, 'host');
} catch (error) {
this.throw('NO_SUCH_OBJECT');
}
let xapi = this.getXAPI(host);
// FIXME: won't work for IPv6
// Detect if NFS or local path for ISO files
let deviceConfig = {location: path};
if (path.indexOf(':') === -1) { // not NFS share
// TODO: legacy will be removed in XAPI soon by FileSR
deviceConfig.legacy_mode = 'true';
}
$wait(xapi.call(
'SR.create',
host.id,
deviceConfig,
'0', // SR size 0 because ISO
nameLabel,
nameDescription,
'iso', // SR type ISO
'iso', // SR content type ISO
true,
{}
));
return true;
});
createIso.permission = 'admin';
createIso.params = {
host: { type: 'string' },
nameLabel: { type: 'string' },
nameDescription: { type: 'string' },
path: { type: 'string' }
};
export {createIso};