| 474 | |
| 475 | |
| 476 | def use_cluster(cluster_name, nodes, ipformat=None, start=True, workloads=None, set_keyspace=True, ccm_options=None, |
| 477 | configuration_options=None, dse_options=None, use_single_interface=USE_SINGLE_INTERFACE): |
| 478 | configuration_options = configuration_options or {} |
| 479 | dse_options = dse_options or {} |
| 480 | workloads = workloads or [] |
| 481 | dse_cluster = True if DSE_VERSION else False |
| 482 | hcd_cluster = True if HCD_VERSION else False |
| 483 | |
| 484 | if ccm_options is None and (DSE_VERSION or HCD_VERSION): |
| 485 | ccm_options = {"version": CCM_VERSION} |
| 486 | elif ccm_options is None: |
| 487 | ccm_options = CCM_KWARGS.copy() |
| 488 | |
| 489 | cassandra_version = ccm_options.get('version', CCM_VERSION) |
| 490 | dse_version = ccm_options.get('version', DSE_VERSION) |
| 491 | |
| 492 | global CCM_CLUSTER |
| 493 | if USE_CASS_EXTERNAL: |
| 494 | if CCM_CLUSTER: |
| 495 | log.debug("Using external CCM cluster {0}".format(CCM_CLUSTER.name)) |
| 496 | else: |
| 497 | ccm_path = os.getenv("CCM_PATH", None) |
| 498 | ccm_name = os.getenv("CCM_NAME", None) |
| 499 | if ccm_path and ccm_name: |
| 500 | CCM_CLUSTER = CCMClusterFactory.load(ccm_path, ccm_name) |
| 501 | log.debug("Using external CCM cluster {0}".format(CCM_CLUSTER.name)) |
| 502 | else: |
| 503 | log.debug("Using unnamed external cluster") |
| 504 | if set_keyspace and start: |
| 505 | setup_keyspace(ipformat=ipformat, wait=False) |
| 506 | return |
| 507 | |
| 508 | if is_current_cluster(cluster_name, nodes, workloads): |
| 509 | log.debug("Using existing cluster, matching topology: {0}".format(cluster_name)) |
| 510 | else: |
| 511 | if CCM_CLUSTER: |
| 512 | log.debug("Stopping existing cluster, topology mismatch: {0}".format(CCM_CLUSTER.name)) |
| 513 | CCM_CLUSTER.stop() |
| 514 | |
| 515 | try: |
| 516 | CCM_CLUSTER = CCMClusterFactory.load(path, cluster_name) |
| 517 | log.debug("Found existing CCM cluster, {0}; clearing.".format(cluster_name)) |
| 518 | CCM_CLUSTER.clear() |
| 519 | CCM_CLUSTER.set_install_dir(**ccm_options) |
| 520 | CCM_CLUSTER.set_configuration_options(configuration_options) |
| 521 | CCM_CLUSTER.set_dse_configuration_options(dse_options) |
| 522 | except Exception: |
| 523 | ex_type, ex, tb = sys.exc_info() |
| 524 | log.warning("{0}: {1} Backtrace: {2}".format(ex_type.__name__, ex, traceback.extract_tb(tb))) |
| 525 | del tb |
| 526 | |
| 527 | ccm_options.update(cmd_line_args_to_dict('CCM_ARGS')) |
| 528 | |
| 529 | log.debug("Creating new CCM cluster, {0}, with args {1}".format(cluster_name, ccm_options)) |
| 530 | |
| 531 | # Make sure we cleanup old cluster dir if it exists |
| 532 | cluster_path = os.path.join(path, cluster_name) |
| 533 | if os.path.exists(cluster_path): |