def _deploy_host(cluster, zone_ref, cluster_ref):
        if not xmlobject.has_element(cluster, "hosts.host"):
            return

        if zone_ref == 0 and cluster_ref == 0:
            cluster_name = cluster.name_
        else:
            cluster_name = generate_dup_name(
                generate_dup_name(cluster.name_, zone_ref, 'z'), cluster_ref,
                'c')

        cinvs = res_ops.get_resource(res_ops.CLUSTER,
                                     session_uuid,
                                     name=cluster_name)
        cinv = get_first_item_from_list(cinvs, 'Cluster', cluster_name,
                                        'L3 network')
        for host in xmlobject.safe_list(cluster.hosts.host):
            if host_ip and host_ip != host.managementIp_:
                continue

            if host.duplication__ == None:
                host_duplication = 1
            else:
                host_duplication = int(host.duplication__)

            for i in range(host_duplication):
                if cluster.hypervisorType_ == inventory.KVM_HYPERVISOR_TYPE:
                    action = api_actions.AddKVMHostAction()
                    action.username = host.username_
                    action.password = host.password_
                    action.timeout = AddKVMHostTimeOut
                elif cluster.hypervisorType_ == inventory.SIMULATOR_HYPERVISOR_TYPE:
                    action = api_actions.AddSimulatorHostAction()
                    action.cpuCapacity = host.cpuCapacity_
                    action.memoryCapacity = sizeunit.get_size(
                        host.memoryCapacity_)

                action.sessionUuid = session_uuid
                action.clusterUuid = cinv.uuid
                action.hostTags = host.hostTags__
                if zone_ref == 0 and cluster_ref == 0 and i == 0:
                    action.name = host.name_
                    action.description = host.description__
                    action.managementIp = host.managementIp_
                else:
                    action.name = generate_dup_name(
                        generate_dup_name(
                            generate_dup_name(host.name_, zone_ref, 'z'),
                            cluster_ref, 'c'), i, 'h')
                    action.description = generate_dup_name(
                        generate_dup_name(
                            generate_dup_name(host.description__, zone_ref,
                                              'z'), cluster_ref, 'c'), i, 'h')
                    action.managementIp = generate_dup_host_ip(
                        host.managementIp_, zone_ref, cluster_ref, i)

                thread = threading.Thread(target=_thread_for_action,
                                          args=(action, ))
                wait_for_thread_queue()
                thread.start()
def add_kvm_host(host_option, session_uuid=None):
    action = api_actions.AddKVMHostAction()
    action.timeout = 300000
    action.clusterUuid = host_option.get_cluster_uuid()
    action.username = host_option.get_username()
    action.password = host_option.get_password()
    action.managementIp = host_option.get_management_ip()
    action.name = host_option.get_name()
    action.description = host_option.get_description()
    action.hostTags = host_option.get_host_tags()
    evt = account_operations.execute_action_with_session(action, session_uuid)
    test_util.action_logger('Add KVM Host [uuid:] %s with [ip:] %s' % \
            (evt.uuid, action.managementIp))
    return evt.inventory