2020-04-09 14:34:24 +00:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright 2016-2020 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.
|
|
|
|
*/
|
|
|
|
|
2023-09-06 14:39:31 +00:00
|
|
|
import { Args, Flags } from '@oclif/core';
|
2023-11-07 22:32:25 +00:00
|
|
|
import Command from '../../command';
|
|
|
|
import * as cf from '../../utils/common-flags';
|
|
|
|
import { getBalenaSdk, stripIndent } from '../../utils/lazy';
|
|
|
|
import { applicationIdInfo } from '../../utils/messages';
|
|
|
|
import { parseAsLocalHostnameOrIp } from '../../utils/validation';
|
2020-04-09 14:34:24 +00:00
|
|
|
|
|
|
|
export default class JoinCmd extends Command {
|
|
|
|
public static description = stripIndent`
|
2021-07-15 13:41:38 +00:00
|
|
|
Move a local device to a fleet on another balena server.
|
2020-04-09 14:34:24 +00:00
|
|
|
|
2021-07-15 13:41:38 +00:00
|
|
|
Move a local device to a fleet on another balena server, causing
|
2020-04-09 14:34:24 +00:00
|
|
|
the device to "join" the new server. The device must be running balenaOS.
|
|
|
|
|
|
|
|
For example, you could provision a device against an openBalena installation
|
|
|
|
where you perform end-to-end tests and then move it to balenaCloud when it's
|
|
|
|
ready for production.
|
|
|
|
|
2021-07-15 13:41:38 +00:00
|
|
|
To move a device between fleets on the same server, use the
|
2020-04-09 14:34:24 +00:00
|
|
|
\`balena device move\` command instead of \`balena join\`.
|
|
|
|
|
|
|
|
If you don't specify a device hostname or IP, this command will automatically
|
|
|
|
scan the local network for balenaOS devices and prompt you to select one
|
2020-12-30 15:36:46 +00:00
|
|
|
from an interactive picker. This may require administrator/root privileges.
|
2021-07-15 13:41:38 +00:00
|
|
|
Likewise, if the fleet option is not provided then a picker will be shown.
|
2020-12-10 12:30:17 +00:00
|
|
|
|
|
|
|
${applicationIdInfo.split('\n').join('\n\t\t')}
|
2020-04-09 14:34:24 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
public static examples = [
|
|
|
|
'$ balena join',
|
|
|
|
'$ balena join balena.local',
|
2021-07-15 13:41:38 +00:00
|
|
|
'$ balena join balena.local --fleet MyFleet',
|
|
|
|
'$ balena join balena.local -f myorg/myfleet',
|
2020-04-09 14:34:24 +00:00
|
|
|
'$ balena join 192.168.1.25',
|
2021-07-15 13:41:38 +00:00
|
|
|
'$ balena join 192.168.1.25 --fleet MyFleet',
|
2020-04-09 14:34:24 +00:00
|
|
|
];
|
|
|
|
|
2023-09-06 14:39:31 +00:00
|
|
|
public static args = {
|
|
|
|
deviceIpOrHostname: Args.string({
|
2020-04-09 14:34:24 +00:00
|
|
|
description: 'the IP or hostname of device',
|
2020-09-09 12:20:57 +00:00
|
|
|
parse: parseAsLocalHostnameOrIp,
|
2023-09-06 14:39:31 +00:00
|
|
|
}),
|
|
|
|
};
|
2020-04-09 14:34:24 +00:00
|
|
|
|
|
|
|
// Hardcoded to preserve camelcase
|
|
|
|
public static usage = 'join [deviceIpOrHostname]';
|
|
|
|
|
2023-09-06 14:39:31 +00:00
|
|
|
public static flags = {
|
2021-07-15 13:41:38 +00:00
|
|
|
fleet: cf.fleet,
|
2023-09-06 14:39:31 +00:00
|
|
|
pollInterval: Flags.integer({
|
2020-09-09 12:20:57 +00:00
|
|
|
description: 'the interval in minutes to check for updates',
|
|
|
|
char: 'i',
|
|
|
|
}),
|
2020-04-09 14:34:24 +00:00
|
|
|
help: cf.help,
|
|
|
|
};
|
|
|
|
|
|
|
|
public static authenticated = true;
|
|
|
|
public static primary = true;
|
|
|
|
|
|
|
|
public async run() {
|
2023-09-06 14:39:31 +00:00
|
|
|
const { args: params, flags: options } = await this.parse(JoinCmd);
|
2020-04-09 14:34:24 +00:00
|
|
|
|
2023-11-07 22:32:25 +00:00
|
|
|
const promote = await import('../../utils/promote');
|
2020-04-09 14:34:24 +00:00
|
|
|
const sdk = getBalenaSdk();
|
2020-09-09 12:20:57 +00:00
|
|
|
const logger = await Command.getLogger();
|
2020-04-09 14:34:24 +00:00
|
|
|
return promote.join(
|
|
|
|
logger,
|
|
|
|
sdk,
|
|
|
|
params.deviceIpOrHostname,
|
2021-12-19 20:50:03 +00:00
|
|
|
options.fleet,
|
2020-09-09 12:20:57 +00:00
|
|
|
options.pollInterval,
|
2020-04-09 14:34:24 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|