This commit is contained in:
Julien Fontanet 2015-04-17 10:38:05 +02:00
parent 9baa415249
commit 72a2110845
3 changed files with 76 additions and 0 deletions

View File

@ -12,6 +12,8 @@ Installation of the [npm package](https://npmjs.org/package/xen-api):
## Usage
### Library
```javascript
var createClient = require('xen-api').createClient
@ -34,6 +36,21 @@ xapi.objects.on('add', function (objects) {
})
```
### CLI
A CLI is provided to help exploration and discovery of the XAPI.
```
> xen-api https://xen1.company.net root
Password: ******
root@xen1.company.net> xapi.connect
'connected'
root@xen1.company.net> xapi.pool.master.name_label
'xen1'
```
## Development
### Installing dependencies

View File

@ -22,6 +22,9 @@
},
"preferGlobal": false,
"main": "dist/",
"bin": {
"xen-api": "dist/cli.js"
},
"files": [
"dist/"
],
@ -29,12 +32,16 @@
"babel-runtime": "^5",
"bluebird": "^2.9.21",
"debug": "^2.1.3",
"event-to-promise": "^0.3.2",
"exec-promise": "^0.5.1",
"lodash.find": "^3.2.0",
"lodash.findkey": "^3.0.1",
"lodash.foreach": "^3.0.2",
"lodash.size": "^3.0.0",
"lodash.startswith": "^3.0.1",
"make-error": "^1.0.2",
"minimist": "^1.1.1",
"pw": "0.0.4",
"xmlrpc": "^1.3.0",
"xo-collection": "0.0.1"
},

View File

@ -0,0 +1,52 @@
import Bluebird, {coroutine} from 'bluebird'
import eventToPromise from 'event-to-promise'
import execPromise from 'exec-promise'
import minimist from 'minimist'
import pw from 'pw'
import {start as createRepl} from 'repl'
import {createClient} from './'
const usage = `Usage: xen-api <url> <user>`
const main = coroutine(function * (args) {
const opts = minimist(args, {
boolean: ['help'],
alias: {
help: 'h'
}
})
if (opts.help) {
return usage
}
const [url, user] = opts._
if (!url || !user) {
throw new Error('missing arguments')
}
process.stdout.write('Password: ')
const password = yield new Bluebird(resolve => {
pw(resolve)
})
const xapi = createClient({url, auth: {user, password}})
yield xapi.connect()
const repl = createRepl({
prompt: `${xapi._humanId}> `
})
repl.context.xapi = xapi
yield eventToPromise(repl, 'exit')
try {
yield xapi.disconnect()
} catch (error) {}
})
export default main
if (!module.parent) {
execPromise(main)
}