mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-04-08 03:44:13 +00:00
Implement device register command
This command registers a new device with the passed application, returning the new device uuid.
This commit is contained in:
parent
61474fba5c
commit
7e6eb4b9e4
@ -71,6 +71,21 @@
|
||||
}
|
||||
};
|
||||
|
||||
exports.register = {
|
||||
signature: 'device register <application>',
|
||||
description: 'register a device',
|
||||
help: 'Use this command to register a device to an application.\n\nExamples:\n\n $ resin device register MyApp',
|
||||
permission: 'user',
|
||||
action: function(params, options, done) {
|
||||
return resin.models.application.get(params.application).then(function(application) {
|
||||
var uuid;
|
||||
uuid = resin.models.device.generateUUID();
|
||||
console.info("Registering to " + application.app_name + ": " + uuid);
|
||||
return resin.models.device.register(application.app_name, uuid);
|
||||
}).get('uuid').nodeify(done);
|
||||
}
|
||||
};
|
||||
|
||||
exports.remove = {
|
||||
signature: 'device rm <uuid>',
|
||||
description: 'remove a device',
|
||||
@ -155,10 +170,7 @@
|
||||
return tmp.tmpNameAsync().then(function(temporalPath) {
|
||||
return capitano.runAsync("os download --output " + temporalPath);
|
||||
}).then(function(temporalPath) {
|
||||
var uuid;
|
||||
uuid = resin.models.device.generateUUID();
|
||||
console.log("Registering to " + application.app_name + ": " + uuid);
|
||||
return resin.models.device.register(application.app_name, uuid).tap(function(device) {
|
||||
return capitano.runAsync("device register " + application.app_name).then(resin.models.device.get).tap(function(device) {
|
||||
console.log('Configuring operating system');
|
||||
return capitano.runAsync("os configure " + temporalPath + " " + uuid).then(function() {
|
||||
console.log('Initializing device');
|
||||
|
@ -72,6 +72,8 @@
|
||||
|
||||
capitano.command(actions.device.identify);
|
||||
|
||||
capitano.command(actions.device.register);
|
||||
|
||||
capitano.command(actions.notes.set);
|
||||
|
||||
capitano.command(actions.keys.list);
|
||||
|
@ -34,6 +34,7 @@ Now you have access to all the commands referenced below.
|
||||
|
||||
- [devices](#devices)
|
||||
- [device <uuid>](#device-60-uuid-62-)
|
||||
- [device register <application>](#device-register-60-application-62-)
|
||||
- [device rm <uuid>](#device-rm-60-uuid-62-)
|
||||
- [device identify <uuid>](#device-identify-60-uuid-62-)
|
||||
- [device rename <uuid> [newName]](#device-rename-60-uuid-62-newname-)
|
||||
@ -242,6 +243,14 @@ Examples:
|
||||
|
||||
$ resin device 7cf02a62a3a84440b1bb5579a3d57469148943278630b17e7fc6c4f7b465c9
|
||||
|
||||
## device register <application>
|
||||
|
||||
Use this command to register a device to an application.
|
||||
|
||||
Examples:
|
||||
|
||||
$ resin device register MyApp
|
||||
|
||||
## device rm <uuid>
|
||||
|
||||
Use this command to remove a device from resin.io.
|
||||
|
@ -89,6 +89,25 @@ exports.info =
|
||||
events.send('device.open', device: device.uuid)
|
||||
.nodeify(done)
|
||||
|
||||
exports.register =
|
||||
signature: 'device register <application>'
|
||||
description: 'register a device'
|
||||
help: '''
|
||||
Use this command to register a device to an application.
|
||||
|
||||
Examples:
|
||||
|
||||
$ resin device register MyApp
|
||||
'''
|
||||
permission: 'user'
|
||||
action: (params, options, done) ->
|
||||
resin.models.application.get(params.application).then (application) ->
|
||||
uuid = resin.models.device.generateUUID()
|
||||
console.info("Registering to #{application.app_name}: #{uuid}")
|
||||
return resin.models.device.register(application.app_name, uuid)
|
||||
.get('uuid')
|
||||
.nodeify(done)
|
||||
|
||||
exports.remove =
|
||||
signature: 'device rm <uuid>'
|
||||
description: 'remove a device'
|
||||
@ -201,41 +220,41 @@ exports.init =
|
||||
tmp.tmpNameAsync().then (temporalPath) ->
|
||||
return capitano.runAsync("os download --output #{temporalPath}")
|
||||
.then (temporalPath) ->
|
||||
uuid = resin.models.device.generateUUID()
|
||||
console.log("Registering to #{application.app_name}: #{uuid}")
|
||||
resin.models.device.register(application.app_name, uuid).tap (device) ->
|
||||
console.log('Configuring operating system')
|
||||
capitano.runAsync("os configure #{temporalPath} #{uuid}").then ->
|
||||
console.log('Initializing device')
|
||||
resin.models.device.getManifestBySlug(application.device_type).then (manifest) ->
|
||||
return form.run(manifest.initialization?.options)
|
||||
.tap (answers) ->
|
||||
if answers.drive?
|
||||
message = "This will erase #{answers.drive}. Are you sure?"
|
||||
patterns.confirm(options.yes, message)
|
||||
.return(answers.drive)
|
||||
.then(umount.umountAsync)
|
||||
.then (answers) ->
|
||||
init.initialize(temporalPath, device.uuid, answers)
|
||||
.then(stepHandler)
|
||||
.return(answers)
|
||||
.tap (answers) ->
|
||||
return if not answers.drive?
|
||||
umount.umountAsync(answers.drive).tap ->
|
||||
console.log("You can safely remove #{answers.drive} now")
|
||||
.then (device) ->
|
||||
console.log('Done')
|
||||
return device.uuid
|
||||
capitano.runAsync("device register #{application.app_name}")
|
||||
.then(resin.models.device.get)
|
||||
.tap (device) ->
|
||||
console.log('Configuring operating system')
|
||||
capitano.runAsync("os configure #{temporalPath} #{uuid}").then ->
|
||||
console.log('Initializing device')
|
||||
resin.models.device.getManifestBySlug(application.device_type).then (manifest) ->
|
||||
return form.run(manifest.initialization?.options)
|
||||
.tap (answers) ->
|
||||
if answers.drive?
|
||||
message = "This will erase #{answers.drive}. Are you sure?"
|
||||
patterns.confirm(options.yes, message)
|
||||
.return(answers.drive)
|
||||
.then(umount.umountAsync)
|
||||
.then (answers) ->
|
||||
init.initialize(temporalPath, device.uuid, answers)
|
||||
.then(stepHandler)
|
||||
.return(answers)
|
||||
.tap (answers) ->
|
||||
return if not answers.drive?
|
||||
umount.umountAsync(answers.drive).tap ->
|
||||
console.log("You can safely remove #{answers.drive} now")
|
||||
.then (device) ->
|
||||
console.log('Done')
|
||||
return device.uuid
|
||||
|
||||
.finally ->
|
||||
fs.statAsync(temporalPath).then (stat) ->
|
||||
return rimraf(temporalPath) if stat.isDirectory()
|
||||
return fs.unlinkAsync(temporalPath)
|
||||
.catch (error) ->
|
||||
.finally ->
|
||||
fs.statAsync(temporalPath).then (stat) ->
|
||||
return rimraf(temporalPath) if stat.isDirectory()
|
||||
return fs.unlinkAsync(temporalPath)
|
||||
.catch (error) ->
|
||||
|
||||
# Ignore errors if temporary file does not exist
|
||||
return if error.code is 'ENOENT'
|
||||
# Ignore errors if temporary file does not exist
|
||||
return if error.code is 'ENOENT'
|
||||
|
||||
throw error
|
||||
throw error
|
||||
|
||||
.nodeify(done)
|
||||
|
@ -48,6 +48,7 @@ capitano.command(actions.device.init)
|
||||
capitano.command(actions.device.info)
|
||||
capitano.command(actions.device.remove)
|
||||
capitano.command(actions.device.identify)
|
||||
capitano.command(actions.device.register)
|
||||
|
||||
# ---------- Notes Module ----------
|
||||
capitano.command(actions.notes.set)
|
||||
|
Loading…
x
Reference in New Issue
Block a user