mirror of
https://github.com/mclueppers/xo-server.git
synced 2025-07-29 00:44:43 +02:00
Various updates.
This commit is contained in:
parent
c611cccc06
commit
c650a92a1d
@ -3,19 +3,6 @@ var Q = require('q');
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// @todo Maybe we should generalize the getter methods (get,
|
|
||||||
// findWhere, where) to two methods: get([properties]) &
|
|
||||||
// first([properties]).
|
|
||||||
//
|
|
||||||
// Each of these methods accept optionnal properties to filter its
|
|
||||||
// results.
|
|
||||||
//
|
|
||||||
// get() returns any models that match while first() returns only the
|
|
||||||
// one.
|
|
||||||
//
|
|
||||||
// These method should also accept a scalar value as a matching value
|
|
||||||
// for the “id” property.
|
|
||||||
|
|
||||||
// @todo Add events.
|
// @todo Add events.
|
||||||
function Collection(models)
|
function Collection(models)
|
||||||
{
|
{
|
||||||
|
12
src/main.js
12
src/main.js
@ -79,8 +79,11 @@ function json_api_call(session, message)
|
|||||||
// JSON-RPC over WebSocket.
|
// JSON-RPC over WebSocket.
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
xo.on('started', function () {
|
||||||
// @todo Port should be configurable.
|
// @todo Port should be configurable.
|
||||||
new (require('ws').Server)({'port': 8080}).on('connection', function (socket) {
|
var server = new (require('ws').Server)({'port': 8080});
|
||||||
|
|
||||||
|
server.on('connection', function (socket) {
|
||||||
var session = new Session(xo);
|
var session = new Session(xo);
|
||||||
session.once('close', function () {
|
session.once('close', function () {
|
||||||
socket.close();
|
socket.close();
|
||||||
@ -97,11 +100,13 @@ new (require('ws').Server)({'port': 8080}).on('connection', function (socket) {
|
|||||||
session.close();
|
session.close();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// JSON-RPC over TCP.
|
// JSON-RPC over TCP.
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
xo.on('started', function () {
|
||||||
require('net').createServer(function (socket) {
|
require('net').createServer(function (socket) {
|
||||||
var session = new Session(xo);
|
var session = new Session(xo);
|
||||||
session.on('close', function () {
|
session.on('close', function () {
|
||||||
@ -160,3 +165,8 @@ require('net').createServer(function (socket) {
|
|||||||
session.close();
|
session.close();
|
||||||
});
|
});
|
||||||
}).listen(1024); // @todo Should be configurable.
|
}).listen(1024); // @todo Should be configurable.
|
||||||
|
});
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
xo.start();
|
||||||
|
76
src/xo.js
76
src/xo.js
@ -33,6 +33,11 @@ var check = function () {
|
|||||||
// Models
|
// Models
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
var Server = Model.extend({
|
||||||
|
'validate': function () {
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// @todo We could also give a permission level to tokens (<=
|
// @todo We could also give a permission level to tokens (<=
|
||||||
// user.permission).
|
// user.permission).
|
||||||
var Token = Model.extend({
|
var Token = Model.extend({
|
||||||
@ -108,15 +113,26 @@ var User = Model.extend({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var Server = Model.extend({
|
var Pool = Model.extend({});
|
||||||
'validate': function () {
|
|
||||||
},
|
var Host = Model.extend({});
|
||||||
});
|
|
||||||
|
var VM = Model.extend({});
|
||||||
|
|
||||||
|
var Network = Model.extend({});
|
||||||
|
|
||||||
|
var SR = Model.extend({});
|
||||||
|
|
||||||
|
var VDI = Model.extend({});
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// Collections
|
// Collections
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
var Servers = Collection.extend({
|
||||||
|
'model': Server,
|
||||||
|
});
|
||||||
|
|
||||||
var Tokens = Collection.extend({
|
var Tokens = Collection.extend({
|
||||||
'model': Token,
|
'model': Token,
|
||||||
|
|
||||||
@ -148,8 +164,28 @@ var Users = Collection.extend({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var Servers = Collection.extend({
|
var Pools = Collection.extend({
|
||||||
'model': Server,
|
'model': Pool,
|
||||||
|
});
|
||||||
|
|
||||||
|
var Hosts = Collection.extend({
|
||||||
|
'model': Host,
|
||||||
|
});
|
||||||
|
|
||||||
|
var VMs = Collection.extend({
|
||||||
|
'model': VM,
|
||||||
|
});
|
||||||
|
|
||||||
|
var Networks = Collection.extend({
|
||||||
|
'model': Network,
|
||||||
|
});
|
||||||
|
|
||||||
|
var SRs = Collection.extend({
|
||||||
|
'model': SR,
|
||||||
|
});
|
||||||
|
|
||||||
|
var VDIs = Collection.extend({
|
||||||
|
'model': VDI,
|
||||||
});
|
});
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
@ -161,10 +197,15 @@ function Xo()
|
|||||||
return new Xo();
|
return new Xo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------
|
||||||
|
// Main objects (@todo should be persistent).
|
||||||
|
|
||||||
this.servers = new Servers();
|
this.servers = new Servers();
|
||||||
this.tokens = new Tokens();
|
this.tokens = new Tokens();
|
||||||
this.users = new Users();
|
this.users = new Users();
|
||||||
|
|
||||||
|
// Temporary user, used for tests while the collection are not
|
||||||
|
// persistent.
|
||||||
this.users.add({
|
this.users.add({
|
||||||
'email': 'bob@gmail.com',
|
'email': 'bob@gmail.com',
|
||||||
'pw_hash': '$2a$10$PsSOXflmnNMEOd0I5ohJQ.cLty0R29koYydD0FBKO9Rb7.jvCelZq',
|
'pw_hash': '$2a$10$PsSOXflmnNMEOd0I5ohJQ.cLty0R29koYydD0FBKO9Rb7.jvCelZq',
|
||||||
@ -184,9 +225,32 @@ function Xo()
|
|||||||
self.emit('user.revoked:'+ user_id);
|
self.emit('user.revoked:'+ user_id);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//--------------------------------------
|
||||||
|
// Xen objects.
|
||||||
|
|
||||||
|
this.pools = new Pools();
|
||||||
|
this.hosts = new Hosts();
|
||||||
|
this.vms = new VMs();
|
||||||
|
|
||||||
|
this.networks = new Networks();
|
||||||
|
this.srs = new SRs();
|
||||||
|
this.vdis = new VDIs();
|
||||||
|
|
||||||
|
// Connecting classes: VIF & PIF, VBD & SR.
|
||||||
}
|
}
|
||||||
require('util').inherits(Xo, require('events').EventEmitter);
|
require('util').inherits(Xo, require('events').EventEmitter);
|
||||||
|
|
||||||
|
Xo.prototype.start = function () {
|
||||||
|
// @todo Connect to persistent collection.
|
||||||
|
|
||||||
|
// @todo Connect to Xen servers & fetch data.
|
||||||
|
|
||||||
|
// -------------------------------------
|
||||||
|
|
||||||
|
this.emit('started');
|
||||||
|
};
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
module.exports = Xo;
|
module.exports = Xo;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user