@Override
  public boolean rebootSecStorageVm(long secStorageVmId) {
    final SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findById(secStorageVmId);

    if (secStorageVm == null || secStorageVm.getState() == State.Destroyed) {
      return false;
    }

    if (secStorageVm.getState() == State.Running && secStorageVm.getHostId() != null) {
      final RebootCommand cmd = new RebootCommand(secStorageVm.getInstanceName());
      final Answer answer = _agentMgr.easySend(secStorageVm.getHostId(), cmd);

      if (answer != null && answer.getResult()) {
        if (s_logger.isDebugEnabled()) {
          s_logger.debug("Successfully reboot secondary storage vm " + secStorageVm.getHostName());
        }

        SubscriptionMgr.getInstance()
            .notifySubscribers(
                ALERT_SUBJECT,
                this,
                new SecStorageVmAlertEventArgs(
                    SecStorageVmAlertEventArgs.SSVM_REBOOTED,
                    secStorageVm.getDataCenterIdToDeployIn(),
                    secStorageVm.getId(),
                    secStorageVm,
                    null));

        return true;
      } else {
        String msg = "Rebooting Secondary Storage VM failed - " + secStorageVm.getHostName();
        if (s_logger.isDebugEnabled()) {
          s_logger.debug(msg);
        }
        return false;
      }
    } else {
      return startSecStorageVm(secStorageVmId) != null;
    }
  }
  public SecondaryStorageVmVO startNew(long dataCenterId, SecondaryStorageVm.Role role) {

    if (!isSecondaryStorageVmRequired(dataCenterId)) {
      if (s_logger.isDebugEnabled()) {
        s_logger.debug(
            "Secondary storage vm not required in zone " + dataCenterId + " acc. to zone config");
      }
      return null;
    }
    if (s_logger.isDebugEnabled()) {
      s_logger.debug(
          "Assign secondary storage vm from a newly started instance for request from data center : "
              + dataCenterId);
    }

    Map<String, Object> context = createSecStorageVmInstance(dataCenterId, role);

    long secStorageVmId = (Long) context.get("secStorageVmId");
    if (secStorageVmId == 0) {
      if (s_logger.isTraceEnabled()) {
        s_logger.trace(
            "Creating secondary storage vm instance failed, data center id : " + dataCenterId);
      }

      return null;
    }

    SecondaryStorageVmVO secStorageVm = _secStorageVmDao.findById(secStorageVmId);
    // SecondaryStorageVmVO secStorageVm =
    // allocSecStorageVmStorage(dataCenterId, secStorageVmId);
    if (secStorageVm != null) {
      SubscriptionMgr.getInstance()
          .notifySubscribers(
              ALERT_SUBJECT,
              this,
              new SecStorageVmAlertEventArgs(
                  SecStorageVmAlertEventArgs.SSVM_CREATED,
                  dataCenterId,
                  secStorageVmId,
                  secStorageVm,
                  null));
      return secStorageVm;
    } else {
      if (s_logger.isDebugEnabled()) {
        s_logger.debug(
            "Unable to allocate secondary storage vm storage, remove the secondary storage vm record from DB, secondary storage vm id: "
                + secStorageVmId);
      }

      SubscriptionMgr.getInstance()
          .notifySubscribers(
              ALERT_SUBJECT,
              this,
              new SecStorageVmAlertEventArgs(
                  SecStorageVmAlertEventArgs.SSVM_CREATE_FAILURE,
                  dataCenterId,
                  secStorageVmId,
                  null,
                  "Unable to allocate storage"));
    }
    return null;
  }