<commit_before>{$wait} = require '../fibers-utils'

#=====================================================================

exports.delete = ({id}) ->
  try
    VBD = @getObject id, 'VBD'
  catch
    @throw 'NO_SUCH_OBJECT'

  xapi = @getXAPI VBD

  # TODO: check if VBD is attached before
  $wait xapi.call 'VBD.destroy', VBD.ref

  return true
exports.delete.permission = 'admin'
exports.delete.params = {
  id: { type: 'string' }
}

exports.disconnect = ({id}) ->
  try
    VBD = @getObject id, 'VBD'
  catch
    @throw 'NO_SUCH_OBJECT'

  xapi = @getXAPI VBD

  # TODO: check if VBD is attached before
  $wait xapi.call 'VBD.unplug_force', VBD.ref

  return true
exports.disconnect.permission = 'admin'
exports.disconnect.params = {
  id: { type: 'string' }
}
<commit_msg>add vbd connect method<commit_after>{$wait} = require '../fibers-utils'

#=====================================================================

exports.delete = ({id}) ->
  try
    VBD = @getObject id, 'VBD'
  catch
    @throw 'NO_SUCH_OBJECT'

  xapi = @getXAPI VBD

  # TODO: check if VBD is attached before
  $wait xapi.call 'VBD.destroy', VBD.ref

  return true
exports.delete.permission = 'admin'
exports.delete.params = {
  id: { type: 'string' }
}

exports.disconnect = ({id}) ->
  try
    VBD = @getObject id, 'VBD'
  catch
    @throw 'NO_SUCH_OBJECT'

  xapi = @getXAPI VBD

  # TODO: check if VBD is attached before
  $wait xapi.call 'VBD.unplug_force', VBD.ref

  return true
exports.disconnect.permission = 'admin'
exports.disconnect.params = {
  id: { type: 'string' }
}

exports.connect = ({id}) ->
  try
    VBD = @getObject id, 'VBD'
  catch
    @throw 'NO_SUCH_OBJECT'

  xapi = @getXAPI VBD

  # TODO: check if VBD is attached before
  $wait xapi.call 'VBD.plug', VBD.ref

  return true
exports.disconnect.permission = 'admin'
exports.disconnect.params = {
  id: { type: 'string' }
}

{'fraction_non_alphanumeric': 0.20276742948376797, 'fraction_numerical': 0.0, 'mean_word_length': 3.5410628019323673, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '67752', 'n_tokens_mistral': 684, 'n_tokens_neox': 658, 'n_words': 169}