linkercli

1.0.6 • Public • Published

README - linkercli

Linker CLI is a command line interface for LinkerIoT Platform, it provide user to remote control with LinkerIoT platform managed devices using RESTful way and also interactive way.

Linker IoT Platform

LinkerIoT platform is a platform that provide cloud connect with your devices. And we also provide related remote managed features for user to control their devices to install, remove or upgrade. More detail, please see: http://linkeriot.io.

Install

npm install linkercli -g

Before Start

If you using private LinkerIoT platform, please set the environment first:

export IOT_SERVER=http://your-server-url:port

Help page

Linker CLI implement help page to let you use "--help" to show command support.

$ linkercli --help

  Usage: linkercli [options] [command]


  Commands:

    config [options] [env]      login to linker service
    project [options] [env]     project related operation
    auth [options] [env]        login to linker service
    token [env]                 get current login token
    device|dev [options] [env]  device related command
    *

  Options:

    -h, --help           output usage information
    -V, --version        output the version number
    -C, --config [UUUU]  The account username of linkeriot (should be an email)

For sub-command help page:

linkercli [sub-command] --help

You can try like this:

$ linkercli auth --help

  Usage: auth [options] [env]

  login to linker service

  Options:

    -h, --help                 output usage information
    -u, --username [username]  The account username of linkeriot (should be an email)
    -p, --password [password]  The account password of linkeriot

For excape some device id, please use "/" for escape:

ex: -AZwXZrybGFFVPyqAAAD as device id, can be escape use "/-AZwXZrybGFFVPyqAAAD"

linkercli dev clear --deviceid "/-AZwXZrybGFFVPyqAAAD"

Auth / Login

Before use of linkercli tool, you need to auth use your username and password.

$ linkercli auth -u your-account -p your-password

{ code: 200,
  msg: 'ok',
  token: '057d0e28d600931e87002958905c4a76d401e402711f06337331de37db40527100b9fc15de3dcb8705abeb189b247fe3' }

Project releated

The related project managed feature can use the project related command.

List your projects

If you already have project in out platform, you can list the project like:

$ linkercli prj list | json

[
  {
    "project_id": "aaaa-bbbb-cccc-dddd",
    "data": {
      "project_alias": "simon-project2",
      "project_archs": [
        "rpi-armv7l",
        "rpi-arm64"
      ],
      "download_urls": {
        "rpi-armv7l": null,
        "rpi-arm64": null
      },
      "create_time": 1460108981483
    }
  }
]

Create project

If you want to create a new project, you need to specify the project name, alias and the cpu architecture that you want to include in the project.

$ linkercli project create -p simon-project -a project-alias -r rpi-armv7l -r rpi-arm64

Get device image

After the device create, system will create the project image in background. And you can download the image using "linkercli project download" command.

$ linkercli prj download -p simon-project -r rpi-armv7l -O /tmp

List devices

If you already have devices in LinkerIoT platform, you can use the device related sub-command to show related information.

$ linkercli dev list -s active | json
[
  {
    "_id": "mxY6yqIkQzb9hZ9SAAAE",
    "hostname": "cubietruck",
    "mem_used": 0.2228827646798143,
    "cpu_used": 0.013967527165392735,
    "arch": "ARMv7 Processor rev 4 (v7l)",
    "ip_detail": {
      "eth0": [
        {
          "address": "192.168.105.123",
          "netmask": "255.255.255.0",
          "family": "IPv4",
          "mac": "02:01:06:41:82:58",
          "internal": false
        },
        {
          "address": "fe80::1:6ff:fe41:8258",
          "netmask": "ffff:ffff:ffff:ffff::",
          "family": "IPv6",
          "mac": "02:01:06:41:82:58",
          "scopeid": 4,
          "internal": false
        }
      ]
    },
    "ips": [
      "192.168.105.123"
    ],
    "rootdisk": 0.8638665072108402,
    "id": "mxY6yqIkQzb9hZ9SAAAE",
    "deviceId": "mxY6yqIkQzb9hZ9SAAAE",
    "projectInfo": {
      "projectid": "simon-project",
      "ownerid": "simonsu.mail@gmail.com",
      "owner": "simonsu.mail@gmail.com"
    },
    "status": "active"
  }
]

Get device running jobs/containers

Once you get the device id, you can look into the running job/container inside the device.

$ linkercli dev ps -d a_54ERXdr4inKCGiAAAA | json
[
  {
    "containerId": "c4c2d8bc7815",
    "command": "\"node web.js\"",
    "image": "git.linkeriot.io:5000/simonsu/sample",
    "createAt": "2016-04-19 02:30:30 +0000 UTC",
    "created": "27 minutes",
    "ports": "0.0.0.0:1337->1337/tcp",
    "status": "Up 27 minutes",
    "size": "0 B",
    "names": "mad_nobel"
  }
]

Service lifecycle in a device

Run a job/container in a device

$ linkercli device run -d a_54ERXdr4inKCGiAAAA -i git.linkeriot.io:5000/simonsu/sample -c "node web.js" -P

Stop the job/container

$ linkercli device rm -d a_54ERXdr4inKCGiAAAA  -I a587c1013c4f

Show the exist images in a device

$ linkercli device images -d a_54ERXdr4inKCGiAAAA  

Get an image into device

$ linkercli dev pull -i git.linkeriot.io:5000/simonsu/sample  -P -d a_54ERXdr4inKCGiAAAA

Delete image in a device

$ linkercli device rm -d a_54ERXdr4inKCGiAAAA  -I a587c1013c4f

List process in a device

$ linkercli dev ps -d a_54ERXdr4inKCGiAAAA | json
[
  {
    "containerId": "09bcc774d9da",
    "command": "\"sh\"",
    "image": "linkerlab/rpi-node:5.9.1-armv7l",
    "createAt": "2016-04-08 08:28:12 +0000 UTC",
    "created": "14 minutes",
    "ports": "",
    "status": "Up 14 minutes",
    "size": "0 B",
    "names": "prickly_shockley"
  }
]

You can also show all process, like:

linkercli dev ps -d a_54ERXdr4inKCGiAAAA --showall |json
[
  {
    "containerId": "f311d7f46e61",
    "command": "\"node web.js\"",
    "image": "git.linkeriot.io:5000/simonsu/sample",
    "createAt": "2016-04-08 08:56:28 +0000 UTC",
    "created": "59 seconds",
    "ports": "",
    "status": "Up 57 seconds",
    "size": "0 B",
    "names": "sharp_lumiere"
  },
  {
    "containerId": "e9ec2a2c8fcb",
    "command": "\"node linkeragent\"",
    "image": "git.linkeriot.io:5000/linkeriot/linker-rpi-agent:armv7l",
    "createAt": "2016-04-08 07:32:22 +0000 UTC",
    "created": "About an hour",
    "ports": "",
    "status": "Up 24 minutes",
    "size": "0 B",
    "names": "hungry_goldstine"
  }
]

Stop container in a device

$ linkercli dev stop -d a_54ERXdr4inKCGiAAAA -I 09bcc774d9da

{
  "code": 200,
  "msg": {
    "err": null,
    "stdo": "09bcc774d9da\n",
    "stde": ""
  }
}

Remove container in a device

$ linkercli dev rm -d a_54ERXdr4inKCGiAAAA -I 09bcc774d9da | json

{
  "code": 200,
  "msg": {
    "err": null,
    "stdo": "09bcc774d9da\n",
    "stde": ""
  }
}

LinkerIoT interactive mode - linkercli-it

linkercli-it is an interactive mode shell for user to interactive with their device like SSH or Telnet. Before use of linkercli-it, you need to retrieve the device id as input to connect with.

$ linkercli-it a_54ERXdr4inKCGiAAAA
***********************************************************************************
 You already connect to device a_54ERXdr4inKCGiAAAA
 Now, you can use the device related command to interactive with your device...
 Please use command "quit" or "exit" for leave the session!
***********************************************************************************
? a_54ERXdr4inKCGiAAAA → ls -l
total 48
-rw-r--r--  1 root root 1828 Apr  8 06:28 builder.js
drwxr-xr-x  2 root root 4096 Apr  8 06:29 lib
-rw-r--r--  1 root root 4951 Apr 13 14:02 linkeragent.js
drwxr-xr-x 44 root root 4096 Apr 14 08:06 node_modules
-rw-r--r--  1 root root  347 Apr  7 08:50 package.json
-rw-r--r--  1 root root 1177 Feb 10 14:45 sample-webhook.json
drwxr-xr-x  2 root root 4096 Apr 13 11:02 scripts
-rw-r--r--  1 root root 3520 Feb 25 10:13 stat.js
-rw-r--r--  1 root root   72 Mar 11 11:24 test-guid.js
-rw-r--r--  1 root root  608 Apr  7 09:06 test.js
-rw-r--r--  1 root root   52 Apr 14 07:43 test.yml

Readme

Keywords

none

Package Sidebar

Install

npm i linkercli

Weekly Downloads

2

Version

1.0.6

License

ISC

Last publish

Collaborators

  • peihsinsu