Git Product home page Git Product logo

rancher.js's Introduction

Build Status (We'll put in some cool shit here. DUH.)

rancher.js

A (hopefully?) awesome Javascript wrapper around the Rancher 1 API(v2) for container orchestration.

Usage

Getting started

The first step is initializing a connection to your Rancher cluster.

const cattleRustler = new rancher.Rancher(BASE_URL, API_KEY, API_SECRET)

The base URL is the URL Rancher uses to communicate with its API. For instance, if you access Rancher at rancher.example.com:8080, then the base URL would be http://rancher.example.com:8080. HTTPS URLs also work. API keys and secrets can be generated by navigating to API > Keys > Add Account API Key. Note that rancher.js doesn't support environment API keys at this point.

First, it's important to get a list of your Rancher environments - this will be needed later.

cattleRustler.getEnvironments()
.then((result) => {
	console.log(result)
	})

The library is promises-based, so await work just fine:

// Inside an async function
let environments = await cattleRustler.getEnvironments()

Here's how you can grab a list of Rancher stacks in a particular environment:

// Inside an async function
let stacks = await cattleRustler.getStacks(environmentId)

To get a list of services inside a stack:

// Inside an async function
let services = await cattleRustler.getServices(stackId)

Creating stacks and services

You can create a new stack by supplying the new stack's name and the intended environment's ID to the createStack method:

// Inside an async function
let newStack = await cattleRustler.createStack(environmentId, newStackName)

This creates a new stack and returns its details, including a stack ID. At this point, it's not possible to pass Docker and Rancher Compose files through rancher.js, although that's definitely an intended feature.

To create a new service:

// Inside an async function
let newService = await cattleRustler.createStackService(environmentId, stackId, scale, serviceName, labels, environmentVars, imageUuid)

Here, labels is a simple object containing label names and values as key-pairs. The same holds true for environmentVars. The imageUuid parameter is the Docker image you wish to spin the service from - so if you wish to spin up the official nginx image, the imageUuid would be docker:nginx:latest. Calling this method results in Rancher orchestrating the service and returning its service ID.

Starting and stopping stacks and services is easy - just call the startStack and stopStack with an environment ID and a stack ID to start/stop a stack; for starting/stopping services, call startService and stopService with an environment ID and a service ID.

License

Here you go.

rancher.js's People

Contributors

rudimk avatar varunmehra5 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.