コード例 #1
0
  @Deprecated
  private ManagedObjectReference addHostToVCenterCluster(
      VmwareContext serviceContext,
      ManagedObjectReference morCluster,
      String host,
      String userName,
      String password)
      throws Exception {

    VmwareClient vclient = serviceContext.getVimClient();
    ManagedObjectReference morHost = vclient.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().addHostTask(morCluster, hostSpec, true, null, null);
      boolean taskResult = vclient.waitForTask(morTask);
      if (!taskResult) {
        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 = vclient.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;
  }
コード例 #2
0
  private void prepareHost(HostMO hostMo, String privateTrafficLabel) throws Exception {
    // For ESX host, we need to enable host firewall to allow VNC access
    HostFirewallSystemMO firewallMo = hostMo.getHostFirewallSystemMO();
    if (firewallMo != null) {
      if (hostMo.getHostType() == VmwareHostType.ESX) {
        firewallMo.enableRuleset("vncServer");
        firewallMo.refreshFirewall();
      }
    }

    // prepare at least one network on the vswitch to enable OVF importing
    String vSwitchName = privateTrafficLabel;
    String vlanId = null;
    String vlanToken;
    String[] tokens = privateTrafficLabel.split(",");
    if (tokens.length >= 2) {
      vSwitchName = tokens[0].trim();
      vlanToken = tokens[1].trim();
      if (!vlanToken.isEmpty()) {
        vlanId = vlanToken;
      }
    }
    s_logger.info(
        "Preparing network on host "
            + hostMo.getContext().toString()
            + " for "
            + privateTrafficLabel);
    // The management network is probably always going to be a physical network with vlans, so
    // assume BroadcastDomainType VLAN
    HypervisorHostHelper.prepareNetwork(
        vSwitchName,
        "cloud.private",
        hostMo,
        vlanId,
        null,
        null,
        180000,
        false,
        BroadcastDomainType.Vlan,
        null);
  }
コード例 #3
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;
  }