mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-19 05:37:51 +00:00
Add device status endpoint api function
Change-type: minor Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
parent
bc563ea963
commit
4cfaf6e666
@ -15,6 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import * as Bluebird from 'bluebird';
|
||||
import * as _ from 'lodash';
|
||||
import * as request from 'request';
|
||||
import * as Stream from 'stream';
|
||||
|
||||
@ -33,6 +34,29 @@ export interface DeviceInfo {
|
||||
arch: string;
|
||||
}
|
||||
|
||||
export interface Status {
|
||||
appState: 'applied' | 'applying';
|
||||
overallDownloadProgress: null | number;
|
||||
containers: Array<{
|
||||
status: string;
|
||||
serviceName: string;
|
||||
appId: number;
|
||||
imageId: number;
|
||||
serviceId: number;
|
||||
containerId: string;
|
||||
createdAt: string;
|
||||
}>;
|
||||
images: Array<{
|
||||
name: string;
|
||||
appId: number;
|
||||
serviceName: string;
|
||||
imageId: number;
|
||||
dockerImageId: string;
|
||||
status: string;
|
||||
downloadProgress: null | number;
|
||||
}>;
|
||||
}
|
||||
|
||||
const deviceEndpoints = {
|
||||
setTargetState: 'v2/local/target-state',
|
||||
getTargetState: 'v2/local/target-state',
|
||||
@ -40,6 +64,7 @@ const deviceEndpoints = {
|
||||
logs: 'v2/local/logs',
|
||||
ping: 'ping',
|
||||
version: 'v2/version',
|
||||
status: 'v2/state/status',
|
||||
};
|
||||
|
||||
export class DeviceAPI {
|
||||
@ -126,6 +151,23 @@ export class DeviceAPI {
|
||||
});
|
||||
}
|
||||
|
||||
public getStatus(): Promise<Status> {
|
||||
const url = this.getUrlForAction('status');
|
||||
|
||||
return DeviceAPI.promisifiedRequest(request.get, {
|
||||
url,
|
||||
json: true,
|
||||
}).then(body => {
|
||||
if (body.status !== 'success') {
|
||||
throw new ApiErrors.DeviceAPIError(
|
||||
'Non-successful response from supervisor status endpoint',
|
||||
);
|
||||
}
|
||||
|
||||
return _.omit(body, 'status') as Status;
|
||||
});
|
||||
}
|
||||
|
||||
public getLogStream(): Bluebird<Stream.Readable> {
|
||||
const url = this.getUrlForAction('logs');
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user