Commit 755ec5cf authored by Masami  Suzuki's avatar Masami Suzuki Committed by Yas Naoi
Browse files

Issue #3281004 by Masami, yas, Ryo Yamashita: Add the function to stop VMware VM in the SPA

parent 82f9940e
Loading
Loading
Loading
Loading
+12 −0
Changes for modules/cloud_dashboard/cloud_dashboard/src/constant/form_template/vmware/vm.ts: 12 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -123,6 +123,18 @@ const VMWARE_VM_TEMPLATE: EntityFormTemplate[] = [
      }
    ],
    submitButtonLabel: 'Start'
  },
  {
    cloudServiceProvider: 'vmware',
    entityName: 'vm',
    actionType: 'stop',
    entityRecords: [
      {
        type: 'label',
        text: 'Are you sure you want to stop VM: {{name}}?'
      }
    ],
    submitButtonLabel: 'Stop'
  }
]

+3 −0
Changes for modules/cloud_dashboard/cloud_dashboard/src/molecules/DataTableRowWithOperationLinks.tsx: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -225,6 +225,9 @@ const DataTableRowWithOperationLinks = ({ dataRecord, dataColumnList, className,
                    case 'Start':
                      xxudData(dataRecord, 'start');
                      break;
                    case 'Stop':
                      xxudData(dataRecord, 'stop');
                      break;
                  }
                }}>
                  {menuInfo[1] !== '' ? <GlyphIcon iconName={menuInfo[1]} /> : <></>}
+9 −0
Changes for modules/cloud_service_providers/vmware/src/Controller/ApiController.php: 9 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -406,6 +406,15 @@ class ApiController extends ControllerBase implements ApiControllerInterface {
            break;
        }
        break;

      case 'stop':
        switch ($entity_type_id) {
          case 'vmware_vm':
            $method_name = 'stopVm';
            $parameter = [];
            break;
        }
        break;
    }

    $result = FALSE;
+2 −24
Changes for modules/cloud_service_providers/vmware/src/Form/VmwareVmStopForm.php: 2 added lines, 24 removed lines.
Original line number Diff line number Diff line
@@ -35,31 +35,9 @@ class VmwareVmStopForm extends VmwareDeleteForm {
   */
  public function submitForm(array &$form, FormStateInterface $form_state): void {
    $entity = $this->entity;

    try {
      $this->vmwareService->setCloudContext($entity->getCloudContext());
      $this->vmwareService->login();
      $result = $this->vmwareService->stopVm([
        'VmId' => $entity->getVmId(),
      ]);

      if (!empty($result['SendToWorker'])) {
        $this->processOperationStatus($entity, 'stopped remotely');
        return;
      }

      $this->vmwareService->updateVms([
        'name' => $entity->getName(),
      ], FALSE);

      $this->processOperationStatus($entity, 'stopped');
      $this->clearCacheValues($entity->getCacheTags());
    }
    catch (\Exception $e) {
      $this->handleException($e);
    }

    if ($this->vmwareOperationsService->stopVm($entity, [])) {
      $form_state->setRedirect("view.{$entity->getEntityTypeId()}.list", ['cloud_context' => $entity->getCloudContext()]);
    }
  }

}
+30 −0
Changes for modules/cloud_service_providers/vmware/src/Service/VmwareOperationsService.php: 30 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -299,4 +299,34 @@ class VmwareOperationsService extends CloudServiceBase implements VmwareOperatio
    }
  }

  /**
   * {@inheritdoc}
   */
  public function stopVm(VmwareVmInterface $entity, array $params): bool {
    try {
      $this->vmwareService->setCloudContext($entity->getCloudContext());
      $this->vmwareService->login();
      $result = $this->vmwareService->stopVm([
        'VmId' => $entity->getVmId(),
      ]);

      if (!empty($result['SendToWorker'])) {
        $this->processOperationStatus($entity, 'stopped remotely');
        return TRUE;
      }

      $this->vmwareService->updateVms([
        'name' => $entity->getName(),
      ], FALSE);

      $this->processOperationStatus($entity, 'stopped');
      $this->clearCacheValues($entity->getCacheTags());
      return TRUE;
    }
    catch (\Exception $e) {
      $this->handleException($e);
      return FALSE;
    }
  }

}
Loading