     if f then Instances.update doc._id, $set:
       state: 'created'
       desiredState: 'running'
+      status: 'Created'
 
 Instances.find({state: 'removed', desiredState: 'stopped'}, fields: {_id: 1}).observe
   added: (doc, olddoc) -> Instances.remove doc._id

  #
  imagePull: (image) ->
    updated = Instances.update {'steps.image': image}, {$set: {'steps.$.completed': true}}


f = true

setServiceField = (fieldName, fieldValue, labels) ->
  if (name = labels['bigboat/instance/name']) and (service = labels['bigboat/service/name'])
    Instances.upsert {name: name}, $set: {"services.#{service}.#{fieldName}": fieldValue}

module.exports =
  updateServiceFQDN: (fqdn, labels) -> setServiceField 'fqdn', fqdn, labels

  updateServicePorts: (ports, labels) -> setServiceField 'ports', ports, labels

  updateContainerName: (name, labels) -> setServiceField 'container.name', name, labels


  updateServiceState: (mappedState, labels) ->
    unless mappedState in SERVICE_STATES
      throw "Service state '#{mappedState}' is not supported."
