Initial VM-template support.

This commit is contained in:
Julien Fontanet 2014-01-15 15:28:48 +01:00
parent 44826da3ee
commit f336832395
5 changed files with 80 additions and 18 deletions

View File

@ -29,12 +29,14 @@
"underscore": "~1.5.2",
"validator": "~2.0.0",
"ws": "~0.4.31",
"xml2js": "~0.4.1",
"xmlrpc": "~1.1.1"
},
"devDependencies": {
"chai": "~1.8.1",
"glob": "~3.2.8",
"mocha": "~1.14.0",
"mocha-as-promised": "~2.0.0",
"node-inspector": "~0.6.1",
"sinon": "~1.7.3"
},

View File

@ -3,6 +3,9 @@
# Tests runner.
$mocha = require 'mocha'
# Promises support for Mocha.
(require 'mocha-as-promised')()
# Used to find the specification files.
$glob = require 'glob'

View File

@ -115,7 +115,7 @@ $watch = (collection, {
# Computes the current value.
value = val.call item
(valuesByNamespace[namespace] ?= {})[item.key] = value
(valuesByNamespace[namespace] ?= []).push value
# Stops here if no values were computed.
return if do ->
@ -187,8 +187,9 @@ $watch = (collection, {
# Handles existing items.
process 'enter', collection.getRaw()
# Returns the generator.
->
# Creates the generator: the function which items will used to
# register to this watcher and to get the current value.
generator = ->
{key} = this
# Register this item has a consumer.
@ -201,14 +202,31 @@ $watch = (collection, {
else
values.common
# Creates a helper to get the value without using an item.
generator.raw = (key) ->
values[if key? then "$#{key}" else 'common']
# Returns the generator.
generator
#=====================================================================
$map = (options) ->
options.init = []
options.init = Object.create null
$watch this, options, (entered, exited) ->
$each entered, (value, key) => @value[key] = value
$each exited, (value, key) => delete @value[key]
changed = false
$each entered, ([key, value]) =>
unless @value[key] is value
@value[key] = value
changed = true
$each exited, ([key, value]) =>
if key of @value
delete @value[key]
changed = true
changed
#---------------------------------------------------------------------
@ -304,6 +322,7 @@ $val = (options) ->
#=====================================================================
module.exports = {
$map
$set
$sum
$val

View File

@ -1,5 +1,14 @@
$_ = require 'underscore'
#---------------------------------------------------------------------
$xml2js = require 'xml2js'
#---------------------------------------------------------------------
# Helpers for dealing with fibers.
{$synchronize} = require './fibers-utils'
#=====================================================================
$isVMRunning = ->
@ -15,6 +24,8 @@ $isHostRunning = ->
$isTaskLive = ->
@genval.status is 'pending' or @genval.status is 'cancelling'
$parseXML = $synchronize 'parseString', $xml2js
$retrieveTags = -> [] # TODO
#=====================================================================
@ -22,6 +33,7 @@ $retrieveTags = -> [] # TODO
module.exports = ->
{
$map
$set
$sum
$val
@ -64,6 +76,11 @@ module.exports = ->
rules = (rules, definition) =>
@rule rule, definition for rule in rules
UUIDsToKeys = $map {
if: -> @val and 'UUID' of @val
val: -> [@val.UUID, @key]
}
# An item is equivalent to a rule but one and only one instance of
# this rule is created without any generator.
@item xo: ->
@ -103,9 +120,8 @@ module.exports = ->
# }
# }
# $UUIDsToKeys: $map {
# }
# Maps the UUIDs to keys (i.e. opaque references).
$UUIDsToKeys: UUIDsToKeys
}
@rule pool: ->
@ -233,7 +249,8 @@ module.exports = ->
}
}
rules ['VM', 'VM-controller', 'VM-template', 'VM-snapshot'], ->
# This definition is shared.
VMdef = ->
@val = {
name_label: -> @genval.name_label
@ -311,6 +328,20 @@ module.exports = ->
$VIFs: -> @genval.VIFs
}
@rule VM: VMdef
@rule 'VM-controller': VMdef
@rule 'VM-snapshot': VMdef
# VM-template starts with the same definition but extends it.
@rule 'VM-template': ->
VMdef.call this
@val.template_info = {
disks: ->
disks = @genval.other_config?.disks
return unless disks?
$parseXML disks
}
@rule SR: ->
@val = {
@ -470,10 +501,8 @@ module.exports = ->
# TODO: UNIX timestamp?
time: -> @genval.timestamp
# FIXME: should be a ref!!!
#
# Links to messages are broken due to this.
object: -> @genval.obj_uuid
# FIXME: loop
#object: -> (UUIDsToKeys.call this)[@genval.obj_uuid]
# TODO: Are these names meaningful?
name: -> @genval.name

View File

@ -8,12 +8,15 @@ $sinon = require 'sinon'
$helpers = require './helpers'
# Helpers for dealing with fibers.
{$promisify} = require './fibers-utils'
#=====================================================================
describe 'spec2', ->
collection = null
before ->
before $promisify ->
# Creates the collection.
collection = new $MappedCollection2()
@ -37,6 +40,8 @@ describe 'spec2', ->
it 'xo', ->
xo = collection.get '00000000-0000-0000-0000-000000000000'
#console.log xo
$expect(xo).to.be.an 'object'
$expect(xo.type).to.equal 'xo'
@ -263,6 +268,10 @@ describe 'spec2', ->
'OpaqueRef:20349ad5-0a0d-4b80-dcc0-0037fa647182'
]
it 'VM-template', ->
vm = collection.get()
console.log vm
it 'SR', ->
sr = collection.get 'OpaqueRef:d6fe49bf-dd48-c929-5aab-b2786a2e7aee'
@ -286,7 +295,7 @@ describe 'spec2', ->
$expect(sr.size).to.equal 2199010672640
expect(sr.$container).to.equal 'OpaqueRef:6462d0b3-8f20-ef76-fddf-002f7af3452e'
$expect(sr.$container).to.equal 'OpaqueRef:6462d0b3-8f20-ef76-fddf-002f7af3452e'
$expect(sr.$PBDs).to.have.members [
'OpaqueRef:ff32de74-138c-9d80-ab58-c631d2aa0e71'
@ -423,7 +432,7 @@ describe 'spec2', ->
$expect(vif.VM).to.equal 'OpaqueRef:fdaba312-c3a5-0190-b1a1-bf389567e620'
it 'network', ->
network = collection.getRaw 'OpaqueRef:dbc93777-f2c0-e888-967d-dd9beeffb3c0'
network = collection.get 'OpaqueRef:dbc93777-f2c0-e888-967d-dd9beeffb3c0'
#console.log network
@ -462,7 +471,7 @@ describe 'spec2', ->
]
it 'message', ->
console.log collection.get()
#console.log collection.get()
it 'task', ->
# FIXME: we need to update the tests data to complete this test.