mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-21 06:33:28 +00:00
Merge pull request #2265 from balena-io/balena-sdk-15.36.0
devices supported: Use new DeviceType data model as source of truth
This commit is contained in:
commit
d559b9a5a1
@ -662,10 +662,11 @@ produce JSON output instead of tabular output
|
||||
|
||||
List the supported device types (like 'raspberrypi3' or 'intel-nuc').
|
||||
|
||||
The --verbose option adds extra columns/fields to the output, including the
|
||||
"STATE" column whose values are one of 'new', 'released' or 'discontinued'.
|
||||
However, 'discontinued' device types are only listed if the '--discontinued'
|
||||
option is used.
|
||||
The --verbose option may add extra columns/fields to the output. Currently
|
||||
this includes the "STATE" column which is DEPRECATED and whose values are one
|
||||
of 'new', 'released' or 'discontinued'. However, 'discontinued' device types
|
||||
are only listed if the '--discontinued' option is also used, and this option
|
||||
is also DEPRECATED.
|
||||
|
||||
The --json option is recommended when scripting the output of this command,
|
||||
because the JSON format is less likely to change and it better represents data
|
||||
@ -683,7 +684,7 @@ Examples:
|
||||
|
||||
#### --discontinued
|
||||
|
||||
include "discontinued" device types
|
||||
include "discontinued" device types (DEPRECATED)
|
||||
|
||||
#### -j, --json
|
||||
|
||||
@ -691,7 +692,7 @@ produce JSON output instead of tabular output
|
||||
|
||||
#### -v, --verbose
|
||||
|
||||
add extra columns in the tabular output (ALIASES, ARCH, STATE)
|
||||
add extra columns in the tabular output (DEPRECATED)
|
||||
|
||||
## device <uuid>
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2016-2019 Balena Ltd.
|
||||
* Copyright 2016-2021 Balena Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -15,13 +15,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { flags } from '@oclif/command';
|
||||
import type * as SDK from 'balena-sdk';
|
||||
import * as _ from 'lodash';
|
||||
import Command from '../../command';
|
||||
|
||||
import * as cf from '../../utils/common-flags';
|
||||
import { getBalenaSdk, getVisuals, stripIndent } from '../../utils/lazy';
|
||||
import { CommandHelp } from '../../utils/oclif-utils';
|
||||
import { isV13 } from '../../utils/version';
|
||||
|
||||
interface FlagsDef {
|
||||
discontinued: boolean;
|
||||
@ -30,17 +30,24 @@ interface FlagsDef {
|
||||
verbose?: boolean;
|
||||
}
|
||||
|
||||
const deprecatedInfo = isV13()
|
||||
? ''
|
||||
: `
|
||||
The --verbose option may add extra columns/fields to the output. Currently
|
||||
this includes the "STATE" column which is DEPRECATED and whose values are one
|
||||
of 'new', 'released' or 'discontinued'. However, 'discontinued' device types
|
||||
are only listed if the '--discontinued' option is also used, and this option
|
||||
is also DEPRECATED.
|
||||
`
|
||||
.split('\n')
|
||||
.join(`\n\t\t`);
|
||||
|
||||
export default class DevicesSupportedCmd extends Command {
|
||||
public static description = stripIndent`
|
||||
List the supported device types (like 'raspberrypi3' or 'intel-nuc').
|
||||
|
||||
List the supported device types (like 'raspberrypi3' or 'intel-nuc').
|
||||
|
||||
The --verbose option adds extra columns/fields to the output, including the
|
||||
"STATE" column whose values are one of 'new', 'released' or 'discontinued'.
|
||||
However, 'discontinued' device types are only listed if the '--discontinued'
|
||||
option is used.
|
||||
|
||||
${deprecatedInfo}
|
||||
The --json option is recommended when scripting the output of this command,
|
||||
because the JSON format is less likely to change and it better represents data
|
||||
types like lists and empty strings (for example, the ALIASES column contains a
|
||||
@ -60,7 +67,9 @@ export default class DevicesSupportedCmd extends Command {
|
||||
|
||||
public static flags: flags.Input<FlagsDef> = {
|
||||
discontinued: flags.boolean({
|
||||
description: 'include "discontinued" device types',
|
||||
description: isV13()
|
||||
? 'No effect (DEPRECATED)'
|
||||
: 'include "discontinued" device types (DEPRECATED)',
|
||||
}),
|
||||
help: cf.help,
|
||||
json: flags.boolean({
|
||||
@ -69,45 +78,71 @@ export default class DevicesSupportedCmd extends Command {
|
||||
}),
|
||||
verbose: flags.boolean({
|
||||
char: 'v',
|
||||
description:
|
||||
'add extra columns in the tabular output (ALIASES, ARCH, STATE)',
|
||||
description: isV13()
|
||||
? 'No effect (DEPRECATED)'
|
||||
: 'add extra columns in the tabular output (DEPRECATED)',
|
||||
}),
|
||||
};
|
||||
|
||||
public async run() {
|
||||
const { flags: options } = this.parse<FlagsDef, {}>(DevicesSupportedCmd);
|
||||
const dts = await getBalenaSdk().models.config.getDeviceTypes();
|
||||
let deviceTypes: Array<Partial<SDK.DeviceTypeJson.DeviceType>> = dts.map(
|
||||
(d) => {
|
||||
if (d.aliases && d.aliases.length) {
|
||||
// remove aliases that are equal to the slug
|
||||
d.aliases = d.aliases.filter((alias: string) => alias !== d.slug);
|
||||
if (!options.json) {
|
||||
// stringify the aliases array with commas and spaces
|
||||
d.aliases = [d.aliases.join(', ')];
|
||||
}
|
||||
} else {
|
||||
// ensure it is always an array (for the benefit of JSON output)
|
||||
d.aliases = [];
|
||||
}
|
||||
return d;
|
||||
},
|
||||
);
|
||||
if (!options.discontinued) {
|
||||
deviceTypes = deviceTypes.filter((dt) => dt.state !== 'DISCONTINUED');
|
||||
}
|
||||
const fields = options.verbose
|
||||
? ['slug', 'aliases', 'arch', 'state', 'name']
|
||||
: ['slug', 'aliases', 'arch', 'name'];
|
||||
deviceTypes = _.sortBy(
|
||||
deviceTypes.map((d) => {
|
||||
const picked = _.pick(d, fields);
|
||||
// 'BETA' renamed to 'NEW'
|
||||
picked.state = picked.state === 'BETA' ? 'NEW' : picked.state;
|
||||
return picked;
|
||||
const [dts, configDTs] = await Promise.all([
|
||||
getBalenaSdk().models.deviceType.getAllSupported({
|
||||
$expand: { is_of__cpu_architecture: { $select: 'slug' } },
|
||||
$select: ['slug', 'name'],
|
||||
}),
|
||||
fields,
|
||||
);
|
||||
getBalenaSdk().models.config.getDeviceTypes(),
|
||||
]);
|
||||
const dtsBySlug = _.keyBy(dts, (dt) => dt.slug);
|
||||
const configDTsBySlug = _.keyBy(configDTs, (dt) => dt.slug);
|
||||
const discontinuedDTs = isV13()
|
||||
? []
|
||||
: configDTs.filter((dt) => dt.state === 'DISCONTINUED');
|
||||
const discontinuedDTsBySlug = _.keyBy(discontinuedDTs, (dt) => dt.slug);
|
||||
// set of slugs from models.deviceType.getAllSupported() plus slugs of
|
||||
// discontinued device types as per models.config.getDeviceTypes()
|
||||
const slugsOfInterest = new Set([
|
||||
...Object.keys(dtsBySlug),
|
||||
...Object.keys(discontinuedDTsBySlug),
|
||||
]);
|
||||
interface DT {
|
||||
slug: string;
|
||||
aliases: string[];
|
||||
arch: string;
|
||||
state?: string; // to be removed in CLI v13
|
||||
name: string;
|
||||
}
|
||||
let deviceTypes: DT[] = [];
|
||||
for (const slug of slugsOfInterest) {
|
||||
const configDT: Partial<typeof configDTs[0]> =
|
||||
configDTsBySlug[slug] || {};
|
||||
if (configDT.state === 'DISCONTINUED' && !options.discontinued) {
|
||||
continue;
|
||||
}
|
||||
const dt: Partial<typeof dts[0]> = dtsBySlug[slug] || {};
|
||||
const aliases = (configDT.aliases || []).filter(
|
||||
(alias) => alias !== slug,
|
||||
);
|
||||
deviceTypes.push({
|
||||
slug,
|
||||
aliases: options.json ? aliases : [aliases.join(', ')],
|
||||
arch:
|
||||
(dt.is_of__cpu_architecture as any)?.[0]?.slug ||
|
||||
configDT.arch ||
|
||||
'n/a',
|
||||
// 'BETA' renamed to 'NEW'
|
||||
// https://www.flowdock.com/app/rulemotion/i-cli/threads/1svvyaf8FAZeSdG4dPJc4kHOvJU
|
||||
state: isV13()
|
||||
? undefined
|
||||
: (configDT.state || 'NEW').replace('BETA', 'NEW'),
|
||||
name: dt.name || configDT.name || 'N/A',
|
||||
});
|
||||
}
|
||||
const fields =
|
||||
options.verbose && !isV13()
|
||||
? ['slug', 'aliases', 'arch', 'state', 'name']
|
||||
: ['slug', 'aliases', 'arch', 'name'];
|
||||
deviceTypes = _.sortBy(deviceTypes, fields);
|
||||
if (options.json) {
|
||||
console.log(JSON.stringify(deviceTypes, null, 4));
|
||||
} else {
|
||||
|
51
npm-shrinkwrap.json
generated
51
npm-shrinkwrap.json
generated
@ -2708,9 +2708,9 @@
|
||||
"integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q=="
|
||||
},
|
||||
"abortcontroller-polyfill": {
|
||||
"version": "1.7.1",
|
||||
"resolved": "https://registry.npmjs.org/abortcontroller-polyfill/-/abortcontroller-polyfill-1.7.1.tgz",
|
||||
"integrity": "sha512-yml9NiDEH4M4p0G4AcPkg8AAa4mF3nfYF28VQxaokpO67j9H7gWgmsVWJ/f1Rn+PzsnDYvzJzWIQzCqDKRvWlA=="
|
||||
"version": "1.7.3",
|
||||
"resolved": "https://registry.npmjs.org/abortcontroller-polyfill/-/abortcontroller-polyfill-1.7.3.tgz",
|
||||
"integrity": "sha512-zetDJxd89y3X99Kvo4qFx8GKlt6GsvN3UcRZHwU6iFA/0KiOmhkTVhe8oRoTBiTVPZu09x3vCra47+w8Yz1+2Q=="
|
||||
},
|
||||
"accepts": {
|
||||
"version": "1.3.7",
|
||||
@ -3475,14 +3475,21 @@
|
||||
}
|
||||
},
|
||||
"balena-register-device": {
|
||||
"version": "7.1.0",
|
||||
"resolved": "https://registry.npmjs.org/balena-register-device/-/balena-register-device-7.1.0.tgz",
|
||||
"integrity": "sha512-DaAK+EtHsSyHmcgGk7LY99j5qTTBKj8xbPwukeHwheGkyVcV1g2lix9Nj6eVkmZ+JYM0pHC4TKFZOiGq6btm+Q==",
|
||||
"version": "7.2.0",
|
||||
"resolved": "https://registry.npmjs.org/balena-register-device/-/balena-register-device-7.2.0.tgz",
|
||||
"integrity": "sha512-Uo8iceob2Zg8gBedZKzSZWTyr5XoDkUN+2oSyyuKVuhZYcZS623Lsj/+I8QdJQutlObgVHjD2k3mM1Pa6loFxA==",
|
||||
"requires": {
|
||||
"@types/uuid": "^8.0.0",
|
||||
"tslib": "^2.0.0",
|
||||
"typed-error": "^3.2.0",
|
||||
"uuid": "^8.2.0"
|
||||
"@types/uuid": "^8.3.0",
|
||||
"tslib": "^2.2.0",
|
||||
"typed-error": "^3.2.1",
|
||||
"uuid": "^8.3.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"tslib": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.2.0.tgz",
|
||||
"integrity": "sha512-gS9GVHRU+RGn5KQM2rllAlR3dU6m7AcpJKdtH8gFvQiC4Otgk98XnmMU+nZenHt/+VhnBPWwgrJsyrdcw6i23w=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"balena-release": {
|
||||
@ -3521,9 +3528,9 @@
|
||||
}
|
||||
},
|
||||
"balena-sdk": {
|
||||
"version": "15.31.0",
|
||||
"resolved": "https://registry.npmjs.org/balena-sdk/-/balena-sdk-15.31.0.tgz",
|
||||
"integrity": "sha512-yvd6RrvRtmLXP4pLM1KQfhHQs9f+ktBSFNUZBUf/+dV31M/eQNjQuiLbaG698aSRpuwR1mHG/T9ITrIjGT0pUg==",
|
||||
"version": "15.36.0",
|
||||
"resolved": "https://registry.npmjs.org/balena-sdk/-/balena-sdk-15.36.0.tgz",
|
||||
"integrity": "sha512-h55dSJpZ8XCJAwvbfinCuGPQXfSIBg/ftkpd6ObV+WQ/iN7DIpBKG0QVPdWoK91Ws0Ie/GzmW4IFvgtS/Yf3hQ==",
|
||||
"requires": {
|
||||
"@balena/es-version": "^1.0.0",
|
||||
"@types/lodash": "^4.14.168",
|
||||
@ -3547,14 +3554,14 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/lodash": {
|
||||
"version": "4.14.168",
|
||||
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.168.tgz",
|
||||
"integrity": "sha512-oVfRvqHV/V6D1yifJbVRU3TMp8OT6o6BG+U9MkwuJ3U8/CsDHvalRpsxBqivn71ztOFZBTfJMvETbqHiaNSj7Q=="
|
||||
"version": "4.14.169",
|
||||
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.169.tgz",
|
||||
"integrity": "sha512-DvmZHoHTFJ8zhVYwCLWbQ7uAbYQEk52Ev2/ZiQ7Y7gQGeV9pjBqjnQpECMHfKS1rCYAhMI7LHVxwyZLZinJgdw=="
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "10.17.56",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.56.tgz",
|
||||
"integrity": "sha512-LuAa6t1t0Bfw4CuSR0UITsm1hP17YL+u82kfHGrHUWdhlBtH7sa7jGY5z7glGaIj/WDYDkRtgGd+KCjCzxBW1w=="
|
||||
"version": "10.17.60",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.60.tgz",
|
||||
"integrity": "sha512-F0KIgDJfy2nA3zMLmWGKxcH2ZVEtCZXHHdOQs2gSaQ27+lNeEfGxzkIw90aXswATX7AZ33tahPbzy6KAfUreVw=="
|
||||
},
|
||||
"lodash": {
|
||||
"version": "4.17.21",
|
||||
@ -15543,9 +15550,9 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"object-inspect": {
|
||||
"version": "1.9.0",
|
||||
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.9.0.tgz",
|
||||
"integrity": "sha512-i3Bp9iTqwhaLZBxGkRfo5ZbE07BQRT7MGu8+nNgwW9ItGp1TzCTw2DLEoWwjClxBjOFI/hWljTAmYGCEwmtnOw=="
|
||||
"version": "1.10.3",
|
||||
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.10.3.tgz",
|
||||
"integrity": "sha512-e5mCJlSH7poANfC8z8S9s9S2IN5/4Zb3aZ33f5s8YqoazCFzNLloLU8r5VCG+G7WoqLvAAZoVMcy3tp/3X0Plw=="
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -207,7 +207,7 @@
|
||||
"balena-image-manager": "^7.0.3",
|
||||
"balena-preload": "^10.4.7",
|
||||
"balena-release": "^3.0.0",
|
||||
"balena-sdk": "^15.31.0",
|
||||
"balena-sdk": "^15.36.0",
|
||||
"balena-semver": "^2.3.0",
|
||||
"balena-settings-client": "^4.0.6",
|
||||
"balena-settings-storage": "^7.0.0",
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019-2020 Balena Ltd.
|
||||
* Copyright 2019-2021 Balena Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -311,7 +311,7 @@ export class BalenaAPIMock extends NockMock {
|
||||
});
|
||||
}
|
||||
|
||||
public expectGetDeviceTypes(opts: ScopeOpts = {}) {
|
||||
public expectGetConfigDeviceTypes(opts: ScopeOpts = {}) {
|
||||
this.optGet('/device-types/v1', opts).replyWithFile(
|
||||
200,
|
||||
path.join(apiResponsePath, 'device-types-GET-v1.json'),
|
||||
@ -319,6 +319,14 @@ export class BalenaAPIMock extends NockMock {
|
||||
);
|
||||
}
|
||||
|
||||
public expectGetDeviceTypes(opts: ScopeOpts = {}) {
|
||||
this.optGet(/^\/v\d+\/device_type($|\?)/, opts).replyWithFile(
|
||||
200,
|
||||
path.join(apiResponsePath, 'device-type-GET-v6.json'),
|
||||
jHeader,
|
||||
);
|
||||
}
|
||||
|
||||
public expectGetConfigVars(opts: ScopeOpts = {}) {
|
||||
this.optGet('/config/vars', opts).reply(200, {
|
||||
reservedNames: [],
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2020 Balena Ltd.
|
||||
* Copyright 2020-2021 Balena Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -76,7 +76,7 @@ describe('balena deploy', function () {
|
||||
docker = new DockerMock();
|
||||
api.expectGetWhoAmI({ optional: true, persist: true });
|
||||
api.expectGetMixpanel({ optional: true });
|
||||
api.expectGetDeviceTypes();
|
||||
api.expectGetConfigDeviceTypes();
|
||||
api.expectGetApplication();
|
||||
api.expectPostRelease();
|
||||
api.expectGetRelease();
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019-2020 Balena Ltd.
|
||||
* Copyright 2019-2021 Balena Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -20,6 +20,8 @@ import { expect } from 'chai';
|
||||
import { BalenaAPIMock } from '../../balena-api-mock';
|
||||
import { cleanOutput, runCommand } from '../../helpers';
|
||||
|
||||
import { isV13 } from '../../../lib/utils/version';
|
||||
|
||||
describe('balena devices supported', function () {
|
||||
let api: BalenaAPIMock;
|
||||
|
||||
@ -44,20 +46,35 @@ describe('balena devices supported', function () {
|
||||
|
||||
it('should list currently supported devices, with correct filtering', async () => {
|
||||
api.expectGetDeviceTypes();
|
||||
api.expectGetConfigDeviceTypes();
|
||||
|
||||
const { out, err } = await runCommand('devices supported');
|
||||
const { out, err } = await runCommand('devices supported -v');
|
||||
|
||||
const lines = cleanOutput(out);
|
||||
const lines = cleanOutput(out, true);
|
||||
|
||||
expect(lines[0].replace(/ +/g, ' ')).to.equal('SLUG ALIASES ARCH NAME');
|
||||
expect(lines[0]).to.equal(
|
||||
isV13() ? 'SLUG ALIASES ARCH NAME' : 'SLUG ALIASES ARCH STATE NAME',
|
||||
);
|
||||
expect(lines).to.have.lengthOf.at.least(2);
|
||||
expect(lines).to.contain(
|
||||
isV13()
|
||||
? 'intel-nuc nuc amd64 Intel NUC'
|
||||
: 'intel-nuc nuc amd64 RELEASED Intel NUC',
|
||||
);
|
||||
expect(lines).to.contain(
|
||||
isV13()
|
||||
? 'odroid-xu4 odroid-ux3, odroid-u3+ armv7hf ODROID-XU4'
|
||||
: 'odroid-xu4 odroid-ux3, odroid-u3+ armv7hf RELEASED ODROID-XU4',
|
||||
);
|
||||
|
||||
// Discontinued devices should be filtered out from results
|
||||
expect(lines.some((l) => l.includes('DISCONTINUED'))).to.be.false;
|
||||
|
||||
// Experimental devices should be listed as new
|
||||
expect(lines.some((l) => l.includes('EXPERIMENTAL'))).to.be.false;
|
||||
expect(lines.some((l) => l.includes('NEW'))).to.be.true;
|
||||
// Beta devices should be listed as new
|
||||
expect(lines.some((l) => l.includes('BETA'))).to.be.false;
|
||||
expect(lines.some((l) => l.includes('NEW'))).to.equal(
|
||||
isV13() ? false : true,
|
||||
);
|
||||
|
||||
expect(err).to.eql([]);
|
||||
});
|
||||
|
@ -1,3 +1,20 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2020-2021 Balena Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { expect } from 'chai';
|
||||
import { promises as fs } from 'fs';
|
||||
import * as process from 'process';
|
||||
@ -30,7 +47,7 @@ if (process.platform !== 'win32') {
|
||||
|
||||
it('should inject a valid config.json file', async () => {
|
||||
api.expectGetApplication();
|
||||
api.expectGetDeviceTypes();
|
||||
api.expectGetConfigDeviceTypes();
|
||||
api.expectDownloadConfig();
|
||||
api.expectApplicationProvisioning();
|
||||
|
||||
|
1634
tests/test-data/api-response/device-type-GET-v6.json
Normal file
1634
tests/test-data/api-response/device-type-GET-v6.json
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user