2015-09-21 21:05:22 +03:00
![logo ](./tools/triton-text.png )
2015-08-26 23:09:40 +03:00
2015-09-21 20:50:34 +03:00
# node-triton
2015-09-06 02:43:40 +03:00
2016-08-22 20:45:21 +03:00
This repository is part of the Joyent Triton project. See the [contribution
guidelines](https://github.com/joyent/triton/blob/master/CONTRIBUTING.md) --
*Triton does not use GitHub PRs* -- and general documentation at the main
[Triton project ](https://github.com/joyent/triton ) page.
2015-09-08 22:04:30 +03:00
`triton` is a CLI tool for working with the CloudAPI for Joyent's Triton [Public Cloud]
(https://docs.joyent.com/public-cloud) and [Private Cloud] (https://docs.joyent.com/private-cloud).
CloudAPI is a RESTful API for end users of the cloud to manage their accounts, instances,
networks, images, and to inquire other relevant details. CloudAPI provides a single view of
docker containers, infrastructure containers and hardware virtual machines available in the
Triton solution.
There is currently another CLI tool known as [node-smartdc ](https://github.com/joyent/node-smartdc )
2015-09-10 02:09:44 +03:00
for CloudAPI. `node-smartdc` CLI works off the 32-character object UUID to uniquely
2015-09-08 22:04:30 +03:00
identify object instances in API requests, and returns response payload in JSON format.
The CLI covers both basic and advanced usage of [CloudAPI ](https://apidocs.joyent.com/cloudapi/ ).
2016-08-22 20:45:21 +03:00
**The `triton` CLI is currently in beta (effectively because it does not yet
have *complete* coverage of all commands from node-smartdc) and will be
expanded over time to support all CloudAPI commands, eventually replacing
`node-smartdc` as both the API client library for Triton cloud and the command
line tool.**
2014-02-07 23:21:24 +02:00
2015-09-08 22:04:30 +03:00
## Setup
2015-07-26 08:46:24 +03:00
2015-09-08 22:04:30 +03:00
### User accounts, authentication, and security
2014-02-07 23:21:24 +02:00
2015-09-08 22:04:30 +03:00
Before you can use the CLI you'll need an account on the cloud to which you are connecting and
an SSH key uploaded. The SSH key is used to identify and secure SSH access to containers and
2015-09-10 02:09:44 +03:00
other resources in Triton.
2014-02-07 23:21:24 +02:00
2015-09-08 22:04:30 +03:00
If you do not already have an account on Joyent Public Cloud, sign up [here ](https://www.joyent.com/public-cloud ).
2014-02-07 23:21:24 +02:00
2015-09-06 02:43:40 +03:00
2015-09-08 22:04:30 +03:00
### API endpoint
Each data center has a single CloudAPI endpoint. For Joyent Public Cloud, you can find the
2015-12-16 02:21:24 +02:00
list of data centers [here ](https://docs.joyent.com/public-cloud/data-centers ).
2015-09-08 22:04:30 +03:00
For private cloud implementations, please consult the private cloud operator for the correct URL.
Have the URL handy as you'll need it in the next step.
2014-02-07 23:21:24 +02:00
2015-09-08 22:04:30 +03:00
### Installation
1. Install [node.js ](http://nodejs.org/ ).
2015-10-01 00:37:28 +03:00
2. `npm install -g triton`
2015-09-08 22:04:30 +03:00
Verify that it is installed and on your PATH:
$ triton --version
Triton CLI 1.0.0
2015-09-06 02:43:40 +03:00
2015-09-08 22:04:30 +03:00
Configure the proper environmental variables that correspond to the API endpoint and account,
for example:
2014-02-07 23:21:24 +02:00
2015-09-06 02:43:40 +03:00
SDC_URL=https://us-east-3b.api.joyent.com
SDC_ACCOUNT=dave.eddy@joyent.com
SDC_KEY_ID=04:0c:22:25:c9:85:d8:e4:fa:27:0d:67:94:68:9e:e9
2014-02-07 23:21:24 +02:00
2015-09-08 22:04:30 +03:00
### Bash completion
2016-01-08 21:07:43 +02:00
Install Bash completion with
2015-09-08 22:04:30 +03:00
2016-01-08 21:07:43 +02:00
```bash
2016-01-28 23:30:11 +02:00
triton completion > /usr/local/etc/bash_completion.d/triton # Mac
triton completion > /etc/bash_completion.d/triton # Linux
2016-01-08 21:07:43 +02:00
```
2015-09-08 22:04:30 +03:00
2016-01-08 21:07:43 +02:00
Alternatively, if you don't have or don't want to use a "bash\_completion.d"
dir, then something like this would work:
2015-09-08 22:04:30 +03:00
2016-01-08 21:07:43 +02:00
```bash
triton completion > ~/.triton.completion
echo "source ~/.triton.completion" >> ~/.bashrc
```
2015-09-08 22:04:30 +03:00
2016-01-08 21:07:43 +02:00
Then open a new shell or manually `source FILE` that completion file, and
play with the bash completions:
triton < TAB >
2015-09-08 22:04:30 +03:00
2015-12-08 21:59:45 +02:00
## `triton` CLI Usage
2014-02-07 23:21:24 +02:00
2015-09-08 22:04:30 +03:00
### Create and view instances
2015-09-06 02:43:40 +03:00
2016-01-10 21:58:18 +02:00
$ triton instance list
2015-09-06 02:43:40 +03:00
SHORTID NAME IMG STATE PRIMARYIP AGO
We have no instances created yet, so let's create some. In order to create
an instance we need to specify two things: an image and a package. An image
represents what will be used as the root of the instances filesystem, and the
package represents the size of the instance, eg. ram, disk size, cpu shares,
etc. More information on images and packages below - for now we'll just use
2015-09-08 22:04:30 +03:00
SmartOS 64bit and a small 128M ram package which is a combo available on the
Joyent Public Cloud.
2016-01-10 21:58:18 +02:00
$ triton instance create base-64 t4-standard-128M
2015-09-08 22:04:30 +03:00
Without a name specified, the container created will have a generated ID. Now
to create a container-native Ubuntu 14.04 container with 2GB of ram with the
name "server-1"
2015-09-06 02:43:40 +03:00
2016-01-10 21:58:18 +02:00
$ triton instance create --name=server-1 ubuntu-14.04 t4-standard-2G
2015-09-08 22:04:30 +03:00
Now list your instances again
2016-01-10 21:58:18 +02:00
$ triton instance list
2015-09-08 22:04:30 +03:00
SHORTID NAME IMG STATE PRIMARYIP AGO
7db6c907 b851ba9 base-64@15.2.0 running 165.225.169.63 9m
9cf1f427 server-1 ubuntu-14.04@20150819 provisioning - 0s
2015-09-06 02:43:40 +03:00
2015-08-26 23:09:40 +03:00
Get a quick overview of your account
$ triton info
2015-09-06 02:43:40 +03:00
login: dave.eddy@joyent.com
name: Dave Eddy
email: dave.eddy@joyent.com
url: https://us-east-3b.api.joyent.com
2015-09-08 22:04:30 +03:00
totalDisk: 50.5 GiB
totalMemory: 2.0 MiB
instances: 2
running: 1
provisioning: 1
To obtain more detailed information of your instance
2016-01-10 21:58:18 +02:00
$ triton instance get server-1
2015-09-08 22:04:30 +03:00
{
"id": "9cf1f427-9a40-c188-ce87-fd0c4a5a2c2c",
"name": "251d4fd",
"type": "smartmachine",
"state": "running",
"image": "c8d68a9e-4682-11e5-9450-4f4fadd0936d",
"ips": [
"165.225.169.54",
"192.168.128.16"
],
"memory": 2048,
"disk": 51200,
"metadata": {
"root_authorized_keys": "(...ssh keys...)"
},
"tags": {},
"created": "2015-09-08T04:56:27.734Z",
"updated": "2015-09-08T04:56:43.000Z",
"networks": [
"feb7b2c5-0063-42f0-a4e6-b812917397f7",
"726379ac-358b-4fb4-bb7c-8bc4548bac1e"
],
"dataset": "c8d68a9e-4682-11e5-9450-4f4fadd0936d",
"primaryIp": "165.225.169.54",
"firewall_enabled": false,
"compute_node": "44454c4c-5400-1034-8053-b5c04f383432",
"package": "t4-standard-2G"
}
2015-09-10 02:09:44 +03:00
2015-09-08 22:04:30 +03:00
### SSH to an instance
2014-02-20 05:52:58 +02:00
2015-08-26 23:09:40 +03:00
Connect to an instance over SSH
2014-02-20 05:52:58 +02:00
2015-09-08 22:04:30 +03:00
$ triton ssh b851ba9
2015-08-26 23:09:40 +03:00
Last login: Wed Aug 26 17:59:35 2015 from 208.184.5.170
__ . .
_| |_ | .-. . . .-. :--. |-
|_ _| ;| || |(.-' | | |
|__| `--' ` -' `;-| ` -' ' ' `-'
/ ; Instance (base-64 15.2.0)
`-' https://docs.joyent.com/images/smartos/base
[root@7db6c907-2693-42bc-ea9b-f38678f2554b ~]# uptime
20:08pm up 2:27, 0 users, load average: 0.00, 0.00, 0.01
[root@7db6c907-2693-42bc-ea9b-f38678f2554b ~]# logout
Connection to 165.225.169.63 closed.
Or non-interactively
2015-09-08 22:04:30 +03:00
$ triton ssh b851ba9 uname -v
2015-08-26 23:09:40 +03:00
joyent_20150826T120743Z
2015-09-08 22:04:30 +03:00
### Manage an instance
2015-09-04 10:09:19 +03:00
2016-01-10 21:58:18 +02:00
Commonly used container operations are supported in the Triton CLI:
2015-09-04 10:09:19 +03:00
2016-01-10 21:58:18 +02:00
$ triton help instance
2015-09-08 22:04:30 +03:00
...
2016-01-10 21:58:18 +02:00
list (ls) List instances.
get Get an instance.
create Create a new instance.
delete (rm) Delete one or more instances.
start Start one or more instances.
stop Stop one or more instances.
reboot Reboot one or more instances.
ssh SSH to the primary IP of an instance
wait Wait on instances changing state.
audit List instance actions.
2015-09-04 10:09:19 +03:00
2015-09-08 22:04:30 +03:00
### View packages and images
2015-09-04 10:09:19 +03:00
2015-12-16 02:21:24 +02:00
Package definitions and images available vary between different data centers
2015-09-09 04:30:42 +03:00
and different Triton cloud implementations.
2015-09-04 10:09:19 +03:00
2016-01-10 21:58:18 +02:00
To see all the packages offered in the data center and specific package
information, use
2015-09-08 22:04:30 +03:00
2016-01-10 21:58:18 +02:00
$ triton package list
$ triton package get ID|NAME
2015-09-08 22:04:30 +03:00
Similarly, to find out the available images and their details, do
2016-01-10 21:58:18 +02:00
$ triton image list
$ triton images ID|NAME
2015-09-08 22:04:30 +03:00
Note that docker images are not shown in `triton images` as they are
maintained in Docker Hub and other third-party registries configured to be
used with Joyent's Triton clouds. **In general, docker containers should be
2016-01-10 21:58:18 +02:00
provisioned and managed with the regular
[`docker` CLI ](https://docs.docker.com/installation/#installation )**
2015-09-09 04:30:42 +03:00
(Triton provides an endpoint that represents the _entire datacenter_
2015-09-08 22:04:30 +03:00
as a single `DOCKER_HOST` . See the [Triton Docker
documentation](https://apidocs.joyent.com/docker) for more information.)
2015-09-04 10:09:19 +03:00
2015-12-08 21:59:45 +02:00
## `TritonApi` Module Usage
Node-triton can also be used as a node module for your own node.js tooling.
2016-12-13 20:04:41 +02:00
A basic example appropriate for a command-line tool is:
```javascript
var mod_bunyan = require('bunyan');
var mod_triton = require('triton');
var log = mod_bunyan.createLogger({name: 'my-tool'});
// See the `createClient` block comment for full usage details:
// https://github.com/joyent/node-triton/blob/master/lib/index.js
mod_triton.createClient({
log: log,
// Use 'env' to pick up 'TRITON_/SDC_' env vars. Or manually specify a
// `profile` object.
profileName: 'env',
unlockKeyFn: mod_triton.promptPassphraseUnlockKey
}, function (err, client) {
if (err) {
// handle err
}
2015-12-08 21:59:45 +02:00
client.listImages(function (err, images) {
client.close(); // Remember to close the client to close TCP conn.
if (err) {
console.error('listImages err:', err);
} else {
console.log(JSON.stringify(images, null, 4));
}
});
2016-12-13 20:04:41 +02:00
});
```
2015-12-08 21:59:45 +02:00
2016-12-13 20:04:41 +02:00
See the following for more details:
- The block-comment for `createClient` in [lib/index.js ](lib/index.js ).
- Some module-usage examples in [examples/ ](examples/ ).
- The lower-level details in the top-comment in
[lib/tritonapi.js ](lib/tritonapi.js ).
2015-12-08 21:59:45 +02:00
2015-09-08 19:55:48 +03:00
## Configuration
This section defines all the vars in a TritonApi config. The baked in defaults
are in "etc/defaults.json" and can be overriden for the CLI in
2016-01-28 23:30:11 +02:00
"~/.triton/config.json" (on Windows: "%APPDATA%/Joyent/Triton/config.json").
2015-09-08 19:55:48 +03:00
| Name | Description |
| ---- | ----------- |
| profile | The name of the triton profile to use. The default with the CLI is "env", i.e. take config from `SDC_*` envvars. |
| cacheDir | The path (relative to the config dir, "~/.triton") where cache data is stored. The default is "cache", i.e. the `triton` CLI caches at "~/.triton/cache". |
2015-09-01 20:55:39 +03:00
## node-triton differences with node-smartdc
2014-02-21 01:45:15 +02:00
2015-09-06 02:43:40 +03:00
- There is a single `triton` command instead of a number of `sdc-*` commands.
2015-12-08 21:59:45 +02:00
- `TRITON_*` environment variables are preferred to the `SDC_*` environment
variables. However the `SDC_*` envvars are still supported.
2016-01-10 21:58:18 +02:00
- Node-smartdc still has more complete coverage of the Triton
[CloudAPI ](https://apidocs.joyent.com/cloudapi/ ). However, `triton` is
catching up and is much more friendly to use.
2014-02-21 01:45:15 +02:00
2014-02-20 05:52:58 +02:00
2015-09-01 20:55:39 +03:00
## Development Hooks
2015-10-05 17:31:45 +03:00
Before commiting be sure to, at least:
2015-09-01 20:55:39 +03:00
make check # lint and style checks
2015-10-05 17:31:45 +03:00
make test-unit # run unit tests
2015-09-01 20:55:39 +03:00
A good way to do that is to install the stock pre-commit hook in your
clone via:
make git-hooks
2015-10-05 17:31:45 +03:00
Also please run the full (longer) test suite (`make test`). See the next
section.
## Test suite
node-triton has both unit tests (`make test-unit`) and integration tests (`make
2015-10-07 09:09:52 +03:00
test-integration`). Integration tests require a config file, by default at
"test/config.json". For example:
2015-10-05 17:31:45 +03:00
2015-10-07 09:09:52 +03:00
$ cat test/config.json
{
"profileName": "east3b",
2015-10-07 22:19:26 +03:00
"allowWriteActions": true,
2015-10-07 09:09:52 +03:00
"image": "minimal-64",
"package": "t4-standard-128M"
}
2015-10-05 17:31:45 +03:00
2015-10-07 09:09:52 +03:00
See "test/config.json.sample" for a description of all config vars. Minimally
just a "profileName" or "profile" is required.
2015-10-05 17:31:45 +03:00
2016-01-10 21:58:18 +02:00
*Warning:* Running the *integration* tests will create resources and could
incur costs if running against a public cloud.
2015-10-07 09:09:52 +03:00
Run all tests:
2015-10-05 17:31:45 +03:00
2015-10-07 09:09:52 +03:00
make test
2015-10-05 17:31:45 +03:00
2015-10-07 09:09:52 +03:00
You can use `TRITON_TEST_CONFIG` to override the test file, e.g.:
2015-10-05 17:31:45 +03:00
2015-10-07 09:09:52 +03:00
$ cat test/coal.json
{
"profileName": "coal",
2015-10-07 22:19:26 +03:00
"allowWriteActions": true
2015-10-07 09:09:52 +03:00
}
$ TRITON_TEST_CONFIG=test/coal.json make test
2015-10-05 17:31:45 +03:00
2015-10-07 09:09:52 +03:00
where "coal" here refers to a development Triton (a.k.a SDC) ["Cloud On A
Laptop"](https://github.com/joyent/sdc#getting-started) standup.
2015-10-05 17:31:45 +03:00
2016-09-18 03:43:45 +03:00
## Release process
Here is how to cut a release:
1. Make a commit to set the intended version in "package.json#version" and changing `## not yet released` at the top of "CHANGES.md" to:
```
## not yet released
## $version
```
2. Get that commit approved and merged via < https: // cr . joyent . us > , as with all
commits to this repo. See the discussion of contribution at the top of this
readme.
3. Once that is merged and you've updated your local copy, run:
```
make cutarelease
```
This will run a couple checks (clean working copy, versions in package.json
and CHANGES.md match), then will git tag and npm publish.
2015-09-06 02:43:40 +03:00
## License
2015-09-01 20:55:39 +03:00
2015-09-06 02:43:40 +03:00
MPL 2.0