Exemplo n.º 1
0
  @Deprecated
  private ManagedObjectReference addHostToVCenterCluster(
      VmwareContext serviceContext,
      ManagedObjectReference morCluster,
      String host,
      String userName,
      String password)
      throws Exception {

    ServiceUtil serviceUtil = serviceContext.getServiceUtil();
    ManagedObjectReference morHost = serviceUtil.getDecendentMoRef(morCluster, "HostSystem", host);
    if (morHost == null) {
      HostConnectSpec hostSpec = new HostConnectSpec();
      hostSpec.setUserName(userName);
      hostSpec.setPassword(password);
      hostSpec.setHostName(host);
      hostSpec.setForce(true); // forcely take over the host

      ManagedObjectReference morTask =
          serviceContext.getService().addHost_Task(morCluster, hostSpec, true, null, null);
      String taskResult = serviceUtil.waitForTask(morTask);
      if (!taskResult.equals("sucess")) {
        s_logger.error(
            "Unable to add host "
                + host
                + " to vSphere cluster due to "
                + TaskMO.getTaskFailureInfo(serviceContext, morTask));
        throw new CloudRuntimeException(
            "Unable to add host " + host + " to vSphere cluster due to " + taskResult);
      }
      serviceContext.waitForTaskProgressDone(morTask);

      // init morHost after it has been created
      morHost = serviceUtil.getDecendentMoRef(morCluster, "HostSystem", host);
      if (morHost == null) {
        throw new CloudRuntimeException(
            "Successfully added host into vSphere but unable to find it later on?!. Please make sure you are either using IP address or full qualified domain name for host");
      }
    }

    // For ESX host, we need to enable host firewall to allow VNC access
    HostMO hostMo = new HostMO(serviceContext, morHost);
    HostFirewallSystemMO firewallMo = hostMo.getHostFirewallSystemMO();
    if (firewallMo != null) {
      firewallMo.enableRuleset("vncServer");
      firewallMo.refreshFirewall();
    }
    return morHost;
  }
Exemplo n.º 2
0
  @Override
  public List<ManagedObjectReference> addHostToPodCluster(
      VmwareContext serviceContext, long dcId, Long podId, Long clusterId, String hostInventoryPath)
      throws Exception {
    ManagedObjectReference mor = serviceContext.getHostMorByPath(hostInventoryPath);
    if (mor != null) {
      List<ManagedObjectReference> returnedHostList = new ArrayList<ManagedObjectReference>();

      if (mor.getType().equals("ComputeResource")) {
        ManagedObjectReference[] hosts =
            (ManagedObjectReference[])
                serviceContext.getServiceUtil().getDynamicProperty(mor, "host");
        assert (hosts != null);

        // For ESX host, we need to enable host firewall to allow VNC access
        HostMO hostMo = new HostMO(serviceContext, hosts[0]);
        HostFirewallSystemMO firewallMo = hostMo.getHostFirewallSystemMO();
        if (firewallMo != null) {
          firewallMo.enableRuleset("vncServer");
          firewallMo.refreshFirewall();
        }

        // prepare at least one network on the vswitch to enable OVF importing
        String managementPortGroupName =
            hostMo.getPortGroupNameByNicType(HostVirtualNicType.management);
        assert (managementPortGroupName != null);
        HostPortGroupSpec spec = hostMo.getPortGroupSpec(managementPortGroupName);
        Integer vlanId = null;
        if (spec.getVlanId() != 0) {
          vlanId = spec.getVlanId();
        }

        HypervisorHostHelper.preparePrivateNetwork(
            _privateNetworkVSwitchName, hostMo, vlanId, 180000);
        returnedHostList.add(hosts[0]);
        return returnedHostList;
      } else if (mor.getType().equals("ClusterComputeResource")) {
        ManagedObjectReference[] hosts =
            (ManagedObjectReference[])
                serviceContext.getServiceUtil().getDynamicProperty(mor, "host");
        assert (hosts != null);

        if (hosts.length > _maxHostsPerCluster) {
          String msg =
              "vCenter cluster size is too big (current configured cluster size: "
                  + _maxHostsPerCluster
                  + ")";
          s_logger.error(msg);
          throw new DiscoveredWithErrorException(msg);
        }

        for (ManagedObjectReference morHost : hosts) {
          // For ESX host, we need to enable host firewall to allow VNC access
          HostMO hostMo = new HostMO(serviceContext, morHost);
          HostFirewallSystemMO firewallMo = hostMo.getHostFirewallSystemMO();
          if (firewallMo != null) {
            firewallMo.enableRuleset("vncServer");
            firewallMo.refreshFirewall();
          }

          String managementPortGroupName =
              hostMo.getPortGroupNameByNicType(HostVirtualNicType.management);
          assert (managementPortGroupName != null);
          HostPortGroupSpec spec = hostMo.getPortGroupSpec(managementPortGroupName);
          Integer vlanId = null;
          if (spec.getVlanId() != 0) {
            vlanId = spec.getVlanId();
          }

          // prepare at least one network on the vswitch to enable OVF importing
          HypervisorHostHelper.preparePrivateNetwork(
              _privateNetworkVSwitchName, hostMo, vlanId, 180000);
          returnedHostList.add(morHost);
        }
        return returnedHostList;
      } else if (mor.getType().equals("HostSystem")) {
        // For ESX host, we need to enable host firewall to allow VNC access
        HostMO hostMo = new HostMO(serviceContext, mor);
        HostFirewallSystemMO firewallMo = hostMo.getHostFirewallSystemMO();
        if (firewallMo != null) {
          firewallMo.enableRuleset("vncServer");
          firewallMo.refreshFirewall();
        }

        String managementPortGroupName =
            hostMo.getPortGroupNameByNicType(HostVirtualNicType.management);
        assert (managementPortGroupName != null);
        HostPortGroupSpec spec = hostMo.getPortGroupSpec(managementPortGroupName);
        Integer vlanId = null;
        if (spec.getVlanId() != 0) {
          vlanId = spec.getVlanId();
        }

        // prepare at least one network on the vswitch to enable OVF importing
        HypervisorHostHelper.preparePrivateNetwork(
            _privateNetworkVSwitchName, hostMo, vlanId, 180000);
        returnedHostList.add(mor);
        return returnedHostList;
      } else {
        s_logger.error(
            "Unsupport host type "
                + mor.getType()
                + ":"
                + mor.get_value()
                + " from inventory path: "
                + hostInventoryPath);
        return null;
      }
    }

    s_logger.error("Unable to find host from inventory path: " + hostInventoryPath);
    return null;
  }