@Override
 public void setVolumesToMachineId(Node node) throws Exception {
   VirtualMachine vm = VmUtil.getVirtualMachine(serviceInstance, node.getVmName());
   String volumes = VmUtil.getVolumes(vm, node.getVmSchema().diskSchema.getDisks());
   Map<String, Object> volumesVariable = new HashMap<String, Object>();
   volumesVariable.put(GUEST_VARIABLE_VOLUMES, volumes);
   setMachineIdVariables(vm, volumesVariable);
 }
  @Override
  public void enableDiskUUID(Node node) throws Exception {
    VirtualMachine vm = VmUtil.getVirtualMachine(serviceInstance, node.getVmName());

    VirtualMachineFlagInfo flagInfo = new VirtualMachineFlagInfo();
    flagInfo.setDiskUuidEnabled(true);
    VirtualMachineConfigSpec configSpec = new VirtualMachineConfigSpec();
    configSpec.setFlags(flagInfo);
    vm.reconfigVM_Task(configSpec);
  }
  public void changeDisks(Node node) throws Exception {
    VirtualMachine vm = VmUtil.getVirtualMachine(serviceInstance, node.getVmName());
    final VirtualMachineConfigSpec configSpec = new VirtualMachineConfigSpec();
    final List<VirtualDeviceConfigSpec> devChanges = new ArrayList<VirtualDeviceConfigSpec>();

    HashMap<String, Disk.Operation> diskMap = new HashMap<String, Disk.Operation>();
    List<DiskCreateSpec> addDisks = DiskSchemaUtil.getDisksToAdd(node, diskMap);

    if (addDisks != null) {
      for (DiskCreateSpec spec : addDisks) {
        devChanges.add(spec.getVcSpec(node.getKey(), vm));
      }
    }

    configSpec.setDeviceChange(devChanges.toArray(new VirtualDeviceConfigSpec[devChanges.size()]));
    logger.info("The node " + node.getVmName() + " configSpec: " + new Gson().toJson(configSpec));
    VmConfigUtil.reconfigure(vm, configSpec);
  }
  @Override
  public void configNetworks(Node node) throws Exception {
    VirtualMachine vm = VmUtil.getVirtualMachine(serviceInstance, node.getVmName());
    VcNetwork vcNet = null;
    String operation = null;
    String network = null;
    String newNetwork = null;

    for (NetworkResource networkResource : node.getTargetHost().getNetworks()) {
      // the setting network for Cloudera director exists in Esx hosts netowrk which the node vm is
      // located in
      if (node.getNetwork().equals(networkResource.getName())) {
        vcNet = new VcNetwork();
        vcNet.update(
            serviceInstance.getRootFolder().getServerConnection(),
            networkResource.toVim25Network(serviceInstance));

        if (vm.getNetworks().length == 0) {
          operation = "add";
          network = node.getNetwork();
        } else {
          operation = "edit";
          network = vm.getNetworks()[0].getName();
          newNetwork = node.getNetwork();
        }
        break;
      }
    }

    if (vcNet == null) {
      throw new Exception("Network " + node.getNetwork() + " is not defined on ESX hosts");
    }

    VmNicOperationService vmNicOperationService =
        new VmNicOperationService(vm, operation, vcNet, network, newNetwork);
    vmNicOperationService.run();
  }