Skip to content

Commit

Permalink
Merge pull request #7 from rudimk/dev
Browse files Browse the repository at this point in the history
v0.5.0
  • Loading branch information
rudimk authored May 14, 2018
2 parents 33a8340 + cf4750b commit 82e137a
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 5 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

[![npm](https://img.shields.io/npm/v/npm.svg?style=plastic)](https://www.npmjs.com/package/rancher.js)

[![Build Status](https://travis-ci.org/rudimk/rancher.js.svg?branch=master)](https://travis-ci.org/rudimk/rancher.js)

# rancher.js
Expand Down Expand Up @@ -67,6 +70,8 @@ let newService = await cattleRustler.createStackService(environmentId, stackId,

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

Expand Down
38 changes: 37 additions & 1 deletion lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,43 @@ class Rancher {
try{
let endpoint = this.baseUrl + '/v2-beta/projects/' + environmentId + '/services/' + serviceId + '?action=deactivate'
let response = await axios({url: endpoint, method: 'post', auth: {username: this.apiKey, password: this.apiSecret}})
return true
return {service: response.data, status: true}
}
catch(err){
console.log(err)
}
}

// Activate a particular service.
async startService(environmentId, serviceId){
try{
let endpoint = this.baseUrl + '/v2-beta/projects/' + environmentId + '/services/' + serviceId + '?action=activate'
let response = await axios({url: endpoint, method: 'post', auth: {username: this.apiKey, password: this.apiSecret}})
return {service: response.data, status: true}
}
catch(err){
console.log(err)
}
}

//Deactivate a stack.
async stopStack(environmentId, stackId){
try{
let endpoint = this.baseUrl + '/v2-beta/projects/' + environmentId + '/stacks/' + stackId + '?action=deactivateservices'
let response = await axios({url: endpoint, method: 'post', auth: {username: this.apiKey, password: this.apiSecret}})
return {stack: response.data, status: true}
}
catch(err){
console.log(err)
}
}

//Activate a stack.
async startStack(environmentId, stackId){
try{
let endpoint = this.baseUrl + '/v2-beta/projects/' + environmentId + '/stacks/' + stackId + '?action=activateservices'
let response = await axios({url: endpoint, method: 'post', auth: {username: this.apiKey, password: this.apiSecret}})
return {stack: response.data, status: true}
}
catch(err){
console.log(err)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rancher.js",
"version": "0.2.0",
"version": "0.5.0",
"description": "A clean interface to Rancher 1.0's API.",
"main": "lib.js",
"scripts": {
Expand Down
26 changes: 23 additions & 3 deletions tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,35 @@ describe("Rancher.js tests: ", function(){
})
})

it("Create a new stack service and then deactivate it", function(){
it("Create a new stack service and then deactivate/activate it", function(){
cattleRustler.createStackService('1a5', '1st5', uuid.v4(), { label1: 'value_one', label2: 'value_two' }, { API_KEY: 'value_one', API_SECRET: 'value_two' }, 'docker:nginx:latest')
.then((serviceResult) => {
expect(serviceResult['id']).to.be.a('string')
console.log(`New service ID: ${serviceResult['id']} || New Service Name: ${serviceResult['name']}`)
console.log('Deactivating service..')
cattleRustler.stopService('1a5', serviceResult['id'])
.then((result) => {
console.log(result)
.then((stopResult) => {
expect(stopResult.status).to.equal(true)
cattleRustler.startService('1a5', serviceResult['id'])
.then((startResult) => {
expect(startResult.status).to.equal(true)
})
})
})
})

it("Create a new stack and then deactivate/activate it", function(){
cattleRustler.createStack('1a5', uuid.v4())
.then((stackResult) => {
//expect(stackResult['id']).to.be.a('string')
console.log(`New Stack ID: ${stackResult['id']} || New Stack Name: ${stackResult['name']}`)
cattleRustler.stopStack('1a5', stackResult['id'])
.then((stopResult) => {
expect(stopResult.status).to.equal(true)
cattleRustler.startStack('1a5', stackResult['id'])
.then((startResult) => {
expect(startResult.status).to.equal(true)
})
})
})
})
Expand Down

0 comments on commit 82e137a

Please sign in to comment.