mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-24 07:46:39 +00:00
scan: Print production devices' info on scan
Resolves: #1713 Change-type: minor Signed-off-by: Marios Balamatsias <mbalamatsias@gmail.com>
This commit is contained in:
parent
8115d156df
commit
7d5a64f59a
@ -1524,6 +1524,11 @@ Only show system logs. This can be used in combination with --service.
|
|||||||
|
|
||||||
Scan for balenaOS devices on your local network.
|
Scan for balenaOS devices on your local network.
|
||||||
|
|
||||||
|
The output includes device information collected through balenaEngine for
|
||||||
|
devices running a development image of balenaOS. Devices running a production
|
||||||
|
image do not expose balenaEngine (on TCP port 2375), which is why less
|
||||||
|
information is printed about them.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
$ balena scan
|
$ balena scan
|
||||||
|
@ -33,6 +33,11 @@ export default class ScanCmd extends Command {
|
|||||||
Scan for balenaOS devices on your local network.
|
Scan for balenaOS devices on your local network.
|
||||||
|
|
||||||
Scan for balenaOS devices on your local network.
|
Scan for balenaOS devices on your local network.
|
||||||
|
|
||||||
|
The output includes device information collected through balenaEngine for
|
||||||
|
devices running a development image of balenaOS. Devices running a production
|
||||||
|
image do not expose balenaEngine (on TCP port 2375), which is why less
|
||||||
|
information is printed about them.
|
||||||
`;
|
`;
|
||||||
|
|
||||||
public static examples = [
|
public static examples = [
|
||||||
@ -99,13 +104,33 @@ export default class ScanCmd extends Command {
|
|||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
const activeLocalDevices: LocalBalenaOsDevice[] = localDevices.filter(
|
|
||||||
|
const developmentDevices: LocalBalenaOsDevice[] = localDevices.filter(
|
||||||
(_localDevice, index) => engineReachableDevices[index],
|
(_localDevice, index) => engineReachableDevices[index],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const productionDevices = _.differenceWith(
|
||||||
|
localDevices,
|
||||||
|
developmentDevices,
|
||||||
|
_.isEqual,
|
||||||
|
);
|
||||||
|
|
||||||
|
const productionDevicesInfo = _.map(
|
||||||
|
productionDevices,
|
||||||
|
(device: LocalBalenaOsDevice) => {
|
||||||
|
return {
|
||||||
|
host: device.host,
|
||||||
|
address: device.address,
|
||||||
|
osVariant: 'production',
|
||||||
|
dockerInfo: undefined,
|
||||||
|
dockerVersion: undefined,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
// Query devices for info
|
// Query devices for info
|
||||||
const devicesInfo = await Promise.all(
|
const devicesInfo = await Promise.all(
|
||||||
activeLocalDevices.map(async ({ host, address }) => {
|
developmentDevices.map(async ({ host, address }) => {
|
||||||
const docker = dockerUtils.createClient({
|
const docker = dockerUtils.createClient({
|
||||||
host: address,
|
host: address,
|
||||||
port: dockerPort,
|
port: dockerPort,
|
||||||
@ -118,6 +143,7 @@ export default class ScanCmd extends Command {
|
|||||||
return {
|
return {
|
||||||
host,
|
host,
|
||||||
address,
|
address,
|
||||||
|
osVariant: 'development',
|
||||||
dockerInfo,
|
dockerInfo,
|
||||||
dockerVersion,
|
dockerVersion,
|
||||||
};
|
};
|
||||||
@ -138,8 +164,10 @@ export default class ScanCmd extends Command {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const cmdOutput = productionDevicesInfo.concat(devicesInfo);
|
||||||
|
|
||||||
// Output results
|
// Output results
|
||||||
if (!options.json && devicesInfo.length === 0) {
|
if (!options.json && cmdOutput.length === 0) {
|
||||||
console.error(
|
console.error(
|
||||||
process.platform === 'win32'
|
process.platform === 'win32'
|
||||||
? ScanCmd.noDevicesFoundMessage + ScanCmd.windowsTipMessage
|
? ScanCmd.noDevicesFoundMessage + ScanCmd.windowsTipMessage
|
||||||
@ -149,8 +177,8 @@ export default class ScanCmd extends Command {
|
|||||||
}
|
}
|
||||||
console.log(
|
console.log(
|
||||||
options.json
|
options.json
|
||||||
? JSON.stringify(devicesInfo, null, 4)
|
? JSON.stringify(cmdOutput, null, 4)
|
||||||
: prettyjson.render(devicesInfo, { noColor: true }),
|
: prettyjson.render(cmdOutput, { noColor: true }),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
typings/balena-sync/index.d.ts
vendored
1
typings/balena-sync/index.d.ts
vendored
@ -23,6 +23,7 @@ declare module 'balena-sync' {
|
|||||||
export interface LocalBalenaOsDevice {
|
export interface LocalBalenaOsDevice {
|
||||||
address: string;
|
address: string;
|
||||||
host: string;
|
host: string;
|
||||||
|
osVariant: string;
|
||||||
port: number;
|
port: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user